bpmn-modeler.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559
  1. /*!
  2. * bpmn-js - bpmn-modeler v0.11.0
  3. * Copyright 2014, 2015 camunda Services GmbH and other contributors
  4. *
  5. * Released under the bpmn.io license
  6. * http://bpmn.io/license
  7. *
  8. * Source Code: https://github.com/bpmn-io/bpmn-js
  9. *
  10. * Date: 2015-08-06
  11. */
  12. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.BpmnJS=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  13. 'use strict';
  14. var inherits = _dereq_(207);
  15. var IdSupport = _dereq_(53),
  16. Ids = _dereq_(205);
  17. var Viewer = _dereq_(2);
  18. var initialDiagram =
  19. '<?xml version="1.0" encoding="UTF-8"?>' +
  20. '<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
  21. 'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
  22. 'xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" ' +
  23. 'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" ' +
  24. 'targetNamespace="http://bpmn.io/schema/bpmn" ' +
  25. 'id="Definitions_1">' +
  26. '<bpmn:process id="Process_1" isExecutable="false">' +
  27. '<bpmn:startEvent id="StartEvent_1"/>' +
  28. '</bpmn:process>' +
  29. '<bpmndi:BPMNDiagram id="BPMNDiagram_1">' +
  30. '<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">' +
  31. '<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">' +
  32. '<dc:Bounds height="36.0" width="36.0" x="173.0" y="102.0"/>' +
  33. '</bpmndi:BPMNShape>' +
  34. '</bpmndi:BPMNPlane>' +
  35. '</bpmndi:BPMNDiagram>' +
  36. '</bpmn:definitions>';
  37. /**
  38. * A modeler for BPMN 2.0 diagrams.
  39. *
  40. *
  41. * ## Extending the Modeler
  42. *
  43. * In order to extend the viewer pass extension modules to bootstrap via the
  44. * `additionalModules` option. An extension module is an object that exposes
  45. * named services.
  46. *
  47. * The following example depicts the integration of a simple
  48. * logging component that integrates with interaction events:
  49. *
  50. *
  51. * ```javascript
  52. *
  53. * // logging component
  54. * function InteractionLogger(eventBus) {
  55. * eventBus.on('element.hover', function(event) {
  56. * console.log()
  57. * })
  58. * }
  59. *
  60. * InteractionLogger.$inject = [ 'eventBus' ]; // minification save
  61. *
  62. * // extension module
  63. * var extensionModule = {
  64. * __init__: [ 'interactionLogger' ],
  65. * interactionLogger: [ 'type', InteractionLogger ]
  66. * };
  67. *
  68. * // extend the viewer
  69. * var bpmnModeler = new Modeler({ additionalModules: [ extensionModule ] });
  70. * bpmnModeler.importXML(...);
  71. * ```
  72. *
  73. *
  74. * ## Customizing / Replacing Components
  75. *
  76. * You can replace individual diagram components by redefining them in override modules.
  77. * This works for all components, including those defined in the core.
  78. *
  79. * Pass in override modules via the `options.additionalModules` flag like this:
  80. *
  81. * ```javascript
  82. * function CustomContextPadProvider(contextPad) {
  83. *
  84. * contextPad.registerProvider(this);
  85. *
  86. * this.getContextPadEntries = function(element) {
  87. * // no entries, effectively disable the context pad
  88. * return {};
  89. * };
  90. * }
  91. *
  92. * CustomContextPadProvider.$inject = [ 'contextPad' ];
  93. *
  94. * var overrideModule = {
  95. * contextPadProvider: [ 'type', CustomContextPadProvider ]
  96. * };
  97. *
  98. * var bpmnModeler = new Modeler({ additionalModules: [ overrideModule ]});
  99. * ```
  100. *
  101. * @param {Object} [options] configuration options to pass to the viewer
  102. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  103. * @param {String|Number} [options.width] the width of the viewer
  104. * @param {String|Number} [options.height] the height of the viewer
  105. * @param {Object} [options.moddleExtensions] extension packages to provide
  106. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  107. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  108. */
  109. function Modeler(options) {
  110. Viewer.call(this, options);
  111. }
  112. inherits(Modeler, Viewer);
  113. Modeler.prototype.createDiagram = function(done) {
  114. return this.importXML(initialDiagram, done);
  115. };
  116. Modeler.prototype.createModdle = function() {
  117. var moddle = Viewer.prototype.createModdle.call(this);
  118. IdSupport.extend(moddle, new Ids([ 32, 36, 1 ]));
  119. return moddle;
  120. };
  121. Modeler.prototype._interactionModules = [
  122. // non-modeling components
  123. _dereq_(14),
  124. _dereq_(182),
  125. _dereq_(178),
  126. _dereq_(179)
  127. ];
  128. Modeler.prototype._modelingModules = [
  129. // modeling components
  130. _dereq_(139),
  131. _dereq_(96),
  132. _dereq_(152),
  133. _dereq_(166),
  134. _dereq_(114),
  135. _dereq_(10),
  136. _dereq_(42),
  137. _dereq_(32),
  138. _dereq_(8),
  139. _dereq_(36)
  140. ];
  141. // modules the modeler is composed of
  142. //
  143. // - viewer modules
  144. // - interaction modules
  145. // - modeling modules
  146. Modeler.prototype._modules = [].concat(
  147. Modeler.prototype._modules,
  148. Modeler.prototype._interactionModules,
  149. Modeler.prototype._modelingModules);
  150. module.exports = Modeler;
  151. },{"10":10,"114":114,"139":139,"14":14,"152":152,"166":166,"178":178,"179":179,"182":182,"2":2,"205":205,"207":207,"32":32,"36":36,"42":42,"53":53,"8":8,"96":96}],2:[function(_dereq_,module,exports){
  152. 'use strict';
  153. var assign = _dereq_(339),
  154. omit = _dereq_(343),
  155. isString = _dereq_(336),
  156. isNumber = _dereq_(333);
  157. var domify = _dereq_(356),
  158. domQuery = _dereq_(359),
  159. domRemove = _dereq_(360);
  160. var Diagram = _dereq_(76),
  161. BpmnModdle = _dereq_(51);
  162. var Importer = _dereq_(45);
  163. function initListeners(diagram, listeners) {
  164. var events = diagram.get('eventBus');
  165. listeners.forEach(function(l) {
  166. events.on(l.event, l.handler);
  167. });
  168. }
  169. function checkValidationError(err) {
  170. // check if we can help the user by indicating wrong BPMN 2.0 xml
  171. // (in case he or the exporting tool did not get that right)
  172. var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
  173. var match = pattern.exec(err.message);
  174. if (match) {
  175. err.message =
  176. 'unparsable content <' + match[1] + '> detected; ' +
  177. 'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
  178. }
  179. return err;
  180. }
  181. var DEFAULT_OPTIONS = {
  182. width: '100%',
  183. height: '100%',
  184. position: 'relative',
  185. container: 'body'
  186. };
  187. /**
  188. * Ensure the passed argument is a proper unit (defaulting to px)
  189. */
  190. function ensureUnit(val) {
  191. return val + (isNumber(val) ? 'px' : '');
  192. }
  193. /**
  194. * A viewer for BPMN 2.0 diagrams.
  195. *
  196. * Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
  197. * additional features.
  198. *
  199. *
  200. * ## Extending the Viewer
  201. *
  202. * In order to extend the viewer pass extension modules to bootstrap via the
  203. * `additionalModules` option. An extension module is an object that exposes
  204. * named services.
  205. *
  206. * The following example depicts the integration of a simple
  207. * logging component that integrates with interaction events:
  208. *
  209. *
  210. * ```javascript
  211. *
  212. * // logging component
  213. * function InteractionLogger(eventBus) {
  214. * eventBus.on('element.hover', function(event) {
  215. * console.log()
  216. * })
  217. * }
  218. *
  219. * InteractionLogger.$inject = [ 'eventBus' ]; // minification save
  220. *
  221. * // extension module
  222. * var extensionModule = {
  223. * __init__: [ 'interactionLogger' ],
  224. * interactionLogger: [ 'type', InteractionLogger ]
  225. * };
  226. *
  227. * // extend the viewer
  228. * var bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
  229. * bpmnViewer.importXML(...);
  230. * ```
  231. *
  232. * @param {Object} [options] configuration options to pass to the viewer
  233. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  234. * @param {String|Number} [options.width] the width of the viewer
  235. * @param {String|Number} [options.height] the height of the viewer
  236. * @param {Object} [options.moddleExtensions] extension packages to provide
  237. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  238. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  239. */
  240. function Viewer(options) {
  241. this.options = options = assign({}, DEFAULT_OPTIONS, options || {});
  242. var parent = options.container;
  243. // support jquery element
  244. // unwrap it if passed
  245. if (parent.get) {
  246. parent = parent.get(0);
  247. }
  248. // support selector
  249. if (isString(parent)) {
  250. parent = domQuery(parent);
  251. }
  252. var container = this.container = domify('<div class="bjs-container"></div>');
  253. parent.appendChild(container);
  254. assign(container.style, {
  255. width: ensureUnit(options.width),
  256. height: ensureUnit(options.height),
  257. position: options.position
  258. });
  259. /**
  260. * The code in the <project-logo></project-logo> area
  261. * must not be changed, see http://bpmn.io/license for more information
  262. *
  263. * <project-logo>
  264. */
  265. /* jshint -W101 */
  266. // inlined ../resources/bpmnjs.png
  267. var logoData = 'iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAMAAADypuvZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRFiMte9PrwldFwfcZPqtqN0+zEyOe1XLgjvuKncsJAZ70y6fXh3vDT////UrQV////G2zN+AAAABB0Uk5T////////////////////AOAjXRkAAAHDSURBVHjavJZJkoUgDEBJmAX8979tM8u3E6x20VlYJfFFMoL4vBDxATxZcakIOJTWSmxvKWVIkJ8jHvlRv1F2LFrVISCZI+tCtQx+XfewgVTfyY3plPiQEAzI3zWy+kR6NBhFBYeBuscJLOUuA2WVLpCjVIaFzrNQZArxAZKUQm6gsj37L9Cb7dnIBUKxENaaMJQqMpDXvSL+ktxdGRm2IsKgJGGPg7atwUG5CcFUEuSv+CwQqizTrvDTNXdMU2bMiDWZd8d7QIySWVRsb2vBBioxOFt4OinPBapL+neAb5KL5IJ8szOza2/DYoipUCx+CjO0Bpsv0V6mktNZ+k8rlABlWG0FrOpKYVo8DT3dBeLEjUBAj7moDogVii7nSS9QzZnFcOVBp1g2PyBQ3Vr5aIapN91VJy33HTJLC1iX2FY6F8gRdaAeIEfVONgtFCzZTmoLEdOjBDfsIOA6128gw3eu1shAajdZNAORxuQDJN5A5PbEG6gNIu24QJD5iNyRMZIr6bsHbCtCU/OaOaSvgkUyDMdDa1BXGf5HJ1To+/Ym6mCKT02Y+/Sa126ZKyd3jxhzpc1r8zVL6YM1Qy/kR4ABAFJ6iQUnivhAAAAAAElFTkSuQmCC';
  268. /* jshint +W101 */
  269. var linkMarkup =
  270. '<a href="http://bpmn.io" ' +
  271. 'target="_blank" ' +
  272. 'class="bjs-powered-by" ' +
  273. 'title="Powered by bpmn.io" ' +
  274. 'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' +
  275. '<img src="data:image/png;base64,' + logoData + '">' +
  276. '</a>';
  277. container.appendChild(domify(linkMarkup));
  278. /* </project-logo> */
  279. }
  280. Viewer.prototype.importXML = function(xml, done) {
  281. var self = this;
  282. this.moddle = this.createModdle();
  283. this.moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
  284. if (err) {
  285. err = checkValidationError(err);
  286. return done(err);
  287. }
  288. var parseWarnings = context.warnings;
  289. self.importDefinitions(definitions, function(err, importWarnings) {
  290. if (err) {
  291. return done(err);
  292. }
  293. done(null, parseWarnings.concat(importWarnings || []));
  294. });
  295. });
  296. };
  297. Viewer.prototype.saveXML = function(options, done) {
  298. if (!done) {
  299. done = options;
  300. options = {};
  301. }
  302. var definitions = this.definitions;
  303. if (!definitions) {
  304. return done(new Error('no definitions loaded'));
  305. }
  306. this.moddle.toXML(definitions, options, done);
  307. };
  308. Viewer.prototype.createModdle = function() {
  309. return new BpmnModdle(this.options.moddleExtensions);
  310. };
  311. Viewer.prototype.saveSVG = function(options, done) {
  312. if (!done) {
  313. done = options;
  314. options = {};
  315. }
  316. var canvas = this.get('canvas');
  317. var contentNode = canvas.getDefaultLayer(),
  318. defsNode = canvas._svg.select('defs');
  319. var contents = contentNode.innerSVG(),
  320. defs = (defsNode && defsNode.outerSVG()) || '';
  321. var bbox = contentNode.getBBox();
  322. var svg =
  323. '<?xml version="1.0" encoding="utf-8"?>\n' +
  324. '<!-- created with bpmn-js / http://bpmn.io -->\n' +
  325. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  326. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
  327. 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
  328. 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
  329. defs + contents +
  330. '</svg>';
  331. done(null, svg);
  332. };
  333. Viewer.prototype.get = function(name) {
  334. if (!this.diagram) {
  335. throw new Error('no diagram loaded');
  336. }
  337. return this.diagram.get(name);
  338. };
  339. Viewer.prototype.invoke = function(fn) {
  340. if (!this.diagram) {
  341. throw new Error('no diagram loaded');
  342. }
  343. return this.diagram.invoke(fn);
  344. };
  345. Viewer.prototype.importDefinitions = function(definitions, done) {
  346. // use try/catch to not swallow synchronous exceptions
  347. // that may be raised during model parsing
  348. try {
  349. if (this.diagram) {
  350. this.clear();
  351. }
  352. this.definitions = definitions;
  353. var diagram = this.diagram = this._createDiagram(this.options);
  354. this._init(diagram);
  355. Importer.importBpmnDiagram(diagram, definitions, done);
  356. } catch (e) {
  357. done(e);
  358. }
  359. };
  360. Viewer.prototype._init = function(diagram) {
  361. initListeners(diagram, this.__listeners || []);
  362. };
  363. Viewer.prototype._createDiagram = function(options) {
  364. var modules = [].concat(options.modules || this.getModules(), options.additionalModules || []);
  365. // add self as an available service
  366. modules.unshift({
  367. bpmnjs: [ 'value', this ],
  368. moddle: [ 'value', this.moddle ]
  369. });
  370. options = omit(options, 'additionalModules');
  371. options = assign(options, {
  372. canvas: { container: this.container },
  373. modules: modules
  374. });
  375. return new Diagram(options);
  376. };
  377. Viewer.prototype.getModules = function() {
  378. return this._modules;
  379. };
  380. /**
  381. * Remove all drawn elements from the viewer.
  382. *
  383. * After calling this method the viewer can still
  384. * be reused for opening another diagram.
  385. */
  386. Viewer.prototype.clear = function() {
  387. var diagram = this.diagram;
  388. if (diagram) {
  389. diagram.destroy();
  390. }
  391. };
  392. /**
  393. * Destroy the viewer instance and remove all its remainders
  394. * from the document tree.
  395. */
  396. Viewer.prototype.destroy = function() {
  397. // clear underlying diagram
  398. this.clear();
  399. // remove container
  400. domRemove(this.container);
  401. };
  402. /**
  403. * Register an event listener on the viewer
  404. *
  405. * @param {String} event
  406. * @param {Function} handler
  407. */
  408. Viewer.prototype.on = function(event, handler) {
  409. var diagram = this.diagram,
  410. listeners = this.__listeners = this.__listeners || [];
  411. listeners.push({ event: event, handler: handler });
  412. if (diagram) {
  413. diagram.get('eventBus').on(event, handler);
  414. }
  415. };
  416. // modules the viewer is composed of
  417. Viewer.prototype._modules = [
  418. _dereq_(3),
  419. _dereq_(159),
  420. _dereq_(143)
  421. ];
  422. module.exports = Viewer;
  423. },{"143":143,"159":159,"3":3,"333":333,"336":336,"339":339,"343":343,"356":356,"359":359,"360":360,"45":45,"51":51,"76":76}],3:[function(_dereq_,module,exports){
  424. module.exports = {
  425. __depends__: [
  426. _dereq_(6),
  427. _dereq_(47)
  428. ]
  429. };
  430. },{"47":47,"6":6}],4:[function(_dereq_,module,exports){
  431. 'use strict';
  432. var inherits = _dereq_(207),
  433. isArray = _dereq_(330),
  434. isObject = _dereq_(334),
  435. assign = _dereq_(339),
  436. forEach = _dereq_(218),
  437. every = _dereq_(215),
  438. includes = _dereq_(220),
  439. some = _dereq_(224);
  440. var DefaultRenderer = _dereq_(87),
  441. TextUtil = _dereq_(196),
  442. DiUtil = _dereq_(48);
  443. var createLine = DefaultRenderer.createLine;
  444. function BpmnRenderer(events, styles, pathMap) {
  445. DefaultRenderer.call(this, styles);
  446. var TASK_BORDER_RADIUS = 10;
  447. var INNER_OUTER_DIST = 3;
  448. var LABEL_STYLE = {
  449. fontFamily: 'Arial, sans-serif',
  450. fontSize: '12px'
  451. };
  452. var textUtil = new TextUtil({
  453. style: LABEL_STYLE,
  454. size: { width: 100 }
  455. });
  456. var markers = {};
  457. function addMarker(id, element) {
  458. markers[id] = element;
  459. }
  460. function marker(id) {
  461. return markers[id];
  462. }
  463. function initMarkers(svg) {
  464. function createMarker(id, options) {
  465. var attrs = assign({
  466. fill: 'black',
  467. strokeWidth: 1,
  468. strokeLinecap: 'round',
  469. strokeDasharray: 'none'
  470. }, options.attrs);
  471. var ref = options.ref || { x: 0, y: 0 };
  472. var scale = options.scale || 1;
  473. // fix for safari / chrome / firefox bug not correctly
  474. // resetting stroke dash array
  475. if (attrs.strokeDasharray === 'none') {
  476. attrs.strokeDasharray = [10000, 1];
  477. }
  478. var marker = options.element
  479. .attr(attrs)
  480. .marker(0, 0, 20, 20, ref.x, ref.y)
  481. .attr({
  482. markerWidth: 20 * scale,
  483. markerHeight: 20 * scale
  484. });
  485. return addMarker(id, marker);
  486. }
  487. createMarker('sequenceflow-end', {
  488. element: svg.path('M 1 5 L 11 10 L 1 15 Z'),
  489. ref: { x: 11, y: 10 },
  490. scale: 0.5
  491. });
  492. createMarker('messageflow-start', {
  493. element: svg.circle(6, 6, 3.5),
  494. attrs: {
  495. fill: 'white',
  496. stroke: 'black'
  497. },
  498. ref: { x: 6, y: 6 }
  499. });
  500. createMarker('messageflow-end', {
  501. element: svg.path('m 1 5 l 0 -3 l 7 3 l -7 3 z'),
  502. attrs: {
  503. fill: 'white',
  504. stroke: 'black',
  505. strokeLinecap: 'butt'
  506. },
  507. ref: { x: 8.5, y: 5 }
  508. });
  509. createMarker('data-association-end', {
  510. element: svg.path('M 1 5 L 11 10 L 1 15'),
  511. attrs: {
  512. fill: 'white',
  513. stroke: 'black'
  514. },
  515. ref: { x: 11, y: 10 },
  516. scale: 0.5
  517. });
  518. createMarker('conditional-flow-marker', {
  519. element: svg.path('M 0 10 L 8 6 L 16 10 L 8 14 Z'),
  520. attrs: {
  521. fill: 'white',
  522. stroke: 'black'
  523. },
  524. ref: { x: -1, y: 10 },
  525. scale: 0.5
  526. });
  527. createMarker('conditional-default-flow-marker', {
  528. element: svg.path('M 1 4 L 5 16'),
  529. attrs: {
  530. stroke: 'black'
  531. },
  532. ref: { x: -5, y: 10 },
  533. scale: 0.5
  534. });
  535. }
  536. function computeStyle(custom, traits, defaultStyles) {
  537. if (!isArray(traits)) {
  538. defaultStyles = traits;
  539. traits = [];
  540. }
  541. return styles.style(traits || [], assign(defaultStyles, custom || {}));
  542. }
  543. function drawCircle(p, width, height, offset, attrs) {
  544. if (isObject(offset)) {
  545. attrs = offset;
  546. offset = 0;
  547. }
  548. offset = offset || 0;
  549. attrs = computeStyle(attrs, {
  550. stroke: 'black',
  551. strokeWidth: 2,
  552. fill: 'white'
  553. });
  554. var cx = width / 2,
  555. cy = height / 2;
  556. return p.circle(cx, cy, Math.round((width + height) / 4 - offset)).attr(attrs);
  557. }
  558. function drawRect(p, width, height, r, offset, attrs) {
  559. if (isObject(offset)) {
  560. attrs = offset;
  561. offset = 0;
  562. }
  563. offset = offset || 0;
  564. attrs = computeStyle(attrs, {
  565. stroke: 'black',
  566. strokeWidth: 2,
  567. fill: 'white'
  568. });
  569. return p.rect(offset, offset, width - offset * 2, height - offset * 2, r).attr(attrs);
  570. }
  571. function drawDiamond(p, width, height, attrs) {
  572. var x_2 = width / 2;
  573. var y_2 = height / 2;
  574. var points = [x_2, 0, width, y_2, x_2, height, 0, y_2 ];
  575. attrs = computeStyle(attrs, {
  576. stroke: 'black',
  577. strokeWidth: 2,
  578. fill: 'white'
  579. });
  580. return p.polygon(points).attr(attrs);
  581. }
  582. function drawLine(p, waypoints, attrs) {
  583. attrs = computeStyle(attrs, [ 'no-fill' ], {
  584. stroke: 'black',
  585. strokeWidth: 2,
  586. fill: 'none'
  587. });
  588. return createLine(waypoints, attrs).appendTo(p);
  589. }
  590. function drawPath(p, d, attrs) {
  591. attrs = computeStyle(attrs, [ 'no-fill' ], {
  592. strokeWidth: 2,
  593. stroke: 'black'
  594. });
  595. return p.path(d).attr(attrs);
  596. }
  597. function as(type) {
  598. return function(p, element) {
  599. return handlers[type](p, element);
  600. };
  601. }
  602. function renderer(type) {
  603. return handlers[type];
  604. }
  605. function renderEventContent(element, p) {
  606. var event = getSemantic(element);
  607. var isThrowing = isThrowEvent(event);
  608. if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) {
  609. return renderer('bpmn:MessageEventDefinition')(p, element, isThrowing);
  610. }
  611. if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) {
  612. return renderer('bpmn:TimerEventDefinition')(p, element, isThrowing);
  613. }
  614. if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) {
  615. return renderer('bpmn:ConditionalEventDefinition')(p, element);
  616. }
  617. if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) {
  618. return renderer('bpmn:SignalEventDefinition')(p, element, isThrowing);
  619. }
  620. if (isTypedEvent(event, 'bpmn:CancelEventDefinition') &&
  621. isTypedEvent(event, 'bpmn:TerminateEventDefinition', { parallelMultiple: false })) {
  622. return renderer('bpmn:MultipleEventDefinition')(p, element, isThrowing);
  623. }
  624. if (isTypedEvent(event, 'bpmn:CancelEventDefinition') &&
  625. isTypedEvent(event, 'bpmn:TerminateEventDefinition', { parallelMultiple: true })) {
  626. return renderer('bpmn:ParallelMultipleEventDefinition')(p, element, isThrowing);
  627. }
  628. if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) {
  629. return renderer('bpmn:EscalationEventDefinition')(p, element, isThrowing);
  630. }
  631. if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) {
  632. return renderer('bpmn:LinkEventDefinition')(p, element, isThrowing);
  633. }
  634. if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) {
  635. return renderer('bpmn:ErrorEventDefinition')(p, element, isThrowing);
  636. }
  637. if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) {
  638. return renderer('bpmn:CancelEventDefinition')(p, element, isThrowing);
  639. }
  640. if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) {
  641. return renderer('bpmn:CompensateEventDefinition')(p, element, isThrowing);
  642. }
  643. if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) {
  644. return renderer('bpmn:TerminateEventDefinition')(p, element, isThrowing);
  645. }
  646. return null;
  647. }
  648. function renderLabel(p, label, options) {
  649. return textUtil.createText(p, label || '', options).addClass('djs-label');
  650. }
  651. function renderEmbeddedLabel(p, element, align) {
  652. var semantic = getSemantic(element);
  653. return renderLabel(p, semantic.name, { box: element, align: align, padding: 5 });
  654. }
  655. function renderExternalLabel(p, element, align) {
  656. var semantic = getSemantic(element);
  657. if (!semantic.name) {
  658. element.hidden = true;
  659. }
  660. return renderLabel(p, semantic.name, { box: element, align: align, style: { fontSize: '11px' } });
  661. }
  662. function renderLaneLabel(p, text, element) {
  663. var textBox = renderLabel(p, text, {
  664. box: { height: 30, width: element.height },
  665. align: 'center-middle'
  666. });
  667. var top = -1 * element.height;
  668. textBox.transform(
  669. 'rotate(270) ' +
  670. 'translate(' + top + ',' + 0 + ')'
  671. );
  672. }
  673. function createPathFromConnection(connection) {
  674. var waypoints = connection.waypoints;
  675. var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
  676. for (var i = 1; i < waypoints.length; i++) {
  677. pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
  678. }
  679. return pathData;
  680. }
  681. var handlers = {
  682. 'bpmn:Event': function(p, element, attrs) {
  683. return drawCircle(p, element.width, element.height, attrs);
  684. },
  685. 'bpmn:StartEvent': function(p, element) {
  686. var attrs = {};
  687. var semantic = getSemantic(element);
  688. if (!semantic.isInterrupting) {
  689. attrs = {
  690. strokeDasharray: '6',
  691. strokeLinecap: 'round'
  692. };
  693. }
  694. var circle = renderer('bpmn:Event')(p, element, attrs);
  695. renderEventContent(element, p);
  696. return circle;
  697. },
  698. 'bpmn:MessageEventDefinition': function(p, element, isThrowing) {
  699. var pathData = pathMap.getScaledPath('EVENT_MESSAGE', {
  700. xScaleFactor: 0.9,
  701. yScaleFactor: 0.9,
  702. containerWidth: element.width,
  703. containerHeight: element.height,
  704. position: {
  705. mx: 0.235,
  706. my: 0.315
  707. }
  708. });
  709. var fill = isThrowing ? 'black' : 'white';
  710. var stroke = isThrowing ? 'white' : 'black';
  711. var messagePath = drawPath(p, pathData, {
  712. strokeWidth: 1,
  713. fill: fill,
  714. stroke: stroke
  715. });
  716. return messagePath;
  717. },
  718. 'bpmn:TimerEventDefinition': function(p, element) {
  719. var circle = drawCircle(p, element.width, element.height, 0.2 * element.height, {
  720. strokeWidth: 2
  721. });
  722. var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', {
  723. xScaleFactor: 0.75,
  724. yScaleFactor: 0.75,
  725. containerWidth: element.width,
  726. containerHeight: element.height,
  727. position: {
  728. mx: 0.5,
  729. my: 0.5
  730. }
  731. });
  732. drawPath(p, pathData, {
  733. strokeWidth: 2,
  734. strokeLinecap: 'square'
  735. });
  736. for(var i = 0;i < 12;i++) {
  737. var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', {
  738. xScaleFactor: 0.75,
  739. yScaleFactor: 0.75,
  740. containerWidth: element.width,
  741. containerHeight: element.height,
  742. position: {
  743. mx: 0.5,
  744. my: 0.5
  745. }
  746. });
  747. var width = element.width / 2;
  748. var height = element.height / 2;
  749. drawPath(p, linePathData, {
  750. strokeWidth: 1,
  751. strokeLinecap: 'square',
  752. transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')'
  753. });
  754. }
  755. return circle;
  756. },
  757. 'bpmn:EscalationEventDefinition': function(p, event, isThrowing) {
  758. var pathData = pathMap.getScaledPath('EVENT_ESCALATION', {
  759. xScaleFactor: 1,
  760. yScaleFactor: 1,
  761. containerWidth: event.width,
  762. containerHeight: event.height,
  763. position: {
  764. mx: 0.5,
  765. my: 0.555
  766. }
  767. });
  768. var fill = isThrowing ? 'black' : 'none';
  769. return drawPath(p, pathData, {
  770. strokeWidth: 1,
  771. fill: fill
  772. });
  773. },
  774. 'bpmn:ConditionalEventDefinition': function(p, event) {
  775. var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', {
  776. xScaleFactor: 1,
  777. yScaleFactor: 1,
  778. containerWidth: event.width,
  779. containerHeight: event.height,
  780. position: {
  781. mx: 0.5,
  782. my: 0.222
  783. }
  784. });
  785. return drawPath(p, pathData, {
  786. strokeWidth: 1
  787. });
  788. },
  789. 'bpmn:LinkEventDefinition': function(p, event, isThrowing) {
  790. var pathData = pathMap.getScaledPath('EVENT_LINK', {
  791. xScaleFactor: 1,
  792. yScaleFactor: 1,
  793. containerWidth: event.width,
  794. containerHeight: event.height,
  795. position: {
  796. mx: 0.57,
  797. my: 0.263
  798. }
  799. });
  800. var fill = isThrowing ? 'black' : 'none';
  801. return drawPath(p, pathData, {
  802. strokeWidth: 1,
  803. fill: fill
  804. });
  805. },
  806. 'bpmn:ErrorEventDefinition': function(p, event, isThrowing) {
  807. var pathData = pathMap.getScaledPath('EVENT_ERROR', {
  808. xScaleFactor: 1.1,
  809. yScaleFactor: 1.1,
  810. containerWidth: event.width,
  811. containerHeight: event.height,
  812. position: {
  813. mx: 0.2,
  814. my: 0.722
  815. }
  816. });
  817. var fill = isThrowing ? 'black' : 'none';
  818. return drawPath(p, pathData, {
  819. strokeWidth: 1,
  820. fill: fill
  821. });
  822. },
  823. 'bpmn:CancelEventDefinition': function(p, event, isThrowing) {
  824. var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', {
  825. xScaleFactor: 1.0,
  826. yScaleFactor: 1.0,
  827. containerWidth: event.width,
  828. containerHeight: event.height,
  829. position: {
  830. mx: 0.638,
  831. my: -0.055
  832. }
  833. });
  834. var fill = isThrowing ? 'black' : 'none';
  835. return drawPath(p, pathData, {
  836. strokeWidth: 1,
  837. fill: fill
  838. }).transform('rotate(45)');
  839. },
  840. 'bpmn:CompensateEventDefinition': function(p, event, isThrowing) {
  841. var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', {
  842. xScaleFactor: 1,
  843. yScaleFactor: 1,
  844. containerWidth: event.width,
  845. containerHeight: event.height,
  846. position: {
  847. mx: 0.201,
  848. my: 0.472
  849. }
  850. });
  851. var fill = isThrowing ? 'black' : 'none';
  852. return drawPath(p, pathData, {
  853. strokeWidth: 1,
  854. fill: fill
  855. });
  856. },
  857. 'bpmn:SignalEventDefinition': function(p, event, isThrowing) {
  858. var pathData = pathMap.getScaledPath('EVENT_SIGNAL', {
  859. xScaleFactor: 0.9,
  860. yScaleFactor: 0.9,
  861. containerWidth: event.width,
  862. containerHeight: event.height,
  863. position: {
  864. mx: 0.5,
  865. my: 0.2
  866. }
  867. });
  868. var fill = isThrowing ? 'black' : 'none';
  869. return drawPath(p, pathData, {
  870. strokeWidth: 1,
  871. fill: fill
  872. });
  873. },
  874. 'bpmn:MultipleEventDefinition': function(p, event, isThrowing) {
  875. var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', {
  876. xScaleFactor: 1.1,
  877. yScaleFactor: 1.1,
  878. containerWidth: event.width,
  879. containerHeight: event.height,
  880. position: {
  881. mx: 0.222,
  882. my: 0.36
  883. }
  884. });
  885. var fill = isThrowing ? 'black' : 'none';
  886. return drawPath(p, pathData, {
  887. strokeWidth: 1,
  888. fill: fill
  889. });
  890. },
  891. 'bpmn:ParallelMultipleEventDefinition': function(p, event) {
  892. var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', {
  893. xScaleFactor: 1.2,
  894. yScaleFactor: 1.2,
  895. containerWidth: event.width,
  896. containerHeight: event.height,
  897. position: {
  898. mx: 0.458,
  899. my: 0.194
  900. }
  901. });
  902. return drawPath(p, pathData, {
  903. strokeWidth: 1
  904. });
  905. },
  906. 'bpmn:EndEvent': function(p, element) {
  907. var circle = renderer('bpmn:Event')(p, element, {
  908. strokeWidth: 4
  909. });
  910. renderEventContent(element, p, true);
  911. return circle;
  912. },
  913. 'bpmn:TerminateEventDefinition': function(p, element) {
  914. var circle = drawCircle(p, element.width, element.height, 8, {
  915. strokeWidth: 4,
  916. fill: 'black'
  917. });
  918. return circle;
  919. },
  920. 'bpmn:IntermediateEvent': function(p, element) {
  921. var outer = renderer('bpmn:Event')(p, element, { strokeWidth: 1 });
  922. /* inner */ drawCircle(p, element.width, element.height, INNER_OUTER_DIST, { strokeWidth: 1, fill: 'none' });
  923. renderEventContent(element, p);
  924. return outer;
  925. },
  926. 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
  927. 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
  928. 'bpmn:Activity': function(p, element, attrs) {
  929. return drawRect(p, element.width, element.height, TASK_BORDER_RADIUS, attrs);
  930. },
  931. 'bpmn:Task': function(p, element, attrs) {
  932. var rect = renderer('bpmn:Activity')(p, element, attrs);
  933. renderEmbeddedLabel(p, element, 'center-middle');
  934. attachTaskMarkers(p, element);
  935. return rect;
  936. },
  937. 'bpmn:ServiceTask': function(p, element) {
  938. var task = renderer('bpmn:Task')(p, element);
  939. var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
  940. abspos: {
  941. x: 12,
  942. y: 18
  943. }
  944. });
  945. /* service bg */ drawPath(p, pathDataBG, {
  946. strokeWidth: 1,
  947. fill: 'none'
  948. });
  949. var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', {
  950. abspos: {
  951. x: 17.2,
  952. y: 18
  953. }
  954. });
  955. /* service fill */ drawPath(p, fillPathData, {
  956. strokeWidth: 0,
  957. stroke: 'none',
  958. fill: 'white'
  959. });
  960. var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
  961. abspos: {
  962. x: 17,
  963. y: 22
  964. }
  965. });
  966. /* service */ drawPath(p, pathData, {
  967. strokeWidth: 1,
  968. fill: 'white'
  969. });
  970. return task;
  971. },
  972. 'bpmn:UserTask': function(p, element) {
  973. var task = renderer('bpmn:Task')(p, element);
  974. var x = 15;
  975. var y = 12;
  976. var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', {
  977. abspos: {
  978. x: x,
  979. y: y
  980. }
  981. });
  982. /* user path */ drawPath(p, pathData, {
  983. strokeWidth: 0.5,
  984. fill: 'none'
  985. });
  986. var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
  987. abspos: {
  988. x: x,
  989. y: y
  990. }
  991. });
  992. /* user2 path */ drawPath(p, pathData2, {
  993. strokeWidth: 0.5,
  994. fill: 'none'
  995. });
  996. var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
  997. abspos: {
  998. x: x,
  999. y: y
  1000. }
  1001. });
  1002. /* user3 path */ drawPath(p, pathData3, {
  1003. strokeWidth: 0.5,
  1004. fill: 'black'
  1005. });
  1006. return task;
  1007. },
  1008. 'bpmn:ManualTask': function(p, element) {
  1009. var task = renderer('bpmn:Task')(p, element);
  1010. var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', {
  1011. abspos: {
  1012. x: 17,
  1013. y: 15
  1014. }
  1015. });
  1016. /* manual path */ drawPath(p, pathData, {
  1017. strokeWidth: 0.25,
  1018. fill: 'white',
  1019. stroke: 'black'
  1020. });
  1021. return task;
  1022. },
  1023. 'bpmn:SendTask': function(p, element) {
  1024. var task = renderer('bpmn:Task')(p, element);
  1025. var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
  1026. xScaleFactor: 1,
  1027. yScaleFactor: 1,
  1028. containerWidth: 21,
  1029. containerHeight: 14,
  1030. position: {
  1031. mx: 0.285,
  1032. my: 0.357
  1033. }
  1034. });
  1035. /* send path */ drawPath(p, pathData, {
  1036. strokeWidth: 1,
  1037. fill: 'black',
  1038. stroke: 'white'
  1039. });
  1040. return task;
  1041. },
  1042. 'bpmn:ReceiveTask' : function(p, element) {
  1043. var semantic = getSemantic(element);
  1044. var task = renderer('bpmn:Task')(p, element);
  1045. var pathData;
  1046. if (semantic.instantiate) {
  1047. drawCircle(p, 28, 28, 20 * 0.22, { strokeWidth: 1 });
  1048. pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', {
  1049. abspos: {
  1050. x: 7.77,
  1051. y: 9.52
  1052. }
  1053. });
  1054. } else {
  1055. pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
  1056. xScaleFactor: 0.9,
  1057. yScaleFactor: 0.9,
  1058. containerWidth: 21,
  1059. containerHeight: 14,
  1060. position: {
  1061. mx: 0.3,
  1062. my: 0.4
  1063. }
  1064. });
  1065. }
  1066. /* receive path */ drawPath(p, pathData, {
  1067. strokeWidth: 1
  1068. });
  1069. return task;
  1070. },
  1071. 'bpmn:ScriptTask': function(p, element) {
  1072. var task = renderer('bpmn:Task')(p, element);
  1073. var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', {
  1074. abspos: {
  1075. x: 15,
  1076. y: 20
  1077. }
  1078. });
  1079. /* script path */ drawPath(p, pathData, {
  1080. strokeWidth: 1
  1081. });
  1082. return task;
  1083. },
  1084. 'bpmn:BusinessRuleTask': function(p, element) {
  1085. var task = renderer('bpmn:Task')(p, element);
  1086. var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', {
  1087. abspos: {
  1088. x: 8,
  1089. y: 8
  1090. }
  1091. });
  1092. var businessHeaderPath = drawPath(p, headerPathData);
  1093. businessHeaderPath.attr({
  1094. strokeWidth: 1,
  1095. fill: 'AAA'
  1096. });
  1097. var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', {
  1098. abspos: {
  1099. x: 8,
  1100. y: 8
  1101. }
  1102. });
  1103. var businessPath = drawPath(p, headerData);
  1104. businessPath.attr({
  1105. strokeWidth: 1
  1106. });
  1107. return task;
  1108. },
  1109. 'bpmn:SubProcess': function(p, element, attrs) {
  1110. var rect = renderer('bpmn:Activity')(p, element, attrs);
  1111. var semantic = getSemantic(element);
  1112. var expanded = DiUtil.isExpanded(semantic);
  1113. var isEventSubProcess = !!semantic.triggeredByEvent;
  1114. if (isEventSubProcess) {
  1115. rect.attr({
  1116. strokeDasharray: '1,2'
  1117. });
  1118. }
  1119. renderEmbeddedLabel(p, element, expanded ? 'center-top' : 'center-middle');
  1120. if (expanded) {
  1121. attachTaskMarkers(p, element);
  1122. } else {
  1123. attachTaskMarkers(p, element, ['SubProcessMarker']);
  1124. }
  1125. return rect;
  1126. },
  1127. 'bpmn:AdHocSubProcess': function(p, element) {
  1128. return renderer('bpmn:SubProcess')(p, element);
  1129. },
  1130. 'bpmn:Transaction': function(p, element) {
  1131. var outer = renderer('bpmn:SubProcess')(p, element);
  1132. var innerAttrs = styles.style([ 'no-fill', 'no-events' ]);
  1133. /* inner path */ drawRect(p, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs);
  1134. return outer;
  1135. },
  1136. 'bpmn:CallActivity': function(p, element) {
  1137. return renderer('bpmn:Task')(p, element, {
  1138. strokeWidth: 5
  1139. });
  1140. },
  1141. 'bpmn:Participant': function(p, element) {
  1142. var lane = renderer('bpmn:Lane')(p, element, {
  1143. fill: 'White'
  1144. });
  1145. var expandedPool = DiUtil.isExpanded(element);
  1146. if (expandedPool) {
  1147. drawLine(p, [
  1148. { x: 30, y: 0 },
  1149. { x: 30, y: element.height }
  1150. ]);
  1151. var text = getSemantic(element).name;
  1152. renderLaneLabel(p, text, element);
  1153. } else {
  1154. // Collapsed pool draw text inline
  1155. var text2 = getSemantic(element).name;
  1156. renderLabel(p, text2, { box: element, align: 'center-middle' });
  1157. }
  1158. var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
  1159. if(participantMultiplicity) {
  1160. renderer('ParticipantMultiplicityMarker')(p, element);
  1161. }
  1162. return lane;
  1163. },
  1164. 'bpmn:Lane': function(p, element, attrs) {
  1165. var rect = drawRect(p, element.width, element.height, 0, attrs || {
  1166. fill: 'none'
  1167. });
  1168. var semantic = getSemantic(element);
  1169. if (semantic.$type === 'bpmn:Lane') {
  1170. var text = semantic.name;
  1171. renderLaneLabel(p, text, element);
  1172. }
  1173. return rect;
  1174. },
  1175. 'bpmn:InclusiveGateway': function(p, element) {
  1176. var diamond = drawDiamond(p, element.width, element.height);
  1177. /* circle path */
  1178. drawCircle(p, element.width, element.height, element.height * 0.24, {
  1179. strokeWidth: 2.5,
  1180. fill: 'none'
  1181. });
  1182. return diamond;
  1183. },
  1184. 'bpmn:ExclusiveGateway': function(p, element) {
  1185. var diamond = drawDiamond(p, element.width, element.height);
  1186. var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', {
  1187. xScaleFactor: 0.4,
  1188. yScaleFactor: 0.4,
  1189. containerWidth: element.width,
  1190. containerHeight: element.height,
  1191. position: {
  1192. mx: 0.32,
  1193. my: 0.3
  1194. }
  1195. });
  1196. if (!!(getDi(element).isMarkerVisible)) {
  1197. drawPath(p, pathData, {
  1198. strokeWidth: 1,
  1199. fill: 'black'
  1200. });
  1201. }
  1202. return diamond;
  1203. },
  1204. 'bpmn:ComplexGateway': function(p, element) {
  1205. var diamond = drawDiamond(p, element.width, element.height);
  1206. var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', {
  1207. xScaleFactor: 0.5,
  1208. yScaleFactor:0.5,
  1209. containerWidth: element.width,
  1210. containerHeight: element.height,
  1211. position: {
  1212. mx: 0.46,
  1213. my: 0.26
  1214. }
  1215. });
  1216. /* complex path */ drawPath(p, pathData, {
  1217. strokeWidth: 1,
  1218. fill: 'black'
  1219. });
  1220. return diamond;
  1221. },
  1222. 'bpmn:ParallelGateway': function(p, element) {
  1223. var diamond = drawDiamond(p, element.width, element.height);
  1224. var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
  1225. xScaleFactor: 0.6,
  1226. yScaleFactor:0.6,
  1227. containerWidth: element.width,
  1228. containerHeight: element.height,
  1229. position: {
  1230. mx: 0.46,
  1231. my: 0.2
  1232. }
  1233. });
  1234. /* parallel path */ drawPath(p, pathData, {
  1235. strokeWidth: 1,
  1236. fill: 'black'
  1237. });
  1238. return diamond;
  1239. },
  1240. 'bpmn:EventBasedGateway': function(p, element) {
  1241. var semantic = getSemantic(element);
  1242. var diamond = drawDiamond(p, element.width, element.height);
  1243. /* outer circle path */ drawCircle(p, element.width, element.height, element.height * 0.20, {
  1244. strokeWidth: 1,
  1245. fill: 'none'
  1246. });
  1247. var type = semantic.eventGatewayType;
  1248. var instantiate = !!semantic.instantiate;
  1249. function drawEvent() {
  1250. var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', {
  1251. xScaleFactor: 0.18,
  1252. yScaleFactor: 0.18,
  1253. containerWidth: element.width,
  1254. containerHeight: element.height,
  1255. position: {
  1256. mx: 0.36,
  1257. my: 0.44
  1258. }
  1259. });
  1260. /* event path */ drawPath(p, pathData, {
  1261. strokeWidth: 2,
  1262. fill: 'none'
  1263. });
  1264. }
  1265. if (type === 'Parallel') {
  1266. var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
  1267. xScaleFactor: 0.4,
  1268. yScaleFactor:0.4,
  1269. containerWidth: element.width,
  1270. containerHeight: element.height,
  1271. position: {
  1272. mx: 0.474,
  1273. my: 0.296
  1274. }
  1275. });
  1276. var parallelPath = drawPath(p, pathData);
  1277. parallelPath.attr({
  1278. strokeWidth: 1,
  1279. fill: 'none'
  1280. });
  1281. } else if (type === 'Exclusive') {
  1282. if (!instantiate) {
  1283. var innerCircle = drawCircle(p, element.width, element.height, element.height * 0.26);
  1284. innerCircle.attr({
  1285. strokeWidth: 1,
  1286. fill: 'none'
  1287. });
  1288. }
  1289. drawEvent();
  1290. }
  1291. return diamond;
  1292. },
  1293. 'bpmn:Gateway': function(p, element) {
  1294. return drawDiamond(p, element.width, element.height);
  1295. },
  1296. 'bpmn:SequenceFlow': function(p, element) {
  1297. var pathData = createPathFromConnection(element);
  1298. var path = drawPath(p, pathData, {
  1299. strokeLinejoin: 'round',
  1300. markerEnd: marker('sequenceflow-end')
  1301. });
  1302. var sequenceFlow = getSemantic(element);
  1303. var source = element.source.businessObject;
  1304. // conditional flow marker
  1305. if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Task')) {
  1306. path.attr({
  1307. markerStart: marker('conditional-flow-marker')
  1308. });
  1309. }
  1310. // default marker
  1311. if (source.default && source.$instanceOf('bpmn:Gateway') && source.default === sequenceFlow) {
  1312. path.attr({
  1313. markerStart: marker('conditional-default-flow-marker')
  1314. });
  1315. }
  1316. return path;
  1317. },
  1318. 'bpmn:Association': function(p, element, attrs) {
  1319. attrs = assign({
  1320. strokeDasharray: '1,6',
  1321. strokeLinecap: 'round',
  1322. strokeLinejoin: 'round'
  1323. }, attrs || {});
  1324. // TODO(nre): style according to directed state
  1325. return drawLine(p, element.waypoints, attrs);
  1326. },
  1327. 'bpmn:DataInputAssociation': function(p, element) {
  1328. return renderer('bpmn:Association')(p, element, {
  1329. markerEnd: marker('data-association-end')
  1330. });
  1331. },
  1332. 'bpmn:DataOutputAssociation': function(p, element) {
  1333. return renderer('bpmn:Association')(p, element, {
  1334. markerEnd: marker('data-association-end')
  1335. });
  1336. },
  1337. 'bpmn:MessageFlow': function(p, element) {
  1338. var semantic = getSemantic(element),
  1339. di = getDi(element);
  1340. var pathData = createPathFromConnection(element);
  1341. var path = drawPath(p, pathData, {
  1342. markerEnd: marker('messageflow-end'),
  1343. markerStart: marker('messageflow-start'),
  1344. strokeDasharray: '10, 12',
  1345. strokeLinecap: 'round',
  1346. strokeLinejoin: 'round',
  1347. strokeWidth: '1.5px'
  1348. });
  1349. if (semantic.messageRef) {
  1350. var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
  1351. var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', {
  1352. abspos: {
  1353. x: midPoint.x,
  1354. y: midPoint.y
  1355. }
  1356. });
  1357. var messageAttrs = { strokeWidth: 1 };
  1358. if (di.messageVisibleKind === 'initiating') {
  1359. messageAttrs.fill = 'white';
  1360. messageAttrs.stroke = 'black';
  1361. } else {
  1362. messageAttrs.fill = '#888';
  1363. messageAttrs.stroke = 'white';
  1364. }
  1365. drawPath(p, markerPathData, messageAttrs);
  1366. }
  1367. return path;
  1368. },
  1369. 'bpmn:DataObject': function(p, element) {
  1370. var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', {
  1371. xScaleFactor: 1,
  1372. yScaleFactor: 1,
  1373. containerWidth: element.width,
  1374. containerHeight: element.height,
  1375. position: {
  1376. mx: 0.474,
  1377. my: 0.296
  1378. }
  1379. });
  1380. var elementObject = drawPath(p, pathData, { fill: 'white' });
  1381. var semantic = getSemantic(element);
  1382. if (isCollection(semantic)) {
  1383. renderDataItemCollection(p, element);
  1384. }
  1385. return elementObject;
  1386. },
  1387. 'bpmn:DataObjectReference': as('bpmn:DataObject'),
  1388. 'bpmn:DataInput': function(p, element) {
  1389. var arrowPathData = pathMap.getRawPath('DATA_ARROW');
  1390. // page
  1391. var elementObject = renderer('bpmn:DataObject')(p, element);
  1392. /* input arrow path */ drawPath(p, arrowPathData, { strokeWidth: 1 });
  1393. return elementObject;
  1394. },
  1395. 'bpmn:DataOutput': function(p, element) {
  1396. var arrowPathData = pathMap.getRawPath('DATA_ARROW');
  1397. // page
  1398. var elementObject = renderer('bpmn:DataObject')(p, element);
  1399. /* output arrow path */ drawPath(p, arrowPathData, {
  1400. strokeWidth: 1,
  1401. fill: 'black'
  1402. });
  1403. return elementObject;
  1404. },
  1405. 'bpmn:DataStoreReference': function(p, element) {
  1406. var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', {
  1407. xScaleFactor: 1,
  1408. yScaleFactor: 1,
  1409. containerWidth: element.width,
  1410. containerHeight: element.height,
  1411. position: {
  1412. mx: 0,
  1413. my: 0.133
  1414. }
  1415. });
  1416. var elementStore = drawPath(p, DATA_STORE_PATH, {
  1417. strokeWidth: 2,
  1418. fill: 'white'
  1419. });
  1420. return elementStore;
  1421. },
  1422. 'bpmn:BoundaryEvent': function(p, element) {
  1423. var semantic = getSemantic(element),
  1424. cancel = semantic.cancelActivity;
  1425. var attrs = {
  1426. strokeWidth: 1
  1427. };
  1428. if (!cancel) {
  1429. attrs.strokeDasharray = '6';
  1430. attrs.strokeLinecap = 'round';
  1431. }
  1432. var outer = renderer('bpmn:Event')(p, element, attrs);
  1433. /* inner path */ drawCircle(p, element.width, element.height, INNER_OUTER_DIST, assign(attrs, { fill: 'none' }));
  1434. renderEventContent(element, p);
  1435. return outer;
  1436. },
  1437. 'bpmn:Group': function(p, element) {
  1438. return drawRect(p, element.width, element.height, TASK_BORDER_RADIUS, {
  1439. strokeWidth: 1,
  1440. strokeDasharray: '8,3,1,3',
  1441. fill: 'none',
  1442. pointerEvents: 'none'
  1443. });
  1444. },
  1445. 'label': function(p, element) {
  1446. return renderExternalLabel(p, element, '');
  1447. },
  1448. 'bpmn:TextAnnotation': function(p, element) {
  1449. var style = {
  1450. 'fill': 'none',
  1451. 'stroke': 'none'
  1452. };
  1453. var textElement = drawRect(p, element.width, element.height, 0, 0, style);
  1454. var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
  1455. xScaleFactor: 1,
  1456. yScaleFactor: 1,
  1457. containerWidth: element.width,
  1458. containerHeight: element.height,
  1459. position: {
  1460. mx: 0.0,
  1461. my: 0.0
  1462. }
  1463. });
  1464. drawPath(p, textPathData);
  1465. var text = getSemantic(element).text || '';
  1466. renderLabel(p, text, { box: element, align: 'left-middle', padding: 5 });
  1467. return textElement;
  1468. },
  1469. 'ParticipantMultiplicityMarker': function(p, element) {
  1470. var subProcessPath = pathMap.getScaledPath('MARKER_PARALLEL', {
  1471. xScaleFactor: 1,
  1472. yScaleFactor: 1,
  1473. containerWidth: element.width,
  1474. containerHeight: element.height,
  1475. position: {
  1476. mx: ((element.width / 2) / element.width),
  1477. my: (element.height - 15) / element.height
  1478. }
  1479. });
  1480. drawPath(p, subProcessPath);
  1481. },
  1482. 'SubProcessMarker': function(p, element) {
  1483. var markerRect = drawRect(p, 14, 14, 0, {
  1484. strokeWidth: 1
  1485. });
  1486. // Process marker is placed in the middle of the box
  1487. // therefore fixed values can be used here
  1488. markerRect.transform('translate(' + (element.width / 2 - 7.5) + ',' + (element.height - 20) + ')');
  1489. var subProcessPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', {
  1490. xScaleFactor: 1.5,
  1491. yScaleFactor: 1.5,
  1492. containerWidth: element.width,
  1493. containerHeight: element.height,
  1494. position: {
  1495. mx: (element.width / 2 - 7.5) / element.width,
  1496. my: (element.height - 20) / element.height
  1497. }
  1498. });
  1499. drawPath(p, subProcessPath);
  1500. },
  1501. 'ParallelMarker': function(p, element, position) {
  1502. var subProcessPath = pathMap.getScaledPath('MARKER_PARALLEL', {
  1503. xScaleFactor: 1,
  1504. yScaleFactor: 1,
  1505. containerWidth: element.width,
  1506. containerHeight: element.height,
  1507. position: {
  1508. mx: ((element.width / 2 + position.parallel) / element.width),
  1509. my: (element.height - 20) / element.height
  1510. }
  1511. });
  1512. drawPath(p, subProcessPath);
  1513. },
  1514. 'SequentialMarker': function(p, element, position) {
  1515. var sequentialPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', {
  1516. xScaleFactor: 1,
  1517. yScaleFactor: 1,
  1518. containerWidth: element.width,
  1519. containerHeight: element.height,
  1520. position: {
  1521. mx: ((element.width / 2 + position.seq) / element.width),
  1522. my: (element.height - 19) / element.height
  1523. }
  1524. });
  1525. drawPath(p, sequentialPath);
  1526. },
  1527. 'CompensationMarker': function(p, element, position) {
  1528. var compensationPath = pathMap.getScaledPath('MARKER_COMPENSATION', {
  1529. xScaleFactor: 1,
  1530. yScaleFactor: 1,
  1531. containerWidth: element.width,
  1532. containerHeight: element.height,
  1533. position: {
  1534. mx: ((element.width / 2 + position.compensation) / element.width),
  1535. my: (element.height - 13) / element.height
  1536. }
  1537. });
  1538. drawPath(p, compensationPath, { strokeWidth: 1 });
  1539. },
  1540. 'LoopMarker': function(p, element, position) {
  1541. var loopPath = pathMap.getScaledPath('MARKER_LOOP', {
  1542. xScaleFactor: 1,
  1543. yScaleFactor: 1,
  1544. containerWidth: element.width,
  1545. containerHeight: element.height,
  1546. position: {
  1547. mx: ((element.width / 2 + position.loop) / element.width),
  1548. my: (element.height - 7) / element.height
  1549. }
  1550. });
  1551. drawPath(p, loopPath, {
  1552. strokeWidth: 1,
  1553. fill: 'none',
  1554. strokeLinecap: 'round',
  1555. strokeMiterlimit: 0.5
  1556. });
  1557. },
  1558. 'AdhocMarker': function(p, element, position) {
  1559. var loopPath = pathMap.getScaledPath('MARKER_ADHOC', {
  1560. xScaleFactor: 1,
  1561. yScaleFactor: 1,
  1562. containerWidth: element.width,
  1563. containerHeight: element.height,
  1564. position: {
  1565. mx: ((element.width / 2 + position.adhoc) / element.width),
  1566. my: (element.height - 15) / element.height
  1567. }
  1568. });
  1569. drawPath(p, loopPath, {
  1570. strokeWidth: 1,
  1571. fill: 'black'
  1572. });
  1573. }
  1574. };
  1575. function attachTaskMarkers(p, element, taskMarkers) {
  1576. var obj = getSemantic(element);
  1577. var subprocess = includes(taskMarkers, 'SubProcessMarker');
  1578. var position;
  1579. if (subprocess) {
  1580. position = {
  1581. seq: -21,
  1582. parallel: -22,
  1583. compensation: -42,
  1584. loop: -18,
  1585. adhoc: 10
  1586. };
  1587. } else {
  1588. position = {
  1589. seq: -3,
  1590. parallel: -6,
  1591. compensation: -27,
  1592. loop: 0,
  1593. adhoc: 10
  1594. };
  1595. }
  1596. forEach(taskMarkers, function(marker) {
  1597. renderer(marker)(p, element, position);
  1598. });
  1599. if (obj.$type === 'bpmn:AdHocSubProcess') {
  1600. renderer('AdhocMarker')(p, element, position);
  1601. }
  1602. if (obj.loopCharacteristics && obj.loopCharacteristics.isSequential === undefined) {
  1603. renderer('LoopMarker')(p, element, position);
  1604. return;
  1605. }
  1606. if (obj.loopCharacteristics &&
  1607. obj.loopCharacteristics.isSequential !== undefined &&
  1608. !obj.loopCharacteristics.isSequential) {
  1609. renderer('ParallelMarker')(p, element, position);
  1610. }
  1611. if (obj.loopCharacteristics && !!obj.loopCharacteristics.isSequential) {
  1612. renderer('SequentialMarker')(p, element, position);
  1613. }
  1614. if (!!obj.isForCompensation) {
  1615. renderer('CompensationMarker')(p, element, position);
  1616. }
  1617. }
  1618. function drawShape(parent, element) {
  1619. var type = element.type;
  1620. var h = handlers[type];
  1621. /* jshint -W040 */
  1622. if (!h) {
  1623. return DefaultRenderer.prototype.drawShape.apply(this, [ parent, element ]);
  1624. } else {
  1625. return h(parent, element);
  1626. }
  1627. }
  1628. function drawConnection(parent, element) {
  1629. var type = element.type;
  1630. var h = handlers[type];
  1631. /* jshint -W040 */
  1632. if (!h) {
  1633. return DefaultRenderer.prototype.drawConnection.apply(this, [ parent, element ]);
  1634. } else {
  1635. return h(parent, element);
  1636. }
  1637. }
  1638. function renderDataItemCollection(p, element) {
  1639. var yPosition = (element.height - 16) / element.height;
  1640. var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', {
  1641. xScaleFactor: 1,
  1642. yScaleFactor: 1,
  1643. containerWidth: element.width,
  1644. containerHeight: element.height,
  1645. position: {
  1646. mx: 0.451,
  1647. my: yPosition
  1648. }
  1649. });
  1650. /* collection path */ drawPath(p, pathData, {
  1651. strokeWidth: 2
  1652. });
  1653. }
  1654. function isCollection(element, filter) {
  1655. return element.isCollection ||
  1656. (element.elementObjectRef && element.elementObjectRef.isCollection);
  1657. }
  1658. function getDi(element) {
  1659. return element.businessObject.di;
  1660. }
  1661. function getSemantic(element) {
  1662. return element.businessObject;
  1663. }
  1664. /**
  1665. * Checks if eventDefinition of the given element matches with semantic type.
  1666. *
  1667. * @return {boolean} true if element is of the given semantic type
  1668. */
  1669. function isTypedEvent(event, eventDefinitionType, filter) {
  1670. function matches(definition, filter) {
  1671. return every(filter, function(val, key) {
  1672. // we want a == conversion here, to be able to catch
  1673. // undefined == false and friends
  1674. /* jshint -W116 */
  1675. return definition[key] == val;
  1676. });
  1677. }
  1678. return some(event.eventDefinitions, function(definition) {
  1679. return definition.$type === eventDefinitionType && matches(event, filter);
  1680. });
  1681. }
  1682. function isThrowEvent(event) {
  1683. return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
  1684. }
  1685. /////// cropping path customizations /////////////////////////
  1686. function componentsToPath(elements) {
  1687. return elements.join(',').replace(/,?([A-z]),?/g, '$1');
  1688. }
  1689. function getCirclePath(shape) {
  1690. var cx = shape.x + shape.width / 2,
  1691. cy = shape.y + shape.height / 2,
  1692. radius = shape.width / 2;
  1693. var circlePath = [
  1694. ['M', cx, cy],
  1695. ['m', 0, -radius],
  1696. ['a', radius, radius, 0, 1, 1, 0, 2 * radius],
  1697. ['a', radius, radius, 0, 1, 1, 0, -2 * radius],
  1698. ['z']
  1699. ];
  1700. return componentsToPath(circlePath);
  1701. }
  1702. function getRoundRectPath(shape) {
  1703. var radius = TASK_BORDER_RADIUS,
  1704. x = shape.x,
  1705. y = shape.y,
  1706. width = shape.width,
  1707. height = shape.height;
  1708. var roundRectPath = [
  1709. ['M', x + radius, y],
  1710. ['l', width - radius * 2, 0],
  1711. ['a', radius, radius, 0, 0, 1, radius, radius],
  1712. ['l', 0, height - radius * 2],
  1713. ['a', radius, radius, 0, 0, 1, -radius, radius],
  1714. ['l', radius * 2 - width, 0],
  1715. ['a', radius, radius, 0, 0, 1, -radius, -radius],
  1716. ['l', 0, radius * 2 - height],
  1717. ['a', radius, radius, 0, 0, 1, radius, -radius],
  1718. ['z']
  1719. ];
  1720. return componentsToPath(roundRectPath);
  1721. }
  1722. function getDiamondPath(shape) {
  1723. var width = shape.width,
  1724. height = shape.height,
  1725. x = shape.x,
  1726. y = shape.y,
  1727. halfWidth = width / 2,
  1728. halfHeight = height / 2;
  1729. var diamondPath = [
  1730. ['M', x + halfWidth, y],
  1731. ['l', halfWidth, halfHeight],
  1732. ['l', -halfWidth, halfHeight],
  1733. ['l', -halfWidth, -halfHeight],
  1734. ['z']
  1735. ];
  1736. return componentsToPath(diamondPath);
  1737. }
  1738. function getRectPath(shape) {
  1739. var x = shape.x,
  1740. y = shape.y,
  1741. width = shape.width,
  1742. height = shape.height;
  1743. var rectPath = [
  1744. ['M', x, y],
  1745. ['l', width, 0],
  1746. ['l', 0, height],
  1747. ['l', -width, 0],
  1748. ['z']
  1749. ];
  1750. return componentsToPath(rectPath);
  1751. }
  1752. function getShapePath(element) {
  1753. var obj = getSemantic(element);
  1754. if (obj.$instanceOf('bpmn:Event')) {
  1755. return getCirclePath(element);
  1756. }
  1757. if (obj.$instanceOf('bpmn:Activity')) {
  1758. return getRoundRectPath(element);
  1759. }
  1760. if (obj.$instanceOf('bpmn:Gateway')) {
  1761. return getDiamondPath(element);
  1762. }
  1763. return getRectPath(element);
  1764. }
  1765. // hook onto canvas init event to initialize
  1766. // connection start/end markers on svg
  1767. events.on('canvas.init', function(event) {
  1768. initMarkers(event.svg);
  1769. });
  1770. this.drawShape = drawShape;
  1771. this.drawConnection = drawConnection;
  1772. this.getShapePath = getShapePath;
  1773. }
  1774. inherits(BpmnRenderer, DefaultRenderer);
  1775. BpmnRenderer.$inject = [ 'eventBus', 'styles', 'pathMap' ];
  1776. module.exports = BpmnRenderer;
  1777. },{"196":196,"207":207,"215":215,"218":218,"220":220,"224":224,"330":330,"334":334,"339":339,"48":48,"87":87}],5:[function(_dereq_,module,exports){
  1778. 'use strict';
  1779. var Snap = _dereq_(200);
  1780. /**
  1781. * Map containing SVG paths needed by BpmnRenderer.
  1782. */
  1783. function PathMap() {
  1784. /**
  1785. * Contains a map of path elements
  1786. *
  1787. * <h1>Path definition</h1>
  1788. * A parameterized path is defined like this:
  1789. * <pre>
  1790. * 'GATEWAY_PARALLEL': {
  1791. * d: 'm {mx},{my} {e.x0},0 0,{e.x1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
  1792. '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
  1793. * height: 17.5,
  1794. * width: 17.5,
  1795. * heightElements: [2.5, 7.5],
  1796. * widthElements: [2.5, 7.5]
  1797. * }
  1798. * </pre>
  1799. * <p>It's important to specify a correct <b>height and width</b> for the path as the scaling
  1800. * is based on the ratio between the specified height and width in this object and the
  1801. * height and width that is set as scale target (Note x,y coordinates will be scaled with
  1802. * individual ratios).</p>
  1803. * <p>The '<b>heightElements</b>' and '<b>widthElements</b>' array must contain the values that will be scaled.
  1804. * The scaling is based on the computed ratios.
  1805. * Coordinates on the y axis should be in the <b>heightElement</b>'s array, they will be scaled using
  1806. * the computed ratio coefficient.
  1807. * In the parameterized path the scaled values can be accessed through the 'e' object in {} brackets.
  1808. * <ul>
  1809. * <li>The values for the y axis can be accessed in the path string using {e.y0}, {e.y1}, ....</li>
  1810. * <li>The values for the x axis can be accessed in the path string using {e.x0}, {e.x1}, ....</li>
  1811. * </ul>
  1812. * The numbers x0, x1 respectively y0, y1, ... map to the corresponding array index.
  1813. * </p>
  1814. */
  1815. this.pathMap = {
  1816. 'EVENT_MESSAGE': {
  1817. 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}',
  1818. height: 36,
  1819. width: 36,
  1820. heightElements: [6, 14],
  1821. widthElements: [10.5, 21]
  1822. },
  1823. 'EVENT_SIGNAL': {
  1824. d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z',
  1825. height: 36,
  1826. width: 36,
  1827. heightElements: [18],
  1828. widthElements: [10, 20]
  1829. },
  1830. 'EVENT_ESCALATION': {
  1831. d: 'm {mx},{my} c -{e.x1},{e.y0} -{e.x3},{e.y1} -{e.x5},{e.y4} {e.x1},-{e.y3} {e.x3},-{e.y5} {e.x5},-{e.y6} ' +
  1832. '{e.x0},{e.y3} {e.x2},{e.y5} {e.x4},{e.y6} -{e.x0},-{e.y0} -{e.x2},-{e.y1} -{e.x4},-{e.y4} z',
  1833. height: 36,
  1834. width: 36,
  1835. heightElements: [2.382, 4.764, 4.926, 6.589333, 7.146, 13.178667, 19.768],
  1836. widthElements: [2.463, 2.808, 4.926, 5.616, 7.389, 8.424]
  1837. },
  1838. 'EVENT_CONDITIONAL': {
  1839. d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' +
  1840. 'M {e.x2},{e.y3} l {e.x0},0 ' +
  1841. 'M {e.x2},{e.y4} l {e.x0},0 ' +
  1842. 'M {e.x2},{e.y5} l {e.x0},0 ' +
  1843. 'M {e.x2},{e.y6} l {e.x0},0 ' +
  1844. 'M {e.x2},{e.y7} l {e.x0},0 ' +
  1845. 'M {e.x2},{e.y8} l {e.x0},0 ',
  1846. height: 36,
  1847. width: 36,
  1848. heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5],
  1849. widthElements: [10.5, 14.5, 12.5]
  1850. },
  1851. 'EVENT_LINK': {
  1852. 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',
  1853. height: 36,
  1854. width: 36,
  1855. heightElements: [4.4375, 6.75, 7.8125],
  1856. widthElements: [9.84375, 13.5]
  1857. },
  1858. 'EVENT_ERROR': {
  1859. 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',
  1860. height: 36,
  1861. width: 36,
  1862. heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714],
  1863. widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636]
  1864. },
  1865. 'EVENT_CANCEL_45': {
  1866. d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
  1867. '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
  1868. height: 36,
  1869. width: 36,
  1870. heightElements: [4.75, 8.5],
  1871. widthElements: [4.75, 8.5]
  1872. },
  1873. 'EVENT_COMPENSATION': {
  1874. d: 'm {mx},{my} {e.x0},-{e.y0} 0,{e.y1} z m {e.x0},0 {e.x0},-{e.y0} 0,{e.y1} z',
  1875. height: 36,
  1876. width: 36,
  1877. heightElements: [5, 10],
  1878. widthElements: [10]
  1879. },
  1880. 'EVENT_TIMER_WH': {
  1881. d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ',
  1882. height: 36,
  1883. width: 36,
  1884. heightElements: [10, 2],
  1885. widthElements: [3, 7]
  1886. },
  1887. 'EVENT_TIMER_LINE': {
  1888. d: 'M {mx},{my} ' +
  1889. 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ',
  1890. height: 36,
  1891. width: 36,
  1892. heightElements: [10, 3],
  1893. widthElements: [0, 0]
  1894. },
  1895. 'EVENT_MULTIPLE': {
  1896. d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z',
  1897. height: 36,
  1898. width: 36,
  1899. heightElements: [6.28099, 12.56199],
  1900. widthElements: [3.1405, 9.42149, 12.56198]
  1901. },
  1902. 'EVENT_PARALLEL_MULTIPLE': {
  1903. d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
  1904. '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
  1905. height: 36,
  1906. width: 36,
  1907. heightElements: [2.56228, 7.68683],
  1908. widthElements: [2.56228, 7.68683]
  1909. },
  1910. 'GATEWAY_EXCLUSIVE': {
  1911. d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' +
  1912. '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' +
  1913. '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z',
  1914. height: 17.5,
  1915. width: 17.5,
  1916. heightElements: [8.5, 6.5312, -6.5312, -8.5],
  1917. widthElements: [6.5, -6.5, 3, -3, 5, -5]
  1918. },
  1919. 'GATEWAY_PARALLEL': {
  1920. d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
  1921. '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
  1922. height: 30,
  1923. width: 30,
  1924. heightElements: [5, 12.5],
  1925. widthElements: [5, 12.5]
  1926. },
  1927. 'GATEWAY_EVENT_BASED': {
  1928. d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z',
  1929. height: 11,
  1930. width: 11,
  1931. heightElements: [-6, 6, 12, -12],
  1932. widthElements: [9, -3, -12]
  1933. },
  1934. 'GATEWAY_COMPLEX': {
  1935. 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} ' +
  1936. '{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} ' +
  1937. '{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} ' +
  1938. '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z',
  1939. height: 17.125,
  1940. width: 17.125,
  1941. heightElements: [4.875, 3.4375, 2.125, 3],
  1942. widthElements: [3.4375, 2.125, 4.875, 3]
  1943. },
  1944. 'DATA_OBJECT_PATH': {
  1945. 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',
  1946. height: 61,
  1947. width: 51,
  1948. heightElements: [10, 50, 60],
  1949. widthElements: [10, 40, 50, 60]
  1950. },
  1951. 'DATA_OBJECT_COLLECTION_PATH': {
  1952. d:'m {mx}, {my} ' +
  1953. 'm 0 15 l 0 -15 ' +
  1954. 'm 4 15 l 0 -15 ' +
  1955. 'm 4 15 l 0 -15 ',
  1956. height: 61,
  1957. width: 51,
  1958. heightElements: [12],
  1959. widthElements: [1, 6, 12, 15]
  1960. },
  1961. 'DATA_ARROW': {
  1962. d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z',
  1963. height: 61,
  1964. width: 51,
  1965. heightElements: [],
  1966. widthElements: []
  1967. },
  1968. 'DATA_STORE': {
  1969. d:'m {mx},{my} ' +
  1970. 'l 0,{e.y2} ' +
  1971. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
  1972. 'l 0,-{e.y2} ' +
  1973. 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' +
  1974. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
  1975. 'm -{e.x2},{e.y0}' +
  1976. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' +
  1977. 'm -{e.x2},{e.y0}' +
  1978. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0',
  1979. height: 61,
  1980. width: 61,
  1981. heightElements: [7, 10, 45],
  1982. widthElements: [2, 58, 60]
  1983. },
  1984. 'TEXT_ANNOTATION': {
  1985. d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0',
  1986. height: 30,
  1987. width: 10,
  1988. heightElements: [30],
  1989. widthElements: [10]
  1990. },
  1991. 'MARKER_SUB_PROCESS': {
  1992. d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0',
  1993. height: 10,
  1994. width: 10,
  1995. heightElements: [],
  1996. widthElements: []
  1997. },
  1998. 'MARKER_PARALLEL': {
  1999. d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
  2000. height: 10,
  2001. width: 10,
  2002. heightElements: [],
  2003. widthElements: []
  2004. },
  2005. 'MARKER_SEQUENTIAL': {
  2006. d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0',
  2007. height: 10,
  2008. width: 10,
  2009. heightElements: [],
  2010. widthElements: []
  2011. },
  2012. 'MARKER_COMPENSATION': {
  2013. d: 'm {mx},{my} 8,-5 0,10 z m 9,0 8,-5 0,10 z',
  2014. height: 10,
  2015. width: 21,
  2016. heightElements: [],
  2017. widthElements: []
  2018. },
  2019. 'MARKER_LOOP': {
  2020. d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' +
  2021. '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' +
  2022. '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' +
  2023. 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902',
  2024. height: 13.9,
  2025. width: 13.7,
  2026. heightElements: [],
  2027. widthElements: []
  2028. },
  2029. 'MARKER_ADHOC': {
  2030. 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 ' +
  2031. '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' +
  2032. '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 ' +
  2033. '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' +
  2034. '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z',
  2035. height: 4,
  2036. width: 15,
  2037. heightElements: [],
  2038. widthElements: []
  2039. },
  2040. 'TASK_TYPE_SEND': {
  2041. 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}',
  2042. height: 14,
  2043. width: 21,
  2044. heightElements: [6, 14],
  2045. widthElements: [10.5, 21]
  2046. },
  2047. 'TASK_TYPE_SCRIPT': {
  2048. d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' +
  2049. 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' +
  2050. 'm -7,-12 l 5,0 ' +
  2051. 'm -4.5,3 l 4.5,0 ' +
  2052. 'm -3,3 l 5,0' +
  2053. 'm -4,3 l 5,0',
  2054. height: 15,
  2055. width: 12.6,
  2056. heightElements: [6, 14],
  2057. widthElements: [10.5, 21]
  2058. },
  2059. 'TASK_TYPE_USER_1': {
  2060. d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' +
  2061. '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' +
  2062. '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' +
  2063. 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' +
  2064. 'm -8,6 l 0,5.5 m 11,0 l 0,-5'
  2065. },
  2066. 'TASK_TYPE_USER_2': {
  2067. d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' +
  2068. '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 '
  2069. },
  2070. 'TASK_TYPE_USER_3': {
  2071. 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 ' +
  2072. '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' +
  2073. '-4.20799998,3.36699999 -4.20699998,4.34799999 z'
  2074. },
  2075. 'TASK_TYPE_MANUAL': {
  2076. 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 ' +
  2077. '-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 ' +
  2078. '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 ' +
  2079. '-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 ' +
  2080. '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 ' +
  2081. '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' +
  2082. '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' +
  2083. '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' +
  2084. '-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 ' +
  2085. '-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 ' +
  2086. '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 ' +
  2087. '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z'
  2088. },
  2089. 'TASK_TYPE_INSTANTIATING_SEND': {
  2090. 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'
  2091. },
  2092. 'TASK_TYPE_SERVICE': {
  2093. d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' +
  2094. '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' +
  2095. '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' +
  2096. 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' +
  2097. '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' +
  2098. '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' +
  2099. '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 ' +
  2100. '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' +
  2101. 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' +
  2102. 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' +
  2103. '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' +
  2104. 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' +
  2105. 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
  2106. '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
  2107. '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
  2108. },
  2109. 'TASK_TYPE_SERVICE_FILL': {
  2110. d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
  2111. '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
  2112. '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
  2113. },
  2114. 'TASK_TYPE_BUSINESS_RULE_HEADER': {
  2115. d: 'm {mx},{my} 0,4 20,0 0,-4 z'
  2116. },
  2117. 'TASK_TYPE_BUSINESS_RULE_MAIN': {
  2118. d: 'm {mx},{my} 0,12 20,0 0,-12 z' +
  2119. 'm 0,8 l 20,0 ' +
  2120. 'm -13,-4 l 0,8'
  2121. },
  2122. 'MESSAGE_FLOW_MARKER': {
  2123. 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'
  2124. }
  2125. };
  2126. this.getRawPath = function getRawPath(pathId) {
  2127. return this.pathMap[pathId].d;
  2128. };
  2129. /**
  2130. * Scales the path to the given height and width.
  2131. * <h1>Use case</h1>
  2132. * <p>Use case is to scale the content of elements (event, gateways) based
  2133. * on the element bounding box's size.
  2134. * </p>
  2135. * <h1>Why not transform</h1>
  2136. * <p>Scaling a path with transform() will also scale the stroke and IE does not support
  2137. * the option 'non-scaling-stroke' to prevent this.
  2138. * Also there are use cases where only some parts of a path should be
  2139. * scaled.</p>
  2140. *
  2141. * @param {String} pathId The ID of the path.
  2142. * @param {Object} param <p>
  2143. * Example param object scales the path to 60% size of the container (data.width, data.height).
  2144. * <pre>
  2145. * {
  2146. * xScaleFactor: 0.6,
  2147. * yScaleFactor:0.6,
  2148. * containerWidth: data.width,
  2149. * containerHeight: data.height,
  2150. * position: {
  2151. * mx: 0.46,
  2152. * my: 0.2,
  2153. * }
  2154. * }
  2155. * </pre>
  2156. * <ul>
  2157. * <li>targetpathwidth = xScaleFactor * containerWidth</li>
  2158. * <li>targetpathheight = yScaleFactor * containerHeight</li>
  2159. * <li>Position is used to set the starting coordinate of the path. M is computed:
  2160. * <ul>
  2161. * <li>position.x * containerWidth</li>
  2162. * <li>position.y * containerHeight</li>
  2163. * </ul>
  2164. * Center of the container <pre> position: {
  2165. * mx: 0.5,
  2166. * my: 0.5,
  2167. * }</pre>
  2168. * Upper left corner of the container
  2169. * <pre> position: {
  2170. * mx: 0.0,
  2171. * my: 0.0,
  2172. * }</pre>
  2173. * </li>
  2174. * </ul>
  2175. * </p>
  2176. *
  2177. */
  2178. this.getScaledPath = function getScaledPath(pathId, param) {
  2179. var rawPath = this.pathMap[pathId];
  2180. // positioning
  2181. // compute the start point of the path
  2182. var mx, my;
  2183. if(!!param.abspos) {
  2184. mx = param.abspos.x;
  2185. my = param.abspos.y;
  2186. } else {
  2187. mx = param.containerWidth * param.position.mx;
  2188. my = param.containerHeight * param.position.my;
  2189. }
  2190. var coordinates = {}; //map for the scaled coordinates
  2191. if(param.position) {
  2192. // path
  2193. var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor;
  2194. var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor;
  2195. //Apply height ratio
  2196. for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) {
  2197. coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio;
  2198. }
  2199. //Apply width ratio
  2200. for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) {
  2201. coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio;
  2202. }
  2203. }
  2204. //Apply value to raw path
  2205. var path = Snap.format(
  2206. rawPath.d, {
  2207. mx: mx,
  2208. my: my,
  2209. e: coordinates
  2210. }
  2211. );
  2212. return path;
  2213. };
  2214. }
  2215. module.exports = PathMap;
  2216. },{"200":200}],6:[function(_dereq_,module,exports){
  2217. module.exports = {
  2218. renderer: [ 'type', _dereq_(4) ],
  2219. pathMap: [ 'type', _dereq_(5) ]
  2220. };
  2221. },{"4":4,"5":5}],7:[function(_dereq_,module,exports){
  2222. 'use strict';
  2223. var assign = _dereq_(339),
  2224. forEach = _dereq_(218),
  2225. is = _dereq_(50).is;
  2226. /**
  2227. * A provider for BPMN 2.0 elements context pad
  2228. */
  2229. function ContextPadProvider(contextPad, modeling, elementFactory,
  2230. connect, create, bpmnReplace,
  2231. canvas) {
  2232. contextPad.registerProvider(this);
  2233. this._contextPad = contextPad;
  2234. this._modeling = modeling;
  2235. this._elementFactory = elementFactory;
  2236. this._connect = connect;
  2237. this._create = create;
  2238. this._bpmnReplace = bpmnReplace;
  2239. this._canvas = canvas;
  2240. }
  2241. ContextPadProvider.$inject = [
  2242. 'contextPad',
  2243. 'modeling',
  2244. 'elementFactory',
  2245. 'connect',
  2246. 'create',
  2247. 'bpmnReplace',
  2248. 'canvas'
  2249. ];
  2250. ContextPadProvider.prototype.getContextPadEntries = function(element) {
  2251. var contextPad = this._contextPad,
  2252. modeling = this._modeling,
  2253. elementFactory = this._elementFactory,
  2254. connect = this._connect,
  2255. create = this._create,
  2256. bpmnReplace = this._bpmnReplace,
  2257. canvas = this._canvas;
  2258. var actions = {};
  2259. if (element.type === 'label') {
  2260. return actions;
  2261. }
  2262. var bpmnElement = element.businessObject;
  2263. function startConnect(event, element, autoActivate) {
  2264. connect.start(event, element, autoActivate);
  2265. }
  2266. function removeElement(e) {
  2267. if (element.waypoints) {
  2268. modeling.removeConnection(element);
  2269. } else {
  2270. modeling.removeShape(element);
  2271. }
  2272. }
  2273. function getReplaceMenuPosition(element) {
  2274. var Y_OFFSET = 5;
  2275. var diagramContainer = canvas.getContainer(),
  2276. pad = contextPad.getPad(element).html;
  2277. var diagramRect = diagramContainer.getBoundingClientRect(),
  2278. padRect = pad.getBoundingClientRect();
  2279. var top = padRect.top - diagramRect.top;
  2280. var left = padRect.left - diagramRect.left;
  2281. var pos = {
  2282. x: left,
  2283. y: top + padRect.height + Y_OFFSET
  2284. };
  2285. return pos;
  2286. }
  2287. function appendAction(type, className, options) {
  2288. function appendListener(event, element) {
  2289. var shape = elementFactory.createShape(assign({ type: type }, options));
  2290. create.start(event, shape, element);
  2291. }
  2292. var shortType = type.replace(/^bpmn\:/, '');
  2293. return {
  2294. group: 'model',
  2295. className: className,
  2296. title: 'Append ' + shortType,
  2297. action: {
  2298. dragstart: appendListener,
  2299. click: appendListener
  2300. }
  2301. };
  2302. }
  2303. if (is(bpmnElement, 'bpmn:FlowNode')) {
  2304. if (!is(bpmnElement, 'bpmn:EndEvent') &&
  2305. !is(bpmnElement, 'bpmn:EventBasedGateway') &&
  2306. !isEventType(bpmnElement, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition')) {
  2307. assign(actions, {
  2308. 'append.end-event': appendAction('bpmn:EndEvent', 'icon-end-event-none'),
  2309. 'append.gateway': appendAction('bpmn:ExclusiveGateway', 'icon-gateway-xor'),
  2310. 'append.append-task': appendAction('bpmn:Task', 'icon-task'),
  2311. 'append.intermediate-event': appendAction('bpmn:IntermediateThrowEvent',
  2312. 'icon-intermediate-event-none')
  2313. });
  2314. }
  2315. if (is(bpmnElement, 'bpmn:EventBasedGateway')) {
  2316. assign(actions, {
  2317. 'append.receive-task': appendAction('bpmn:ReceiveTask', 'icon-receive-task'),
  2318. 'append.message-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
  2319. 'icon-intermediate-event-catch-message',
  2320. { _eventDefinitionType: 'bpmn:MessageEventDefinition'}),
  2321. 'append.timer-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
  2322. 'icon-intermediate-event-catch-timer',
  2323. { _eventDefinitionType: 'bpmn:TimerEventDefinition'}),
  2324. 'append.condtion-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
  2325. 'icon-intermediate-event-catch-condition',
  2326. { _eventDefinitionType: 'bpmn:ConditionalEventDefinition'}),
  2327. 'append.signal-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
  2328. 'icon-intermediate-event-catch-signal',
  2329. { _eventDefinitionType: 'bpmn:SignalEventDefinition'})
  2330. });
  2331. }
  2332. // Replace menu entry
  2333. assign(actions, {
  2334. 'replace': {
  2335. group: 'edit',
  2336. className: 'icon-screw-wrench',
  2337. title: 'Change type',
  2338. action: {
  2339. click: function(event, element) {
  2340. bpmnReplace.openChooser(getReplaceMenuPosition(element), element);
  2341. }
  2342. }
  2343. }
  2344. });
  2345. }
  2346. if (is(bpmnElement, 'bpmn:FlowNode') ||
  2347. is(bpmnElement, 'bpmn:InteractionNode')) {
  2348. assign(actions, {
  2349. 'append.text-annotation': appendAction('bpmn:TextAnnotation', 'icon-text-annotation'),
  2350. 'connect': {
  2351. group: 'connect',
  2352. className: 'icon-connection-multi',
  2353. title: 'Connect using Sequence/MessageFlow',
  2354. action: {
  2355. click: startConnect,
  2356. dragstart: startConnect
  2357. }
  2358. }
  2359. });
  2360. }
  2361. // Delete Element Entry
  2362. assign(actions, {
  2363. 'delete': {
  2364. group: 'edit',
  2365. className: 'icon-trash',
  2366. title: 'Remove',
  2367. action: {
  2368. click: removeElement,
  2369. dragstart: removeElement
  2370. }
  2371. }
  2372. });
  2373. return actions;
  2374. };
  2375. function isEventType(eventBo, type, definition) {
  2376. var isType = eventBo.$instanceOf(type);
  2377. var isDefinition = false;
  2378. var definitions = eventBo.eventDefinitions || [];
  2379. forEach(definitions, function(def) {
  2380. if (def.$type === definition) {
  2381. isDefinition = true;
  2382. }
  2383. });
  2384. return isType && isDefinition;
  2385. }
  2386. module.exports = ContextPadProvider;
  2387. },{"218":218,"339":339,"50":50}],8:[function(_dereq_,module,exports){
  2388. module.exports = {
  2389. __depends__: [
  2390. _dereq_(73),
  2391. _dereq_(102),
  2392. _dereq_(159),
  2393. _dereq_(100),
  2394. _dereq_(104),
  2395. _dereq_(39)
  2396. ],
  2397. __init__: [ 'contextPadProvider' ],
  2398. contextPadProvider: [ 'type', _dereq_(7) ]
  2399. };
  2400. },{"100":100,"102":102,"104":104,"159":159,"39":39,"7":7,"73":73}],9:[function(_dereq_,module,exports){
  2401. 'use strict';
  2402. function BpmnKeyBindings(
  2403. keyboard, spaceTool, lassoTool,
  2404. directEditing, selection, canvas,
  2405. elementRegistry) {
  2406. keyboard.addListener(function(key, modifiers) {
  2407. // ctrl + a -> select all elements
  2408. if (key === 65 && keyboard.isCmd(modifiers)) {
  2409. // select all elements except for the invisible
  2410. // root element
  2411. var rootElement = canvas.getRootElement();
  2412. var elements = elementRegistry.filter(function(element) {
  2413. return element != rootElement;
  2414. });
  2415. selection.select(elements);
  2416. return true;
  2417. }
  2418. if (keyboard.hasModifier(modifiers)) {
  2419. return;
  2420. }
  2421. // s -> activate space tool
  2422. if (key === 83) {
  2423. spaceTool.activateSelection();
  2424. return true;
  2425. }
  2426. // l -> activate lasso tool
  2427. if (key === 76) {
  2428. lassoTool.activateSelection();
  2429. return true;
  2430. }
  2431. var currentSelection = selection.get();
  2432. // e -> activate direct editing
  2433. if (key === 69) {
  2434. if (currentSelection.length) {
  2435. directEditing.activate(currentSelection[0]);
  2436. }
  2437. return true;
  2438. }
  2439. });
  2440. }
  2441. BpmnKeyBindings.$inject = [
  2442. 'keyboard',
  2443. 'spaceTool',
  2444. 'lassoTool',
  2445. 'directEditing',
  2446. 'selection',
  2447. 'canvas',
  2448. 'elementRegistry'
  2449. ];
  2450. module.exports = BpmnKeyBindings;
  2451. },{}],10:[function(_dereq_,module,exports){
  2452. module.exports = {
  2453. __depends__: [
  2454. _dereq_(110)
  2455. ],
  2456. __init__: [ 'bpmnKeyBindings' ],
  2457. bpmnKeyBindings: [ 'type', _dereq_(9) ]
  2458. };
  2459. },{"110":110,"9":9}],11:[function(_dereq_,module,exports){
  2460. 'use strict';
  2461. var UpdateLabelHandler = _dereq_(13);
  2462. var LabelUtil = _dereq_(12);
  2463. var is = _dereq_(50).is,
  2464. isExpanded = _dereq_(48).isExpanded;
  2465. var MIN_BOUNDS = {
  2466. width: 150,
  2467. height: 50
  2468. };
  2469. function LabelEditingProvider(eventBus, canvas, directEditing, commandStack, injector) {
  2470. directEditing.registerProvider(this);
  2471. commandStack.registerHandler('element.updateLabel', UpdateLabelHandler);
  2472. // listen to dblclick on non-root elements
  2473. eventBus.on('element.dblclick', function(event) {
  2474. directEditing.activate(event.element);
  2475. });
  2476. // complete on followup canvas operation
  2477. eventBus.on([ 'element.mousedown', 'drag.activate', 'canvas.viewbox.changed' ], function(event) {
  2478. directEditing.complete();
  2479. });
  2480. // cancel on command stack changes
  2481. eventBus.on([ 'commandStack.changed' ], function() {
  2482. directEditing.cancel();
  2483. });
  2484. // activate direct editing for activities and text annotations
  2485. if ('ontouchstart' in document.documentElement) {
  2486. // we deactivate automatic label editing on mobile devices
  2487. // as it breaks the user interaction workflow
  2488. // TODO(nre): we should temporarily focus the edited element here
  2489. // and release the focused viewport after the direct edit operation is finished
  2490. } else {
  2491. eventBus.on('create.end', 500, function(e) {
  2492. var element = e.shape,
  2493. canExecute = e.context.canExecute;
  2494. if (!canExecute) {
  2495. return;
  2496. }
  2497. if (is(element, 'bpmn:Task') || is(element, 'bpmn:TextAnnotation') ||
  2498. (is(element, 'bpmn:SubProcess') && !isExpanded(element))) {
  2499. directEditing.activate(element);
  2500. }
  2501. });
  2502. }
  2503. this._canvas = canvas;
  2504. this._commandStack = commandStack;
  2505. }
  2506. LabelEditingProvider.$inject = [ 'eventBus', 'canvas', 'directEditing', 'commandStack', 'injector' ];
  2507. module.exports = LabelEditingProvider;
  2508. LabelEditingProvider.prototype.activate = function(element) {
  2509. var text = LabelUtil.getLabel(element);
  2510. if (text === undefined) {
  2511. return;
  2512. }
  2513. var bbox = this.getEditingBBox(element);
  2514. // adjust for expanded pools AND lanes
  2515. if ((is(element, 'bpmn:Participant') && isExpanded(element)) || is(element, 'bpmn:Lane')) {
  2516. bbox.width = MIN_BOUNDS.width;
  2517. bbox.height = MIN_BOUNDS.height;
  2518. bbox.x = bbox.x + 10 - bbox.width / 2;
  2519. bbox.y = bbox.mid.y - bbox.height / 2;
  2520. }
  2521. // adjust for expanded sub processes
  2522. if (is(element, 'bpmn:SubProcess') && isExpanded(element)) {
  2523. bbox.height = MIN_BOUNDS.height;
  2524. bbox.x = bbox.mid.x - bbox.width / 2;
  2525. bbox.y = bbox.y + 10 - bbox.height / 2;
  2526. }
  2527. return { bounds: bbox, text: text };
  2528. };
  2529. LabelEditingProvider.prototype.getEditingBBox = function(element, maxBounds) {
  2530. var target = element.label || element;
  2531. var bbox = this._canvas.getAbsoluteBBox(target);
  2532. var mid = {
  2533. x: bbox.x + bbox.width / 2,
  2534. y: bbox.y + bbox.height / 2
  2535. };
  2536. // external label
  2537. if (target.labelTarget) {
  2538. bbox.width = Math.max(bbox.width, MIN_BOUNDS.width);
  2539. bbox.height = Math.max(bbox.height, MIN_BOUNDS.height);
  2540. bbox.x = mid.x - bbox.width / 2;
  2541. }
  2542. bbox.mid = mid;
  2543. return bbox;
  2544. };
  2545. LabelEditingProvider.prototype.update = function(element, newLabel) {
  2546. this._commandStack.execute('element.updateLabel', {
  2547. element: element,
  2548. newLabel: newLabel
  2549. });
  2550. };
  2551. },{"12":12,"13":13,"48":48,"50":50}],12:[function(_dereq_,module,exports){
  2552. 'use strict';
  2553. function getLabelAttr(semantic) {
  2554. if (semantic.$instanceOf('bpmn:FlowElement') ||
  2555. semantic.$instanceOf('bpmn:Participant') ||
  2556. semantic.$instanceOf('bpmn:Lane') ||
  2557. semantic.$instanceOf('bpmn:SequenceFlow') ||
  2558. semantic.$instanceOf('bpmn:MessageFlow')) {
  2559. return 'name';
  2560. }
  2561. if (semantic.$instanceOf('bpmn:TextAnnotation')) {
  2562. return 'text';
  2563. }
  2564. }
  2565. module.exports.getLabel = function(element) {
  2566. var semantic = element.businessObject,
  2567. attr = getLabelAttr(semantic);
  2568. if (attr) {
  2569. return semantic[attr] || '';
  2570. }
  2571. };
  2572. module.exports.setLabel = function(element, text) {
  2573. var semantic = element.businessObject,
  2574. attr = getLabelAttr(semantic);
  2575. if (attr) {
  2576. semantic[attr] = text;
  2577. }
  2578. var label = element.label || element;
  2579. // show label
  2580. label.hidden = false;
  2581. return label;
  2582. };
  2583. },{}],13:[function(_dereq_,module,exports){
  2584. 'use strict';
  2585. var LabelUtil = _dereq_(12);
  2586. /**
  2587. * A handler that updates the text of a BPMN element.
  2588. *
  2589. * @param {EventBus} eventBus
  2590. */
  2591. function UpdateTextHandler(eventBus) {
  2592. function setText(element, text) {
  2593. var label = LabelUtil.setLabel(element, text);
  2594. eventBus.fire('element.changed', { element: label });
  2595. }
  2596. function execute(ctx) {
  2597. ctx.oldLabel = LabelUtil.getLabel(ctx.element);
  2598. return setText(ctx.element, ctx.newLabel);
  2599. }
  2600. function revert(ctx) {
  2601. return setText(ctx.element, ctx.oldLabel);
  2602. }
  2603. function canExecute(ctx) {
  2604. return true;
  2605. }
  2606. // API
  2607. this.execute = execute;
  2608. this.revert = revert;
  2609. this.canExecute = canExecute;
  2610. }
  2611. UpdateTextHandler.$inject = [ 'eventBus' ];
  2612. module.exports = UpdateTextHandler;
  2613. },{"12":12}],14:[function(_dereq_,module,exports){
  2614. module.exports = {
  2615. __depends__: [
  2616. _dereq_(80),
  2617. _dereq_(98),
  2618. _dereq_(73)
  2619. ],
  2620. __init__: [ 'labelEditingProvider' ],
  2621. labelEditingProvider: [ 'type', _dereq_(11) ]
  2622. };
  2623. },{"11":11,"73":73,"80":80,"98":98}],15:[function(_dereq_,module,exports){
  2624. 'use strict';
  2625. var map = _dereq_(221),
  2626. assign = _dereq_(339),
  2627. pick = _dereq_(345);
  2628. function BpmnFactory(moddle) {
  2629. this._model = moddle;
  2630. }
  2631. BpmnFactory.$inject = [ 'moddle' ];
  2632. BpmnFactory.prototype._needsId = function(element) {
  2633. return element.$instanceOf('bpmn:RootElement') ||
  2634. element.$instanceOf('bpmn:FlowElement') ||
  2635. element.$instanceOf('bpmn:MessageFlow') ||
  2636. element.$instanceOf('bpmn:Artifact') ||
  2637. element.$instanceOf('bpmn:Participant') ||
  2638. element.$instanceOf('bpmn:Process') ||
  2639. element.$instanceOf('bpmn:Collaboration') ||
  2640. element.$instanceOf('bpmndi:BPMNShape') ||
  2641. element.$instanceOf('bpmndi:BPMNEdge') ||
  2642. element.$instanceOf('bpmndi:BPMNDiagram') ||
  2643. element.$instanceOf('bpmndi:BPMNPlane');
  2644. };
  2645. BpmnFactory.prototype._ensureId = function(element) {
  2646. // generate semantic ids for elements
  2647. // bpmn:SequenceFlow -> SequenceFlow_ID
  2648. var prefix = (element.$type || '').replace(/^[^:]*:/g, '') + '_';
  2649. if (!element.id && this._needsId(element)) {
  2650. element.id = this._model.ids.nextPrefixed(prefix, element);
  2651. }
  2652. };
  2653. BpmnFactory.prototype.create = function(type, attrs) {
  2654. var element = this._model.create(type, attrs || {});
  2655. this._ensureId(element);
  2656. return element;
  2657. };
  2658. BpmnFactory.prototype.createDiLabel = function() {
  2659. return this.create('bpmndi:BPMNLabel', {
  2660. bounds: this.createDiBounds()
  2661. });
  2662. };
  2663. BpmnFactory.prototype.createDiShape = function(semantic, bounds, attrs) {
  2664. return this.create('bpmndi:BPMNShape', assign({
  2665. bpmnElement: semantic,
  2666. bounds: this.createDiBounds(bounds)
  2667. }, attrs));
  2668. };
  2669. BpmnFactory.prototype.createDiBounds = function(bounds) {
  2670. return this.create('dc:Bounds', bounds);
  2671. };
  2672. BpmnFactory.prototype.createDiWaypoints = function(waypoints) {
  2673. return map(waypoints, function(pos) {
  2674. return this.createDiWaypoint(pos);
  2675. }, this);
  2676. };
  2677. BpmnFactory.prototype.createDiWaypoint = function(point) {
  2678. return this.create('dc:Point', pick(point, [ 'x', 'y' ]));
  2679. };
  2680. BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) {
  2681. return this.create('bpmndi:BPMNEdge', assign({
  2682. bpmnElement: semantic
  2683. }, attrs));
  2684. };
  2685. BpmnFactory.prototype.createDiPlane = function(semantic) {
  2686. return this.create('bpmndi:BPMNPlane', {
  2687. bpmnElement: semantic
  2688. });
  2689. };
  2690. module.exports = BpmnFactory;
  2691. },{"221":221,"339":339,"345":345}],16:[function(_dereq_,module,exports){
  2692. 'use strict';
  2693. var assign = _dereq_(339),
  2694. inherits = _dereq_(207);
  2695. var LabelUtil = _dereq_(49);
  2696. var hasExternalLabel = LabelUtil.hasExternalLabel,
  2697. getExternalLabelMid = LabelUtil.getExternalLabelMid;
  2698. var CommandInterceptor = _dereq_(78);
  2699. function LabelSupport(eventBus, modeling, bpmnFactory) {
  2700. CommandInterceptor.call(this, eventBus);
  2701. // create external labels on shape creation
  2702. this.postExecute([ 'shape.create', 'connection.create' ], function(e) {
  2703. var context = e.context;
  2704. var element = context.shape || context.connection,
  2705. businessObject = element.businessObject;
  2706. var position;
  2707. if (hasExternalLabel(businessObject)) {
  2708. position = getExternalLabelMid(element);
  2709. modeling.createLabel(element, position, {
  2710. id: businessObject.id + '_label',
  2711. businessObject: businessObject
  2712. });
  2713. }
  2714. });
  2715. // update di information on label movement and creation
  2716. this.executed([ 'label.create', 'shape.moved' ], function(e) {
  2717. var element = e.context.shape,
  2718. businessObject = element.businessObject,
  2719. di = businessObject.di;
  2720. // we want to trigger on real labels only
  2721. if (!element.labelTarget) {
  2722. return;
  2723. }
  2724. if (!di.label) {
  2725. di.label = bpmnFactory.create('bpmndi:BPMNLabel', {
  2726. bounds: bpmnFactory.create('dc:Bounds')
  2727. });
  2728. }
  2729. assign(di.label.bounds, {
  2730. x: element.x,
  2731. y: element.y,
  2732. width: element.width,
  2733. height: element.height
  2734. });
  2735. });
  2736. }
  2737. inherits(LabelSupport, CommandInterceptor);
  2738. LabelSupport.$inject = [ 'eventBus', 'modeling', 'bpmnFactory' ];
  2739. module.exports = LabelSupport;
  2740. },{"207":207,"339":339,"49":49,"78":78}],17:[function(_dereq_,module,exports){
  2741. 'use strict';
  2742. var inherits = _dereq_(207);
  2743. var assign = _dereq_(339);
  2744. var BaseLayouter = _dereq_(172),
  2745. ManhattanLayout = _dereq_(175);
  2746. var LayoutUtil = _dereq_(174);
  2747. var getMid = LayoutUtil.getMid,
  2748. getOrientation = LayoutUtil.getOrientation;
  2749. var is = _dereq_(50).is;
  2750. function BpmnLayouter() {}
  2751. inherits(BpmnLayouter, BaseLayouter);
  2752. module.exports = BpmnLayouter;
  2753. BpmnLayouter.prototype.layoutConnection = function(connection, layoutHints) {
  2754. var source = connection.source,
  2755. target = connection.target,
  2756. waypoints = connection.waypoints,
  2757. start,
  2758. end;
  2759. var manhattanOptions,
  2760. updatedWaypoints;
  2761. start = getConnectionDocking(waypoints, 0, source);
  2762. end = getConnectionDocking(waypoints, waypoints && waypoints.length - 1, target);
  2763. // TODO (nre): support vertical modeling
  2764. // and invert preferredLayouts accordingly
  2765. // manhattan layout sequence / message flows
  2766. if (is(connection, 'bpmn:MessageFlow')) {
  2767. manhattanOptions = {
  2768. preferredLayouts: [ 'straight', 'v:v' ]
  2769. };
  2770. } else
  2771. // layout all connection between flow elements h:h,
  2772. //
  2773. // except for
  2774. //
  2775. // (1) outgoing of BoundaryEvents -> layout h:v or v:h based on attach orientation
  2776. // (2) incoming / outgoing of Gateway -> v:h (outgoing), h:v (incoming)
  2777. //
  2778. if (is(connection, 'bpmn:SequenceFlow')) {
  2779. // make sure boundary event connections do
  2780. // not look ugly =:>
  2781. if (is(source, 'bpmn:BoundaryEvent')) {
  2782. var orientation = getAttachOrientation(source);
  2783. if (/left|right/.test(orientation)) {
  2784. manhattanOptions = {
  2785. preferredLayouts: [ 'h:v' ]
  2786. };
  2787. } else
  2788. if (/top|bottom/.test(orientation)) {
  2789. manhattanOptions = {
  2790. preferredLayouts: [ 'v:h' ]
  2791. };
  2792. }
  2793. } else
  2794. if (is(source, 'bpmn:Gateway')) {
  2795. manhattanOptions = {
  2796. preferredLayouts: [ 'v:h' ]
  2797. };
  2798. } else
  2799. if (is(target, 'bpmn:Gateway')) {
  2800. manhattanOptions = {
  2801. preferredLayouts: [ 'h:v' ]
  2802. };
  2803. }
  2804. // apply horizontal love <3
  2805. else {
  2806. manhattanOptions = {
  2807. preferredLayouts: [ 'h:h' ]
  2808. };
  2809. }
  2810. }
  2811. if (manhattanOptions) {
  2812. manhattanOptions = assign(manhattanOptions, layoutHints);
  2813. updatedWaypoints =
  2814. ManhattanLayout.repairConnection(
  2815. source, target,
  2816. start, end,
  2817. waypoints,
  2818. manhattanOptions);
  2819. }
  2820. return updatedWaypoints || [ start, end ];
  2821. };
  2822. function getAttachOrientation(attachedElement) {
  2823. var hostElement = attachedElement.host,
  2824. padding = -10;
  2825. return getOrientation(getMid(attachedElement), hostElement, padding);
  2826. }
  2827. function getConnectionDocking(waypoints, idx, shape) {
  2828. var point = waypoints && waypoints[idx];
  2829. return point ? (point.original || point) : getMid(shape);
  2830. }
  2831. },{"172":172,"174":174,"175":175,"207":207,"339":339,"50":50}],18:[function(_dereq_,module,exports){
  2832. 'use strict';
  2833. var assign = _dereq_(339),
  2834. forEach = _dereq_(218),
  2835. inherits = _dereq_(207);
  2836. var Collections = _dereq_(184),
  2837. Model = _dereq_(176);
  2838. var getBusinessObject = _dereq_(50).getBusinessObject,
  2839. is = _dereq_(50).is;
  2840. var CommandInterceptor = _dereq_(78);
  2841. /**
  2842. * A handler responsible for updating the underlying BPMN 2.0 XML + DI
  2843. * once changes on the diagram happen
  2844. */
  2845. function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) {
  2846. CommandInterceptor.call(this, eventBus);
  2847. this._bpmnFactory = bpmnFactory;
  2848. var self = this;
  2849. ////// connection cropping /////////////////////////
  2850. // crop connection ends during create/update
  2851. function cropConnection(e) {
  2852. var context = e.context,
  2853. connection;
  2854. if (!context.cropped) {
  2855. connection = context.connection;
  2856. connection.waypoints = connectionDocking.getCroppedWaypoints(connection);
  2857. context.cropped = true;
  2858. }
  2859. }
  2860. this.executed([
  2861. 'connection.layout',
  2862. 'connection.create',
  2863. 'connection.reconnectEnd',
  2864. 'connection.reconnectStart'
  2865. ], cropConnection);
  2866. this.reverted([ 'connection.layout' ], function(e) {
  2867. delete e.context.cropped;
  2868. });
  2869. ////// BPMN + DI update /////////////////////////
  2870. // update parent
  2871. function updateParent(e) {
  2872. self.updateParent(e.context.shape || e.context.connection);
  2873. }
  2874. this.executed([ 'shape.move',
  2875. 'shape.create',
  2876. 'shape.delete',
  2877. 'connection.create',
  2878. 'connection.move',
  2879. 'connection.delete' ], updateParent);
  2880. this.reverted([ 'shape.move',
  2881. 'shape.create',
  2882. 'shape.delete',
  2883. 'connection.create',
  2884. 'connection.move',
  2885. 'connection.delete' ], updateParent);
  2886. /*
  2887. * ## Updating Parent
  2888. *
  2889. * When morphing a Process into a Collaboration or vice-versa,
  2890. * make sure that both the *semantic* and *di* parent of each element
  2891. * is updated.
  2892. *
  2893. */
  2894. function updateRoot(event) {
  2895. var context = event.context,
  2896. oldRoot = context.oldRoot,
  2897. children = oldRoot.children;
  2898. forEach(children, function(child) {
  2899. self.updateParent(child);
  2900. });
  2901. }
  2902. this.executed([ 'canvas.updateRoot' ], updateRoot);
  2903. this.reverted([ 'canvas.updateRoot' ], updateRoot);
  2904. // update bounds
  2905. function updateBounds(e) {
  2906. self.updateBounds(e.context.shape);
  2907. }
  2908. this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], updateBounds);
  2909. this.reverted([ 'shape.move', 'shape.create', 'shape.resize' ], updateBounds);
  2910. // attach / detach connection
  2911. function updateConnection(e) {
  2912. self.updateConnection(e.context.connection);
  2913. }
  2914. this.executed([
  2915. 'connection.create',
  2916. 'connection.move',
  2917. 'connection.delete',
  2918. 'connection.reconnectEnd',
  2919. 'connection.reconnectStart'
  2920. ], updateConnection);
  2921. this.reverted([
  2922. 'connection.create',
  2923. 'connection.move',
  2924. 'connection.delete',
  2925. 'connection.reconnectEnd',
  2926. 'connection.reconnectStart'
  2927. ], updateConnection);
  2928. // update waypoints
  2929. function updateConnectionWaypoints(e) {
  2930. self.updateConnectionWaypoints(e.context.connection);
  2931. }
  2932. this.executed([
  2933. 'connection.layout',
  2934. 'connection.move',
  2935. 'connection.updateWaypoints',
  2936. 'connection.reconnectEnd',
  2937. 'connection.reconnectStart'
  2938. ], updateConnectionWaypoints);
  2939. this.reverted([
  2940. 'connection.layout',
  2941. 'connection.move',
  2942. 'connection.updateWaypoints',
  2943. 'connection.reconnectEnd',
  2944. 'connection.reconnectStart'
  2945. ], updateConnectionWaypoints);
  2946. // update attachments
  2947. function updateAttachment(e) {
  2948. self.updateAttachment(e.context);
  2949. }
  2950. this.executed([ 'shape.attach' ], updateAttachment);
  2951. this.reverted([ 'shape.attach' ], updateAttachment);
  2952. }
  2953. inherits(BpmnUpdater, CommandInterceptor);
  2954. module.exports = BpmnUpdater;
  2955. BpmnUpdater.$inject = [ 'eventBus', 'bpmnFactory', 'connectionDocking'];
  2956. /////// implementation //////////////////////////////////
  2957. BpmnUpdater.prototype.updateAttachment = function(context) {
  2958. var shape = context.shape,
  2959. businessObject = shape.businessObject,
  2960. host = shape.host;
  2961. businessObject.attachedToRef = host && host.businessObject;
  2962. };
  2963. BpmnUpdater.prototype.updateParent = function(element) {
  2964. // do not update BPMN 2.0 label parent
  2965. if (element instanceof Model.Label) {
  2966. return;
  2967. }
  2968. var parentShape = element.parent;
  2969. var businessObject = element.businessObject,
  2970. parentBusinessObject = parentShape && parentShape.businessObject,
  2971. parentDi = parentBusinessObject && parentBusinessObject.di;
  2972. this.updateSemanticParent(businessObject, parentBusinessObject);
  2973. this.updateDiParent(businessObject.di, parentDi);
  2974. };
  2975. BpmnUpdater.prototype.updateBounds = function(shape) {
  2976. var di = shape.businessObject.di;
  2977. var bounds = (shape instanceof Model.Label) ? this._getLabel(di).bounds : di.bounds;
  2978. assign(bounds, {
  2979. x: shape.x,
  2980. y: shape.y,
  2981. width: shape.width,
  2982. height: shape.height
  2983. });
  2984. };
  2985. BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
  2986. if (parentDi && !is(parentDi, 'bpmndi:BPMNPlane')) {
  2987. parentDi = parentDi.$parent;
  2988. }
  2989. if (di.$parent === parentDi) {
  2990. return;
  2991. }
  2992. var planeElements = (parentDi || di.$parent).get('planeElement');
  2993. if (parentDi) {
  2994. planeElements.push(di);
  2995. di.$parent = parentDi;
  2996. } else {
  2997. Collections.remove(planeElements, di);
  2998. di.$parent = null;
  2999. }
  3000. };
  3001. function getDefinitions(element) {
  3002. while (element && !is(element, 'bpmn:Definitions')) {
  3003. element = element.$parent;
  3004. }
  3005. return element;
  3006. }
  3007. BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent) {
  3008. var containment;
  3009. if (businessObject.$parent === newParent) {
  3010. return;
  3011. }
  3012. if (is(businessObject, 'bpmn:FlowElement')) {
  3013. if (newParent && is(newParent, 'bpmn:Participant')) {
  3014. newParent = newParent.processRef;
  3015. }
  3016. containment = 'flowElements';
  3017. } else
  3018. if (is(businessObject, 'bpmn:Artifact')) {
  3019. while (newParent &&
  3020. !is(newParent, 'bpmn:Process') &&
  3021. !is(newParent, 'bpmn:SubProcess') &&
  3022. !is(newParent, 'bpmn:Collaboration')) {
  3023. if (is(newParent, 'bpmn:Participant')) {
  3024. newParent = newParent.processRef;
  3025. break;
  3026. } else {
  3027. newParent = newParent.$parent;
  3028. }
  3029. }
  3030. containment = 'artifacts';
  3031. } else
  3032. if (is(businessObject, 'bpmn:MessageFlow')) {
  3033. containment = 'messageFlows';
  3034. } else
  3035. if (is(businessObject, 'bpmn:Participant')) {
  3036. containment = 'participants';
  3037. // make sure the participants process is properly attached / detached
  3038. // from the XML document
  3039. var process = businessObject.processRef,
  3040. definitions;
  3041. if (process) {
  3042. definitions = getDefinitions(businessObject.$parent || newParent);
  3043. if (businessObject.$parent) {
  3044. Collections.remove(definitions.get('rootElements'), process);
  3045. process.$parent = null;
  3046. }
  3047. if (newParent) {
  3048. Collections.add(definitions.get('rootElements'), process);
  3049. process.$parent = definitions;
  3050. }
  3051. }
  3052. }
  3053. if (!containment) {
  3054. throw new Error('no parent for ', businessObject, newParent);
  3055. }
  3056. var children;
  3057. if (businessObject.$parent) {
  3058. // remove from old parent
  3059. children = businessObject.$parent.get(containment);
  3060. Collections.remove(children, businessObject);
  3061. }
  3062. if (!newParent) {
  3063. businessObject.$parent = null;
  3064. } else {
  3065. // add to new parent
  3066. children = newParent.get(containment);
  3067. children.push(businessObject);
  3068. businessObject.$parent = newParent;
  3069. }
  3070. };
  3071. BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
  3072. connection.businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
  3073. };
  3074. BpmnUpdater.prototype.updateConnection = function(connection) {
  3075. var businessObject = getBusinessObject(connection),
  3076. newSource = getBusinessObject(connection.source),
  3077. newTarget = getBusinessObject(connection.target);
  3078. var inverseSet = is(businessObject, 'bpmn:SequenceFlow');
  3079. if (businessObject.sourceRef !== newSource) {
  3080. if (inverseSet) {
  3081. Collections.remove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
  3082. if (newSource && newSource.get('outgoing')) {
  3083. newSource.get('outgoing').push(businessObject);
  3084. }
  3085. }
  3086. businessObject.sourceRef = newSource;
  3087. }
  3088. if (businessObject.targetRef !== newTarget) {
  3089. if (inverseSet) {
  3090. Collections.remove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
  3091. if (newTarget && newTarget.get('incoming')) {
  3092. newTarget.get('incoming').push(businessObject);
  3093. }
  3094. }
  3095. businessObject.targetRef = newTarget;
  3096. }
  3097. businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
  3098. };
  3099. /////// helpers /////////////////////////////////////////
  3100. BpmnUpdater.prototype._getLabel = function(di) {
  3101. if (!di.label) {
  3102. di.label = this._bpmnFactory.createDiLabel();
  3103. }
  3104. return di.label;
  3105. };
  3106. },{"176":176,"184":184,"207":207,"218":218,"339":339,"50":50,"78":78}],19:[function(_dereq_,module,exports){
  3107. 'use strict';
  3108. var assign = _dereq_(339),
  3109. inherits = _dereq_(207);
  3110. var BaseElementFactory = _dereq_(82),
  3111. LabelUtil = _dereq_(49);
  3112. /**
  3113. * A bpmn-aware factory for diagram-js shapes
  3114. */
  3115. function ElementFactory(bpmnFactory, moddle) {
  3116. BaseElementFactory.call(this);
  3117. this._bpmnFactory = bpmnFactory;
  3118. this._moddle = moddle;
  3119. }
  3120. inherits(ElementFactory, BaseElementFactory);
  3121. ElementFactory.$inject = [ 'bpmnFactory', 'moddle' ];
  3122. module.exports = ElementFactory;
  3123. ElementFactory.prototype.baseCreate = BaseElementFactory.prototype.create;
  3124. ElementFactory.prototype.create = function(elementType, attrs) {
  3125. // no special magic for labels,
  3126. // we assume their businessObjects have already been created
  3127. // and wired via attrs
  3128. if (elementType === 'label') {
  3129. return this.baseCreate(elementType, assign({ type: 'label' }, LabelUtil.DEFAULT_LABEL_SIZE, attrs));
  3130. }
  3131. attrs = attrs || {};
  3132. var businessObject = attrs.businessObject,
  3133. size;
  3134. if (!businessObject) {
  3135. if (!attrs.type) {
  3136. throw new Error('no shape type specified');
  3137. }
  3138. businessObject = this._bpmnFactory.create(attrs.type);
  3139. }
  3140. if (!businessObject.di) {
  3141. if (elementType === 'root') {
  3142. businessObject.di = this._bpmnFactory.createDiPlane(businessObject, [], {
  3143. id: businessObject.id + '_di'
  3144. });
  3145. } else
  3146. if (elementType === 'connection') {
  3147. businessObject.di = this._bpmnFactory.createDiEdge(businessObject, [], {
  3148. id: businessObject.id + '_di'
  3149. });
  3150. } else {
  3151. businessObject.di = this._bpmnFactory.createDiShape(businessObject, {}, {
  3152. id: businessObject.id + '_di'
  3153. });
  3154. }
  3155. }
  3156. if (!!attrs.isExpanded) {
  3157. businessObject.di.isExpanded = attrs.isExpanded;
  3158. }
  3159. if (businessObject.$instanceOf('bpmn:ExclusiveGateway')) {
  3160. businessObject.di.isMarkerVisible = true;
  3161. }
  3162. if (attrs._eventDefinitionType) {
  3163. var eventDefinitions = businessObject.get('eventDefinitions') || [],
  3164. newEventDefinition = this._moddle.create(attrs._eventDefinitionType);
  3165. eventDefinitions.push(newEventDefinition);
  3166. businessObject.eventDefinitions = eventDefinitions;
  3167. }
  3168. size = this._getDefaultSize(businessObject);
  3169. attrs = assign({
  3170. businessObject: businessObject,
  3171. id: businessObject.id
  3172. }, size, attrs);
  3173. return this.baseCreate(elementType, attrs);
  3174. };
  3175. ElementFactory.prototype._getDefaultSize = function(semantic) {
  3176. if (semantic.$instanceOf('bpmn:SubProcess')) {
  3177. var isExpanded = semantic.di.isExpanded === true;
  3178. if (isExpanded) {
  3179. return { width: 350, height: 200 };
  3180. } else {
  3181. return { width: 100, height: 80 };
  3182. }
  3183. }
  3184. if (semantic.$instanceOf('bpmn:Task')) {
  3185. return { width: 100, height: 80 };
  3186. }
  3187. if (semantic.$instanceOf('bpmn:Gateway')) {
  3188. return { width: 50, height: 50 };
  3189. }
  3190. if (semantic.$instanceOf('bpmn:Event')) {
  3191. return { width: 36, height: 36 };
  3192. }
  3193. if (semantic.$instanceOf('bpmn:Participant')) {
  3194. return { width: 600, height: 250 };
  3195. }
  3196. return { width: 100, height: 80 };
  3197. };
  3198. ElementFactory.prototype.createParticipantShape = function(collapsed) {
  3199. var participantShape = this.createShape({ type: 'bpmn:Participant' });
  3200. if (!collapsed) {
  3201. participantShape.businessObject.processRef = this._bpmnFactory.create('bpmn:Process');
  3202. }
  3203. return participantShape;
  3204. };
  3205. },{"207":207,"339":339,"49":49,"82":82}],20:[function(_dereq_,module,exports){
  3206. 'use strict';
  3207. var inherits = _dereq_(207);
  3208. var BaseModeling = _dereq_(115);
  3209. var UpdatePropertiesHandler = _dereq_(31),
  3210. UpdateCanvasRootHandler = _dereq_(30);
  3211. /**
  3212. * BPMN 2.0 modeling features activator
  3213. *
  3214. * @param {EventBus} eventBus
  3215. * @param {ElementFactory} elementFactory
  3216. * @param {CommandStack} commandStack
  3217. * @param {BpmnRules} bpmnRules
  3218. */
  3219. function Modeling(eventBus, elementFactory, commandStack, bpmnRules) {
  3220. BaseModeling.call(this, eventBus, elementFactory, commandStack);
  3221. this._bpmnRules = bpmnRules;
  3222. }
  3223. inherits(Modeling, BaseModeling);
  3224. Modeling.$inject = [ 'eventBus', 'elementFactory', 'commandStack', 'bpmnRules' ];
  3225. module.exports = Modeling;
  3226. Modeling.prototype.getHandlers = function() {
  3227. var handlers = BaseModeling.prototype.getHandlers.call(this);
  3228. handlers['element.updateProperties'] = UpdatePropertiesHandler;
  3229. handlers['canvas.updateRoot'] = UpdateCanvasRootHandler;
  3230. return handlers;
  3231. };
  3232. Modeling.prototype.updateLabel = function(element, newLabel) {
  3233. this._commandStack.execute('element.updateLabel', {
  3234. element: element,
  3235. newLabel: newLabel
  3236. });
  3237. };
  3238. var getSharedParent = _dereq_(21).getSharedParent;
  3239. Modeling.prototype.connect = function(source, target, attrs) {
  3240. var bpmnRules = this._bpmnRules;
  3241. if (!attrs) {
  3242. if (bpmnRules.canConnectMessageFlow(source, target)) {
  3243. attrs = {
  3244. type: 'bpmn:MessageFlow'
  3245. };
  3246. } else
  3247. if (bpmnRules.canConnectSequenceFlow(source, target)) {
  3248. attrs = {
  3249. type: 'bpmn:SequenceFlow'
  3250. };
  3251. } else {
  3252. attrs = {
  3253. type: 'bpmn:Association'
  3254. };
  3255. }
  3256. }
  3257. return this.createConnection(source, target, attrs, getSharedParent(source, target));
  3258. };
  3259. Modeling.prototype.updateProperties = function(element, properties) {
  3260. this._commandStack.execute('element.updateProperties', {
  3261. element: element,
  3262. properties: properties
  3263. });
  3264. };
  3265. /**
  3266. * Transform the current diagram into a collaboration.
  3267. *
  3268. * @return {djs.model.Root} the new root element
  3269. */
  3270. Modeling.prototype.makeCollaboration = function() {
  3271. var collaborationElement = this._create('root', {
  3272. type: 'bpmn:Collaboration'
  3273. });
  3274. var context = {
  3275. newRoot: collaborationElement
  3276. };
  3277. this._commandStack.execute('canvas.updateRoot', context);
  3278. return collaborationElement;
  3279. };
  3280. /**
  3281. * Transform the current diagram into a process.
  3282. *
  3283. * @return {djs.model.Root} the new root element
  3284. */
  3285. Modeling.prototype.makeProcess = function() {
  3286. var processElement = this._create('root', {
  3287. type: 'bpmn:Process'
  3288. });
  3289. var context = {
  3290. newRoot: processElement
  3291. };
  3292. this._commandStack.execute('canvas.updateRoot', context);
  3293. };
  3294. },{"115":115,"207":207,"21":21,"30":30,"31":31}],21:[function(_dereq_,module,exports){
  3295. 'use strict';
  3296. var find = _dereq_(217);
  3297. function getParents(element) {
  3298. var parents = [];
  3299. while (element) {
  3300. element = element.parent;
  3301. if (element) {
  3302. parents.push(element);
  3303. }
  3304. }
  3305. return parents;
  3306. }
  3307. module.exports.getParents = getParents;
  3308. function getSharedParent(a, b) {
  3309. var parentsA = getParents(a),
  3310. parentsB = getParents(b);
  3311. return find(parentsA, function(parent) {
  3312. return parentsB.indexOf(parent) !== -1;
  3313. });
  3314. }
  3315. module.exports.getSharedParent = getSharedParent;
  3316. },{"217":217}],22:[function(_dereq_,module,exports){
  3317. 'use strict';
  3318. var inherits = _dereq_(207);
  3319. var is = _dereq_(50).is;
  3320. var CommandInterceptor = _dereq_(78);
  3321. function AppendBehavior(eventBus, elementFactory, bpmnRules) {
  3322. CommandInterceptor.call(this, eventBus);
  3323. // assign correct shape position unless already set
  3324. this.preExecute('shape.append', function(context) {
  3325. var source = context.source,
  3326. shape = context.shape;
  3327. if (!context.position) {
  3328. if (is(shape, 'bpmn:TextAnnotation')) {
  3329. context.position = {
  3330. x: source.x + source.width / 2 + 75,
  3331. y: source.y - (50) - shape.height / 2
  3332. };
  3333. } else {
  3334. context.position = {
  3335. x: source.x + source.width + 80 + shape.width / 2,
  3336. y: source.y + source.height / 2
  3337. };
  3338. }
  3339. }
  3340. }, true);
  3341. }
  3342. AppendBehavior.$inject = [ 'eventBus', 'elementFactory', 'bpmnRules' ];
  3343. inherits(AppendBehavior, CommandInterceptor);
  3344. module.exports = AppendBehavior;
  3345. },{"207":207,"50":50,"78":78}],23:[function(_dereq_,module,exports){
  3346. 'use strict';
  3347. var inherits = _dereq_(207);
  3348. var CommandInterceptor = _dereq_(78);
  3349. var is = _dereq_(50).is;
  3350. /**
  3351. * BPMN specific create boundary event behavior
  3352. */
  3353. function CreateBoundaryEventBehavior(eventBus, modeling, elementFactory, bpmnFactory) {
  3354. CommandInterceptor.call(this, eventBus);
  3355. /**
  3356. * replace intermediate event with boundary event when
  3357. * attaching it to a shape
  3358. */
  3359. this.preExecute('shape.create', function(context) {
  3360. var shape = context.shape,
  3361. host = context.host,
  3362. businessObject,
  3363. boundaryEvent;
  3364. var attrs = {
  3365. cancelActivity: true
  3366. };
  3367. if (host && is(shape, 'bpmn:IntermediateThrowEvent')) {
  3368. attrs.attachedToRef = host.businessObject;
  3369. businessObject = bpmnFactory.create('bpmn:BoundaryEvent', attrs);
  3370. boundaryEvent = {
  3371. type: 'bpmn:BoundaryEvent',
  3372. businessObject: businessObject
  3373. };
  3374. context.shape = elementFactory.createShape(boundaryEvent);
  3375. }
  3376. }, true);
  3377. }
  3378. CreateBoundaryEventBehavior.$inject = [ 'eventBus', 'modeling', 'elementFactory', 'bpmnFactory' ];
  3379. inherits(CreateBoundaryEventBehavior, CommandInterceptor);
  3380. module.exports = CreateBoundaryEventBehavior;
  3381. },{"207":207,"50":50,"78":78}],24:[function(_dereq_,module,exports){
  3382. 'use strict';
  3383. var inherits = _dereq_(207);
  3384. var assign = _dereq_(339);
  3385. var CommandInterceptor = _dereq_(78);
  3386. var getApproxIntersection = _dereq_(191).getApproxIntersection;
  3387. function copy(obj) {
  3388. return assign({}, obj);
  3389. }
  3390. function CreateOnFlowBehavior(eventBus, bpmnRules, modeling) {
  3391. CommandInterceptor.call(this, eventBus);
  3392. /**
  3393. * Reconnect start / end of a connection after
  3394. * dropping an element on a flow.
  3395. */
  3396. this.preExecute('shape.create', function(context) {
  3397. var parent = context.parent,
  3398. shape = context.shape;
  3399. if (bpmnRules.canInsert(shape, parent)) {
  3400. context.targetFlow = parent;
  3401. context.parent = parent.parent;
  3402. }
  3403. }, true);
  3404. this.postExecute('shape.create', function(context) {
  3405. var shape = context.shape,
  3406. targetFlow = context.targetFlow,
  3407. position = context.position,
  3408. source,
  3409. target,
  3410. reconnected,
  3411. intersection,
  3412. waypoints,
  3413. waypointsBefore,
  3414. waypointsAfter,
  3415. dockingPoint;
  3416. if (targetFlow) {
  3417. waypoints = targetFlow.waypoints;
  3418. intersection = getApproxIntersection(waypoints, position);
  3419. if (intersection) {
  3420. waypointsBefore = waypoints.slice(0, intersection.index);
  3421. waypointsAfter = waypoints.slice(intersection.index + (intersection.bendpoint ? 1 : 0));
  3422. dockingPoint = intersection.bendpoint ? waypoints[intersection.index] : position;
  3423. waypointsBefore.push(copy(dockingPoint));
  3424. waypointsAfter.unshift(copy(dockingPoint));
  3425. }
  3426. source = targetFlow.source;
  3427. target = targetFlow.target;
  3428. if (bpmnRules.canConnect(source, shape, targetFlow)) {
  3429. // reconnect source -> inserted shape
  3430. modeling.reconnectEnd(targetFlow, shape, waypointsBefore || copy(position));
  3431. reconnected = true;
  3432. }
  3433. if (bpmnRules.canConnect(shape, target, targetFlow)) {
  3434. if (!reconnected) {
  3435. // reconnect inserted shape -> end
  3436. modeling.reconnectStart(targetFlow, shape, waypointsAfter || copy(position));
  3437. } else {
  3438. modeling.connect(shape, target, { type: targetFlow.type, waypoints: waypointsAfter });
  3439. }
  3440. }
  3441. }
  3442. }, true);
  3443. }
  3444. inherits(CreateOnFlowBehavior, CommandInterceptor);
  3445. CreateOnFlowBehavior.$inject = [ 'eventBus', 'bpmnRules', 'modeling' ];
  3446. module.exports = CreateOnFlowBehavior;
  3447. },{"191":191,"207":207,"339":339,"78":78}],25:[function(_dereq_,module,exports){
  3448. 'use strict';
  3449. var inherits = _dereq_(207);
  3450. var CommandInterceptor = _dereq_(78);
  3451. var is = _dereq_(50).is;
  3452. /**
  3453. * BPMN specific create participant behavior
  3454. */
  3455. function CreateParticipantBehavior(eventBus, modeling, elementFactory, bpmnFactory) {
  3456. CommandInterceptor.call(this, eventBus);
  3457. /**
  3458. * morph process into collaboration before adding
  3459. * participant onto collaboration
  3460. */
  3461. this.preExecute('shape.create', function(context) {
  3462. var parent = context.parent,
  3463. shape = context.shape,
  3464. position = context.position;
  3465. if (is(parent, 'bpmn:Process') && is(shape, 'bpmn:Participant')) {
  3466. // this is going to detach the process root
  3467. // and set the returned collaboration element
  3468. // as the new root element
  3469. var collaborationElement = modeling.makeCollaboration();
  3470. // monkey patch the create context
  3471. // so that the participant is being dropped
  3472. // onto the new collaboration root instead
  3473. context.position = position;
  3474. context.parent = collaborationElement;
  3475. context.processRoot = parent;
  3476. }
  3477. }, true);
  3478. this.execute('shape.create', function(context) {
  3479. var processRoot = context.processRoot,
  3480. shape = context.shape;
  3481. if (processRoot) {
  3482. context.oldProcessRef = shape.businessObject.processRef;
  3483. // assign the participant processRef
  3484. shape.businessObject.processRef = processRoot.businessObject;
  3485. }
  3486. }, true);
  3487. this.revert('shape.create', function(context) {
  3488. var processRoot = context.processRoot,
  3489. shape = context.shape;
  3490. if (processRoot) {
  3491. // assign the participant processRef
  3492. shape.businessObject.processRef = context.oldProcessRef;
  3493. }
  3494. }, true);
  3495. this.postExecute('shape.create', function(context) {
  3496. var processRoot = context.processRoot,
  3497. shape = context.shape;
  3498. if (processRoot) {
  3499. // process root is already detached at this point
  3500. var processChildren = processRoot.children.slice();
  3501. modeling.moveShapes(processChildren, { x: 0, y: 0 }, shape);
  3502. }
  3503. }, true);
  3504. }
  3505. CreateParticipantBehavior.$inject = [ 'eventBus', 'modeling', 'elementFactory', 'bpmnFactory' ];
  3506. inherits(CreateParticipantBehavior, CommandInterceptor);
  3507. module.exports = CreateParticipantBehavior;
  3508. },{"207":207,"50":50,"78":78}],26:[function(_dereq_,module,exports){
  3509. 'use strict';
  3510. var is = _dereq_(50).is;
  3511. function ModelingFeedback(eventBus, tooltips) {
  3512. function showError(position, message) {
  3513. tooltips.add({
  3514. position: {
  3515. x: position.x + 5,
  3516. y: position.y + 5
  3517. },
  3518. type: 'error',
  3519. timeout: 2000,
  3520. html: '<div>' + message + '</div>'
  3521. });
  3522. }
  3523. eventBus.on([ 'shape.move.rejected', 'create.rejected' ], function(event) {
  3524. var context = event.context,
  3525. shape = context.shape,
  3526. target = context.target;
  3527. if (is(target, 'bpmn:Collaboration') && is(shape, 'bpmn:FlowNode')) {
  3528. showError(event, 'flow elements must be children of pools/participants');
  3529. }
  3530. });
  3531. }
  3532. ModelingFeedback.$inject = [ 'eventBus', 'tooltips' ];
  3533. module.exports = ModelingFeedback;
  3534. },{"50":50}],27:[function(_dereq_,module,exports){
  3535. 'use strict';
  3536. var inherits = _dereq_(207);
  3537. var CommandInterceptor = _dereq_(78);
  3538. var is = _dereq_(50).is;
  3539. /**
  3540. * BPMN specific remove behavior
  3541. */
  3542. function RemoveBehavior(eventBus, modeling) {
  3543. CommandInterceptor.call(this, eventBus);
  3544. /**
  3545. * morph collaboration diagram into process diagram
  3546. * after the last participant has been removed
  3547. */
  3548. this.preExecute('shape.delete', function(context) {
  3549. var shape = context.shape,
  3550. parent = shape.parent;
  3551. // activate the behavior if the shape to be removed
  3552. // is a participant
  3553. if (is(shape, 'bpmn:Participant')) {
  3554. context.collaborationRoot = parent;
  3555. }
  3556. }, true);
  3557. this.postExecute('shape.delete', function(context) {
  3558. var collaborationRoot = context.collaborationRoot;
  3559. if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
  3560. // replace empty collaboration with process diagram
  3561. modeling.makeProcess();
  3562. }
  3563. }, true);
  3564. }
  3565. RemoveBehavior.$inject = [ 'eventBus', 'modeling' ];
  3566. inherits(RemoveBehavior, CommandInterceptor);
  3567. module.exports = RemoveBehavior;
  3568. },{"207":207,"50":50,"78":78}],28:[function(_dereq_,module,exports){
  3569. 'use strict';
  3570. var forEach = _dereq_(218),
  3571. inherits = _dereq_(207);
  3572. var CommandInterceptor = _dereq_(78);
  3573. var is = _dereq_(50).is,
  3574. getSharedParent = _dereq_(21).getSharedParent;
  3575. function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules) {
  3576. CommandInterceptor.call(this, eventBus);
  3577. function replaceConnection(connection) {
  3578. var source = connection.source,
  3579. target = connection.target;
  3580. var replacementType,
  3581. remove;
  3582. /**
  3583. * Check if incoming or outgoing connections
  3584. * can stay or could be substituted with an
  3585. * appropriate replacement.
  3586. *
  3587. * This holds true for SequenceFlow <> MessageFlow.
  3588. */
  3589. if (is(connection, 'bpmn:SequenceFlow')) {
  3590. if (!bpmnRules.canConnectSequenceFlow(source, target)) {
  3591. remove = true;
  3592. }
  3593. if (bpmnRules.canConnectMessageFlow(source, target)) {
  3594. replacementType = 'bpmn:MessageFlow';
  3595. }
  3596. }
  3597. // transform message flows into sequence flows, if possible
  3598. if (is(connection, 'bpmn:MessageFlow')) {
  3599. if (!bpmnRules.canConnectMessageFlow(source, target)) {
  3600. remove = true;
  3601. }
  3602. if (bpmnRules.canConnectSequenceFlow(source, target)) {
  3603. replacementType = 'bpmn:SequenceFlow';
  3604. }
  3605. }
  3606. if (is(connection, 'bpmn:Association') && !bpmnRules.canConnectAssociation(source, target)) {
  3607. remove = true;
  3608. }
  3609. // remove invalid connection
  3610. if (remove) {
  3611. modeling.removeConnection(connection);
  3612. }
  3613. // replace SequenceFlow <> MessageFlow
  3614. if (replacementType) {
  3615. modeling.createConnection(source, target, {
  3616. type: replacementType,
  3617. waypoints: connection.waypoints.slice()
  3618. }, getSharedParent(source, target));
  3619. }
  3620. }
  3621. this.postExecuted('shapes.move', function(context) {
  3622. var closure = context.closure,
  3623. allConnections = closure.allConnections;
  3624. forEach(allConnections, replaceConnection);
  3625. }, true);
  3626. this.postExecuted([
  3627. 'connection.reconnectStart',
  3628. 'connection.reconnectEnd'
  3629. ], function(event){
  3630. var connection = event.context.connection;
  3631. replaceConnection(connection);
  3632. });
  3633. }
  3634. inherits(ReplaceConnectionBehavior, CommandInterceptor);
  3635. ReplaceConnectionBehavior.$inject = [ 'eventBus', 'modeling', 'bpmnRules' ];
  3636. module.exports = ReplaceConnectionBehavior;
  3637. },{"207":207,"21":21,"218":218,"50":50,"78":78}],29:[function(_dereq_,module,exports){
  3638. module.exports = {
  3639. __init__: [
  3640. 'appendBehavior',
  3641. 'createParticipantBehavior',
  3642. 'createBoundaryEventBehavior',
  3643. 'createOnFlowBehavior',
  3644. 'replaceConnectionBehavior',
  3645. 'removeBehavior',
  3646. 'modelingFeedback'
  3647. ],
  3648. appendBehavior: [ 'type', _dereq_(22) ],
  3649. createParticipantBehavior: [ 'type', _dereq_(25) ],
  3650. createBoundaryEventBehavior: [ 'type', _dereq_(23) ],
  3651. createOnFlowBehavior: [ 'type', _dereq_(24) ],
  3652. replaceConnectionBehavior: [ 'type', _dereq_(28) ],
  3653. removeBehavior: [ 'type', _dereq_(27) ],
  3654. modelingFeedback: [ 'type', _dereq_(26) ]
  3655. };
  3656. },{"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28}],30:[function(_dereq_,module,exports){
  3657. 'use strict';
  3658. var Collections = _dereq_(184);
  3659. function UpdateCanvasRootHandler(canvas, modeling) {
  3660. this._canvas = canvas;
  3661. this._modeling = modeling;
  3662. }
  3663. UpdateCanvasRootHandler.$inject = [ 'canvas', 'modeling' ];
  3664. module.exports = UpdateCanvasRootHandler;
  3665. UpdateCanvasRootHandler.prototype.execute = function(context) {
  3666. var canvas = this._canvas;
  3667. var newRoot = context.newRoot,
  3668. newRootBusinessObject = newRoot.businessObject,
  3669. oldRoot = canvas.getRootElement(),
  3670. oldRootBusinessObject = oldRoot.businessObject,
  3671. bpmnDefinitions = oldRootBusinessObject.$parent,
  3672. diPlane = oldRootBusinessObject.di;
  3673. // (1) replace process old <> new root
  3674. canvas.setRootElement(newRoot, true);
  3675. // (2) update root elements
  3676. Collections.add(bpmnDefinitions.rootElements, newRootBusinessObject);
  3677. newRootBusinessObject.$parent = bpmnDefinitions;
  3678. Collections.remove(bpmnDefinitions.rootElements, oldRootBusinessObject);
  3679. oldRootBusinessObject.$parent = null;
  3680. // (3) wire di
  3681. oldRootBusinessObject.di = null;
  3682. diPlane.bpmnElement = newRootBusinessObject;
  3683. newRootBusinessObject.di = diPlane;
  3684. context.oldRoot = oldRoot;
  3685. };
  3686. UpdateCanvasRootHandler.prototype.revert = function(context) {
  3687. var canvas = this._canvas;
  3688. var newRoot = context.newRoot,
  3689. newRootBusinessObject = newRoot.businessObject,
  3690. oldRoot = context.oldRoot,
  3691. oldRootBusinessObject = oldRoot.businessObject,
  3692. bpmnDefinitions = newRootBusinessObject.$parent,
  3693. diPlane = newRootBusinessObject.di;
  3694. // (1) replace process old <> new root
  3695. canvas.setRootElement(oldRoot, true);
  3696. // (2) update root elements
  3697. Collections.remove(bpmnDefinitions.rootElements, newRootBusinessObject);
  3698. newRootBusinessObject.$parent = null;
  3699. Collections.add(bpmnDefinitions.rootElements, oldRootBusinessObject);
  3700. oldRootBusinessObject.$parent = bpmnDefinitions;
  3701. // (3) wire di
  3702. newRootBusinessObject.di = null;
  3703. diPlane.bpmnElement = oldRootBusinessObject;
  3704. oldRootBusinessObject.di = diPlane;
  3705. };
  3706. },{"184":184}],31:[function(_dereq_,module,exports){
  3707. 'use strict';
  3708. var reduce = _dereq_(346),
  3709. keys = _dereq_(340),
  3710. forEach = _dereq_(218);
  3711. var DEFAULT_FLOW = 'default',
  3712. NAME = 'name',
  3713. ID = 'id';
  3714. /**
  3715. * A handler that implements a BPMN 2.0 property update.
  3716. *
  3717. * This should be used to set simple properties on elements with
  3718. * an underlying BPMN business object.
  3719. *
  3720. * Use respective diagram-js provided handlers if you would
  3721. * like to perform automated modeling.
  3722. */
  3723. function UpdatePropertiesHandler(elementRegistry) {
  3724. this._elementRegistry = elementRegistry;
  3725. }
  3726. UpdatePropertiesHandler.$inject = [ 'elementRegistry' ];
  3727. module.exports = UpdatePropertiesHandler;
  3728. function getProperties(businessObject, propertyNames) {
  3729. return reduce(propertyNames, function(result, key) {
  3730. result[key] = businessObject.get(key);
  3731. return result;
  3732. }, {});
  3733. }
  3734. function setProperties(businessObject, properties) {
  3735. forEach(properties, function(value, key) {
  3736. businessObject.set(key, value);
  3737. });
  3738. }
  3739. ////// api /////////////////////////////////////////////
  3740. /**
  3741. * Updates a BPMN element with a list of new properties
  3742. *
  3743. * @param {Object} context
  3744. * @param {djs.model.Base} context.element the element to update
  3745. * @param {Object} context.properties a list of properties to set on the element's
  3746. * businessObject (the BPMN model element)
  3747. *
  3748. * @return {Array<djs.mode.Base>} the updated element
  3749. */
  3750. UpdatePropertiesHandler.prototype.execute = function(context) {
  3751. var element = context.element,
  3752. changed = [ element ];
  3753. if (!element) {
  3754. throw new Error('element required');
  3755. }
  3756. var elementRegistry = this._elementRegistry;
  3757. var businessObject = element.businessObject,
  3758. properties = context.properties,
  3759. oldProperties = context.oldProperties || getProperties(businessObject, keys(properties));
  3760. if (ID in properties) {
  3761. elementRegistry.updateId(element, properties[ID]);
  3762. }
  3763. // correctly indicate visual changes on default flow updates
  3764. if (DEFAULT_FLOW in properties) {
  3765. if (properties[DEFAULT_FLOW]) {
  3766. changed.push(elementRegistry.get(properties[DEFAULT_FLOW].id));
  3767. }
  3768. if (businessObject[DEFAULT_FLOW]) {
  3769. changed.push(elementRegistry.get(businessObject[DEFAULT_FLOW].id));
  3770. }
  3771. }
  3772. if (NAME in properties && element.label) {
  3773. changed.push(element.label);
  3774. }
  3775. // update properties
  3776. setProperties(businessObject, properties);
  3777. // store old values
  3778. context.oldProperties = oldProperties;
  3779. context.changed = changed;
  3780. // indicate changed on objects affected by the update
  3781. return changed;
  3782. };
  3783. /**
  3784. * Reverts the update on a BPMN elements properties.
  3785. *
  3786. * @param {Object} context
  3787. *
  3788. * @return {djs.mode.Base} the updated element
  3789. */
  3790. UpdatePropertiesHandler.prototype.revert = function(context) {
  3791. var element = context.element,
  3792. oldProperties = context.oldProperties,
  3793. businessObject = element.businessObject,
  3794. elementRegistry = this._elementRegistry;
  3795. // update properties
  3796. setProperties(businessObject, oldProperties);
  3797. if (ID in oldProperties) {
  3798. elementRegistry.updateId(element, oldProperties[ID]);
  3799. }
  3800. return context.changed;
  3801. };
  3802. },{"218":218,"340":340,"346":346}],32:[function(_dereq_,module,exports){
  3803. module.exports = {
  3804. __init__: [ 'modeling', 'bpmnUpdater', 'bpmnLabelSupport' ],
  3805. __depends__: [
  3806. _dereq_(14),
  3807. _dereq_(34),
  3808. _dereq_(29),
  3809. _dereq_(80),
  3810. _dereq_(168),
  3811. _dereq_(112),
  3812. _dereq_(91),
  3813. _dereq_(159),
  3814. _dereq_(98)
  3815. ],
  3816. bpmnFactory: [ 'type', _dereq_(15) ],
  3817. bpmnUpdater: [ 'type', _dereq_(18) ],
  3818. elementFactory: [ 'type', _dereq_(19) ],
  3819. modeling: [ 'type', _dereq_(20) ],
  3820. bpmnLabelSupport: [ 'type', _dereq_(16) ],
  3821. layouter: [ 'type', _dereq_(17) ],
  3822. connectionDocking: [ 'type', _dereq_(173) ]
  3823. };
  3824. },{"112":112,"14":14,"15":15,"159":159,"16":16,"168":168,"17":17,"173":173,"18":18,"19":19,"20":20,"29":29,"34":34,"80":80,"91":91,"98":98}],33:[function(_dereq_,module,exports){
  3825. 'use strict';
  3826. var groupBy = _dereq_(219),
  3827. size = _dereq_(223),
  3828. find = _dereq_(217),
  3829. any = _dereq_(214),
  3830. inherits = _dereq_(207);
  3831. var getParents = _dereq_(21).getParents,
  3832. is = _dereq_(50).is,
  3833. getBusinessObject = _dereq_(50).getBusinessObject,
  3834. isExpanded = _dereq_(48).isExpanded;
  3835. var RuleProvider = _dereq_(153);
  3836. var isBoundaryAttachment = _dereq_(41).getBoundaryAttachment;
  3837. /**
  3838. * BPMN specific modeling rule
  3839. */
  3840. function BpmnRules(eventBus) {
  3841. RuleProvider.call(this, eventBus);
  3842. }
  3843. inherits(BpmnRules, RuleProvider);
  3844. BpmnRules.$inject = [ 'eventBus' ];
  3845. module.exports = BpmnRules;
  3846. BpmnRules.prototype.init = function() {
  3847. this.addRule('connection.create', function(context) {
  3848. var source = context.source,
  3849. target = context.target;
  3850. return canConnect(source, target);
  3851. });
  3852. this.addRule('connection.reconnectStart', function(context) {
  3853. var connection = context.connection,
  3854. source = context.hover || context.source,
  3855. target = connection.target;
  3856. return canConnect(source, target, connection);
  3857. });
  3858. this.addRule('connection.reconnectEnd', function(context) {
  3859. var connection = context.connection,
  3860. source = connection.source,
  3861. target = context.hover || context.target;
  3862. return canConnect(source, target, connection);
  3863. });
  3864. this.addRule('connection.updateWaypoints', function(context) {
  3865. // OK! but visually ignore
  3866. return null;
  3867. });
  3868. this.addRule('shape.resize', function(context) {
  3869. var shape = context.shape,
  3870. newBounds = context.newBounds;
  3871. return canResize(shape, newBounds);
  3872. });
  3873. this.addRule('shapes.move', function(context) {
  3874. var target = context.target,
  3875. shapes = context.shapes,
  3876. position = context.position;
  3877. return canAttach(shapes, target, null, position) || canMove(shapes, target, position);
  3878. });
  3879. this.addRule([ 'shape.create', 'shape.append' ], function(context) {
  3880. var target = context.target,
  3881. shape = context.shape,
  3882. source = context.source,
  3883. position = context.position;
  3884. return canAttach([ shape ], target, source, position) || canCreate(shape, target, source, position);
  3885. });
  3886. };
  3887. BpmnRules.prototype.canConnectMessageFlow = canConnectMessageFlow;
  3888. BpmnRules.prototype.canConnectSequenceFlow = canConnectSequenceFlow;
  3889. BpmnRules.prototype.canConnectAssociation = canConnectAssociation;
  3890. BpmnRules.prototype.canMove = canMove;
  3891. BpmnRules.prototype.canAttach = canAttach;
  3892. BpmnRules.prototype.canDrop = canDrop;
  3893. BpmnRules.prototype.canInsert = canInsert;
  3894. BpmnRules.prototype.canCreate = canCreate;
  3895. BpmnRules.prototype.canConnect = canConnect;
  3896. BpmnRules.prototype.canResize = canResize;
  3897. /**
  3898. * Utility functions for rule checking
  3899. */
  3900. function nonExistantOrLabel(element) {
  3901. return !element || isLabel(element);
  3902. }
  3903. function isSame(a, b) {
  3904. return a === b;
  3905. }
  3906. function getOrganizationalParent(element) {
  3907. var bo = getBusinessObject(element);
  3908. while (bo && !is(bo, 'bpmn:Process')) {
  3909. if (is(bo, 'bpmn:Participant')) {
  3910. return bo.processRef || bo;
  3911. }
  3912. bo = bo.$parent;
  3913. }
  3914. return bo;
  3915. }
  3916. function isSameOrganization(a, b) {
  3917. var parentA = getOrganizationalParent(a),
  3918. parentB = getOrganizationalParent(b);
  3919. return parentA === parentB;
  3920. }
  3921. function isMessageFlowSource(element) {
  3922. return is(element, 'bpmn:InteractionNode') && (
  3923. !is(element, 'bpmn:Event') || (
  3924. is(element, 'bpmn:ThrowEvent') &&
  3925. hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
  3926. )
  3927. );
  3928. }
  3929. function isMessageFlowTarget(element) {
  3930. return is(element, 'bpmn:InteractionNode') && (
  3931. !is(element, 'bpmn:Event') || (
  3932. is(element, 'bpmn:CatchEvent') &&
  3933. hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
  3934. )
  3935. );
  3936. }
  3937. function getScopeParent(element) {
  3938. var bo = getBusinessObject(element);
  3939. if (is(bo, 'bpmn:Participant')) {
  3940. return null;
  3941. }
  3942. while (bo) {
  3943. bo = bo.$parent;
  3944. if (is(bo, 'bpmn:FlowElementsContainer')) {
  3945. return bo;
  3946. }
  3947. }
  3948. return bo;
  3949. }
  3950. function isSameScope(a, b) {
  3951. var scopeParentA = getScopeParent(a),
  3952. scopeParentB = getScopeParent(b);
  3953. return scopeParentA && (scopeParentA === scopeParentB);
  3954. }
  3955. function hasEventDefinition(element, eventDefinition) {
  3956. var bo = getBusinessObject(element);
  3957. return !!find(bo.eventDefinitions || [], function(definition) {
  3958. return is(definition, eventDefinition);
  3959. });
  3960. }
  3961. function hasEventDefinitionOrNone(element, eventDefinition) {
  3962. var bo = getBusinessObject(element);
  3963. return (bo.eventDefinitions || []).every(function(definition) {
  3964. return is(definition, eventDefinition);
  3965. });
  3966. }
  3967. function isSequenceFlowSource(element) {
  3968. return is(element, 'bpmn:FlowNode') && !is(element, 'bpmn:EndEvent') &&
  3969. !(is(element, 'bpmn:IntermediateThrowEvent') &&
  3970. hasEventDefinition(element, 'bpmn:LinkEventDefinition')
  3971. );
  3972. }
  3973. function isSequenceFlowTarget(element) {
  3974. return is(element, 'bpmn:FlowNode') &&
  3975. !is(element, 'bpmn:StartEvent') &&
  3976. !is(element, 'bpmn:BoundaryEvent') &&
  3977. !(is(element, 'bpmn:IntermediateCatchEvent') &&
  3978. hasEventDefinition(element, 'bpmn:LinkEventDefinition'));
  3979. }
  3980. function isEventBasedTarget(element) {
  3981. return is(element, 'bpmn:ReceiveTask') || (
  3982. is(element, 'bpmn:IntermediateCatchEvent') && (
  3983. hasEventDefinition(element, 'bpmn:MessageEventDefinition') ||
  3984. hasEventDefinition(element, 'bpmn:TimerEventDefinition') ||
  3985. hasEventDefinition(element, 'bpmn:ConditionalEventDefinition') ||
  3986. hasEventDefinition(element, 'bpmn:SignalEventDefinition')
  3987. )
  3988. );
  3989. }
  3990. function isLabel(element) {
  3991. return element.labelTarget;
  3992. }
  3993. function isConnection(element) {
  3994. return element.waypoints;
  3995. }
  3996. function isParent(possibleParent, element) {
  3997. var allParents = getParents(element);
  3998. return allParents.indexOf(possibleParent) !== -1;
  3999. }
  4000. function canConnect(source, target, connection) {
  4001. if (nonExistantOrLabel(source) || nonExistantOrLabel(target)) {
  4002. return null;
  4003. }
  4004. // See https://github.com/bpmn-io/bpmn-js/issues/178
  4005. // as a workround we disallow connections with same
  4006. // target and source element.
  4007. // This rule must be removed if a auto layout for this
  4008. // connections is implemented.
  4009. if (isSame(source, target)) {
  4010. return false;
  4011. }
  4012. if (canConnectMessageFlow(source, target) ||
  4013. canConnectSequenceFlow(source, target)) {
  4014. return true;
  4015. }
  4016. if (is(connection, 'bpmn:Association')) {
  4017. return canConnectAssociation(source, target);
  4018. }
  4019. return false;
  4020. }
  4021. /**
  4022. * Can an element be dropped into the target element
  4023. *
  4024. * @return {Boolean}
  4025. */
  4026. function canDrop(element, target) {
  4027. // can move labels everywhere
  4028. if (isLabel(element) && !isConnection(target)) {
  4029. return true;
  4030. }
  4031. // allow to create new participants on
  4032. // on existing collaboration and process diagrams
  4033. if (is(element, 'bpmn:Participant')) {
  4034. return is(target, 'bpmn:Process') || is(target, 'bpmn:Collaboration');
  4035. }
  4036. if (is(element, 'bpmn:BoundaryEvent')) {
  4037. return false;
  4038. }
  4039. // drop flow elements onto flow element containers
  4040. // and participants
  4041. if (is(element, 'bpmn:FlowElement')) {
  4042. if (is(target, 'bpmn:FlowElementsContainer')) {
  4043. return isExpanded(target) !== false;
  4044. }
  4045. return is(target, 'bpmn:Participant');
  4046. }
  4047. if (is(element, 'bpmn:Artifact')) {
  4048. return is(target, 'bpmn:Collaboration') ||
  4049. is(target, 'bpmn:Participant') ||
  4050. is(target, 'bpmn:Process');
  4051. }
  4052. if (is(element, 'bpmn:MessageFlow')) {
  4053. return is(target, 'bpmn:Collaboration');
  4054. }
  4055. return false;
  4056. }
  4057. function isBoundaryEvent(element) {
  4058. return !isLabel(element) && is(element, 'bpmn:BoundaryEvent');
  4059. }
  4060. /**
  4061. * We treat IntermediateThrowEvents as boundary events during create,
  4062. * this must be reflected in the rules.
  4063. */
  4064. function isBoundaryCandidate(element) {
  4065. return isBoundaryEvent(element) ||
  4066. (is(element, 'bpmn:IntermediateThrowEvent') && !element.parent);
  4067. }
  4068. function canAttach(elements, target, source, position) {
  4069. // disallow appending as boundary event
  4070. if (source) {
  4071. return false;
  4072. }
  4073. // only (re-)attach one element at a time
  4074. if (elements.length !== 1) {
  4075. return false;
  4076. }
  4077. var element = elements[0];
  4078. // do not attach labels
  4079. if (isLabel(element)) {
  4080. return false;
  4081. }
  4082. // only handle boundary events
  4083. if (!isBoundaryCandidate(element)) {
  4084. return false;
  4085. }
  4086. // allow default move operation
  4087. if (!target) {
  4088. return true;
  4089. }
  4090. // only allow drop on activities
  4091. if (!is(target, 'bpmn:Activity')) {
  4092. return false;
  4093. }
  4094. // only attach to subprocess border
  4095. if (position && !isBoundaryAttachment(position, target)) {
  4096. return false;
  4097. }
  4098. return 'attach';
  4099. }
  4100. function canMove(elements, target) {
  4101. // only move if they have the same parent
  4102. if (!haveSameParent(elements)) {
  4103. return false;
  4104. }
  4105. // do not move selection containing boundary events
  4106. if (any(elements, isBoundaryEvent)) {
  4107. return false;
  4108. }
  4109. // allow default move check to start move operation
  4110. if (!target) {
  4111. return true;
  4112. }
  4113. return elements.every(function(element) {
  4114. return canDrop(element, target);
  4115. });
  4116. }
  4117. function canCreate(shape, target, source, position) {
  4118. if (!target) {
  4119. return false;
  4120. }
  4121. if (isLabel(target)) {
  4122. return null;
  4123. }
  4124. if (isSame(source, target)) {
  4125. return false;
  4126. }
  4127. // ensure we do not drop the element
  4128. // into source
  4129. if (source && isParent(source, target)) {
  4130. return false;
  4131. }
  4132. return canDrop(shape, target, position) || canInsert(shape, target, position);
  4133. }
  4134. function canResize(shape, newBounds) {
  4135. if (is(shape, 'bpmn:SubProcess')) {
  4136. return (!!isExpanded(shape)) && (
  4137. !newBounds || (newBounds.width >= 100 && newBounds.height >= 80)
  4138. );
  4139. }
  4140. if (is(shape, 'bpmn:Participant')) {
  4141. return !newBounds || (newBounds.width >= 100 && newBounds.height >= 80);
  4142. }
  4143. if (is(shape, 'bpmn:TextAnnotation')) {
  4144. return true;
  4145. }
  4146. return false;
  4147. }
  4148. function canConnectAssociation(source, target) {
  4149. // do not connect connections
  4150. if (isConnection(source) || isConnection(target)) {
  4151. return false;
  4152. }
  4153. // connect if different parent
  4154. return !isParent(target, source) &&
  4155. !isParent(source, target);
  4156. }
  4157. function canConnectMessageFlow(source, target) {
  4158. return isMessageFlowSource(source) &&
  4159. isMessageFlowTarget(target) &&
  4160. !isSameOrganization(source, target);
  4161. }
  4162. function canConnectSequenceFlow(source, target) {
  4163. return isSequenceFlowSource(source) &&
  4164. isSequenceFlowTarget(target) &&
  4165. isSameScope(source, target) &&
  4166. !(is(source, 'bpmn:EventBasedGateway') && !isEventBasedTarget(target));
  4167. }
  4168. function canInsert(shape, flow, position) {
  4169. // return true if we can drop on the
  4170. // underlying flow parent
  4171. //
  4172. // at this point we are not really able to talk
  4173. // about connection rules (yet)
  4174. return (
  4175. is(flow, 'bpmn:SequenceFlow') ||
  4176. is(flow, 'bpmn:MessageFlow')
  4177. ) && is(shape, 'bpmn:FlowNode') && !is(shape, 'bpmn:BoundaryEvent') &&
  4178. canDrop(shape, flow.parent, position);
  4179. }
  4180. function haveSameParent(elements) {
  4181. return size(groupBy(elements, function(e) { return e.parent && e.parent.id; })) === 1;
  4182. }
  4183. },{"153":153,"207":207,"21":21,"214":214,"217":217,"219":219,"223":223,"41":41,"48":48,"50":50}],34:[function(_dereq_,module,exports){
  4184. module.exports = {
  4185. __depends__: [
  4186. _dereq_(155)
  4187. ],
  4188. __init__: [ 'bpmnRules' ],
  4189. bpmnRules: [ 'type', _dereq_(33) ]
  4190. };
  4191. },{"155":155,"33":33}],35:[function(_dereq_,module,exports){
  4192. 'use strict';
  4193. var assign = _dereq_(339);
  4194. /**
  4195. * A palette provider for BPMN 2.0 elements.
  4196. */
  4197. function PaletteProvider(palette, create, elementFactory, spaceTool, lassoTool) {
  4198. this._create = create;
  4199. this._elementFactory = elementFactory;
  4200. this._spaceTool = spaceTool;
  4201. this._lassoTool = lassoTool;
  4202. palette.registerProvider(this);
  4203. }
  4204. module.exports = PaletteProvider;
  4205. PaletteProvider.$inject = [ 'palette', 'create', 'elementFactory', 'spaceTool', 'lassoTool' ];
  4206. PaletteProvider.prototype.getPaletteEntries = function(element) {
  4207. var actions = {},
  4208. create = this._create,
  4209. elementFactory = this._elementFactory,
  4210. spaceTool = this._spaceTool,
  4211. lassoTool = this._lassoTool;
  4212. function createAction(type, group, className, title, options) {
  4213. function createListener(event) {
  4214. var shape = elementFactory.createShape(assign({ type: type }, options));
  4215. if (options) {
  4216. shape.businessObject.di.isExpanded = options.isExpanded;
  4217. }
  4218. create.start(event, shape);
  4219. }
  4220. var shortType = type.replace(/^bpmn\:/, '');
  4221. return {
  4222. group: group,
  4223. className: className,
  4224. title: title || 'Create ' + shortType,
  4225. action: {
  4226. dragstart: createListener,
  4227. click: createListener
  4228. }
  4229. };
  4230. }
  4231. function createParticipant(event, collapsed) {
  4232. create.start(event, elementFactory.createParticipantShape(collapsed));
  4233. }
  4234. assign(actions, {
  4235. 'lasso-tool': {
  4236. group: 'tools',
  4237. className: 'icon-lasso-tool',
  4238. title: 'Activate the lasso tool',
  4239. action: {
  4240. click: function(event) {
  4241. lassoTool.activateSelection(event);
  4242. }
  4243. }
  4244. },
  4245. 'space-tool': {
  4246. group: 'tools',
  4247. className: 'icon-space-tool',
  4248. title: 'Activate the create/remove space tool',
  4249. action: {
  4250. click: function(event) {
  4251. spaceTool.activateSelection(event);
  4252. }
  4253. }
  4254. },
  4255. 'tool-separator': {
  4256. group: 'tools',
  4257. separator: true
  4258. },
  4259. 'create.start-event': createAction(
  4260. 'bpmn:StartEvent', 'event', 'icon-start-event-none'
  4261. ),
  4262. 'create.intermediate-event': createAction(
  4263. 'bpmn:IntermediateThrowEvent', 'event', 'icon-intermediate-event-none'
  4264. ),
  4265. 'create.end-event': createAction(
  4266. 'bpmn:EndEvent', 'event', 'icon-end-event-none'
  4267. ),
  4268. 'create.exclusive-gateway': createAction(
  4269. 'bpmn:ExclusiveGateway', 'gateway', 'icon-gateway-xor'
  4270. ),
  4271. 'create.task': createAction(
  4272. 'bpmn:Task', 'activity', 'icon-task'
  4273. ),
  4274. 'create.subprocess-expanded': createAction(
  4275. 'bpmn:SubProcess', 'activity', 'icon-subprocess-expanded', 'Create expanded SubProcess',
  4276. { isExpanded: true }
  4277. ),
  4278. 'create.participant-expanded': {
  4279. group: 'collaboration',
  4280. className: 'icon-participant',
  4281. title: 'Create Pool/Participant',
  4282. action: {
  4283. dragstart: createParticipant,
  4284. click: createParticipant
  4285. }
  4286. }
  4287. });
  4288. return actions;
  4289. };
  4290. },{"339":339}],36:[function(_dereq_,module,exports){
  4291. module.exports = {
  4292. __depends__: [
  4293. _dereq_(145),
  4294. _dereq_(104),
  4295. _dereq_(166),
  4296. _dereq_(114)
  4297. ],
  4298. __init__: [ 'paletteProvider' ],
  4299. paletteProvider: [ 'type', _dereq_(35) ]
  4300. };
  4301. },{"104":104,"114":114,"145":145,"166":166,"35":35}],37:[function(_dereq_,module,exports){
  4302. 'use strict';
  4303. var forEach = _dereq_(218),
  4304. filter = _dereq_(216),
  4305. pick = _dereq_(345),
  4306. assign = _dereq_(339);
  4307. var REPLACE_OPTIONS = _dereq_(38);
  4308. var startEventReplace = REPLACE_OPTIONS.START_EVENT,
  4309. intermediateEventReplace = REPLACE_OPTIONS.INTERMEDIATE_EVENT,
  4310. endEventReplace = REPLACE_OPTIONS.END_EVENT,
  4311. gatewayReplace = REPLACE_OPTIONS.GATEWAY,
  4312. taskReplace = REPLACE_OPTIONS.TASK,
  4313. subProcessExpandedReplace = REPLACE_OPTIONS.SUBPROCESS_EXPANDED,
  4314. transactionReplace = REPLACE_OPTIONS.TRANSACTION,
  4315. boundaryEventReplace = REPLACE_OPTIONS.BOUNDARY_EVENT;
  4316. var is = _dereq_(50).is,
  4317. getBusinessObject = _dereq_(50).getBusinessObject,
  4318. isExpanded = _dereq_(48).isExpanded;
  4319. var CUSTOM_PROPERTIES = [
  4320. 'cancelActivity',
  4321. 'instantiate',
  4322. 'eventGatewayType'
  4323. ];
  4324. /**
  4325. * A replace menu provider that gives users the controls to choose
  4326. * and replace BPMN elements with each other.
  4327. *
  4328. * @param {BpmnFactory} bpmnFactory
  4329. * @param {Moddle} moddle
  4330. * @param {PopupMenu} popupMenu
  4331. * @param {Replace} replace
  4332. */
  4333. function BpmnReplace(bpmnFactory, moddle, popupMenu, replace, selection, modeling, eventBus) {
  4334. var self = this,
  4335. currentElement;
  4336. /**
  4337. * Prepares a new business object for the replacement element
  4338. * and triggers the replace operation.
  4339. *
  4340. * @param {djs.model.Base} element
  4341. * @param {Object} target
  4342. * @return {djs.model.Base} the newly created element
  4343. */
  4344. function replaceElement(element, target) {
  4345. var type = target.type,
  4346. oldBusinessObject = element.businessObject,
  4347. businessObject = bpmnFactory.create(type);
  4348. var newElement = {
  4349. type: type,
  4350. businessObject: businessObject
  4351. };
  4352. // initialize custom BPMN extensions
  4353. if (target.eventDefinition) {
  4354. var eventDefinitions = businessObject.get('eventDefinitions'),
  4355. eventDefinition = moddle.create(target.eventDefinition);
  4356. eventDefinitions.push(eventDefinition);
  4357. }
  4358. // initialize special properties defined in target definition
  4359. assign(businessObject, pick(target, CUSTOM_PROPERTIES));
  4360. // copy size (for activities only)
  4361. if (is(oldBusinessObject, 'bpmn:Activity')) {
  4362. // TODO: need also to respect min/max Size
  4363. newElement.width = element.width;
  4364. newElement.height = element.height;
  4365. }
  4366. if (is(oldBusinessObject, 'bpmn:SubProcess')) {
  4367. newElement.isExpanded = isExpanded(oldBusinessObject);
  4368. }
  4369. // TODO: copy other elligable properties from old business object
  4370. businessObject.name = oldBusinessObject.name;
  4371. businessObject.loopCharacteristics = oldBusinessObject.loopCharacteristics;
  4372. newElement = replace.replaceElement(element, newElement);
  4373. selection.select(newElement);
  4374. return newElement;
  4375. }
  4376. function toggleLoopEntry(event, entry) {
  4377. var loopEntries = self.getLoopEntries(currentElement);
  4378. var loopCharacteristics;
  4379. if (entry.active) {
  4380. loopCharacteristics = undefined;
  4381. } else {
  4382. forEach(loopEntries, function(action) {
  4383. var options = action.options;
  4384. if (entry.id === action.id) {
  4385. loopCharacteristics = moddle.create(options.loopCharacteristics);
  4386. if (options.isSequential) {
  4387. loopCharacteristics.isSequential = options.isSequential;
  4388. }
  4389. }
  4390. });
  4391. }
  4392. modeling.updateProperties(currentElement, { loopCharacteristics: loopCharacteristics });
  4393. }
  4394. function getLoopEntries(element) {
  4395. currentElement = element;
  4396. var businessObject = getBusinessObject(element),
  4397. loopCharacteristics = businessObject.loopCharacteristics;
  4398. var isSequential,
  4399. isLoop,
  4400. isParallel;
  4401. if (loopCharacteristics) {
  4402. isSequential = loopCharacteristics.isSequential;
  4403. isLoop = loopCharacteristics.isSequential === undefined;
  4404. isParallel = loopCharacteristics.isSequential !== undefined && !loopCharacteristics.isSequential;
  4405. }
  4406. var loopEntries = [
  4407. {
  4408. id: 'toggle-parallel-mi',
  4409. className: 'icon-parallel-mi-marker',
  4410. active: isParallel,
  4411. action: toggleLoopEntry,
  4412. options: {
  4413. loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
  4414. isSequential: false
  4415. }
  4416. },
  4417. {
  4418. id: 'toggle-sequential-mi',
  4419. className: 'icon-sequential-mi-marker',
  4420. active: isSequential,
  4421. action: toggleLoopEntry,
  4422. options: {
  4423. loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
  4424. isSequential: true
  4425. }
  4426. },
  4427. {
  4428. id: 'toggle-loop',
  4429. className: 'icon-loop-marker',
  4430. active: isLoop,
  4431. action: toggleLoopEntry,
  4432. options: {
  4433. loopCharacteristics: 'bpmn:StandardLoopCharacteristics'
  4434. }
  4435. }
  4436. ];
  4437. return loopEntries;
  4438. }
  4439. function getAdHocEntry(element) {
  4440. var businessObject = getBusinessObject(element);
  4441. var isAdHoc = is(businessObject, 'bpmn:AdHocSubProcess');
  4442. var adHocEntry = {
  4443. id: 'toggle-adhoc',
  4444. className: 'icon-ad-hoc-marker',
  4445. active: isAdHoc,
  4446. action: function(event, entry) {
  4447. if (isAdHoc) {
  4448. return replaceElement(element, { type: 'bpmn:SubProcess' });
  4449. } else {
  4450. return replaceElement(element, { type: 'bpmn:AdHocSubProcess' });
  4451. }
  4452. }
  4453. };
  4454. return adHocEntry;
  4455. }
  4456. function getReplaceOptions(element) {
  4457. var menuEntries = [];
  4458. var businessObject = element.businessObject;
  4459. if (is(businessObject, 'bpmn:StartEvent')) {
  4460. addEntries(startEventReplace, filterEvents);
  4461. } else
  4462. if (is(businessObject, 'bpmn:IntermediateCatchEvent') ||
  4463. is(businessObject, 'bpmn:IntermediateThrowEvent')) {
  4464. addEntries(intermediateEventReplace, filterEvents);
  4465. } else
  4466. if (is(businessObject, 'bpmn:EndEvent')) {
  4467. addEntries(endEventReplace, filterEvents);
  4468. } else
  4469. if (is(businessObject, 'bpmn:Gateway')) {
  4470. addEntries(gatewayReplace, function(entry) {
  4471. return entry.target.type !== businessObject.$type;
  4472. });
  4473. } else
  4474. if (is(businessObject, 'bpmn:Transaction')) {
  4475. addEntries(transactionReplace, filterEvents);
  4476. } else
  4477. if (is(businessObject, 'bpmn:SubProcess') && isExpanded(businessObject)) {
  4478. addEntries(subProcessExpandedReplace, filterEvents);
  4479. } else
  4480. if (is(businessObject, 'bpmn:AdHocSubProcess') && !isExpanded(businessObject)) {
  4481. addEntries(taskReplace, function(entry) {
  4482. return entry.target.type !== 'bpmn:SubProcess';
  4483. });
  4484. } else
  4485. if (is(businessObject, 'bpmn:BoundaryEvent')) {
  4486. addEntries(boundaryEventReplace, filterEvents);
  4487. } else
  4488. if (is(businessObject, 'bpmn:FlowNode')) {
  4489. addEntries(taskReplace, function(entry) {
  4490. return entry.target.type !== businessObject.$type;
  4491. });
  4492. }
  4493. function filterEvents(entry) {
  4494. var target = entry.target;
  4495. var eventDefinition = businessObject.eventDefinitions && businessObject.eventDefinitions[0].$type,
  4496. cancelActivity;
  4497. if (businessObject.$type === 'bpmn:BoundaryEvent') {
  4498. cancelActivity = target.cancelActivity !== false;
  4499. }
  4500. var isEventDefinitionEqual = target.eventDefinition == eventDefinition,
  4501. isEventTypeEqual = businessObject.$type == target.type,
  4502. isInterruptingEqual = businessObject.cancelActivity == cancelActivity;
  4503. return ((!isEventDefinitionEqual && isEventTypeEqual) ||
  4504. !isEventTypeEqual) ||
  4505. !(isEventDefinitionEqual && isEventTypeEqual && isInterruptingEqual);
  4506. }
  4507. function addEntries(entries, filterFun) {
  4508. // Filter selected type from the array
  4509. var filteredEntries = filter(entries, filterFun);
  4510. // Add entries to replace menu
  4511. forEach(filteredEntries, function(definition) {
  4512. var entry = addMenuEntry(definition);
  4513. menuEntries.push(entry);
  4514. });
  4515. }
  4516. function addMenuEntry(definition) {
  4517. return {
  4518. label: definition.label,
  4519. className: definition.className,
  4520. id: definition.actionName,
  4521. action: function() {
  4522. return replaceElement(element, definition.target);
  4523. }
  4524. };
  4525. }
  4526. return menuEntries;
  4527. }
  4528. /**
  4529. * [function description]
  4530. * @param {Object} position
  4531. * @param {Object} element
  4532. */
  4533. this.openChooser = function(position, element) {
  4534. var entries = this.getReplaceOptions(element),
  4535. headerEntries = [];
  4536. if (is(element, 'bpmn:Activity')) {
  4537. headerEntries = headerEntries.concat(this.getLoopEntries(element));
  4538. }
  4539. if (is(element, 'bpmn:SubProcess') && !is(element, 'bpmn:Transaction')) {
  4540. headerEntries.push(this.getAdHocEntry(element));
  4541. }
  4542. popupMenu.open({
  4543. className: 'replace-menu',
  4544. element: element,
  4545. position: position,
  4546. headerEntries: headerEntries,
  4547. entries: entries
  4548. });
  4549. };
  4550. this.getReplaceOptions = getReplaceOptions;
  4551. this.getLoopEntries = getLoopEntries;
  4552. this.getAdHocEntry = getAdHocEntry;
  4553. this.replaceElement = replaceElement;
  4554. }
  4555. BpmnReplace.$inject = [ 'bpmnFactory', 'moddle', 'popupMenu', 'replace', 'selection', 'modeling', 'eventBus' ];
  4556. module.exports = BpmnReplace;
  4557. },{"216":216,"218":218,"339":339,"345":345,"38":38,"48":48,"50":50}],38:[function(_dereq_,module,exports){
  4558. 'use strict';
  4559. module.exports.START_EVENT = [
  4560. {
  4561. label: 'Start Event',
  4562. actionName: 'replace-with-none-start',
  4563. className: 'icon-start-event-none',
  4564. target: {
  4565. type: 'bpmn:StartEvent'
  4566. }
  4567. },
  4568. {
  4569. label: 'Intermediate Throw Event',
  4570. actionName: 'replace-with-none-intermediate-throwing',
  4571. className: 'icon-intermediate-event-none',
  4572. target: {
  4573. type: 'bpmn:IntermediateThrowEvent'
  4574. }
  4575. },
  4576. {
  4577. label: 'End Event',
  4578. actionName: 'replace-with-none-end',
  4579. className: 'icon-end-event-none',
  4580. target: {
  4581. type: 'bpmn:EndEvent'
  4582. }
  4583. },
  4584. {
  4585. label: 'Message Start Event',
  4586. actionName: 'replace-with-message-start',
  4587. className: 'icon-start-event-message',
  4588. target: {
  4589. type: 'bpmn:StartEvent',
  4590. eventDefinition: 'bpmn:MessageEventDefinition'
  4591. }
  4592. },
  4593. {
  4594. label: 'Timer Start Event',
  4595. actionName: 'replace-with-timer-start',
  4596. className: 'icon-start-event-timer',
  4597. target: {
  4598. type: 'bpmn:StartEvent',
  4599. eventDefinition: 'bpmn:TimerEventDefinition'
  4600. }
  4601. },
  4602. {
  4603. label: 'Conditional Start Event',
  4604. actionName: 'replace-with-conditional-start',
  4605. className: 'icon-start-event-condition',
  4606. target: {
  4607. type: 'bpmn:StartEvent',
  4608. eventDefinition: 'bpmn:ConditionalEventDefinition'
  4609. }
  4610. },
  4611. {
  4612. label: 'Signal Start Event',
  4613. actionName: 'replace-with-signal-start',
  4614. className: 'icon-start-event-signal',
  4615. target: {
  4616. type: 'bpmn:StartEvent',
  4617. eventDefinition: 'bpmn:SignalEventDefinition'
  4618. }
  4619. }
  4620. ];
  4621. module.exports.INTERMEDIATE_EVENT = [
  4622. {
  4623. label: 'Start Event',
  4624. actionName: 'replace-with-none-start',
  4625. className: 'icon-start-event-none',
  4626. target: {
  4627. type: 'bpmn:StartEvent'
  4628. }
  4629. },
  4630. {
  4631. label: 'Intermediate Throw Event',
  4632. actionName: 'replace-with-none-intermediate-throw',
  4633. className: 'icon-intermediate-event-none',
  4634. target: {
  4635. type: 'bpmn:IntermediateThrowEvent'
  4636. }
  4637. },
  4638. {
  4639. label: 'End Event',
  4640. actionName: 'replace-with-none-end',
  4641. className: 'icon-end-event-none',
  4642. target: {
  4643. type: 'bpmn:EndEvent'
  4644. }
  4645. },
  4646. {
  4647. label: 'Message Intermediate Catch Event',
  4648. actionName: 'replace-with-message-intermediate-catch',
  4649. className: 'icon-intermediate-event-catch-message',
  4650. target: {
  4651. type: 'bpmn:IntermediateCatchEvent',
  4652. eventDefinition: 'bpmn:MessageEventDefinition'
  4653. }
  4654. },
  4655. {
  4656. label: 'Message Intermediate Throw Event',
  4657. actionName: 'replace-with-message-intermediate-throw',
  4658. className: 'icon-intermediate-event-throw-message',
  4659. target: {
  4660. type: 'bpmn:IntermediateThrowEvent',
  4661. eventDefinition: 'bpmn:MessageEventDefinition'
  4662. }
  4663. },
  4664. {
  4665. label: 'Timer Intermediate Catch Event',
  4666. actionName: 'replace-with-timer-intermediate-catch',
  4667. className: 'icon-intermediate-event-catch-timer',
  4668. target: {
  4669. type: 'bpmn:IntermediateCatchEvent',
  4670. eventDefinition: 'bpmn:TimerEventDefinition'
  4671. }
  4672. },
  4673. {
  4674. label: 'Escalation Intermediate Catch Event',
  4675. actionName: 'replace-with-escalation-intermediate-catch',
  4676. className: 'icon-intermediate-event-catch-escalation',
  4677. target: {
  4678. type: 'bpmn:IntermediateCatchEvent',
  4679. eventDefinition: 'bpmn:EscalationEventDefinition'
  4680. }
  4681. },
  4682. {
  4683. label: 'Conditional Intermediate Catch Event',
  4684. actionName: 'replace-with-conditional-intermediate-catch',
  4685. className: 'icon-intermediate-event-catch-condition',
  4686. target: {
  4687. type: 'bpmn:IntermediateCatchEvent',
  4688. eventDefinition: 'bpmn:ConditionalEventDefinition'
  4689. }
  4690. },
  4691. {
  4692. label: 'Link Intermediate Catch Event',
  4693. actionName: 'replace-with-link-intermediate-catch',
  4694. className: 'icon-intermediate-event-catch-link',
  4695. target: {
  4696. type: 'bpmn:IntermediateCatchEvent',
  4697. eventDefinition: 'bpmn:LinkEventDefinition'
  4698. }
  4699. },
  4700. {
  4701. label: 'Link Intermediate Throw Event',
  4702. actionName: 'replace-with-link-intermediate-throw',
  4703. className: 'icon-intermediate-event-throw-link',
  4704. target: {
  4705. type: 'bpmn:IntermediateThrowEvent',
  4706. eventDefinition: 'bpmn:LinkEventDefinition'
  4707. }
  4708. },
  4709. {
  4710. label: 'Compensation Intermediate Throw Event',
  4711. actionName: 'replace-with-compensation-intermediate-throw',
  4712. className: 'icon-intermediate-event-throw-compensation',
  4713. target: {
  4714. type: 'bpmn:IntermediateThrowEvent',
  4715. eventDefinition: 'bpmn:CompensateEventDefinition'
  4716. }
  4717. },
  4718. {
  4719. label: 'Signal Intermediate Catch Event',
  4720. actionName: 'replace-with-signal-intermediate-catch',
  4721. className: 'icon-intermediate-event-catch-signal',
  4722. target: {
  4723. type: 'bpmn:IntermediateCatchEvent',
  4724. eventDefinition: 'bpmn:SignalEventDefinition'
  4725. }
  4726. },
  4727. {
  4728. label: 'Signal Intermediate Throw Event',
  4729. actionName: 'replace-with-signal-intermediate-throw',
  4730. className: 'icon-intermediate-event-throw-signal',
  4731. target: {
  4732. type: 'bpmn:IntermediateThrowEvent',
  4733. eventDefinition: 'bpmn:SignalEventDefinition'
  4734. }
  4735. }
  4736. ];
  4737. module.exports.END_EVENT = [
  4738. {
  4739. label: 'Start Event',
  4740. actionName: 'replace-with-none-start',
  4741. className: 'icon-start-event-none',
  4742. target: {
  4743. type: 'bpmn:StartEvent'
  4744. }
  4745. },
  4746. {
  4747. label: 'Intermediate Throw Event',
  4748. actionName: 'replace-with-none-intermediate-throw',
  4749. className: 'icon-intermediate-event-none',
  4750. target: {
  4751. type: 'bpmn:IntermediateThrowEvent'
  4752. }
  4753. },
  4754. {
  4755. label: 'End Event',
  4756. actionName: 'replace-with-none-end',
  4757. className: 'icon-end-event-none',
  4758. target: {
  4759. type: 'bpmn:EndEvent'
  4760. }
  4761. },
  4762. {
  4763. label: 'Message End Event',
  4764. actionName: 'replace-with-message-end',
  4765. className: 'icon-end-event-message',
  4766. target: {
  4767. type: 'bpmn:EndEvent',
  4768. eventDefinition: 'bpmn:MessageEventDefinition'
  4769. }
  4770. },
  4771. {
  4772. label: 'Escalation End Event',
  4773. actionName: 'replace-with-escalation-end',
  4774. className: 'icon-end-event-escalation',
  4775. target: {
  4776. type: 'bpmn:EndEvent',
  4777. eventDefinition: 'bpmn:EscalationEventDefinition'
  4778. }
  4779. },
  4780. {
  4781. label: 'Error End Event',
  4782. actionName: 'replace-with-error-end',
  4783. className: 'icon-end-event-error',
  4784. target: {
  4785. type: 'bpmn:EndEvent',
  4786. eventDefinition: 'bpmn:ErrorEventDefinition'
  4787. }
  4788. },
  4789. {
  4790. label: 'Cancel End Event',
  4791. actionName: 'replace-with-cancel-end',
  4792. className: 'icon-end-event-cancel',
  4793. target: {
  4794. type: 'bpmn:EndEvent',
  4795. eventDefinition: 'bpmn:CancelEventDefinition'
  4796. }
  4797. },
  4798. {
  4799. label: 'Compensation End Event',
  4800. actionName: 'replace-with-compensation-end',
  4801. className: 'icon-end-event-compensation',
  4802. target: {
  4803. type: 'bpmn:EndEvent',
  4804. eventDefinition: 'bpmn:CompensateEventDefinition'
  4805. }
  4806. },
  4807. {
  4808. label: 'Signal End Event',
  4809. actionName: 'replace-with-signal-end',
  4810. className: 'icon-end-event-signal',
  4811. target: {
  4812. type: 'bpmn:EndEvent',
  4813. eventDefinition: 'bpmn:SignalEventDefinition'
  4814. }
  4815. },
  4816. {
  4817. label: 'Terminate End Event',
  4818. actionName: 'replace-with-terminate-end',
  4819. className: 'icon-end-event-terminate',
  4820. target: {
  4821. type: 'bpmn:EndEvent',
  4822. eventDefinition: 'bpmn:TerminateEventDefinition'
  4823. }
  4824. }
  4825. ];
  4826. module.exports.GATEWAY = [
  4827. {
  4828. label: 'Exclusive Gateway',
  4829. actionName: 'replace-with-exclusive-gateway',
  4830. className: 'icon-gateway-xor',
  4831. target: {
  4832. type: 'bpmn:ExclusiveGateway'
  4833. }
  4834. },
  4835. {
  4836. label: 'Parallel Gateway',
  4837. actionName: 'replace-with-parallel-gateway',
  4838. className: 'icon-gateway-parallel',
  4839. target: {
  4840. type: 'bpmn:ParallelGateway'
  4841. }
  4842. },
  4843. {
  4844. label: 'Inclusive Gateway',
  4845. actionName: 'replace-with-inclusive-gateway',
  4846. className: 'icon-gateway-or',
  4847. target: {
  4848. type: 'bpmn:InclusiveGateway'
  4849. }
  4850. },
  4851. {
  4852. label: 'Complex Gateway',
  4853. actionName: 'replace-with-complex-gateway',
  4854. className: 'icon-gateway-complex',
  4855. target: {
  4856. type: 'bpmn:ComplexGateway'
  4857. }
  4858. },
  4859. {
  4860. label: 'Event based Gateway',
  4861. actionName: 'replace-with-event-based-gateway',
  4862. className: 'icon-gateway-eventbased',
  4863. target: {
  4864. type: 'bpmn:EventBasedGateway',
  4865. instantiate: false,
  4866. eventGatewayType: 'Exclusive'
  4867. }
  4868. }
  4869. // Gateways deactivated until https://github.com/bpmn-io/bpmn-js/issues/194
  4870. // {
  4871. // label: 'Event based instantiating Gateway',
  4872. // actionName: 'replace-with-exclusive-event-based-gateway',
  4873. // className: 'icon-exclusive-event-based',
  4874. // target: {
  4875. // type: 'bpmn:EventBasedGateway'
  4876. // },
  4877. // options: {
  4878. // businessObject: { instantiate: true, eventGatewayType: 'Exclusive' }
  4879. // }
  4880. // },
  4881. // {
  4882. // label: 'Parallel Event based instantiating Gateway',
  4883. // actionName: 'replace-with-parallel-event-based-instantiate-gateway',
  4884. // className: 'icon-parallel-event-based-instantiate-gateway',
  4885. // target: {
  4886. // type: 'bpmn:EventBasedGateway'
  4887. // },
  4888. // options: {
  4889. // businessObject: { instantiate: true, eventGatewayType: 'Parallel' }
  4890. // }
  4891. // }
  4892. ];
  4893. module.exports.SUBPROCESS_EXPANDED = [
  4894. {
  4895. label: 'Transaction',
  4896. actionName: 'replace-with-transaction',
  4897. className: 'icon-transaction',
  4898. target: {
  4899. type: 'bpmn:Transaction',
  4900. isExpanded: true
  4901. }
  4902. }
  4903. ];
  4904. module.exports.TRANSACTION = [
  4905. {
  4906. label: 'Sub Process',
  4907. actionName: 'replace-with-subprocess',
  4908. className: 'icon-subprocess-expanded',
  4909. target: {
  4910. type: 'bpmn:SubProcess'
  4911. }
  4912. }
  4913. ];
  4914. module.exports.TASK = [
  4915. {
  4916. label: 'Task',
  4917. actionName: 'replace-with-task',
  4918. className: 'icon-task',
  4919. target: {
  4920. type: 'bpmn:Task'
  4921. }
  4922. },
  4923. {
  4924. label: 'Send Task',
  4925. actionName: 'replace-with-send-task',
  4926. className: 'icon-send',
  4927. target: {
  4928. type: 'bpmn:SendTask'
  4929. }
  4930. },
  4931. {
  4932. label: 'Receive Task',
  4933. actionName: 'replace-with-receive-task',
  4934. className: 'icon-receive',
  4935. target: {
  4936. type: 'bpmn:ReceiveTask'
  4937. }
  4938. },
  4939. {
  4940. label: 'User Task',
  4941. actionName: 'replace-with-user-task',
  4942. className: 'icon-user',
  4943. target: {
  4944. type: 'bpmn:UserTask'
  4945. }
  4946. },
  4947. {
  4948. label: 'Manual Task',
  4949. actionName: 'replace-with-manual-task',
  4950. className: 'icon-manual',
  4951. target: {
  4952. type: 'bpmn:ManualTask'
  4953. }
  4954. },
  4955. {
  4956. label: 'Business Rule Task',
  4957. actionName: 'replace-with-rule-task',
  4958. className: 'icon-business-rule',
  4959. target: {
  4960. type: 'bpmn:BusinessRuleTask'
  4961. }
  4962. },
  4963. {
  4964. label: 'Service Task',
  4965. actionName: 'replace-with-service-task',
  4966. className: 'icon-service',
  4967. target: {
  4968. type: 'bpmn:ServiceTask'
  4969. }
  4970. },
  4971. {
  4972. label: 'Script Task',
  4973. actionName: 'replace-with-script-task',
  4974. className: 'icon-script',
  4975. target: {
  4976. type: 'bpmn:ScriptTask'
  4977. }
  4978. },
  4979. {
  4980. label: 'Call Activity',
  4981. actionName: 'replace-with-call-activity',
  4982. className: 'icon-call-activity',
  4983. target: {
  4984. type: 'bpmn:CallActivity'
  4985. }
  4986. },
  4987. {
  4988. label: 'Sub Process (collapsed)',
  4989. actionName: 'replace-with-collapsed-subprocess',
  4990. className: 'icon-subprocess-collapsed',
  4991. target: {
  4992. type: 'bpmn:SubProcess',
  4993. isExpanded: false
  4994. }
  4995. }
  4996. ];
  4997. module.exports.BOUNDARY_EVENT = [
  4998. {
  4999. label: 'Message Boundary Event',
  5000. actionName: 'replace-with-message-boundary',
  5001. className: 'icon-intermediate-event-catch-message',
  5002. target: {
  5003. type: 'bpmn:BoundaryEvent',
  5004. eventDefinition: 'bpmn:MessageEventDefinition'
  5005. }
  5006. },
  5007. {
  5008. label: 'Timer Boundary Event',
  5009. actionName: 'replace-with-timer-boundary',
  5010. className: 'icon-intermediate-event-catch-timer',
  5011. target: {
  5012. type: 'bpmn:BoundaryEvent',
  5013. eventDefinition: 'bpmn:TimerEventDefinition'
  5014. }
  5015. },
  5016. {
  5017. label: 'Escalation Boundary Event',
  5018. actionName: 'replace-with-escalation-boundary',
  5019. className: 'icon-intermediate-event-catch-escalation',
  5020. target: {
  5021. type: 'bpmn:BoundaryEvent',
  5022. eventDefinition: 'bpmn:EscalationEventDefinition'
  5023. }
  5024. },
  5025. {
  5026. label: 'Conditional Boundary Event',
  5027. actionName: 'replace-with-conditional-boundary',
  5028. className: 'icon-intermediate-event-catch-condition',
  5029. target: {
  5030. type: 'bpmn:BoundaryEvent',
  5031. eventDefinition: 'bpmn:ConditionalEventDefinition'
  5032. }
  5033. },
  5034. {
  5035. label: 'Error Boundary Event',
  5036. actionName: 'replace-with-error-boundary',
  5037. className: 'icon-intermediate-event-catch-error',
  5038. target: {
  5039. type: 'bpmn:BoundaryEvent',
  5040. eventDefinition: 'bpmn:ErrorEventDefinition'
  5041. }
  5042. },
  5043. {
  5044. label: 'Signal Boundary Event',
  5045. actionName: 'replace-with-signal-boundary',
  5046. className: 'icon-intermediate-event-catch-signal',
  5047. target: {
  5048. type: 'bpmn:BoundaryEvent',
  5049. eventDefinition: 'bpmn:SignalEventDefinition'
  5050. }
  5051. },
  5052. {
  5053. label: 'Message Boundary Event (non-interrupting)',
  5054. actionName: 'replace-with-non-interrupting-message-boundary',
  5055. className: 'icon-intermediate-event-catch-non-interrupting-message',
  5056. target: {
  5057. type: 'bpmn:BoundaryEvent',
  5058. eventDefinition: 'bpmn:MessageEventDefinition',
  5059. cancelActivity: false
  5060. }
  5061. },
  5062. {
  5063. label: 'Timer Boundary Event (non-interrupting)',
  5064. actionName: 'replace-with-non-interrupting-timer-boundary',
  5065. className: 'icon-intermediate-event-catch-non-interrupting-timer',
  5066. target: {
  5067. type: 'bpmn:BoundaryEvent',
  5068. eventDefinition: 'bpmn:TimerEventDefinition',
  5069. cancelActivity: false
  5070. }
  5071. },
  5072. {
  5073. label: 'Escalation Boundary Event (non-interrupting)',
  5074. actionName: 'replace-with-non-interrupting-escalation-boundary',
  5075. className: 'icon-intermediate-event-catch-non-interrupting-escalation',
  5076. target: {
  5077. type: 'bpmn:BoundaryEvent',
  5078. eventDefinition: 'bpmn:EscalationEventDefinition',
  5079. cancelActivity: false
  5080. }
  5081. },
  5082. {
  5083. label: 'Conditional Boundary Event (non-interrupting)',
  5084. actionName: 'replace-with-non-interrupting-conditional-boundary',
  5085. className: 'icon-intermediate-event-catch-non-interrupting-condition',
  5086. target: {
  5087. type: 'bpmn:BoundaryEvent',
  5088. eventDefinition: 'bpmn:ConditionalEventDefinition',
  5089. cancelActivity: false
  5090. }
  5091. },
  5092. {
  5093. label: 'Signal Boundary Event (non-interrupting)',
  5094. actionName: 'replace-with-non-interrupting-signal-boundary',
  5095. className: 'icon-intermediate-event-catch-non-interrupting-signal',
  5096. target: {
  5097. type: 'bpmn:BoundaryEvent',
  5098. eventDefinition: 'bpmn:SignalEventDefinition',
  5099. cancelActivity: false
  5100. }
  5101. },
  5102. ];
  5103. },{}],39:[function(_dereq_,module,exports){
  5104. module.exports = {
  5105. __depends__: [
  5106. _dereq_(147),
  5107. _dereq_(149),
  5108. _dereq_(159)
  5109. ],
  5110. bpmnReplace: [ 'type', _dereq_(37) ]
  5111. };
  5112. },{"147":147,"149":149,"159":159,"37":37}],40:[function(_dereq_,module,exports){
  5113. 'use strict';
  5114. var inherits = _dereq_(207);
  5115. var forEach = _dereq_(218);
  5116. var getBoundingBox = _dereq_(186).getBBox;
  5117. var is = _dereq_(21).is,
  5118. isExpanded = _dereq_(48).isExpanded;
  5119. var Snapping = _dereq_(162),
  5120. SnapUtil = _dereq_(161);
  5121. var is = _dereq_(50).is;
  5122. var round = Math.round;
  5123. var mid = SnapUtil.mid,
  5124. topLeft = SnapUtil.topLeft,
  5125. bottomRight = SnapUtil.bottomRight,
  5126. isSnapped = SnapUtil.isSnapped,
  5127. setSnapped = SnapUtil.setSnapped,
  5128. getBoundaryAttachment = _dereq_(41).getBoundaryAttachment;
  5129. /**
  5130. * BPMN specific snapping functionality
  5131. *
  5132. * * snap on process elements if a pool is created inside a
  5133. * process diagram
  5134. *
  5135. * @param {EventBus} eventBus
  5136. * @param {Canvas} canvas
  5137. */
  5138. function BpmnSnapping(eventBus, canvas, bpmnRules) {
  5139. // instantiate super
  5140. Snapping.call(this, eventBus, canvas);
  5141. /**
  5142. * Drop participant on process <> process elements snapping
  5143. */
  5144. eventBus.on('create.start', function(event) {
  5145. var context = event.context,
  5146. shape = context.shape,
  5147. rootElement = canvas.getRootElement();
  5148. // snap participant around existing elements (if any)
  5149. if (is(shape, 'bpmn:Participant') && is(rootElement, 'bpmn:Process')) {
  5150. initParticipantSnapping(context, shape, rootElement.children);
  5151. }
  5152. });
  5153. eventBus.on([ 'create.move', 'create.end' ], 1500, function(event) {
  5154. var context = event.context,
  5155. shape = context.shape,
  5156. participantSnapBox = context.participantSnapBox;
  5157. if (!isSnapped(event) && participantSnapBox) {
  5158. snapParticipant(participantSnapBox, shape, event);
  5159. }
  5160. });
  5161. eventBus.on('shape.move.start', function(event) {
  5162. var context = event.context,
  5163. shape = context.shape,
  5164. rootElement = canvas.getRootElement();
  5165. // snap participant around existing elements (if any)
  5166. if (is(shape, 'bpmn:Participant') && is(rootElement, 'bpmn:Process')) {
  5167. initParticipantSnapping(context, shape, rootElement.children);
  5168. }
  5169. });
  5170. function canAttach(shape, target, position) {
  5171. return bpmnRules.canAttach([ shape ], target, null, position) === 'attach';
  5172. }
  5173. /**
  5174. * Snap boundary events to elements border
  5175. */
  5176. eventBus.on([ 'create.move', 'create.end' ], 1500, function(event) {
  5177. var context = event.context,
  5178. target = context.target,
  5179. shape = context.shape;
  5180. if (target && !isSnapped(event) && canAttach(shape, target, event)) {
  5181. snapBoundaryEvent(event, shape, target);
  5182. }
  5183. });
  5184. eventBus.on([ 'shape.move.move', 'shape.move.end' ], 1500, function(event) {
  5185. var context = event.context,
  5186. target = context.target,
  5187. shape = context.shape;
  5188. if (target && !isSnapped(event) && canAttach(shape, target, event)) {
  5189. snapBoundaryEvent(event, shape, target);
  5190. }
  5191. });
  5192. eventBus.on('resize.start', 1500, function(event) {
  5193. var context = event.context,
  5194. shape = context.shape;
  5195. if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
  5196. context.minDimensions = { width: 140, height: 120 };
  5197. }
  5198. if (is(shape, 'bpmn:Participant')) {
  5199. context.minDimensions = { width: 300, height: 150 };
  5200. context.childrenBoxPadding = {
  5201. left: 50,
  5202. right: 35
  5203. };
  5204. }
  5205. if (is(shape, 'bpmn:TextAnnotation')) {
  5206. context.minDimensions = { width: 50, height: 50 };
  5207. }
  5208. });
  5209. }
  5210. inherits(BpmnSnapping, Snapping);
  5211. BpmnSnapping.$inject = [ 'eventBus', 'canvas', 'bpmnRules' ];
  5212. module.exports = BpmnSnapping;
  5213. BpmnSnapping.prototype.initSnap = function(event) {
  5214. var context = event.context,
  5215. shape = event.shape,
  5216. shapeMid,
  5217. shapeBounds,
  5218. shapeTopLeft,
  5219. shapeBottomRight,
  5220. snapContext;
  5221. snapContext = Snapping.prototype.initSnap.call(this, event);
  5222. if (is(shape, 'bpmn:Participant')) {
  5223. // assign higher priority for outer snaps on participants
  5224. snapContext.setSnapLocations([ 'top-left', 'bottom-right', 'mid' ]);
  5225. }
  5226. if (shape) {
  5227. shapeMid = mid(shape, event);
  5228. shapeBounds = {
  5229. width: shape.width,
  5230. height: shape.height,
  5231. x: isNaN(shape.x) ? round(shapeMid.x - shape.width / 2) : shape.x,
  5232. y: isNaN(shape.y) ? round(shapeMid.y - shape.height / 2) : shape.y,
  5233. };
  5234. shapeTopLeft = topLeft(shapeBounds);
  5235. shapeBottomRight = bottomRight(shapeBounds);
  5236. snapContext.setSnapOrigin('top-left', {
  5237. x: shapeTopLeft.x - event.x,
  5238. y: shapeTopLeft.y - event.y
  5239. });
  5240. snapContext.setSnapOrigin('bottom-right', {
  5241. x: shapeBottomRight.x - event.x,
  5242. y: shapeBottomRight.y - event.y
  5243. });
  5244. forEach(shape.outgoing, function(c) {
  5245. var docking = c.waypoints[0];
  5246. docking = docking.original || docking;
  5247. snapContext.setSnapOrigin(c.id + '-docking', {
  5248. x: docking.x - event.x,
  5249. y: docking.y - event.y
  5250. });
  5251. });
  5252. forEach(shape.incoming, function(c) {
  5253. var docking = c.waypoints[c.waypoints.length - 1];
  5254. docking = docking.original || docking;
  5255. snapContext.setSnapOrigin(c.id + '-docking', {
  5256. x: docking.x - event.x,
  5257. y: docking.y - event.y
  5258. });
  5259. });
  5260. }
  5261. var source = context.source;
  5262. if (source) {
  5263. snapContext.addDefaultSnap('mid', mid(source));
  5264. }
  5265. };
  5266. BpmnSnapping.prototype.addTargetSnaps = function(snapPoints, shape, target) {
  5267. // use target parent as snap target
  5268. if (is(shape, 'bpmn:BoundaryEvent')) {
  5269. target = target.parent;
  5270. }
  5271. // add sequence flow parents as snap targets
  5272. if (is(target, 'bpmn:SequenceFlow')) {
  5273. this.addTargetSnaps(snapPoints, shape, target.parent);
  5274. }
  5275. var siblings = this.getSiblings(shape, target) || [];
  5276. forEach(siblings, function(s) {
  5277. snapPoints.add('mid', mid(s));
  5278. if (is(s, 'bpmn:Participant')) {
  5279. snapPoints.add('top-left', topLeft(s));
  5280. snapPoints.add('bottom-right', bottomRight(s));
  5281. }
  5282. });
  5283. forEach(shape.incoming, function(c) {
  5284. if (siblings.indexOf(c.source) === -1) {
  5285. snapPoints.add('mid', mid(c.source));
  5286. }
  5287. var docking = c.waypoints[0];
  5288. snapPoints.add(c.id + '-docking', docking.original || docking);
  5289. });
  5290. forEach(shape.outgoing, function(c) {
  5291. if (siblings.indexOf(c.target) === -1) {
  5292. snapPoints.add('mid', mid(c.target));
  5293. }
  5294. var docking = c.waypoints[c.waypoints.length - 1];
  5295. snapPoints.add(c.id + '-docking', docking.original || docking);
  5296. });
  5297. };
  5298. /////// participant snapping //////////////////
  5299. function initParticipantSnapping(context, shape, elements) {
  5300. if (!elements.length) {
  5301. return;
  5302. }
  5303. var snapBox = getBoundingBox(elements.filter(function(e) {
  5304. return !e.labelTarget && !e.waypoints;
  5305. }));
  5306. snapBox.x -= 50;
  5307. snapBox.y -= 20;
  5308. snapBox.width += 70;
  5309. snapBox.height += 40;
  5310. // adjust shape height to include bounding box
  5311. shape.width = Math.max(shape.width, snapBox.width);
  5312. shape.height = Math.max(shape.height, snapBox.height);
  5313. context.participantSnapBox = snapBox;
  5314. }
  5315. function snapParticipant(snapBox, shape, event, offset) {
  5316. offset = offset || 0;
  5317. var shapeHalfWidth = shape.width / 2 - offset,
  5318. shapeHalfHeight = shape.height / 2;
  5319. var currentTopLeft = {
  5320. x: event.x - shapeHalfWidth - offset,
  5321. y: event.y - shapeHalfHeight
  5322. };
  5323. var currentBottomRight = {
  5324. x: event.x + shapeHalfWidth + offset,
  5325. y: event.y + shapeHalfHeight
  5326. };
  5327. var snapTopLeft = snapBox,
  5328. snapBottomRight = bottomRight(snapBox);
  5329. if (currentTopLeft.x >= snapTopLeft.x) {
  5330. setSnapped(event, 'x', snapTopLeft.x + offset + shapeHalfWidth);
  5331. } else
  5332. if (currentBottomRight.x <= snapBottomRight.x) {
  5333. setSnapped(event, 'x', snapBottomRight.x - offset - shapeHalfWidth);
  5334. }
  5335. if (currentTopLeft.y >= snapTopLeft.y) {
  5336. setSnapped(event, 'y', snapTopLeft.y + shapeHalfHeight);
  5337. } else
  5338. if (currentBottomRight.y <= snapBottomRight.y) {
  5339. setSnapped(event, 'y', snapBottomRight.y - shapeHalfHeight);
  5340. }
  5341. }
  5342. /////// boundary event snapping /////////////////////////
  5343. var LayoutUtil = _dereq_(174);
  5344. function snapBoundaryEvent(event, shape, target) {
  5345. var targetTRBL = LayoutUtil.asTRBL(target);
  5346. var direction = getBoundaryAttachment(event, target);
  5347. if (/top/.test(direction)) {
  5348. setSnapped(event, 'y', targetTRBL.top);
  5349. } else
  5350. if (/bottom/.test(direction)) {
  5351. setSnapped(event, 'y', targetTRBL.bottom);
  5352. }
  5353. if (/left/.test(direction)) {
  5354. setSnapped(event, 'x', targetTRBL.left);
  5355. } else
  5356. if (/right/.test(direction)) {
  5357. setSnapped(event, 'x', targetTRBL.right);
  5358. }
  5359. }
  5360. },{"161":161,"162":162,"174":174,"186":186,"207":207,"21":21,"218":218,"41":41,"48":48,"50":50}],41:[function(_dereq_,module,exports){
  5361. 'use strict';
  5362. var getOrientation = _dereq_(174).getOrientation;
  5363. module.exports.getBoundaryAttachment = function(position, targetBounds) {
  5364. var orientation = getOrientation(position, targetBounds, -15);
  5365. if (orientation !== 'intersect') {
  5366. return orientation;
  5367. } else {
  5368. return null;
  5369. }
  5370. };
  5371. },{"174":174}],42:[function(_dereq_,module,exports){
  5372. module.exports = {
  5373. __init__: [ 'snapping' ],
  5374. snapping: [ 'type', _dereq_(40) ]
  5375. };
  5376. },{"40":40}],43:[function(_dereq_,module,exports){
  5377. 'use strict';
  5378. var assign = _dereq_(339),
  5379. map = _dereq_(221);
  5380. var LabelUtil = _dereq_(49);
  5381. var is = _dereq_(50).is;
  5382. var hasExternalLabel = LabelUtil.hasExternalLabel,
  5383. getExternalLabelBounds = LabelUtil.getExternalLabelBounds,
  5384. isExpanded = _dereq_(48).isExpanded,
  5385. elementToString = _dereq_(46).elementToString;
  5386. function elementData(semantic, attrs) {
  5387. return assign({
  5388. id: semantic.id,
  5389. type: semantic.$type,
  5390. businessObject: semantic
  5391. }, attrs);
  5392. }
  5393. function collectWaypoints(waypoints) {
  5394. return map(waypoints, function(p) {
  5395. return { x: p.x, y: p.y };
  5396. });
  5397. }
  5398. function notYetDrawn(semantic, refSemantic, property) {
  5399. return new Error(
  5400. 'element ' + elementToString(refSemantic) + ' referenced by ' +
  5401. elementToString(semantic) + '#' + property + ' not yet drawn');
  5402. }
  5403. /**
  5404. * An importer that adds bpmn elements to the canvas
  5405. *
  5406. * @param {EventBus} eventBus
  5407. * @param {Canvas} canvas
  5408. * @param {ElementFactory} elementFactory
  5409. * @param {ElementRegistry} elementRegistry
  5410. */
  5411. function BpmnImporter(eventBus, canvas, elementFactory, elementRegistry) {
  5412. this._eventBus = eventBus;
  5413. this._canvas = canvas;
  5414. this._elementFactory = elementFactory;
  5415. this._elementRegistry = elementRegistry;
  5416. }
  5417. BpmnImporter.$inject = [ 'eventBus', 'canvas', 'elementFactory', 'elementRegistry' ];
  5418. module.exports = BpmnImporter;
  5419. /**
  5420. * Add bpmn element (semantic) to the canvas onto the
  5421. * specified parent shape.
  5422. */
  5423. BpmnImporter.prototype.add = function(semantic, parentElement) {
  5424. var di = semantic.di,
  5425. element;
  5426. // ROOT ELEMENT
  5427. // handle the special case that we deal with a
  5428. // invisible root element (process or collaboration)
  5429. if (di.$instanceOf('bpmndi:BPMNPlane')) {
  5430. // add a virtual element (not being drawn)
  5431. element = this._elementFactory.createRoot(elementData(semantic));
  5432. this._canvas.setRootElement(element);
  5433. }
  5434. // SHAPE
  5435. else if (di.$instanceOf('bpmndi:BPMNShape')) {
  5436. var collapsed = !isExpanded(semantic);
  5437. var hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
  5438. var bounds = semantic.di.bounds;
  5439. element = this._elementFactory.createShape(elementData(semantic, {
  5440. collapsed: collapsed,
  5441. hidden: hidden,
  5442. x: Math.round(bounds.x),
  5443. y: Math.round(bounds.y),
  5444. width: Math.round(bounds.width),
  5445. height: Math.round(bounds.height)
  5446. }));
  5447. if (is(semantic, 'bpmn:BoundaryEvent')) {
  5448. this._attachBoundary(semantic, element);
  5449. }
  5450. this._canvas.addShape(element, parentElement);
  5451. }
  5452. // CONNECTION
  5453. else if (di.$instanceOf('bpmndi:BPMNEdge')) {
  5454. var source = this._getSource(semantic),
  5455. target = this._getTarget(semantic);
  5456. element = this._elementFactory.createConnection(elementData(semantic, {
  5457. source: source,
  5458. target: target,
  5459. waypoints: collectWaypoints(semantic.di.waypoint)
  5460. }));
  5461. this._canvas.addConnection(element, parentElement);
  5462. } else {
  5463. throw new Error('unknown di ' + elementToString(di) + ' for element ' + elementToString(semantic));
  5464. }
  5465. // (optional) LABEL
  5466. if (hasExternalLabel(semantic)) {
  5467. this.addLabel(semantic, element);
  5468. }
  5469. this._eventBus.fire('bpmnElement.added', { element: element });
  5470. return element;
  5471. };
  5472. /**
  5473. * Attach the boundary element to the given host
  5474. *
  5475. * @param {ModdleElement} boundarySemantic
  5476. * @param {djs.model.Base} boundaryElement
  5477. */
  5478. BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
  5479. var hostSemantic = boundarySemantic.attachedToRef;
  5480. if (!hostSemantic) {
  5481. throw new Error('missing ' + elementToString(boundarySemantic) + '#attachedToRef');
  5482. }
  5483. var host = this._elementRegistry.get(hostSemantic.id),
  5484. attachers = host && host.attachers;
  5485. if (!host) {
  5486. throw notYetDrawn(boundarySemantic, hostSemantic, 'attachedToRef');
  5487. }
  5488. // wire element.host <> host.attachers
  5489. boundaryElement.host = host;
  5490. if (!attachers) {
  5491. host.attachers = attachers = [];
  5492. }
  5493. if (attachers.indexOf(boundaryElement) === -1) {
  5494. attachers.push(boundaryElement);
  5495. }
  5496. };
  5497. /**
  5498. * add label for an element
  5499. */
  5500. BpmnImporter.prototype.addLabel = function(semantic, element) {
  5501. var bounds = getExternalLabelBounds(semantic, element);
  5502. var label = this._elementFactory.createLabel(elementData(semantic, {
  5503. id: semantic.id + '_label',
  5504. labelTarget: element,
  5505. type: 'label',
  5506. hidden: element.hidden,
  5507. x: Math.round(bounds.x),
  5508. y: Math.round(bounds.y),
  5509. width: Math.round(bounds.width),
  5510. height: Math.round(bounds.height)
  5511. }));
  5512. return this._canvas.addShape(label, element.parent);
  5513. };
  5514. /**
  5515. * Return the drawn connection end based on the given side.
  5516. *
  5517. * @throws {Error} if the end is not yet drawn
  5518. */
  5519. BpmnImporter.prototype._getEnd = function(semantic, side) {
  5520. var element,
  5521. refSemantic,
  5522. type = semantic.$type;
  5523. refSemantic = semantic[side + 'Ref'];
  5524. // handle mysterious isMany DataAssociation#sourceRef
  5525. if (side === 'source' && type === 'bpmn:DataInputAssociation') {
  5526. refSemantic = refSemantic && refSemantic[0];
  5527. }
  5528. // fix source / target for DataInputAssociation / DataOutputAssociation
  5529. if (side === 'source' && type === 'bpmn:DataOutputAssociation' ||
  5530. side === 'target' && type === 'bpmn:DataInputAssociation') {
  5531. refSemantic = semantic.$parent;
  5532. }
  5533. element = refSemantic && this._getElement(refSemantic);
  5534. if (element) {
  5535. return element;
  5536. }
  5537. if (refSemantic) {
  5538. throw notYetDrawn(semantic, refSemantic, side + 'Ref');
  5539. } else {
  5540. throw new Error(elementToString(semantic) + '#' + side + 'Ref not specified');
  5541. }
  5542. };
  5543. BpmnImporter.prototype._getSource = function(semantic) {
  5544. return this._getEnd(semantic, 'source');
  5545. };
  5546. BpmnImporter.prototype._getTarget = function(semantic) {
  5547. return this._getEnd(semantic, 'target');
  5548. };
  5549. BpmnImporter.prototype._getElement = function(semantic) {
  5550. return this._elementRegistry.get(semantic.id);
  5551. };
  5552. },{"221":221,"339":339,"46":46,"48":48,"49":49,"50":50}],44:[function(_dereq_,module,exports){
  5553. 'use strict';
  5554. var filter = _dereq_(216),
  5555. find = _dereq_(217),
  5556. forEach = _dereq_(218);
  5557. var Refs = _dereq_(369);
  5558. var elementToString = _dereq_(46).elementToString;
  5559. var diRefs = new Refs({ name: 'bpmnElement', enumerable: true }, { name: 'di' });
  5560. /**
  5561. * Returns true if an element has the given meta-model type
  5562. *
  5563. * @param {ModdleElement} element
  5564. * @param {String} type
  5565. *
  5566. * @return {Boolean}
  5567. */
  5568. function is(element, type) {
  5569. return element.$instanceOf(type);
  5570. }
  5571. /**
  5572. * Find a suitable display candidate for definitions where the DI does not
  5573. * correctly specify one.
  5574. */
  5575. function findDisplayCandidate(definitions) {
  5576. return find(definitions.rootElements, function(e) {
  5577. return is(e, 'bpmn:Process') || is(e, 'bpmn:Collaboration');
  5578. });
  5579. }
  5580. function BpmnTreeWalker(handler) {
  5581. // list of containers already walked
  5582. var handledProcesses = [];
  5583. // list of elements to handle deferred to ensure
  5584. // prerequisites are drawn
  5585. var deferred = [];
  5586. ///// Helpers /////////////////////////////////
  5587. function contextual(fn, ctx) {
  5588. return function(e) {
  5589. fn(e, ctx);
  5590. };
  5591. }
  5592. function visit(element, ctx) {
  5593. var gfx = element.gfx;
  5594. // avoid multiple rendering of elements
  5595. if (gfx) {
  5596. throw new Error('already rendered ' + elementToString(element));
  5597. }
  5598. // call handler
  5599. return handler.element(element, ctx);
  5600. }
  5601. function visitRoot(element, diagram) {
  5602. return handler.root(element, diagram);
  5603. }
  5604. function visitIfDi(element, ctx) {
  5605. try {
  5606. return element.di && visit(element, ctx);
  5607. } catch (e) {
  5608. logError(e.message, { element: element, error: e });
  5609. console.error('failed to import ' + elementToString(element));
  5610. console.error(e);
  5611. }
  5612. }
  5613. function logError(message, context) {
  5614. handler.error(message, context);
  5615. }
  5616. ////// DI handling ////////////////////////////
  5617. function registerDi(di) {
  5618. var bpmnElement = di.bpmnElement;
  5619. if (bpmnElement) {
  5620. if (bpmnElement.di) {
  5621. logError('multiple DI elements defined for ' + elementToString(bpmnElement), { element: bpmnElement });
  5622. } else {
  5623. diRefs.bind(bpmnElement, 'di');
  5624. bpmnElement.di = di;
  5625. }
  5626. } else {
  5627. logError('no bpmnElement referenced in ' + elementToString(di), { element: di });
  5628. }
  5629. }
  5630. function handleDiagram(diagram) {
  5631. handlePlane(diagram.plane);
  5632. }
  5633. function handlePlane(plane) {
  5634. registerDi(plane);
  5635. forEach(plane.planeElement, handlePlaneElement);
  5636. }
  5637. function handlePlaneElement(planeElement) {
  5638. registerDi(planeElement);
  5639. }
  5640. ////// Semantic handling //////////////////////
  5641. function handleDefinitions(definitions, diagram) {
  5642. // make sure we walk the correct bpmnElement
  5643. var diagrams = definitions.diagrams;
  5644. if (diagram && diagrams.indexOf(diagram) === -1) {
  5645. throw new Error('diagram not part of bpmn:Definitions');
  5646. }
  5647. if (!diagram && diagrams && diagrams.length) {
  5648. diagram = diagrams[0];
  5649. }
  5650. // no diagram -> nothing to import
  5651. if (!diagram) {
  5652. return;
  5653. }
  5654. // load DI from selected diagram only
  5655. handleDiagram(diagram);
  5656. var plane = diagram.plane;
  5657. if (!plane) {
  5658. throw new Error('no plane for ' + elementToString(diagram));
  5659. }
  5660. var rootElement = plane.bpmnElement;
  5661. // ensure we default to a suitable display candidate (process or collaboration),
  5662. // even if non is specified in DI
  5663. if (!rootElement) {
  5664. rootElement = findDisplayCandidate(definitions);
  5665. if (!rootElement) {
  5666. return logError('no process or collaboration present to display');
  5667. } else {
  5668. logError('correcting missing bpmnElement on ' + elementToString(plane) + ' to ' + elementToString(rootElement));
  5669. // correct DI on the fly
  5670. plane.bpmnElement = rootElement;
  5671. registerDi(plane);
  5672. }
  5673. }
  5674. var ctx = visitRoot(rootElement, plane);
  5675. if (is(rootElement, 'bpmn:Process')) {
  5676. handleProcess(rootElement, ctx);
  5677. } else if (is(rootElement, 'bpmn:Collaboration')) {
  5678. handleCollaboration(rootElement, ctx);
  5679. // force drawing of everything not yet drawn that is part of the target DI
  5680. handleUnhandledProcesses(definitions.rootElements, ctx);
  5681. } else {
  5682. throw new Error('unsupported bpmnElement for ' + elementToString(plane) + ' : ' + elementToString(rootElement));
  5683. }
  5684. // handle all deferred elements
  5685. handleDeferred(deferred);
  5686. }
  5687. function handleDeferred(deferred) {
  5688. forEach(deferred, function(d) { d(); });
  5689. }
  5690. function handleProcess(process, context) {
  5691. handleFlowElementsContainer(process, context);
  5692. handleIoSpecification(process.ioSpecification, context);
  5693. handleArtifacts(process.artifacts, context);
  5694. // log process handled
  5695. handledProcesses.push(process);
  5696. }
  5697. function handleUnhandledProcesses(rootElements) {
  5698. // walk through all processes that have not yet been drawn and draw them
  5699. // if they contain lanes with DI information.
  5700. // we do this to pass the free-floating lane test cases in the MIWG test suite
  5701. var processes = filter(rootElements, function(e) {
  5702. return is(e, 'bpmn:Process') && e.laneSets && handledProcesses.indexOf(e) === -1;
  5703. });
  5704. processes.forEach(contextual(handleProcess));
  5705. }
  5706. function handleMessageFlow(messageFlow, context) {
  5707. visitIfDi(messageFlow, context);
  5708. }
  5709. function handleMessageFlows(messageFlows, context) {
  5710. forEach(messageFlows, contextual(handleMessageFlow, context));
  5711. }
  5712. function handleDataAssociation(association, context) {
  5713. visitIfDi(association, context);
  5714. }
  5715. function handleDataInput(dataInput, context) {
  5716. visitIfDi(dataInput, context);
  5717. }
  5718. function handleDataOutput(dataOutput, context) {
  5719. visitIfDi(dataOutput, context);
  5720. }
  5721. function handleArtifact(artifact, context) {
  5722. // bpmn:TextAnnotation
  5723. // bpmn:Group
  5724. // bpmn:Association
  5725. visitIfDi(artifact, context);
  5726. }
  5727. function handleArtifacts(artifacts, context) {
  5728. forEach(artifacts, function(e) {
  5729. if (is(e, 'bpmn:Association')) {
  5730. deferred.push(function() {
  5731. handleArtifact(e, context);
  5732. });
  5733. } else {
  5734. handleArtifact(e, context);
  5735. }
  5736. });
  5737. }
  5738. function handleIoSpecification(ioSpecification, context) {
  5739. if (!ioSpecification) {
  5740. return;
  5741. }
  5742. forEach(ioSpecification.dataInputs, contextual(handleDataInput, context));
  5743. forEach(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
  5744. }
  5745. function handleSubProcess(subProcess, context) {
  5746. handleFlowElementsContainer(subProcess, context);
  5747. handleArtifacts(subProcess.artifacts, context);
  5748. }
  5749. function handleFlowNode(flowNode, context) {
  5750. var childCtx = visitIfDi(flowNode, context);
  5751. if (is(flowNode, 'bpmn:SubProcess')) {
  5752. handleSubProcess(flowNode, childCtx || context);
  5753. }
  5754. }
  5755. function handleSequenceFlow(sequenceFlow, context) {
  5756. visitIfDi(sequenceFlow, context);
  5757. }
  5758. function handleDataElement(dataObject, context) {
  5759. visitIfDi(dataObject, context);
  5760. }
  5761. function handleBoundaryEvent(dataObject, context) {
  5762. visitIfDi(dataObject, context);
  5763. }
  5764. function handleLane(lane, context) {
  5765. var newContext = visitIfDi(lane, context);
  5766. if (lane.childLaneSet) {
  5767. handleLaneSet(lane.childLaneSet, newContext || context);
  5768. } else {
  5769. var filterList = filter(lane.flowNodeRef, function(e) {
  5770. return e.$type !== 'bpmn:BoundaryEvent';
  5771. });
  5772. handleFlowElements(filterList, newContext || context);
  5773. }
  5774. }
  5775. function handleLaneSet(laneSet, context) {
  5776. forEach(laneSet.lanes, contextual(handleLane, context));
  5777. }
  5778. function handleLaneSets(laneSets, context) {
  5779. forEach(laneSets, contextual(handleLaneSet, context));
  5780. }
  5781. function handleFlowElementsContainer(container, context) {
  5782. if (container.laneSets) {
  5783. handleLaneSets(container.laneSets, context);
  5784. handleNonFlowNodes(container.flowElements);
  5785. } else {
  5786. handleFlowElements(container.flowElements, context);
  5787. }
  5788. }
  5789. function handleNonFlowNodes(flowElements, context) {
  5790. forEach(flowElements, function(e) {
  5791. if (is(e, 'bpmn:SequenceFlow')) {
  5792. deferred.push(function() {
  5793. handleSequenceFlow(e, context);
  5794. });
  5795. } else if (is(e, 'bpmn:BoundaryEvent')) {
  5796. deferred.unshift(function() {
  5797. handleBoundaryEvent(e, context);
  5798. });
  5799. } else if (is(e, 'bpmn:DataObject')) {
  5800. // SKIP (assume correct referencing via DataObjectReference)
  5801. } else if (is(e, 'bpmn:DataStoreReference')) {
  5802. handleDataElement(e, context);
  5803. } else if (is(e, 'bpmn:DataObjectReference')) {
  5804. handleDataElement(e, context);
  5805. }
  5806. });
  5807. }
  5808. function handleFlowElements(flowElements, context) {
  5809. forEach(flowElements, function(e) {
  5810. if (is(e, 'bpmn:SequenceFlow')) {
  5811. deferred.push(function() {
  5812. handleSequenceFlow(e, context);
  5813. });
  5814. } else if (is(e, 'bpmn:BoundaryEvent')) {
  5815. deferred.unshift(function() {
  5816. handleBoundaryEvent(e, context);
  5817. });
  5818. } else if (is(e, 'bpmn:FlowNode')) {
  5819. handleFlowNode(e, context);
  5820. if (is(e, 'bpmn:Activity')) {
  5821. handleIoSpecification(e.ioSpecification, context);
  5822. // defer handling of associations
  5823. deferred.push(function() {
  5824. forEach(e.dataInputAssociations, contextual(handleDataAssociation, context));
  5825. forEach(e.dataOutputAssociations, contextual(handleDataAssociation, context));
  5826. });
  5827. }
  5828. } else if (is(e, 'bpmn:DataObject')) {
  5829. // SKIP (assume correct referencing via DataObjectReference)
  5830. } else if (is(e, 'bpmn:DataStoreReference')) {
  5831. handleDataElement(e, context);
  5832. } else if (is(e, 'bpmn:DataObjectReference')) {
  5833. handleDataElement(e, context);
  5834. } else {
  5835. logError(
  5836. 'unrecognized flowElement ' + elementToString(e) + ' in context ' +
  5837. (context ? elementToString(context.businessObject) : null),
  5838. { element: e, context: context });
  5839. }
  5840. });
  5841. }
  5842. function handleParticipant(participant, context) {
  5843. var newCtx = visitIfDi(participant, context);
  5844. var process = participant.processRef;
  5845. if (process) {
  5846. handleProcess(process, newCtx || context);
  5847. }
  5848. }
  5849. function handleCollaboration(collaboration) {
  5850. forEach(collaboration.participants, contextual(handleParticipant));
  5851. handleArtifacts(collaboration.artifacts);
  5852. // handle message flows latest in the process
  5853. deferred.push(function() {
  5854. handleMessageFlows(collaboration.messageFlows);
  5855. });
  5856. }
  5857. ///// API ////////////////////////////////
  5858. return {
  5859. handleDefinitions: handleDefinitions
  5860. };
  5861. }
  5862. module.exports = BpmnTreeWalker;
  5863. },{"216":216,"217":217,"218":218,"369":369,"46":46}],45:[function(_dereq_,module,exports){
  5864. 'use strict';
  5865. var BpmnTreeWalker = _dereq_(44);
  5866. /**
  5867. * Import the definitions into a diagram.
  5868. *
  5869. * Errors and warnings are reported through the specified callback.
  5870. *
  5871. * @param {Diagram} diagram
  5872. * @param {ModdleElement} definitions
  5873. * @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done
  5874. */
  5875. function importBpmnDiagram(diagram, definitions, done) {
  5876. var importer = diagram.get('bpmnImporter'),
  5877. eventBus = diagram.get('eventBus');
  5878. var error,
  5879. warnings = [];
  5880. function parse(definitions) {
  5881. var visitor = {
  5882. root: function(element) {
  5883. return importer.add(element);
  5884. },
  5885. element: function(element, parentShape) {
  5886. return importer.add(element, parentShape);
  5887. },
  5888. error: function(message, context) {
  5889. warnings.push({ message: message, context: context });
  5890. }
  5891. };
  5892. var walker = new BpmnTreeWalker(visitor);
  5893. // import
  5894. walker.handleDefinitions(definitions);
  5895. }
  5896. eventBus.fire('import.start');
  5897. try {
  5898. parse(definitions);
  5899. } catch (e) {
  5900. error = e;
  5901. }
  5902. eventBus.fire(error ? 'import.error' : 'import.success', { error: error, warnings: warnings });
  5903. done(error, warnings);
  5904. }
  5905. module.exports.importBpmnDiagram = importBpmnDiagram;
  5906. },{"44":44}],46:[function(_dereq_,module,exports){
  5907. 'use strict';
  5908. module.exports.elementToString = function(e) {
  5909. if (!e) {
  5910. return '<null>';
  5911. }
  5912. return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
  5913. };
  5914. },{}],47:[function(_dereq_,module,exports){
  5915. module.exports = {
  5916. bpmnImporter: [ 'type', _dereq_(43) ]
  5917. };
  5918. },{"43":43}],48:[function(_dereq_,module,exports){
  5919. 'use strict';
  5920. var is = _dereq_(50).is,
  5921. getBusinessObject = _dereq_(50).getBusinessObject;
  5922. module.exports.isExpanded = function(element) {
  5923. if (is(element, 'bpmn:CallActivity')) {
  5924. return false;
  5925. }
  5926. if (is(element, 'bpmn:SubProcess')) {
  5927. return getBusinessObject(element).di.isExpanded;
  5928. }
  5929. if (is(element, 'bpmn:Participant')) {
  5930. return !!getBusinessObject(element).processRef;
  5931. }
  5932. return true;
  5933. };
  5934. },{"50":50}],49:[function(_dereq_,module,exports){
  5935. 'use strict';
  5936. var assign = _dereq_(339);
  5937. var DEFAULT_LABEL_SIZE = module.exports.DEFAULT_LABEL_SIZE = {
  5938. width: 90,
  5939. height: 20
  5940. };
  5941. /**
  5942. * Returns true if the given semantic has an external label
  5943. *
  5944. * @param {BpmnElement} semantic
  5945. * @return {Boolean} true if has label
  5946. */
  5947. module.exports.hasExternalLabel = function(semantic) {
  5948. return semantic.$instanceOf('bpmn:Event') ||
  5949. semantic.$instanceOf('bpmn:Gateway') ||
  5950. semantic.$instanceOf('bpmn:DataStoreReference') ||
  5951. semantic.$instanceOf('bpmn:DataObjectReference') ||
  5952. semantic.$instanceOf('bpmn:SequenceFlow') ||
  5953. semantic.$instanceOf('bpmn:MessageFlow');
  5954. };
  5955. /**
  5956. * Get the middle of a number of waypoints
  5957. *
  5958. * @param {Array<Point>} waypoints
  5959. * @return {Point} the mid point
  5960. */
  5961. var getWaypointsMid = module.exports.getWaypointsMid = function(waypoints) {
  5962. var mid = waypoints.length / 2 - 1;
  5963. var first = waypoints[Math.floor(mid)];
  5964. var second = waypoints[Math.ceil(mid + 0.01)];
  5965. return {
  5966. x: first.x + (second.x - first.x) / 2,
  5967. y: first.y + (second.y - first.y) / 2
  5968. };
  5969. };
  5970. var getExternalLabelMid = module.exports.getExternalLabelMid = function(element) {
  5971. if (element.waypoints) {
  5972. return getWaypointsMid(element.waypoints);
  5973. } else {
  5974. return {
  5975. x: element.x + element.width / 2,
  5976. y: element.y + element.height + DEFAULT_LABEL_SIZE.height / 2
  5977. };
  5978. }
  5979. };
  5980. /**
  5981. * Returns the bounds of an elements label, parsed from the elements DI or
  5982. * generated from its bounds.
  5983. *
  5984. * @param {BpmnElement} semantic
  5985. * @param {djs.model.Base} element
  5986. */
  5987. module.exports.getExternalLabelBounds = function(semantic, element) {
  5988. var mid,
  5989. size,
  5990. bounds,
  5991. di = semantic.di,
  5992. label = di.label;
  5993. if (label && label.bounds) {
  5994. bounds = label.bounds;
  5995. size = {
  5996. width: Math.max(DEFAULT_LABEL_SIZE.width, bounds.width),
  5997. height: bounds.height
  5998. };
  5999. mid = {
  6000. x: bounds.x + bounds.width / 2,
  6001. y: bounds.y + bounds.height / 2
  6002. };
  6003. } else {
  6004. mid = getExternalLabelMid(element);
  6005. size = DEFAULT_LABEL_SIZE;
  6006. }
  6007. return assign({
  6008. x: mid.x - size.width / 2,
  6009. y: mid.y - size.height / 2
  6010. }, size);
  6011. };
  6012. },{"339":339}],50:[function(_dereq_,module,exports){
  6013. 'use strict';
  6014. /**
  6015. * Is an element of the given BPMN type?
  6016. *
  6017. * @param {djs.model.Base|ModdleElement} element
  6018. * @param {String} type
  6019. *
  6020. * @return {Boolean}
  6021. */
  6022. function is(element, type) {
  6023. var bo = getBusinessObject(element);
  6024. return bo && bo.$instanceOf(type);
  6025. }
  6026. module.exports.is = is;
  6027. /**
  6028. * Return the business object for a given element.
  6029. *
  6030. * @param {djs.model.Base|ModdleElement} element
  6031. *
  6032. * @return {ModdleElement}
  6033. */
  6034. function getBusinessObject(element) {
  6035. return (element && element.businessObject) || element;
  6036. }
  6037. module.exports.getBusinessObject = getBusinessObject;
  6038. },{}],51:[function(_dereq_,module,exports){
  6039. module.exports = _dereq_(54);
  6040. },{"54":54}],52:[function(_dereq_,module,exports){
  6041. 'use strict';
  6042. var isString = _dereq_(336),
  6043. isFunction = _dereq_(331),
  6044. assign = _dereq_(339);
  6045. var Moddle = _dereq_(60),
  6046. XmlReader = _dereq_(56),
  6047. XmlWriter = _dereq_(57);
  6048. /**
  6049. * A sub class of {@link Moddle} with support for import and export of BPMN 2.0 xml files.
  6050. *
  6051. * @class BpmnModdle
  6052. * @extends Moddle
  6053. *
  6054. * @param {Object|Array} packages to use for instantiating the model
  6055. * @param {Object} [options] additional options to pass over
  6056. */
  6057. function BpmnModdle(packages, options) {
  6058. Moddle.call(this, packages, options);
  6059. }
  6060. BpmnModdle.prototype = Object.create(Moddle.prototype);
  6061. module.exports = BpmnModdle;
  6062. /**
  6063. * Instantiates a BPMN model tree from a given xml string.
  6064. *
  6065. * @param {String} xmlStr
  6066. * @param {String} [typeName='bpmn:Definitions'] name of the root element
  6067. * @param {Object} [options] options to pass to the underlying reader
  6068. * @param {Function} done callback that is invoked with (err, result, parseContext)
  6069. * once the import completes
  6070. */
  6071. BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options, done) {
  6072. if (!isString(typeName)) {
  6073. done = options;
  6074. options = typeName;
  6075. typeName = 'bpmn:Definitions';
  6076. }
  6077. if (isFunction(options)) {
  6078. done = options;
  6079. options = {};
  6080. }
  6081. var reader = new XmlReader(assign({ model: this, lax: true }, options));
  6082. var rootHandler = reader.handler(typeName);
  6083. reader.fromXML(xmlStr, rootHandler, done);
  6084. };
  6085. /**
  6086. * Serializes a BPMN 2.0 object tree to XML.
  6087. *
  6088. * @param {String} element the root element, typically an instance of `bpmn:Definitions`
  6089. * @param {Object} [options] to pass to the underlying writer
  6090. * @param {Function} done callback invoked with (err, xmlStr) once the import completes
  6091. */
  6092. BpmnModdle.prototype.toXML = function(element, options, done) {
  6093. if (isFunction(options)) {
  6094. done = options;
  6095. options = {};
  6096. }
  6097. var writer = new XmlWriter(options);
  6098. try {
  6099. var result = writer.toXML(element);
  6100. done(null, result);
  6101. } catch (e) {
  6102. done(e);
  6103. }
  6104. };
  6105. },{"331":331,"336":336,"339":339,"56":56,"57":57,"60":60}],53:[function(_dereq_,module,exports){
  6106. 'use strict';
  6107. var ID_PATTERN = /^(.*:)?id$/;
  6108. /**
  6109. * Extends the bpmn instance with id support.
  6110. *
  6111. * @example
  6112. *
  6113. * var moddle, ids;
  6114. *
  6115. * require('id-support').extend(moddle, ids);
  6116. *
  6117. * moddle.ids.next(); // create a next id
  6118. * moddle.ids; // ids instance
  6119. *
  6120. * // claims id as used
  6121. * moddle.create('foo:Bar', { id: 'fooobar1' });
  6122. *
  6123. *
  6124. * @param {Moddle} model
  6125. * @param {Ids} ids
  6126. *
  6127. * @return {Moddle} the extended moddle instance
  6128. */
  6129. module.exports.extend = function(model, ids) {
  6130. var set = model.properties.set;
  6131. // do not reinitialize setter
  6132. // unless it is already initialized
  6133. if (!model.ids) {
  6134. model.properties.set = function(target, property, value) {
  6135. // ensure we log used ids once they are assigned
  6136. // to model elements
  6137. if (ID_PATTERN.test(property)) {
  6138. var assigned = model.ids.assigned(value);
  6139. if (assigned && assigned !== target) {
  6140. throw new Error('id <' + value + '> already used');
  6141. }
  6142. model.ids.claim(value, target);
  6143. }
  6144. set.call(this, target, property, value);
  6145. };
  6146. }
  6147. model.ids = ids;
  6148. return model;
  6149. };
  6150. },{}],54:[function(_dereq_,module,exports){
  6151. 'use strict';
  6152. var assign = _dereq_(339);
  6153. var BpmnModdle = _dereq_(52);
  6154. var packages = {
  6155. bpmn: _dereq_(69),
  6156. bpmndi: _dereq_(70),
  6157. dc: _dereq_(71),
  6158. di: _dereq_(72)
  6159. };
  6160. module.exports = function(additionalPackages, options) {
  6161. return new BpmnModdle(assign({}, packages, additionalPackages), options);
  6162. };
  6163. },{"339":339,"52":52,"69":69,"70":70,"71":71,"72":72}],55:[function(_dereq_,module,exports){
  6164. 'use strict';
  6165. function capitalize(string) {
  6166. return string.charAt(0).toUpperCase() + string.slice(1);
  6167. }
  6168. function lower(string) {
  6169. return string.charAt(0).toLowerCase() + string.slice(1);
  6170. }
  6171. function hasLowerCaseAlias(pkg) {
  6172. return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
  6173. }
  6174. module.exports.aliasToName = function(alias, pkg) {
  6175. if (hasLowerCaseAlias(pkg)) {
  6176. return capitalize(alias);
  6177. } else {
  6178. return alias;
  6179. }
  6180. };
  6181. module.exports.nameToAlias = function(name, pkg) {
  6182. if (hasLowerCaseAlias(pkg)) {
  6183. return lower(name);
  6184. } else {
  6185. return name;
  6186. }
  6187. };
  6188. module.exports.DEFAULT_NS_MAP = {
  6189. 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
  6190. };
  6191. var XSI_TYPE = module.exports.XSI_TYPE = 'xsi:type';
  6192. function serializeFormat(element) {
  6193. return element.xml && element.xml.serialize;
  6194. }
  6195. module.exports.serializeAsType = function(element) {
  6196. return serializeFormat(element) === XSI_TYPE;
  6197. };
  6198. module.exports.serializeAsProperty = function(element) {
  6199. return serializeFormat(element) === 'property';
  6200. };
  6201. },{}],56:[function(_dereq_,module,exports){
  6202. 'use strict';
  6203. var reduce = _dereq_(222),
  6204. forEach = _dereq_(218),
  6205. find = _dereq_(217),
  6206. assign = _dereq_(339),
  6207. defer = _dereq_(229);
  6208. var Stack = _dereq_(59),
  6209. SaxParser = _dereq_(58).parser,
  6210. Moddle = _dereq_(60),
  6211. parseNameNs = _dereq_(65).parseName,
  6212. Types = _dereq_(68),
  6213. coerceType = Types.coerceType,
  6214. isSimpleType = Types.isSimple,
  6215. common = _dereq_(55),
  6216. XSI_TYPE = common.XSI_TYPE,
  6217. XSI_URI = common.DEFAULT_NS_MAP.xsi,
  6218. serializeAsType = common.serializeAsType,
  6219. aliasToName = common.aliasToName;
  6220. function parseNodeAttributes(node) {
  6221. var nodeAttrs = node.attributes;
  6222. return reduce(nodeAttrs, function(result, v, k) {
  6223. var name, ns;
  6224. if (!v.local) {
  6225. name = v.prefix;
  6226. } else {
  6227. ns = parseNameNs(v.name, v.prefix);
  6228. name = ns.name;
  6229. }
  6230. result[name] = v.value;
  6231. return result;
  6232. }, {});
  6233. }
  6234. function normalizeType(node, attr, model) {
  6235. var nameNs = parseNameNs(attr.value);
  6236. var uri = node.ns[nameNs.prefix || ''],
  6237. localName = nameNs.localName,
  6238. pkg = uri && model.getPackage(uri),
  6239. typePrefix;
  6240. if (pkg) {
  6241. typePrefix = pkg.xml && pkg.xml.typePrefix;
  6242. if (typePrefix && localName.indexOf(typePrefix) === 0) {
  6243. localName = localName.slice(typePrefix.length);
  6244. }
  6245. attr.value = pkg.prefix + ':' + localName;
  6246. }
  6247. }
  6248. /**
  6249. * Normalizes namespaces for a node given an optional default namespace and a
  6250. * number of mappings from uris to default prefixes.
  6251. *
  6252. * @param {XmlNode} node
  6253. * @param {Model} model the model containing all registered namespaces
  6254. * @param {Uri} defaultNsUri
  6255. */
  6256. function normalizeNamespaces(node, model, defaultNsUri) {
  6257. var uri, prefix;
  6258. uri = node.uri || defaultNsUri;
  6259. if (uri) {
  6260. var pkg = model.getPackage(uri);
  6261. if (pkg) {
  6262. prefix = pkg.prefix;
  6263. } else {
  6264. prefix = node.prefix;
  6265. }
  6266. node.prefix = prefix;
  6267. node.uri = uri;
  6268. }
  6269. forEach(node.attributes, function(attr) {
  6270. // normalize xsi:type attributes because the
  6271. // assigned type may or may not be namespace prefixed
  6272. if (attr.uri === XSI_URI && attr.local === 'type') {
  6273. normalizeType(node, attr, model);
  6274. }
  6275. normalizeNamespaces(attr, model, null);
  6276. });
  6277. }
  6278. /**
  6279. * A parse context.
  6280. *
  6281. * @class
  6282. *
  6283. * @param {Object} options
  6284. * @param {ElementHandler} options.parseRoot the root handler for parsing a document
  6285. * @param {boolean} [options.lax=false] whether or not to ignore invalid elements
  6286. */
  6287. function Context(options) {
  6288. /**
  6289. * @property {ElementHandler} parseRoot
  6290. */
  6291. /**
  6292. * @property {Boolean} lax
  6293. */
  6294. assign(this, options);
  6295. var elementsById = this.elementsById = {};
  6296. var references = this.references = [];
  6297. var warnings = this.warnings = [];
  6298. this.addReference = function(reference) {
  6299. references.push(reference);
  6300. };
  6301. this.addElement = function(id, element) {
  6302. if (!id || !element) {
  6303. throw new Error('[xml-reader] id or ctx must not be null');
  6304. }
  6305. elementsById[id] = element;
  6306. };
  6307. this.addWarning = function (w) {
  6308. warnings.push(w);
  6309. };
  6310. }
  6311. function BaseHandler() {}
  6312. BaseHandler.prototype.handleEnd = function() {};
  6313. BaseHandler.prototype.handleText = function() {};
  6314. BaseHandler.prototype.handleNode = function() {};
  6315. /**
  6316. * A simple pass through handler that does nothing except for
  6317. * ignoring all input it receives.
  6318. *
  6319. * This is used to ignore unknown elements and
  6320. * attributes.
  6321. */
  6322. function NoopHandler() { }
  6323. NoopHandler.prototype = new BaseHandler();
  6324. NoopHandler.prototype.handleNode = function() {
  6325. return this;
  6326. };
  6327. function BodyHandler() {}
  6328. BodyHandler.prototype = new BaseHandler();
  6329. BodyHandler.prototype.handleText = function(text) {
  6330. this.body = (this.body || '') + text;
  6331. };
  6332. function ReferenceHandler(property, context) {
  6333. this.property = property;
  6334. this.context = context;
  6335. }
  6336. ReferenceHandler.prototype = new BodyHandler();
  6337. ReferenceHandler.prototype.handleNode = function(node) {
  6338. if (this.element) {
  6339. throw new Error('expected no sub nodes');
  6340. } else {
  6341. this.element = this.createReference(node);
  6342. }
  6343. return this;
  6344. };
  6345. ReferenceHandler.prototype.handleEnd = function() {
  6346. this.element.id = this.body;
  6347. };
  6348. ReferenceHandler.prototype.createReference = function() {
  6349. return {
  6350. property: this.property.ns.name,
  6351. id: ''
  6352. };
  6353. };
  6354. function ValueHandler(propertyDesc, element) {
  6355. this.element = element;
  6356. this.propertyDesc = propertyDesc;
  6357. }
  6358. ValueHandler.prototype = new BodyHandler();
  6359. ValueHandler.prototype.handleEnd = function() {
  6360. var value = this.body,
  6361. element = this.element,
  6362. propertyDesc = this.propertyDesc;
  6363. value = coerceType(propertyDesc.type, value);
  6364. if (propertyDesc.isMany) {
  6365. element.get(propertyDesc.name).push(value);
  6366. } else {
  6367. element.set(propertyDesc.name, value);
  6368. }
  6369. };
  6370. function BaseElementHandler() {}
  6371. BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
  6372. BaseElementHandler.prototype.handleNode = function(node) {
  6373. var parser = this,
  6374. element = this.element,
  6375. id;
  6376. if (!element) {
  6377. element = this.element = this.createElement(node);
  6378. id = element.id;
  6379. if (id) {
  6380. this.context.addElement(id, element);
  6381. }
  6382. } else {
  6383. parser = this.handleChild(node);
  6384. }
  6385. return parser;
  6386. };
  6387. /**
  6388. * @class XMLReader.ElementHandler
  6389. *
  6390. */
  6391. function ElementHandler(model, type, context) {
  6392. this.model = model;
  6393. this.type = model.getType(type);
  6394. this.context = context;
  6395. }
  6396. ElementHandler.prototype = new BaseElementHandler();
  6397. ElementHandler.prototype.addReference = function(reference) {
  6398. this.context.addReference(reference);
  6399. };
  6400. ElementHandler.prototype.handleEnd = function() {
  6401. var value = this.body,
  6402. element = this.element,
  6403. descriptor = element.$descriptor,
  6404. bodyProperty = descriptor.bodyProperty;
  6405. if (bodyProperty && value !== undefined) {
  6406. value = coerceType(bodyProperty.type, value);
  6407. element.set(bodyProperty.name, value);
  6408. }
  6409. };
  6410. /**
  6411. * Create an instance of the model from the given node.
  6412. *
  6413. * @param {Element} node the xml node
  6414. */
  6415. ElementHandler.prototype.createElement = function(node) {
  6416. var attributes = parseNodeAttributes(node),
  6417. Type = this.type,
  6418. descriptor = Type.$descriptor,
  6419. context = this.context,
  6420. instance = new Type({});
  6421. forEach(attributes, function(value, name) {
  6422. var prop = descriptor.propertiesByName[name];
  6423. if (prop && prop.isReference) {
  6424. context.addReference({
  6425. element: instance,
  6426. property: prop.ns.name,
  6427. id: value
  6428. });
  6429. } else {
  6430. if (prop) {
  6431. value = coerceType(prop.type, value);
  6432. }
  6433. instance.set(name, value);
  6434. }
  6435. });
  6436. return instance;
  6437. };
  6438. ElementHandler.prototype.getPropertyForNode = function(node) {
  6439. var nameNs = parseNameNs(node.local, node.prefix);
  6440. var type = this.type,
  6441. model = this.model,
  6442. descriptor = type.$descriptor;
  6443. var propertyName = nameNs.name,
  6444. property = descriptor.propertiesByName[propertyName],
  6445. elementTypeName,
  6446. elementType,
  6447. typeAnnotation;
  6448. // search for properties by name first
  6449. if (property) {
  6450. if (serializeAsType(property)) {
  6451. typeAnnotation = node.attributes[XSI_TYPE];
  6452. // xsi type is optional, if it does not exists the
  6453. // default type is assumed
  6454. if (typeAnnotation) {
  6455. elementTypeName = typeAnnotation.value;
  6456. // TODO: extract real name from attribute
  6457. elementType = model.getType(elementTypeName);
  6458. return assign({}, property, { effectiveType: elementType.$descriptor.name });
  6459. }
  6460. }
  6461. // search for properties by name first
  6462. return property;
  6463. }
  6464. var pkg = model.getPackage(nameNs.prefix);
  6465. if (pkg) {
  6466. elementTypeName = nameNs.prefix + ':' + aliasToName(nameNs.localName, descriptor.$pkg);
  6467. elementType = model.getType(elementTypeName);
  6468. // search for collection members later
  6469. property = find(descriptor.properties, function(p) {
  6470. return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
  6471. });
  6472. if (property) {
  6473. return assign({}, property, { effectiveType: elementType.$descriptor.name });
  6474. }
  6475. } else {
  6476. // parse unknown element (maybe extension)
  6477. property = find(descriptor.properties, function(p) {
  6478. return !p.isReference && !p.isAttribute && p.type === 'Element';
  6479. });
  6480. if (property) {
  6481. return property;
  6482. }
  6483. }
  6484. throw new Error('unrecognized element <' + nameNs.name + '>');
  6485. };
  6486. ElementHandler.prototype.toString = function() {
  6487. return 'ElementDescriptor[' + this.type.$descriptor.name + ']';
  6488. };
  6489. ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
  6490. return new ValueHandler(propertyDesc, element);
  6491. };
  6492. ElementHandler.prototype.referenceHandler = function(propertyDesc) {
  6493. return new ReferenceHandler(propertyDesc, this.context);
  6494. };
  6495. ElementHandler.prototype.handler = function(type) {
  6496. if (type === 'Element') {
  6497. return new GenericElementHandler(this.model, type, this.context);
  6498. } else {
  6499. return new ElementHandler(this.model, type, this.context);
  6500. }
  6501. };
  6502. /**
  6503. * Handle the child element parsing
  6504. *
  6505. * @param {Element} node the xml node
  6506. */
  6507. ElementHandler.prototype.handleChild = function(node) {
  6508. var propertyDesc, type, element, childHandler;
  6509. propertyDesc = this.getPropertyForNode(node);
  6510. element = this.element;
  6511. type = propertyDesc.effectiveType || propertyDesc.type;
  6512. if (isSimpleType(type)) {
  6513. return this.valueHandler(propertyDesc, element);
  6514. }
  6515. if (propertyDesc.isReference) {
  6516. childHandler = this.referenceHandler(propertyDesc).handleNode(node);
  6517. } else {
  6518. childHandler = this.handler(type).handleNode(node);
  6519. }
  6520. var newElement = childHandler.element;
  6521. // child handles may decide to skip elements
  6522. // by not returning anything
  6523. if (newElement !== undefined) {
  6524. if (propertyDesc.isMany) {
  6525. element.get(propertyDesc.name).push(newElement);
  6526. } else {
  6527. element.set(propertyDesc.name, newElement);
  6528. }
  6529. if (propertyDesc.isReference) {
  6530. assign(newElement, {
  6531. element: element
  6532. });
  6533. this.context.addReference(newElement);
  6534. } else {
  6535. // establish child -> parent relationship
  6536. newElement.$parent = element;
  6537. }
  6538. }
  6539. return childHandler;
  6540. };
  6541. function GenericElementHandler(model, type, context) {
  6542. this.model = model;
  6543. this.context = context;
  6544. }
  6545. GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
  6546. GenericElementHandler.prototype.createElement = function(node) {
  6547. var name = node.name,
  6548. prefix = node.prefix,
  6549. uri = node.ns[prefix],
  6550. attributes = node.attributes;
  6551. return this.model.createAny(name, uri, attributes);
  6552. };
  6553. GenericElementHandler.prototype.handleChild = function(node) {
  6554. var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
  6555. element = this.element;
  6556. var newElement = handler.element,
  6557. children;
  6558. if (newElement !== undefined) {
  6559. children = element.$children = element.$children || [];
  6560. children.push(newElement);
  6561. // establish child -> parent relationship
  6562. newElement.$parent = element;
  6563. }
  6564. return handler;
  6565. };
  6566. GenericElementHandler.prototype.handleText = function(text) {
  6567. this.body = this.body || '' + text;
  6568. };
  6569. GenericElementHandler.prototype.handleEnd = function() {
  6570. if (this.body) {
  6571. this.element.$body = this.body;
  6572. }
  6573. };
  6574. /**
  6575. * A reader for a meta-model
  6576. *
  6577. * @param {Object} options
  6578. * @param {Model} options.model used to read xml files
  6579. * @param {Boolean} options.lax whether to make parse errors warnings
  6580. */
  6581. function XMLReader(options) {
  6582. if (options instanceof Moddle) {
  6583. options = {
  6584. model: options
  6585. };
  6586. }
  6587. assign(this, { lax: false }, options);
  6588. }
  6589. XMLReader.prototype.fromXML = function(xml, rootHandler, done) {
  6590. var model = this.model,
  6591. lax = this.lax,
  6592. context = new Context({
  6593. parseRoot: rootHandler
  6594. });
  6595. var parser = new SaxParser(true, { xmlns: true, trim: true }),
  6596. stack = new Stack();
  6597. rootHandler.context = context;
  6598. // push root handler
  6599. stack.push(rootHandler);
  6600. function resolveReferences() {
  6601. var elementsById = context.elementsById;
  6602. var references = context.references;
  6603. var i, r;
  6604. for (i = 0; !!(r = references[i]); i++) {
  6605. var element = r.element;
  6606. var reference = elementsById[r.id];
  6607. var property = element.$descriptor.propertiesByName[r.property];
  6608. if (!reference) {
  6609. context.addWarning({
  6610. message: 'unresolved reference <' + r.id + '>',
  6611. element: r.element,
  6612. property: r.property,
  6613. value: r.id
  6614. });
  6615. }
  6616. if (property.isMany) {
  6617. var collection = element.get(property.name),
  6618. idx = collection.indexOf(r);
  6619. if (!reference) {
  6620. // remove unresolvable reference
  6621. collection.splice(idx, 1);
  6622. } else {
  6623. // update reference
  6624. collection[idx] = reference;
  6625. }
  6626. } else {
  6627. element.set(property.name, reference);
  6628. }
  6629. }
  6630. }
  6631. function handleClose(tagName) {
  6632. stack.pop().handleEnd();
  6633. }
  6634. function handleOpen(node) {
  6635. var handler = stack.peek();
  6636. normalizeNamespaces(node, model);
  6637. try {
  6638. stack.push(handler.handleNode(node));
  6639. } catch (e) {
  6640. var line = this.line,
  6641. column = this.column;
  6642. var message =
  6643. 'unparsable content <' + node.name + '> detected\n\t' +
  6644. 'line: ' + line + '\n\t' +
  6645. 'column: ' + column + '\n\t' +
  6646. 'nested error: ' + e.message;
  6647. if (lax) {
  6648. context.addWarning({
  6649. message: message,
  6650. error: e
  6651. });
  6652. console.warn('could not parse node');
  6653. console.warn(e);
  6654. stack.push(new NoopHandler());
  6655. } else {
  6656. console.error('could not parse document');
  6657. console.error(e);
  6658. throw new Error(message);
  6659. }
  6660. }
  6661. }
  6662. function handleText(text) {
  6663. stack.peek().handleText(text);
  6664. }
  6665. parser.onopentag = handleOpen;
  6666. parser.oncdata = parser.ontext = handleText;
  6667. parser.onclosetag = handleClose;
  6668. parser.onend = resolveReferences;
  6669. // deferred parse XML to make loading really ascnchronous
  6670. // this ensures the execution environment (node or browser)
  6671. // is kept responsive and that certain optimization strategies
  6672. // can kick in
  6673. defer(function() {
  6674. var error;
  6675. try {
  6676. parser.write(xml).close();
  6677. } catch (e) {
  6678. error = e;
  6679. }
  6680. done(error, error ? undefined : rootHandler.element, context);
  6681. });
  6682. };
  6683. XMLReader.prototype.handler = function(name) {
  6684. return new ElementHandler(this.model, name);
  6685. };
  6686. module.exports = XMLReader;
  6687. module.exports.ElementHandler = ElementHandler;
  6688. },{"217":217,"218":218,"222":222,"229":229,"339":339,"55":55,"58":58,"59":59,"60":60,"65":65,"68":68}],57:[function(_dereq_,module,exports){
  6689. 'use strict';
  6690. var map = _dereq_(221),
  6691. forEach = _dereq_(218),
  6692. isString = _dereq_(336),
  6693. filter = _dereq_(216),
  6694. assign = _dereq_(339);
  6695. var Types = _dereq_(68),
  6696. parseNameNs = _dereq_(65).parseName,
  6697. common = _dereq_(55),
  6698. nameToAlias = common.nameToAlias,
  6699. serializeAsType = common.serializeAsType,
  6700. serializeAsProperty = common.serializeAsProperty;
  6701. var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n',
  6702. ESCAPE_CHARS = /(<|>|'|"|&|\n\r|\n)/g,
  6703. DEFAULT_NS_MAP = common.DEFAULT_NS_MAP,
  6704. XSI_TYPE = common.XSI_TYPE;
  6705. function nsName(ns) {
  6706. if (isString(ns)) {
  6707. return ns;
  6708. } else {
  6709. return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
  6710. }
  6711. }
  6712. function getElementNs(ns, descriptor) {
  6713. if (descriptor.isGeneric) {
  6714. return descriptor.name;
  6715. } else {
  6716. return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
  6717. }
  6718. }
  6719. function getPropertyNs(ns, descriptor) {
  6720. return assign({ localName: descriptor.ns.localName }, ns);
  6721. }
  6722. function getSerializableProperties(element) {
  6723. var descriptor = element.$descriptor;
  6724. return filter(descriptor.properties, function(p) {
  6725. var name = p.name;
  6726. // do not serialize defaults
  6727. if (!element.hasOwnProperty(name)) {
  6728. return false;
  6729. }
  6730. var value = element[name];
  6731. // do not serialize default equals
  6732. if (value === p.default) {
  6733. return false;
  6734. }
  6735. return p.isMany ? value.length : true;
  6736. });
  6737. }
  6738. var ESCAPE_MAP = {
  6739. '\n': '10',
  6740. '\n\r': '10',
  6741. '"': '34',
  6742. '\'': '39',
  6743. '<': '60',
  6744. '>': '62',
  6745. '&': '38'
  6746. };
  6747. /**
  6748. * Escape a string attribute to not contain any bad values (line breaks, '"', ...)
  6749. *
  6750. * @param {String} str the string to escape
  6751. * @return {String} the escaped string
  6752. */
  6753. function escapeAttr(str) {
  6754. // ensure we are handling strings here
  6755. str = isString(str) ? str : '' + str;
  6756. return str.replace(ESCAPE_CHARS, function(str) {
  6757. return '&#' + ESCAPE_MAP[str] + ';';
  6758. });
  6759. }
  6760. function filterAttributes(props) {
  6761. return filter(props, function(p) { return p.isAttr; });
  6762. }
  6763. function filterContained(props) {
  6764. return filter(props, function(p) { return !p.isAttr; });
  6765. }
  6766. function ReferenceSerializer(parent, ns) {
  6767. this.ns = ns;
  6768. }
  6769. ReferenceSerializer.prototype.build = function(element) {
  6770. this.element = element;
  6771. return this;
  6772. };
  6773. ReferenceSerializer.prototype.serializeTo = function(writer) {
  6774. writer
  6775. .appendIndent()
  6776. .append('<' + nsName(this.ns) + '>' + this.element.id + '</' + nsName(this.ns) + '>')
  6777. .appendNewLine();
  6778. };
  6779. function BodySerializer() {}
  6780. BodySerializer.prototype.serializeValue = BodySerializer.prototype.serializeTo = function(writer) {
  6781. var escape = this.escape;
  6782. if (escape) {
  6783. writer.append('<![CDATA[');
  6784. }
  6785. writer.append(this.value);
  6786. if (escape) {
  6787. writer.append(']]>');
  6788. }
  6789. };
  6790. BodySerializer.prototype.build = function(prop, value) {
  6791. this.value = value;
  6792. if (prop.type === 'String' && ESCAPE_CHARS.test(value)) {
  6793. this.escape = true;
  6794. }
  6795. return this;
  6796. };
  6797. function ValueSerializer(ns) {
  6798. this.ns = ns;
  6799. }
  6800. ValueSerializer.prototype = new BodySerializer();
  6801. ValueSerializer.prototype.serializeTo = function(writer) {
  6802. writer
  6803. .appendIndent()
  6804. .append('<' + nsName(this.ns) + '>');
  6805. this.serializeValue(writer);
  6806. writer
  6807. .append( '</' + nsName(this.ns) + '>')
  6808. .appendNewLine();
  6809. };
  6810. function ElementSerializer(parent, ns) {
  6811. this.body = [];
  6812. this.attrs = [];
  6813. this.parent = parent;
  6814. this.ns = ns;
  6815. }
  6816. ElementSerializer.prototype.build = function(element) {
  6817. this.element = element;
  6818. var otherAttrs = this.parseNsAttributes(element);
  6819. if (!this.ns) {
  6820. this.ns = this.nsTagName(element.$descriptor);
  6821. }
  6822. if (element.$descriptor.isGeneric) {
  6823. this.parseGeneric(element);
  6824. } else {
  6825. var properties = getSerializableProperties(element);
  6826. this.parseAttributes(filterAttributes(properties));
  6827. this.parseContainments(filterContained(properties));
  6828. this.parseGenericAttributes(element, otherAttrs);
  6829. }
  6830. return this;
  6831. };
  6832. ElementSerializer.prototype.nsTagName = function(descriptor) {
  6833. var effectiveNs = this.logNamespaceUsed(descriptor.ns);
  6834. return getElementNs(effectiveNs, descriptor);
  6835. };
  6836. ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
  6837. var effectiveNs = this.logNamespaceUsed(descriptor.ns);
  6838. return getPropertyNs(effectiveNs, descriptor);
  6839. };
  6840. ElementSerializer.prototype.isLocalNs = function(ns) {
  6841. return ns.uri === this.ns.uri;
  6842. };
  6843. ElementSerializer.prototype.nsAttributeName = function(element) {
  6844. var ns;
  6845. if (isString(element)) {
  6846. ns = parseNameNs(element);
  6847. } else
  6848. if (element.ns) {
  6849. ns = element.ns;
  6850. }
  6851. var effectiveNs = this.logNamespaceUsed(ns);
  6852. // strip prefix if same namespace like parent
  6853. if (this.isLocalNs(effectiveNs)) {
  6854. return { localName: ns.localName };
  6855. } else {
  6856. return assign({ localName: ns.localName }, effectiveNs);
  6857. }
  6858. };
  6859. ElementSerializer.prototype.parseGeneric = function(element) {
  6860. var self = this,
  6861. body = this.body,
  6862. attrs = this.attrs;
  6863. forEach(element, function(val, key) {
  6864. if (key === '$body') {
  6865. body.push(new BodySerializer().build({ type: 'String' }, val));
  6866. } else
  6867. if (key === '$children') {
  6868. forEach(val, function(child) {
  6869. body.push(new ElementSerializer(self).build(child));
  6870. });
  6871. } else
  6872. if (key.indexOf('$') !== 0) {
  6873. attrs.push({ name: key, value: escapeAttr(val) });
  6874. }
  6875. });
  6876. };
  6877. /**
  6878. * Parse namespaces and return a list of left over generic attributes
  6879. *
  6880. * @param {Object} element
  6881. * @return {Array<Object>}
  6882. */
  6883. ElementSerializer.prototype.parseNsAttributes = function(element) {
  6884. var self = this;
  6885. var genericAttrs = element.$attrs;
  6886. var attributes = [];
  6887. // parse namespace attributes first
  6888. // and log them. push non namespace attributes to a list
  6889. // and process them later
  6890. forEach(genericAttrs, function(value, name) {
  6891. var nameNs = parseNameNs(name);
  6892. if (nameNs.prefix === 'xmlns') {
  6893. self.logNamespace({ prefix: nameNs.localName, uri: value });
  6894. } else
  6895. if (!nameNs.prefix && nameNs.localName === 'xmlns') {
  6896. self.logNamespace({ uri: value });
  6897. } else {
  6898. attributes.push({ name: name, value: value });
  6899. }
  6900. });
  6901. return attributes;
  6902. };
  6903. ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
  6904. var self = this;
  6905. forEach(attributes, function(attr) {
  6906. // do not serialize xsi:type attribute
  6907. // it is set manually based on the actual implementation type
  6908. if (attr.name === XSI_TYPE) {
  6909. return;
  6910. }
  6911. try {
  6912. self.addAttribute(self.nsAttributeName(attr.name), attr.value);
  6913. } catch (e) {
  6914. console.warn('[writer] missing namespace information for ', attr.name, '=', attr.value, 'on', element, e);
  6915. }
  6916. });
  6917. };
  6918. ElementSerializer.prototype.parseContainments = function(properties) {
  6919. var self = this,
  6920. body = this.body,
  6921. element = this.element;
  6922. forEach(properties, function(p) {
  6923. var value = element.get(p.name),
  6924. isReference = p.isReference,
  6925. isMany = p.isMany;
  6926. var ns = self.nsPropertyTagName(p);
  6927. if (!isMany) {
  6928. value = [ value ];
  6929. }
  6930. if (p.isBody) {
  6931. body.push(new BodySerializer().build(p, value[0]));
  6932. } else
  6933. if (Types.isSimple(p.type)) {
  6934. forEach(value, function(v) {
  6935. body.push(new ValueSerializer(ns).build(p, v));
  6936. });
  6937. } else
  6938. if (isReference) {
  6939. forEach(value, function(v) {
  6940. body.push(new ReferenceSerializer(self, ns).build(v));
  6941. });
  6942. } else {
  6943. // allow serialization via type
  6944. // rather than element name
  6945. var asType = serializeAsType(p),
  6946. asProperty = serializeAsProperty(p);
  6947. forEach(value, function(v) {
  6948. var serializer;
  6949. if (asType) {
  6950. serializer = new TypeSerializer(self, ns);
  6951. } else
  6952. if (asProperty) {
  6953. serializer = new ElementSerializer(self, ns);
  6954. } else {
  6955. serializer = new ElementSerializer(self);
  6956. }
  6957. body.push(serializer.build(v));
  6958. });
  6959. }
  6960. });
  6961. };
  6962. ElementSerializer.prototype.getNamespaces = function() {
  6963. if (!this.parent) {
  6964. if (!this.namespaces) {
  6965. this.namespaces = {
  6966. prefixMap: {},
  6967. uriMap: {},
  6968. used: {}
  6969. };
  6970. }
  6971. } else {
  6972. this.namespaces = this.parent.getNamespaces();
  6973. }
  6974. return this.namespaces;
  6975. };
  6976. ElementSerializer.prototype.logNamespace = function(ns) {
  6977. var namespaces = this.getNamespaces();
  6978. var existing = namespaces.uriMap[ns.uri];
  6979. if (!existing) {
  6980. namespaces.uriMap[ns.uri] = ns;
  6981. }
  6982. namespaces.prefixMap[ns.prefix] = ns.uri;
  6983. return ns;
  6984. };
  6985. ElementSerializer.prototype.logNamespaceUsed = function(ns) {
  6986. var element = this.element,
  6987. model = element.$model,
  6988. namespaces = this.getNamespaces();
  6989. // ns may be
  6990. //
  6991. // * prefix only
  6992. // * prefix:uri
  6993. var prefix = ns.prefix;
  6994. var uri = ns.uri || DEFAULT_NS_MAP[prefix] ||
  6995. namespaces.prefixMap[prefix] || (model ? (model.getPackage(prefix) || {}).uri : null);
  6996. if (!uri) {
  6997. throw new Error('no namespace uri given for prefix <' + ns.prefix + '>');
  6998. }
  6999. ns = namespaces.uriMap[uri];
  7000. if (!ns) {
  7001. ns = this.logNamespace({ prefix: prefix, uri: uri });
  7002. }
  7003. if (!namespaces.used[ns.uri]) {
  7004. namespaces.used[ns.uri] = ns;
  7005. }
  7006. return ns;
  7007. };
  7008. ElementSerializer.prototype.parseAttributes = function(properties) {
  7009. var self = this,
  7010. element = this.element;
  7011. forEach(properties, function(p) {
  7012. self.logNamespaceUsed(p.ns);
  7013. var value = element.get(p.name);
  7014. if (p.isReference) {
  7015. value = value.id;
  7016. }
  7017. self.addAttribute(self.nsAttributeName(p), value);
  7018. });
  7019. };
  7020. ElementSerializer.prototype.addAttribute = function(name, value) {
  7021. var attrs = this.attrs;
  7022. if (isString(value)) {
  7023. value = escapeAttr(value);
  7024. }
  7025. attrs.push({ name: name, value: value });
  7026. };
  7027. ElementSerializer.prototype.serializeAttributes = function(writer) {
  7028. var attrs = this.attrs,
  7029. root = !this.parent,
  7030. namespaces = this.namespaces;
  7031. function collectNsAttrs() {
  7032. return map(namespaces.used, function(ns) {
  7033. var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
  7034. return { name: name, value: ns.uri };
  7035. });
  7036. }
  7037. if (root) {
  7038. attrs = collectNsAttrs().concat(attrs);
  7039. }
  7040. forEach(attrs, function(a) {
  7041. writer
  7042. .append(' ')
  7043. .append(nsName(a.name)).append('="').append(a.value).append('"');
  7044. });
  7045. };
  7046. ElementSerializer.prototype.serializeTo = function(writer) {
  7047. var hasBody = this.body.length,
  7048. indent = !(this.body.length === 1 && this.body[0] instanceof BodySerializer);
  7049. writer
  7050. .appendIndent()
  7051. .append('<' + nsName(this.ns));
  7052. this.serializeAttributes(writer);
  7053. writer.append(hasBody ? '>' : ' />');
  7054. if (hasBody) {
  7055. if (indent) {
  7056. writer
  7057. .appendNewLine()
  7058. .indent();
  7059. }
  7060. forEach(this.body, function(b) {
  7061. b.serializeTo(writer);
  7062. });
  7063. if (indent) {
  7064. writer
  7065. .unindent()
  7066. .appendIndent();
  7067. }
  7068. writer.append('</' + nsName(this.ns) + '>');
  7069. }
  7070. writer.appendNewLine();
  7071. };
  7072. /**
  7073. * A serializer for types that handles serialization of data types
  7074. */
  7075. function TypeSerializer(parent, ns) {
  7076. ElementSerializer.call(this, parent, ns);
  7077. }
  7078. TypeSerializer.prototype = new ElementSerializer();
  7079. TypeSerializer.prototype.build = function(element) {
  7080. var descriptor = element.$descriptor;
  7081. this.element = element;
  7082. this.typeNs = this.nsTagName(descriptor);
  7083. // add xsi:type attribute to represent the elements
  7084. // actual type
  7085. var typeNs = this.typeNs,
  7086. pkg = element.$model.getPackage(typeNs.uri),
  7087. typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
  7088. this.addAttribute(this.nsAttributeName(XSI_TYPE),
  7089. (typeNs.prefix ? typeNs.prefix + ':' : '') +
  7090. typePrefix + descriptor.ns.localName);
  7091. // do the usual stuff
  7092. return ElementSerializer.prototype.build.call(this, element);
  7093. };
  7094. TypeSerializer.prototype.isLocalNs = function(ns) {
  7095. return ns.uri === this.typeNs.uri;
  7096. };
  7097. function SavingWriter() {
  7098. this.value = '';
  7099. this.write = function(str) {
  7100. this.value += str;
  7101. };
  7102. }
  7103. function FormatingWriter(out, format) {
  7104. var indent = [''];
  7105. this.append = function(str) {
  7106. out.write(str);
  7107. return this;
  7108. };
  7109. this.appendNewLine = function() {
  7110. if (format) {
  7111. out.write('\n');
  7112. }
  7113. return this;
  7114. };
  7115. this.appendIndent = function() {
  7116. if (format) {
  7117. out.write(indent.join(' '));
  7118. }
  7119. return this;
  7120. };
  7121. this.indent = function() {
  7122. indent.push('');
  7123. return this;
  7124. };
  7125. this.unindent = function() {
  7126. indent.pop();
  7127. return this;
  7128. };
  7129. }
  7130. /**
  7131. * A writer for meta-model backed document trees
  7132. *
  7133. * @param {Object} options output options to pass into the writer
  7134. */
  7135. function XMLWriter(options) {
  7136. options = assign({ format: false, preamble: true }, options || {});
  7137. function toXML(tree, writer) {
  7138. var internalWriter = writer || new SavingWriter();
  7139. var formatingWriter = new FormatingWriter(internalWriter, options.format);
  7140. if (options.preamble) {
  7141. formatingWriter.append(XML_PREAMBLE);
  7142. }
  7143. new ElementSerializer().build(tree).serializeTo(formatingWriter);
  7144. if (!writer) {
  7145. return internalWriter.value;
  7146. }
  7147. }
  7148. return {
  7149. toXML: toXML
  7150. };
  7151. }
  7152. module.exports = XMLWriter;
  7153. },{"216":216,"218":218,"221":221,"336":336,"339":339,"55":55,"65":65,"68":68}],58:[function(_dereq_,module,exports){
  7154. (function (Buffer){
  7155. // wrapper for non-node envs
  7156. ;(function (sax) {
  7157. sax.parser = function (strict, opt) { return new SAXParser(strict, opt) }
  7158. sax.SAXParser = SAXParser
  7159. sax.SAXStream = SAXStream
  7160. sax.createStream = createStream
  7161. // When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns.
  7162. // When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)),
  7163. // since that's the earliest that a buffer overrun could occur. This way, checks are
  7164. // as rare as required, but as often as necessary to ensure never crossing this bound.
  7165. // Furthermore, buffers are only tested at most once per write(), so passing a very
  7166. // large string into write() might have undesirable effects, but this is manageable by
  7167. // the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme
  7168. // edge case, result in creating at most one complete copy of the string passed in.
  7169. // Set to Infinity to have unlimited buffers.
  7170. sax.MAX_BUFFER_LENGTH = 64 * 1024
  7171. var buffers = [
  7172. "comment", "sgmlDecl", "textNode", "tagName", "doctype",
  7173. "procInstName", "procInstBody", "entity", "attribName",
  7174. "attribValue", "cdata", "script"
  7175. ]
  7176. sax.EVENTS = // for discoverability.
  7177. [ "text"
  7178. , "processinginstruction"
  7179. , "sgmldeclaration"
  7180. , "doctype"
  7181. , "comment"
  7182. , "attribute"
  7183. , "opentag"
  7184. , "closetag"
  7185. , "opencdata"
  7186. , "cdata"
  7187. , "closecdata"
  7188. , "error"
  7189. , "end"
  7190. , "ready"
  7191. , "script"
  7192. , "opennamespace"
  7193. , "closenamespace"
  7194. ]
  7195. function SAXParser (strict, opt) {
  7196. if (!(this instanceof SAXParser)) return new SAXParser(strict, opt)
  7197. var parser = this
  7198. clearBuffers(parser)
  7199. parser.q = parser.c = ""
  7200. parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH
  7201. parser.opt = opt || {}
  7202. parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags
  7203. parser.looseCase = parser.opt.lowercase ? "toLowerCase" : "toUpperCase"
  7204. parser.tags = []
  7205. parser.closed = parser.closedRoot = parser.sawRoot = false
  7206. parser.tag = parser.error = null
  7207. parser.strict = !!strict
  7208. parser.noscript = !!(strict || parser.opt.noscript)
  7209. parser.state = S.BEGIN
  7210. parser.ENTITIES = Object.create(sax.ENTITIES)
  7211. parser.attribList = []
  7212. // namespaces form a prototype chain.
  7213. // it always points at the current tag,
  7214. // which protos to its parent tag.
  7215. if (parser.opt.xmlns) parser.ns = Object.create(rootNS)
  7216. // mostly just for error reporting
  7217. parser.trackPosition = parser.opt.position !== false
  7218. if (parser.trackPosition) {
  7219. parser.position = parser.line = parser.column = 0
  7220. }
  7221. emit(parser, "onready")
  7222. }
  7223. if (!Object.create) Object.create = function (o) {
  7224. function f () { this.__proto__ = o }
  7225. f.prototype = o
  7226. return new f
  7227. }
  7228. if (!Object.getPrototypeOf) Object.getPrototypeOf = function (o) {
  7229. return o.__proto__
  7230. }
  7231. if (!Object.keys) Object.keys = function (o) {
  7232. var a = []
  7233. for (var i in o) if (o.hasOwnProperty(i)) a.push(i)
  7234. return a
  7235. }
  7236. function checkBufferLength (parser) {
  7237. var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10)
  7238. , maxActual = 0
  7239. for (var i = 0, l = buffers.length; i < l; i ++) {
  7240. var len = parser[buffers[i]].length
  7241. if (len > maxAllowed) {
  7242. // Text/cdata nodes can get big, and since they're buffered,
  7243. // we can get here under normal conditions.
  7244. // Avoid issues by emitting the text node now,
  7245. // so at least it won't get any bigger.
  7246. switch (buffers[i]) {
  7247. case "textNode":
  7248. closeText(parser)
  7249. break
  7250. case "cdata":
  7251. emitNode(parser, "oncdata", parser.cdata)
  7252. parser.cdata = ""
  7253. break
  7254. case "script":
  7255. emitNode(parser, "onscript", parser.script)
  7256. parser.script = ""
  7257. break
  7258. default:
  7259. error(parser, "Max buffer length exceeded: "+buffers[i])
  7260. }
  7261. }
  7262. maxActual = Math.max(maxActual, len)
  7263. }
  7264. // schedule the next check for the earliest possible buffer overrun.
  7265. parser.bufferCheckPosition = (sax.MAX_BUFFER_LENGTH - maxActual)
  7266. + parser.position
  7267. }
  7268. function clearBuffers (parser) {
  7269. for (var i = 0, l = buffers.length; i < l; i ++) {
  7270. parser[buffers[i]] = ""
  7271. }
  7272. }
  7273. function flushBuffers (parser) {
  7274. closeText(parser)
  7275. if (parser.cdata !== "") {
  7276. emitNode(parser, "oncdata", parser.cdata)
  7277. parser.cdata = ""
  7278. }
  7279. if (parser.script !== "") {
  7280. emitNode(parser, "onscript", parser.script)
  7281. parser.script = ""
  7282. }
  7283. }
  7284. SAXParser.prototype =
  7285. { end: function () { end(this) }
  7286. , write: write
  7287. , resume: function () { this.error = null; return this }
  7288. , close: function () { return this.write(null) }
  7289. , flush: function () { flushBuffers(this) }
  7290. }
  7291. try {
  7292. var Stream = _dereq_("stream").Stream
  7293. } catch (ex) {
  7294. var Stream = function () {}
  7295. }
  7296. var streamWraps = sax.EVENTS.filter(function (ev) {
  7297. return ev !== "error" && ev !== "end"
  7298. })
  7299. function createStream (strict, opt) {
  7300. return new SAXStream(strict, opt)
  7301. }
  7302. function SAXStream (strict, opt) {
  7303. if (!(this instanceof SAXStream)) return new SAXStream(strict, opt)
  7304. Stream.apply(this)
  7305. this._parser = new SAXParser(strict, opt)
  7306. this.writable = true
  7307. this.readable = true
  7308. var me = this
  7309. this._parser.onend = function () {
  7310. me.emit("end")
  7311. }
  7312. this._parser.onerror = function (er) {
  7313. me.emit("error", er)
  7314. // if didn't throw, then means error was handled.
  7315. // go ahead and clear error, so we can write again.
  7316. me._parser.error = null
  7317. }
  7318. this._decoder = null;
  7319. streamWraps.forEach(function (ev) {
  7320. Object.defineProperty(me, "on" + ev, {
  7321. get: function () { return me._parser["on" + ev] },
  7322. set: function (h) {
  7323. if (!h) {
  7324. me.removeAllListeners(ev)
  7325. return me._parser["on"+ev] = h
  7326. }
  7327. me.on(ev, h)
  7328. },
  7329. enumerable: true,
  7330. configurable: false
  7331. })
  7332. })
  7333. }
  7334. SAXStream.prototype = Object.create(Stream.prototype,
  7335. { constructor: { value: SAXStream } })
  7336. SAXStream.prototype.write = function (data) {
  7337. if (typeof Buffer === 'function' &&
  7338. typeof Buffer.isBuffer === 'function' &&
  7339. Buffer.isBuffer(data)) {
  7340. if (!this._decoder) {
  7341. var SD = _dereq_('string_decoder').StringDecoder
  7342. this._decoder = new SD('utf8')
  7343. }
  7344. data = this._decoder.write(data);
  7345. }
  7346. this._parser.write(data.toString())
  7347. this.emit("data", data)
  7348. return true
  7349. }
  7350. SAXStream.prototype.end = function (chunk) {
  7351. if (chunk && chunk.length) this.write(chunk)
  7352. this._parser.end()
  7353. return true
  7354. }
  7355. SAXStream.prototype.on = function (ev, handler) {
  7356. var me = this
  7357. if (!me._parser["on"+ev] && streamWraps.indexOf(ev) !== -1) {
  7358. me._parser["on"+ev] = function () {
  7359. var args = arguments.length === 1 ? [arguments[0]]
  7360. : Array.apply(null, arguments)
  7361. args.splice(0, 0, ev)
  7362. me.emit.apply(me, args)
  7363. }
  7364. }
  7365. return Stream.prototype.on.call(me, ev, handler)
  7366. }
  7367. // character classes and tokens
  7368. var whitespace = "\r\n\t "
  7369. // this really needs to be replaced with character classes.
  7370. // XML allows all manner of ridiculous numbers and digits.
  7371. , number = "0124356789"
  7372. , letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  7373. // (Letter | "_" | ":")
  7374. , quote = "'\""
  7375. , entity = number+letter+"#"
  7376. , attribEnd = whitespace + ">"
  7377. , CDATA = "[CDATA["
  7378. , DOCTYPE = "DOCTYPE"
  7379. , XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
  7380. , XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/"
  7381. , rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE }
  7382. // turn all the string character sets into character class objects.
  7383. whitespace = charClass(whitespace)
  7384. number = charClass(number)
  7385. letter = charClass(letter)
  7386. // http://www.w3.org/TR/REC-xml/#NT-NameStartChar
  7387. // This implementation works on strings, a single character at a time
  7388. // as such, it cannot ever support astral-plane characters (10000-EFFFF)
  7389. // without a significant breaking change to either this parser, or the
  7390. // JavaScript language. Implementation of an emoji-capable xml parser
  7391. // is left as an exercise for the reader.
  7392. var nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/
  7393. var nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040\.\d-]/
  7394. quote = charClass(quote)
  7395. entity = charClass(entity)
  7396. attribEnd = charClass(attribEnd)
  7397. function charClass (str) {
  7398. return str.split("").reduce(function (s, c) {
  7399. s[c] = true
  7400. return s
  7401. }, {})
  7402. }
  7403. function isRegExp (c) {
  7404. return Object.prototype.toString.call(c) === '[object RegExp]'
  7405. }
  7406. function is (charclass, c) {
  7407. return isRegExp(charclass) ? !!c.match(charclass) : charclass[c]
  7408. }
  7409. function not (charclass, c) {
  7410. return !is(charclass, c)
  7411. }
  7412. var S = 0
  7413. sax.STATE =
  7414. { BEGIN : S++
  7415. , TEXT : S++ // general stuff
  7416. , TEXT_ENTITY : S++ // &amp and such.
  7417. , OPEN_WAKA : S++ // <
  7418. , SGML_DECL : S++ // <!BLARG
  7419. , SGML_DECL_QUOTED : S++ // <!BLARG foo "bar
  7420. , DOCTYPE : S++ // <!DOCTYPE
  7421. , DOCTYPE_QUOTED : S++ // <!DOCTYPE "//blah
  7422. , DOCTYPE_DTD : S++ // <!DOCTYPE "//blah" [ ...
  7423. , DOCTYPE_DTD_QUOTED : S++ // <!DOCTYPE "//blah" [ "foo
  7424. , COMMENT_STARTING : S++ // <!-
  7425. , COMMENT : S++ // <!--
  7426. , COMMENT_ENDING : S++ // <!-- blah -
  7427. , COMMENT_ENDED : S++ // <!-- blah --
  7428. , CDATA : S++ // <![CDATA[ something
  7429. , CDATA_ENDING : S++ // ]
  7430. , CDATA_ENDING_2 : S++ // ]]
  7431. , PROC_INST : S++ // <?hi
  7432. , PROC_INST_BODY : S++ // <?hi there
  7433. , PROC_INST_ENDING : S++ // <?hi "there" ?
  7434. , OPEN_TAG : S++ // <strong
  7435. , OPEN_TAG_SLASH : S++ // <strong /
  7436. , ATTRIB : S++ // <a
  7437. , ATTRIB_NAME : S++ // <a foo
  7438. , ATTRIB_NAME_SAW_WHITE : S++ // <a foo _
  7439. , ATTRIB_VALUE : S++ // <a foo=
  7440. , ATTRIB_VALUE_QUOTED : S++ // <a foo="bar
  7441. , ATTRIB_VALUE_CLOSED : S++ // <a foo="bar"
  7442. , ATTRIB_VALUE_UNQUOTED : S++ // <a foo=bar
  7443. , ATTRIB_VALUE_ENTITY_Q : S++ // <foo bar="&quot;"
  7444. , ATTRIB_VALUE_ENTITY_U : S++ // <foo bar=&quot;
  7445. , CLOSE_TAG : S++ // </a
  7446. , CLOSE_TAG_SAW_WHITE : S++ // </a >
  7447. , SCRIPT : S++ // <script> ...
  7448. , SCRIPT_ENDING : S++ // <script> ... <
  7449. }
  7450. sax.ENTITIES =
  7451. { "amp" : "&"
  7452. , "gt" : ">"
  7453. , "lt" : "<"
  7454. , "quot" : "\""
  7455. , "apos" : "'"
  7456. , "AElig" : 198
  7457. , "Aacute" : 193
  7458. , "Acirc" : 194
  7459. , "Agrave" : 192
  7460. , "Aring" : 197
  7461. , "Atilde" : 195
  7462. , "Auml" : 196
  7463. , "Ccedil" : 199
  7464. , "ETH" : 208
  7465. , "Eacute" : 201
  7466. , "Ecirc" : 202
  7467. , "Egrave" : 200
  7468. , "Euml" : 203
  7469. , "Iacute" : 205
  7470. , "Icirc" : 206
  7471. , "Igrave" : 204
  7472. , "Iuml" : 207
  7473. , "Ntilde" : 209
  7474. , "Oacute" : 211
  7475. , "Ocirc" : 212
  7476. , "Ograve" : 210
  7477. , "Oslash" : 216
  7478. , "Otilde" : 213
  7479. , "Ouml" : 214
  7480. , "THORN" : 222
  7481. , "Uacute" : 218
  7482. , "Ucirc" : 219
  7483. , "Ugrave" : 217
  7484. , "Uuml" : 220
  7485. , "Yacute" : 221
  7486. , "aacute" : 225
  7487. , "acirc" : 226
  7488. , "aelig" : 230
  7489. , "agrave" : 224
  7490. , "aring" : 229
  7491. , "atilde" : 227
  7492. , "auml" : 228
  7493. , "ccedil" : 231
  7494. , "eacute" : 233
  7495. , "ecirc" : 234
  7496. , "egrave" : 232
  7497. , "eth" : 240
  7498. , "euml" : 235
  7499. , "iacute" : 237
  7500. , "icirc" : 238
  7501. , "igrave" : 236
  7502. , "iuml" : 239
  7503. , "ntilde" : 241
  7504. , "oacute" : 243
  7505. , "ocirc" : 244
  7506. , "ograve" : 242
  7507. , "oslash" : 248
  7508. , "otilde" : 245
  7509. , "ouml" : 246
  7510. , "szlig" : 223
  7511. , "thorn" : 254
  7512. , "uacute" : 250
  7513. , "ucirc" : 251
  7514. , "ugrave" : 249
  7515. , "uuml" : 252
  7516. , "yacute" : 253
  7517. , "yuml" : 255
  7518. , "copy" : 169
  7519. , "reg" : 174
  7520. , "nbsp" : 160
  7521. , "iexcl" : 161
  7522. , "cent" : 162
  7523. , "pound" : 163
  7524. , "curren" : 164
  7525. , "yen" : 165
  7526. , "brvbar" : 166
  7527. , "sect" : 167
  7528. , "uml" : 168
  7529. , "ordf" : 170
  7530. , "laquo" : 171
  7531. , "not" : 172
  7532. , "shy" : 173
  7533. , "macr" : 175
  7534. , "deg" : 176
  7535. , "plusmn" : 177
  7536. , "sup1" : 185
  7537. , "sup2" : 178
  7538. , "sup3" : 179
  7539. , "acute" : 180
  7540. , "micro" : 181
  7541. , "para" : 182
  7542. , "middot" : 183
  7543. , "cedil" : 184
  7544. , "ordm" : 186
  7545. , "raquo" : 187
  7546. , "frac14" : 188
  7547. , "frac12" : 189
  7548. , "frac34" : 190
  7549. , "iquest" : 191
  7550. , "times" : 215
  7551. , "divide" : 247
  7552. , "OElig" : 338
  7553. , "oelig" : 339
  7554. , "Scaron" : 352
  7555. , "scaron" : 353
  7556. , "Yuml" : 376
  7557. , "fnof" : 402
  7558. , "circ" : 710
  7559. , "tilde" : 732
  7560. , "Alpha" : 913
  7561. , "Beta" : 914
  7562. , "Gamma" : 915
  7563. , "Delta" : 916
  7564. , "Epsilon" : 917
  7565. , "Zeta" : 918
  7566. , "Eta" : 919
  7567. , "Theta" : 920
  7568. , "Iota" : 921
  7569. , "Kappa" : 922
  7570. , "Lambda" : 923
  7571. , "Mu" : 924
  7572. , "Nu" : 925
  7573. , "Xi" : 926
  7574. , "Omicron" : 927
  7575. , "Pi" : 928
  7576. , "Rho" : 929
  7577. , "Sigma" : 931
  7578. , "Tau" : 932
  7579. , "Upsilon" : 933
  7580. , "Phi" : 934
  7581. , "Chi" : 935
  7582. , "Psi" : 936
  7583. , "Omega" : 937
  7584. , "alpha" : 945
  7585. , "beta" : 946
  7586. , "gamma" : 947
  7587. , "delta" : 948
  7588. , "epsilon" : 949
  7589. , "zeta" : 950
  7590. , "eta" : 951
  7591. , "theta" : 952
  7592. , "iota" : 953
  7593. , "kappa" : 954
  7594. , "lambda" : 955
  7595. , "mu" : 956
  7596. , "nu" : 957
  7597. , "xi" : 958
  7598. , "omicron" : 959
  7599. , "pi" : 960
  7600. , "rho" : 961
  7601. , "sigmaf" : 962
  7602. , "sigma" : 963
  7603. , "tau" : 964
  7604. , "upsilon" : 965
  7605. , "phi" : 966
  7606. , "chi" : 967
  7607. , "psi" : 968
  7608. , "omega" : 969
  7609. , "thetasym" : 977
  7610. , "upsih" : 978
  7611. , "piv" : 982
  7612. , "ensp" : 8194
  7613. , "emsp" : 8195
  7614. , "thinsp" : 8201
  7615. , "zwnj" : 8204
  7616. , "zwj" : 8205
  7617. , "lrm" : 8206
  7618. , "rlm" : 8207
  7619. , "ndash" : 8211
  7620. , "mdash" : 8212
  7621. , "lsquo" : 8216
  7622. , "rsquo" : 8217
  7623. , "sbquo" : 8218
  7624. , "ldquo" : 8220
  7625. , "rdquo" : 8221
  7626. , "bdquo" : 8222
  7627. , "dagger" : 8224
  7628. , "Dagger" : 8225
  7629. , "bull" : 8226
  7630. , "hellip" : 8230
  7631. , "permil" : 8240
  7632. , "prime" : 8242
  7633. , "Prime" : 8243
  7634. , "lsaquo" : 8249
  7635. , "rsaquo" : 8250
  7636. , "oline" : 8254
  7637. , "frasl" : 8260
  7638. , "euro" : 8364
  7639. , "image" : 8465
  7640. , "weierp" : 8472
  7641. , "real" : 8476
  7642. , "trade" : 8482
  7643. , "alefsym" : 8501
  7644. , "larr" : 8592
  7645. , "uarr" : 8593
  7646. , "rarr" : 8594
  7647. , "darr" : 8595
  7648. , "harr" : 8596
  7649. , "crarr" : 8629
  7650. , "lArr" : 8656
  7651. , "uArr" : 8657
  7652. , "rArr" : 8658
  7653. , "dArr" : 8659
  7654. , "hArr" : 8660
  7655. , "forall" : 8704
  7656. , "part" : 8706
  7657. , "exist" : 8707
  7658. , "empty" : 8709
  7659. , "nabla" : 8711
  7660. , "isin" : 8712
  7661. , "notin" : 8713
  7662. , "ni" : 8715
  7663. , "prod" : 8719
  7664. , "sum" : 8721
  7665. , "minus" : 8722
  7666. , "lowast" : 8727
  7667. , "radic" : 8730
  7668. , "prop" : 8733
  7669. , "infin" : 8734
  7670. , "ang" : 8736
  7671. , "and" : 8743
  7672. , "or" : 8744
  7673. , "cap" : 8745
  7674. , "cup" : 8746
  7675. , "int" : 8747
  7676. , "there4" : 8756
  7677. , "sim" : 8764
  7678. , "cong" : 8773
  7679. , "asymp" : 8776
  7680. , "ne" : 8800
  7681. , "equiv" : 8801
  7682. , "le" : 8804
  7683. , "ge" : 8805
  7684. , "sub" : 8834
  7685. , "sup" : 8835
  7686. , "nsub" : 8836
  7687. , "sube" : 8838
  7688. , "supe" : 8839
  7689. , "oplus" : 8853
  7690. , "otimes" : 8855
  7691. , "perp" : 8869
  7692. , "sdot" : 8901
  7693. , "lceil" : 8968
  7694. , "rceil" : 8969
  7695. , "lfloor" : 8970
  7696. , "rfloor" : 8971
  7697. , "lang" : 9001
  7698. , "rang" : 9002
  7699. , "loz" : 9674
  7700. , "spades" : 9824
  7701. , "clubs" : 9827
  7702. , "hearts" : 9829
  7703. , "diams" : 9830
  7704. }
  7705. Object.keys(sax.ENTITIES).forEach(function (key) {
  7706. var e = sax.ENTITIES[key]
  7707. var s = typeof e === 'number' ? String.fromCharCode(e) : e
  7708. sax.ENTITIES[key] = s
  7709. })
  7710. for (var S in sax.STATE) sax.STATE[sax.STATE[S]] = S
  7711. // shorthand
  7712. S = sax.STATE
  7713. function emit (parser, event, data) {
  7714. parser[event] && parser[event](data)
  7715. }
  7716. function emitNode (parser, nodeType, data) {
  7717. if (parser.textNode) closeText(parser)
  7718. emit(parser, nodeType, data)
  7719. }
  7720. function closeText (parser) {
  7721. parser.textNode = textopts(parser.opt, parser.textNode)
  7722. if (parser.textNode) emit(parser, "ontext", parser.textNode)
  7723. parser.textNode = ""
  7724. }
  7725. function textopts (opt, text) {
  7726. if (opt.trim) text = text.trim()
  7727. if (opt.normalize) text = text.replace(/\s+/g, " ")
  7728. return text
  7729. }
  7730. function error (parser, er) {
  7731. closeText(parser)
  7732. if (parser.trackPosition) {
  7733. er += "\nLine: "+parser.line+
  7734. "\nColumn: "+parser.column+
  7735. "\nChar: "+parser.c
  7736. }
  7737. er = new Error(er)
  7738. parser.error = er
  7739. emit(parser, "onerror", er)
  7740. return parser
  7741. }
  7742. function end (parser) {
  7743. if (!parser.closedRoot) strictFail(parser, "Unclosed root tag")
  7744. if ((parser.state !== S.BEGIN) && (parser.state !== S.TEXT)) error(parser, "Unexpected end")
  7745. closeText(parser)
  7746. parser.c = ""
  7747. parser.closed = true
  7748. emit(parser, "onend")
  7749. SAXParser.call(parser, parser.strict, parser.opt)
  7750. return parser
  7751. }
  7752. function strictFail (parser, message) {
  7753. if (typeof parser !== 'object' || !(parser instanceof SAXParser))
  7754. throw new Error('bad call to strictFail');
  7755. if (parser.strict) error(parser, message)
  7756. }
  7757. function newTag (parser) {
  7758. if (!parser.strict) parser.tagName = parser.tagName[parser.looseCase]()
  7759. var parent = parser.tags[parser.tags.length - 1] || parser
  7760. , tag = parser.tag = { name : parser.tagName, attributes : {} }
  7761. // will be overridden if tag contails an xmlns="foo" or xmlns:foo="bar"
  7762. if (parser.opt.xmlns) tag.ns = parent.ns
  7763. parser.attribList.length = 0
  7764. }
  7765. function qname (name, attribute) {
  7766. var i = name.indexOf(":")
  7767. , qualName = i < 0 ? [ "", name ] : name.split(":")
  7768. , prefix = qualName[0]
  7769. , local = qualName[1]
  7770. // <x "xmlns"="http://foo">
  7771. if (attribute && name === "xmlns") {
  7772. prefix = "xmlns"
  7773. local = ""
  7774. }
  7775. return { prefix: prefix, local: local }
  7776. }
  7777. function attrib (parser) {
  7778. if (!parser.strict) parser.attribName = parser.attribName[parser.looseCase]()
  7779. if (parser.attribList.indexOf(parser.attribName) !== -1 ||
  7780. parser.tag.attributes.hasOwnProperty(parser.attribName)) {
  7781. return parser.attribName = parser.attribValue = ""
  7782. }
  7783. if (parser.opt.xmlns) {
  7784. var qn = qname(parser.attribName, true)
  7785. , prefix = qn.prefix
  7786. , local = qn.local
  7787. if (prefix === "xmlns") {
  7788. // namespace binding attribute; push the binding into scope
  7789. if (local === "xml" && parser.attribValue !== XML_NAMESPACE) {
  7790. strictFail( parser
  7791. , "xml: prefix must be bound to " + XML_NAMESPACE + "\n"
  7792. + "Actual: " + parser.attribValue )
  7793. } else if (local === "xmlns" && parser.attribValue !== XMLNS_NAMESPACE) {
  7794. strictFail( parser
  7795. , "xmlns: prefix must be bound to " + XMLNS_NAMESPACE + "\n"
  7796. + "Actual: " + parser.attribValue )
  7797. } else {
  7798. var tag = parser.tag
  7799. , parent = parser.tags[parser.tags.length - 1] || parser
  7800. if (tag.ns === parent.ns) {
  7801. tag.ns = Object.create(parent.ns)
  7802. }
  7803. tag.ns[local] = parser.attribValue
  7804. }
  7805. }
  7806. // defer onattribute events until all attributes have been seen
  7807. // so any new bindings can take effect; preserve attribute order
  7808. // so deferred events can be emitted in document order
  7809. parser.attribList.push([parser.attribName, parser.attribValue])
  7810. } else {
  7811. // in non-xmlns mode, we can emit the event right away
  7812. parser.tag.attributes[parser.attribName] = parser.attribValue
  7813. emitNode( parser
  7814. , "onattribute"
  7815. , { name: parser.attribName
  7816. , value: parser.attribValue } )
  7817. }
  7818. parser.attribName = parser.attribValue = ""
  7819. }
  7820. function openTag (parser, selfClosing) {
  7821. if (parser.opt.xmlns) {
  7822. // emit namespace binding events
  7823. var tag = parser.tag
  7824. // add namespace info to tag
  7825. var qn = qname(parser.tagName)
  7826. tag.prefix = qn.prefix
  7827. tag.local = qn.local
  7828. tag.uri = tag.ns[qn.prefix] || ""
  7829. if (tag.prefix && !tag.uri) {
  7830. strictFail(parser, "Unbound namespace prefix: "
  7831. + JSON.stringify(parser.tagName))
  7832. tag.uri = qn.prefix
  7833. }
  7834. var parent = parser.tags[parser.tags.length - 1] || parser
  7835. if (tag.ns && parent.ns !== tag.ns) {
  7836. Object.keys(tag.ns).forEach(function (p) {
  7837. emitNode( parser
  7838. , "onopennamespace"
  7839. , { prefix: p , uri: tag.ns[p] } )
  7840. })
  7841. }
  7842. // handle deferred onattribute events
  7843. // Note: do not apply default ns to attributes:
  7844. // http://www.w3.org/TR/REC-xml-names/#defaulting
  7845. for (var i = 0, l = parser.attribList.length; i < l; i ++) {
  7846. var nv = parser.attribList[i]
  7847. var name = nv[0]
  7848. , value = nv[1]
  7849. , qualName = qname(name, true)
  7850. , prefix = qualName.prefix
  7851. , local = qualName.local
  7852. , uri = prefix == "" ? "" : (tag.ns[prefix] || "")
  7853. , a = { name: name
  7854. , value: value
  7855. , prefix: prefix
  7856. , local: local
  7857. , uri: uri
  7858. }
  7859. // if there's any attributes with an undefined namespace,
  7860. // then fail on them now.
  7861. if (prefix && prefix != "xmlns" && !uri) {
  7862. strictFail(parser, "Unbound namespace prefix: "
  7863. + JSON.stringify(prefix))
  7864. a.uri = prefix
  7865. }
  7866. parser.tag.attributes[name] = a
  7867. emitNode(parser, "onattribute", a)
  7868. }
  7869. parser.attribList.length = 0
  7870. }
  7871. parser.tag.isSelfClosing = !!selfClosing
  7872. // process the tag
  7873. parser.sawRoot = true
  7874. parser.tags.push(parser.tag)
  7875. emitNode(parser, "onopentag", parser.tag)
  7876. if (!selfClosing) {
  7877. // special case for <script> in non-strict mode.
  7878. if (!parser.noscript && parser.tagName.toLowerCase() === "script") {
  7879. parser.state = S.SCRIPT
  7880. } else {
  7881. parser.state = S.TEXT
  7882. }
  7883. parser.tag = null
  7884. parser.tagName = ""
  7885. }
  7886. parser.attribName = parser.attribValue = ""
  7887. parser.attribList.length = 0
  7888. }
  7889. function closeTag (parser) {
  7890. if (!parser.tagName) {
  7891. strictFail(parser, "Weird empty close tag.")
  7892. parser.textNode += "</>"
  7893. parser.state = S.TEXT
  7894. return
  7895. }
  7896. if (parser.script) {
  7897. if (parser.tagName !== "script") {
  7898. parser.script += "</" + parser.tagName + ">"
  7899. parser.tagName = ""
  7900. parser.state = S.SCRIPT
  7901. return
  7902. }
  7903. emitNode(parser, "onscript", parser.script)
  7904. parser.script = ""
  7905. }
  7906. // first make sure that the closing tag actually exists.
  7907. // <a><b></c></b></a> will close everything, otherwise.
  7908. var t = parser.tags.length
  7909. var tagName = parser.tagName
  7910. if (!parser.strict) tagName = tagName[parser.looseCase]()
  7911. var closeTo = tagName
  7912. while (t --) {
  7913. var close = parser.tags[t]
  7914. if (close.name !== closeTo) {
  7915. // fail the first time in strict mode
  7916. strictFail(parser, "Unexpected close tag")
  7917. } else break
  7918. }
  7919. // didn't find it. we already failed for strict, so just abort.
  7920. if (t < 0) {
  7921. strictFail(parser, "Unmatched closing tag: "+parser.tagName)
  7922. parser.textNode += "</" + parser.tagName + ">"
  7923. parser.state = S.TEXT
  7924. return
  7925. }
  7926. parser.tagName = tagName
  7927. var s = parser.tags.length
  7928. while (s --> t) {
  7929. var tag = parser.tag = parser.tags.pop()
  7930. parser.tagName = parser.tag.name
  7931. emitNode(parser, "onclosetag", parser.tagName)
  7932. var x = {}
  7933. for (var i in tag.ns) x[i] = tag.ns[i]
  7934. var parent = parser.tags[parser.tags.length - 1] || parser
  7935. if (parser.opt.xmlns && tag.ns !== parent.ns) {
  7936. // remove namespace bindings introduced by tag
  7937. Object.keys(tag.ns).forEach(function (p) {
  7938. var n = tag.ns[p]
  7939. emitNode(parser, "onclosenamespace", { prefix: p, uri: n })
  7940. })
  7941. }
  7942. }
  7943. if (t === 0) parser.closedRoot = true
  7944. parser.tagName = parser.attribValue = parser.attribName = ""
  7945. parser.attribList.length = 0
  7946. parser.state = S.TEXT
  7947. }
  7948. function parseEntity (parser) {
  7949. var entity = parser.entity
  7950. , entityLC = entity.toLowerCase()
  7951. , num
  7952. , numStr = ""
  7953. if (parser.ENTITIES[entity])
  7954. return parser.ENTITIES[entity]
  7955. if (parser.ENTITIES[entityLC])
  7956. return parser.ENTITIES[entityLC]
  7957. entity = entityLC
  7958. if (entity.charAt(0) === "#") {
  7959. if (entity.charAt(1) === "x") {
  7960. entity = entity.slice(2)
  7961. num = parseInt(entity, 16)
  7962. numStr = num.toString(16)
  7963. } else {
  7964. entity = entity.slice(1)
  7965. num = parseInt(entity, 10)
  7966. numStr = num.toString(10)
  7967. }
  7968. }
  7969. entity = entity.replace(/^0+/, "")
  7970. if (numStr.toLowerCase() !== entity) {
  7971. strictFail(parser, "Invalid character entity")
  7972. return "&"+parser.entity + ";"
  7973. }
  7974. return String.fromCodePoint(num)
  7975. }
  7976. function write (chunk) {
  7977. var parser = this
  7978. if (this.error) throw this.error
  7979. if (parser.closed) return error(parser,
  7980. "Cannot write after close. Assign an onready handler.")
  7981. if (chunk === null) return end(parser)
  7982. var i = 0, c = ""
  7983. while (parser.c = c = chunk.charAt(i++)) {
  7984. if (parser.trackPosition) {
  7985. parser.position ++
  7986. if (c === "\n") {
  7987. parser.line ++
  7988. parser.column = 0
  7989. } else parser.column ++
  7990. }
  7991. switch (parser.state) {
  7992. case S.BEGIN:
  7993. if (c === "<") {
  7994. parser.state = S.OPEN_WAKA
  7995. parser.startTagPosition = parser.position
  7996. } else if (not(whitespace,c)) {
  7997. // have to process this as a text node.
  7998. // weird, but happens.
  7999. strictFail(parser, "Non-whitespace before first tag.")
  8000. parser.textNode = c
  8001. parser.state = S.TEXT
  8002. }
  8003. continue
  8004. case S.TEXT:
  8005. if (parser.sawRoot && !parser.closedRoot) {
  8006. var starti = i-1
  8007. while (c && c!=="<" && c!=="&") {
  8008. c = chunk.charAt(i++)
  8009. if (c && parser.trackPosition) {
  8010. parser.position ++
  8011. if (c === "\n") {
  8012. parser.line ++
  8013. parser.column = 0
  8014. } else parser.column ++
  8015. }
  8016. }
  8017. parser.textNode += chunk.substring(starti, i-1)
  8018. }
  8019. if (c === "<") {
  8020. parser.state = S.OPEN_WAKA
  8021. parser.startTagPosition = parser.position
  8022. } else {
  8023. if (not(whitespace, c) && (!parser.sawRoot || parser.closedRoot))
  8024. strictFail(parser, "Text data outside of root node.")
  8025. if (c === "&") parser.state = S.TEXT_ENTITY
  8026. else parser.textNode += c
  8027. }
  8028. continue
  8029. case S.SCRIPT:
  8030. // only non-strict
  8031. if (c === "<") {
  8032. parser.state = S.SCRIPT_ENDING
  8033. } else parser.script += c
  8034. continue
  8035. case S.SCRIPT_ENDING:
  8036. if (c === "/") {
  8037. parser.state = S.CLOSE_TAG
  8038. } else {
  8039. parser.script += "<" + c
  8040. parser.state = S.SCRIPT
  8041. }
  8042. continue
  8043. case S.OPEN_WAKA:
  8044. // either a /, ?, !, or text is coming next.
  8045. if (c === "!") {
  8046. parser.state = S.SGML_DECL
  8047. parser.sgmlDecl = ""
  8048. } else if (is(whitespace, c)) {
  8049. // wait for it...
  8050. } else if (is(nameStart,c)) {
  8051. parser.state = S.OPEN_TAG
  8052. parser.tagName = c
  8053. } else if (c === "/") {
  8054. parser.state = S.CLOSE_TAG
  8055. parser.tagName = ""
  8056. } else if (c === "?") {
  8057. parser.state = S.PROC_INST
  8058. parser.procInstName = parser.procInstBody = ""
  8059. } else {
  8060. strictFail(parser, "Unencoded <")
  8061. // if there was some whitespace, then add that in.
  8062. if (parser.startTagPosition + 1 < parser.position) {
  8063. var pad = parser.position - parser.startTagPosition
  8064. c = new Array(pad).join(" ") + c
  8065. }
  8066. parser.textNode += "<" + c
  8067. parser.state = S.TEXT
  8068. }
  8069. continue
  8070. case S.SGML_DECL:
  8071. if ((parser.sgmlDecl+c).toUpperCase() === CDATA) {
  8072. emitNode(parser, "onopencdata")
  8073. parser.state = S.CDATA
  8074. parser.sgmlDecl = ""
  8075. parser.cdata = ""
  8076. } else if (parser.sgmlDecl+c === "--") {
  8077. parser.state = S.COMMENT
  8078. parser.comment = ""
  8079. parser.sgmlDecl = ""
  8080. } else if ((parser.sgmlDecl+c).toUpperCase() === DOCTYPE) {
  8081. parser.state = S.DOCTYPE
  8082. if (parser.doctype || parser.sawRoot) strictFail(parser,
  8083. "Inappropriately located doctype declaration")
  8084. parser.doctype = ""
  8085. parser.sgmlDecl = ""
  8086. } else if (c === ">") {
  8087. emitNode(parser, "onsgmldeclaration", parser.sgmlDecl)
  8088. parser.sgmlDecl = ""
  8089. parser.state = S.TEXT
  8090. } else if (is(quote, c)) {
  8091. parser.state = S.SGML_DECL_QUOTED
  8092. parser.sgmlDecl += c
  8093. } else parser.sgmlDecl += c
  8094. continue
  8095. case S.SGML_DECL_QUOTED:
  8096. if (c === parser.q) {
  8097. parser.state = S.SGML_DECL
  8098. parser.q = ""
  8099. }
  8100. parser.sgmlDecl += c
  8101. continue
  8102. case S.DOCTYPE:
  8103. if (c === ">") {
  8104. parser.state = S.TEXT
  8105. emitNode(parser, "ondoctype", parser.doctype)
  8106. parser.doctype = true // just remember that we saw it.
  8107. } else {
  8108. parser.doctype += c
  8109. if (c === "[") parser.state = S.DOCTYPE_DTD
  8110. else if (is(quote, c)) {
  8111. parser.state = S.DOCTYPE_QUOTED
  8112. parser.q = c
  8113. }
  8114. }
  8115. continue
  8116. case S.DOCTYPE_QUOTED:
  8117. parser.doctype += c
  8118. if (c === parser.q) {
  8119. parser.q = ""
  8120. parser.state = S.DOCTYPE
  8121. }
  8122. continue
  8123. case S.DOCTYPE_DTD:
  8124. parser.doctype += c
  8125. if (c === "]") parser.state = S.DOCTYPE
  8126. else if (is(quote,c)) {
  8127. parser.state = S.DOCTYPE_DTD_QUOTED
  8128. parser.q = c
  8129. }
  8130. continue
  8131. case S.DOCTYPE_DTD_QUOTED:
  8132. parser.doctype += c
  8133. if (c === parser.q) {
  8134. parser.state = S.DOCTYPE_DTD
  8135. parser.q = ""
  8136. }
  8137. continue
  8138. case S.COMMENT:
  8139. if (c === "-") parser.state = S.COMMENT_ENDING
  8140. else parser.comment += c
  8141. continue
  8142. case S.COMMENT_ENDING:
  8143. if (c === "-") {
  8144. parser.state = S.COMMENT_ENDED
  8145. parser.comment = textopts(parser.opt, parser.comment)
  8146. if (parser.comment) emitNode(parser, "oncomment", parser.comment)
  8147. parser.comment = ""
  8148. } else {
  8149. parser.comment += "-" + c
  8150. parser.state = S.COMMENT
  8151. }
  8152. continue
  8153. case S.COMMENT_ENDED:
  8154. if (c !== ">") {
  8155. strictFail(parser, "Malformed comment")
  8156. // allow <!-- blah -- bloo --> in non-strict mode,
  8157. // which is a comment of " blah -- bloo "
  8158. parser.comment += "--" + c
  8159. parser.state = S.COMMENT
  8160. } else parser.state = S.TEXT
  8161. continue
  8162. case S.CDATA:
  8163. if (c === "]") parser.state = S.CDATA_ENDING
  8164. else parser.cdata += c
  8165. continue
  8166. case S.CDATA_ENDING:
  8167. if (c === "]") parser.state = S.CDATA_ENDING_2
  8168. else {
  8169. parser.cdata += "]" + c
  8170. parser.state = S.CDATA
  8171. }
  8172. continue
  8173. case S.CDATA_ENDING_2:
  8174. if (c === ">") {
  8175. if (parser.cdata) emitNode(parser, "oncdata", parser.cdata)
  8176. emitNode(parser, "onclosecdata")
  8177. parser.cdata = ""
  8178. parser.state = S.TEXT
  8179. } else if (c === "]") {
  8180. parser.cdata += "]"
  8181. } else {
  8182. parser.cdata += "]]" + c
  8183. parser.state = S.CDATA
  8184. }
  8185. continue
  8186. case S.PROC_INST:
  8187. if (c === "?") parser.state = S.PROC_INST_ENDING
  8188. else if (is(whitespace, c)) parser.state = S.PROC_INST_BODY
  8189. else parser.procInstName += c
  8190. continue
  8191. case S.PROC_INST_BODY:
  8192. if (!parser.procInstBody && is(whitespace, c)) continue
  8193. else if (c === "?") parser.state = S.PROC_INST_ENDING
  8194. else parser.procInstBody += c
  8195. continue
  8196. case S.PROC_INST_ENDING:
  8197. if (c === ">") {
  8198. emitNode(parser, "onprocessinginstruction", {
  8199. name : parser.procInstName,
  8200. body : parser.procInstBody
  8201. })
  8202. parser.procInstName = parser.procInstBody = ""
  8203. parser.state = S.TEXT
  8204. } else {
  8205. parser.procInstBody += "?" + c
  8206. parser.state = S.PROC_INST_BODY
  8207. }
  8208. continue
  8209. case S.OPEN_TAG:
  8210. if (is(nameBody, c)) parser.tagName += c
  8211. else {
  8212. newTag(parser)
  8213. if (c === ">") openTag(parser)
  8214. else if (c === "/") parser.state = S.OPEN_TAG_SLASH
  8215. else {
  8216. if (not(whitespace, c)) strictFail(
  8217. parser, "Invalid character in tag name")
  8218. parser.state = S.ATTRIB
  8219. }
  8220. }
  8221. continue
  8222. case S.OPEN_TAG_SLASH:
  8223. if (c === ">") {
  8224. openTag(parser, true)
  8225. closeTag(parser)
  8226. } else {
  8227. strictFail(parser, "Forward-slash in opening tag not followed by >")
  8228. parser.state = S.ATTRIB
  8229. }
  8230. continue
  8231. case S.ATTRIB:
  8232. // haven't read the attribute name yet.
  8233. if (is(whitespace, c)) continue
  8234. else if (c === ">") openTag(parser)
  8235. else if (c === "/") parser.state = S.OPEN_TAG_SLASH
  8236. else if (is(nameStart, c)) {
  8237. parser.attribName = c
  8238. parser.attribValue = ""
  8239. parser.state = S.ATTRIB_NAME
  8240. } else strictFail(parser, "Invalid attribute name")
  8241. continue
  8242. case S.ATTRIB_NAME:
  8243. if (c === "=") parser.state = S.ATTRIB_VALUE
  8244. else if (c === ">") {
  8245. strictFail(parser, "Attribute without value")
  8246. parser.attribValue = parser.attribName
  8247. attrib(parser)
  8248. openTag(parser)
  8249. }
  8250. else if (is(whitespace, c)) parser.state = S.ATTRIB_NAME_SAW_WHITE
  8251. else if (is(nameBody, c)) parser.attribName += c
  8252. else strictFail(parser, "Invalid attribute name")
  8253. continue
  8254. case S.ATTRIB_NAME_SAW_WHITE:
  8255. if (c === "=") parser.state = S.ATTRIB_VALUE
  8256. else if (is(whitespace, c)) continue
  8257. else {
  8258. strictFail(parser, "Attribute without value")
  8259. parser.tag.attributes[parser.attribName] = ""
  8260. parser.attribValue = ""
  8261. emitNode(parser, "onattribute",
  8262. { name : parser.attribName, value : "" })
  8263. parser.attribName = ""
  8264. if (c === ">") openTag(parser)
  8265. else if (is(nameStart, c)) {
  8266. parser.attribName = c
  8267. parser.state = S.ATTRIB_NAME
  8268. } else {
  8269. strictFail(parser, "Invalid attribute name")
  8270. parser.state = S.ATTRIB
  8271. }
  8272. }
  8273. continue
  8274. case S.ATTRIB_VALUE:
  8275. if (is(whitespace, c)) continue
  8276. else if (is(quote, c)) {
  8277. parser.q = c
  8278. parser.state = S.ATTRIB_VALUE_QUOTED
  8279. } else {
  8280. strictFail(parser, "Unquoted attribute value")
  8281. parser.state = S.ATTRIB_VALUE_UNQUOTED
  8282. parser.attribValue = c
  8283. }
  8284. continue
  8285. case S.ATTRIB_VALUE_QUOTED:
  8286. if (c !== parser.q) {
  8287. if (c === "&") parser.state = S.ATTRIB_VALUE_ENTITY_Q
  8288. else parser.attribValue += c
  8289. continue
  8290. }
  8291. attrib(parser)
  8292. parser.q = ""
  8293. parser.state = S.ATTRIB_VALUE_CLOSED
  8294. continue
  8295. case S.ATTRIB_VALUE_CLOSED:
  8296. if (is(whitespace, c)) {
  8297. parser.state = S.ATTRIB
  8298. } else if (c === ">") openTag(parser)
  8299. else if (c === "/") parser.state = S.OPEN_TAG_SLASH
  8300. else if (is(nameStart, c)) {
  8301. strictFail(parser, "No whitespace between attributes")
  8302. parser.attribName = c
  8303. parser.attribValue = ""
  8304. parser.state = S.ATTRIB_NAME
  8305. } else strictFail(parser, "Invalid attribute name")
  8306. continue
  8307. case S.ATTRIB_VALUE_UNQUOTED:
  8308. if (not(attribEnd,c)) {
  8309. if (c === "&") parser.state = S.ATTRIB_VALUE_ENTITY_U
  8310. else parser.attribValue += c
  8311. continue
  8312. }
  8313. attrib(parser)
  8314. if (c === ">") openTag(parser)
  8315. else parser.state = S.ATTRIB
  8316. continue
  8317. case S.CLOSE_TAG:
  8318. if (!parser.tagName) {
  8319. if (is(whitespace, c)) continue
  8320. else if (not(nameStart, c)) {
  8321. if (parser.script) {
  8322. parser.script += "</" + c
  8323. parser.state = S.SCRIPT
  8324. } else {
  8325. strictFail(parser, "Invalid tagname in closing tag.")
  8326. }
  8327. } else parser.tagName = c
  8328. }
  8329. else if (c === ">") closeTag(parser)
  8330. else if (is(nameBody, c)) parser.tagName += c
  8331. else if (parser.script) {
  8332. parser.script += "</" + parser.tagName
  8333. parser.tagName = ""
  8334. parser.state = S.SCRIPT
  8335. } else {
  8336. if (not(whitespace, c)) strictFail(parser,
  8337. "Invalid tagname in closing tag")
  8338. parser.state = S.CLOSE_TAG_SAW_WHITE
  8339. }
  8340. continue
  8341. case S.CLOSE_TAG_SAW_WHITE:
  8342. if (is(whitespace, c)) continue
  8343. if (c === ">") closeTag(parser)
  8344. else strictFail(parser, "Invalid characters in closing tag")
  8345. continue
  8346. case S.TEXT_ENTITY:
  8347. case S.ATTRIB_VALUE_ENTITY_Q:
  8348. case S.ATTRIB_VALUE_ENTITY_U:
  8349. switch(parser.state) {
  8350. case S.TEXT_ENTITY:
  8351. var returnState = S.TEXT, buffer = "textNode"
  8352. break
  8353. case S.ATTRIB_VALUE_ENTITY_Q:
  8354. var returnState = S.ATTRIB_VALUE_QUOTED, buffer = "attribValue"
  8355. break
  8356. case S.ATTRIB_VALUE_ENTITY_U:
  8357. var returnState = S.ATTRIB_VALUE_UNQUOTED, buffer = "attribValue"
  8358. break
  8359. }
  8360. if (c === ";") {
  8361. parser[buffer] += parseEntity(parser)
  8362. parser.entity = ""
  8363. parser.state = returnState
  8364. }
  8365. else if (is(entity, c)) parser.entity += c
  8366. else {
  8367. strictFail(parser, "Invalid character entity")
  8368. parser[buffer] += "&" + parser.entity + c
  8369. parser.entity = ""
  8370. parser.state = returnState
  8371. }
  8372. continue
  8373. default:
  8374. throw new Error(parser, "Unknown state: " + parser.state)
  8375. }
  8376. } // while
  8377. // cdata blocks can get very big under normal conditions. emit and move on.
  8378. // if (parser.state === S.CDATA && parser.cdata) {
  8379. // emitNode(parser, "oncdata", parser.cdata)
  8380. // parser.cdata = ""
  8381. // }
  8382. if (parser.position >= parser.bufferCheckPosition) checkBufferLength(parser)
  8383. return parser
  8384. }
  8385. /*! http://mths.be/fromcodepoint v0.1.0 by @mathias */
  8386. if (!String.fromCodePoint) {
  8387. (function() {
  8388. var stringFromCharCode = String.fromCharCode;
  8389. var floor = Math.floor;
  8390. var fromCodePoint = function() {
  8391. var MAX_SIZE = 0x4000;
  8392. var codeUnits = [];
  8393. var highSurrogate;
  8394. var lowSurrogate;
  8395. var index = -1;
  8396. var length = arguments.length;
  8397. if (!length) {
  8398. return '';
  8399. }
  8400. var result = '';
  8401. while (++index < length) {
  8402. var codePoint = Number(arguments[index]);
  8403. if (
  8404. !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
  8405. codePoint < 0 || // not a valid Unicode code point
  8406. codePoint > 0x10FFFF || // not a valid Unicode code point
  8407. floor(codePoint) != codePoint // not an integer
  8408. ) {
  8409. throw RangeError('Invalid code point: ' + codePoint);
  8410. }
  8411. if (codePoint <= 0xFFFF) { // BMP code point
  8412. codeUnits.push(codePoint);
  8413. } else { // Astral code point; split in surrogate halves
  8414. // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  8415. codePoint -= 0x10000;
  8416. highSurrogate = (codePoint >> 10) + 0xD800;
  8417. lowSurrogate = (codePoint % 0x400) + 0xDC00;
  8418. codeUnits.push(highSurrogate, lowSurrogate);
  8419. }
  8420. if (index + 1 == length || codeUnits.length > MAX_SIZE) {
  8421. result += stringFromCharCode.apply(null, codeUnits);
  8422. codeUnits.length = 0;
  8423. }
  8424. }
  8425. return result;
  8426. };
  8427. if (Object.defineProperty) {
  8428. Object.defineProperty(String, 'fromCodePoint', {
  8429. 'value': fromCodePoint,
  8430. 'configurable': true,
  8431. 'writable': true
  8432. });
  8433. } else {
  8434. String.fromCodePoint = fromCodePoint;
  8435. }
  8436. }());
  8437. }
  8438. })(typeof exports === "undefined" ? sax = {} : exports);
  8439. }).call(this,undefined)
  8440. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icG1uLW1vZGRsZS9ub2RlX21vZHVsZXMvbW9kZGxlLXhtbC9ub2RlX21vZHVsZXMvc2F4L2xpYi9zYXguanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6ImdlbmVyYXRlZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyIvLyB3cmFwcGVyIGZvciBub24tbm9kZSBlbnZzXG47KGZ1bmN0aW9uIChzYXgpIHtcblxuc2F4LnBhcnNlciA9IGZ1bmN0aW9uIChzdHJpY3QsIG9wdCkgeyByZXR1cm4gbmV3IFNBWFBhcnNlcihzdHJpY3QsIG9wdCkgfVxuc2F4LlNBWFBhcnNlciA9IFNBWFBhcnNlclxuc2F4LlNBWFN0cmVhbSA9IFNBWFN0cmVhbVxuc2F4LmNyZWF0ZVN0cmVhbSA9IGNyZWF0ZVN0cmVhbVxuXG4vLyBXaGVuIHdlIHBhc3MgdGhlIE1BWF9CVUZGRVJfTEVOR1RIIHBvc2l0aW9uLCBzdGFydCBjaGVja2luZyBmb3IgYnVmZmVyIG92ZXJydW5zLlxuLy8gV2hlbiB3ZSBjaGVjaywgc2NoZWR1bGUgdGhlIG5leHQgY2hlY2sgZm9yIE1BWF9CVUZGRVJfTEVOR1RIIC0gKG1heChidWZmZXIgbGVuZ3RocykpLFxuLy8gc2luY2UgdGhhdCdzIHRoZSBlYXJsaWVzdCB0aGF0IGEgYnVmZmVyIG92ZXJydW4gY291bGQgb2NjdXIuICBUaGlzIHdheSwgY2hlY2tzIGFyZVxuLy8gYXMgcmFyZSBhcyByZXF1aXJlZCwgYnV0IGFzIG9mdGVuIGFzIG5lY2Vzc2FyeSB0byBlbnN1cmUgbmV2ZXIgY3Jvc3NpbmcgdGhpcyBib3VuZC5cbi8vIEZ1cnRoZXJtb3JlLCBidWZmZXJzIGFyZSBvbmx5IHRlc3RlZCBhdCBtb3N0IG9uY2UgcGVyIHdyaXRlKCksIHNvIHBhc3NpbmcgYSB2ZXJ5XG4vLyBsYXJnZSBzdHJpbmcgaW50byB3cml0ZSgpIG1pZ2h0IGhhdmUgdW5kZXNpcmFibGUgZWZmZWN0cywgYnV0IHRoaXMgaXMgbWFuYWdlYWJsZSBieVxuLy8gdGhlIGNhbGxlciwgc28gaXQgaXMgYXNzdW1lZCB0byBiZSBzYWZlLiAgVGh1cywgYSBjYWxsIHRvIHdyaXRlKCkgbWF5LCBpbiB0aGUgZXh0cmVtZVxuLy8gZWRnZSBjYXNlLCByZXN1bHQgaW4gY3JlYXRpbmcgYXQgbW9zdCBvbmUgY29tcGxldGUgY29weSBvZiB0aGUgc3RyaW5nIHBhc3NlZCBpbi5cbi8vIFNldCB0byBJbmZpbml0eSB0byBoYXZlIHVubGltaXRlZCBidWZmZXJzLlxuc2F4Lk1BWF9CVUZGRVJfTEVOR1RIID0gNjQgKiAxMDI0XG5cbnZhciBidWZmZXJzID0gW1xuICBcImNvbW1lbnRcIiwgXCJzZ21sRGVjbFwiLCBcInRleHROb2RlXCIsIFwidGFnTmFtZVwiLCBcImRvY3R5cGVcIixcbiAgXCJwcm9jSW5zdE5hbWVcIiwgXCJwcm9jSW5zdEJvZHlcIiwgXCJlbnRpdHlcIiwgXCJhdHRyaWJOYW1lXCIsXG4gIFwiYXR0cmliVmFsdWVcIiwgXCJjZGF0YVwiLCBcInNjcmlwdFwiXG5dXG5cbnNheC5FVkVOVFMgPSAvLyBmb3IgZGlzY292ZXJhYmlsaXR5LlxuICBbIFwidGV4dFwiXG4gICwgXCJwcm9jZXNzaW5naW5zdHJ1Y3Rpb25cIlxuICAsIFwic2dtbGRlY2xhcmF0aW9uXCJcbiAgLCBcImRvY3R5cGVcIlxuICAsIFwiY29tbWVudFwiXG4gICwgXCJhdHRyaWJ1dGVcIlxuICAsIFwib3BlbnRhZ1wiXG4gICwgXCJjbG9zZXRhZ1wiXG4gICwgXCJvcGVuY2RhdGFcIlxuICAsIFwiY2RhdGFcIlxuICAsIFwiY2xvc2VjZGF0YVwiXG4gICwgXCJlcnJvclwiXG4gICwgXCJlbmRcIlxuICAsIFwicmVhZHlcIlxuICAsIFwic2NyaXB0XCJcbiAgLCBcIm9wZW5uYW1lc3BhY2VcIlxuICAsIFwiY2xvc2VuYW1lc3BhY2VcIlxuICBdXG5cbmZ1bmN0aW9uIFNBWFBhcnNlciAoc3RyaWN0LCBvcHQpIHtcbiAgaWYgKCEodGhpcyBpbnN0YW5jZW9mIFNBWFBhcnNlcikpIHJldHVybiBuZXcgU0FYUGFyc2VyKHN0cmljdCwgb3B0KVxuXG4gIHZhciBwYXJzZXIgPSB0aGlzXG4gIGNsZWFyQnVmZmVycyhwYXJzZXIpXG4gIHBhcnNlci5xID0gcGFyc2VyLmMgPSBcIlwiXG4gIHBhcnNlci5idWZmZXJDaGVja1Bvc2l0aW9uID0gc2F4Lk1BWF9CVUZGRVJfTEVOR1RIXG4gIHBhcnNlci5vcHQgPSBvcHQgfHwge31cbiAgcGFyc2VyLm9wdC5sb3dlcmNhc2UgPSBwYXJzZXIub3B0Lmxvd2VyY2FzZSB8fCBwYXJzZXIub3B0Lmxvd2VyY2FzZXRhZ3NcbiAgcGFyc2VyLmxvb3NlQ2FzZSA9IHBhcnNlci5vcHQubG93ZXJjYXNlID8gXCJ0b0xvd2VyQ2FzZVwiIDogXCJ0b1VwcGVyQ2FzZVwiXG4gIHBhcnNlci50YWdzID0gW11cbiAgcGFyc2VyLmNsb3NlZCA9IHBhcnNlci5jbG9zZWRSb290ID0gcGFyc2VyLnNhd1Jvb3QgPSBmYWxzZVxuICBwYXJzZXIudGFnID0gcGFyc2VyLmVycm9yID0gbnVsbFxuICBwYXJzZXIuc3RyaWN0ID0gISFzdHJpY3RcbiAgcGFyc2VyLm5vc2NyaXB0ID0gISEoc3RyaWN0IHx8IHBhcnNlci5vcHQubm9zY3JpcHQpXG4gIHBhcnNlci5zdGF0ZSA9IFMuQkVHSU5cbiAgcGFyc2VyLkVOVElUSUVTID0gT2JqZWN0LmNyZWF0ZShzYXguRU5USVRJRVMpXG4gIHBhcnNlci5hdHRyaWJMaXN0ID0gW11cblxuICAvLyBuYW1lc3BhY2VzIGZvcm0gYSBwcm90b3R5cGUgY2hhaW4uXG4gIC8vIGl0IGFsd2F5cyBwb2ludHMgYXQgdGhlIGN1cnJlbnQgdGFnLFxuICAvLyB3aGljaCBwcm90b3MgdG8gaXRzIHBhcmVudCB0YWcuXG4gIGlmIChwYXJzZXIub3B0LnhtbG5zKSBwYXJzZXIubnMgPSBPYmplY3QuY3JlYXRlKHJvb3ROUylcblxuICAvLyBtb3N0bHkganVzdCBmb3IgZXJyb3IgcmVwb3J0aW5nXG4gIHBhcnNlci50cmFja1Bvc2l0aW9uID0gcGFyc2VyLm9wdC5wb3NpdGlvbiAhPT0gZmFsc2VcbiAgaWYgKHBhcnNlci50cmFja1Bvc2l0aW9uKSB7XG4gICAgcGFyc2VyLnBvc2l0aW9uID0gcGFyc2VyLmxpbmUgPSBwYXJzZXIuY29sdW1uID0gMFxuICB9XG4gIGVtaXQocGFyc2VyLCBcIm9ucmVhZHlcIilcbn1cblxuaWYgKCFPYmplY3QuY3JlYXRlKSBPYmplY3QuY3JlYXRlID0gZnVuY3Rpb24gKG8pIHtcbiAgZnVuY3Rpb24gZiAoKSB7IHRoaXMuX19wcm90b19fID0gbyB9XG4gIGYucHJvdG90eXBlID0gb1xuICByZXR1cm4gbmV3IGZcbn1cblxuaWYgKCFPYmplY3QuZ2V0UHJvdG90eXBlT2YpIE9iamVjdC5nZXRQcm90b3R5cGVPZiA9IGZ1bmN0aW9uIChvKSB7XG4gIHJldHVybiBvLl9fcHJvdG9fX1xufVxuXG5pZiAoIU9iamVjdC5rZXlzKSBPYmplY3Qua2V5cyA9IGZ1bmN0aW9uIChvKSB7XG4gIHZhciBhID0gW11cbiAgZm9yICh2YXIgaSBpbiBvKSBpZiAoby5oYXNPd25Qcm9wZXJ0eShpKSkgYS5wdXNoKGkpXG4gIHJldHVybiBhXG59XG5cbmZ1bmN0aW9uIGNoZWNrQnVmZmVyTGVuZ3RoIChwYXJzZXIpIHtcbiAgdmFyIG1heEFsbG93ZWQgPSBNYXRoLm1heChzYXguTUFYX0JVRkZFUl9MRU5HVEgsIDEwKVxuICAgICwgbWF4QWN0dWFsID0gMFxuICBmb3IgKHZhciBpID0gMCwgbCA9IGJ1ZmZlcnMubGVuZ3RoOyBpIDwgbDsgaSArKykge1xuICAgIHZhciBsZW4gPSBwYXJzZXJbYnVmZmVyc1tpXV0ubGVuZ3RoXG4gICAgaWYgKGxlbiA+IG1heEFsbG93ZWQpIHtcbiAgICAgIC8vIFRleHQvY2RhdGEgbm9kZXMgY2FuIGdldCBiaWcsIGFuZCBzaW5jZSB0aGV5J3JlIGJ1ZmZlcmVkLFxuICAgICAgLy8gd2UgY2FuIGdldCBoZXJlIHVuZGVyIG5vcm1hbCBjb25kaXRpb25zLlxuICAgICAgLy8gQXZvaWQgaXNzdWVzIGJ5IGVtaXR0aW5nIHRoZSB0ZXh0IG5vZGUgbm93LFxuICAgICAgLy8gc28gYXQgbGVhc3QgaXQgd29uJ3QgZ2V0IGFueSBiaWdnZXIuXG4gICAgICBzd2l0Y2ggKGJ1ZmZlcnNbaV0pIHtcbiAgICAgICAgY2FzZSBcInRleHROb2RlXCI6XG4gICAgICAgICAgY2xvc2VUZXh0KHBhcnNlcilcbiAgICAgICAgYnJlYWtcblxuICAgICAgICBjYXNlIFwiY2RhdGFcIjpcbiAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsIFwib25jZGF0YVwiLCBwYXJzZXIuY2RhdGEpXG4gICAgICAgICAgcGFyc2VyLmNkYXRhID0gXCJcIlxuICAgICAgICBicmVha1xuXG4gICAgICAgIGNhc2UgXCJzY3JpcHRcIjpcbiAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsIFwib25zY3JpcHRcIiwgcGFyc2VyLnNjcmlwdClcbiAgICAgICAgICBwYXJzZXIuc2NyaXB0ID0gXCJcIlxuICAgICAgICBicmVha1xuXG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgZXJyb3IocGFyc2VyLCBcIk1heCBidWZmZXIgbGVuZ3RoIGV4Y2VlZGVkOiBcIitidWZmZXJzW2ldKVxuICAgICAgfVxuICAgIH1cbiAgICBtYXhBY3R1YWwgPSBNYXRoLm1heChtYXhBY3R1YWwsIGxlbilcbiAgfVxuICAvLyBzY2hlZHVsZSB0aGUgbmV4dCBjaGVjayBmb3IgdGhlIGVhcmxpZXN0IHBvc3NpYmxlIGJ1ZmZlciBvdmVycnVuLlxuICBwYXJzZXIuYnVmZmVyQ2hlY2tQb3NpdGlvbiA9IChzYXguTUFYX0JVRkZFUl9MRU5HVEggLSBtYXhBY3R1YWwpXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICsgcGFyc2VyLnBvc2l0aW9uXG59XG5cbmZ1bmN0aW9uIGNsZWFyQnVmZmVycyAocGFyc2VyKSB7XG4gIGZvciAodmFyIGkgPSAwLCBsID0gYnVmZmVycy5sZW5ndGg7IGkgPCBsOyBpICsrKSB7XG4gICAgcGFyc2VyW2J1ZmZlcnNbaV1dID0gXCJcIlxuICB9XG59XG5cbmZ1bmN0aW9uIGZsdXNoQnVmZmVycyAocGFyc2VyKSB7XG4gIGNsb3NlVGV4dChwYXJzZXIpXG4gIGlmIChwYXJzZXIuY2RhdGEgIT09IFwiXCIpIHtcbiAgICBlbWl0Tm9kZShwYXJzZXIsIFwib25jZGF0YVwiLCBwYXJzZXIuY2RhdGEpXG4gICAgcGFyc2VyLmNkYXRhID0gXCJcIlxuICB9XG4gIGlmIChwYXJzZXIuc2NyaXB0ICE9PSBcIlwiKSB7XG4gICAgZW1pdE5vZGUocGFyc2VyLCBcIm9uc2NyaXB0XCIsIHBhcnNlci5zY3JpcHQpXG4gICAgcGFyc2VyLnNjcmlwdCA9IFwiXCJcbiAgfVxufVxuXG5TQVhQYXJzZXIucHJvdG90eXBlID1cbiAgeyBlbmQ6IGZ1bmN0aW9uICgpIHsgZW5kKHRoaXMpIH1cbiAgLCB3cml0ZTogd3JpdGVcbiAgLCByZXN1bWU6IGZ1bmN0aW9uICgpIHsgdGhpcy5lcnJvciA9IG51bGw7IHJldHVybiB0aGlzIH1cbiAgLCBjbG9zZTogZnVuY3Rpb24gKCkgeyByZXR1cm4gdGhpcy53cml0ZShudWxsKSB9XG4gICwgZmx1c2g6IGZ1bmN0aW9uICgpIHsgZmx1c2hCdWZmZXJzKHRoaXMpIH1cbiAgfVxuXG50cnkge1xuICB2YXIgU3RyZWFtID0gcmVxdWlyZShcInN0cmVhbVwiKS5TdHJlYW1cbn0gY2F0Y2ggKGV4KSB7XG4gIHZhciBTdHJlYW0gPSBmdW5jdGlvbiAoKSB7fVxufVxuXG5cbnZhciBzdHJlYW1XcmFwcyA9IHNheC5FVkVOVFMuZmlsdGVyKGZ1bmN0aW9uIChldikge1xuICByZXR1cm4gZXYgIT09IFwiZXJyb3JcIiAmJiBldiAhPT0gXCJlbmRcIlxufSlcblxuZnVuY3Rpb24gY3JlYXRlU3RyZWFtIChzdHJpY3QsIG9wdCkge1xuICByZXR1cm4gbmV3IFNBWFN0cmVhbShzdHJpY3QsIG9wdClcbn1cblxuZnVuY3Rpb24gU0FYU3RyZWFtIChzdHJpY3QsIG9wdCkge1xuICBpZiAoISh0aGlzIGluc3RhbmNlb2YgU0FYU3RyZWFtKSkgcmV0dXJuIG5ldyBTQVhTdHJlYW0oc3RyaWN0LCBvcHQpXG5cbiAgU3RyZWFtLmFwcGx5KHRoaXMpXG5cbiAgdGhpcy5fcGFyc2VyID0gbmV3IFNBWFBhcnNlcihzdHJpY3QsIG9wdClcbiAgdGhpcy53cml0YWJsZSA9IHRydWVcbiAgdGhpcy5yZWFkYWJsZSA9IHRydWVcblxuXG4gIHZhciBtZSA9IHRoaXNcblxuICB0aGlzLl9wYXJzZXIub25lbmQgPSBmdW5jdGlvbiAoKSB7XG4gICAgbWUuZW1pdChcImVuZFwiKVxuICB9XG5cbiAgdGhpcy5fcGFyc2VyLm9uZXJyb3IgPSBmdW5jdGlvbiAoZXIpIHtcbiAgICBtZS5lbWl0KFwiZXJyb3JcIiwgZXIpXG5cbiAgICAvLyBpZiBkaWRuJ3QgdGhyb3csIHRoZW4gbWVhbnMgZXJyb3Igd2FzIGhhbmRsZWQuXG4gICAgLy8gZ28gYWhlYWQgYW5kIGNsZWFyIGVycm9yLCBzbyB3ZSBjYW4gd3JpdGUgYWdhaW4uXG4gICAgbWUuX3BhcnNlci5lcnJvciA9IG51bGxcbiAgfVxuXG4gIHRoaXMuX2RlY29kZXIgPSBudWxsO1xuXG4gIHN0cmVhbVdyYXBzLmZvckVhY2goZnVuY3Rpb24gKGV2KSB7XG4gICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KG1lLCBcIm9uXCIgKyBldiwge1xuICAgICAgZ2V0OiBmdW5jdGlvbiAoKSB7IHJldHVybiBtZS5fcGFyc2VyW1wib25cIiArIGV2XSB9LFxuICAgICAgc2V0OiBmdW5jdGlvbiAoaCkge1xuICAgICAgICBpZiAoIWgpIHtcbiAgICAgICAgICBtZS5yZW1vdmVBbGxMaXN0ZW5lcnMoZXYpXG4gICAgICAgICAgcmV0dXJuIG1lLl9wYXJzZXJbXCJvblwiK2V2XSA9IGhcbiAgICAgICAgfVxuICAgICAgICBtZS5vbihldiwgaClcbiAgICAgIH0sXG4gICAgICBlbnVtZXJhYmxlOiB0cnVlLFxuICAgICAgY29uZmlndXJhYmxlOiBmYWxzZVxuICAgIH0pXG4gIH0pXG59XG5cblNBWFN0cmVhbS5wcm90b3R5cGUgPSBPYmplY3QuY3JlYXRlKFN0cmVhbS5wcm90b3R5cGUsXG4gIHsgY29uc3RydWN0b3I6IHsgdmFsdWU6IFNBWFN0cmVhbSB9IH0pXG5cblNBWFN0cmVhbS5wcm90b3R5cGUud3JpdGUgPSBmdW5jdGlvbiAoZGF0YSkge1xuICBpZiAodHlwZW9mIEJ1ZmZlciA9PT0gJ2Z1bmN0aW9uJyAmJlxuICAgICAgdHlwZW9mIEJ1ZmZlci5pc0J1ZmZlciA9PT0gJ2Z1bmN0aW9uJyAmJlxuICAgICAgQnVmZmVyLmlzQnVmZmVyKGRhdGEpKSB7XG4gICAgaWYgKCF0aGlzLl9kZWNvZGVyKSB7XG4gICAgICB2YXIgU0QgPSByZXF1aXJlKCdzdHJpbmdfZGVjb2RlcicpLlN0cmluZ0RlY29kZXJcbiAgICAgIHRoaXMuX2RlY29kZXIgPSBuZXcgU0QoJ3V0ZjgnKVxuICAgIH1cbiAgICBkYXRhID0gdGhpcy5fZGVjb2Rlci53cml0ZShkYXRhKTtcbiAgfVxuXG4gIHRoaXMuX3BhcnNlci53cml0ZShkYXRhLnRvU3RyaW5nKCkpXG4gIHRoaXMuZW1pdChcImRhdGFcIiwgZGF0YSlcbiAgcmV0dXJuIHRydWVcbn1cblxuU0FYU3RyZWFtLnByb3RvdHlwZS5lbmQgPSBmdW5jdGlvbiAoY2h1bmspIHtcbiAgaWYgKGNodW5rICYmIGNodW5rLmxlbmd0aCkgdGhpcy53cml0ZShjaHVuaylcbiAgdGhpcy5fcGFyc2VyLmVuZCgpXG4gIHJldHVybiB0cnVlXG59XG5cblNBWFN0cmVhbS5wcm90b3R5cGUub24gPSBmdW5jdGlvbiAoZXYsIGhhbmRsZXIpIHtcbiAgdmFyIG1lID0gdGhpc1xuICBpZiAoIW1lLl9wYXJzZXJbXCJvblwiK2V2XSAmJiBzdHJlYW1XcmFwcy5pbmRleE9mKGV2KSAhPT0gLTEpIHtcbiAgICBtZS5fcGFyc2VyW1wib25cIitldl0gPSBmdW5jdGlvbiAoKSB7XG4gICAgICB2YXIgYXJncyA9IGFyZ3VtZW50cy5sZW5ndGggPT09IDEgPyBbYXJndW1lbnRzWzBdXVxuICAgICAgICAgICAgICAgOiBBcnJheS5hcHBseShudWxsLCBhcmd1bWVudHMpXG4gICAgICBhcmdzLnNwbGljZSgwLCAwLCBldilcbiAgICAgIG1lLmVtaXQuYXBwbHkobWUsIGFyZ3MpXG4gICAgfVxuICB9XG5cbiAgcmV0dXJuIFN0cmVhbS5wcm90b3R5cGUub24uY2FsbChtZSwgZXYsIGhhbmRsZXIpXG59XG5cblxuXG4vLyBjaGFyYWN0ZXIgY2xhc3NlcyBhbmQgdG9rZW5zXG52YXIgd2hpdGVzcGFjZSA9IFwiXFxyXFxuXFx0IFwiXG4gIC8vIHRoaXMgcmVhbGx5IG5lZWRzIHRvIGJlIHJlcGxhY2VkIHdpdGggY2hhcmFjdGVyIGNsYXNzZXMuXG4gIC8vIFhNTCBhbGxvd3MgYWxsIG1hbm5lciBvZiByaWRpY3Vsb3VzIG51bWJlcnMgYW5kIGRpZ2l0cy5cbiAgLCBudW1iZXIgPSBcIjAxMjQzNTY3ODlcIlxuICAsIGxldHRlciA9IFwiYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWlwiXG4gIC8vIChMZXR0ZXIgfCBcIl9cIiB8IFwiOlwiKVxuICAsIHF1b3RlID0gXCInXFxcIlwiXG4gICwgZW50aXR5ID0gbnVtYmVyK2xldHRlcitcIiNcIlxuICAsIGF0dHJpYkVuZCA9IHdoaXRlc3BhY2UgKyBcIj5cIlxuICAsIENEQVRBID0gXCJbQ0RBVEFbXCJcbiAgLCBET0NUWVBFID0gXCJET0NUWVBFXCJcbiAgLCBYTUxfTkFNRVNQQUNFID0gXCJodHRwOi8vd3d3LnczLm9yZy9YTUwvMTk5OC9uYW1lc3BhY2VcIlxuICAsIFhNTE5TX05BTUVTUEFDRSA9IFwiaHR0cDovL3d3dy53My5vcmcvMjAwMC94bWxucy9cIlxuICAsIHJvb3ROUyA9IHsgeG1sOiBYTUxfTkFNRVNQQUNFLCB4bWxuczogWE1MTlNfTkFNRVNQQUNFIH1cblxuLy8gdHVybiBhbGwgdGhlIHN0cmluZyBjaGFyYWN0ZXIgc2V0cyBpbnRvIGNoYXJhY3RlciBjbGFzcyBvYmplY3RzLlxud2hpdGVzcGFjZSA9IGNoYXJDbGFzcyh3aGl0ZXNwYWNlKVxubnVtYmVyID0gY2hhckNsYXNzKG51bWJlcilcbmxldHRlciA9IGNoYXJDbGFzcyhsZXR0ZXIpXG5cbi8vIGh0dHA6Ly93d3cudzMub3JnL1RSL1JFQy14bWwvI05ULU5hbWVTdGFydENoYXJcbi8vIFRoaXMgaW1wbGVtZW50YXRpb24gd29ya3Mgb24gc3RyaW5ncywgYSBzaW5nbGUgY2hhcmFjdGVyIGF0IGEgdGltZVxuLy8gYXMgc3VjaCwgaXQgY2Fubm90IGV2ZXIgc3VwcG9ydCBhc3RyYWwtcGxhbmUgY2hhcmFjdGVycyAoMTAwMDAtRUZGRkYpXG4vLyB3aXRob3V0IGEgc2lnbmlmaWNhbnQgYnJlYWtpbmcgY2hhbmdlIHRvIGVpdGhlciB0aGlzICBwYXJzZXIsIG9yIHRoZVxuLy8gSmF2YVNjcmlwdCBsYW5ndWFnZS4gIEltcGxlbWVudGF0aW9uIG9mIGFuIGVtb2ppLWNhcGFibGUgeG1sIHBhcnNlclxuLy8gaXMgbGVmdCBhcyBhbiBleGVyY2lzZSBmb3IgdGhlIHJlYWRlci5cbnZhciBuYW1lU3RhcnQgPSAvWzpfQS1aYS16XFx1MDBDMC1cXHUwMEQ2XFx1MDBEOC1cXHUwMEY2XFx1MDBGOC1cXHUwMkZGXFx1MDM3MC1cXHUwMzdEXFx1MDM3Ri1cXHUxRkZGXFx1MjAwQy1cXHUyMDBEXFx1MjA3MC1cXHUyMThGXFx1MkMwMC1cXHUyRkVGXFx1MzAwMS1cXHVEN0ZGXFx1RjkwMC1cXHVGRENGXFx1RkRGMC1cXHVGRkZEXS9cblxudmFyIG5hbWVCb2R5ID0gL1s6X0EtWmEtelxcdTAwQzAtXFx1MDBENlxcdTAwRDgtXFx1MDBGNlxcdTAwRjgtXFx1MDJGRlxcdTAzNzAtXFx1MDM3RFxcdTAzN0YtXFx1MUZGRlxcdTIwMEMtXFx1MjAwRFxcdTIwNzAtXFx1MjE4RlxcdTJDMDAtXFx1MkZFRlxcdTMwMDEtXFx1RDdGRlxcdUY5MDAtXFx1RkRDRlxcdUZERjAtXFx1RkZGRFxcdTAwQjdcXHUwMzAwLVxcdTAzNkZcXHUyMDNGLVxcdTIwNDBcXC5cXGQtXS9cblxucXVvdGUgPSBjaGFyQ2xhc3MocXVvdGUpXG5lbnRpdHkgPSBjaGFyQ2xhc3MoZW50aXR5KVxuYXR0cmliRW5kID0gY2hhckNsYXNzKGF0dHJpYkVuZClcblxuZnVuY3Rpb24gY2hhckNsYXNzIChzdHIpIHtcbiAgcmV0dXJuIHN0ci5zcGxpdChcIlwiKS5yZWR1Y2UoZnVuY3Rpb24gKHMsIGMpIHtcbiAgICBzW2NdID0gdHJ1ZVxuICAgIHJldHVybiBzXG4gIH0sIHt9KVxufVxuXG5mdW5jdGlvbiBpc1JlZ0V4cCAoYykge1xuICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5jYWxsKGMpID09PSAnW29iamVjdCBSZWdFeHBdJ1xufVxuXG5mdW5jdGlvbiBpcyAoY2hhcmNsYXNzLCBjKSB7XG4gIHJldHVybiBpc1JlZ0V4cChjaGFyY2xhc3MpID8gISFjLm1hdGNoKGNoYXJjbGFzcykgOiBjaGFyY2xhc3NbY11cbn1cblxuZnVuY3Rpb24gbm90IChjaGFyY2xhc3MsIGMpIHtcbiAgcmV0dXJuICFpcyhjaGFyY2xhc3MsIGMpXG59XG5cbnZhciBTID0gMFxuc2F4LlNUQVRFID1cbnsgQkVHSU4gICAgICAgICAgICAgICAgICAgICA6IFMrK1xuLCBURVhUICAgICAgICAgICAgICAgICAgICAgIDogUysrIC8vIGdlbmVyYWwgc3R1ZmZcbiwgVEVYVF9FTlRJVFkgICAgICAgICAgICAgICA6IFMrKyAvLyAmYW1wIGFuZCBzdWNoLlxuLCBPUEVOX1dBS0EgICAgICAgICAgICAgICAgIDogUysrIC8vIDxcbiwgU0dNTF9ERUNMICAgICAgICAgICAgICAgICA6IFMrKyAvLyA8IUJMQVJHXG4sIFNHTUxfREVDTF9RVU9URUQgICAgICAgICAgOiBTKysgLy8gPCFCTEFSRyBmb28gXCJiYXJcbiwgRE9DVFlQRSAgICAgICAgICAgICAgICAgICA6IFMrKyAvLyA8IURPQ1RZUEVcbiwgRE9DVFlQRV9RVU9URUQgICAgICAgICAgICA6IFMrKyAvLyA8IURPQ1RZUEUgXCIvL2JsYWhcbiwgRE9DVFlQRV9EVEQgICAgICAgICAgICAgICA6IFMrKyAvLyA8IURPQ1RZUEUgXCIvL2JsYWhcIiBbIC4uLlxuLCBET0NUWVBFX0RURF9RVU9URUQgICAgICAgIDogUysrIC8vIDwhRE9DVFlQRSBcIi8vYmxhaFwiIFsgXCJmb29cbiwgQ09NTUVOVF9TVEFSVElORyAgICAgICAgICA6IFMrKyAvLyA8IS1cbiwgQ09NTUVOVCAgICAgICAgICAgICAgICAgICA6IFMrKyAvLyA8IS0tXG4sIENPTU1FTlRfRU5ESU5HICAgICAgICAgICAgOiBTKysgLy8gPCEtLSBibGFoIC1cbiwgQ09NTUVOVF9FTkRFRCAgICAgICAgICAgICA6IFMrKyAvLyA8IS0tIGJsYWggLS1cbiwgQ0RBVEEgICAgICAgICAgICAgICAgICAgICA6IFMrKyAvLyA8IVtDREFUQVsgc29tZXRoaW5nXG4sIENEQVRBX0VORElORyAgICAgICAgICAgICAgOiBTKysgLy8gXVxuLCBDREFUQV9FTkRJTkdfMiAgICAgICAgICAgIDogUysrIC8vIF1dXG4sIFBST0NfSU5TVCAgICAgICAgICAgICAgICAgOiBTKysgLy8gPD9oaVxuLCBQUk9DX0lOU1RfQk9EWSAgICAgICAgICAgIDogUysrIC8vIDw/aGkgdGhlcmVcbiwgUFJPQ19JTlNUX0VORElORyAgICAgICAgICA6IFMrKyAvLyA8P2hpIFwidGhlcmVcIiA/XG4sIE9QRU5fVEFHICAgICAgICAgICAgICAgICAgOiBTKysgLy8gPHN0cm9uZ1xuLCBPUEVOX1RBR19TTEFTSCAgICAgICAgICAgIDogUysrIC8vIDxzdHJvbmcgL1xuLCBBVFRSSUIgICAgICAgICAgICAgICAgICAgIDogUysrIC8vIDxhXG4sIEFUVFJJQl9OQU1FICAgICAgICAgICAgICAgOiBTKysgLy8gPGEgZm9vXG4sIEFUVFJJQl9OQU1FX1NBV19XSElURSAgICAgOiBTKysgLy8gPGEgZm9vIF9cbiwgQVRUUklCX1ZBTFVFICAgICAgICAgICAgICA6IFMrKyAvLyA8YSBmb289XG4sIEFUVFJJQl9WQUxVRV9RVU9URUQgICAgICAgOiBTKysgLy8gPGEgZm9vPVwiYmFyXG4sIEFUVFJJQl9WQUxVRV9DTE9TRUQgICAgICAgOiBTKysgLy8gPGEgZm9vPVwiYmFyXCJcbiwgQVRUUklCX1ZBTFVFX1VOUVVPVEVEICAgICA6IFMrKyAvLyA8YSBmb289YmFyXG4sIEFUVFJJQl9WQUxVRV9FTlRJVFlfUSAgICAgOiBTKysgLy8gPGZvbyBiYXI9XCImcXVvdDtcIlxuLCBBVFRSSUJfVkFMVUVfRU5USVRZX1UgICAgIDogUysrIC8vIDxmb28gYmFyPSZxdW90O1xuLCBDTE9TRV9UQUcgICAgICAgICAgICAgICAgIDogUysrIC8vIDwvYVxuLCBDTE9TRV9UQUdfU0FXX1dISVRFICAgICAgIDogUysrIC8vIDwvYSAgID5cbiwgU0NSSVBUICAgICAgICAgICAgICAgICAgICA6IFMrKyAvLyA8c2NyaXB0PiAuLi5cbiwgU0NSSVBUX0VORElORyAgICAgICAgICAgICA6IFMrKyAvLyA8c2NyaXB0PiAuLi4gPFxufVxuXG5zYXguRU5USVRJRVMgPVxueyBcImFtcFwiIDogXCImXCJcbiwgXCJndFwiIDogXCI+XCJcbiwgXCJsdFwiIDogXCI8XCJcbiwgXCJxdW90XCIgOiBcIlxcXCJcIlxuLCBcImFwb3NcIiA6IFwiJ1wiXG4sIFwiQUVsaWdcIiA6IDE5OFxuLCBcIkFhY3V0ZVwiIDogMTkzXG4sIFwiQWNpcmNcIiA6IDE5NFxuLCBcIkFncmF2ZVwiIDogMTkyXG4sIFwiQXJpbmdcIiA6IDE5N1xuLCBcIkF0aWxkZVwiIDogMTk1XG4sIFwiQXVtbFwiIDogMTk2XG4sIFwiQ2NlZGlsXCIgOiAxOTlcbiwgXCJFVEhcIiA6IDIwOFxuLCBcIkVhY3V0ZVwiIDogMjAxXG4sIFwiRWNpcmNcIiA6IDIwMlxuLCBcIkVncmF2ZVwiIDogMjAwXG4sIFwiRXVtbFwiIDogMjAzXG4sIFwiSWFjdXRlXCIgOiAyMDVcbiwgXCJJY2lyY1wiIDogMjA2XG4sIFwiSWdyYXZlXCIgOiAyMDRcbiwgXCJJdW1sXCIgOiAyMDdcbiwgXCJOdGlsZGVcIiA6IDIwOVxuLCBcIk9hY3V0ZVwiIDogMjExXG4sIFwiT2NpcmNcIiA6IDIxMlxuLCBcIk9ncmF2ZVwiIDogMjEwXG4sIFwiT3NsYXNoXCIgOiAyMTZcbiwgXCJPdGlsZGVcIiA6IDIxM1xuLCBcIk91bWxcIiA6IDIxNFxuLCBcIlRIT1JOXCIgOiAyMjJcbiwgXCJVYWN1dGVcIiA6IDIxOFxuLCBcIlVjaXJjXCIgOiAyMTlcbiwgXCJVZ3JhdmVcIiA6IDIxN1xuLCBcIlV1bWxcIiA6IDIyMFxuLCBcIllhY3V0ZVwiIDogMjIxXG4sIFwiYWFjdXRlXCIgOiAyMjVcbiwgXCJhY2lyY1wiIDogMjI2XG4sIFwiYWVsaWdcIiA6IDIzMFxuLCBcImFncmF2ZVwiIDogMjI0XG4sIFwiYXJpbmdcIiA6IDIyOVxuLCBcImF0aWxkZVwiIDogMjI3XG4sIFwiYXVtbFwiIDogMjI4XG4sIFwiY2NlZGlsXCIgOiAyMzFcbiwgXCJlYWN1dGVcIiA6IDIzM1xuLCBcImVjaXJjXCIgOiAyMzRcbiwgXCJlZ3JhdmVcIiA6IDIzMlxuLCBcImV0aFwiIDogMjQwXG4sIFwiZXVtbFwiIDogMjM1XG4sIFwiaWFjdXRlXCIgOiAyMzdcbiwgXCJpY2lyY1wiIDogMjM4XG4sIFwiaWdyYXZlXCIgOiAyMzZcbiwgXCJpdW1sXCIgOiAyMzlcbiwgXCJudGlsZGVcIiA6IDI0MVxuLCBcIm9hY3V0ZVwiIDogMjQzXG4sIFwib2NpcmNcIiA6IDI0NFxuLCBcIm9ncmF2ZVwiIDogMjQyXG4sIFwib3NsYXNoXCIgOiAyNDhcbiwgXCJvdGlsZGVcIiA6IDI0NVxuLCBcIm91bWxcIiA6IDI0NlxuLCBcInN6bGlnXCIgOiAyMjNcbiwgXCJ0aG9yblwiIDogMjU0XG4sIFwidWFjdXRlXCIgOiAyNTBcbiwgXCJ1Y2lyY1wiIDogMjUxXG4sIFwidWdyYXZlXCIgOiAyNDlcbiwgXCJ1dW1sXCIgOiAyNTJcbiwgXCJ5YWN1dGVcIiA6IDI1M1xuLCBcInl1bWxcIiA6IDI1NVxuLCBcImNvcHlcIiA6IDE2OVxuLCBcInJlZ1wiIDogMTc0XG4sIFwibmJzcFwiIDogMTYwXG4sIFwiaWV4Y2xcIiA6IDE2MVxuLCBcImNlbnRcIiA6IDE2MlxuLCBcInBvdW5kXCIgOiAxNjNcbiwgXCJjdXJyZW5cIiA6IDE2NFxuLCBcInllblwiIDogMTY1XG4sIFwiYnJ2YmFyXCIgOiAxNjZcbiwgXCJzZWN0XCIgOiAxNjdcbiwgXCJ1bWxcIiA6IDE2OFxuLCBcIm9yZGZcIiA6IDE3MFxuLCBcImxhcXVvXCIgOiAxNzFcbiwgXCJub3RcIiA6IDE3MlxuLCBcInNoeVwiIDogMTczXG4sIFwibWFjclwiIDogMTc1XG4sIFwiZGVnXCIgOiAxNzZcbiwgXCJwbHVzbW5cIiA6IDE3N1xuLCBcInN1cDFcIiA6IDE4NVxuLCBcInN1cDJcIiA6IDE3OFxuLCBcInN1cDNcIiA6IDE3OVxuLCBcImFjdXRlXCIgOiAxODBcbiwgXCJtaWNyb1wiIDogMTgxXG4sIFwicGFyYVwiIDogMTgyXG4sIFwibWlkZG90XCIgOiAxODNcbiwgXCJjZWRpbFwiIDogMTg0XG4sIFwib3JkbVwiIDogMTg2XG4sIFwicmFxdW9cIiA6IDE4N1xuLCBcImZyYWMxNFwiIDogMTg4XG4sIFwiZnJhYzEyXCIgOiAxODlcbiwgXCJmcmFjMzRcIiA6IDE5MFxuLCBcImlxdWVzdFwiIDogMTkxXG4sIFwidGltZXNcIiA6IDIxNVxuLCBcImRpdmlkZVwiIDogMjQ3XG4sIFwiT0VsaWdcIiA6IDMzOFxuLCBcIm9lbGlnXCIgOiAzMzlcbiwgXCJTY2Fyb25cIiA6IDM1MlxuLCBcInNjYXJvblwiIDogMzUzXG4sIFwiWXVtbFwiIDogMzc2XG4sIFwiZm5vZlwiIDogNDAyXG4sIFwiY2lyY1wiIDogNzEwXG4sIFwidGlsZGVcIiA6IDczMlxuLCBcIkFscGhhXCIgOiA5MTNcbiwgXCJCZXRhXCIgOiA5MTRcbiwgXCJHYW1tYVwiIDogOTE1XG4sIFwiRGVsdGFcIiA6IDkxNlxuLCBcIkVwc2lsb25cIiA6IDkxN1xuLCBcIlpldGFcIiA6IDkxOFxuLCBcIkV0YVwiIDogOTE5XG4sIFwiVGhldGFcIiA6IDkyMFxuLCBcIklvdGFcIiA6IDkyMVxuLCBcIkthcHBhXCIgOiA5MjJcbiwgXCJMYW1iZGFcIiA6IDkyM1xuLCBcIk11XCIgOiA5MjRcbiwgXCJOdVwiIDogOTI1XG4sIFwiWGlcIiA6IDkyNlxuLCBcIk9taWNyb25cIiA6IDkyN1xuLCBcIlBpXCIgOiA5MjhcbiwgXCJSaG9cIiA6IDkyOVxuLCBcIlNpZ21hXCIgOiA5MzFcbiwgXCJUYXVcIiA6IDkzMlxuLCBcIlVwc2lsb25cIiA6IDkzM1xuLCBcIlBoaVwiIDogOTM0XG4sIFwiQ2hpXCIgOiA5MzVcbiwgXCJQc2lcIiA6IDkzNlxuLCBcIk9tZWdhXCIgOiA5MzdcbiwgXCJhbHBoYVwiIDogOTQ1XG4sIFwiYmV0YVwiIDogOTQ2XG4sIFwiZ2FtbWFcIiA6IDk0N1xuLCBcImRlbHRhXCIgOiA5NDhcbiwgXCJlcHNpbG9uXCIgOiA5NDlcbiwgXCJ6ZXRhXCIgOiA5NTBcbiwgXCJldGFcIiA6IDk1MVxuLCBcInRoZXRhXCIgOiA5NTJcbiwgXCJpb3RhXCIgOiA5NTNcbiwgXCJrYXBwYVwiIDogOTU0XG4sIFwibGFtYmRhXCIgOiA5NTVcbiwgXCJtdVwiIDogOTU2XG4sIFwibnVcIiA6IDk1N1xuLCBcInhpXCIgOiA5NThcbiwgXCJvbWljcm9uXCIgOiA5NTlcbiwgXCJwaVwiIDogOTYwXG4sIFwicmhvXCIgOiA5NjFcbiwgXCJzaWdtYWZcIiA6IDk2MlxuLCBcInNpZ21hXCIgOiA5NjNcbiwgXCJ0YXVcIiA6IDk2NFxuLCBcInVwc2lsb25cIiA6IDk2NVxuLCBcInBoaVwiIDogOTY2XG4sIFwiY2hpXCIgOiA5NjdcbiwgXCJwc2lcIiA6IDk2OFxuLCBcIm9tZWdhXCIgOiA5NjlcbiwgXCJ0aGV0YXN5bVwiIDogOTc3XG4sIFwidXBzaWhcIiA6IDk3OFxuLCBcInBpdlwiIDogOTgyXG4sIFwiZW5zcFwiIDogODE5NFxuLCBcImVtc3BcIiA6IDgxOTVcbiwgXCJ0aGluc3BcIiA6IDgyMDFcbiwgXCJ6d25qXCIgOiA4MjA0XG4sIFwiendqXCIgOiA4MjA1XG4sIFwibHJtXCIgOiA4MjA2XG4sIFwicmxtXCIgOiA4MjA3XG4sIFwibmRhc2hcIiA6IDgyMTFcbiwgXCJtZGFzaFwiIDogODIxMlxuLCBcImxzcXVvXCIgOiA4MjE2XG4sIFwicnNxdW9cIiA6IDgyMTdcbiwgXCJzYnF1b1wiIDogODIxOFxuLCBcImxkcXVvXCIgOiA4MjIwXG4sIFwicmRxdW9cIiA6IDgyMjFcbiwgXCJiZHF1b1wiIDogODIyMlxuLCBcImRhZ2dlclwiIDogODIyNFxuLCBcIkRhZ2dlclwiIDogODIyNVxuLCBcImJ1bGxcIiA6IDgyMjZcbiwgXCJoZWxsaXBcIiA6IDgyMzBcbiwgXCJwZXJtaWxcIiA6IDgyNDBcbiwgXCJwcmltZVwiIDogODI0MlxuLCBcIlByaW1lXCIgOiA4MjQzXG4sIFwibHNhcXVvXCIgOiA4MjQ5XG4sIFwicnNhcXVvXCIgOiA4MjUwXG4sIFwib2xpbmVcIiA6IDgyNTRcbiwgXCJmcmFzbFwiIDogODI2MFxuLCBcImV1cm9cIiA6IDgzNjRcbiwgXCJpbWFnZVwiIDogODQ2NVxuLCBcIndlaWVycFwiIDogODQ3MlxuLCBcInJlYWxcIiA6IDg0NzZcbiwgXCJ0cmFkZVwiIDogODQ4MlxuLCBcImFsZWZzeW1cIiA6IDg1MDFcbiwgXCJsYXJyXCIgOiA4NTkyXG4sIFwidWFyclwiIDogODU5M1xuLCBcInJhcnJcIiA6IDg1OTRcbiwgXCJkYXJyXCIgOiA4NTk1XG4sIFwiaGFyclwiIDogODU5NlxuLCBcImNyYXJyXCIgOiA4NjI5XG4sIFwibEFyclwiIDogODY1NlxuLCBcInVBcnJcIiA6IDg2NTdcbiwgXCJyQXJyXCIgOiA4NjU4XG4sIFwiZEFyclwiIDogODY1OVxuLCBcImhBcnJcIiA6IDg2NjBcbiwgXCJmb3JhbGxcIiA6IDg3MDRcbiwgXCJwYXJ0XCIgOiA4NzA2XG4sIFwiZXhpc3RcIiA6IDg3MDdcbiwgXCJlbXB0eVwiIDogODcwOVxuLCBcIm5hYmxhXCIgOiA4NzExXG4sIFwiaXNpblwiIDogODcxMlxuLCBcIm5vdGluXCIgOiA4NzEzXG4sIFwibmlcIiA6IDg3MTVcbiwgXCJwcm9kXCIgOiA4NzE5XG4sIFwic3VtXCIgOiA4NzIxXG4sIFwibWludXNcIiA6IDg3MjJcbiwgXCJsb3dhc3RcIiA6IDg3MjdcbiwgXCJyYWRpY1wiIDogODczMFxuLCBcInByb3BcIiA6IDg3MzNcbiwgXCJpbmZpblwiIDogODczNFxuLCBcImFuZ1wiIDogODczNlxuLCBcImFuZFwiIDogODc0M1xuLCBcIm9yXCIgOiA4NzQ0XG4sIFwiY2FwXCIgOiA4NzQ1XG4sIFwiY3VwXCIgOiA4NzQ2XG4sIFwiaW50XCIgOiA4NzQ3XG4sIFwidGhlcmU0XCIgOiA4NzU2XG4sIFwic2ltXCIgOiA4NzY0XG4sIFwiY29uZ1wiIDogODc3M1xuLCBcImFzeW1wXCIgOiA4Nzc2XG4sIFwibmVcIiA6IDg4MDBcbiwgXCJlcXVpdlwiIDogODgwMVxuLCBcImxlXCIgOiA4ODA0XG4sIFwiZ2VcIiA6IDg4MDVcbiwgXCJzdWJcIiA6IDg4MzRcbiwgXCJzdXBcIiA6IDg4MzVcbiwgXCJuc3ViXCIgOiA4ODM2XG4sIFwic3ViZVwiIDogODgzOFxuLCBcInN1cGVcIiA6IDg4MzlcbiwgXCJvcGx1c1wiIDogODg1M1xuLCBcIm90aW1lc1wiIDogODg1NVxuLCBcInBlcnBcIiA6IDg4NjlcbiwgXCJzZG90XCIgOiA4OTAxXG4sIFwibGNlaWxcIiA6IDg5NjhcbiwgXCJyY2VpbFwiIDogODk2OVxuLCBcImxmbG9vclwiIDogODk3MFxuLCBcInJmbG9vclwiIDogODk3MVxuLCBcImxhbmdcIiA6IDkwMDFcbiwgXCJyYW5nXCIgOiA5MDAyXG4sIFwibG96XCIgOiA5Njc0XG4sIFwic3BhZGVzXCIgOiA5ODI0XG4sIFwiY2x1YnNcIiA6IDk4MjdcbiwgXCJoZWFydHNcIiA6IDk4MjlcbiwgXCJkaWFtc1wiIDogOTgzMFxufVxuXG5PYmplY3Qua2V5cyhzYXguRU5USVRJRVMpLmZvckVhY2goZnVuY3Rpb24gKGtleSkge1xuICAgIHZhciBlID0gc2F4LkVOVElUSUVTW2tleV1cbiAgICB2YXIgcyA9IHR5cGVvZiBlID09PSAnbnVtYmVyJyA/IFN0cmluZy5mcm9tQ2hhckNvZGUoZSkgOiBlXG4gICAgc2F4LkVOVElUSUVTW2tleV0gPSBzXG59KVxuXG5mb3IgKHZhciBTIGluIHNheC5TVEFURSkgc2F4LlNUQVRFW3NheC5TVEFURVtTXV0gPSBTXG5cbi8vIHNob3J0aGFuZFxuUyA9IHNheC5TVEFURVxuXG5mdW5jdGlvbiBlbWl0IChwYXJzZXIsIGV2ZW50LCBkYXRhKSB7XG4gIHBhcnNlcltldmVudF0gJiYgcGFyc2VyW2V2ZW50XShkYXRhKVxufVxuXG5mdW5jdGlvbiBlbWl0Tm9kZSAocGFyc2VyLCBub2RlVHlwZSwgZGF0YSkge1xuICBpZiAocGFyc2VyLnRleHROb2RlKSBjbG9zZVRleHQocGFyc2VyKVxuICBlbWl0KHBhcnNlciwgbm9kZVR5cGUsIGRhdGEpXG59XG5cbmZ1bmN0aW9uIGNsb3NlVGV4dCAocGFyc2VyKSB7XG4gIHBhcnNlci50ZXh0Tm9kZSA9IHRleHRvcHRzKHBhcnNlci5vcHQsIHBhcnNlci50ZXh0Tm9kZSlcbiAgaWYgKHBhcnNlci50ZXh0Tm9kZSkgZW1pdChwYXJzZXIsIFwib250ZXh0XCIsIHBhcnNlci50ZXh0Tm9kZSlcbiAgcGFyc2VyLnRleHROb2RlID0gXCJcIlxufVxuXG5mdW5jdGlvbiB0ZXh0b3B0cyAob3B0LCB0ZXh0KSB7XG4gIGlmIChvcHQudHJpbSkgdGV4dCA9IHRleHQudHJpbSgpXG4gIGlmIChvcHQubm9ybWFsaXplKSB0ZXh0ID0gdGV4dC5yZXBsYWNlKC9cXHMrL2csIFwiIFwiKVxuICByZXR1cm4gdGV4dFxufVxuXG5mdW5jdGlvbiBlcnJvciAocGFyc2VyLCBlcikge1xuICBjbG9zZVRleHQocGFyc2VyKVxuICBpZiAocGFyc2VyLnRyYWNrUG9zaXRpb24pIHtcbiAgICBlciArPSBcIlxcbkxpbmU6IFwiK3BhcnNlci5saW5lK1xuICAgICAgICAgIFwiXFxuQ29sdW1uOiBcIitwYXJzZXIuY29sdW1uK1xuICAgICAgICAgIFwiXFxuQ2hhcjogXCIrcGFyc2VyLmNcbiAgfVxuICBlciA9IG5ldyBFcnJvcihlcilcbiAgcGFyc2VyLmVycm9yID0gZXJcbiAgZW1pdChwYXJzZXIsIFwib25lcnJvclwiLCBlcilcbiAgcmV0dXJuIHBhcnNlclxufVxuXG5mdW5jdGlvbiBlbmQgKHBhcnNlcikge1xuICBpZiAoIXBhcnNlci5jbG9zZWRSb290KSBzdHJpY3RGYWlsKHBhcnNlciwgXCJVbmNsb3NlZCByb290IHRhZ1wiKVxuICBpZiAoKHBhcnNlci5zdGF0ZSAhPT0gUy5CRUdJTikgJiYgKHBhcnNlci5zdGF0ZSAhPT0gUy5URVhUKSkgZXJyb3IocGFyc2VyLCBcIlVuZXhwZWN0ZWQgZW5kXCIpXG4gIGNsb3NlVGV4dChwYXJzZXIpXG4gIHBhcnNlci5jID0gXCJcIlxuICBwYXJzZXIuY2xvc2VkID0gdHJ1ZVxuICBlbWl0KHBhcnNlciwgXCJvbmVuZFwiKVxuICBTQVhQYXJzZXIuY2FsbChwYXJzZXIsIHBhcnNlci5zdHJpY3QsIHBhcnNlci5vcHQpXG4gIHJldHVybiBwYXJzZXJcbn1cblxuZnVuY3Rpb24gc3RyaWN0RmFpbCAocGFyc2VyLCBtZXNzYWdlKSB7XG4gIGlmICh0eXBlb2YgcGFyc2VyICE9PSAnb2JqZWN0JyB8fCAhKHBhcnNlciBpbnN0YW5jZW9mIFNBWFBhcnNlcikpXG4gICAgdGhyb3cgbmV3IEVycm9yKCdiYWQgY2FsbCB0byBzdHJpY3RGYWlsJyk7XG4gIGlmIChwYXJzZXIuc3RyaWN0KSBlcnJvcihwYXJzZXIsIG1lc3NhZ2UpXG59XG5cbmZ1bmN0aW9uIG5ld1RhZyAocGFyc2VyKSB7XG4gIGlmICghcGFyc2VyLnN0cmljdCkgcGFyc2VyLnRhZ05hbWUgPSBwYXJzZXIudGFnTmFtZVtwYXJzZXIubG9vc2VDYXNlXSgpXG4gIHZhciBwYXJlbnQgPSBwYXJzZXIudGFnc1twYXJzZXIudGFncy5sZW5ndGggLSAxXSB8fCBwYXJzZXJcbiAgICAsIHRhZyA9IHBhcnNlci50YWcgPSB7IG5hbWUgOiBwYXJzZXIudGFnTmFtZSwgYXR0cmlidXRlcyA6IHt9IH1cblxuICAvLyB3aWxsIGJlIG92ZXJyaWRkZW4gaWYgdGFnIGNvbnRhaWxzIGFuIHhtbG5zPVwiZm9vXCIgb3IgeG1sbnM6Zm9vPVwiYmFyXCJcbiAgaWYgKHBhcnNlci5vcHQueG1sbnMpIHRhZy5ucyA9IHBhcmVudC5uc1xuICBwYXJzZXIuYXR0cmliTGlzdC5sZW5ndGggPSAwXG59XG5cbmZ1bmN0aW9uIHFuYW1lIChuYW1lLCBhdHRyaWJ1dGUpIHtcbiAgdmFyIGkgPSBuYW1lLmluZGV4T2YoXCI6XCIpXG4gICAgLCBxdWFsTmFtZSA9IGkgPCAwID8gWyBcIlwiLCBuYW1lIF0gOiBuYW1lLnNwbGl0KFwiOlwiKVxuICAgICwgcHJlZml4ID0gcXVhbE5hbWVbMF1cbiAgICAsIGxvY2FsID0gcXVhbE5hbWVbMV1cblxuICAvLyA8eCBcInhtbG5zXCI9XCJodHRwOi8vZm9vXCI+XG4gIGlmIChhdHRyaWJ1dGUgJiYgbmFtZSA9PT0gXCJ4bWxuc1wiKSB7XG4gICAgcHJlZml4ID0gXCJ4bWxuc1wiXG4gICAgbG9jYWwgPSBcIlwiXG4gIH1cblxuICByZXR1cm4geyBwcmVmaXg6IHByZWZpeCwgbG9jYWw6IGxvY2FsIH1cbn1cblxuZnVuY3Rpb24gYXR0cmliIChwYXJzZXIpIHtcbiAgaWYgKCFwYXJzZXIuc3RyaWN0KSBwYXJzZXIuYXR0cmliTmFtZSA9IHBhcnNlci5hdHRyaWJOYW1lW3BhcnNlci5sb29zZUNhc2VdKClcblxuICBpZiAocGFyc2VyLmF0dHJpYkxpc3QuaW5kZXhPZihwYXJzZXIuYXR0cmliTmFtZSkgIT09IC0xIHx8XG4gICAgICBwYXJzZXIudGFnLmF0dHJpYnV0ZXMuaGFzT3duUHJvcGVydHkocGFyc2VyLmF0dHJpYk5hbWUpKSB7XG4gICAgcmV0dXJuIHBhcnNlci5hdHRyaWJOYW1lID0gcGFyc2VyLmF0dHJpYlZhbHVlID0gXCJcIlxuICB9XG5cbiAgaWYgKHBhcnNlci5vcHQueG1sbnMpIHtcbiAgICB2YXIgcW4gPSBxbmFtZShwYXJzZXIuYXR0cmliTmFtZSwgdHJ1ZSlcbiAgICAgICwgcHJlZml4ID0gcW4ucHJlZml4XG4gICAgICAsIGxvY2FsID0gcW4ubG9jYWxcblxuICAgIGlmIChwcmVmaXggPT09IFwieG1sbnNcIikge1xuICAgICAgLy8gbmFtZXNwYWNlIGJpbmRpbmcgYXR0cmlidXRlOyBwdXNoIHRoZSBiaW5kaW5nIGludG8gc2NvcGVcbiAgICAgIGlmIChsb2NhbCA9PT0gXCJ4bWxcIiAmJiBwYXJzZXIuYXR0cmliVmFsdWUgIT09IFhNTF9OQU1FU1BBQ0UpIHtcbiAgICAgICAgc3RyaWN0RmFpbCggcGFyc2VyXG4gICAgICAgICAgICAgICAgICAsIFwieG1sOiBwcmVmaXggbXVzdCBiZSBib3VuZCB0byBcIiArIFhNTF9OQU1FU1BBQ0UgKyBcIlxcblwiXG4gICAgICAgICAgICAgICAgICArIFwiQWN0dWFsOiBcIiArIHBhcnNlci5hdHRyaWJWYWx1ZSApXG4gICAgICB9IGVsc2UgaWYgKGxvY2FsID09PSBcInhtbG5zXCIgJiYgcGFyc2VyLmF0dHJpYlZhbHVlICE9PSBYTUxOU19OQU1FU1BBQ0UpIHtcbiAgICAgICAgc3RyaWN0RmFpbCggcGFyc2VyXG4gICAgICAgICAgICAgICAgICAsIFwieG1sbnM6IHByZWZpeCBtdXN0IGJlIGJvdW5kIHRvIFwiICsgWE1MTlNfTkFNRVNQQUNFICsgXCJcXG5cIlxuICAgICAgICAgICAgICAgICAgKyBcIkFjdHVhbDogXCIgKyBwYXJzZXIuYXR0cmliVmFsdWUgKVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgdmFyIHRhZyA9IHBhcnNlci50YWdcbiAgICAgICAgICAsIHBhcmVudCA9IHBhcnNlci50YWdzW3BhcnNlci50YWdzLmxlbmd0aCAtIDFdIHx8IHBhcnNlclxuICAgICAgICBpZiAodGFnLm5zID09PSBwYXJlbnQubnMpIHtcbiAgICAgICAgICB0YWcubnMgPSBPYmplY3QuY3JlYXRlKHBhcmVudC5ucylcbiAgICAgICAgfVxuICAgICAgICB0YWcubnNbbG9jYWxdID0gcGFyc2VyLmF0dHJpYlZhbHVlXG4gICAgICB9XG4gICAgfVxuXG4gICAgLy8gZGVmZXIgb25hdHRyaWJ1dGUgZXZlbnRzIHVudGlsIGFsbCBhdHRyaWJ1dGVzIGhhdmUgYmVlbiBzZWVuXG4gICAgLy8gc28gYW55IG5ldyBiaW5kaW5ncyBjYW4gdGFrZSBlZmZlY3Q7IHByZXNlcnZlIGF0dHJpYnV0ZSBvcmRlclxuICAgIC8vIHNvIGRlZmVycmVkIGV2ZW50cyBjYW4gYmUgZW1pdHRlZCBpbiBkb2N1bWVudCBvcmRlclxuICAgIHBhcnNlci5hdHRyaWJMaXN0LnB1c2goW3BhcnNlci5hdHRyaWJOYW1lLCBwYXJzZXIuYXR0cmliVmFsdWVdKVxuICB9IGVsc2Uge1xuICAgIC8vIGluIG5vbi14bWxucyBtb2RlLCB3ZSBjYW4gZW1pdCB0aGUgZXZlbnQgcmlnaHQgYXdheVxuICAgIHBhcnNlci50YWcuYXR0cmlidXRlc1twYXJzZXIuYXR0cmliTmFtZV0gPSBwYXJzZXIuYXR0cmliVmFsdWVcbiAgICBlbWl0Tm9kZSggcGFyc2VyXG4gICAgICAgICAgICAsIFwib25hdHRyaWJ1dGVcIlxuICAgICAgICAgICAgLCB7IG5hbWU6IHBhcnNlci5hdHRyaWJOYW1lXG4gICAgICAgICAgICAgICwgdmFsdWU6IHBhcnNlci5hdHRyaWJWYWx1ZSB9IClcbiAgfVxuXG4gIHBhcnNlci5hdHRyaWJOYW1lID0gcGFyc2VyLmF0dHJpYlZhbHVlID0gXCJcIlxufVxuXG5mdW5jdGlvbiBvcGVuVGFnIChwYXJzZXIsIHNlbGZDbG9zaW5nKSB7XG4gIGlmIChwYXJzZXIub3B0LnhtbG5zKSB7XG4gICAgLy8gZW1pdCBuYW1lc3BhY2UgYmluZGluZyBldmVudHNcbiAgICB2YXIgdGFnID0gcGFyc2VyLnRhZ1xuXG4gICAgLy8gYWRkIG5hbWVzcGFjZSBpbmZvIHRvIHRhZ1xuICAgIHZhciBxbiA9IHFuYW1lKHBhcnNlci50YWdOYW1lKVxuICAgIHRhZy5wcmVmaXggPSBxbi5wcmVmaXhcbiAgICB0YWcubG9jYWwgPSBxbi5sb2NhbFxuICAgIHRhZy51cmkgPSB0YWcubnNbcW4ucHJlZml4XSB8fCBcIlwiXG5cbiAgICBpZiAodGFnLnByZWZpeCAmJiAhdGFnLnVyaSkge1xuICAgICAgc3RyaWN0RmFpbChwYXJzZXIsIFwiVW5ib3VuZCBuYW1lc3BhY2UgcHJlZml4OiBcIlxuICAgICAgICAgICAgICAgICAgICAgICArIEpTT04uc3RyaW5naWZ5KHBhcnNlci50YWdOYW1lKSlcbiAgICAgIHRhZy51cmkgPSBxbi5wcmVmaXhcbiAgICB9XG5cbiAgICB2YXIgcGFyZW50ID0gcGFyc2VyLnRhZ3NbcGFyc2VyLnRhZ3MubGVuZ3RoIC0gMV0gfHwgcGFyc2VyXG4gICAgaWYgKHRhZy5ucyAmJiBwYXJlbnQubnMgIT09IHRhZy5ucykge1xuICAgICAgT2JqZWN0LmtleXModGFnLm5zKS5mb3JFYWNoKGZ1bmN0aW9uIChwKSB7XG4gICAgICAgIGVtaXROb2RlKCBwYXJzZXJcbiAgICAgICAgICAgICAgICAsIFwib25vcGVubmFtZXNwYWNlXCJcbiAgICAgICAgICAgICAgICAsIHsgcHJlZml4OiBwICwgdXJpOiB0YWcubnNbcF0gfSApXG4gICAgICB9KVxuICAgIH1cblxuICAgIC8vIGhhbmRsZSBkZWZlcnJlZCBvbmF0dHJpYnV0ZSBldmVudHNcbiAgICAvLyBOb3RlOiBkbyBub3QgYXBwbHkgZGVmYXVsdCBucyB0byBhdHRyaWJ1dGVzOlxuICAgIC8vICAgaHR0cDovL3d3dy53My5vcmcvVFIvUkVDLXhtbC1uYW1lcy8jZGVmYXVsdGluZ1xuICAgIGZvciAodmFyIGkgPSAwLCBsID0gcGFyc2VyLmF0dHJpYkxpc3QubGVuZ3RoOyBpIDwgbDsgaSArKykge1xuICAgICAgdmFyIG52ID0gcGFyc2VyLmF0dHJpYkxpc3RbaV1cbiAgICAgIHZhciBuYW1lID0gbnZbMF1cbiAgICAgICAgLCB2YWx1ZSA9IG52WzFdXG4gICAgICAgICwgcXVhbE5hbWUgPSBxbmFtZShuYW1lLCB0cnVlKVxuICAgICAgICAsIHByZWZpeCA9IHF1YWxOYW1lLnByZWZpeFxuICAgICAgICAsIGxvY2FsID0gcXVhbE5hbWUubG9jYWxcbiAgICAgICAgLCB1cmkgPSBwcmVmaXggPT0gXCJcIiA/IFwiXCIgOiAodGFnLm5zW3ByZWZpeF0gfHwgXCJcIilcbiAgICAgICAgLCBhID0geyBuYW1lOiBuYW1lXG4gICAgICAgICAgICAgICwgdmFsdWU6IHZhbHVlXG4gICAgICAgICAgICAgICwgcHJlZml4OiBwcmVmaXhcbiAgICAgICAgICAgICAgLCBsb2NhbDogbG9jYWxcbiAgICAgICAgICAgICAgLCB1cmk6IHVyaVxuICAgICAgICAgICAgICB9XG5cbiAgICAgIC8vIGlmIHRoZXJlJ3MgYW55IGF0dHJpYnV0ZXMgd2l0aCBhbiB1bmRlZmluZWQgbmFtZXNwYWNlLFxuICAgICAgLy8gdGhlbiBmYWlsIG9uIHRoZW0gbm93LlxuICAgICAgaWYgKHByZWZpeCAmJiBwcmVmaXggIT0gXCJ4bWxuc1wiICYmICF1cmkpIHtcbiAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsIFwiVW5ib3VuZCBuYW1lc3BhY2UgcHJlZml4OiBcIlxuICAgICAgICAgICAgICAgICAgICAgICAgICsgSlNPTi5zdHJpbmdpZnkocHJlZml4KSlcbiAgICAgICAgYS51cmkgPSBwcmVmaXhcbiAgICAgIH1cbiAgICAgIHBhcnNlci50YWcuYXR0cmlidXRlc1tuYW1lXSA9IGFcbiAgICAgIGVtaXROb2RlKHBhcnNlciwgXCJvbmF0dHJpYnV0ZVwiLCBhKVxuICAgIH1cbiAgICBwYXJzZXIuYXR0cmliTGlzdC5sZW5ndGggPSAwXG4gIH1cblxuICBwYXJzZXIudGFnLmlzU2VsZkNsb3NpbmcgPSAhIXNlbGZDbG9zaW5nXG5cbiAgLy8gcHJvY2VzcyB0aGUgdGFnXG4gIHBhcnNlci5zYXdSb290ID0gdHJ1ZVxuICBwYXJzZXIudGFncy5wdXNoKHBhcnNlci50YWcpXG4gIGVtaXROb2RlKHBhcnNlciwgXCJvbm9wZW50YWdcIiwgcGFyc2VyLnRhZylcbiAgaWYgKCFzZWxmQ2xvc2luZykge1xuICAgIC8vIHNwZWNpYWwgY2FzZSBmb3IgPHNjcmlwdD4gaW4gbm9uLXN0cmljdCBtb2RlLlxuICAgIGlmICghcGFyc2VyLm5vc2NyaXB0ICYmIHBhcnNlci50YWdOYW1lLnRvTG93ZXJDYXNlKCkgPT09IFwic2NyaXB0XCIpIHtcbiAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0NSSVBUXG4gICAgfSBlbHNlIHtcbiAgICAgIHBhcnNlci5zdGF0ZSA9IFMuVEVYVFxuICAgIH1cbiAgICBwYXJzZXIudGFnID0gbnVsbFxuICAgIHBhcnNlci50YWdOYW1lID0gXCJcIlxuICB9XG4gIHBhcnNlci5hdHRyaWJOYW1lID0gcGFyc2VyLmF0dHJpYlZhbHVlID0gXCJcIlxuICBwYXJzZXIuYXR0cmliTGlzdC5sZW5ndGggPSAwXG59XG5cbmZ1bmN0aW9uIGNsb3NlVGFnIChwYXJzZXIpIHtcbiAgaWYgKCFwYXJzZXIudGFnTmFtZSkge1xuICAgIHN0cmljdEZhaWwocGFyc2VyLCBcIldlaXJkIGVtcHR5IGNsb3NlIHRhZy5cIilcbiAgICBwYXJzZXIudGV4dE5vZGUgKz0gXCI8Lz5cIlxuICAgIHBhcnNlci5zdGF0ZSA9IFMuVEVYVFxuICAgIHJldHVyblxuICB9XG5cbiAgaWYgKHBhcnNlci5zY3JpcHQpIHtcbiAgICBpZiAocGFyc2VyLnRhZ05hbWUgIT09IFwic2NyaXB0XCIpIHtcbiAgICAgIHBhcnNlci5zY3JpcHQgKz0gXCI8L1wiICsgcGFyc2VyLnRhZ05hbWUgKyBcIj5cIlxuICAgICAgcGFyc2VyLnRhZ05hbWUgPSBcIlwiXG4gICAgICBwYXJzZXIuc3RhdGUgPSBTLlNDUklQVFxuICAgICAgcmV0dXJuXG4gICAgfVxuICAgIGVtaXROb2RlKHBhcnNlciwgXCJvbnNjcmlwdFwiLCBwYXJzZXIuc2NyaXB0KVxuICAgIHBhcnNlci5zY3JpcHQgPSBcIlwiXG4gIH1cblxuICAvLyBmaXJzdCBtYWtlIHN1cmUgdGhhdCB0aGUgY2xvc2luZyB0YWcgYWN0dWFsbHkgZXhpc3RzLlxuICAvLyA8YT48Yj48L2M+PC9iPjwvYT4gd2lsbCBjbG9zZSBldmVyeXRoaW5nLCBvdGhlcndpc2UuXG4gIHZhciB0ID0gcGFyc2VyLnRhZ3MubGVuZ3RoXG4gIHZhciB0YWdOYW1lID0gcGFyc2VyLnRhZ05hbWVcbiAgaWYgKCFwYXJzZXIuc3RyaWN0KSB0YWdOYW1lID0gdGFnTmFtZVtwYXJzZXIubG9vc2VDYXNlXSgpXG4gIHZhciBjbG9zZVRvID0gdGFnTmFtZVxuICB3aGlsZSAodCAtLSkge1xuICAgIHZhciBjbG9zZSA9IHBhcnNlci50YWdzW3RdXG4gICAgaWYgKGNsb3NlLm5hbWUgIT09IGNsb3NlVG8pIHtcbiAgICAgIC8vIGZhaWwgdGhlIGZpcnN0IHRpbWUgaW4gc3RyaWN0IG1vZGVcbiAgICAgIHN0cmljdEZhaWwocGFyc2VyLCBcIlVuZXhwZWN0ZWQgY2xvc2UgdGFnXCIpXG4gICAgfSBlbHNlIGJyZWFrXG4gIH1cblxuICAvLyBkaWRuJ3QgZmluZCBpdC4gIHdlIGFscmVhZHkgZmFpbGVkIGZvciBzdHJpY3QsIHNvIGp1c3QgYWJvcnQuXG4gIGlmICh0IDwgMCkge1xuICAgIHN0cmljdEZhaWwocGFyc2VyLCBcIlVubWF0Y2hlZCBjbG9zaW5nIHRhZzogXCIrcGFyc2VyLnRhZ05hbWUpXG4gICAgcGFyc2VyLnRleHROb2RlICs9IFwiPC9cIiArIHBhcnNlci50YWdOYW1lICsgXCI+XCJcbiAgICBwYXJzZXIuc3RhdGUgPSBTLlRFWFRcbiAgICByZXR1cm5cbiAgfVxuICBwYXJzZXIudGFnTmFtZSA9IHRhZ05hbWVcbiAgdmFyIHMgPSBwYXJzZXIudGFncy5sZW5ndGhcbiAgd2hpbGUgKHMgLS0+IHQpIHtcbiAgICB2YXIgdGFnID0gcGFyc2VyLnRhZyA9IHBhcnNlci50YWdzLnBvcCgpXG4gICAgcGFyc2VyLnRhZ05hbWUgPSBwYXJzZXIudGFnLm5hbWVcbiAgICBlbWl0Tm9kZShwYXJzZXIsIFwib25jbG9zZXRhZ1wiLCBwYXJzZXIudGFnTmFtZSlcblxuICAgIHZhciB4ID0ge31cbiAgICBmb3IgKHZhciBpIGluIHRhZy5ucykgeFtpXSA9IHRhZy5uc1tpXVxuXG4gICAgdmFyIHBhcmVudCA9IHBhcnNlci50YWdzW3BhcnNlci50YWdzLmxlbmd0aCAtIDFdIHx8IHBhcnNlclxuICAgIGlmIChwYXJzZXIub3B0LnhtbG5zICYmIHRhZy5ucyAhPT0gcGFyZW50Lm5zKSB7XG4gICAgICAvLyByZW1vdmUgbmFtZXNwYWNlIGJpbmRpbmdzIGludHJvZHVjZWQgYnkgdGFnXG4gICAgICBPYmplY3Qua2V5cyh0YWcubnMpLmZvckVhY2goZnVuY3Rpb24gKHApIHtcbiAgICAgICAgdmFyIG4gPSB0YWcubnNbcF1cbiAgICAgICAgZW1pdE5vZGUocGFyc2VyLCBcIm9uY2xvc2VuYW1lc3BhY2VcIiwgeyBwcmVmaXg6IHAsIHVyaTogbiB9KVxuICAgICAgfSlcbiAgICB9XG4gIH1cbiAgaWYgKHQgPT09IDApIHBhcnNlci5jbG9zZWRSb290ID0gdHJ1ZVxuICBwYXJzZXIudGFnTmFtZSA9IHBhcnNlci5hdHRyaWJWYWx1ZSA9IHBhcnNlci5hdHRyaWJOYW1lID0gXCJcIlxuICBwYXJzZXIuYXR0cmliTGlzdC5sZW5ndGggPSAwXG4gIHBhcnNlci5zdGF0ZSA9IFMuVEVYVFxufVxuXG5mdW5jdGlvbiBwYXJzZUVudGl0eSAocGFyc2VyKSB7XG4gIHZhciBlbnRpdHkgPSBwYXJzZXIuZW50aXR5XG4gICAgLCBlbnRpdHlMQyA9IGVudGl0eS50b0xvd2VyQ2FzZSgpXG4gICAgLCBudW1cbiAgICAsIG51bVN0ciA9IFwiXCJcbiAgaWYgKHBhcnNlci5FTlRJVElFU1tlbnRpdHldKVxuICAgIHJldHVybiBwYXJzZXIuRU5USVRJRVNbZW50aXR5XVxuICBpZiAocGFyc2VyLkVOVElUSUVTW2VudGl0eUxDXSlcbiAgICByZXR1cm4gcGFyc2VyLkVOVElUSUVTW2VudGl0eUxDXVxuICBlbnRpdHkgPSBlbnRpdHlMQ1xuICBpZiAoZW50aXR5LmNoYXJBdCgwKSA9PT0gXCIjXCIpIHtcbiAgICBpZiAoZW50aXR5LmNoYXJBdCgxKSA9PT0gXCJ4XCIpIHtcbiAgICAgIGVudGl0eSA9IGVudGl0eS5zbGljZSgyKVxuICAgICAgbnVtID0gcGFyc2VJbnQoZW50aXR5LCAxNilcbiAgICAgIG51bVN0ciA9IG51bS50b1N0cmluZygxNilcbiAgICB9IGVsc2Uge1xuICAgICAgZW50aXR5ID0gZW50aXR5LnNsaWNlKDEpXG4gICAgICBudW0gPSBwYXJzZUludChlbnRpdHksIDEwKVxuICAgICAgbnVtU3RyID0gbnVtLnRvU3RyaW5nKDEwKVxuICAgIH1cbiAgfVxuICBlbnRpdHkgPSBlbnRpdHkucmVwbGFjZSgvXjArLywgXCJcIilcbiAgaWYgKG51bVN0ci50b0xvd2VyQ2FzZSgpICE9PSBlbnRpdHkpIHtcbiAgICBzdHJpY3RGYWlsKHBhcnNlciwgXCJJbnZhbGlkIGNoYXJhY3RlciBlbnRpdHlcIilcbiAgICByZXR1cm4gXCImXCIrcGFyc2VyLmVudGl0eSArIFwiO1wiXG4gIH1cblxuICByZXR1cm4gU3RyaW5nLmZyb21Db2RlUG9pbnQobnVtKVxufVxuXG5mdW5jdGlvbiB3cml0ZSAoY2h1bmspIHtcbiAgdmFyIHBhcnNlciA9IHRoaXNcbiAgaWYgKHRoaXMuZXJyb3IpIHRocm93IHRoaXMuZXJyb3JcbiAgaWYgKHBhcnNlci5jbG9zZWQpIHJldHVybiBlcnJvcihwYXJzZXIsXG4gICAgXCJDYW5ub3Qgd3JpdGUgYWZ0ZXIgY2xvc2UuIEFzc2lnbiBhbiBvbnJlYWR5IGhhbmRsZXIuXCIpXG4gIGlmIChjaHVuayA9PT0gbnVsbCkgcmV0dXJuIGVuZChwYXJzZXIpXG4gIHZhciBpID0gMCwgYyA9IFwiXCJcbiAgd2hpbGUgKHBhcnNlci5jID0gYyA9IGNodW5rLmNoYXJBdChpKyspKSB7XG4gICAgaWYgKHBhcnNlci50cmFja1Bvc2l0aW9uKSB7XG4gICAgICBwYXJzZXIucG9zaXRpb24gKytcbiAgICAgIGlmIChjID09PSBcIlxcblwiKSB7XG4gICAgICAgIHBhcnNlci5saW5lICsrXG4gICAgICAgIHBhcnNlci5jb2x1bW4gPSAwXG4gICAgICB9IGVsc2UgcGFyc2VyLmNvbHVtbiArK1xuICAgIH1cbiAgICBzd2l0Y2ggKHBhcnNlci5zdGF0ZSkge1xuXG4gICAgICBjYXNlIFMuQkVHSU46XG4gICAgICAgIGlmIChjID09PSBcIjxcIikge1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuT1BFTl9XQUtBXG4gICAgICAgICAgcGFyc2VyLnN0YXJ0VGFnUG9zaXRpb24gPSBwYXJzZXIucG9zaXRpb25cbiAgICAgICAgfSBlbHNlIGlmIChub3Qod2hpdGVzcGFjZSxjKSkge1xuICAgICAgICAgIC8vIGhhdmUgdG8gcHJvY2VzcyB0aGlzIGFzIGEgdGV4dCBub2RlLlxuICAgICAgICAgIC8vIHdlaXJkLCBidXQgaGFwcGVucy5cbiAgICAgICAgICBzdHJpY3RGYWlsKHBhcnNlciwgXCJOb24td2hpdGVzcGFjZSBiZWZvcmUgZmlyc3QgdGFnLlwiKVxuICAgICAgICAgIHBhcnNlci50ZXh0Tm9kZSA9IGNcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlRFWFRcbiAgICAgICAgfVxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLlRFWFQ6XG4gICAgICAgIGlmIChwYXJzZXIuc2F3Um9vdCAmJiAhcGFyc2VyLmNsb3NlZFJvb3QpIHtcbiAgICAgICAgICB2YXIgc3RhcnRpID0gaS0xXG4gICAgICAgICAgd2hpbGUgKGMgJiYgYyE9PVwiPFwiICYmIGMhPT1cIiZcIikge1xuICAgICAgICAgICAgYyA9IGNodW5rLmNoYXJBdChpKyspXG4gICAgICAgICAgICBpZiAoYyAmJiBwYXJzZXIudHJhY2tQb3NpdGlvbikge1xuICAgICAgICAgICAgICBwYXJzZXIucG9zaXRpb24gKytcbiAgICAgICAgICAgICAgaWYgKGMgPT09IFwiXFxuXCIpIHtcbiAgICAgICAgICAgICAgICBwYXJzZXIubGluZSArK1xuICAgICAgICAgICAgICAgIHBhcnNlci5jb2x1bW4gPSAwXG4gICAgICAgICAgICAgIH0gZWxzZSBwYXJzZXIuY29sdW1uICsrXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIHBhcnNlci50ZXh0Tm9kZSArPSBjaHVuay5zdWJzdHJpbmcoc3RhcnRpLCBpLTEpXG4gICAgICAgIH1cbiAgICAgICAgaWYgKGMgPT09IFwiPFwiKSB7XG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5PUEVOX1dBS0FcbiAgICAgICAgICBwYXJzZXIuc3RhcnRUYWdQb3NpdGlvbiA9IHBhcnNlci5wb3NpdGlvblxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmIChub3Qod2hpdGVzcGFjZSwgYykgJiYgKCFwYXJzZXIuc2F3Um9vdCB8fCBwYXJzZXIuY2xvc2VkUm9vdCkpXG4gICAgICAgICAgICBzdHJpY3RGYWlsKHBhcnNlciwgXCJUZXh0IGRhdGEgb3V0c2lkZSBvZiByb290IG5vZGUuXCIpXG4gICAgICAgICAgaWYgKGMgPT09IFwiJlwiKSBwYXJzZXIuc3RhdGUgPSBTLlRFWFRfRU5USVRZXG4gICAgICAgICAgZWxzZSBwYXJzZXIudGV4dE5vZGUgKz0gY1xuICAgICAgICB9XG4gICAgICBjb250aW51ZVxuXG4gICAgICBjYXNlIFMuU0NSSVBUOlxuICAgICAgICAvLyBvbmx5IG5vbi1zdHJpY3RcbiAgICAgICAgaWYgKGMgPT09IFwiPFwiKSB7XG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5TQ1JJUFRfRU5ESU5HXG4gICAgICAgIH0gZWxzZSBwYXJzZXIuc2NyaXB0ICs9IGNcbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5TQ1JJUFRfRU5ESU5HOlxuICAgICAgICBpZiAoYyA9PT0gXCIvXCIpIHtcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNMT1NFX1RBR1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHBhcnNlci5zY3JpcHQgKz0gXCI8XCIgKyBjXG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5TQ1JJUFRcbiAgICAgICAgfVxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLk9QRU5fV0FLQTpcbiAgICAgICAgLy8gZWl0aGVyIGEgLywgPywgISwgb3IgdGV4dCBpcyBjb21pbmcgbmV4dC5cbiAgICAgICAgaWYgKGMgPT09IFwiIVwiKSB7XG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5TR01MX0RFQ0xcbiAgICAgICAgICBwYXJzZXIuc2dtbERlY2wgPSBcIlwiXG4gICAgICAgIH0gZWxzZSBpZiAoaXMod2hpdGVzcGFjZSwgYykpIHtcbiAgICAgICAgICAvLyB3YWl0IGZvciBpdC4uLlxuICAgICAgICB9IGVsc2UgaWYgKGlzKG5hbWVTdGFydCxjKSkge1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuT1BFTl9UQUdcbiAgICAgICAgICBwYXJzZXIudGFnTmFtZSA9IGNcbiAgICAgICAgfSBlbHNlIGlmIChjID09PSBcIi9cIikge1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ0xPU0VfVEFHXG4gICAgICAgICAgcGFyc2VyLnRhZ05hbWUgPSBcIlwiXG4gICAgICAgIH0gZWxzZSBpZiAoYyA9PT0gXCI/XCIpIHtcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlBST0NfSU5TVFxuICAgICAgICAgIHBhcnNlci5wcm9jSW5zdE5hbWUgPSBwYXJzZXIucHJvY0luc3RCb2R5ID0gXCJcIlxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCBcIlVuZW5jb2RlZCA8XCIpXG4gICAgICAgICAgLy8gaWYgdGhlcmUgd2FzIHNvbWUgd2hpdGVzcGFjZSwgdGhlbiBhZGQgdGhhdCBpbi5cbiAgICAgICAgICBpZiAocGFyc2VyLnN0YXJ0VGFnUG9zaXRpb24gKyAxIDwgcGFyc2VyLnBvc2l0aW9uKSB7XG4gICAgICAgICAgICB2YXIgcGFkID0gcGFyc2VyLnBvc2l0aW9uIC0gcGFyc2VyLnN0YXJ0VGFnUG9zaXRpb25cbiAgICAgICAgICAgIGMgPSBuZXcgQXJyYXkocGFkKS5qb2luKFwiIFwiKSArIGNcbiAgICAgICAgICB9XG4gICAgICAgICAgcGFyc2VyLnRleHROb2RlICs9IFwiPFwiICsgY1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuVEVYVFxuICAgICAgICB9XG4gICAgICBjb250aW51ZVxuXG4gICAgICBjYXNlIFMuU0dNTF9ERUNMOlxuICAgICAgICBpZiAoKHBhcnNlci5zZ21sRGVjbCtjKS50b1VwcGVyQ2FzZSgpID09PSBDREFUQSkge1xuICAgICAgICAgIGVtaXROb2RlKHBhcnNlciwgXCJvbm9wZW5jZGF0YVwiKVxuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ0RBVEFcbiAgICAgICAgICBwYXJzZXIuc2dtbERlY2wgPSBcIlwiXG4gICAgICAgICAgcGFyc2VyLmNkYXRhID0gXCJcIlxuICAgICAgICB9IGVsc2UgaWYgKHBhcnNlci5zZ21sRGVjbCtjID09PSBcIi0tXCIpIHtcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNPTU1FTlRcbiAgICAgICAgICBwYXJzZXIuY29tbWVudCA9IFwiXCJcbiAgICAgICAgICBwYXJzZXIuc2dtbERlY2wgPSBcIlwiXG4gICAgICAgIH0gZWxzZSBpZiAoKHBhcnNlci5zZ21sRGVjbCtjKS50b1VwcGVyQ2FzZSgpID09PSBET0NUWVBFKSB7XG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5ET0NUWVBFXG4gICAgICAgICAgaWYgKHBhcnNlci5kb2N0eXBlIHx8IHBhcnNlci5zYXdSb290KSBzdHJpY3RGYWlsKHBhcnNlcixcbiAgICAgICAgICAgIFwiSW5hcHByb3ByaWF0ZWx5IGxvY2F0ZWQgZG9jdHlwZSBkZWNsYXJhdGlvblwiKVxuICAgICAgICAgIHBhcnNlci5kb2N0eXBlID0gXCJcIlxuICAgICAgICAgIHBhcnNlci5zZ21sRGVjbCA9IFwiXCJcbiAgICAgICAgfSBlbHNlIGlmIChjID09PSBcIj5cIikge1xuICAgICAgICAgIGVtaXROb2RlKHBhcnNlciwgXCJvbnNnbWxkZWNsYXJhdGlvblwiLCBwYXJzZXIuc2dtbERlY2wpXG4gICAgICAgICAgcGFyc2VyLnNnbWxEZWNsID0gXCJcIlxuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuVEVYVFxuICAgICAgICB9IGVsc2UgaWYgKGlzKHF1b3RlLCBjKSkge1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0dNTF9ERUNMX1FVT1RFRFxuICAgICAgICAgIHBhcnNlci5zZ21sRGVjbCArPSBjXG4gICAgICAgIH0gZWxzZSBwYXJzZXIuc2dtbERlY2wgKz0gY1xuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLlNHTUxfREVDTF9RVU9URUQ6XG4gICAgICAgIGlmIChjID09PSBwYXJzZXIucSkge1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0dNTF9ERUNMXG4gICAgICAgICAgcGFyc2VyLnEgPSBcIlwiXG4gICAgICAgIH1cbiAgICAgICAgcGFyc2VyLnNnbWxEZWNsICs9IGNcbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5ET0NUWVBFOlxuICAgICAgICBpZiAoYyA9PT0gXCI+XCIpIHtcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlRFWFRcbiAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsIFwib25kb2N0eXBlXCIsIHBhcnNlci5kb2N0eXBlKVxuICAgICAgICAgIHBhcnNlci5kb2N0eXBlID0gdHJ1ZSAvLyBqdXN0IHJlbWVtYmVyIHRoYXQgd2Ugc2F3IGl0LlxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHBhcnNlci5kb2N0eXBlICs9IGNcbiAgICAgICAgICBpZiAoYyA9PT0gXCJbXCIpIHBhcnNlci5zdGF0ZSA9IFMuRE9DVFlQRV9EVERcbiAgICAgICAgICBlbHNlIGlmIChpcyhxdW90ZSwgYykpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuRE9DVFlQRV9RVU9URURcbiAgICAgICAgICAgIHBhcnNlci5xID0gY1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLkRPQ1RZUEVfUVVPVEVEOlxuICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgIGlmIChjID09PSBwYXJzZXIucSkge1xuICAgICAgICAgIHBhcnNlci5xID0gXCJcIlxuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuRE9DVFlQRVxuICAgICAgICB9XG4gICAgICBjb250aW51ZVxuXG4gICAgICBjYXNlIFMuRE9DVFlQRV9EVEQ6XG4gICAgICAgIHBhcnNlci5kb2N0eXBlICs9IGNcbiAgICAgICAgaWYgKGMgPT09IFwiXVwiKSBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVcbiAgICAgICAgZWxzZSBpZiAoaXMocXVvdGUsYykpIHtcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVfRFREX1FVT1RFRFxuICAgICAgICAgIHBhcnNlci5xID0gY1xuICAgICAgICB9XG4gICAgICBjb250aW51ZVxuXG4gICAgICBjYXNlIFMuRE9DVFlQRV9EVERfUVVPVEVEOlxuICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgIGlmIChjID09PSBwYXJzZXIucSkge1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuRE9DVFlQRV9EVERcbiAgICAgICAgICBwYXJzZXIucSA9IFwiXCJcbiAgICAgICAgfVxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLkNPTU1FTlQ6XG4gICAgICAgIGlmIChjID09PSBcIi1cIikgcGFyc2VyLnN0YXRlID0gUy5DT01NRU5UX0VORElOR1xuICAgICAgICBlbHNlIHBhcnNlci5jb21tZW50ICs9IGNcbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5DT01NRU5UX0VORElORzpcbiAgICAgICAgaWYgKGMgPT09IFwiLVwiKSB7XG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DT01NRU5UX0VOREVEXG4gICAgICAgICAgcGFyc2VyLmNvbW1lbnQgPSB0ZXh0b3B0cyhwYXJzZXIub3B0LCBwYXJzZXIuY29tbWVudClcbiAgICAgICAgICBpZiAocGFyc2VyLmNvbW1lbnQpIGVtaXROb2RlKHBhcnNlciwgXCJvbmNvbW1lbnRcIiwgcGFyc2VyLmNvbW1lbnQpXG4gICAgICAgICAgcGFyc2VyLmNvbW1lbnQgPSBcIlwiXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgcGFyc2VyLmNvbW1lbnQgKz0gXCItXCIgKyBjXG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DT01NRU5UXG4gICAgICAgIH1cbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5DT01NRU5UX0VOREVEOlxuICAgICAgICBpZiAoYyAhPT0gXCI+XCIpIHtcbiAgICAgICAgICBzdHJpY3RGYWlsKHBhcnNlciwgXCJNYWxmb3JtZWQgY29tbWVudFwiKVxuICAgICAgICAgIC8vIGFsbG93IDwhLS0gYmxhaCAtLSBibG9vIC0tPiBpbiBub24tc3RyaWN0IG1vZGUsXG4gICAgICAgICAgLy8gd2hpY2ggaXMgYSBjb21tZW50IG9mIFwiIGJsYWggLS0gYmxvbyBcIlxuICAgICAgICAgIHBhcnNlci5jb21tZW50ICs9IFwiLS1cIiArIGNcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNPTU1FTlRcbiAgICAgICAgfSBlbHNlIHBhcnNlci5zdGF0ZSA9IFMuVEVYVFxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLkNEQVRBOlxuICAgICAgICBpZiAoYyA9PT0gXCJdXCIpIHBhcnNlci5zdGF0ZSA9IFMuQ0RBVEFfRU5ESU5HXG4gICAgICAgIGVsc2UgcGFyc2VyLmNkYXRhICs9IGNcbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5DREFUQV9FTkRJTkc6XG4gICAgICAgIGlmIChjID09PSBcIl1cIikgcGFyc2VyLnN0YXRlID0gUy5DREFUQV9FTkRJTkdfMlxuICAgICAgICBlbHNlIHtcbiAgICAgICAgICBwYXJzZXIuY2RhdGEgKz0gXCJdXCIgKyBjXG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DREFUQVxuICAgICAgICB9XG4gICAgICBjb250aW51ZVxuXG4gICAgICBjYXNlIFMuQ0RBVEFfRU5ESU5HXzI6XG4gICAgICAgIGlmIChjID09PSBcIj5cIikge1xuICAgICAgICAgIGlmIChwYXJzZXIuY2RhdGEpIGVtaXROb2RlKHBhcnNlciwgXCJvbmNkYXRhXCIsIHBhcnNlci5jZGF0YSlcbiAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsIFwib25jbG9zZWNkYXRhXCIpXG4gICAgICAgICAgcGFyc2VyLmNkYXRhID0gXCJcIlxuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuVEVYVFxuICAgICAgICB9IGVsc2UgaWYgKGMgPT09IFwiXVwiKSB7XG4gICAgICAgICAgcGFyc2VyLmNkYXRhICs9IFwiXVwiXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgcGFyc2VyLmNkYXRhICs9IFwiXV1cIiArIGNcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNEQVRBXG4gICAgICAgIH1cbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5QUk9DX0lOU1Q6XG4gICAgICAgIGlmIChjID09PSBcIj9cIikgcGFyc2VyLnN0YXRlID0gUy5QUk9DX0lOU1RfRU5ESU5HXG4gICAgICAgIGVsc2UgaWYgKGlzKHdoaXRlc3BhY2UsIGMpKSBwYXJzZXIuc3RhdGUgPSBTLlBST0NfSU5TVF9CT0RZXG4gICAgICAgIGVsc2UgcGFyc2VyLnByb2NJbnN0TmFtZSArPSBjXG4gICAgICBjb250aW51ZVxuXG4gICAgICBjYXNlIFMuUFJPQ19JTlNUX0JPRFk6XG4gICAgICAgIGlmICghcGFyc2VyLnByb2NJbnN0Qm9keSAmJiBpcyh3aGl0ZXNwYWNlLCBjKSkgY29udGludWVcbiAgICAgICAgZWxzZSBpZiAoYyA9PT0gXCI/XCIpIHBhcnNlci5zdGF0ZSA9IFMuUFJPQ19JTlNUX0VORElOR1xuICAgICAgICBlbHNlIHBhcnNlci5wcm9jSW5zdEJvZHkgKz0gY1xuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLlBST0NfSU5TVF9FTkRJTkc6XG4gICAgICAgIGlmIChjID09PSBcIj5cIikge1xuICAgICAgICAgIGVtaXROb2RlKHBhcnNlciwgXCJvbnByb2Nlc3NpbmdpbnN0cnVjdGlvblwiLCB7XG4gICAgICAgICAgICBuYW1lIDogcGFyc2VyLnByb2NJbnN0TmFtZSxcbiAgICAgICAgICAgIGJvZHkgOiBwYXJzZXIucHJvY0luc3RCb2R5XG4gICAgICAgICAgfSlcbiAgICAgICAgICBwYXJzZXIucHJvY0luc3ROYW1lID0gcGFyc2VyLnByb2NJbnN0Qm9keSA9IFwiXCJcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlRFWFRcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBwYXJzZXIucHJvY0luc3RCb2R5ICs9IFwiP1wiICsgY1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuUFJPQ19JTlNUX0JPRFlcbiAgICAgICAgfVxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLk9QRU5fVEFHOlxuICAgICAgICBpZiAoaXMobmFtZUJvZHksIGMpKSBwYXJzZXIudGFnTmFtZSArPSBjXG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgIG5ld1RhZyhwYXJzZXIpXG4gICAgICAgICAgaWYgKGMgPT09IFwiPlwiKSBvcGVuVGFnKHBhcnNlcilcbiAgICAgICAgICBlbHNlIGlmIChjID09PSBcIi9cIikgcGFyc2VyLnN0YXRlID0gUy5PUEVOX1RBR19TTEFTSFxuICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgaWYgKG5vdCh3aGl0ZXNwYWNlLCBjKSkgc3RyaWN0RmFpbChcbiAgICAgICAgICAgICAgcGFyc2VyLCBcIkludmFsaWQgY2hhcmFjdGVyIGluIHRhZyBuYW1lXCIpXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQlxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLk9QRU5fVEFHX1NMQVNIOlxuICAgICAgICBpZiAoYyA9PT0gXCI+XCIpIHtcbiAgICAgICAgICBvcGVuVGFnKHBhcnNlciwgdHJ1ZSlcbiAgICAgICAgICBjbG9zZVRhZyhwYXJzZXIpXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsIFwiRm9yd2FyZC1zbGFzaCBpbiBvcGVuaW5nIHRhZyBub3QgZm9sbG93ZWQgYnkgPlwiKVxuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCXG4gICAgICAgIH1cbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5BVFRSSUI6XG4gICAgICAgIC8vIGhhdmVuJ3QgcmVhZCB0aGUgYXR0cmlidXRlIG5hbWUgeWV0LlxuICAgICAgICBpZiAoaXMod2hpdGVzcGFjZSwgYykpIGNvbnRpbnVlXG4gICAgICAgIGVsc2UgaWYgKGMgPT09IFwiPlwiKSBvcGVuVGFnKHBhcnNlcilcbiAgICAgICAgZWxzZSBpZiAoYyA9PT0gXCIvXCIpIHBhcnNlci5zdGF0ZSA9IFMuT1BFTl9UQUdfU0xBU0hcbiAgICAgICAgZWxzZSBpZiAoaXMobmFtZVN0YXJ0LCBjKSkge1xuICAgICAgICAgIHBhcnNlci5hdHRyaWJOYW1lID0gY1xuICAgICAgICAgIHBhcnNlci5hdHRyaWJWYWx1ZSA9IFwiXCJcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9OQU1FXG4gICAgICAgIH0gZWxzZSBzdHJpY3RGYWlsKHBhcnNlciwgXCJJbnZhbGlkIGF0dHJpYnV0ZSBuYW1lXCIpXG4gICAgICBjb250aW51ZVxuXG4gICAgICBjYXNlIFMuQVRUUklCX05BTUU6XG4gICAgICAgIGlmIChjID09PSBcIj1cIikgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJfVkFMVUVcbiAgICAgICAgZWxzZSBpZiAoYyA9PT0gXCI+XCIpIHtcbiAgICAgICAgICBzdHJpY3RGYWlsKHBhcnNlciwgXCJBdHRyaWJ1dGUgd2l0aG91dCB2YWx1ZVwiKVxuICAgICAgICAgIHBhcnNlci5hdHRyaWJWYWx1ZSA9IHBhcnNlci5hdHRyaWJOYW1lXG4gICAgICAgICAgYXR0cmliKHBhcnNlcilcbiAgICAgICAgICBvcGVuVGFnKHBhcnNlcilcbiAgICAgICAgfVxuICAgICAgICBlbHNlIGlmIChpcyh3aGl0ZXNwYWNlLCBjKSkgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJfTkFNRV9TQVdfV0hJVEVcbiAgICAgICAgZWxzZSBpZiAoaXMobmFtZUJvZHksIGMpKSBwYXJzZXIuYXR0cmliTmFtZSArPSBjXG4gICAgICAgIGVsc2Ugc3RyaWN0RmFpbChwYXJzZXIsIFwiSW52YWxpZCBhdHRyaWJ1dGUgbmFtZVwiKVxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLkFUVFJJQl9OQU1FX1NBV19XSElURTpcbiAgICAgICAgaWYgKGMgPT09IFwiPVwiKSBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9WQUxVRVxuICAgICAgICBlbHNlIGlmIChpcyh3aGl0ZXNwYWNlLCBjKSkgY29udGludWVcbiAgICAgICAgZWxzZSB7XG4gICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsIFwiQXR0cmlidXRlIHdpdGhvdXQgdmFsdWVcIilcbiAgICAgICAgICBwYXJzZXIudGFnLmF0dHJpYnV0ZXNbcGFyc2VyLmF0dHJpYk5hbWVdID0gXCJcIlxuICAgICAgICAgIHBhcnNlci5hdHRyaWJWYWx1ZSA9IFwiXCJcbiAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsIFwib25hdHRyaWJ1dGVcIixcbiAgICAgICAgICAgICAgICAgICB7IG5hbWUgOiBwYXJzZXIuYXR0cmliTmFtZSwgdmFsdWUgOiBcIlwiIH0pXG4gICAgICAgICAgcGFyc2VyLmF0dHJpYk5hbWUgPSBcIlwiXG4gICAgICAgICAgaWYgKGMgPT09IFwiPlwiKSBvcGVuVGFnKHBhcnNlcilcbiAgICAgICAgICBlbHNlIGlmIChpcyhuYW1lU3RhcnQsIGMpKSB7XG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliTmFtZSA9IGNcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX05BTUVcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsIFwiSW52YWxpZCBhdHRyaWJ1dGUgbmFtZVwiKVxuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5BVFRSSUJfVkFMVUU6XG4gICAgICAgIGlmIChpcyh3aGl0ZXNwYWNlLCBjKSkgY29udGludWVcbiAgICAgICAgZWxzZSBpZiAoaXMocXVvdGUsIGMpKSB7XG4gICAgICAgICAgcGFyc2VyLnEgPSBjXG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJfVkFMVUVfUVVPVEVEXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsIFwiVW5xdW90ZWQgYXR0cmlidXRlIHZhbHVlXCIpXG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJfVkFMVUVfVU5RVU9URURcbiAgICAgICAgICBwYXJzZXIuYXR0cmliVmFsdWUgPSBjXG4gICAgICAgIH1cbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5BVFRSSUJfVkFMVUVfUVVPVEVEOlxuICAgICAgICBpZiAoYyAhPT0gcGFyc2VyLnEpIHtcbiAgICAgICAgICBpZiAoYyA9PT0gXCImXCIpIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX0VOVElUWV9RXG4gICAgICAgICAgZWxzZSBwYXJzZXIuYXR0cmliVmFsdWUgKz0gY1xuICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgIH1cbiAgICAgICAgYXR0cmliKHBhcnNlcilcbiAgICAgICAgcGFyc2VyLnEgPSBcIlwiXG4gICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX0NMT1NFRFxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9DTE9TRUQ6XG4gICAgICAgIGlmIChpcyh3aGl0ZXNwYWNlLCBjKSkge1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCXG4gICAgICAgIH0gZWxzZSBpZiAoYyA9PT0gXCI+XCIpIG9wZW5UYWcocGFyc2VyKVxuICAgICAgICBlbHNlIGlmIChjID09PSBcIi9cIikgcGFyc2VyLnN0YXRlID0gUy5PUEVOX1RBR19TTEFTSFxuICAgICAgICBlbHNlIGlmIChpcyhuYW1lU3RhcnQsIGMpKSB7XG4gICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsIFwiTm8gd2hpdGVzcGFjZSBiZXR3ZWVuIGF0dHJpYnV0ZXNcIilcbiAgICAgICAgICBwYXJzZXIuYXR0cmliTmFtZSA9IGNcbiAgICAgICAgICBwYXJzZXIuYXR0cmliVmFsdWUgPSBcIlwiXG4gICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJfTkFNRVxuICAgICAgICB9IGVsc2Ugc3RyaWN0RmFpbChwYXJzZXIsIFwiSW52YWxpZCBhdHRyaWJ1dGUgbmFtZVwiKVxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9VTlFVT1RFRDpcbiAgICAgICAgaWYgKG5vdChhdHRyaWJFbmQsYykpIHtcbiAgICAgICAgICBpZiAoYyA9PT0gXCImXCIpIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX0VOVElUWV9VXG4gICAgICAgICAgZWxzZSBwYXJzZXIuYXR0cmliVmFsdWUgKz0gY1xuICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgIH1cbiAgICAgICAgYXR0cmliKHBhcnNlcilcbiAgICAgICAgaWYgKGMgPT09IFwiPlwiKSBvcGVuVGFnKHBhcnNlcilcbiAgICAgICAgZWxzZSBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQlxuICAgICAgY29udGludWVcblxuICAgICAgY2FzZSBTLkNMT1NFX1RBRzpcbiAgICAgICAgaWYgKCFwYXJzZXIudGFnTmFtZSkge1xuICAgICAgICAgIGlmIChpcyh3aGl0ZXNwYWNlLCBjKSkgY29udGludWVcbiAgICAgICAgICBlbHNlIGlmIChub3QobmFtZVN0YXJ0LCBjKSkge1xuICAgICAgICAgICAgaWYgKHBhcnNlci5zY3JpcHQpIHtcbiAgICAgICAgICAgICAgcGFyc2VyLnNjcmlwdCArPSBcIjwvXCIgKyBjXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0NSSVBUXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBzdHJpY3RGYWlsKHBhcnNlciwgXCJJbnZhbGlkIHRhZ25hbWUgaW4gY2xvc2luZyB0YWcuXCIpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIHBhcnNlci50YWdOYW1lID0gY1xuICAgICAgICB9XG4gICAgICAgIGVsc2UgaWYgKGMgPT09IFwiPlwiKSBjbG9zZVRhZyhwYXJzZXIpXG4gICAgICAgIGVsc2UgaWYgKGlzKG5hbWVCb2R5LCBjKSkgcGFyc2VyLnRhZ05hbWUgKz0gY1xuICAgICAgICBlbHNlIGlmIChwYXJzZXIuc2NyaXB0KSB7XG4gICAgICAgICAgcGFyc2VyLnNjcmlwdCArPSBcIjwvXCIgKyBwYXJzZXIudGFnTmFtZVxuICAgICAgICAgIHBhcnNlci50YWdOYW1lID0gXCJcIlxuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0NSSVBUXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKG5vdCh3aGl0ZXNwYWNlLCBjKSkgc3RyaWN0RmFpbChwYXJzZXIsXG4gICAgICAgICAgICBcIkludmFsaWQgdGFnbmFtZSBpbiBjbG9zaW5nIHRhZ1wiKVxuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ0xPU0VfVEFHX1NBV19XSElURVxuICAgICAgICB9XG4gICAgICBjb250aW51ZVxuXG4gICAgICBjYXNlIFMuQ0xPU0VfVEFHX1NBV19XSElURTpcbiAgICAgICAgaWYgKGlzKHdoaXRlc3BhY2UsIGMpKSBjb250aW51ZVxuICAgICAgICBpZiAoYyA9PT0gXCI+XCIpIGNsb3NlVGFnKHBhcnNlcilcbiAgICAgICAgZWxzZSBzdHJpY3RGYWlsKHBhcnNlciwgXCJJbnZhbGlkIGNoYXJhY3RlcnMgaW4gY2xvc2luZyB0YWdcIilcbiAgICAgIGNvbnRpbnVlXG5cbiAgICAgIGNhc2UgUy5URVhUX0VOVElUWTpcbiAgICAgIGNhc2UgUy5BVFRSSUJfVkFMVUVfRU5USVRZX1E6XG4gICAgICBjYXNlIFMuQVRUUklCX1ZBTFVFX0VOVElUWV9VOlxuICAgICAgICBzd2l0Y2gocGFyc2VyLnN0YXRlKSB7XG4gICAgICAgICAgY2FzZSBTLlRFWFRfRU5USVRZOlxuICAgICAgICAgICAgdmFyIHJldHVyblN0YXRlID0gUy5URVhULCBidWZmZXIgPSBcInRleHROb2RlXCJcbiAgICAgICAgICBicmVha1xuXG4gICAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9FTlRJVFlfUTpcbiAgICAgICAgICAgIHZhciByZXR1cm5TdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX1FVT1RFRCwgYnVmZmVyID0gXCJhdHRyaWJWYWx1ZVwiXG4gICAgICAgICAgYnJlYWtcblxuICAgICAgICAgIGNhc2UgUy5BVFRSSUJfVkFMVUVfRU5USVRZX1U6XG4gICAgICAgICAgICB2YXIgcmV0dXJuU3RhdGUgPSBTLkFUVFJJQl9WQUxVRV9VTlFVT1RFRCwgYnVmZmVyID0gXCJhdHRyaWJWYWx1ZVwiXG4gICAgICAgICAgYnJlYWtcbiAgICAgICAgfVxuICAgICAgICBpZiAoYyA9PT0gXCI7XCIpIHtcbiAgICAgICAgICBwYXJzZXJbYnVmZmVyXSArPSBwYXJzZUVudGl0eShwYXJzZXIpXG4gICAgICAgICAgcGFyc2VyLmVudGl0eSA9IFwiXCJcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSByZXR1cm5TdGF0ZVxuICAgICAgICB9XG4gICAgICAgIGVsc2UgaWYgKGlzKGVudGl0eSwgYykpIHBhcnNlci5lbnRpdHkgKz0gY1xuICAgICAgICBlbHNlIHtcbiAgICAgICAgICBzdHJpY3RGYWlsKHBhcnNlciwgXCJJbnZhbGlkIGNoYXJhY3RlciBlbnRpdHlcIilcbiAgICAgICAgICBwYXJzZXJbYnVmZmVyXSArPSBcIiZcIiArIHBhcnNlci5lbnRpdHkgKyBjXG4gICAgICAgICAgcGFyc2VyLmVudGl0eSA9IFwiXCJcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSByZXR1cm5TdGF0ZVxuICAgICAgICB9XG4gICAgICBjb250aW51ZVxuXG4gICAgICBkZWZhdWx0OlxuICAgICAgICB0aHJvdyBuZXcgRXJyb3IocGFyc2VyLCBcIlVua25vd24gc3RhdGU6IFwiICsgcGFyc2VyLnN0YXRlKVxuICAgIH1cbiAgfSAvLyB3aGlsZVxuICAvLyBjZGF0YSBibG9ja3MgY2FuIGdldCB2ZXJ5IGJpZyB1bmRlciBub3JtYWwgY29uZGl0aW9ucy4gZW1pdCBhbmQgbW92ZSBvbi5cbiAgLy8gaWYgKHBhcnNlci5zdGF0ZSA9PT0gUy5DREFUQSAmJiBwYXJzZXIuY2RhdGEpIHtcbiAgLy8gICBlbWl0Tm9kZShwYXJzZXIsIFwib25jZGF0YVwiLCBwYXJzZXIuY2RhdGEpXG4gIC8vICAgcGFyc2VyLmNkYXRhID0gXCJcIlxuICAvLyB9XG4gIGlmIChwYXJzZXIucG9zaXRpb24gPj0gcGFyc2VyLmJ1ZmZlckNoZWNrUG9zaXRpb24pIGNoZWNrQnVmZmVyTGVuZ3RoKHBhcnNlcilcbiAgcmV0dXJuIHBhcnNlclxufVxuXG4vKiEgaHR0cDovL210aHMuYmUvZnJvbWNvZGVwb2ludCB2MC4xLjAgYnkgQG1hdGhpYXMgKi9cbmlmICghU3RyaW5nLmZyb21Db2RlUG9pbnQpIHtcbiAgICAgICAgKGZ1bmN0aW9uKCkge1xuICAgICAgICAgICAgICAgIHZhciBzdHJpbmdGcm9tQ2hhckNvZGUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlO1xuICAgICAgICAgICAgICAgIHZhciBmbG9vciA9IE1hdGguZmxvb3I7XG4gICAgICAgICAgICAgICAgdmFyIGZyb21Db2RlUG9pbnQgPSBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBNQVhfU0laRSA9IDB4NDAwMDtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBjb2RlVW5pdHMgPSBbXTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBoaWdoU3Vycm9nYXRlO1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGxvd1N1cnJvZ2F0ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBpbmRleCA9IC0xO1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGxlbmd0aCA9IGFyZ3VtZW50cy5sZW5ndGg7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWxlbmd0aCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gJyc7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgcmVzdWx0ID0gJyc7XG4gICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoKytpbmRleCA8IGxlbmd0aCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgY29kZVBvaW50ID0gTnVtYmVyKGFyZ3VtZW50c1tpbmRleF0pO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIWlzRmluaXRlKGNvZGVQb2ludCkgfHwgLy8gYE5hTmAsIGArSW5maW5pdHlgLCBvciBgLUluZmluaXR5YFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA8IDAgfHwgLy8gbm90IGEgdmFsaWQgVW5pY29kZSBjb2RlIHBvaW50XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID4gMHgxMEZGRkYgfHwgLy8gbm90IGEgdmFsaWQgVW5pY29kZSBjb2RlIHBvaW50XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmxvb3IoY29kZVBvaW50KSAhPSBjb2RlUG9pbnQgLy8gbm90IGFuIGludGVnZXJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcignSW52YWxpZCBjb2RlIHBvaW50OiAnICsgY29kZVBvaW50KTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoY29kZVBvaW50IDw9IDB4RkZGRikgeyAvLyBCTVAgY29kZSBwb2ludFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvZGVVbml0cy5wdXNoKGNvZGVQb2ludCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7IC8vIEFzdHJhbCBjb2RlIHBvaW50OyBzcGxpdCBpbiBzdXJyb2dhdGUgaGFsdmVzXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gaHR0cDovL21hdGhpYXNieW5lbnMuYmUvbm90ZXMvamF2YXNjcmlwdC1lbmNvZGluZyNzdXJyb2dhdGUtZm9ybXVsYWVcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgLT0gMHgxMDAwMDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBoaWdoU3Vycm9nYXRlID0gKGNvZGVQb2ludCA+PiAxMCkgKyAweEQ4MDA7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbG93U3Vycm9nYXRlID0gKGNvZGVQb2ludCAlIDB4NDAwKSArIDB4REMwMDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb2RlVW5pdHMucHVzaChoaWdoU3Vycm9nYXRlLCBsb3dTdXJyb2dhdGUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbmRleCArIDEgPT0gbGVuZ3RoIHx8IGNvZGVVbml0cy5sZW5ndGggPiBNQVhfU0laRSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCArPSBzdHJpbmdGcm9tQ2hhckNvZGUuYXBwbHkobnVsbCwgY29kZVVuaXRzKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb2RlVW5pdHMubGVuZ3RoID0gMDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgIGlmIChPYmplY3QuZGVmaW5lUHJvcGVydHkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShTdHJpbmcsICdmcm9tQ29kZVBvaW50Jywge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAndmFsdWUnOiBmcm9tQ29kZVBvaW50LFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnY29uZmlndXJhYmxlJzogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3dyaXRhYmxlJzogdHJ1ZVxuICAgICAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIFN0cmluZy5mcm9tQ29kZVBvaW50ID0gZnJvbUNvZGVQb2ludDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgIH0oKSk7XG59XG5cbn0pKHR5cGVvZiBleHBvcnRzID09PSBcInVuZGVmaW5lZFwiID8gc2F4ID0ge30gOiBleHBvcnRzKTtcbiJdfQ==
  8441. },{"undefined":undefined}],59:[function(_dereq_,module,exports){
  8442. /**
  8443. * Tiny stack for browser or server
  8444. *
  8445. * @author Jason Mulligan <jason.mulligan@avoidwork.com>
  8446. * @copyright 2014 Jason Mulligan
  8447. * @license BSD-3 <https://raw.github.com/avoidwork/tiny-stack/master/LICENSE>
  8448. * @link http://avoidwork.github.io/tiny-stack
  8449. * @module tiny-stack
  8450. * @version 0.1.0
  8451. */
  8452. ( function ( global ) {
  8453. "use strict";
  8454. /**
  8455. * TinyStack
  8456. *
  8457. * @constructor
  8458. */
  8459. function TinyStack () {
  8460. this.data = [null];
  8461. this.top = 0;
  8462. }
  8463. /**
  8464. * Clears the stack
  8465. *
  8466. * @method clear
  8467. * @memberOf TinyStack
  8468. * @return {Object} {@link TinyStack}
  8469. */
  8470. TinyStack.prototype.clear = function clear () {
  8471. this.data = [null];
  8472. this.top = 0;
  8473. return this;
  8474. };
  8475. /**
  8476. * Gets the size of the stack
  8477. *
  8478. * @method length
  8479. * @memberOf TinyStack
  8480. * @return {Number} Size of stack
  8481. */
  8482. TinyStack.prototype.length = function length () {
  8483. return this.top;
  8484. };
  8485. /**
  8486. * Gets the item at the top of the stack
  8487. *
  8488. * @method peek
  8489. * @memberOf TinyStack
  8490. * @return {Mixed} Item at the top of the stack
  8491. */
  8492. TinyStack.prototype.peek = function peek () {
  8493. return this.data[this.top];
  8494. };
  8495. /**
  8496. * Gets & removes the item at the top of the stack
  8497. *
  8498. * @method pop
  8499. * @memberOf TinyStack
  8500. * @return {Mixed} Item at the top of the stack
  8501. */
  8502. TinyStack.prototype.pop = function pop () {
  8503. if ( this.top > 0 ) {
  8504. this.top--;
  8505. return this.data.pop();
  8506. }
  8507. else {
  8508. return undefined;
  8509. }
  8510. };
  8511. /**
  8512. * Pushes an item onto the stack
  8513. *
  8514. * @method push
  8515. * @memberOf TinyStack
  8516. * @return {Object} {@link TinyStack}
  8517. */
  8518. TinyStack.prototype.push = function push ( arg ) {
  8519. this.data[++this.top] = arg;
  8520. return this;
  8521. };
  8522. /**
  8523. * TinyStack factory
  8524. *
  8525. * @method factory
  8526. * @return {Object} {@link TinyStack}
  8527. */
  8528. function factory () {
  8529. return new TinyStack();
  8530. }
  8531. // Node, AMD & window supported
  8532. if ( typeof exports != "undefined" ) {
  8533. module.exports = factory;
  8534. }
  8535. else if ( typeof define == "function" ) {
  8536. define( function () {
  8537. return factory;
  8538. } );
  8539. }
  8540. else {
  8541. global.stack = factory;
  8542. }
  8543. } )( this );
  8544. },{}],60:[function(_dereq_,module,exports){
  8545. module.exports = _dereq_(64);
  8546. },{"64":64}],61:[function(_dereq_,module,exports){
  8547. 'use strict';
  8548. function Base() { }
  8549. Base.prototype.get = function(name) {
  8550. return this.$model.properties.get(this, name);
  8551. };
  8552. Base.prototype.set = function(name, value) {
  8553. this.$model.properties.set(this, name, value);
  8554. };
  8555. module.exports = Base;
  8556. },{}],62:[function(_dereq_,module,exports){
  8557. 'use strict';
  8558. var pick = _dereq_(345),
  8559. assign = _dereq_(339),
  8560. forEach = _dereq_(218);
  8561. var parseNameNs = _dereq_(65).parseName;
  8562. function DescriptorBuilder(nameNs) {
  8563. this.ns = nameNs;
  8564. this.name = nameNs.name;
  8565. this.allTypes = [];
  8566. this.properties = [];
  8567. this.propertiesByName = {};
  8568. }
  8569. module.exports = DescriptorBuilder;
  8570. DescriptorBuilder.prototype.build = function() {
  8571. return pick(this, [ 'ns', 'name', 'allTypes', 'properties', 'propertiesByName', 'bodyProperty' ]);
  8572. };
  8573. DescriptorBuilder.prototype.addProperty = function(p, idx) {
  8574. this.addNamedProperty(p, true);
  8575. var properties = this.properties;
  8576. if (idx !== undefined) {
  8577. properties.splice(idx, 0, p);
  8578. } else {
  8579. properties.push(p);
  8580. }
  8581. };
  8582. DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty) {
  8583. var oldNameNs = oldProperty.ns;
  8584. var props = this.properties,
  8585. propertiesByName = this.propertiesByName,
  8586. rename = oldProperty.name !== newProperty.name;
  8587. if (oldProperty.isBody) {
  8588. if (!newProperty.isBody) {
  8589. throw new Error(
  8590. 'property <' + newProperty.ns.name + '> must be body property ' +
  8591. 'to refine <' + oldProperty.ns.name + '>');
  8592. }
  8593. // TODO: Check compatibility
  8594. this.setBodyProperty(newProperty, false);
  8595. }
  8596. // replacing the named property is intentional
  8597. // thus, validate only if this is a "rename" operation
  8598. this.addNamedProperty(newProperty, rename);
  8599. // replace old property at index with new one
  8600. var idx = props.indexOf(oldProperty);
  8601. if (idx === -1) {
  8602. throw new Error('property <' + oldNameNs.name + '> not found in property list');
  8603. }
  8604. props[idx] = newProperty;
  8605. // replace propertiesByName entry with new property
  8606. propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
  8607. };
  8608. DescriptorBuilder.prototype.redefineProperty = function(p) {
  8609. var nsPrefix = p.ns.prefix;
  8610. var parts = p.redefines.split('#');
  8611. var name = parseNameNs(parts[0], nsPrefix);
  8612. var attrName = parseNameNs(parts[1], name.prefix).name;
  8613. var redefinedProperty = this.propertiesByName[attrName];
  8614. if (!redefinedProperty) {
  8615. throw new Error('refined property <' + attrName + '> not found');
  8616. } else {
  8617. this.replaceProperty(redefinedProperty, p);
  8618. }
  8619. delete p.redefines;
  8620. };
  8621. DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
  8622. var ns = p.ns,
  8623. propsByName = this.propertiesByName;
  8624. if (validate) {
  8625. this.assertNotDefined(p, ns.name);
  8626. this.assertNotDefined(p, ns.localName);
  8627. }
  8628. propsByName[ns.name] = propsByName[ns.localName] = p;
  8629. };
  8630. DescriptorBuilder.prototype.removeNamedProperty = function(p) {
  8631. var ns = p.ns,
  8632. propsByName = this.propertiesByName;
  8633. delete propsByName[ns.name];
  8634. delete propsByName[ns.localName];
  8635. };
  8636. DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
  8637. if (validate && this.bodyProperty) {
  8638. throw new Error(
  8639. 'body property defined multiple times ' +
  8640. '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
  8641. }
  8642. this.bodyProperty = p;
  8643. };
  8644. DescriptorBuilder.prototype.addIdProperty = function(name) {
  8645. var nameNs = parseNameNs(name, this.ns.prefix);
  8646. var p = {
  8647. name: nameNs.localName,
  8648. type: 'String',
  8649. isAttr: true,
  8650. ns: nameNs
  8651. };
  8652. // ensure that id is always the first attribute (if present)
  8653. this.addProperty(p, 0);
  8654. };
  8655. DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
  8656. var propertyName = p.name,
  8657. definedProperty = this.propertiesByName[propertyName];
  8658. if (definedProperty) {
  8659. throw new Error(
  8660. 'property <' + propertyName + '> already defined; ' +
  8661. 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
  8662. '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
  8663. }
  8664. };
  8665. DescriptorBuilder.prototype.hasProperty = function(name) {
  8666. return this.propertiesByName[name];
  8667. };
  8668. DescriptorBuilder.prototype.addTrait = function(t) {
  8669. var allTypes = this.allTypes;
  8670. if (allTypes.indexOf(t) !== -1) {
  8671. return;
  8672. }
  8673. forEach(t.properties, function(p) {
  8674. // clone property to allow extensions
  8675. p = assign({}, p, {
  8676. name: p.ns.localName
  8677. });
  8678. Object.defineProperty(p, 'definedBy', {
  8679. value: t
  8680. });
  8681. // add redefine support
  8682. if (p.redefines) {
  8683. this.redefineProperty(p);
  8684. } else {
  8685. if (p.isBody) {
  8686. this.setBodyProperty(p);
  8687. }
  8688. this.addProperty(p);
  8689. }
  8690. }, this);
  8691. allTypes.push(t);
  8692. };
  8693. },{"218":218,"339":339,"345":345,"65":65}],63:[function(_dereq_,module,exports){
  8694. 'use strict';
  8695. var forEach = _dereq_(218);
  8696. var Base = _dereq_(61);
  8697. function Factory(model, properties) {
  8698. this.model = model;
  8699. this.properties = properties;
  8700. }
  8701. module.exports = Factory;
  8702. Factory.prototype.createType = function(descriptor) {
  8703. var model = this.model;
  8704. var props = this.properties,
  8705. prototype = Object.create(Base.prototype);
  8706. // initialize default values
  8707. forEach(descriptor.properties, function(p) {
  8708. if (!p.isMany && p.default !== undefined) {
  8709. prototype[p.name] = p.default;
  8710. }
  8711. });
  8712. props.defineModel(prototype, model);
  8713. props.defineDescriptor(prototype, descriptor);
  8714. var name = descriptor.ns.name;
  8715. /**
  8716. * The new type constructor
  8717. */
  8718. function ModdleElement(attrs) {
  8719. props.define(this, '$type', { value: name, enumerable: true });
  8720. props.define(this, '$attrs', { value: {} });
  8721. props.define(this, '$parent', { writable: true });
  8722. forEach(attrs, function(val, key) {
  8723. this.set(key, val);
  8724. }, this);
  8725. }
  8726. ModdleElement.prototype = prototype;
  8727. ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
  8728. // static links
  8729. props.defineModel(ModdleElement, model);
  8730. props.defineDescriptor(ModdleElement, descriptor);
  8731. return ModdleElement;
  8732. };
  8733. },{"218":218,"61":61}],64:[function(_dereq_,module,exports){
  8734. 'use strict';
  8735. var isString = _dereq_(336),
  8736. isObject = _dereq_(334),
  8737. forEach = _dereq_(218),
  8738. find = _dereq_(217);
  8739. var Factory = _dereq_(63),
  8740. Registry = _dereq_(67),
  8741. Properties = _dereq_(66);
  8742. var parseNameNs = _dereq_(65).parseName;
  8743. //// Moddle implementation /////////////////////////////////////////////////
  8744. /**
  8745. * @class Moddle
  8746. *
  8747. * A model that can be used to create elements of a specific type.
  8748. *
  8749. * @example
  8750. *
  8751. * var Moddle = require('moddle');
  8752. *
  8753. * var pkg = {
  8754. * name: 'mypackage',
  8755. * prefix: 'my',
  8756. * types: [
  8757. * { name: 'Root' }
  8758. * ]
  8759. * };
  8760. *
  8761. * var moddle = new Moddle([pkg]);
  8762. *
  8763. * @param {Array<Package>} packages the packages to contain
  8764. * @param {Object} options additional options to pass to the model
  8765. */
  8766. function Moddle(packages, options) {
  8767. options = options || {};
  8768. this.properties = new Properties(this);
  8769. this.factory = new Factory(this, this.properties);
  8770. this.registry = new Registry(packages, this.properties, options);
  8771. this.typeCache = {};
  8772. }
  8773. module.exports = Moddle;
  8774. /**
  8775. * Create an instance of the specified type.
  8776. *
  8777. * @method Moddle#create
  8778. *
  8779. * @example
  8780. *
  8781. * var foo = moddle.create('my:Foo');
  8782. * var bar = moddle.create('my:Bar', { id: 'BAR_1' });
  8783. *
  8784. * @param {String|Object} descriptor the type descriptor or name know to the model
  8785. * @param {Object} attrs a number of attributes to initialize the model instance with
  8786. * @return {Object} model instance
  8787. */
  8788. Moddle.prototype.create = function(descriptor, attrs) {
  8789. var Type = this.getType(descriptor);
  8790. if (!Type) {
  8791. throw new Error('unknown type <' + descriptor + '>');
  8792. }
  8793. return new Type(attrs);
  8794. };
  8795. /**
  8796. * Returns the type representing a given descriptor
  8797. *
  8798. * @method Moddle#getType
  8799. *
  8800. * @example
  8801. *
  8802. * var Foo = moddle.getType('my:Foo');
  8803. * var foo = new Foo({ 'id' : 'FOO_1' });
  8804. *
  8805. * @param {String|Object} descriptor the type descriptor or name know to the model
  8806. * @return {Object} the type representing the descriptor
  8807. */
  8808. Moddle.prototype.getType = function(descriptor) {
  8809. var cache = this.typeCache;
  8810. var name = isString(descriptor) ? descriptor : descriptor.ns.name;
  8811. var type = cache[name];
  8812. if (!type) {
  8813. descriptor = this.registry.getEffectiveDescriptor(name);
  8814. type = cache[name] = this.factory.createType(descriptor);
  8815. }
  8816. return type;
  8817. };
  8818. /**
  8819. * Creates an any-element type to be used within model instances.
  8820. *
  8821. * This can be used to create custom elements that lie outside the meta-model.
  8822. * The created element contains all the meta-data required to serialize it
  8823. * as part of meta-model elements.
  8824. *
  8825. * @method Moddle#createAny
  8826. *
  8827. * @example
  8828. *
  8829. * var foo = moddle.createAny('vendor:Foo', 'http://vendor', {
  8830. * value: 'bar'
  8831. * });
  8832. *
  8833. * var container = moddle.create('my:Container', 'http://my', {
  8834. * any: [ foo ]
  8835. * });
  8836. *
  8837. * // go ahead and serialize the stuff
  8838. *
  8839. *
  8840. * @param {String} name the name of the element
  8841. * @param {String} nsUri the namespace uri of the element
  8842. * @param {Object} [properties] a map of properties to initialize the instance with
  8843. * @return {Object} the any type instance
  8844. */
  8845. Moddle.prototype.createAny = function(name, nsUri, properties) {
  8846. var nameNs = parseNameNs(name);
  8847. var element = {
  8848. $type: name
  8849. };
  8850. var descriptor = {
  8851. name: name,
  8852. isGeneric: true,
  8853. ns: {
  8854. prefix: nameNs.prefix,
  8855. localName: nameNs.localName,
  8856. uri: nsUri
  8857. }
  8858. };
  8859. this.properties.defineDescriptor(element, descriptor);
  8860. this.properties.defineModel(element, this);
  8861. this.properties.define(element, '$parent', { enumerable: false, writable: true });
  8862. forEach(properties, function(a, key) {
  8863. if (isObject(a) && a.value !== undefined) {
  8864. element[a.name] = a.value;
  8865. } else {
  8866. element[key] = a;
  8867. }
  8868. });
  8869. return element;
  8870. };
  8871. /**
  8872. * Returns a registered package by uri or prefix
  8873. *
  8874. * @return {Object} the package
  8875. */
  8876. Moddle.prototype.getPackage = function(uriOrPrefix) {
  8877. return this.registry.getPackage(uriOrPrefix);
  8878. };
  8879. /**
  8880. * Returns a snapshot of all known packages
  8881. *
  8882. * @return {Object} the package
  8883. */
  8884. Moddle.prototype.getPackages = function() {
  8885. return this.registry.getPackages();
  8886. };
  8887. /**
  8888. * Returns the descriptor for an element
  8889. */
  8890. Moddle.prototype.getElementDescriptor = function(element) {
  8891. return element.$descriptor;
  8892. };
  8893. /**
  8894. * Returns true if the given descriptor or instance
  8895. * represents the given type.
  8896. *
  8897. * May be applied to this, if element is omitted.
  8898. */
  8899. Moddle.prototype.hasType = function(element, type) {
  8900. if (type === undefined) {
  8901. type = element;
  8902. element = this;
  8903. }
  8904. var descriptor = element.$model.getElementDescriptor(element);
  8905. return !!find(descriptor.allTypes, function(t) {
  8906. return t.name === type;
  8907. });
  8908. };
  8909. /**
  8910. * Returns the descriptor of an elements named property
  8911. */
  8912. Moddle.prototype.getPropertyDescriptor = function(element, property) {
  8913. return this.getElementDescriptor(element).propertiesByName[property];
  8914. };
  8915. },{"217":217,"218":218,"334":334,"336":336,"63":63,"65":65,"66":66,"67":67}],65:[function(_dereq_,module,exports){
  8916. 'use strict';
  8917. /**
  8918. * Parses a namespaced attribute name of the form (ns:)localName to an object,
  8919. * given a default prefix to assume in case no explicit namespace is given.
  8920. *
  8921. * @param {String} name
  8922. * @param {String} [defaultPrefix] the default prefix to take, if none is present.
  8923. *
  8924. * @return {Object} the parsed name
  8925. */
  8926. module.exports.parseName = function(name, defaultPrefix) {
  8927. var parts = name.split(/:/),
  8928. localName, prefix;
  8929. // no prefix (i.e. only local name)
  8930. if (parts.length === 1) {
  8931. localName = name;
  8932. prefix = defaultPrefix;
  8933. } else
  8934. // prefix + local name
  8935. if (parts.length === 2) {
  8936. localName = parts[1];
  8937. prefix = parts[0];
  8938. } else {
  8939. throw new Error('expected <prefix:localName> or <localName>, got ' + name);
  8940. }
  8941. name = (prefix ? prefix + ':' : '') + localName;
  8942. return {
  8943. name: name,
  8944. prefix: prefix,
  8945. localName: localName
  8946. };
  8947. };
  8948. },{}],66:[function(_dereq_,module,exports){
  8949. 'use strict';
  8950. /**
  8951. * A utility that gets and sets properties of model elements.
  8952. *
  8953. * @param {Model} model
  8954. */
  8955. function Properties(model) {
  8956. this.model = model;
  8957. }
  8958. module.exports = Properties;
  8959. /**
  8960. * Sets a named property on the target element
  8961. *
  8962. * @param {Object} target
  8963. * @param {String} name
  8964. * @param {Object} value
  8965. */
  8966. Properties.prototype.set = function(target, name, value) {
  8967. var property = this.model.getPropertyDescriptor(target, name);
  8968. if (!property) {
  8969. target.$attrs[name] = value;
  8970. } else {
  8971. Object.defineProperty(target, property.name, {
  8972. enumerable: !property.isReference,
  8973. writable: true,
  8974. value: value
  8975. });
  8976. }
  8977. };
  8978. /**
  8979. * Returns the named property of the given element
  8980. *
  8981. * @param {Object} target
  8982. * @param {String} name
  8983. *
  8984. * @return {Object}
  8985. */
  8986. Properties.prototype.get = function(target, name) {
  8987. var property = this.model.getPropertyDescriptor(target, name);
  8988. if (!property) {
  8989. return target.$attrs[name];
  8990. }
  8991. var propertyName = property.name;
  8992. // check if access to collection property and lazily initialize it
  8993. if (!target[propertyName] && property.isMany) {
  8994. Object.defineProperty(target, propertyName, {
  8995. enumerable: !property.isReference,
  8996. writable: true,
  8997. value: []
  8998. });
  8999. }
  9000. return target[propertyName];
  9001. };
  9002. /**
  9003. * Define a property on the target element
  9004. *
  9005. * @param {Object} target
  9006. * @param {String} name
  9007. * @param {Object} options
  9008. */
  9009. Properties.prototype.define = function(target, name, options) {
  9010. Object.defineProperty(target, name, options);
  9011. };
  9012. /**
  9013. * Define the descriptor for an element
  9014. */
  9015. Properties.prototype.defineDescriptor = function(target, descriptor) {
  9016. this.define(target, '$descriptor', { value: descriptor });
  9017. };
  9018. /**
  9019. * Define the model for an element
  9020. */
  9021. Properties.prototype.defineModel = function(target, model) {
  9022. this.define(target, '$model', { value: model });
  9023. };
  9024. },{}],67:[function(_dereq_,module,exports){
  9025. 'use strict';
  9026. var assign = _dereq_(339),
  9027. forEach = _dereq_(218);
  9028. var Types = _dereq_(68),
  9029. DescriptorBuilder = _dereq_(62);
  9030. var parseNameNs = _dereq_(65).parseName,
  9031. isBuiltInType = Types.isBuiltIn;
  9032. function Registry(packages, properties, options) {
  9033. this.options = assign({ generateId: 'id' }, options || {});
  9034. this.packageMap = {};
  9035. this.typeMap = {};
  9036. this.packages = [];
  9037. this.properties = properties;
  9038. forEach(packages, this.registerPackage, this);
  9039. }
  9040. module.exports = Registry;
  9041. Registry.prototype.getPackage = function(uriOrPrefix) {
  9042. return this.packageMap[uriOrPrefix];
  9043. };
  9044. Registry.prototype.getPackages = function() {
  9045. return this.packages;
  9046. };
  9047. Registry.prototype.registerPackage = function(pkg) {
  9048. // copy package
  9049. pkg = assign({}, pkg);
  9050. // register types
  9051. forEach(pkg.types, function(descriptor) {
  9052. this.registerType(descriptor, pkg);
  9053. }, this);
  9054. this.packageMap[pkg.uri] = this.packageMap[pkg.prefix] = pkg;
  9055. this.packages.push(pkg);
  9056. };
  9057. /**
  9058. * Register a type from a specific package with us
  9059. */
  9060. Registry.prototype.registerType = function(type, pkg) {
  9061. type = assign({}, type, {
  9062. superClass: (type.superClass || []).slice(),
  9063. extends: (type.extends || []).slice(),
  9064. properties: (type.properties || []).slice()
  9065. });
  9066. var ns = parseNameNs(type.name, pkg.prefix),
  9067. name = ns.name,
  9068. propertiesByName = {};
  9069. // parse properties
  9070. forEach(type.properties, function(p) {
  9071. // namespace property names
  9072. var propertyNs = parseNameNs(p.name, ns.prefix),
  9073. propertyName = propertyNs.name;
  9074. // namespace property types
  9075. if (!isBuiltInType(p.type)) {
  9076. p.type = parseNameNs(p.type, propertyNs.prefix).name;
  9077. }
  9078. assign(p, {
  9079. ns: propertyNs,
  9080. name: propertyName
  9081. });
  9082. propertiesByName[propertyName] = p;
  9083. });
  9084. // update ns + name
  9085. assign(type, {
  9086. ns: ns,
  9087. name: name,
  9088. propertiesByName: propertiesByName
  9089. });
  9090. forEach(type.extends, function(extendsName) {
  9091. var extended = this.typeMap[extendsName];
  9092. extended.traits = extended.traits || [];
  9093. extended.traits.push(name);
  9094. }, this);
  9095. // link to package
  9096. this.definePackage(type, pkg);
  9097. // register
  9098. this.typeMap[name] = type;
  9099. };
  9100. /**
  9101. * Traverse the type hierarchy from bottom to top.
  9102. */
  9103. Registry.prototype.mapTypes = function(nsName, iterator) {
  9104. var type = isBuiltInType(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
  9105. var self = this;
  9106. /**
  9107. * Traverse the selected super type or trait
  9108. *
  9109. * @param {String} cls
  9110. */
  9111. function traverseSuper(cls) {
  9112. var parentNs = parseNameNs(cls, isBuiltInType(cls) ? '' : nsName.prefix);
  9113. self.mapTypes(parentNs, iterator);
  9114. }
  9115. if (!type) {
  9116. throw new Error('unknown type <' + nsName.name + '>');
  9117. }
  9118. forEach(type.superClass, traverseSuper);
  9119. iterator(type);
  9120. forEach(type.traits, traverseSuper);
  9121. };
  9122. /**
  9123. * Returns the effective descriptor for a type.
  9124. *
  9125. * @param {String} type the namespaced name (ns:localName) of the type
  9126. *
  9127. * @return {Descriptor} the resulting effective descriptor
  9128. */
  9129. Registry.prototype.getEffectiveDescriptor = function(name) {
  9130. var nsName = parseNameNs(name);
  9131. var builder = new DescriptorBuilder(nsName);
  9132. this.mapTypes(nsName, function(type) {
  9133. builder.addTrait(type);
  9134. });
  9135. // check we have an id assigned
  9136. var id = this.options.generateId;
  9137. if (id && !builder.hasProperty(id)) {
  9138. builder.addIdProperty(id);
  9139. }
  9140. var descriptor = builder.build();
  9141. // define package link
  9142. this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
  9143. return descriptor;
  9144. };
  9145. Registry.prototype.definePackage = function(target, pkg) {
  9146. this.properties.define(target, '$pkg', { value: pkg });
  9147. };
  9148. },{"218":218,"339":339,"62":62,"65":65,"68":68}],68:[function(_dereq_,module,exports){
  9149. 'use strict';
  9150. /**
  9151. * Built-in moddle types
  9152. */
  9153. var BUILTINS = {
  9154. String: true,
  9155. Boolean: true,
  9156. Integer: true,
  9157. Real: true,
  9158. Element: true
  9159. };
  9160. /**
  9161. * Converters for built in types from string representations
  9162. */
  9163. var TYPE_CONVERTERS = {
  9164. String: function(s) { return s; },
  9165. Boolean: function(s) { return s === 'true'; },
  9166. Integer: function(s) { return parseInt(s, 10); },
  9167. Real: function(s) { return parseFloat(s, 10); }
  9168. };
  9169. /**
  9170. * Convert a type to its real representation
  9171. */
  9172. module.exports.coerceType = function(type, value) {
  9173. var converter = TYPE_CONVERTERS[type];
  9174. if (converter) {
  9175. return converter(value);
  9176. } else {
  9177. return value;
  9178. }
  9179. };
  9180. /**
  9181. * Return whether the given type is built-in
  9182. */
  9183. module.exports.isBuiltIn = function(type) {
  9184. return !!BUILTINS[type];
  9185. };
  9186. /**
  9187. * Return whether the given type is simple
  9188. */
  9189. module.exports.isSimple = function(type) {
  9190. return !!TYPE_CONVERTERS[type];
  9191. };
  9192. },{}],69:[function(_dereq_,module,exports){
  9193. module.exports={
  9194. "name": "BPMN20",
  9195. "uri": "http://www.omg.org/spec/BPMN/20100524/MODEL",
  9196. "associations": [],
  9197. "types": [
  9198. {
  9199. "name": "Interface",
  9200. "superClass": [
  9201. "RootElement"
  9202. ],
  9203. "properties": [
  9204. {
  9205. "name": "name",
  9206. "isAttr": true,
  9207. "type": "String"
  9208. },
  9209. {
  9210. "name": "operations",
  9211. "type": "Operation",
  9212. "isMany": true
  9213. },
  9214. {
  9215. "name": "implementationRef",
  9216. "type": "String",
  9217. "isAttr": true
  9218. }
  9219. ]
  9220. },
  9221. {
  9222. "name": "Operation",
  9223. "superClass": [
  9224. "BaseElement"
  9225. ],
  9226. "properties": [
  9227. {
  9228. "name": "name",
  9229. "isAttr": true,
  9230. "type": "String"
  9231. },
  9232. {
  9233. "name": "inMessageRef",
  9234. "type": "Message",
  9235. "isAttr": true,
  9236. "isReference": true
  9237. },
  9238. {
  9239. "name": "outMessageRef",
  9240. "type": "Message",
  9241. "isAttr": true,
  9242. "isReference": true
  9243. },
  9244. {
  9245. "name": "errorRefs",
  9246. "type": "Error",
  9247. "isMany": true,
  9248. "isReference": true
  9249. },
  9250. {
  9251. "name": "implementationRef",
  9252. "type": "String",
  9253. "isAttr": true
  9254. }
  9255. ]
  9256. },
  9257. {
  9258. "name": "EndPoint",
  9259. "superClass": [
  9260. "RootElement"
  9261. ]
  9262. },
  9263. {
  9264. "name": "Auditing",
  9265. "superClass": [
  9266. "BaseElement"
  9267. ]
  9268. },
  9269. {
  9270. "name": "GlobalTask",
  9271. "superClass": [
  9272. "CallableElement"
  9273. ],
  9274. "properties": [
  9275. {
  9276. "name": "resources",
  9277. "type": "ResourceRole",
  9278. "isMany": true
  9279. }
  9280. ]
  9281. },
  9282. {
  9283. "name": "Monitoring",
  9284. "superClass": [
  9285. "BaseElement"
  9286. ]
  9287. },
  9288. {
  9289. "name": "Performer",
  9290. "superClass": [
  9291. "ResourceRole"
  9292. ]
  9293. },
  9294. {
  9295. "name": "Process",
  9296. "superClass": [
  9297. "FlowElementsContainer",
  9298. "CallableElement"
  9299. ],
  9300. "properties": [
  9301. {
  9302. "name": "processType",
  9303. "type": "ProcessType",
  9304. "isAttr": true
  9305. },
  9306. {
  9307. "name": "isClosed",
  9308. "isAttr": true,
  9309. "type": "Boolean"
  9310. },
  9311. {
  9312. "name": "auditing",
  9313. "type": "Auditing"
  9314. },
  9315. {
  9316. "name": "monitoring",
  9317. "type": "Monitoring"
  9318. },
  9319. {
  9320. "name": "properties",
  9321. "type": "Property",
  9322. "isMany": true
  9323. },
  9324. {
  9325. "name": "artifacts",
  9326. "type": "Artifact",
  9327. "isMany": true
  9328. },
  9329. {
  9330. "name": "resources",
  9331. "type": "ResourceRole",
  9332. "isMany": true
  9333. },
  9334. {
  9335. "name": "correlationSubscriptions",
  9336. "type": "CorrelationSubscription",
  9337. "isMany": true
  9338. },
  9339. {
  9340. "name": "supports",
  9341. "type": "Process",
  9342. "isMany": true,
  9343. "isReference": true
  9344. },
  9345. {
  9346. "name": "definitionalCollaborationRef",
  9347. "type": "Collaboration",
  9348. "isAttr": true,
  9349. "isReference": true
  9350. },
  9351. {
  9352. "name": "isExecutable",
  9353. "isAttr": true,
  9354. "type": "Boolean"
  9355. }
  9356. ]
  9357. },
  9358. {
  9359. "name": "LaneSet",
  9360. "superClass": [
  9361. "BaseElement"
  9362. ],
  9363. "properties": [
  9364. {
  9365. "name": "lanes",
  9366. "type": "Lane",
  9367. "isMany": true
  9368. },
  9369. {
  9370. "name": "name",
  9371. "isAttr": true,
  9372. "type": "String"
  9373. }
  9374. ]
  9375. },
  9376. {
  9377. "name": "Lane",
  9378. "superClass": [
  9379. "BaseElement"
  9380. ],
  9381. "properties": [
  9382. {
  9383. "name": "name",
  9384. "isAttr": true,
  9385. "type": "String"
  9386. },
  9387. {
  9388. "name": "childLaneSet",
  9389. "type": "LaneSet",
  9390. "xml": {
  9391. "serialize": "xsi:type"
  9392. }
  9393. },
  9394. {
  9395. "name": "partitionElementRef",
  9396. "type": "BaseElement",
  9397. "isAttr": true,
  9398. "isReference": true
  9399. },
  9400. {
  9401. "name": "flowNodeRef",
  9402. "type": "FlowNode",
  9403. "isMany": true,
  9404. "isReference": true
  9405. },
  9406. {
  9407. "name": "partitionElement",
  9408. "type": "BaseElement"
  9409. }
  9410. ]
  9411. },
  9412. {
  9413. "name": "GlobalManualTask",
  9414. "superClass": [
  9415. "GlobalTask"
  9416. ]
  9417. },
  9418. {
  9419. "name": "ManualTask",
  9420. "superClass": [
  9421. "Task"
  9422. ]
  9423. },
  9424. {
  9425. "name": "UserTask",
  9426. "superClass": [
  9427. "Task"
  9428. ],
  9429. "properties": [
  9430. {
  9431. "name": "renderings",
  9432. "type": "Rendering",
  9433. "isMany": true
  9434. },
  9435. {
  9436. "name": "implementation",
  9437. "isAttr": true,
  9438. "type": "String"
  9439. }
  9440. ]
  9441. },
  9442. {
  9443. "name": "Rendering",
  9444. "superClass": [
  9445. "BaseElement"
  9446. ]
  9447. },
  9448. {
  9449. "name": "HumanPerformer",
  9450. "superClass": [
  9451. "Performer"
  9452. ]
  9453. },
  9454. {
  9455. "name": "PotentialOwner",
  9456. "superClass": [
  9457. "HumanPerformer"
  9458. ]
  9459. },
  9460. {
  9461. "name": "GlobalUserTask",
  9462. "superClass": [
  9463. "GlobalTask"
  9464. ],
  9465. "properties": [
  9466. {
  9467. "name": "implementation",
  9468. "isAttr": true,
  9469. "type": "String"
  9470. },
  9471. {
  9472. "name": "renderings",
  9473. "type": "Rendering",
  9474. "isMany": true
  9475. }
  9476. ]
  9477. },
  9478. {
  9479. "name": "Gateway",
  9480. "isAbstract": true,
  9481. "superClass": [
  9482. "FlowNode"
  9483. ],
  9484. "properties": [
  9485. {
  9486. "name": "gatewayDirection",
  9487. "type": "GatewayDirection",
  9488. "default": "Unspecified",
  9489. "isAttr": true
  9490. }
  9491. ]
  9492. },
  9493. {
  9494. "name": "EventBasedGateway",
  9495. "superClass": [
  9496. "Gateway"
  9497. ],
  9498. "properties": [
  9499. {
  9500. "name": "instantiate",
  9501. "default": false,
  9502. "isAttr": true,
  9503. "type": "Boolean"
  9504. },
  9505. {
  9506. "name": "eventGatewayType",
  9507. "type": "EventBasedGatewayType",
  9508. "isAttr": true,
  9509. "default": "Exclusive"
  9510. }
  9511. ]
  9512. },
  9513. {
  9514. "name": "ComplexGateway",
  9515. "superClass": [
  9516. "Gateway"
  9517. ],
  9518. "properties": [
  9519. {
  9520. "name": "activationCondition",
  9521. "type": "Expression",
  9522. "xml": {
  9523. "serialize": "xsi:type"
  9524. }
  9525. },
  9526. {
  9527. "name": "default",
  9528. "type": "SequenceFlow",
  9529. "isAttr": true,
  9530. "isReference": true
  9531. }
  9532. ]
  9533. },
  9534. {
  9535. "name": "ExclusiveGateway",
  9536. "superClass": [
  9537. "Gateway"
  9538. ],
  9539. "properties": [
  9540. {
  9541. "name": "default",
  9542. "type": "SequenceFlow",
  9543. "isAttr": true,
  9544. "isReference": true
  9545. }
  9546. ]
  9547. },
  9548. {
  9549. "name": "InclusiveGateway",
  9550. "superClass": [
  9551. "Gateway"
  9552. ],
  9553. "properties": [
  9554. {
  9555. "name": "default",
  9556. "type": "SequenceFlow",
  9557. "isAttr": true,
  9558. "isReference": true
  9559. }
  9560. ]
  9561. },
  9562. {
  9563. "name": "ParallelGateway",
  9564. "superClass": [
  9565. "Gateway"
  9566. ]
  9567. },
  9568. {
  9569. "name": "RootElement",
  9570. "isAbstract": true,
  9571. "superClass": [
  9572. "BaseElement"
  9573. ]
  9574. },
  9575. {
  9576. "name": "Relationship",
  9577. "superClass": [
  9578. "BaseElement"
  9579. ],
  9580. "properties": [
  9581. {
  9582. "name": "type",
  9583. "isAttr": true,
  9584. "type": "String"
  9585. },
  9586. {
  9587. "name": "direction",
  9588. "type": "RelationshipDirection",
  9589. "isAttr": true
  9590. },
  9591. {
  9592. "name": "source",
  9593. "isMany": true,
  9594. "isReference": true,
  9595. "type": "Element"
  9596. },
  9597. {
  9598. "name": "target",
  9599. "isMany": true,
  9600. "isReference": true,
  9601. "type": "Element"
  9602. }
  9603. ]
  9604. },
  9605. {
  9606. "name": "BaseElement",
  9607. "isAbstract": true,
  9608. "properties": [
  9609. {
  9610. "name": "id",
  9611. "isAttr": true,
  9612. "type": "String"
  9613. },
  9614. {
  9615. "name": "documentation",
  9616. "type": "Documentation",
  9617. "isMany": true
  9618. },
  9619. {
  9620. "name": "extensionDefinitions",
  9621. "type": "ExtensionDefinition",
  9622. "isMany": true,
  9623. "isReference": true
  9624. },
  9625. {
  9626. "name": "extensionElements",
  9627. "type": "ExtensionElements"
  9628. }
  9629. ]
  9630. },
  9631. {
  9632. "name": "Extension",
  9633. "properties": [
  9634. {
  9635. "name": "mustUnderstand",
  9636. "default": false,
  9637. "isAttr": true,
  9638. "type": "Boolean"
  9639. },
  9640. {
  9641. "name": "definition",
  9642. "type": "ExtensionDefinition"
  9643. }
  9644. ]
  9645. },
  9646. {
  9647. "name": "ExtensionDefinition",
  9648. "properties": [
  9649. {
  9650. "name": "name",
  9651. "isAttr": true,
  9652. "type": "String"
  9653. },
  9654. {
  9655. "name": "extensionAttributeDefinitions",
  9656. "type": "ExtensionAttributeDefinition",
  9657. "isMany": true
  9658. }
  9659. ]
  9660. },
  9661. {
  9662. "name": "ExtensionAttributeDefinition",
  9663. "properties": [
  9664. {
  9665. "name": "name",
  9666. "isAttr": true,
  9667. "type": "String"
  9668. },
  9669. {
  9670. "name": "type",
  9671. "isAttr": true,
  9672. "type": "String"
  9673. },
  9674. {
  9675. "name": "isReference",
  9676. "default": false,
  9677. "isAttr": true,
  9678. "type": "Boolean"
  9679. },
  9680. {
  9681. "name": "extensionDefinition",
  9682. "type": "ExtensionDefinition",
  9683. "isAttr": true,
  9684. "isReference": true
  9685. }
  9686. ]
  9687. },
  9688. {
  9689. "name": "ExtensionElements",
  9690. "properties": [
  9691. {
  9692. "name": "valueRef",
  9693. "isAttr": true,
  9694. "isReference": true,
  9695. "type": "Element"
  9696. },
  9697. {
  9698. "name": "values",
  9699. "type": "Element",
  9700. "isMany": true
  9701. },
  9702. {
  9703. "name": "extensionAttributeDefinition",
  9704. "type": "ExtensionAttributeDefinition",
  9705. "isAttr": true,
  9706. "isReference": true
  9707. }
  9708. ]
  9709. },
  9710. {
  9711. "name": "Documentation",
  9712. "superClass": [
  9713. "BaseElement"
  9714. ],
  9715. "properties": [
  9716. {
  9717. "name": "text",
  9718. "type": "String",
  9719. "isBody": true
  9720. },
  9721. {
  9722. "name": "textFormat",
  9723. "default": "text/plain",
  9724. "isAttr": true,
  9725. "type": "String"
  9726. }
  9727. ]
  9728. },
  9729. {
  9730. "name": "Event",
  9731. "isAbstract": true,
  9732. "superClass": [
  9733. "FlowNode",
  9734. "InteractionNode"
  9735. ],
  9736. "properties": [
  9737. {
  9738. "name": "properties",
  9739. "type": "Property",
  9740. "isMany": true
  9741. }
  9742. ]
  9743. },
  9744. {
  9745. "name": "IntermediateCatchEvent",
  9746. "superClass": [
  9747. "CatchEvent"
  9748. ]
  9749. },
  9750. {
  9751. "name": "IntermediateThrowEvent",
  9752. "superClass": [
  9753. "ThrowEvent"
  9754. ]
  9755. },
  9756. {
  9757. "name": "EndEvent",
  9758. "superClass": [
  9759. "ThrowEvent"
  9760. ]
  9761. },
  9762. {
  9763. "name": "StartEvent",
  9764. "superClass": [
  9765. "CatchEvent"
  9766. ],
  9767. "properties": [
  9768. {
  9769. "name": "isInterrupting",
  9770. "default": true,
  9771. "isAttr": true,
  9772. "type": "Boolean"
  9773. }
  9774. ]
  9775. },
  9776. {
  9777. "name": "ThrowEvent",
  9778. "isAbstract": true,
  9779. "superClass": [
  9780. "Event"
  9781. ],
  9782. "properties": [
  9783. {
  9784. "name": "inputSet",
  9785. "type": "InputSet"
  9786. },
  9787. {
  9788. "name": "eventDefinitionRefs",
  9789. "type": "EventDefinition",
  9790. "isMany": true,
  9791. "isReference": true
  9792. },
  9793. {
  9794. "name": "dataInputAssociation",
  9795. "type": "DataInputAssociation",
  9796. "isMany": true
  9797. },
  9798. {
  9799. "name": "dataInputs",
  9800. "type": "DataInput",
  9801. "isMany": true
  9802. },
  9803. {
  9804. "name": "eventDefinitions",
  9805. "type": "EventDefinition",
  9806. "isMany": true
  9807. }
  9808. ]
  9809. },
  9810. {
  9811. "name": "CatchEvent",
  9812. "isAbstract": true,
  9813. "superClass": [
  9814. "Event"
  9815. ],
  9816. "properties": [
  9817. {
  9818. "name": "parallelMultiple",
  9819. "isAttr": true,
  9820. "type": "Boolean",
  9821. "default": false
  9822. },
  9823. {
  9824. "name": "outputSet",
  9825. "type": "OutputSet"
  9826. },
  9827. {
  9828. "name": "eventDefinitionRefs",
  9829. "type": "EventDefinition",
  9830. "isMany": true,
  9831. "isReference": true
  9832. },
  9833. {
  9834. "name": "dataOutputAssociation",
  9835. "type": "DataOutputAssociation",
  9836. "isMany": true
  9837. },
  9838. {
  9839. "name": "dataOutputs",
  9840. "type": "DataOutput",
  9841. "isMany": true
  9842. },
  9843. {
  9844. "name": "eventDefinitions",
  9845. "type": "EventDefinition",
  9846. "isMany": true
  9847. }
  9848. ]
  9849. },
  9850. {
  9851. "name": "BoundaryEvent",
  9852. "superClass": [
  9853. "CatchEvent"
  9854. ],
  9855. "properties": [
  9856. {
  9857. "name": "cancelActivity",
  9858. "default": true,
  9859. "isAttr": true,
  9860. "type": "Boolean"
  9861. },
  9862. {
  9863. "name": "attachedToRef",
  9864. "type": "Activity",
  9865. "isAttr": true,
  9866. "isReference": true
  9867. }
  9868. ]
  9869. },
  9870. {
  9871. "name": "EventDefinition",
  9872. "isAbstract": true,
  9873. "superClass": [
  9874. "RootElement"
  9875. ]
  9876. },
  9877. {
  9878. "name": "CancelEventDefinition",
  9879. "superClass": [
  9880. "EventDefinition"
  9881. ]
  9882. },
  9883. {
  9884. "name": "ErrorEventDefinition",
  9885. "superClass": [
  9886. "EventDefinition"
  9887. ],
  9888. "properties": [
  9889. {
  9890. "name": "errorRef",
  9891. "type": "Error",
  9892. "isAttr": true,
  9893. "isReference": true
  9894. }
  9895. ]
  9896. },
  9897. {
  9898. "name": "TerminateEventDefinition",
  9899. "superClass": [
  9900. "EventDefinition"
  9901. ]
  9902. },
  9903. {
  9904. "name": "EscalationEventDefinition",
  9905. "superClass": [
  9906. "EventDefinition"
  9907. ],
  9908. "properties": [
  9909. {
  9910. "name": "escalationRef",
  9911. "type": "Escalation",
  9912. "isAttr": true,
  9913. "isReference": true
  9914. }
  9915. ]
  9916. },
  9917. {
  9918. "name": "Escalation",
  9919. "properties": [
  9920. {
  9921. "name": "structureRef",
  9922. "type": "ItemDefinition",
  9923. "isAttr": true,
  9924. "isReference": true
  9925. },
  9926. {
  9927. "name": "name",
  9928. "isAttr": true,
  9929. "type": "String"
  9930. },
  9931. {
  9932. "name": "escalationCode",
  9933. "isAttr": true,
  9934. "type": "String"
  9935. }
  9936. ],
  9937. "superClass": [
  9938. "RootElement"
  9939. ]
  9940. },
  9941. {
  9942. "name": "CompensateEventDefinition",
  9943. "superClass": [
  9944. "EventDefinition"
  9945. ],
  9946. "properties": [
  9947. {
  9948. "name": "waitForCompletion",
  9949. "isAttr": true,
  9950. "type": "Boolean"
  9951. },
  9952. {
  9953. "name": "activityRef",
  9954. "type": "Activity",
  9955. "isAttr": true,
  9956. "isReference": true
  9957. }
  9958. ]
  9959. },
  9960. {
  9961. "name": "TimerEventDefinition",
  9962. "superClass": [
  9963. "EventDefinition"
  9964. ],
  9965. "properties": [
  9966. {
  9967. "name": "timeDate",
  9968. "type": "Expression",
  9969. "xml": {
  9970. "serialize": "xsi:type"
  9971. }
  9972. },
  9973. {
  9974. "name": "timeCycle",
  9975. "type": "Expression",
  9976. "xml": {
  9977. "serialize": "xsi:type"
  9978. }
  9979. },
  9980. {
  9981. "name": "timeDuration",
  9982. "type": "Expression",
  9983. "xml": {
  9984. "serialize": "xsi:type"
  9985. }
  9986. }
  9987. ]
  9988. },
  9989. {
  9990. "name": "LinkEventDefinition",
  9991. "superClass": [
  9992. "EventDefinition"
  9993. ],
  9994. "properties": [
  9995. {
  9996. "name": "name",
  9997. "isAttr": true,
  9998. "type": "String"
  9999. },
  10000. {
  10001. "name": "target",
  10002. "type": "LinkEventDefinition",
  10003. "isAttr": true,
  10004. "isReference": true
  10005. },
  10006. {
  10007. "name": "source",
  10008. "type": "LinkEventDefinition",
  10009. "isMany": true,
  10010. "isReference": true
  10011. }
  10012. ]
  10013. },
  10014. {
  10015. "name": "MessageEventDefinition",
  10016. "superClass": [
  10017. "EventDefinition"
  10018. ],
  10019. "properties": [
  10020. {
  10021. "name": "messageRef",
  10022. "type": "Message",
  10023. "isAttr": true,
  10024. "isReference": true
  10025. },
  10026. {
  10027. "name": "operationRef",
  10028. "type": "Operation",
  10029. "isAttr": true,
  10030. "isReference": true
  10031. }
  10032. ]
  10033. },
  10034. {
  10035. "name": "ConditionalEventDefinition",
  10036. "superClass": [
  10037. "EventDefinition"
  10038. ],
  10039. "properties": [
  10040. {
  10041. "name": "condition",
  10042. "type": "Expression",
  10043. "xml": {
  10044. "serialize": "xsi:type"
  10045. }
  10046. }
  10047. ]
  10048. },
  10049. {
  10050. "name": "SignalEventDefinition",
  10051. "superClass": [
  10052. "EventDefinition"
  10053. ],
  10054. "properties": [
  10055. {
  10056. "name": "signalRef",
  10057. "type": "Signal",
  10058. "isAttr": true,
  10059. "isReference": true
  10060. }
  10061. ]
  10062. },
  10063. {
  10064. "name": "Signal",
  10065. "superClass": [
  10066. "RootElement"
  10067. ],
  10068. "properties": [
  10069. {
  10070. "name": "structureRef",
  10071. "type": "ItemDefinition",
  10072. "isAttr": true,
  10073. "isReference": true
  10074. },
  10075. {
  10076. "name": "name",
  10077. "isAttr": true,
  10078. "type": "String"
  10079. }
  10080. ]
  10081. },
  10082. {
  10083. "name": "ImplicitThrowEvent",
  10084. "superClass": [
  10085. "ThrowEvent"
  10086. ]
  10087. },
  10088. {
  10089. "name": "DataState",
  10090. "superClass": [
  10091. "BaseElement"
  10092. ],
  10093. "properties": [
  10094. {
  10095. "name": "name",
  10096. "isAttr": true,
  10097. "type": "String"
  10098. }
  10099. ]
  10100. },
  10101. {
  10102. "name": "ItemAwareElement",
  10103. "superClass": [
  10104. "BaseElement"
  10105. ],
  10106. "properties": [
  10107. {
  10108. "name": "itemSubjectRef",
  10109. "type": "ItemDefinition",
  10110. "isAttr": true,
  10111. "isReference": true
  10112. },
  10113. {
  10114. "name": "dataState",
  10115. "type": "DataState"
  10116. }
  10117. ]
  10118. },
  10119. {
  10120. "name": "DataAssociation",
  10121. "superClass": [
  10122. "BaseElement"
  10123. ],
  10124. "properties": [
  10125. {
  10126. "name": "transformation",
  10127. "type": "FormalExpression"
  10128. },
  10129. {
  10130. "name": "assignment",
  10131. "type": "Assignment",
  10132. "isMany": true
  10133. },
  10134. {
  10135. "name": "sourceRef",
  10136. "type": "ItemAwareElement",
  10137. "isMany": true,
  10138. "isReference": true
  10139. },
  10140. {
  10141. "name": "targetRef",
  10142. "type": "ItemAwareElement",
  10143. "isReference": true
  10144. }
  10145. ]
  10146. },
  10147. {
  10148. "name": "DataInput",
  10149. "superClass": [
  10150. "ItemAwareElement"
  10151. ],
  10152. "properties": [
  10153. {
  10154. "name": "name",
  10155. "isAttr": true,
  10156. "type": "String"
  10157. },
  10158. {
  10159. "name": "isCollection",
  10160. "default": false,
  10161. "isAttr": true,
  10162. "type": "Boolean"
  10163. },
  10164. {
  10165. "name": "inputSetRefs",
  10166. "type": "InputSet",
  10167. "isVirtual": true,
  10168. "isMany": true,
  10169. "isReference": true
  10170. },
  10171. {
  10172. "name": "inputSetWithOptional",
  10173. "type": "InputSet",
  10174. "isVirtual": true,
  10175. "isMany": true,
  10176. "isReference": true
  10177. },
  10178. {
  10179. "name": "inputSetWithWhileExecuting",
  10180. "type": "InputSet",
  10181. "isVirtual": true,
  10182. "isMany": true,
  10183. "isReference": true
  10184. }
  10185. ]
  10186. },
  10187. {
  10188. "name": "DataOutput",
  10189. "superClass": [
  10190. "ItemAwareElement"
  10191. ],
  10192. "properties": [
  10193. {
  10194. "name": "name",
  10195. "isAttr": true,
  10196. "type": "String"
  10197. },
  10198. {
  10199. "name": "isCollection",
  10200. "default": false,
  10201. "isAttr": true,
  10202. "type": "Boolean"
  10203. },
  10204. {
  10205. "name": "outputSetRefs",
  10206. "type": "OutputSet",
  10207. "isVirtual": true,
  10208. "isMany": true,
  10209. "isReference": true
  10210. },
  10211. {
  10212. "name": "outputSetWithOptional",
  10213. "type": "OutputSet",
  10214. "isVirtual": true,
  10215. "isMany": true,
  10216. "isReference": true
  10217. },
  10218. {
  10219. "name": "outputSetWithWhileExecuting",
  10220. "type": "OutputSet",
  10221. "isVirtual": true,
  10222. "isMany": true,
  10223. "isReference": true
  10224. }
  10225. ]
  10226. },
  10227. {
  10228. "name": "InputSet",
  10229. "superClass": [
  10230. "BaseElement"
  10231. ],
  10232. "properties": [
  10233. {
  10234. "name": "name",
  10235. "isAttr": true,
  10236. "type": "String"
  10237. },
  10238. {
  10239. "name": "dataInputRefs",
  10240. "type": "DataInput",
  10241. "isMany": true,
  10242. "isReference": true
  10243. },
  10244. {
  10245. "name": "optionalInputRefs",
  10246. "type": "DataInput",
  10247. "isMany": true,
  10248. "isReference": true
  10249. },
  10250. {
  10251. "name": "whileExecutingInputRefs",
  10252. "type": "DataInput",
  10253. "isMany": true,
  10254. "isReference": true
  10255. },
  10256. {
  10257. "name": "outputSetRefs",
  10258. "type": "OutputSet",
  10259. "isMany": true,
  10260. "isReference": true
  10261. }
  10262. ]
  10263. },
  10264. {
  10265. "name": "OutputSet",
  10266. "superClass": [
  10267. "BaseElement"
  10268. ],
  10269. "properties": [
  10270. {
  10271. "name": "dataOutputRefs",
  10272. "type": "DataOutput",
  10273. "isMany": true,
  10274. "isReference": true
  10275. },
  10276. {
  10277. "name": "name",
  10278. "isAttr": true,
  10279. "type": "String"
  10280. },
  10281. {
  10282. "name": "inputSetRefs",
  10283. "type": "InputSet",
  10284. "isMany": true,
  10285. "isReference": true
  10286. },
  10287. {
  10288. "name": "optionalOutputRefs",
  10289. "type": "DataOutput",
  10290. "isMany": true,
  10291. "isReference": true
  10292. },
  10293. {
  10294. "name": "whileExecutingOutputRefs",
  10295. "type": "DataOutput",
  10296. "isMany": true,
  10297. "isReference": true
  10298. }
  10299. ]
  10300. },
  10301. {
  10302. "name": "Property",
  10303. "superClass": [
  10304. "ItemAwareElement"
  10305. ],
  10306. "properties": [
  10307. {
  10308. "name": "name",
  10309. "isAttr": true,
  10310. "type": "String"
  10311. }
  10312. ]
  10313. },
  10314. {
  10315. "name": "DataInputAssociation",
  10316. "superClass": [
  10317. "DataAssociation"
  10318. ]
  10319. },
  10320. {
  10321. "name": "DataOutputAssociation",
  10322. "superClass": [
  10323. "DataAssociation"
  10324. ]
  10325. },
  10326. {
  10327. "name": "InputOutputSpecification",
  10328. "superClass": [
  10329. "BaseElement"
  10330. ],
  10331. "properties": [
  10332. {
  10333. "name": "dataInputs",
  10334. "type": "DataInput",
  10335. "isMany": true
  10336. },
  10337. {
  10338. "name": "dataOutputs",
  10339. "type": "DataOutput",
  10340. "isMany": true
  10341. },
  10342. {
  10343. "name": "inputSets",
  10344. "type": "InputSet",
  10345. "isMany": true
  10346. },
  10347. {
  10348. "name": "outputSets",
  10349. "type": "OutputSet",
  10350. "isMany": true
  10351. }
  10352. ]
  10353. },
  10354. {
  10355. "name": "DataObject",
  10356. "superClass": [
  10357. "FlowElement",
  10358. "ItemAwareElement"
  10359. ],
  10360. "properties": [
  10361. {
  10362. "name": "isCollection",
  10363. "default": false,
  10364. "isAttr": true,
  10365. "type": "Boolean"
  10366. }
  10367. ]
  10368. },
  10369. {
  10370. "name": "InputOutputBinding",
  10371. "properties": [
  10372. {
  10373. "name": "inputDataRef",
  10374. "type": "InputSet",
  10375. "isAttr": true,
  10376. "isReference": true
  10377. },
  10378. {
  10379. "name": "outputDataRef",
  10380. "type": "OutputSet",
  10381. "isAttr": true,
  10382. "isReference": true
  10383. },
  10384. {
  10385. "name": "operationRef",
  10386. "type": "Operation",
  10387. "isAttr": true,
  10388. "isReference": true
  10389. }
  10390. ]
  10391. },
  10392. {
  10393. "name": "Assignment",
  10394. "superClass": [
  10395. "BaseElement"
  10396. ],
  10397. "properties": [
  10398. {
  10399. "name": "from",
  10400. "type": "Expression",
  10401. "xml": {
  10402. "serialize": "xsi:type"
  10403. }
  10404. },
  10405. {
  10406. "name": "to",
  10407. "type": "Expression",
  10408. "xml": {
  10409. "serialize": "xsi:type"
  10410. }
  10411. }
  10412. ]
  10413. },
  10414. {
  10415. "name": "DataStore",
  10416. "superClass": [
  10417. "RootElement",
  10418. "ItemAwareElement"
  10419. ],
  10420. "properties": [
  10421. {
  10422. "name": "name",
  10423. "isAttr": true,
  10424. "type": "String"
  10425. },
  10426. {
  10427. "name": "capacity",
  10428. "isAttr": true,
  10429. "type": "Integer"
  10430. },
  10431. {
  10432. "name": "isUnlimited",
  10433. "default": true,
  10434. "isAttr": true,
  10435. "type": "Boolean"
  10436. }
  10437. ]
  10438. },
  10439. {
  10440. "name": "DataStoreReference",
  10441. "superClass": [
  10442. "ItemAwareElement",
  10443. "FlowElement"
  10444. ],
  10445. "properties": [
  10446. {
  10447. "name": "dataStoreRef",
  10448. "type": "DataStore",
  10449. "isAttr": true,
  10450. "isReference": true
  10451. }
  10452. ]
  10453. },
  10454. {
  10455. "name": "DataObjectReference",
  10456. "superClass": [
  10457. "ItemAwareElement",
  10458. "FlowElement"
  10459. ],
  10460. "properties": [
  10461. {
  10462. "name": "dataObjectRef",
  10463. "type": "DataObject",
  10464. "isAttr": true,
  10465. "isReference": true
  10466. }
  10467. ]
  10468. },
  10469. {
  10470. "name": "ConversationLink",
  10471. "superClass": [
  10472. "BaseElement"
  10473. ],
  10474. "properties": [
  10475. {
  10476. "name": "sourceRef",
  10477. "type": "InteractionNode",
  10478. "isAttr": true,
  10479. "isReference": true
  10480. },
  10481. {
  10482. "name": "targetRef",
  10483. "type": "InteractionNode",
  10484. "isAttr": true,
  10485. "isReference": true
  10486. },
  10487. {
  10488. "name": "name",
  10489. "isAttr": true,
  10490. "type": "String"
  10491. }
  10492. ]
  10493. },
  10494. {
  10495. "name": "ConversationAssociation",
  10496. "superClass": [
  10497. "BaseElement"
  10498. ],
  10499. "properties": [
  10500. {
  10501. "name": "innerConversationNodeRef",
  10502. "type": "ConversationNode",
  10503. "isAttr": true,
  10504. "isReference": true
  10505. },
  10506. {
  10507. "name": "outerConversationNodeRef",
  10508. "type": "ConversationNode",
  10509. "isAttr": true,
  10510. "isReference": true
  10511. }
  10512. ]
  10513. },
  10514. {
  10515. "name": "CallConversation",
  10516. "superClass": [
  10517. "ConversationNode"
  10518. ],
  10519. "properties": [
  10520. {
  10521. "name": "calledCollaborationRef",
  10522. "type": "Collaboration",
  10523. "isAttr": true,
  10524. "isReference": true
  10525. },
  10526. {
  10527. "name": "participantAssociations",
  10528. "type": "ParticipantAssociation",
  10529. "isMany": true
  10530. }
  10531. ]
  10532. },
  10533. {
  10534. "name": "Conversation",
  10535. "superClass": [
  10536. "ConversationNode"
  10537. ]
  10538. },
  10539. {
  10540. "name": "SubConversation",
  10541. "superClass": [
  10542. "ConversationNode"
  10543. ],
  10544. "properties": [
  10545. {
  10546. "name": "conversationNodes",
  10547. "type": "ConversationNode",
  10548. "isMany": true
  10549. }
  10550. ]
  10551. },
  10552. {
  10553. "name": "ConversationNode",
  10554. "isAbstract": true,
  10555. "superClass": [
  10556. "InteractionNode",
  10557. "BaseElement"
  10558. ],
  10559. "properties": [
  10560. {
  10561. "name": "name",
  10562. "isAttr": true,
  10563. "type": "String"
  10564. },
  10565. {
  10566. "name": "participantRefs",
  10567. "type": "Participant",
  10568. "isMany": true,
  10569. "isReference": true
  10570. },
  10571. {
  10572. "name": "messageFlowRefs",
  10573. "type": "MessageFlow",
  10574. "isMany": true,
  10575. "isReference": true
  10576. },
  10577. {
  10578. "name": "correlationKeys",
  10579. "type": "CorrelationKey",
  10580. "isMany": true
  10581. }
  10582. ]
  10583. },
  10584. {
  10585. "name": "GlobalConversation",
  10586. "superClass": [
  10587. "Collaboration"
  10588. ]
  10589. },
  10590. {
  10591. "name": "PartnerEntity",
  10592. "superClass": [
  10593. "RootElement"
  10594. ],
  10595. "properties": [
  10596. {
  10597. "name": "name",
  10598. "isAttr": true,
  10599. "type": "String"
  10600. },
  10601. {
  10602. "name": "participantRef",
  10603. "type": "Participant",
  10604. "isMany": true,
  10605. "isReference": true
  10606. }
  10607. ]
  10608. },
  10609. {
  10610. "name": "PartnerRole",
  10611. "superClass": [
  10612. "RootElement"
  10613. ],
  10614. "properties": [
  10615. {
  10616. "name": "name",
  10617. "isAttr": true,
  10618. "type": "String"
  10619. },
  10620. {
  10621. "name": "participantRef",
  10622. "type": "Participant",
  10623. "isMany": true,
  10624. "isReference": true
  10625. }
  10626. ]
  10627. },
  10628. {
  10629. "name": "CorrelationProperty",
  10630. "superClass": [
  10631. "RootElement"
  10632. ],
  10633. "properties": [
  10634. {
  10635. "name": "correlationPropertyRetrievalExpression",
  10636. "type": "CorrelationPropertyRetrievalExpression",
  10637. "isMany": true
  10638. },
  10639. {
  10640. "name": "name",
  10641. "isAttr": true,
  10642. "type": "String"
  10643. },
  10644. {
  10645. "name": "type",
  10646. "type": "ItemDefinition",
  10647. "isAttr": true,
  10648. "isReference": true
  10649. }
  10650. ]
  10651. },
  10652. {
  10653. "name": "Error",
  10654. "superClass": [
  10655. "RootElement"
  10656. ],
  10657. "properties": [
  10658. {
  10659. "name": "structureRef",
  10660. "type": "ItemDefinition",
  10661. "isAttr": true,
  10662. "isReference": true
  10663. },
  10664. {
  10665. "name": "name",
  10666. "isAttr": true,
  10667. "type": "String"
  10668. },
  10669. {
  10670. "name": "errorCode",
  10671. "isAttr": true,
  10672. "type": "String"
  10673. }
  10674. ]
  10675. },
  10676. {
  10677. "name": "CorrelationKey",
  10678. "superClass": [
  10679. "BaseElement"
  10680. ],
  10681. "properties": [
  10682. {
  10683. "name": "correlationPropertyRef",
  10684. "type": "CorrelationProperty",
  10685. "isMany": true,
  10686. "isReference": true
  10687. },
  10688. {
  10689. "name": "name",
  10690. "isAttr": true,
  10691. "type": "String"
  10692. }
  10693. ]
  10694. },
  10695. {
  10696. "name": "Expression",
  10697. "superClass": [
  10698. "BaseElement"
  10699. ],
  10700. "isAbstract": true
  10701. },
  10702. {
  10703. "name": "FormalExpression",
  10704. "superClass": [
  10705. "Expression"
  10706. ],
  10707. "properties": [
  10708. {
  10709. "name": "language",
  10710. "isAttr": true,
  10711. "type": "String"
  10712. },
  10713. {
  10714. "name": "body",
  10715. "type": "String",
  10716. "isBody": true
  10717. },
  10718. {
  10719. "name": "evaluatesToTypeRef",
  10720. "type": "ItemDefinition",
  10721. "isAttr": true,
  10722. "isReference": true
  10723. }
  10724. ]
  10725. },
  10726. {
  10727. "name": "Message",
  10728. "superClass": [
  10729. "RootElement"
  10730. ],
  10731. "properties": [
  10732. {
  10733. "name": "name",
  10734. "isAttr": true,
  10735. "type": "String"
  10736. },
  10737. {
  10738. "name": "itemRef",
  10739. "type": "ItemDefinition",
  10740. "isAttr": true,
  10741. "isReference": true
  10742. }
  10743. ]
  10744. },
  10745. {
  10746. "name": "ItemDefinition",
  10747. "superClass": [
  10748. "RootElement"
  10749. ],
  10750. "properties": [
  10751. {
  10752. "name": "itemKind",
  10753. "type": "ItemKind",
  10754. "isAttr": true
  10755. },
  10756. {
  10757. "name": "structureRef",
  10758. "type": "String",
  10759. "isAttr": true
  10760. },
  10761. {
  10762. "name": "isCollection",
  10763. "default": false,
  10764. "isAttr": true,
  10765. "type": "Boolean"
  10766. },
  10767. {
  10768. "name": "import",
  10769. "type": "Import",
  10770. "isAttr": true,
  10771. "isReference": true
  10772. }
  10773. ]
  10774. },
  10775. {
  10776. "name": "FlowElement",
  10777. "isAbstract": true,
  10778. "superClass": [
  10779. "BaseElement"
  10780. ],
  10781. "properties": [
  10782. {
  10783. "name": "name",
  10784. "isAttr": true,
  10785. "type": "String"
  10786. },
  10787. {
  10788. "name": "auditing",
  10789. "type": "Auditing"
  10790. },
  10791. {
  10792. "name": "monitoring",
  10793. "type": "Monitoring"
  10794. },
  10795. {
  10796. "name": "categoryValueRef",
  10797. "type": "CategoryValue",
  10798. "isMany": true,
  10799. "isReference": true
  10800. }
  10801. ]
  10802. },
  10803. {
  10804. "name": "SequenceFlow",
  10805. "superClass": [
  10806. "FlowElement"
  10807. ],
  10808. "properties": [
  10809. {
  10810. "name": "isImmediate",
  10811. "isAttr": true,
  10812. "type": "Boolean"
  10813. },
  10814. {
  10815. "name": "conditionExpression",
  10816. "type": "Expression",
  10817. "xml": {
  10818. "serialize": "xsi:type"
  10819. }
  10820. },
  10821. {
  10822. "name": "sourceRef",
  10823. "type": "FlowNode",
  10824. "isAttr": true,
  10825. "isReference": true
  10826. },
  10827. {
  10828. "name": "targetRef",
  10829. "type": "FlowNode",
  10830. "isAttr": true,
  10831. "isReference": true
  10832. }
  10833. ]
  10834. },
  10835. {
  10836. "name": "FlowElementsContainer",
  10837. "isAbstract": true,
  10838. "superClass": [
  10839. "BaseElement"
  10840. ],
  10841. "properties": [
  10842. {
  10843. "name": "laneSets",
  10844. "type": "LaneSet",
  10845. "isMany": true
  10846. },
  10847. {
  10848. "name": "flowElements",
  10849. "type": "FlowElement",
  10850. "isMany": true
  10851. }
  10852. ]
  10853. },
  10854. {
  10855. "name": "CallableElement",
  10856. "isAbstract": true,
  10857. "superClass": [
  10858. "RootElement"
  10859. ],
  10860. "properties": [
  10861. {
  10862. "name": "name",
  10863. "isAttr": true,
  10864. "type": "String"
  10865. },
  10866. {
  10867. "name": "ioSpecification",
  10868. "type": "InputOutputSpecification",
  10869. "xml": {
  10870. "serialize": "property"
  10871. }
  10872. },
  10873. {
  10874. "name": "supportedInterfaceRefs",
  10875. "type": "Interface",
  10876. "isMany": true,
  10877. "isReference": true
  10878. },
  10879. {
  10880. "name": "ioBinding",
  10881. "type": "InputOutputBinding",
  10882. "isMany": true,
  10883. "xml": {
  10884. "serialize": "property"
  10885. }
  10886. }
  10887. ]
  10888. },
  10889. {
  10890. "name": "FlowNode",
  10891. "isAbstract": true,
  10892. "superClass": [
  10893. "FlowElement"
  10894. ],
  10895. "properties": [
  10896. {
  10897. "name": "incoming",
  10898. "type": "SequenceFlow",
  10899. "isMany": true,
  10900. "isReference": true
  10901. },
  10902. {
  10903. "name": "outgoing",
  10904. "type": "SequenceFlow",
  10905. "isMany": true,
  10906. "isReference": true
  10907. },
  10908. {
  10909. "name": "lanes",
  10910. "type": "Lane",
  10911. "isVirtual": true,
  10912. "isMany": true,
  10913. "isReference": true
  10914. }
  10915. ]
  10916. },
  10917. {
  10918. "name": "CorrelationPropertyRetrievalExpression",
  10919. "superClass": [
  10920. "BaseElement"
  10921. ],
  10922. "properties": [
  10923. {
  10924. "name": "messagePath",
  10925. "type": "FormalExpression"
  10926. },
  10927. {
  10928. "name": "messageRef",
  10929. "type": "Message",
  10930. "isAttr": true,
  10931. "isReference": true
  10932. }
  10933. ]
  10934. },
  10935. {
  10936. "name": "CorrelationPropertyBinding",
  10937. "superClass": [
  10938. "BaseElement"
  10939. ],
  10940. "properties": [
  10941. {
  10942. "name": "dataPath",
  10943. "type": "FormalExpression"
  10944. },
  10945. {
  10946. "name": "correlationPropertyRef",
  10947. "type": "CorrelationProperty",
  10948. "isAttr": true,
  10949. "isReference": true
  10950. }
  10951. ]
  10952. },
  10953. {
  10954. "name": "Resource",
  10955. "superClass": [
  10956. "RootElement"
  10957. ],
  10958. "properties": [
  10959. {
  10960. "name": "name",
  10961. "isAttr": true,
  10962. "type": "String"
  10963. },
  10964. {
  10965. "name": "resourceParameters",
  10966. "type": "ResourceParameter",
  10967. "isMany": true
  10968. }
  10969. ]
  10970. },
  10971. {
  10972. "name": "ResourceParameter",
  10973. "superClass": [
  10974. "BaseElement"
  10975. ],
  10976. "properties": [
  10977. {
  10978. "name": "name",
  10979. "isAttr": true,
  10980. "type": "String"
  10981. },
  10982. {
  10983. "name": "isRequired",
  10984. "isAttr": true,
  10985. "type": "Boolean"
  10986. },
  10987. {
  10988. "name": "type",
  10989. "type": "ItemDefinition",
  10990. "isAttr": true,
  10991. "isReference": true
  10992. }
  10993. ]
  10994. },
  10995. {
  10996. "name": "CorrelationSubscription",
  10997. "superClass": [
  10998. "BaseElement"
  10999. ],
  11000. "properties": [
  11001. {
  11002. "name": "correlationKeyRef",
  11003. "type": "CorrelationKey",
  11004. "isAttr": true,
  11005. "isReference": true
  11006. },
  11007. {
  11008. "name": "correlationPropertyBinding",
  11009. "type": "CorrelationPropertyBinding",
  11010. "isMany": true
  11011. }
  11012. ]
  11013. },
  11014. {
  11015. "name": "MessageFlow",
  11016. "superClass": [
  11017. "BaseElement"
  11018. ],
  11019. "properties": [
  11020. {
  11021. "name": "name",
  11022. "isAttr": true,
  11023. "type": "String"
  11024. },
  11025. {
  11026. "name": "sourceRef",
  11027. "type": "InteractionNode",
  11028. "isAttr": true,
  11029. "isReference": true
  11030. },
  11031. {
  11032. "name": "targetRef",
  11033. "type": "InteractionNode",
  11034. "isAttr": true,
  11035. "isReference": true
  11036. },
  11037. {
  11038. "name": "messageRef",
  11039. "type": "Message",
  11040. "isAttr": true,
  11041. "isReference": true
  11042. }
  11043. ]
  11044. },
  11045. {
  11046. "name": "MessageFlowAssociation",
  11047. "superClass": [
  11048. "BaseElement"
  11049. ],
  11050. "properties": [
  11051. {
  11052. "name": "innerMessageFlowRef",
  11053. "type": "MessageFlow",
  11054. "isAttr": true,
  11055. "isReference": true
  11056. },
  11057. {
  11058. "name": "outerMessageFlowRef",
  11059. "type": "MessageFlow",
  11060. "isAttr": true,
  11061. "isReference": true
  11062. }
  11063. ]
  11064. },
  11065. {
  11066. "name": "InteractionNode",
  11067. "isAbstract": true,
  11068. "properties": [
  11069. {
  11070. "name": "incomingConversationLinks",
  11071. "type": "ConversationLink",
  11072. "isVirtual": true,
  11073. "isMany": true,
  11074. "isReference": true
  11075. },
  11076. {
  11077. "name": "outgoingConversationLinks",
  11078. "type": "ConversationLink",
  11079. "isVirtual": true,
  11080. "isMany": true,
  11081. "isReference": true
  11082. }
  11083. ]
  11084. },
  11085. {
  11086. "name": "Participant",
  11087. "superClass": [
  11088. "InteractionNode",
  11089. "BaseElement"
  11090. ],
  11091. "properties": [
  11092. {
  11093. "name": "name",
  11094. "isAttr": true,
  11095. "type": "String"
  11096. },
  11097. {
  11098. "name": "interfaceRefs",
  11099. "type": "Interface",
  11100. "isMany": true,
  11101. "isReference": true
  11102. },
  11103. {
  11104. "name": "participantMultiplicity",
  11105. "type": "ParticipantMultiplicity"
  11106. },
  11107. {
  11108. "name": "endPointRefs",
  11109. "type": "EndPoint",
  11110. "isMany": true,
  11111. "isReference": true
  11112. },
  11113. {
  11114. "name": "processRef",
  11115. "type": "Process",
  11116. "isAttr": true,
  11117. "isReference": true
  11118. }
  11119. ]
  11120. },
  11121. {
  11122. "name": "ParticipantAssociation",
  11123. "superClass": [
  11124. "BaseElement"
  11125. ],
  11126. "properties": [
  11127. {
  11128. "name": "innerParticipantRef",
  11129. "type": "Participant",
  11130. "isAttr": true,
  11131. "isReference": true
  11132. },
  11133. {
  11134. "name": "outerParticipantRef",
  11135. "type": "Participant",
  11136. "isAttr": true,
  11137. "isReference": true
  11138. }
  11139. ]
  11140. },
  11141. {
  11142. "name": "ParticipantMultiplicity",
  11143. "properties": [
  11144. {
  11145. "name": "minimum",
  11146. "default": 0,
  11147. "isAttr": true,
  11148. "type": "Integer"
  11149. },
  11150. {
  11151. "name": "maximum",
  11152. "default": 1,
  11153. "isAttr": true,
  11154. "type": "Integer"
  11155. }
  11156. ]
  11157. },
  11158. {
  11159. "name": "Collaboration",
  11160. "superClass": [
  11161. "RootElement"
  11162. ],
  11163. "properties": [
  11164. {
  11165. "name": "name",
  11166. "isAttr": true,
  11167. "type": "String"
  11168. },
  11169. {
  11170. "name": "isClosed",
  11171. "isAttr": true,
  11172. "type": "Boolean"
  11173. },
  11174. {
  11175. "name": "choreographyRef",
  11176. "type": "Choreography",
  11177. "isMany": true,
  11178. "isReference": true
  11179. },
  11180. {
  11181. "name": "artifacts",
  11182. "type": "Artifact",
  11183. "isMany": true
  11184. },
  11185. {
  11186. "name": "participantAssociations",
  11187. "type": "ParticipantAssociation",
  11188. "isMany": true
  11189. },
  11190. {
  11191. "name": "messageFlowAssociations",
  11192. "type": "MessageFlowAssociation",
  11193. "isMany": true
  11194. },
  11195. {
  11196. "name": "conversationAssociations",
  11197. "type": "ConversationAssociation"
  11198. },
  11199. {
  11200. "name": "participants",
  11201. "type": "Participant",
  11202. "isMany": true
  11203. },
  11204. {
  11205. "name": "messageFlows",
  11206. "type": "MessageFlow",
  11207. "isMany": true
  11208. },
  11209. {
  11210. "name": "correlationKeys",
  11211. "type": "CorrelationKey",
  11212. "isMany": true
  11213. },
  11214. {
  11215. "name": "conversations",
  11216. "type": "ConversationNode",
  11217. "isMany": true
  11218. },
  11219. {
  11220. "name": "conversationLinks",
  11221. "type": "ConversationLink",
  11222. "isMany": true
  11223. }
  11224. ]
  11225. },
  11226. {
  11227. "name": "ChoreographyActivity",
  11228. "isAbstract": true,
  11229. "superClass": [
  11230. "FlowNode"
  11231. ],
  11232. "properties": [
  11233. {
  11234. "name": "participantRefs",
  11235. "type": "Participant",
  11236. "isMany": true,
  11237. "isReference": true
  11238. },
  11239. {
  11240. "name": "initiatingParticipantRef",
  11241. "type": "Participant",
  11242. "isAttr": true,
  11243. "isReference": true
  11244. },
  11245. {
  11246. "name": "correlationKeys",
  11247. "type": "CorrelationKey",
  11248. "isMany": true
  11249. },
  11250. {
  11251. "name": "loopType",
  11252. "type": "ChoreographyLoopType",
  11253. "default": "None",
  11254. "isAttr": true
  11255. }
  11256. ]
  11257. },
  11258. {
  11259. "name": "CallChoreography",
  11260. "superClass": [
  11261. "ChoreographyActivity"
  11262. ],
  11263. "properties": [
  11264. {
  11265. "name": "calledChoreographyRef",
  11266. "type": "Choreography",
  11267. "isAttr": true,
  11268. "isReference": true
  11269. },
  11270. {
  11271. "name": "participantAssociations",
  11272. "type": "ParticipantAssociation",
  11273. "isMany": true
  11274. }
  11275. ]
  11276. },
  11277. {
  11278. "name": "SubChoreography",
  11279. "superClass": [
  11280. "ChoreographyActivity",
  11281. "FlowElementsContainer"
  11282. ],
  11283. "properties": [
  11284. {
  11285. "name": "artifacts",
  11286. "type": "Artifact",
  11287. "isMany": true
  11288. }
  11289. ]
  11290. },
  11291. {
  11292. "name": "ChoreographyTask",
  11293. "superClass": [
  11294. "ChoreographyActivity"
  11295. ],
  11296. "properties": [
  11297. {
  11298. "name": "messageFlowRef",
  11299. "type": "MessageFlow",
  11300. "isMany": true,
  11301. "isReference": true
  11302. }
  11303. ]
  11304. },
  11305. {
  11306. "name": "Choreography",
  11307. "superClass": [
  11308. "FlowElementsContainer",
  11309. "Collaboration"
  11310. ]
  11311. },
  11312. {
  11313. "name": "GlobalChoreographyTask",
  11314. "superClass": [
  11315. "Choreography"
  11316. ],
  11317. "properties": [
  11318. {
  11319. "name": "initiatingParticipantRef",
  11320. "type": "Participant",
  11321. "isAttr": true,
  11322. "isReference": true
  11323. }
  11324. ]
  11325. },
  11326. {
  11327. "name": "TextAnnotation",
  11328. "superClass": [
  11329. "Artifact"
  11330. ],
  11331. "properties": [
  11332. {
  11333. "name": "text",
  11334. "type": "String"
  11335. },
  11336. {
  11337. "name": "textFormat",
  11338. "default": "text/plain",
  11339. "isAttr": true,
  11340. "type": "String"
  11341. }
  11342. ]
  11343. },
  11344. {
  11345. "name": "Group",
  11346. "superClass": [
  11347. "Artifact"
  11348. ],
  11349. "properties": [
  11350. {
  11351. "name": "categoryValueRef",
  11352. "type": "CategoryValue",
  11353. "isAttr": true,
  11354. "isReference": true
  11355. }
  11356. ]
  11357. },
  11358. {
  11359. "name": "Association",
  11360. "superClass": [
  11361. "Artifact"
  11362. ],
  11363. "properties": [
  11364. {
  11365. "name": "associationDirection",
  11366. "type": "AssociationDirection",
  11367. "isAttr": true
  11368. },
  11369. {
  11370. "name": "sourceRef",
  11371. "type": "BaseElement",
  11372. "isAttr": true,
  11373. "isReference": true
  11374. },
  11375. {
  11376. "name": "targetRef",
  11377. "type": "BaseElement",
  11378. "isAttr": true,
  11379. "isReference": true
  11380. }
  11381. ]
  11382. },
  11383. {
  11384. "name": "Category",
  11385. "superClass": [
  11386. "RootElement"
  11387. ],
  11388. "properties": [
  11389. {
  11390. "name": "categoryValue",
  11391. "type": "CategoryValue",
  11392. "isMany": true
  11393. },
  11394. {
  11395. "name": "name",
  11396. "isAttr": true,
  11397. "type": "String"
  11398. }
  11399. ]
  11400. },
  11401. {
  11402. "name": "Artifact",
  11403. "isAbstract": true,
  11404. "superClass": [
  11405. "BaseElement"
  11406. ]
  11407. },
  11408. {
  11409. "name": "CategoryValue",
  11410. "superClass": [
  11411. "BaseElement"
  11412. ],
  11413. "properties": [
  11414. {
  11415. "name": "categorizedFlowElements",
  11416. "type": "FlowElement",
  11417. "isVirtual": true,
  11418. "isMany": true,
  11419. "isReference": true
  11420. },
  11421. {
  11422. "name": "value",
  11423. "isAttr": true,
  11424. "type": "String"
  11425. }
  11426. ]
  11427. },
  11428. {
  11429. "name": "Activity",
  11430. "isAbstract": true,
  11431. "superClass": [
  11432. "FlowNode"
  11433. ],
  11434. "properties": [
  11435. {
  11436. "name": "isForCompensation",
  11437. "default": false,
  11438. "isAttr": true,
  11439. "type": "Boolean"
  11440. },
  11441. {
  11442. "name": "default",
  11443. "type": "SequenceFlow",
  11444. "isAttr": true,
  11445. "isReference": true
  11446. },
  11447. {
  11448. "name": "ioSpecification",
  11449. "type": "InputOutputSpecification",
  11450. "xml": {
  11451. "serialize": "property"
  11452. }
  11453. },
  11454. {
  11455. "name": "boundaryEventRefs",
  11456. "type": "BoundaryEvent",
  11457. "isMany": true,
  11458. "isReference": true
  11459. },
  11460. {
  11461. "name": "properties",
  11462. "type": "Property",
  11463. "isMany": true
  11464. },
  11465. {
  11466. "name": "dataInputAssociations",
  11467. "type": "DataInputAssociation",
  11468. "isMany": true
  11469. },
  11470. {
  11471. "name": "dataOutputAssociations",
  11472. "type": "DataOutputAssociation",
  11473. "isMany": true
  11474. },
  11475. {
  11476. "name": "startQuantity",
  11477. "default": 1,
  11478. "isAttr": true,
  11479. "type": "Integer"
  11480. },
  11481. {
  11482. "name": "resources",
  11483. "type": "ResourceRole",
  11484. "isMany": true
  11485. },
  11486. {
  11487. "name": "completionQuantity",
  11488. "default": 1,
  11489. "isAttr": true,
  11490. "type": "Integer"
  11491. },
  11492. {
  11493. "name": "loopCharacteristics",
  11494. "type": "LoopCharacteristics"
  11495. }
  11496. ]
  11497. },
  11498. {
  11499. "name": "ServiceTask",
  11500. "superClass": [
  11501. "Task"
  11502. ],
  11503. "properties": [
  11504. {
  11505. "name": "implementation",
  11506. "isAttr": true,
  11507. "type": "String"
  11508. },
  11509. {
  11510. "name": "operationRef",
  11511. "type": "Operation",
  11512. "isAttr": true,
  11513. "isReference": true
  11514. }
  11515. ]
  11516. },
  11517. {
  11518. "name": "SubProcess",
  11519. "superClass": [
  11520. "Activity",
  11521. "FlowElementsContainer",
  11522. "InteractionNode"
  11523. ],
  11524. "properties": [
  11525. {
  11526. "name": "triggeredByEvent",
  11527. "default": false,
  11528. "isAttr": true,
  11529. "type": "Boolean"
  11530. },
  11531. {
  11532. "name": "artifacts",
  11533. "type": "Artifact",
  11534. "isMany": true
  11535. }
  11536. ]
  11537. },
  11538. {
  11539. "name": "LoopCharacteristics",
  11540. "isAbstract": true,
  11541. "superClass": [
  11542. "BaseElement"
  11543. ]
  11544. },
  11545. {
  11546. "name": "MultiInstanceLoopCharacteristics",
  11547. "superClass": [
  11548. "LoopCharacteristics"
  11549. ],
  11550. "properties": [
  11551. {
  11552. "name": "isSequential",
  11553. "default": false,
  11554. "isAttr": true,
  11555. "type": "Boolean"
  11556. },
  11557. {
  11558. "name": "behavior",
  11559. "type": "MultiInstanceBehavior",
  11560. "default": "All",
  11561. "isAttr": true
  11562. },
  11563. {
  11564. "name": "loopCardinality",
  11565. "type": "Expression",
  11566. "xml": {
  11567. "serialize": "xsi:type"
  11568. }
  11569. },
  11570. {
  11571. "name": "loopDataInputRef",
  11572. "type": "ItemAwareElement",
  11573. "isAttr": true,
  11574. "isReference": true
  11575. },
  11576. {
  11577. "name": "loopDataOutputRef",
  11578. "type": "ItemAwareElement",
  11579. "isAttr": true,
  11580. "isReference": true
  11581. },
  11582. {
  11583. "name": "inputDataItem",
  11584. "type": "DataInput"
  11585. },
  11586. {
  11587. "name": "outputDataItem",
  11588. "type": "DataOutput"
  11589. },
  11590. {
  11591. "name": "completionCondition",
  11592. "type": "Expression",
  11593. "xml": {
  11594. "serialize": "xsi:type"
  11595. }
  11596. },
  11597. {
  11598. "name": "complexBehaviorDefinition",
  11599. "type": "ComplexBehaviorDefinition",
  11600. "isMany": true
  11601. },
  11602. {
  11603. "name": "oneBehaviorEventRef",
  11604. "type": "EventDefinition",
  11605. "isAttr": true,
  11606. "isReference": true
  11607. },
  11608. {
  11609. "name": "noneBehaviorEventRef",
  11610. "type": "EventDefinition",
  11611. "isAttr": true,
  11612. "isReference": true
  11613. }
  11614. ]
  11615. },
  11616. {
  11617. "name": "StandardLoopCharacteristics",
  11618. "superClass": [
  11619. "LoopCharacteristics"
  11620. ],
  11621. "properties": [
  11622. {
  11623. "name": "testBefore",
  11624. "default": false,
  11625. "isAttr": true,
  11626. "type": "Boolean"
  11627. },
  11628. {
  11629. "name": "loopCondition",
  11630. "type": "Expression",
  11631. "xml": {
  11632. "serialize": "xsi:type"
  11633. }
  11634. },
  11635. {
  11636. "name": "loopMaximum",
  11637. "type": "Expression",
  11638. "xml": {
  11639. "serialize": "xsi:type"
  11640. }
  11641. }
  11642. ]
  11643. },
  11644. {
  11645. "name": "CallActivity",
  11646. "superClass": [
  11647. "Activity"
  11648. ],
  11649. "properties": [
  11650. {
  11651. "name": "calledElement",
  11652. "type": "String",
  11653. "isAttr": true
  11654. }
  11655. ]
  11656. },
  11657. {
  11658. "name": "Task",
  11659. "superClass": [
  11660. "Activity",
  11661. "InteractionNode"
  11662. ]
  11663. },
  11664. {
  11665. "name": "SendTask",
  11666. "superClass": [
  11667. "Task"
  11668. ],
  11669. "properties": [
  11670. {
  11671. "name": "implementation",
  11672. "isAttr": true,
  11673. "type": "String"
  11674. },
  11675. {
  11676. "name": "operationRef",
  11677. "type": "Operation",
  11678. "isAttr": true,
  11679. "isReference": true
  11680. },
  11681. {
  11682. "name": "messageRef",
  11683. "type": "Message",
  11684. "isAttr": true,
  11685. "isReference": true
  11686. }
  11687. ]
  11688. },
  11689. {
  11690. "name": "ReceiveTask",
  11691. "superClass": [
  11692. "Task"
  11693. ],
  11694. "properties": [
  11695. {
  11696. "name": "implementation",
  11697. "isAttr": true,
  11698. "type": "String"
  11699. },
  11700. {
  11701. "name": "instantiate",
  11702. "default": false,
  11703. "isAttr": true,
  11704. "type": "Boolean"
  11705. },
  11706. {
  11707. "name": "operationRef",
  11708. "type": "Operation",
  11709. "isAttr": true,
  11710. "isReference": true
  11711. },
  11712. {
  11713. "name": "messageRef",
  11714. "type": "Message",
  11715. "isAttr": true,
  11716. "isReference": true
  11717. }
  11718. ]
  11719. },
  11720. {
  11721. "name": "ScriptTask",
  11722. "superClass": [
  11723. "Task"
  11724. ],
  11725. "properties": [
  11726. {
  11727. "name": "scriptFormat",
  11728. "isAttr": true,
  11729. "type": "String"
  11730. },
  11731. {
  11732. "name": "script",
  11733. "type": "String"
  11734. }
  11735. ]
  11736. },
  11737. {
  11738. "name": "BusinessRuleTask",
  11739. "superClass": [
  11740. "Task"
  11741. ],
  11742. "properties": [
  11743. {
  11744. "name": "implementation",
  11745. "isAttr": true,
  11746. "type": "String"
  11747. }
  11748. ]
  11749. },
  11750. {
  11751. "name": "AdHocSubProcess",
  11752. "superClass": [
  11753. "SubProcess"
  11754. ],
  11755. "properties": [
  11756. {
  11757. "name": "completionCondition",
  11758. "type": "Expression",
  11759. "xml": {
  11760. "serialize": "xsi:type"
  11761. }
  11762. },
  11763. {
  11764. "name": "ordering",
  11765. "type": "AdHocOrdering",
  11766. "isAttr": true
  11767. },
  11768. {
  11769. "name": "cancelRemainingInstances",
  11770. "default": true,
  11771. "isAttr": true,
  11772. "type": "Boolean"
  11773. }
  11774. ]
  11775. },
  11776. {
  11777. "name": "Transaction",
  11778. "superClass": [
  11779. "SubProcess"
  11780. ],
  11781. "properties": [
  11782. {
  11783. "name": "protocol",
  11784. "isAttr": true,
  11785. "type": "String"
  11786. },
  11787. {
  11788. "name": "method",
  11789. "isAttr": true,
  11790. "type": "String"
  11791. }
  11792. ]
  11793. },
  11794. {
  11795. "name": "GlobalScriptTask",
  11796. "superClass": [
  11797. "GlobalTask"
  11798. ],
  11799. "properties": [
  11800. {
  11801. "name": "scriptLanguage",
  11802. "isAttr": true,
  11803. "type": "String"
  11804. },
  11805. {
  11806. "name": "script",
  11807. "isAttr": true,
  11808. "type": "String"
  11809. }
  11810. ]
  11811. },
  11812. {
  11813. "name": "GlobalBusinessRuleTask",
  11814. "superClass": [
  11815. "GlobalTask"
  11816. ],
  11817. "properties": [
  11818. {
  11819. "name": "implementation",
  11820. "isAttr": true,
  11821. "type": "String"
  11822. }
  11823. ]
  11824. },
  11825. {
  11826. "name": "ComplexBehaviorDefinition",
  11827. "superClass": [
  11828. "BaseElement"
  11829. ],
  11830. "properties": [
  11831. {
  11832. "name": "condition",
  11833. "type": "FormalExpression"
  11834. },
  11835. {
  11836. "name": "event",
  11837. "type": "ImplicitThrowEvent"
  11838. }
  11839. ]
  11840. },
  11841. {
  11842. "name": "ResourceRole",
  11843. "superClass": [
  11844. "BaseElement"
  11845. ],
  11846. "properties": [
  11847. {
  11848. "name": "resourceRef",
  11849. "type": "Resource",
  11850. "isReference": true
  11851. },
  11852. {
  11853. "name": "resourceParameterBindings",
  11854. "type": "ResourceParameterBinding",
  11855. "isMany": true
  11856. },
  11857. {
  11858. "name": "resourceAssignmentExpression",
  11859. "type": "ResourceAssignmentExpression"
  11860. },
  11861. {
  11862. "name": "name",
  11863. "isAttr": true,
  11864. "type": "String"
  11865. }
  11866. ]
  11867. },
  11868. {
  11869. "name": "ResourceParameterBinding",
  11870. "properties": [
  11871. {
  11872. "name": "expression",
  11873. "type": "Expression",
  11874. "xml": {
  11875. "serialize": "xsi:type"
  11876. }
  11877. },
  11878. {
  11879. "name": "parameterRef",
  11880. "type": "ResourceParameter",
  11881. "isAttr": true,
  11882. "isReference": true
  11883. }
  11884. ]
  11885. },
  11886. {
  11887. "name": "ResourceAssignmentExpression",
  11888. "properties": [
  11889. {
  11890. "name": "expression",
  11891. "type": "Expression",
  11892. "xml": {
  11893. "serialize": "xsi:type"
  11894. }
  11895. }
  11896. ]
  11897. },
  11898. {
  11899. "name": "Import",
  11900. "properties": [
  11901. {
  11902. "name": "importType",
  11903. "isAttr": true,
  11904. "type": "String"
  11905. },
  11906. {
  11907. "name": "location",
  11908. "isAttr": true,
  11909. "type": "String"
  11910. },
  11911. {
  11912. "name": "namespace",
  11913. "isAttr": true,
  11914. "type": "String"
  11915. }
  11916. ]
  11917. },
  11918. {
  11919. "name": "Definitions",
  11920. "superClass": [
  11921. "BaseElement"
  11922. ],
  11923. "properties": [
  11924. {
  11925. "name": "name",
  11926. "isAttr": true,
  11927. "type": "String"
  11928. },
  11929. {
  11930. "name": "targetNamespace",
  11931. "isAttr": true,
  11932. "type": "String"
  11933. },
  11934. {
  11935. "name": "expressionLanguage",
  11936. "default": "http://www.w3.org/1999/XPath",
  11937. "isAttr": true,
  11938. "type": "String"
  11939. },
  11940. {
  11941. "name": "typeLanguage",
  11942. "default": "http://www.w3.org/2001/XMLSchema",
  11943. "isAttr": true,
  11944. "type": "String"
  11945. },
  11946. {
  11947. "name": "imports",
  11948. "type": "Import",
  11949. "isMany": true
  11950. },
  11951. {
  11952. "name": "extensions",
  11953. "type": "Extension",
  11954. "isMany": true
  11955. },
  11956. {
  11957. "name": "rootElements",
  11958. "type": "RootElement",
  11959. "isMany": true
  11960. },
  11961. {
  11962. "name": "diagrams",
  11963. "isMany": true,
  11964. "type": "bpmndi:BPMNDiagram"
  11965. },
  11966. {
  11967. "name": "exporter",
  11968. "isAttr": true,
  11969. "type": "String"
  11970. },
  11971. {
  11972. "name": "relationships",
  11973. "type": "Relationship",
  11974. "isMany": true
  11975. },
  11976. {
  11977. "name": "exporterVersion",
  11978. "isAttr": true,
  11979. "type": "String"
  11980. }
  11981. ]
  11982. }
  11983. ],
  11984. "emumerations": [
  11985. {
  11986. "name": "ProcessType",
  11987. "literalValues": [
  11988. {
  11989. "name": "None"
  11990. },
  11991. {
  11992. "name": "Public"
  11993. },
  11994. {
  11995. "name": "Private"
  11996. }
  11997. ]
  11998. },
  11999. {
  12000. "name": "GatewayDirection",
  12001. "literalValues": [
  12002. {
  12003. "name": "Unspecified"
  12004. },
  12005. {
  12006. "name": "Converging"
  12007. },
  12008. {
  12009. "name": "Diverging"
  12010. },
  12011. {
  12012. "name": "Mixed"
  12013. }
  12014. ]
  12015. },
  12016. {
  12017. "name": "EventBasedGatewayType",
  12018. "literalValues": [
  12019. {
  12020. "name": "Parallel"
  12021. },
  12022. {
  12023. "name": "Exclusive"
  12024. }
  12025. ]
  12026. },
  12027. {
  12028. "name": "RelationshipDirection",
  12029. "literalValues": [
  12030. {
  12031. "name": "None"
  12032. },
  12033. {
  12034. "name": "Forward"
  12035. },
  12036. {
  12037. "name": "Backward"
  12038. },
  12039. {
  12040. "name": "Both"
  12041. }
  12042. ]
  12043. },
  12044. {
  12045. "name": "ItemKind",
  12046. "literalValues": [
  12047. {
  12048. "name": "Physical"
  12049. },
  12050. {
  12051. "name": "Information"
  12052. }
  12053. ]
  12054. },
  12055. {
  12056. "name": "ChoreographyLoopType",
  12057. "literalValues": [
  12058. {
  12059. "name": "None"
  12060. },
  12061. {
  12062. "name": "Standard"
  12063. },
  12064. {
  12065. "name": "MultiInstanceSequential"
  12066. },
  12067. {
  12068. "name": "MultiInstanceParallel"
  12069. }
  12070. ]
  12071. },
  12072. {
  12073. "name": "AssociationDirection",
  12074. "literalValues": [
  12075. {
  12076. "name": "None"
  12077. },
  12078. {
  12079. "name": "One"
  12080. },
  12081. {
  12082. "name": "Both"
  12083. }
  12084. ]
  12085. },
  12086. {
  12087. "name": "MultiInstanceBehavior",
  12088. "literalValues": [
  12089. {
  12090. "name": "None"
  12091. },
  12092. {
  12093. "name": "One"
  12094. },
  12095. {
  12096. "name": "All"
  12097. },
  12098. {
  12099. "name": "Complex"
  12100. }
  12101. ]
  12102. },
  12103. {
  12104. "name": "AdHocOrdering",
  12105. "literalValues": [
  12106. {
  12107. "name": "Parallel"
  12108. },
  12109. {
  12110. "name": "Sequential"
  12111. }
  12112. ]
  12113. }
  12114. ],
  12115. "prefix": "bpmn",
  12116. "xml": {
  12117. "tagAlias": "lowerCase",
  12118. "typePrefix": "t"
  12119. }
  12120. }
  12121. },{}],70:[function(_dereq_,module,exports){
  12122. module.exports={
  12123. "name": "BPMNDI",
  12124. "uri": "http://www.omg.org/spec/BPMN/20100524/DI",
  12125. "types": [
  12126. {
  12127. "name": "BPMNDiagram",
  12128. "properties": [
  12129. {
  12130. "name": "plane",
  12131. "type": "BPMNPlane",
  12132. "redefines": "di:Diagram#rootElement"
  12133. },
  12134. {
  12135. "name": "labelStyle",
  12136. "type": "BPMNLabelStyle",
  12137. "isMany": true
  12138. }
  12139. ],
  12140. "superClass": [
  12141. "di:Diagram"
  12142. ]
  12143. },
  12144. {
  12145. "name": "BPMNPlane",
  12146. "properties": [
  12147. {
  12148. "name": "bpmnElement",
  12149. "isAttr": true,
  12150. "isReference": true,
  12151. "type": "bpmn:BaseElement",
  12152. "redefines": "di:DiagramElement#modelElement"
  12153. }
  12154. ],
  12155. "superClass": [
  12156. "di:Plane"
  12157. ]
  12158. },
  12159. {
  12160. "name": "BPMNShape",
  12161. "properties": [
  12162. {
  12163. "name": "bpmnElement",
  12164. "isAttr": true,
  12165. "isReference": true,
  12166. "type": "bpmn:BaseElement",
  12167. "redefines": "di:DiagramElement#modelElement"
  12168. },
  12169. {
  12170. "name": "isHorizontal",
  12171. "isAttr": true,
  12172. "type": "Boolean"
  12173. },
  12174. {
  12175. "name": "isExpanded",
  12176. "isAttr": true,
  12177. "type": "Boolean"
  12178. },
  12179. {
  12180. "name": "isMarkerVisible",
  12181. "isAttr": true,
  12182. "type": "Boolean"
  12183. },
  12184. {
  12185. "name": "label",
  12186. "type": "BPMNLabel"
  12187. },
  12188. {
  12189. "name": "isMessageVisible",
  12190. "isAttr": true,
  12191. "type": "Boolean"
  12192. },
  12193. {
  12194. "name": "participantBandKind",
  12195. "type": "ParticipantBandKind",
  12196. "isAttr": true
  12197. },
  12198. {
  12199. "name": "choreographyActivityShape",
  12200. "type": "BPMNShape",
  12201. "isAttr": true,
  12202. "isReference": true
  12203. }
  12204. ],
  12205. "superClass": [
  12206. "di:LabeledShape"
  12207. ]
  12208. },
  12209. {
  12210. "name": "BPMNEdge",
  12211. "properties": [
  12212. {
  12213. "name": "label",
  12214. "type": "BPMNLabel"
  12215. },
  12216. {
  12217. "name": "bpmnElement",
  12218. "isAttr": true,
  12219. "isReference": true,
  12220. "type": "bpmn:BaseElement",
  12221. "redefines": "di:DiagramElement#modelElement"
  12222. },
  12223. {
  12224. "name": "sourceElement",
  12225. "isAttr": true,
  12226. "isReference": true,
  12227. "type": "di:DiagramElement",
  12228. "redefines": "di:Edge#source"
  12229. },
  12230. {
  12231. "name": "targetElement",
  12232. "isAttr": true,
  12233. "isReference": true,
  12234. "type": "di:DiagramElement",
  12235. "redefines": "di:Edge#target"
  12236. },
  12237. {
  12238. "name": "messageVisibleKind",
  12239. "type": "MessageVisibleKind",
  12240. "isAttr": true,
  12241. "default": "initiating"
  12242. }
  12243. ],
  12244. "superClass": [
  12245. "di:LabeledEdge"
  12246. ]
  12247. },
  12248. {
  12249. "name": "BPMNLabel",
  12250. "properties": [
  12251. {
  12252. "name": "labelStyle",
  12253. "type": "BPMNLabelStyle",
  12254. "isAttr": true,
  12255. "isReference": true,
  12256. "redefines": "di:DiagramElement#style"
  12257. }
  12258. ],
  12259. "superClass": [
  12260. "di:Label"
  12261. ]
  12262. },
  12263. {
  12264. "name": "BPMNLabelStyle",
  12265. "properties": [
  12266. {
  12267. "name": "font",
  12268. "type": "dc:Font"
  12269. }
  12270. ],
  12271. "superClass": [
  12272. "di:Style"
  12273. ]
  12274. }
  12275. ],
  12276. "emumerations": [
  12277. {
  12278. "name": "ParticipantBandKind",
  12279. "literalValues": [
  12280. {
  12281. "name": "top_initiating"
  12282. },
  12283. {
  12284. "name": "middle_initiating"
  12285. },
  12286. {
  12287. "name": "bottom_initiating"
  12288. },
  12289. {
  12290. "name": "top_non_initiating"
  12291. },
  12292. {
  12293. "name": "middle_non_initiating"
  12294. },
  12295. {
  12296. "name": "bottom_non_initiating"
  12297. }
  12298. ]
  12299. },
  12300. {
  12301. "name": "MessageVisibleKind",
  12302. "literalValues": [
  12303. {
  12304. "name": "initiating"
  12305. },
  12306. {
  12307. "name": "non_initiating"
  12308. }
  12309. ]
  12310. }
  12311. ],
  12312. "associations": [],
  12313. "prefix": "bpmndi"
  12314. }
  12315. },{}],71:[function(_dereq_,module,exports){
  12316. module.exports={
  12317. "name": "DC",
  12318. "uri": "http://www.omg.org/spec/DD/20100524/DC",
  12319. "types": [
  12320. {
  12321. "name": "Boolean"
  12322. },
  12323. {
  12324. "name": "Integer"
  12325. },
  12326. {
  12327. "name": "Real"
  12328. },
  12329. {
  12330. "name": "String"
  12331. },
  12332. {
  12333. "name": "Font",
  12334. "properties": [
  12335. {
  12336. "name": "name",
  12337. "type": "String",
  12338. "isAttr": true
  12339. },
  12340. {
  12341. "name": "size",
  12342. "type": "Real",
  12343. "isAttr": true
  12344. },
  12345. {
  12346. "name": "isBold",
  12347. "type": "Boolean",
  12348. "isAttr": true
  12349. },
  12350. {
  12351. "name": "isItalic",
  12352. "type": "Boolean",
  12353. "isAttr": true
  12354. },
  12355. {
  12356. "name": "isUnderline",
  12357. "type": "Boolean",
  12358. "isAttr": true
  12359. },
  12360. {
  12361. "name": "isStrikeThrough",
  12362. "type": "Boolean",
  12363. "isAttr": true
  12364. }
  12365. ]
  12366. },
  12367. {
  12368. "name": "Point",
  12369. "properties": [
  12370. {
  12371. "name": "x",
  12372. "type": "Real",
  12373. "default": "0",
  12374. "isAttr": true
  12375. },
  12376. {
  12377. "name": "y",
  12378. "type": "Real",
  12379. "default": "0",
  12380. "isAttr": true
  12381. }
  12382. ]
  12383. },
  12384. {
  12385. "name": "Bounds",
  12386. "properties": [
  12387. {
  12388. "name": "x",
  12389. "type": "Real",
  12390. "default": "0",
  12391. "isAttr": true
  12392. },
  12393. {
  12394. "name": "y",
  12395. "type": "Real",
  12396. "default": "0",
  12397. "isAttr": true
  12398. },
  12399. {
  12400. "name": "width",
  12401. "type": "Real",
  12402. "isAttr": true
  12403. },
  12404. {
  12405. "name": "height",
  12406. "type": "Real",
  12407. "isAttr": true
  12408. }
  12409. ]
  12410. }
  12411. ],
  12412. "prefix": "dc",
  12413. "associations": []
  12414. }
  12415. },{}],72:[function(_dereq_,module,exports){
  12416. module.exports={
  12417. "name": "DI",
  12418. "uri": "http://www.omg.org/spec/DD/20100524/DI",
  12419. "types": [
  12420. {
  12421. "name": "DiagramElement",
  12422. "isAbstract": true,
  12423. "properties": [
  12424. {
  12425. "name": "extension",
  12426. "type": "Extension"
  12427. },
  12428. {
  12429. "name": "owningDiagram",
  12430. "type": "Diagram",
  12431. "isReadOnly": true,
  12432. "isVirtual": true,
  12433. "isReference": true
  12434. },
  12435. {
  12436. "name": "owningElement",
  12437. "type": "DiagramElement",
  12438. "isReadOnly": true,
  12439. "isVirtual": true,
  12440. "isReference": true
  12441. },
  12442. {
  12443. "name": "modelElement",
  12444. "isReadOnly": true,
  12445. "isVirtual": true,
  12446. "isReference": true,
  12447. "type": "Element"
  12448. },
  12449. {
  12450. "name": "style",
  12451. "type": "Style",
  12452. "isReadOnly": true,
  12453. "isVirtual": true,
  12454. "isReference": true
  12455. },
  12456. {
  12457. "name": "ownedElement",
  12458. "type": "DiagramElement",
  12459. "isReadOnly": true,
  12460. "isVirtual": true,
  12461. "isMany": true
  12462. }
  12463. ]
  12464. },
  12465. {
  12466. "name": "Node",
  12467. "isAbstract": true,
  12468. "superClass": [
  12469. "DiagramElement"
  12470. ]
  12471. },
  12472. {
  12473. "name": "Edge",
  12474. "isAbstract": true,
  12475. "superClass": [
  12476. "DiagramElement"
  12477. ],
  12478. "properties": [
  12479. {
  12480. "name": "source",
  12481. "type": "DiagramElement",
  12482. "isReadOnly": true,
  12483. "isVirtual": true,
  12484. "isReference": true
  12485. },
  12486. {
  12487. "name": "target",
  12488. "type": "DiagramElement",
  12489. "isReadOnly": true,
  12490. "isVirtual": true,
  12491. "isReference": true
  12492. },
  12493. {
  12494. "name": "waypoint",
  12495. "isUnique": false,
  12496. "isMany": true,
  12497. "type": "dc:Point",
  12498. "xml": {
  12499. "serialize": "xsi:type"
  12500. }
  12501. }
  12502. ]
  12503. },
  12504. {
  12505. "name": "Diagram",
  12506. "isAbstract": true,
  12507. "properties": [
  12508. {
  12509. "name": "rootElement",
  12510. "type": "DiagramElement",
  12511. "isReadOnly": true,
  12512. "isVirtual": true
  12513. },
  12514. {
  12515. "name": "name",
  12516. "isAttr": true,
  12517. "type": "String"
  12518. },
  12519. {
  12520. "name": "documentation",
  12521. "isAttr": true,
  12522. "type": "String"
  12523. },
  12524. {
  12525. "name": "resolution",
  12526. "isAttr": true,
  12527. "type": "Real"
  12528. },
  12529. {
  12530. "name": "ownedStyle",
  12531. "type": "Style",
  12532. "isReadOnly": true,
  12533. "isVirtual": true,
  12534. "isMany": true
  12535. }
  12536. ]
  12537. },
  12538. {
  12539. "name": "Shape",
  12540. "isAbstract": true,
  12541. "superClass": [
  12542. "Node"
  12543. ],
  12544. "properties": [
  12545. {
  12546. "name": "bounds",
  12547. "type": "dc:Bounds"
  12548. }
  12549. ]
  12550. },
  12551. {
  12552. "name": "Plane",
  12553. "isAbstract": true,
  12554. "superClass": [
  12555. "Node"
  12556. ],
  12557. "properties": [
  12558. {
  12559. "name": "planeElement",
  12560. "type": "DiagramElement",
  12561. "subsettedProperty": "DiagramElement-ownedElement",
  12562. "isMany": true
  12563. }
  12564. ]
  12565. },
  12566. {
  12567. "name": "LabeledEdge",
  12568. "isAbstract": true,
  12569. "superClass": [
  12570. "Edge"
  12571. ],
  12572. "properties": [
  12573. {
  12574. "name": "ownedLabel",
  12575. "type": "Label",
  12576. "isReadOnly": true,
  12577. "subsettedProperty": "DiagramElement-ownedElement",
  12578. "isVirtual": true,
  12579. "isMany": true
  12580. }
  12581. ]
  12582. },
  12583. {
  12584. "name": "LabeledShape",
  12585. "isAbstract": true,
  12586. "superClass": [
  12587. "Shape"
  12588. ],
  12589. "properties": [
  12590. {
  12591. "name": "ownedLabel",
  12592. "type": "Label",
  12593. "isReadOnly": true,
  12594. "subsettedProperty": "DiagramElement-ownedElement",
  12595. "isVirtual": true,
  12596. "isMany": true
  12597. }
  12598. ]
  12599. },
  12600. {
  12601. "name": "Label",
  12602. "isAbstract": true,
  12603. "superClass": [
  12604. "Node"
  12605. ],
  12606. "properties": [
  12607. {
  12608. "name": "bounds",
  12609. "type": "dc:Bounds"
  12610. }
  12611. ]
  12612. },
  12613. {
  12614. "name": "Style",
  12615. "isAbstract": true
  12616. },
  12617. {
  12618. "name": "Extension",
  12619. "properties": [
  12620. {
  12621. "name": "values",
  12622. "type": "Element",
  12623. "isMany": true
  12624. }
  12625. ]
  12626. }
  12627. ],
  12628. "associations": [],
  12629. "prefix": "di",
  12630. "xml": {
  12631. "tagAlias": "lowerCase"
  12632. }
  12633. }
  12634. },{}],73:[function(_dereq_,module,exports){
  12635. module.exports = {
  12636. __depends__: [ _dereq_(108) ],
  12637. __init__: [ 'directEditing' ],
  12638. directEditing: [ 'type', _dereq_(74) ]
  12639. };
  12640. },{"108":108,"74":74}],74:[function(_dereq_,module,exports){
  12641. 'use strict';
  12642. var bind = _dereq_(227),
  12643. find = _dereq_(217);
  12644. var TextBox = _dereq_(75);
  12645. /**
  12646. * A direct editing component that allows users
  12647. * to edit an elements text directly in the diagram
  12648. *
  12649. * @param {EventBus} eventBus the event bus
  12650. */
  12651. function DirectEditing(eventBus, canvas) {
  12652. this._eventBus = eventBus;
  12653. this._providers = [];
  12654. this._textbox = new TextBox({
  12655. container: canvas.getContainer(),
  12656. keyHandler: bind(this._handleKey, this)
  12657. });
  12658. }
  12659. DirectEditing.$inject = [ 'eventBus', 'canvas' ];
  12660. /**
  12661. * Register a direct editing provider
  12662. * @param {Object} provider the provider, must expose an #activate(element) method that returns
  12663. * an activation context ({ bounds: {x, y, width, height }, text }) if
  12664. * direct editing is available for the given element.
  12665. * Additionally the provider must expose a #update(element, value) method
  12666. * to receive direct editing updates.
  12667. */
  12668. DirectEditing.prototype.registerProvider = function(provider) {
  12669. this._providers.push(provider);
  12670. };
  12671. /**
  12672. * Returns true if direct editing is currently active
  12673. *
  12674. * @return {Boolean}
  12675. */
  12676. DirectEditing.prototype.isActive = function() {
  12677. return !!this._active;
  12678. };
  12679. /**
  12680. * Cancel direct editing, if it is currently active
  12681. */
  12682. DirectEditing.prototype.cancel = function() {
  12683. if (!this._active) {
  12684. return;
  12685. }
  12686. this._fire('cancel');
  12687. this.close();
  12688. };
  12689. DirectEditing.prototype._fire = function(event) {
  12690. this._eventBus.fire('directEditing.' + event, { active: this._active });
  12691. };
  12692. DirectEditing.prototype.close = function() {
  12693. this._textbox.destroy();
  12694. this._fire('deactivate');
  12695. this._active = null;
  12696. };
  12697. DirectEditing.prototype.complete = function() {
  12698. var active = this._active;
  12699. if (!active) {
  12700. return;
  12701. }
  12702. var text = this.getValue();
  12703. if (text !== active.context.text) {
  12704. active.provider.update(active.element, text, active.context.text);
  12705. }
  12706. this._fire('complete');
  12707. this.close();
  12708. };
  12709. DirectEditing.prototype.getValue = function() {
  12710. return this._textbox.getValue();
  12711. };
  12712. DirectEditing.prototype._handleKey = function(e) {
  12713. // stop bubble
  12714. e.stopPropagation();
  12715. var key = e.keyCode || e.charCode;
  12716. // ESC
  12717. if (key === 27) {
  12718. e.preventDefault();
  12719. return this.cancel();
  12720. }
  12721. // Enter
  12722. if (key === 13 && !e.shiftKey) {
  12723. e.preventDefault();
  12724. return this.complete();
  12725. }
  12726. };
  12727. /**
  12728. * Activate direct editing on the given element
  12729. *
  12730. * @param {Object} ElementDescriptor the descriptor for a shape or connection
  12731. * @return {Boolean} true if the activation was possible
  12732. */
  12733. DirectEditing.prototype.activate = function(element) {
  12734. if (this.isActive()) {
  12735. this.cancel();
  12736. }
  12737. // the direct editing context
  12738. var context;
  12739. var provider = find(this._providers, function(p) {
  12740. return !!(context = p.activate(element)) ? p : null;
  12741. });
  12742. // check if activation took place
  12743. if (context) {
  12744. this._textbox.create(context.bounds, context.style, context.text);
  12745. this._active = {
  12746. element: element,
  12747. context: context,
  12748. provider: provider
  12749. };
  12750. this._fire('activate');
  12751. }
  12752. return !!context;
  12753. };
  12754. module.exports = DirectEditing;
  12755. },{"217":217,"227":227,"75":75}],75:[function(_dereq_,module,exports){
  12756. 'use strict';
  12757. var assign = _dereq_(339),
  12758. domEvent = _dereq_(357),
  12759. domRemove = _dereq_(360);
  12760. function stopPropagation(event) {
  12761. event.stopPropagation();
  12762. }
  12763. function TextBox(options) {
  12764. this.container = options.container;
  12765. this.textarea = document.createElement('textarea');
  12766. this.keyHandler = options.keyHandler || function() {};
  12767. }
  12768. module.exports = TextBox;
  12769. TextBox.prototype.create = function(bounds, style, value) {
  12770. var textarea = this.textarea,
  12771. container = this.container;
  12772. assign(textarea.style, {
  12773. width: bounds.width + 'px',
  12774. height: bounds.height + 'px',
  12775. left: bounds.x + 'px',
  12776. top: bounds.y + 'px',
  12777. position: 'absolute',
  12778. textAlign: 'center',
  12779. boxSizing: 'border-box'
  12780. }, style || {});
  12781. textarea.value = value;
  12782. textarea.title = 'Press SHIFT+Enter for line feed';
  12783. domEvent.bind(textarea, 'keydown', this.keyHandler);
  12784. domEvent.bind(textarea, 'mousedown', stopPropagation);
  12785. container.appendChild(textarea);
  12786. setTimeout(function() {
  12787. if (textarea.parent) {
  12788. textarea.select();
  12789. }
  12790. textarea.focus();
  12791. }, 100);
  12792. };
  12793. TextBox.prototype.destroy = function() {
  12794. var textarea = this.textarea;
  12795. textarea.value = '';
  12796. domEvent.unbind(textarea, 'keydown', this.keyHandler);
  12797. domEvent.unbind(textarea, 'mousedown', stopPropagation);
  12798. domRemove(textarea);
  12799. };
  12800. TextBox.prototype.getValue = function() {
  12801. return this.textarea.value;
  12802. };
  12803. },{"339":339,"357":357,"360":360}],76:[function(_dereq_,module,exports){
  12804. module.exports = _dereq_(77);
  12805. },{"77":77}],77:[function(_dereq_,module,exports){
  12806. 'use strict';
  12807. var di = _dereq_(202);
  12808. /**
  12809. * Bootstrap an injector from a list of modules, instantiating a number of default components
  12810. *
  12811. * @ignore
  12812. * @param {Array<didi.Module>} bootstrapModules
  12813. *
  12814. * @return {didi.Injector} a injector to use to access the components
  12815. */
  12816. function bootstrap(bootstrapModules) {
  12817. var modules = [],
  12818. components = [];
  12819. function hasModule(m) {
  12820. return modules.indexOf(m) >= 0;
  12821. }
  12822. function addModule(m) {
  12823. modules.push(m);
  12824. }
  12825. function visit(m) {
  12826. if (hasModule(m)) {
  12827. return;
  12828. }
  12829. (m.__depends__ || []).forEach(visit);
  12830. if (hasModule(m)) {
  12831. return;
  12832. }
  12833. addModule(m);
  12834. (m.__init__ || []).forEach(function(c) {
  12835. components.push(c);
  12836. });
  12837. }
  12838. bootstrapModules.forEach(visit);
  12839. var injector = new di.Injector(modules);
  12840. components.forEach(function(c) {
  12841. try {
  12842. // eagerly resolve component (fn or string)
  12843. injector[typeof c === 'string' ? 'get' : 'invoke'](c);
  12844. } catch (e) {
  12845. console.error('Failed to instantiate component');
  12846. console.error(e.stack);
  12847. throw e;
  12848. }
  12849. });
  12850. return injector;
  12851. }
  12852. /**
  12853. * Creates an injector from passed options.
  12854. *
  12855. * @ignore
  12856. * @param {Object} options
  12857. * @return {didi.Injector}
  12858. */
  12859. function createInjector(options) {
  12860. options = options || {};
  12861. var configModule = {
  12862. 'config': ['value', options]
  12863. };
  12864. var coreModule = _dereq_(86);
  12865. var modules = [ configModule, coreModule ].concat(options.modules || []);
  12866. return bootstrap(modules);
  12867. }
  12868. /**
  12869. * The main diagram-js entry point that bootstraps the diagram with the given
  12870. * configuration.
  12871. *
  12872. * To register extensions with the diagram, pass them as Array<didi.Module> to the constructor.
  12873. *
  12874. * @class djs.Diagram
  12875. * @memberOf djs
  12876. * @constructor
  12877. *
  12878. * @example
  12879. *
  12880. * <caption>Creating a plug-in that logs whenever a shape is added to the canvas.</caption>
  12881. *
  12882. * // plug-in implemenentation
  12883. * function MyLoggingPlugin(eventBus) {
  12884. * eventBus.on('shape.added', function(event) {
  12885. * console.log('shape ', event.shape, ' was added to the diagram');
  12886. * });
  12887. * }
  12888. *
  12889. * // export as module
  12890. * module.exports = {
  12891. * __init__: [ 'myLoggingPlugin' ],
  12892. * myLoggingPlugin: [ 'type', MyLoggingPlugin ]
  12893. * };
  12894. *
  12895. *
  12896. * // instantiate the diagram with the new plug-in
  12897. *
  12898. * var diagram = new Diagram({ modules: [ require('path-to-my-logging-plugin') ] });
  12899. *
  12900. * diagram.invoke([ 'canvas', function(canvas) {
  12901. * // add shape to drawing canvas
  12902. * canvas.addShape({ x: 10, y: 10 });
  12903. * });
  12904. *
  12905. * // 'shape ... was added to the diagram' logged to console
  12906. *
  12907. * @param {Object} options
  12908. * @param {Array<didi.Module>} [options.modules] external modules to instantiate with the diagram
  12909. * @param {didi.Injector} [injector] an (optional) injector to bootstrap the diagram with
  12910. */
  12911. function Diagram(options, injector) {
  12912. // create injector unless explicitly specified
  12913. this.injector = injector = injector || createInjector(options);
  12914. // API
  12915. /**
  12916. * Resolves a diagram service
  12917. *
  12918. * @method Diagram#get
  12919. *
  12920. * @param {String} name the name of the diagram service to be retrieved
  12921. * @param {Object} [locals] a number of locals to use to resolve certain dependencies
  12922. */
  12923. this.get = injector.get;
  12924. /**
  12925. * Executes a function into which diagram services are injected
  12926. *
  12927. * @method Diagram#invoke
  12928. *
  12929. * @param {Function|Object[]} fn the function to resolve
  12930. * @param {Object} locals a number of locals to use to resolve certain dependencies
  12931. */
  12932. this.invoke = injector.invoke;
  12933. // init
  12934. // indicate via event
  12935. /**
  12936. * An event indicating that all plug-ins are loaded.
  12937. *
  12938. * Use this event to fire other events to interested plug-ins
  12939. *
  12940. * @memberOf Diagram
  12941. *
  12942. * @event diagram.init
  12943. *
  12944. * @example
  12945. *
  12946. * eventBus.on('diagram.init', function() {
  12947. * eventBus.fire('my-custom-event', { foo: 'BAR' });
  12948. * });
  12949. *
  12950. * @type {Object}
  12951. */
  12952. this.get('eventBus').fire('diagram.init');
  12953. }
  12954. module.exports = Diagram;
  12955. /**
  12956. * Destroys the diagram
  12957. *
  12958. * @method Diagram#destroy
  12959. */
  12960. Diagram.prototype.destroy = function() {
  12961. this.get('eventBus').fire('diagram.destroy');
  12962. };
  12963. },{"202":202,"86":86}],78:[function(_dereq_,module,exports){
  12964. 'use strict';
  12965. var forEach = _dereq_(218),
  12966. isFunction = _dereq_(331),
  12967. isArray = _dereq_(330),
  12968. isNumber = _dereq_(333);
  12969. var DEFAULT_PRIORITY = 1000;
  12970. /**
  12971. * A utility that can be used to plug-in into the command execution for
  12972. * extension and/or validation.
  12973. *
  12974. * @param {EventBus} eventBus
  12975. *
  12976. * @example
  12977. *
  12978. * var inherits = require('inherits');
  12979. *
  12980. * var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
  12981. *
  12982. * function CommandLogger(eventBus) {
  12983. * CommandInterceptor.call(this, eventBus);
  12984. *
  12985. * this.preExecute(function(event) {
  12986. * console.log('command pre-execute', event);
  12987. * });
  12988. * }
  12989. *
  12990. * inherits(CommandLogger, CommandInterceptor);
  12991. *
  12992. */
  12993. function CommandInterceptor(eventBus) {
  12994. this._eventBus = eventBus;
  12995. }
  12996. CommandInterceptor.$inject = [ 'eventBus' ];
  12997. module.exports = CommandInterceptor;
  12998. function unwrapEvent(fn) {
  12999. return function(event) {
  13000. return fn(event.context, event.command, event);
  13001. };
  13002. }
  13003. /**
  13004. * Register an interceptor for a command execution
  13005. *
  13006. * @param {String|Array<String>} [events] list of commands to register on
  13007. * @param {String} [hook] command hook, i.e. preExecute, executed to listen on
  13008. * @param {Number} [priority] the priority on which to hook into the execution
  13009. * @param {Function} handlerFn interceptor to be invoked with (event)
  13010. * @param {Boolean} unwrap if true, unwrap the event and pass (context, command, event) to the
  13011. * listener instead
  13012. */
  13013. CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap) {
  13014. if (isFunction(hook) || isNumber(hook)) {
  13015. unwrap = handlerFn;
  13016. handlerFn = priority;
  13017. priority = hook;
  13018. hook = null;
  13019. }
  13020. if (isFunction(priority)) {
  13021. unwrap = handlerFn;
  13022. handlerFn = priority;
  13023. priority = DEFAULT_PRIORITY;
  13024. }
  13025. if (!isFunction(handlerFn)) {
  13026. throw new Error('handlerFn must be a function');
  13027. }
  13028. if (!isArray(events)) {
  13029. events = [ events ];
  13030. }
  13031. var eventBus = this._eventBus;
  13032. forEach(events, function(event) {
  13033. // concat commandStack(.event)?(.hook)?
  13034. var fullEvent = [ 'commandStack', event, hook ].filter(function(e) { return e; }).join('.');
  13035. eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn) : handlerFn);
  13036. });
  13037. };
  13038. var hooks = [
  13039. 'canExecute',
  13040. 'preExecute',
  13041. 'preExecuted',
  13042. 'execute',
  13043. 'executed',
  13044. 'postExecute',
  13045. 'postExecuted',
  13046. 'revert',
  13047. 'reverted'
  13048. ];
  13049. /*
  13050. * Install hook shortcuts
  13051. *
  13052. * This will generate the CommandInterceptor#(preExecute|...|reverted) methods
  13053. * which will in term forward to CommandInterceptor#on.
  13054. */
  13055. forEach(hooks, function(hook) {
  13056. /**
  13057. * {canExecute|preExecute|preExecuted|execute|executed|postExecute|postExecuted|revert|reverted}
  13058. *
  13059. * A named hook for plugging into the command execution
  13060. *
  13061. * @param {String|Array<String>} [events] list of commands to register on
  13062. * @param {Number} [priority] the priority on which to hook into the execution
  13063. * @param {Function} handlerFn interceptor to be invoked with (event)
  13064. * @param {Boolean} [unwrap=false] if true, unwrap the event and pass (context, command, event) to the
  13065. * listener instead
  13066. */
  13067. CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap) {
  13068. if (isFunction(events) || isNumber(events)) {
  13069. unwrap = handlerFn;
  13070. handlerFn = priority;
  13071. priority = events;
  13072. events = null;
  13073. }
  13074. this.on(events, hook, priority, handlerFn, unwrap);
  13075. };
  13076. });
  13077. },{"218":218,"330":330,"331":331,"333":333}],79:[function(_dereq_,module,exports){
  13078. 'use strict';
  13079. var unique = _dereq_(211),
  13080. isArray = _dereq_(330),
  13081. assign = _dereq_(339);
  13082. var InternalEvent = _dereq_(84).Event;
  13083. /**
  13084. * A service that offers un- and redoable execution of commands.
  13085. *
  13086. * The command stack is responsible for executing modeling actions
  13087. * in a un- and redoable manner. To do this it delegates the actual
  13088. * command execution to {@link CommandHandler}s.
  13089. *
  13090. * Command handlers provide {@link CommandHandler#execute(ctx)} and
  13091. * {@link CommandHandler#revert(ctx)} methods to un- and redo a command
  13092. * identified by a command context.
  13093. *
  13094. *
  13095. * ## Life-Cycle events
  13096. *
  13097. * In the process the command stack fires a number of life-cycle events
  13098. * that other components to participate in the command execution.
  13099. *
  13100. * * preExecute
  13101. * * preExecuted
  13102. * * execute
  13103. * * executed
  13104. * * postExecute
  13105. * * postExecuted
  13106. * * revert
  13107. * * reverted
  13108. *
  13109. * A special event is used for validating, whether a command can be
  13110. * performed prior to its execution.
  13111. *
  13112. * * canExecute
  13113. *
  13114. * Each of the events is fired as `commandStack.{eventName}` and
  13115. * `commandStack.{commandName}.{eventName}`, respectively. This gives
  13116. * components fine grained control on where to hook into.
  13117. *
  13118. * The event object fired transports `command`, the name of the
  13119. * command and `context`, the command context.
  13120. *
  13121. *
  13122. * ## Creating Command Handlers
  13123. *
  13124. * Command handlers should provide the {@link CommandHandler#execute(ctx)}
  13125. * and {@link CommandHandler#revert(ctx)} methods to implement
  13126. * redoing and undoing of a command. They must ensure undo is performed
  13127. * properly in order not to break the undo chain.
  13128. *
  13129. * Command handlers may execute other modeling operations (and thus
  13130. * commands) in their `preExecute` and `postExecute` phases. The command
  13131. * stack will properly group all commands together into a logical unit
  13132. * that may be re- and undone atomically.
  13133. *
  13134. * Command handlers must not execute other commands from within their
  13135. * core implementation (`execute`, `revert`).
  13136. *
  13137. *
  13138. * ## Change Tracking
  13139. *
  13140. * During the execution of the CommandStack it will keep track of all
  13141. * elements that have been touched during the command's execution.
  13142. *
  13143. * At the end of the CommandStack execution it will notify interested
  13144. * components via an 'elements.changed' event with all the dirty
  13145. * elements.
  13146. *
  13147. * The event can be picked up by components that are interested in the fact
  13148. * that elements have been changed. One use case for this is updating
  13149. * their graphical representation after moving / resizing or deletion.
  13150. *
  13151. *
  13152. * @param {EventBus} eventBus
  13153. * @param {Injector} injector
  13154. */
  13155. function CommandStack(eventBus, injector) {
  13156. /**
  13157. * A map of all registered command handlers.
  13158. *
  13159. * @type {Object}
  13160. */
  13161. this._handlerMap = {};
  13162. /**
  13163. * A stack containing all re/undoable actions on the diagram
  13164. *
  13165. * @type {Array<Object>}
  13166. */
  13167. this._stack = [];
  13168. /**
  13169. * The current index on the stack
  13170. *
  13171. * @type {Number}
  13172. */
  13173. this._stackIdx = -1;
  13174. /**
  13175. * Current active commandStack execution
  13176. *
  13177. * @type {Object}
  13178. */
  13179. this._currentExecution = {
  13180. actions: [],
  13181. dirty: []
  13182. };
  13183. this._injector = injector;
  13184. this._eventBus = eventBus;
  13185. this._uid = 1;
  13186. }
  13187. CommandStack.$inject = [ 'eventBus', 'injector' ];
  13188. module.exports = CommandStack;
  13189. /**
  13190. * Execute a command
  13191. *
  13192. * @param {String} command the command to execute
  13193. * @param {Object} context the environment to execute the command in
  13194. */
  13195. CommandStack.prototype.execute = function(command, context) {
  13196. if (!command) {
  13197. throw new Error('command required');
  13198. }
  13199. var action = { command: command, context: context };
  13200. this._pushAction(action);
  13201. this._internalExecute(action);
  13202. this._popAction(action);
  13203. };
  13204. /**
  13205. * Ask whether a given command can be executed.
  13206. *
  13207. * Implementors may hook into the mechanism on two ways:
  13208. *
  13209. * * in event listeners:
  13210. *
  13211. * Users may prevent the execution via an event listener.
  13212. * It must prevent the default action for `commandStack.(<command>.)canExecute` events.
  13213. *
  13214. * * in command handlers:
  13215. *
  13216. * If the method {@link CommandHandler#canExecute} is implemented in a handler
  13217. * it will be called to figure out whether the execution is allowed.
  13218. *
  13219. * @param {String} command the command to execute
  13220. * @param {Object} context the environment to execute the command in
  13221. *
  13222. * @return {Boolean} true if the command can be executed
  13223. */
  13224. CommandStack.prototype.canExecute = function(command, context) {
  13225. var action = { command: command, context: context };
  13226. var handler = this._getHandler(command);
  13227. if (!handler) {
  13228. return false;
  13229. }
  13230. var result = this._fire(command, 'canExecute', action);
  13231. // handler#canExecute will only be called if no listener
  13232. // decided on a result already
  13233. if (result === undefined && handler.canExecute) {
  13234. result = handler.canExecute(context);
  13235. }
  13236. return result;
  13237. };
  13238. /**
  13239. * Clear the command stack, erasing all undo / redo history
  13240. */
  13241. CommandStack.prototype.clear = function() {
  13242. this._stack.length = 0;
  13243. this._stackIdx = -1;
  13244. this._fire('changed');
  13245. };
  13246. /**
  13247. * Undo last command(s)
  13248. */
  13249. CommandStack.prototype.undo = function() {
  13250. var action = this._getUndoAction(),
  13251. next;
  13252. if (action) {
  13253. this._pushAction(action);
  13254. while (action) {
  13255. this._internalUndo(action);
  13256. next = this._getUndoAction();
  13257. if (!next || next.id !== action.id) {
  13258. break;
  13259. }
  13260. action = next;
  13261. }
  13262. this._popAction();
  13263. }
  13264. };
  13265. /**
  13266. * Redo last command(s)
  13267. */
  13268. CommandStack.prototype.redo = function() {
  13269. var action = this._getRedoAction(),
  13270. next;
  13271. if (action) {
  13272. this._pushAction(action);
  13273. while (action) {
  13274. this._internalExecute(action, true);
  13275. next = this._getRedoAction();
  13276. if (!next || next.id !== action.id) {
  13277. break;
  13278. }
  13279. action = next;
  13280. }
  13281. this._popAction();
  13282. }
  13283. };
  13284. /**
  13285. * Register a handler instance with the command stack
  13286. *
  13287. * @param {String} command
  13288. * @param {CommandHandler} handler
  13289. */
  13290. CommandStack.prototype.register = function(command, handler) {
  13291. this._setHandler(command, handler);
  13292. };
  13293. /**
  13294. * Register a handler type with the command stack
  13295. * by instantiating it and injecting its dependencies.
  13296. *
  13297. * @param {String} command
  13298. * @param {Function} a constructor for a {@link CommandHandler}
  13299. */
  13300. CommandStack.prototype.registerHandler = function(command, handlerCls) {
  13301. if (!command || !handlerCls) {
  13302. throw new Error('command and handlerCls must be defined');
  13303. }
  13304. var handler = this._injector.instantiate(handlerCls);
  13305. this.register(command, handler);
  13306. };
  13307. CommandStack.prototype.canUndo = function() {
  13308. return !!this._getUndoAction();
  13309. };
  13310. CommandStack.prototype.canRedo = function() {
  13311. return !!this._getRedoAction();
  13312. };
  13313. ////// stack access //////////////////////////////////////
  13314. CommandStack.prototype._getRedoAction = function() {
  13315. return this._stack[this._stackIdx + 1];
  13316. };
  13317. CommandStack.prototype._getUndoAction = function() {
  13318. return this._stack[this._stackIdx];
  13319. };
  13320. ////// internal functionality /////////////////////////////
  13321. CommandStack.prototype._internalUndo = function(action) {
  13322. var command = action.command,
  13323. context = action.context;
  13324. var handler = this._getHandler(command);
  13325. this._fire(command, 'revert', action);
  13326. this._markDirty(handler.revert(context));
  13327. this._revertedAction(action);
  13328. this._fire(command, 'reverted', action);
  13329. };
  13330. CommandStack.prototype._fire = function(command, qualifier, event) {
  13331. if (arguments.length < 3) {
  13332. event = qualifier;
  13333. qualifier = null;
  13334. }
  13335. var names = qualifier ? [ command + '.' + qualifier, qualifier ] : [ command ],
  13336. i, name, result;
  13337. event = assign(new InternalEvent(), event);
  13338. for (i = 0; !!(name = names[i]); i++) {
  13339. result = this._eventBus.fire('commandStack.' + name, event);
  13340. if (event.cancelBubble) {
  13341. break;
  13342. }
  13343. }
  13344. return result;
  13345. };
  13346. CommandStack.prototype._createId = function() {
  13347. return this._uid++;
  13348. };
  13349. CommandStack.prototype._internalExecute = function(action, redo) {
  13350. var command = action.command,
  13351. context = action.context;
  13352. var handler = this._getHandler(command);
  13353. if (!handler) {
  13354. throw new Error('no command handler registered for <' + command + '>');
  13355. }
  13356. this._pushAction(action);
  13357. if (!redo) {
  13358. this._fire(command, 'preExecute', action);
  13359. if (handler.preExecute) {
  13360. handler.preExecute(context);
  13361. }
  13362. this._fire(command, 'preExecuted', action);
  13363. }
  13364. this._fire(command, 'execute', action);
  13365. // execute
  13366. this._markDirty(handler.execute(context));
  13367. // log to stack
  13368. this._executedAction(action, redo);
  13369. this._fire(command, 'executed', action);
  13370. if (!redo) {
  13371. this._fire(command, 'postExecute', action);
  13372. if (handler.postExecute) {
  13373. handler.postExecute(context);
  13374. }
  13375. this._fire(command, 'postExecuted', action);
  13376. }
  13377. this._popAction(action);
  13378. };
  13379. CommandStack.prototype._pushAction = function(action) {
  13380. var execution = this._currentExecution,
  13381. actions = execution.actions;
  13382. var baseAction = actions[0];
  13383. if (!action.id) {
  13384. action.id = (baseAction && baseAction.id) || this._createId();
  13385. }
  13386. actions.push(action);
  13387. };
  13388. CommandStack.prototype._popAction = function() {
  13389. var execution = this._currentExecution,
  13390. actions = execution.actions,
  13391. dirty = execution.dirty;
  13392. actions.pop();
  13393. if (!actions.length) {
  13394. this._eventBus.fire('elements.changed', { elements: unique(dirty) });
  13395. dirty.length = 0;
  13396. this._fire('changed');
  13397. }
  13398. };
  13399. CommandStack.prototype._markDirty = function(elements) {
  13400. var execution = this._currentExecution;
  13401. if (!elements) {
  13402. return;
  13403. }
  13404. elements = isArray(elements) ? elements : [ elements ];
  13405. execution.dirty = execution.dirty.concat(elements);
  13406. };
  13407. CommandStack.prototype._executedAction = function(action, redo) {
  13408. var stackIdx = ++this._stackIdx;
  13409. if (!redo) {
  13410. this._stack.splice(stackIdx, this._stack.length, action);
  13411. }
  13412. };
  13413. CommandStack.prototype._revertedAction = function(action) {
  13414. this._stackIdx--;
  13415. };
  13416. CommandStack.prototype._getHandler = function(command) {
  13417. return this._handlerMap[command];
  13418. };
  13419. CommandStack.prototype._setHandler = function(command, handler) {
  13420. if (!command || !handler) {
  13421. throw new Error('command and handler required');
  13422. }
  13423. if (this._handlerMap[command]) {
  13424. throw new Error('overriding handler for command <' + command + '>');
  13425. }
  13426. this._handlerMap[command] = handler;
  13427. };
  13428. },{"211":211,"330":330,"339":339,"84":84}],80:[function(_dereq_,module,exports){
  13429. module.exports = {
  13430. commandStack: [ 'type', _dereq_(79) ]
  13431. };
  13432. },{"79":79}],81:[function(_dereq_,module,exports){
  13433. 'use strict';
  13434. var isNumber = _dereq_(333),
  13435. assign = _dereq_(339),
  13436. forEach = _dereq_(218),
  13437. every = _dereq_(215);
  13438. var Collections = _dereq_(184);
  13439. var Snap = _dereq_(200);
  13440. function round(number, resolution) {
  13441. return Math.round(number * resolution) / resolution;
  13442. }
  13443. function ensurePx(number) {
  13444. return isNumber(number) ? number + 'px' : number;
  13445. }
  13446. /**
  13447. * Creates a HTML container element for a SVG element with
  13448. * the given configuration
  13449. *
  13450. * @param {Object} options
  13451. * @return {HTMLElement} the container element
  13452. */
  13453. function createContainer(options) {
  13454. options = assign({}, { width: '100%', height: '100%' }, options);
  13455. var container = options.container || document.body;
  13456. // create a <div> around the svg element with the respective size
  13457. // this way we can always get the correct container size
  13458. // (this is impossible for <svg> elements at the moment)
  13459. var parent = document.createElement('div');
  13460. parent.setAttribute('class', 'djs-container');
  13461. assign(parent.style, {
  13462. position: 'relative',
  13463. overflow: 'hidden',
  13464. width: ensurePx(options.width),
  13465. height: ensurePx(options.height)
  13466. });
  13467. container.appendChild(parent);
  13468. return parent;
  13469. }
  13470. function createGroup(parent, cls) {
  13471. return parent.group().attr({ 'class' : cls });
  13472. }
  13473. var BASE_LAYER = 'base';
  13474. var REQUIRED_MODEL_ATTRS = {
  13475. shape: [ 'x', 'y', 'width', 'height' ],
  13476. connection: [ 'waypoints' ]
  13477. };
  13478. /**
  13479. * The main drawing canvas.
  13480. *
  13481. * @class
  13482. * @constructor
  13483. *
  13484. * @emits Canvas#canvas.init
  13485. *
  13486. * @param {Object} config
  13487. * @param {EventBus} eventBus
  13488. * @param {GraphicsFactory} graphicsFactory
  13489. * @param {ElementRegistry} elementRegistry
  13490. */
  13491. function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
  13492. this._eventBus = eventBus;
  13493. this._elementRegistry = elementRegistry;
  13494. this._graphicsFactory = graphicsFactory;
  13495. this._init(config || {});
  13496. }
  13497. Canvas.$inject = [ 'config.canvas', 'eventBus', 'graphicsFactory', 'elementRegistry' ];
  13498. module.exports = Canvas;
  13499. Canvas.prototype._init = function(config) {
  13500. // Creates a <svg> element that is wrapped into a <div>.
  13501. // This way we are always able to correctly figure out the size of the svg element
  13502. // by querying the parent node.
  13503. //
  13504. // (It is not possible to get the size of a svg element cross browser @ 2014-04-01)
  13505. //
  13506. // <div class="djs-container" style="width: {desired-width}, height: {desired-height}">
  13507. // <svg width="100%" height="100%">
  13508. // ...
  13509. // </svg>
  13510. // </div>
  13511. // html container
  13512. var eventBus = this._eventBus,
  13513. container = createContainer(config),
  13514. svg = Snap.createSnapAt('100%', '100%', container),
  13515. viewport = createGroup(svg, 'viewport'),
  13516. self = this;
  13517. this._container = container;
  13518. this._svg = svg;
  13519. this._viewport = viewport;
  13520. this._layers = {};
  13521. eventBus.on('diagram.init', function(event) {
  13522. /**
  13523. * An event indicating that the canvas is ready to be drawn on.
  13524. *
  13525. * @memberOf Canvas
  13526. *
  13527. * @event canvas.init
  13528. *
  13529. * @type {Object}
  13530. * @property {Snap<SVGSVGElement>} svg the created svg element
  13531. * @property {Snap<SVGGroup>} viewport the direct parent of diagram elements and shapes
  13532. */
  13533. eventBus.fire('canvas.init', { svg: svg, viewport: viewport });
  13534. });
  13535. eventBus.on('diagram.destroy', function() {
  13536. var parent = self._container.parentNode;
  13537. if (parent) {
  13538. parent.removeChild(container);
  13539. }
  13540. eventBus.fire('canvas.destroy', { svg: self._svg, viewport: self._viewport });
  13541. self._svg.remove();
  13542. self._svg = self._container = self._layers = self._viewport = null;
  13543. });
  13544. };
  13545. /**
  13546. * Returns the default layer on which
  13547. * all elements are drawn.
  13548. *
  13549. * @returns {Snap<SVGGroup>}
  13550. */
  13551. Canvas.prototype.getDefaultLayer = function() {
  13552. return this.getLayer(BASE_LAYER);
  13553. };
  13554. /**
  13555. * Returns a layer that is used to draw elements
  13556. * or annotations on it.
  13557. *
  13558. * @param {String} name
  13559. *
  13560. * @returns {Snap<SVGGroup>}
  13561. */
  13562. Canvas.prototype.getLayer = function(name) {
  13563. if (!name) {
  13564. throw new Error('must specify a name');
  13565. }
  13566. var layer = this._layers[name];
  13567. if (!layer) {
  13568. layer = this._layers[name] = createGroup(this._viewport, 'layer-' + name);
  13569. }
  13570. return layer;
  13571. };
  13572. /**
  13573. * Returns the html element that encloses the
  13574. * drawing canvas.
  13575. *
  13576. * @return {DOMNode}
  13577. */
  13578. Canvas.prototype.getContainer = function() {
  13579. return this._container;
  13580. };
  13581. /////////////// markers ///////////////////////////////////
  13582. Canvas.prototype._updateMarker = function(element, marker, add) {
  13583. var container;
  13584. if (!element.id) {
  13585. element = this._elementRegistry.get(element);
  13586. }
  13587. // we need to access all
  13588. container = this._elementRegistry._elements[element.id];
  13589. if (!container) {
  13590. return;
  13591. }
  13592. forEach([ container.gfx, container.secondaryGfx ], function(gfx) {
  13593. if (gfx) {
  13594. // invoke either addClass or removeClass based on mode
  13595. gfx[add ? 'addClass' : 'removeClass'](marker);
  13596. }
  13597. });
  13598. /**
  13599. * An event indicating that a marker has been updated for an element
  13600. *
  13601. * @event element.marker.update
  13602. * @type {Object}
  13603. * @property {djs.model.Element} element the shape
  13604. * @property {Object} gfx the graphical representation of the shape
  13605. * @property {String} marker
  13606. * @property {Boolean} add true if the marker was added, false if it got removed
  13607. */
  13608. this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add });
  13609. };
  13610. /**
  13611. * Adds a marker to an element (basically a css class).
  13612. *
  13613. * Fires the element.marker.update event, making it possible to
  13614. * integrate extension into the marker life-cycle, too.
  13615. *
  13616. * @example
  13617. * canvas.addMarker('foo', 'some-marker');
  13618. *
  13619. * var fooGfx = canvas.getGraphics('foo');
  13620. *
  13621. * fooGfx; // <g class="... some-marker"> ... </g>
  13622. *
  13623. * @param {String|djs.model.Base} element
  13624. * @param {String} marker
  13625. */
  13626. Canvas.prototype.addMarker = function(element, marker) {
  13627. this._updateMarker(element, marker, true);
  13628. };
  13629. /**
  13630. * Remove a marker from an element.
  13631. *
  13632. * Fires the element.marker.update event, making it possible to
  13633. * integrate extension into the marker life-cycle, too.
  13634. *
  13635. * @param {String|djs.model.Base} element
  13636. * @param {String} marker
  13637. */
  13638. Canvas.prototype.removeMarker = function(element, marker) {
  13639. this._updateMarker(element, marker, false);
  13640. };
  13641. /**
  13642. * Check the existence of a marker on element.
  13643. *
  13644. * @param {String|djs.model.Base} element
  13645. * @param {String} marker
  13646. */
  13647. Canvas.prototype.hasMarker = function(element, marker) {
  13648. if (!element.id) {
  13649. element = this._elementRegistry.get(element);
  13650. }
  13651. var gfx = this.getGraphics(element);
  13652. return gfx && gfx.hasClass(marker);
  13653. };
  13654. /**
  13655. * Toggles a marker on an element.
  13656. *
  13657. * Fires the element.marker.update event, making it possible to
  13658. * integrate extension into the marker life-cycle, too.
  13659. *
  13660. * @param {String|djs.model.Base} element
  13661. * @param {String} marker
  13662. */
  13663. Canvas.prototype.toggleMarker = function(element, marker) {
  13664. if(this.hasMarker(element, marker)) {
  13665. this.removeMarker(element, marker);
  13666. } else {
  13667. this.addMarker(element, marker);
  13668. }
  13669. };
  13670. Canvas.prototype.getRootElement = function() {
  13671. if (!this._rootElement) {
  13672. this.setRootElement({ id: '__implicitroot' });
  13673. }
  13674. return this._rootElement;
  13675. };
  13676. //////////////// root element handling ///////////////////////////
  13677. /**
  13678. * Sets a given element as the new root element for the canvas
  13679. * and returns the new root element.
  13680. *
  13681. * @param {Object|djs.model.Root} element
  13682. * @param {Boolean} [override] whether to override the current root element, if any
  13683. *
  13684. * @return {Object|djs.model.Root} new root element
  13685. */
  13686. Canvas.prototype.setRootElement = function(element, override) {
  13687. this._ensureValid('root', element);
  13688. var oldRoot = this._rootElement,
  13689. elementRegistry = this._elementRegistry,
  13690. eventBus = this._eventBus;
  13691. if (oldRoot) {
  13692. if (!override) {
  13693. throw new Error('rootElement already set, need to specify override');
  13694. }
  13695. // simulate element remove event sequence
  13696. eventBus.fire('root.remove', { element: oldRoot });
  13697. eventBus.fire('root.removed', { element: oldRoot });
  13698. elementRegistry.remove(oldRoot);
  13699. }
  13700. var gfx = this.getDefaultLayer();
  13701. // resemble element add event sequence
  13702. eventBus.fire('root.add', { element: element });
  13703. elementRegistry.add(element, gfx, this._svg);
  13704. eventBus.fire('root.added', { element: element, gfx: gfx });
  13705. this._rootElement = element;
  13706. return element;
  13707. };
  13708. ///////////// add functionality ///////////////////////////////
  13709. Canvas.prototype._ensureValid = function(type, element) {
  13710. if (!element.id) {
  13711. throw new Error('element must have an id');
  13712. }
  13713. if (this._elementRegistry.get(element.id)) {
  13714. throw new Error('element with id ' + element.id + ' already exists');
  13715. }
  13716. var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
  13717. var valid = every(requiredAttrs, function(attr) {
  13718. return typeof element[attr] !== 'undefined';
  13719. });
  13720. if (!valid) {
  13721. throw new Error(
  13722. 'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
  13723. }
  13724. };
  13725. Canvas.prototype._setParent = function(element, parent, idx) {
  13726. Collections.add(parent.children, element, idx);
  13727. element.parent = parent;
  13728. };
  13729. /**
  13730. * Adds an element to the canvas.
  13731. *
  13732. * This wires the parent <-> child relationship between the element and
  13733. * a explicitly specified parent or an implicit root element.
  13734. *
  13735. * During add it emits the events
  13736. *
  13737. * * <{type}.add> (element, parent)
  13738. * * <{type}.added> (element, gfx)
  13739. *
  13740. * Extensions may hook into these events to perform their magic.
  13741. *
  13742. * @param {String} type
  13743. * @param {Object|djs.model.Base} element
  13744. * @param {Object|djs.model.Base} [parent]
  13745. *
  13746. * @return {Object|djs.model.Base} the added element
  13747. */
  13748. Canvas.prototype._addElement = function(type, element, parent) {
  13749. parent = parent || this.getRootElement();
  13750. var eventBus = this._eventBus,
  13751. graphicsFactory = this._graphicsFactory,
  13752. idx;
  13753. this._ensureValid(type, element);
  13754. eventBus.fire(type + '.add', { element: element, parent: parent });
  13755. this._setParent(element, parent, idx);
  13756. // create graphics
  13757. var gfx = graphicsFactory.create(type, element);
  13758. this._elementRegistry.add(element, gfx);
  13759. // update its visual
  13760. graphicsFactory.update(type, element, gfx);
  13761. eventBus.fire(type + '.added', { element: element, gfx: gfx });
  13762. return element;
  13763. };
  13764. /**
  13765. * Adds a shape to the canvas
  13766. *
  13767. * @param {Object|djs.model.Shape} shape to add to the diagram
  13768. * @param {djs.model.Base} [parent]
  13769. *
  13770. * @return {djs.model.Shape} the added shape
  13771. */
  13772. Canvas.prototype.addShape = function(shape, parent) {
  13773. return this._addElement('shape', shape, parent);
  13774. };
  13775. /**
  13776. * Adds a connection to the canvas
  13777. *
  13778. * @param {Object|djs.model.Connection} connection to add to the diagram
  13779. * @param {djs.model.Base} [parent]
  13780. *
  13781. * @return {djs.model.Connection} the added connection
  13782. */
  13783. Canvas.prototype.addConnection = function(connection, parent) {
  13784. return this._addElement('connection', connection, parent);
  13785. };
  13786. /**
  13787. * Internal remove element
  13788. */
  13789. Canvas.prototype._removeElement = function(element, type) {
  13790. var elementRegistry = this._elementRegistry,
  13791. graphicsFactory = this._graphicsFactory,
  13792. eventBus = this._eventBus;
  13793. element = elementRegistry.get(element.id || element);
  13794. if (!element) {
  13795. // element was removed already
  13796. return;
  13797. }
  13798. eventBus.fire(type + '.remove', { element: element });
  13799. graphicsFactory.remove(element);
  13800. // unset parent <-> child relationship
  13801. Collections.remove(element.parent && element.parent.children, element);
  13802. element.parent = null;
  13803. eventBus.fire(type + '.removed', { element: element });
  13804. elementRegistry.remove(element);
  13805. return element;
  13806. };
  13807. /**
  13808. * Removes a shape from the canvas
  13809. *
  13810. * @param {String|djs.model.Shape} shape or shape id to be removed
  13811. *
  13812. * @return {djs.model.Shape} the removed shape
  13813. */
  13814. Canvas.prototype.removeShape = function(shape) {
  13815. /**
  13816. * An event indicating that a shape is about to be removed from the canvas.
  13817. *
  13818. * @memberOf Canvas
  13819. *
  13820. * @event shape.remove
  13821. * @type {Object}
  13822. * @property {djs.model.Shape} element the shape descriptor
  13823. * @property {Object} gfx the graphical representation of the shape
  13824. */
  13825. /**
  13826. * An event indicating that a shape has been removed from the canvas.
  13827. *
  13828. * @memberOf Canvas
  13829. *
  13830. * @event shape.removed
  13831. * @type {Object}
  13832. * @property {djs.model.Shape} element the shape descriptor
  13833. * @property {Object} gfx the graphical representation of the shape
  13834. */
  13835. return this._removeElement(shape, 'shape');
  13836. };
  13837. /**
  13838. * Removes a connection from the canvas
  13839. *
  13840. * @param {String|djs.model.Connection} connection or connection id to be removed
  13841. *
  13842. * @return {djs.model.Connection} the removed connection
  13843. */
  13844. Canvas.prototype.removeConnection = function(connection) {
  13845. /**
  13846. * An event indicating that a connection is about to be removed from the canvas.
  13847. *
  13848. * @memberOf Canvas
  13849. *
  13850. * @event connection.remove
  13851. * @type {Object}
  13852. * @property {djs.model.Connection} element the connection descriptor
  13853. * @property {Object} gfx the graphical representation of the connection
  13854. */
  13855. /**
  13856. * An event indicating that a connection has been removed from the canvas.
  13857. *
  13858. * @memberOf Canvas
  13859. *
  13860. * @event connection.removed
  13861. * @type {Object}
  13862. * @property {djs.model.Connection} element the connection descriptor
  13863. * @property {Object} gfx the graphical representation of the connection
  13864. */
  13865. return this._removeElement(connection, 'connection');
  13866. };
  13867. /**
  13868. * Sends a shape to the front.
  13869. *
  13870. * This method takes parent / child relationships between shapes into account
  13871. * and makes sure that children are properly handled, too.
  13872. *
  13873. * @param {djs.model.Shape} shape descriptor of the shape to be sent to front
  13874. * @param {boolean} [bubble=true] whether to send parent shapes to front, too
  13875. */
  13876. Canvas.prototype.sendToFront = function(shape, bubble) {
  13877. if (bubble !== false) {
  13878. bubble = true;
  13879. }
  13880. if (bubble && shape.parent) {
  13881. this.sendToFront(shape.parent);
  13882. }
  13883. forEach(shape.children, function(child) {
  13884. this.sendToFront(child, false);
  13885. }, this);
  13886. var gfx = this.getGraphics(shape),
  13887. gfxParent = gfx.parent();
  13888. gfx.remove().appendTo(gfxParent);
  13889. };
  13890. /**
  13891. * Return the graphical object underlaying a certain diagram element
  13892. *
  13893. * @param {String|djs.model.Base} element descriptor of the element
  13894. * @param {Boolean} [secondary=false] whether to return the secondary connected element
  13895. *
  13896. * @return {SVGElement}
  13897. */
  13898. Canvas.prototype.getGraphics = function(element, secondary) {
  13899. return this._elementRegistry.getGraphics(element, secondary);
  13900. };
  13901. Canvas.prototype._fireViewboxChange = function() {
  13902. this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox(false) });
  13903. };
  13904. /**
  13905. * Gets or sets the view box of the canvas, i.e. the area that is currently displayed
  13906. *
  13907. * @param {Object} [box] the new view box to set
  13908. * @param {Number} box.x the top left X coordinate of the canvas visible in view box
  13909. * @param {Number} box.y the top left Y coordinate of the canvas visible in view box
  13910. * @param {Number} box.width the visible width
  13911. * @param {Number} box.height
  13912. *
  13913. * @example
  13914. *
  13915. * canvas.viewbox({ x: 100, y: 100, width: 500, height: 500 })
  13916. *
  13917. * // sets the visible area of the diagram to (100|100) -> (600|100)
  13918. * // and and scales it according to the diagram width
  13919. *
  13920. * @return {Object} the current view box
  13921. */
  13922. Canvas.prototype.viewbox = function(box) {
  13923. if (box === undefined && this._cachedViewbox) {
  13924. return this._cachedViewbox;
  13925. }
  13926. var viewport = this._viewport,
  13927. innerBox,
  13928. outerBox = this.getSize(),
  13929. matrix,
  13930. scale,
  13931. x, y;
  13932. if (!box) {
  13933. // compute the inner box based on the
  13934. // diagrams default layer. This allows us to exclude
  13935. // external components, such as overlays
  13936. innerBox = this.getDefaultLayer().getBBox(true);
  13937. matrix = viewport.transform().localMatrix;
  13938. scale = round(matrix.a, 1000);
  13939. x = round(-matrix.e || 0, 1000);
  13940. y = round(-matrix.f || 0, 1000);
  13941. box = this._cachedViewbox = {
  13942. x: x ? x / scale : 0,
  13943. y: y ? y / scale : 0,
  13944. width: outerBox.width / scale,
  13945. height: outerBox.height / scale,
  13946. scale: scale,
  13947. inner: {
  13948. width: innerBox.width,
  13949. height: innerBox.height,
  13950. x: innerBox.x,
  13951. y: innerBox.y
  13952. },
  13953. outer: outerBox
  13954. };
  13955. return box;
  13956. } else {
  13957. scale = Math.min(outerBox.width / box.width, outerBox.height / box.height);
  13958. matrix = new Snap.Matrix().scale(scale).translate(-box.x, -box.y);
  13959. viewport.transform(matrix);
  13960. this._fireViewboxChange();
  13961. }
  13962. return box;
  13963. };
  13964. /**
  13965. * Gets or sets the scroll of the canvas.
  13966. *
  13967. * @param {Object} [delta] the new scroll to apply.
  13968. *
  13969. * @param {Number} [delta.dx]
  13970. * @param {Number} [delta.dy]
  13971. */
  13972. Canvas.prototype.scroll = function(delta) {
  13973. var node = this._viewport.node;
  13974. var matrix = node.getCTM();
  13975. if (delta) {
  13976. delta = assign({ dx: 0, dy: 0 }, delta || {});
  13977. matrix = this._svg.node.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
  13978. setCTM(node, matrix);
  13979. this._fireViewboxChange();
  13980. }
  13981. return { x: matrix.e, y: matrix.f };
  13982. };
  13983. /**
  13984. * Gets or sets the current zoom of the canvas, optionally zooming to the specified position.
  13985. *
  13986. * @param {String|Number} [newScale] the new zoom level, either a number, i.e. 0.9,
  13987. * or `fit-viewport` to adjust the size to fit the current viewport
  13988. * @param {String|Point} [center] the reference point { x: .., y: ..} to zoom to, 'auto' to zoom into mid or null
  13989. *
  13990. * @return {Number} the current scale
  13991. */
  13992. Canvas.prototype.zoom = function(newScale, center) {
  13993. if (newScale === 'fit-viewport') {
  13994. return this._fitViewport(center);
  13995. }
  13996. var vbox = this.viewbox(),
  13997. outer,
  13998. matrix;
  13999. if (newScale === undefined) {
  14000. return vbox.scale;
  14001. }
  14002. if (typeof center !== 'object') {
  14003. outer = vbox.outer;
  14004. center = {
  14005. x: outer.width / 2,
  14006. y: outer.height / 2
  14007. };
  14008. }
  14009. matrix = this._setZoom(newScale, center);
  14010. this._fireViewboxChange();
  14011. return round(matrix.a, 1000);
  14012. };
  14013. function setCTM(node, m) {
  14014. var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')';
  14015. node.setAttribute('transform', mstr);
  14016. }
  14017. Canvas.prototype._fitViewport = function(center) {
  14018. var vbox = this.viewbox(),
  14019. outer = vbox.outer,
  14020. inner = vbox.inner,
  14021. newScale,
  14022. newViewbox;
  14023. // display the complete diagram without zooming in.
  14024. // instead of relying on internal zoom, we perform a
  14025. // hard reset on the canvas viewbox to realize this
  14026. //
  14027. // if diagram does not need to be zoomed in, we focus it around
  14028. // the diagram origin instead
  14029. if (inner.x >= 0 &&
  14030. inner.y >= 0 &&
  14031. inner.x + inner.width <= outer.width &&
  14032. inner.y + inner.height <= outer.height &&
  14033. !center) {
  14034. newViewbox = {
  14035. x: 0,
  14036. y: 0,
  14037. width: Math.max(inner.width + inner.x, outer.width),
  14038. height: Math.max(inner.height + inner.y, outer.height)
  14039. };
  14040. } else {
  14041. newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height);
  14042. newViewbox = {
  14043. x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0),
  14044. y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0),
  14045. width: outer.width / newScale,
  14046. height: outer.height / newScale
  14047. };
  14048. }
  14049. this.viewbox(newViewbox);
  14050. return this.viewbox().scale;
  14051. };
  14052. Canvas.prototype._setZoom = function(scale, center) {
  14053. var svg = this._svg.node,
  14054. viewport = this._viewport.node;
  14055. var matrix = svg.createSVGMatrix();
  14056. var point = svg.createSVGPoint();
  14057. var centerPoint,
  14058. originalPoint,
  14059. currentMatrix,
  14060. scaleMatrix,
  14061. newMatrix;
  14062. currentMatrix = viewport.getCTM();
  14063. var currentScale = currentMatrix.a;
  14064. if (center) {
  14065. centerPoint = assign(point, center);
  14066. // revert applied viewport transformations
  14067. originalPoint = centerPoint.matrixTransform(currentMatrix.inverse());
  14068. // create scale matrix
  14069. scaleMatrix = matrix
  14070. .translate(originalPoint.x, originalPoint.y)
  14071. .scale(1 / currentScale * scale)
  14072. .translate(-originalPoint.x, -originalPoint.y);
  14073. newMatrix = currentMatrix.multiply(scaleMatrix);
  14074. } else {
  14075. newMatrix = matrix.scale(scale);
  14076. }
  14077. setCTM(this._viewport.node, newMatrix);
  14078. return newMatrix;
  14079. };
  14080. /**
  14081. * Returns the size of the canvas
  14082. *
  14083. * @return {Dimensions}
  14084. */
  14085. Canvas.prototype.getSize = function () {
  14086. return {
  14087. width: this._container.clientWidth,
  14088. height: this._container.clientHeight
  14089. };
  14090. };
  14091. /**
  14092. * Return the absolute bounding box for the given element
  14093. *
  14094. * The absolute bounding box may be used to display overlays in the
  14095. * callers (browser) coordinate system rather than the zoomed in/out
  14096. * canvas coordinates.
  14097. *
  14098. * @param {ElementDescriptor} element
  14099. * @return {Bounds} the absolute bounding box
  14100. */
  14101. Canvas.prototype.getAbsoluteBBox = function(element) {
  14102. var vbox = this.viewbox();
  14103. var bbox;
  14104. // connection
  14105. // use svg bbox
  14106. if (element.waypoints) {
  14107. var gfx = this.getGraphics(element);
  14108. var transformBBox = gfx.getBBox(true);
  14109. bbox = gfx.getBBox();
  14110. bbox.x -= transformBBox.x;
  14111. bbox.y -= transformBBox.y;
  14112. bbox.width += 2 * transformBBox.x;
  14113. bbox.height += 2 * transformBBox.y;
  14114. }
  14115. // shapes
  14116. // use data
  14117. else {
  14118. bbox = element;
  14119. }
  14120. var x = bbox.x * vbox.scale - vbox.x * vbox.scale;
  14121. var y = bbox.y * vbox.scale - vbox.y * vbox.scale;
  14122. var width = bbox.width * vbox.scale;
  14123. var height = bbox.height * vbox.scale;
  14124. return {
  14125. x: x,
  14126. y: y,
  14127. width: width,
  14128. height: height
  14129. };
  14130. };
  14131. },{"184":184,"200":200,"215":215,"218":218,"333":333,"339":339}],82:[function(_dereq_,module,exports){
  14132. 'use strict';
  14133. var Model = _dereq_(176);
  14134. /**
  14135. * A factory for diagram-js shapes
  14136. */
  14137. function ElementFactory() {
  14138. this._uid = 12;
  14139. }
  14140. module.exports = ElementFactory;
  14141. ElementFactory.prototype.createRoot = function(attrs) {
  14142. return this.create('root', attrs);
  14143. };
  14144. ElementFactory.prototype.createLabel = function(attrs) {
  14145. return this.create('label', attrs);
  14146. };
  14147. ElementFactory.prototype.createShape = function(attrs) {
  14148. return this.create('shape', attrs);
  14149. };
  14150. ElementFactory.prototype.createConnection = function(attrs) {
  14151. return this.create('connection', attrs);
  14152. };
  14153. /**
  14154. * Create a model element with the given type and
  14155. * a number of pre-set attributes.
  14156. *
  14157. * @param {String} type
  14158. * @param {Object} attrs
  14159. * @return {djs.model.Base} the newly created model instance
  14160. */
  14161. ElementFactory.prototype.create = function(type, attrs) {
  14162. attrs = attrs || {};
  14163. if (!attrs.id) {
  14164. attrs.id = type + '_' + (this._uid++);
  14165. }
  14166. return Model.create(type, attrs);
  14167. };
  14168. },{"176":176}],83:[function(_dereq_,module,exports){
  14169. 'use strict';
  14170. var ELEMENT_ID = 'data-element-id';
  14171. /**
  14172. * @class
  14173. *
  14174. * A registry that keeps track of all shapes in the diagram.
  14175. */
  14176. function ElementRegistry() {
  14177. this._elements = {};
  14178. }
  14179. module.exports = ElementRegistry;
  14180. /**
  14181. * Register a pair of (element, gfx, (secondaryGfx)).
  14182. *
  14183. * @param {djs.model.Base} element
  14184. * @param {Snap<SVGElement>} gfx
  14185. * @param {Snap<SVGElement>} [secondaryGfx] optional other element to register, too
  14186. */
  14187. ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
  14188. var id = element.id;
  14189. this._validateId(id);
  14190. // associate dom node with element
  14191. gfx.attr(ELEMENT_ID, id);
  14192. if (secondaryGfx) {
  14193. secondaryGfx.attr(ELEMENT_ID, id);
  14194. }
  14195. this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx };
  14196. };
  14197. /**
  14198. * Removes an element from the registry.
  14199. *
  14200. * @param {djs.model.Base} element
  14201. */
  14202. ElementRegistry.prototype.remove = function(element) {
  14203. var elements = this._elements,
  14204. id = element.id || element,
  14205. container = id && elements[id];
  14206. if (container) {
  14207. // unset element id on gfx
  14208. container.gfx.attr(ELEMENT_ID, null);
  14209. if (container.secondaryGfx) {
  14210. container.secondaryGfx.attr(ELEMENT_ID, null);
  14211. }
  14212. delete elements[id];
  14213. }
  14214. };
  14215. /**
  14216. * Update the id of an element
  14217. *
  14218. * @param {djs.model.Base} element
  14219. * @param {String} newId
  14220. */
  14221. ElementRegistry.prototype.updateId = function(element, newId) {
  14222. this._validateId(newId);
  14223. if (typeof element === 'string') {
  14224. element = this.get(element);
  14225. }
  14226. var gfx = this.getGraphics(element),
  14227. secondaryGfx = this.getGraphics(element, true);
  14228. this.remove(element);
  14229. element.id = newId;
  14230. this.add(element, gfx, secondaryGfx);
  14231. };
  14232. /**
  14233. * Return the model element for a given id or graphics.
  14234. *
  14235. * @example
  14236. *
  14237. * elementRegistry.get('SomeElementId_1');
  14238. * elementRegistry.get(gfx);
  14239. *
  14240. *
  14241. * @param {String|SVGElement} filter for selecting the element
  14242. *
  14243. * @return {djs.model.Base}
  14244. */
  14245. ElementRegistry.prototype.get = function(filter) {
  14246. var id;
  14247. if (typeof filter === 'string') {
  14248. id = filter;
  14249. } else {
  14250. id = filter && filter.attr(ELEMENT_ID);
  14251. }
  14252. var container = this._elements[id];
  14253. return container && container.element;
  14254. };
  14255. /**
  14256. * Return all elements that match a given filter function.
  14257. *
  14258. * @param {Function} fn
  14259. *
  14260. * @return {Array<djs.model.Base>}
  14261. */
  14262. ElementRegistry.prototype.filter = function(fn) {
  14263. var filtered = [];
  14264. this.forEach(function(element, gfx) {
  14265. if(fn(element, gfx)) {
  14266. filtered.push(element);
  14267. }
  14268. });
  14269. return filtered;
  14270. };
  14271. /**
  14272. * Return all rendered model elements.
  14273. *
  14274. * @return {Array<djs.model.Base>}
  14275. */
  14276. ElementRegistry.prototype.getAll = function() {
  14277. return this.filter(function(e) { return e; });
  14278. };
  14279. /**
  14280. * Iterate over all diagram elements.
  14281. *
  14282. * @param {Function} fn
  14283. */
  14284. ElementRegistry.prototype.forEach = function(fn) {
  14285. var map = this._elements;
  14286. Object.keys(map).forEach(function(id) {
  14287. var container = map[id],
  14288. element = container.element,
  14289. gfx = container.gfx;
  14290. return fn(element, gfx);
  14291. });
  14292. };
  14293. /**
  14294. * Return the graphical representation of an element or its id.
  14295. *
  14296. * @example
  14297. * elementRegistry.getGraphics('SomeElementId_1');
  14298. * elementRegistry.getGraphics(rootElement); // <g ...>
  14299. *
  14300. * elementRegistry.getGraphics(rootElement, true); // <svg ...>
  14301. *
  14302. *
  14303. * @param {String|djs.model.Base} filter
  14304. * @param {Boolean} [secondary=false] whether to return the secondary connected element
  14305. *
  14306. * @return {SVGElement}
  14307. */
  14308. ElementRegistry.prototype.getGraphics = function(filter, secondary) {
  14309. var id = filter.id || filter;
  14310. var container = this._elements[id];
  14311. return container && (secondary ? container.secondaryGfx : container.gfx);
  14312. };
  14313. /**
  14314. * Validate the suitability of the given id and signals a problem
  14315. * with an exception.
  14316. *
  14317. * @param {String} id
  14318. *
  14319. * @throws {Error} if id is empty or already assigned
  14320. */
  14321. ElementRegistry.prototype._validateId = function(id) {
  14322. if (!id) {
  14323. throw new Error('element must have an id');
  14324. }
  14325. if (this._elements[id]) {
  14326. throw new Error('element with id ' + id + ' already added');
  14327. }
  14328. };
  14329. },{}],84:[function(_dereq_,module,exports){
  14330. 'use strict';
  14331. var isFunction = _dereq_(331),
  14332. isArray = _dereq_(330),
  14333. isNumber = _dereq_(333),
  14334. assign = _dereq_(339);
  14335. var DEFAULT_PRIORITY = 1000;
  14336. /**
  14337. * A general purpose event bus.
  14338. *
  14339. * This component is used to communicate across a diagram instance.
  14340. * Other parts of a diagram can use it to listen to and broadcast events.
  14341. *
  14342. *
  14343. * ## Registering for Events
  14344. *
  14345. * The event bus provides the {@link EventBus#on} and {@link EventBus#once}
  14346. * methods to register for events. {@link EventBus#off} can be used to
  14347. * remove event registrations. Listeners receive an instance of {@link Event}
  14348. * as the first argument. It allows them to hook into the event execution.
  14349. *
  14350. * ```javascript
  14351. *
  14352. * // listen for event
  14353. * eventBus.on('foo', function(event) {
  14354. *
  14355. * // access event type
  14356. * event.type; // 'foo'
  14357. *
  14358. * // stop propagation to other listeners
  14359. * event.stopPropagation();
  14360. *
  14361. * // prevent event default
  14362. * event.preventDefault();
  14363. * });
  14364. *
  14365. * // listen for event with custom payload
  14366. * eventBus.on('bar', function(event, payload) {
  14367. * console.log(payload);
  14368. * });
  14369. *
  14370. * // listen for event returning value
  14371. * eventBus.on('foobar', function(event) {
  14372. *
  14373. * // stop event propagation + prevent default
  14374. * return false;
  14375. *
  14376. * // stop event propagation + return custom result
  14377. * return {
  14378. * complex: 'listening result'
  14379. * };
  14380. * });
  14381. *
  14382. *
  14383. * // listen with custom priority (default=1000, higher is better)
  14384. * eventBus.on('priorityfoo', 1500, function(event) {
  14385. * console.log('invoked first!');
  14386. * });
  14387. * ```
  14388. *
  14389. *
  14390. * ## Emitting Events
  14391. *
  14392. * Events can be emitted via the event bus using {@link EventBus#fire}.
  14393. *
  14394. * ```javascript
  14395. *
  14396. * // false indicates that the default action
  14397. * // was prevented by listeners
  14398. * if (eventBus.fire('foo') === false) {
  14399. * console.log('default has been prevented!');
  14400. * };
  14401. *
  14402. *
  14403. * // custom args + return value listener
  14404. * eventBus.on('sum', function(event, a, b) {
  14405. * return a + b;
  14406. * });
  14407. *
  14408. * // you can pass custom arguments + retrieve result values.
  14409. * var sum = eventBus.fire('sum', 1, 2);
  14410. * console.log(sum); // 3
  14411. * ```
  14412. */
  14413. function EventBus() {
  14414. this._listeners = {};
  14415. // cleanup on destroy
  14416. var self = this;
  14417. // destroy on lowest priority to allow
  14418. // message passing until the bitter end
  14419. this.on('diagram.destroy', 1, function() {
  14420. self._listeners = null;
  14421. });
  14422. }
  14423. module.exports = EventBus;
  14424. /**
  14425. * Register an event listener for events with the given name.
  14426. *
  14427. * The callback will be invoked with `event, ...additionalArguments`
  14428. * that have been passed to {@link EventBus#fire}.
  14429. *
  14430. * Returning false from a listener will prevent the events default action
  14431. * (if any is specified). To stop an event from being processed further in
  14432. * other listeners execute {@link Event#stopPropagation}.
  14433. *
  14434. * Returning anything but `undefined` from a listener will stop the listener propagation.
  14435. *
  14436. * @param {String|Array<String>} events
  14437. * @param {Number} [priority=1000] the priority in which this listener is called, larger is higher
  14438. * @param {Function} callback
  14439. */
  14440. EventBus.prototype.on = function(events, priority, callback) {
  14441. events = isArray(events) ? events : [ events ];
  14442. if (isFunction(priority)) {
  14443. callback = priority;
  14444. priority = DEFAULT_PRIORITY;
  14445. }
  14446. if (!isNumber(priority)) {
  14447. throw new Error('priority must be a number');
  14448. }
  14449. var self = this,
  14450. listener = { priority: priority, callback: callback };
  14451. events.forEach(function(e) {
  14452. self._addListener(e, listener);
  14453. });
  14454. };
  14455. /**
  14456. * Register an event listener that is executed only once.
  14457. *
  14458. * @param {String} event the event name to register for
  14459. * @param {Function} callback the callback to execute
  14460. */
  14461. EventBus.prototype.once = function(event, callback) {
  14462. var self = this;
  14463. function wrappedCallback() {
  14464. callback.apply(self, arguments);
  14465. self.off(event, wrappedCallback);
  14466. }
  14467. this.on(event, wrappedCallback);
  14468. };
  14469. /**
  14470. * Removes event listeners by event and callback.
  14471. *
  14472. * If no callback is given, all listeners for a given event name are being removed.
  14473. *
  14474. * @param {String} event
  14475. * @param {Function} [callback]
  14476. */
  14477. EventBus.prototype.off = function(event, callback) {
  14478. var listeners = this._getListeners(event),
  14479. listener, idx;
  14480. if (callback) {
  14481. // move through listeners from back to front
  14482. // and remove matching listeners
  14483. for (idx = listeners.length - 1; !!(listener = listeners[idx]); idx--) {
  14484. if (listener.callback === callback) {
  14485. listeners.splice(idx, 1);
  14486. }
  14487. }
  14488. } else {
  14489. // clear listeners
  14490. listeners.length = 0;
  14491. }
  14492. };
  14493. /**
  14494. * Fires a named event.
  14495. *
  14496. * @example
  14497. *
  14498. * // fire event by name
  14499. * events.fire('foo');
  14500. *
  14501. * // fire event object with nested type
  14502. * var event = { type: 'foo' };
  14503. * events.fire(event);
  14504. *
  14505. * // fire event with explicit type
  14506. * var event = { x: 10, y: 20 };
  14507. * events.fire('element.moved', event);
  14508. *
  14509. * // pass additional arguments to the event
  14510. * events.on('foo', function(event, bar) {
  14511. * alert(bar);
  14512. * });
  14513. *
  14514. * events.fire({ type: 'foo' }, 'I am bar!');
  14515. *
  14516. * @param {String} [name] the optional event name
  14517. * @param {Object} [event] the event object
  14518. * @param {...Object} additional arguments to be passed to the callback functions
  14519. *
  14520. * @return {Boolean} the events return value, if specified or false if the
  14521. * default action was prevented by listeners
  14522. */
  14523. EventBus.prototype.fire = function(type, data) {
  14524. var event,
  14525. originalType,
  14526. listeners, idx, listener,
  14527. returnValue,
  14528. args;
  14529. args = Array.prototype.slice.call(arguments);
  14530. if (typeof type === 'object') {
  14531. event = type;
  14532. type = event.type;
  14533. }
  14534. if (!type) {
  14535. throw new Error('no event type specified');
  14536. }
  14537. listeners = this._listeners[type];
  14538. if (!listeners) {
  14539. return;
  14540. }
  14541. // we make sure we fire instances of our home made
  14542. // events here. We wrap them only once, though
  14543. if (data instanceof Event) {
  14544. // we are fine, we alread have an event
  14545. event = data;
  14546. } else {
  14547. event = new Event();
  14548. event.init(data);
  14549. }
  14550. // ensure we pass the event as the first parameter
  14551. args[0] = event;
  14552. // original event type (in case we delegate)
  14553. originalType = event.type;
  14554. try {
  14555. // update event type before delegation
  14556. if (type !== originalType) {
  14557. event.type = type;
  14558. }
  14559. for (idx = 0; !!(listener = listeners[idx]); idx++) {
  14560. // handle stopped propagation
  14561. if (event.cancelBubble) {
  14562. break;
  14563. }
  14564. try {
  14565. // returning false prevents the default action
  14566. returnValue = event.returnValue = listener.callback.apply(null, args);
  14567. // stop propagation on return value
  14568. if (returnValue !== undefined) {
  14569. event.stopPropagation();
  14570. }
  14571. // prevent default on return false
  14572. if (returnValue === false) {
  14573. event.preventDefault();
  14574. }
  14575. } catch (e) {
  14576. if (!this.handleError(e)) {
  14577. console.error('unhandled error in event listener');
  14578. console.error(e.stack);
  14579. throw e;
  14580. }
  14581. }
  14582. }
  14583. } finally {
  14584. // reset event type after delegation
  14585. if (type !== originalType) {
  14586. event.type = originalType;
  14587. }
  14588. }
  14589. // set the return value to false if the event default
  14590. // got prevented and no other return value exists
  14591. if (returnValue === undefined && event.defaultPrevented) {
  14592. returnValue = false;
  14593. }
  14594. return returnValue;
  14595. };
  14596. EventBus.prototype.handleError = function(error) {
  14597. return this.fire('error', { error: error }) === false;
  14598. };
  14599. /*
  14600. * Add new listener with a certain priority to the list
  14601. * of listeners (for the given event).
  14602. *
  14603. * The semantics of listener registration / listener execution are
  14604. * first register, first serve: New listeners will always be inserted
  14605. * after existing listeners with the same priority.
  14606. *
  14607. * Example: Inserting two listeners with priority 1000 and 1300
  14608. *
  14609. * * before: [ 1500, 1500, 1000, 1000 ]
  14610. * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
  14611. *
  14612. * @param {String} event
  14613. * @param {Object} listener { priority, callback }
  14614. */
  14615. EventBus.prototype._addListener = function(event, newListener) {
  14616. var listeners = this._getListeners(event),
  14617. existingListener,
  14618. idx;
  14619. // ensure we order listeners by priority from
  14620. // 0 (high) to n > 0 (low)
  14621. for (idx = 0; !!(existingListener = listeners[idx]); idx++) {
  14622. if (existingListener.priority < newListener.priority) {
  14623. // prepend newListener at before existingListener
  14624. listeners.splice(idx, 0, newListener);
  14625. return;
  14626. }
  14627. }
  14628. listeners.push(newListener);
  14629. };
  14630. EventBus.prototype._getListeners = function(name) {
  14631. var listeners = this._listeners[name];
  14632. if (!listeners) {
  14633. this._listeners[name] = listeners = [];
  14634. }
  14635. return listeners;
  14636. };
  14637. /**
  14638. * A event that is emitted via the event bus.
  14639. */
  14640. function Event() { }
  14641. module.exports.Event = Event;
  14642. Event.prototype.stopPropagation = function() {
  14643. this.cancelBubble = true;
  14644. };
  14645. Event.prototype.preventDefault = function() {
  14646. this.defaultPrevented = true;
  14647. };
  14648. Event.prototype.init = function(data) {
  14649. assign(this, data || {});
  14650. };
  14651. },{"330":330,"331":331,"333":333,"339":339}],85:[function(_dereq_,module,exports){
  14652. 'use strict';
  14653. var forEach = _dereq_(218),
  14654. reduce = _dereq_(222);
  14655. var GraphicsUtil = _dereq_(189),
  14656. domClear = _dereq_(353);
  14657. /**
  14658. * A factory that creates graphical elements
  14659. *
  14660. * @param {Renderer} renderer
  14661. */
  14662. function GraphicsFactory(renderer, elementRegistry) {
  14663. this._renderer = renderer;
  14664. this._elementRegistry = elementRegistry;
  14665. }
  14666. GraphicsFactory.$inject = [ 'renderer', 'elementRegistry' ];
  14667. module.exports = GraphicsFactory;
  14668. GraphicsFactory.prototype._getChildren = function(element) {
  14669. var gfx = this._elementRegistry.getGraphics(element);
  14670. var childrenGfx;
  14671. // root element
  14672. if (!element.parent) {
  14673. childrenGfx = gfx;
  14674. } else {
  14675. childrenGfx = GraphicsUtil.getChildren(gfx);
  14676. if (!childrenGfx) {
  14677. childrenGfx = gfx.parent().group().attr('class', 'djs-children');
  14678. }
  14679. }
  14680. return childrenGfx;
  14681. };
  14682. /**
  14683. * Clears the graphical representation of the element and returns the
  14684. * cleared visual (the <g class="djs-visual" /> element).
  14685. */
  14686. GraphicsFactory.prototype._clear = function(gfx) {
  14687. var visual = GraphicsUtil.getVisual(gfx);
  14688. domClear(visual.node);
  14689. return visual;
  14690. };
  14691. /**
  14692. * Creates a gfx container for shapes and connections
  14693. *
  14694. * The layout is as follows:
  14695. *
  14696. * <g class="djs-group">
  14697. *
  14698. * <!-- the gfx -->
  14699. * <g class="djs-element djs-(shape|connection)">
  14700. * <g class="djs-visual">
  14701. * <!-- the renderer draws in here -->
  14702. * </g>
  14703. *
  14704. * <!-- extensions (overlays, click box, ...) goes here
  14705. * </g>
  14706. *
  14707. * <!-- the gfx child nodes -->
  14708. * <g class="djs-children"></g>
  14709. * </g>
  14710. *
  14711. * @param {Object} parent
  14712. * @param {String} type the type of the element, i.e. shape | connection
  14713. */
  14714. GraphicsFactory.prototype._createContainer = function(type, parentGfx) {
  14715. var outerGfx = parentGfx.group().attr('class', 'djs-group'),
  14716. gfx = outerGfx.group().attr('class', 'djs-element djs-' + type);
  14717. // create visual
  14718. gfx.group().attr('class', 'djs-visual');
  14719. return gfx;
  14720. };
  14721. GraphicsFactory.prototype.create = function(type, element) {
  14722. var childrenGfx = this._getChildren(element.parent);
  14723. return this._createContainer(type, childrenGfx);
  14724. };
  14725. GraphicsFactory.prototype.updateContainments = function(elements) {
  14726. var self = this,
  14727. elementRegistry = this._elementRegistry,
  14728. parents;
  14729. parents = reduce(elements, function(map, e) {
  14730. if (e.parent) {
  14731. map[e.parent.id] = e.parent;
  14732. }
  14733. return map;
  14734. }, {});
  14735. // update all parents of changed and reorganized their children
  14736. // in the correct order (as indicated in our model)
  14737. forEach(parents, function(parent) {
  14738. var childGfx = self._getChildren(parent),
  14739. children = parent.children;
  14740. if (!children) {
  14741. return;
  14742. }
  14743. forEach(children.slice().reverse(), function(c) {
  14744. var gfx = elementRegistry.getGraphics(c);
  14745. gfx.parent().prependTo(childGfx);
  14746. });
  14747. });
  14748. };
  14749. GraphicsFactory.prototype.update = function(type, element, gfx) {
  14750. // Do not update root element
  14751. if (!element.parent) {
  14752. return;
  14753. }
  14754. var visual = this._clear(gfx);
  14755. // redraw
  14756. if (type === 'shape') {
  14757. this._renderer.drawShape(visual, element);
  14758. // update positioning
  14759. gfx.translate(element.x, element.y);
  14760. } else
  14761. if (type === 'connection') {
  14762. this._renderer.drawConnection(visual, element);
  14763. } else {
  14764. throw new Error('unknown type: ' + type);
  14765. }
  14766. gfx.attr('display', element.hidden ? 'none' : 'block');
  14767. };
  14768. GraphicsFactory.prototype.remove = function(element) {
  14769. var gfx = this._elementRegistry.getGraphics(element);
  14770. // remove
  14771. gfx.parent().remove();
  14772. };
  14773. },{"189":189,"218":218,"222":222,"353":353}],86:[function(_dereq_,module,exports){
  14774. module.exports = {
  14775. __depends__: [ _dereq_(89) ],
  14776. __init__: [ 'canvas' ],
  14777. canvas: [ 'type', _dereq_(81) ],
  14778. elementRegistry: [ 'type', _dereq_(83) ],
  14779. elementFactory: [ 'type', _dereq_(82) ],
  14780. eventBus: [ 'type', _dereq_(84) ],
  14781. graphicsFactory: [ 'type', _dereq_(85) ]
  14782. };
  14783. },{"81":81,"82":82,"83":83,"84":84,"85":85,"89":89}],87:[function(_dereq_,module,exports){
  14784. 'use strict';
  14785. var Snap = _dereq_(200);
  14786. /**
  14787. * The default renderer used for shapes and connections.
  14788. *
  14789. * @param {Styles} styles
  14790. */
  14791. function Renderer(styles) {
  14792. this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
  14793. this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
  14794. }
  14795. module.exports = Renderer;
  14796. Renderer.$inject = ['styles'];
  14797. Renderer.prototype.drawShape = function drawShape(gfxGroup, data) {
  14798. return gfxGroup.rect(0, 0, data.width || 0, data.height || 0).attr(this.SHAPE_STYLE);
  14799. };
  14800. Renderer.prototype.drawConnection = function drawConnection(gfxGroup, data) {
  14801. return createLine(data.waypoints, this.CONNECTION_STYLE).appendTo(gfxGroup);
  14802. };
  14803. function componentsToPath(components) {
  14804. return components.join(',').replace(/,?([A-z]),?/g, '$1');
  14805. }
  14806. /**
  14807. * Gets the default SVG path of a shape that represents it's visual bounds.
  14808. *
  14809. * @param {djs.model.Shape} shape
  14810. * @return {string} svg path
  14811. */
  14812. Renderer.prototype.getShapePath = function getShapePath(shape) {
  14813. var x = shape.x,
  14814. y = shape.y,
  14815. width = shape.width,
  14816. height = shape.height;
  14817. var shapePath = [
  14818. ['M', x, y],
  14819. ['l', width, 0],
  14820. ['l', 0, height],
  14821. ['l', -width, 0],
  14822. ['z']
  14823. ];
  14824. return componentsToPath(shapePath);
  14825. };
  14826. /**
  14827. * Gets the default SVG path of a connection that represents it's visual bounds.
  14828. *
  14829. * @param {djs.model.Connection} connection
  14830. * @return {string} svg path
  14831. */
  14832. Renderer.prototype.getConnectionPath = function getConnectionPath(connection) {
  14833. var waypoints = connection.waypoints;
  14834. var idx, point, connectionPath = [];
  14835. for (idx = 0; !!(point = waypoints[idx]); idx++) {
  14836. // take invisible docking into account
  14837. // when creating the path
  14838. point = point.original || point;
  14839. connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]);
  14840. }
  14841. return componentsToPath(connectionPath);
  14842. };
  14843. function toSVGPoints(points) {
  14844. var result = '';
  14845. for (var i = 0, p; !!(p = points[i]); i++) {
  14846. result += p.x + ',' + p.y + ' ';
  14847. }
  14848. return result;
  14849. }
  14850. function createLine(points, attrs) {
  14851. return Snap.create('polyline', { points: toSVGPoints(points) }).attr(attrs || {});
  14852. }
  14853. function updateLine(gfx, points) {
  14854. return gfx.attr({ points: toSVGPoints(points) });
  14855. }
  14856. module.exports.createLine = createLine;
  14857. module.exports.updateLine = updateLine;
  14858. },{"200":200}],88:[function(_dereq_,module,exports){
  14859. 'use strict';
  14860. var isArray = _dereq_(330),
  14861. assign = _dereq_(339),
  14862. reduce = _dereq_(222);
  14863. /**
  14864. * A component that manages shape styles
  14865. */
  14866. function Styles() {
  14867. var defaultTraits = {
  14868. 'no-fill': {
  14869. fill: 'none'
  14870. },
  14871. 'no-border': {
  14872. strokeOpacity: 0.0
  14873. },
  14874. 'no-events': {
  14875. pointerEvents: 'none'
  14876. }
  14877. };
  14878. /**
  14879. * Builds a style definition from a className, a list of traits and an object of additional attributes.
  14880. *
  14881. * @param {String} className
  14882. * @param {Array<String>} traits
  14883. * @param {Object} additionalAttrs
  14884. *
  14885. * @return {Object} the style defintion
  14886. */
  14887. this.cls = function(className, traits, additionalAttrs) {
  14888. var attrs = this.style(traits, additionalAttrs);
  14889. return assign(attrs, { 'class': className });
  14890. };
  14891. /**
  14892. * Builds a style definition from a list of traits and an object of additional attributes.
  14893. *
  14894. * @param {Array<String>} traits
  14895. * @param {Object} additionalAttrs
  14896. *
  14897. * @return {Object} the style defintion
  14898. */
  14899. this.style = function(traits, additionalAttrs) {
  14900. if (!isArray(traits) && !additionalAttrs) {
  14901. additionalAttrs = traits;
  14902. traits = [];
  14903. }
  14904. var attrs = reduce(traits, function(attrs, t) {
  14905. return assign(attrs, defaultTraits[t] || {});
  14906. }, {});
  14907. return additionalAttrs ? assign(attrs, additionalAttrs) : attrs;
  14908. };
  14909. }
  14910. module.exports = Styles;
  14911. },{"222":222,"330":330,"339":339}],89:[function(_dereq_,module,exports){
  14912. module.exports = {
  14913. renderer: [ 'type', _dereq_(87) ],
  14914. styles: [ 'type', _dereq_(88) ]
  14915. };
  14916. },{"87":87,"88":88}],90:[function(_dereq_,module,exports){
  14917. 'use strict';
  14918. var forEach = _dereq_(218),
  14919. flatten = _dereq_(208),
  14920. filter = _dereq_(216),
  14921. groupBy = _dereq_(219),
  14922. map = _dereq_(221);
  14923. var saveClear = _dereq_(195).saveClear;
  14924. var inherits = _dereq_(207);
  14925. var LOW_PRIORITY = 250,
  14926. HIGH_PRIORITY = 1500;
  14927. var CommandInterceptor = _dereq_(78);
  14928. function AttachSupport(eventBus, modeling, moveVisuals, rules) {
  14929. CommandInterceptor.call(this, eventBus);
  14930. // remove all the nested attached elements from the moved
  14931. // shapes; they will be moved together with the host element
  14932. // anyway
  14933. eventBus.on('shape.move.start', HIGH_PRIORITY, function(e) {
  14934. var context = e.context,
  14935. shapes = context.shapes;
  14936. context.shapes = removeAttached(shapes);
  14937. });
  14938. // add attachers to the visual's group
  14939. eventBus.on('shape.move.start', LOW_PRIORITY, function(e) {
  14940. var context = e.context,
  14941. shapes = context.shapes,
  14942. attachers = context.movedAttachers = getAttachers(shapes);
  14943. forEach(attachers, function(attacher) {
  14944. moveVisuals.makeDraggable(context, attacher, true);
  14945. });
  14946. });
  14947. // move all attachments after the other shapes are done moving
  14948. this.postExecuted([ 'shapes.move' ], function(event) {
  14949. var context = event.context,
  14950. closure = context.closure,
  14951. enclosedElements = closure.enclosedElements,
  14952. attachers = getAttachers(closure.enclosedElements);
  14953. // ensure we move all attachers with their hosts
  14954. // if they have not been moved already
  14955. forEach(attachers, function(attacher){
  14956. if (!enclosedElements[attacher.id]) {
  14957. modeling.moveShape(attacher, context.delta, context.newParent);
  14958. }
  14959. });
  14960. });
  14961. // perform the attaching after shapes are done moving
  14962. this.postExecuted([ 'shapes.move' ], function(e) {
  14963. var context = e.context,
  14964. shapes = context.shapes,
  14965. newHost = context.newHost,
  14966. attachers;
  14967. if (shapes.length > 1) {
  14968. return;
  14969. }
  14970. if (newHost) {
  14971. attachers = shapes;
  14972. } else {
  14973. attachers = filter(shapes, function(s) {
  14974. return !!s.host;
  14975. });
  14976. }
  14977. forEach(attachers, function(attacher) {
  14978. modeling.updateAttachment(attacher, newHost);
  14979. });
  14980. });
  14981. // update attachments if the host is replaced
  14982. this.postExecute([ 'shape.replace' ], function(e) {
  14983. var context = e.context,
  14984. oldShape = context.oldShape,
  14985. newShape = context.newShape;
  14986. saveClear(oldShape.attachers, function(attacher) {
  14987. var allowed = rules.allowed('shapes.move', {
  14988. target: newShape,
  14989. shapes: [attacher]
  14990. });
  14991. if (allowed === 'attach') {
  14992. modeling.updateAttachment(attacher, newShape);
  14993. } else {
  14994. modeling.removeShape(attacher);
  14995. }
  14996. });
  14997. });
  14998. // remove attachments
  14999. this.preExecute([ 'shape.delete' ], function(event) {
  15000. var shape = event.context.shape;
  15001. saveClear(shape.attachers, function(attacher) {
  15002. modeling.removeShape(attacher);
  15003. });
  15004. });
  15005. }
  15006. inherits(AttachSupport, CommandInterceptor);
  15007. AttachSupport.$inject = [ 'eventBus', 'modeling', 'moveVisuals', 'rules' ];
  15008. module.exports = AttachSupport;
  15009. /**
  15010. * Return attachers of the given shapes
  15011. *
  15012. * @param {Array<djs.model.Base>} shapes
  15013. * @return {Array<djs.model.Base>}
  15014. */
  15015. function getAttachers(shapes) {
  15016. return flatten(map(shapes, function(s) {
  15017. return s.attachers || [];
  15018. }));
  15019. }
  15020. /**
  15021. * Return a filtered list of elements that do not
  15022. * contain attached elements with hosts being part
  15023. * of the selection.
  15024. *
  15025. * @param {Array<djs.model.Base>} elements
  15026. *
  15027. * @return {Array<djs.model.Base>} filtered
  15028. */
  15029. function removeAttached(elements) {
  15030. var ids = groupBy(elements, 'id');
  15031. return filter(elements, function(element) {
  15032. while (element) {
  15033. // host in selection
  15034. if (element.host && ids[element.host.id]) {
  15035. return false;
  15036. }
  15037. element = element.parent;
  15038. }
  15039. return true;
  15040. });
  15041. }
  15042. },{"195":195,"207":207,"208":208,"216":216,"218":218,"219":219,"221":221,"78":78}],91:[function(_dereq_,module,exports){
  15043. module.exports = {
  15044. __depends__: [
  15045. _dereq_(139),
  15046. _dereq_(112)
  15047. ],
  15048. __init__: [ 'attachSupport'],
  15049. attachSupport: [ 'type', _dereq_(90) ]
  15050. };
  15051. },{"112":112,"139":139,"90":90}],92:[function(_dereq_,module,exports){
  15052. 'use strict';
  15053. var Geometry = _dereq_(188),
  15054. BendpointUtil = _dereq_(94);
  15055. var MARKER_OK = 'connect-ok',
  15056. MARKER_NOT_OK = 'connect-not-ok',
  15057. MARKER_CONNECT_HOVER = 'connect-hover',
  15058. MARKER_CONNECT_UPDATING = 'djs-updating';
  15059. var COMMAND_BENDPOINT_UPDATE = 'connection.updateWaypoints',
  15060. COMMAND_RECONNECT_START = 'connection.reconnectStart',
  15061. COMMAND_RECONNECT_END = 'connection.reconnectEnd';
  15062. var round = Math.round;
  15063. /**
  15064. * A component that implements moving of bendpoints
  15065. */
  15066. function BendpointMove(injector, eventBus, canvas, dragging, graphicsFactory, rules, modeling) {
  15067. var connectionDocking;
  15068. // optional connection docking integration
  15069. try {
  15070. connectionDocking = injector.get('connectionDocking');
  15071. } catch (e) {}
  15072. // API
  15073. this.start = function(event, connection, bendpointIndex, insert) {
  15074. var type,
  15075. context,
  15076. waypoints = connection.waypoints,
  15077. gfx = canvas.getGraphics(connection);
  15078. if (!insert && bendpointIndex === 0) {
  15079. type = COMMAND_RECONNECT_START;
  15080. } else
  15081. if (!insert && bendpointIndex === waypoints.length - 1) {
  15082. type = COMMAND_RECONNECT_END;
  15083. } else {
  15084. type = COMMAND_BENDPOINT_UPDATE;
  15085. }
  15086. context = {
  15087. connection: connection,
  15088. bendpointIndex: bendpointIndex,
  15089. insert: insert,
  15090. type: type
  15091. };
  15092. dragging.activate(event, 'bendpoint.move', {
  15093. data: {
  15094. connection: connection,
  15095. connectionGfx: gfx,
  15096. context: context
  15097. }
  15098. });
  15099. };
  15100. // DRAGGING IMPLEMENTATION
  15101. function redrawConnection(data) {
  15102. graphicsFactory.update('connection', data.connection, data.connectionGfx);
  15103. }
  15104. function filterRedundantWaypoints(waypoints) {
  15105. return waypoints.filter(function(r, idx) {
  15106. return !Geometry.pointsOnLine(waypoints[idx - 1], waypoints[idx + 1], r);
  15107. });
  15108. }
  15109. eventBus.on('bendpoint.move.start', function(e) {
  15110. var context = e.context,
  15111. connection = context.connection,
  15112. originalWaypoints = connection.waypoints,
  15113. waypoints = originalWaypoints.slice(),
  15114. insert = context.insert,
  15115. idx = context.bendpointIndex;
  15116. context.originalWaypoints = originalWaypoints;
  15117. if (insert) {
  15118. // insert placeholder for bendpoint to-be-added
  15119. waypoints.splice(idx, 0, null);
  15120. }
  15121. connection.waypoints = waypoints;
  15122. // add dragger gfx
  15123. context.draggerGfx = BendpointUtil.addBendpoint(canvas.getLayer('overlays'));
  15124. context.draggerGfx.addClass('djs-dragging');
  15125. canvas.addMarker(connection, MARKER_CONNECT_UPDATING);
  15126. });
  15127. eventBus.on('bendpoint.move.hover', function(e) {
  15128. e.context.hover = e.hover;
  15129. canvas.addMarker(e.hover, MARKER_CONNECT_HOVER);
  15130. });
  15131. eventBus.on([
  15132. 'bendpoint.move.out',
  15133. 'bendpoint.move.cleanup'
  15134. ], function(e) {
  15135. // remove connect marker
  15136. // if it was added
  15137. var hover = e.context.hover;
  15138. if (hover) {
  15139. canvas.removeMarker(hover, MARKER_CONNECT_HOVER);
  15140. canvas.removeMarker(hover, e.context.target ? MARKER_OK : MARKER_NOT_OK);
  15141. }
  15142. });
  15143. eventBus.on('bendpoint.move.move', function(e) {
  15144. var context = e.context,
  15145. moveType = context.type,
  15146. connection = e.connection,
  15147. source, target;
  15148. connection.waypoints[context.bendpointIndex] = { x: e.x, y: e.y };
  15149. if (connectionDocking) {
  15150. if (context.hover) {
  15151. if (moveType === COMMAND_RECONNECT_START) {
  15152. source = context.hover;
  15153. }
  15154. if (moveType === COMMAND_RECONNECT_END) {
  15155. target = context.hover;
  15156. }
  15157. }
  15158. connection.waypoints = connectionDocking.getCroppedWaypoints(connection, source, target);
  15159. }
  15160. // asks whether reconnect / bendpoint move / bendpoint add
  15161. // is allowed at the given position
  15162. var allowed = context.allowed = rules.allowed(context.type, context);
  15163. if (allowed) {
  15164. if (context.hover) {
  15165. canvas.removeMarker(context.hover, MARKER_NOT_OK);
  15166. canvas.addMarker(context.hover, MARKER_OK);
  15167. context.target = context.hover;
  15168. }
  15169. } else
  15170. if (allowed === false) {
  15171. if (context.hover) {
  15172. canvas.removeMarker(context.hover, MARKER_OK);
  15173. canvas.addMarker(context.hover, MARKER_NOT_OK);
  15174. context.target = null;
  15175. }
  15176. }
  15177. // add dragger gfx
  15178. context.draggerGfx.translate(e.x, e.y);
  15179. redrawConnection(e);
  15180. });
  15181. eventBus.on([
  15182. 'bendpoint.move.end',
  15183. 'bendpoint.move.cancel'
  15184. ], function(e) {
  15185. var context = e.context,
  15186. connection = context.connection;
  15187. // remove dragger gfx
  15188. context.draggerGfx.remove();
  15189. context.newWaypoints = connection.waypoints.slice();
  15190. connection.waypoints = context.originalWaypoints;
  15191. canvas.removeMarker(connection, MARKER_CONNECT_UPDATING);
  15192. });
  15193. eventBus.on('bendpoint.move.end', function(e) {
  15194. var context = e.context,
  15195. waypoints = context.newWaypoints,
  15196. bendpointIndex = context.bendpointIndex,
  15197. bendpoint = waypoints[bendpointIndex],
  15198. allowed = context.allowed;
  15199. // ensure we have actual pixel values bendpoint
  15200. // coordinates (important when zoom level was > 1 during move)
  15201. bendpoint.x = round(bendpoint.x);
  15202. bendpoint.y = round(bendpoint.y);
  15203. if (allowed === true && context.type === COMMAND_RECONNECT_START) {
  15204. modeling.reconnectStart(context.connection, context.target, bendpoint);
  15205. } else
  15206. if (allowed === true && context.type === COMMAND_RECONNECT_END) {
  15207. modeling.reconnectEnd(context.connection, context.target, bendpoint);
  15208. } else
  15209. if (allowed !== false && context.type === COMMAND_BENDPOINT_UPDATE) {
  15210. modeling.updateWaypoints(context.connection, filterRedundantWaypoints(waypoints));
  15211. } else {
  15212. redrawConnection(e);
  15213. return false;
  15214. }
  15215. });
  15216. eventBus.on('bendpoint.move.cancel', function(e) {
  15217. redrawConnection(e);
  15218. });
  15219. }
  15220. BendpointMove.$inject = [ 'injector', 'eventBus', 'canvas', 'dragging', 'graphicsFactory', 'rules', 'modeling' ];
  15221. module.exports = BendpointMove;
  15222. },{"188":188,"94":94}],93:[function(_dereq_,module,exports){
  15223. 'use strict';
  15224. var assign = _dereq_(339),
  15225. pick = _dereq_(345),
  15226. forEach = _dereq_(218);
  15227. var Snap = _dereq_(200);
  15228. var round = Math.round;
  15229. function BendpointSnapping(eventBus) {
  15230. function snapTo(candidates, point) {
  15231. return Snap.snapTo(candidates, point);
  15232. }
  15233. function toPoint(e) {
  15234. return pick(e, [ 'x', 'y' ]);
  15235. }
  15236. function mid(element) {
  15237. if (element.width) {
  15238. return {
  15239. x: round(element.width / 2 + element.x),
  15240. y: round(element.height / 2 + element.y)
  15241. };
  15242. }
  15243. }
  15244. function getSnapPoints(context) {
  15245. var snapPoints = context.snapPoints,
  15246. waypoints = context.connection.waypoints,
  15247. bendpointIndex = context.bendpointIndex,
  15248. referenceWaypoints = [ waypoints[bendpointIndex - 1], waypoints[bendpointIndex + 1] ];
  15249. if (!snapPoints) {
  15250. context.snapPoints = snapPoints = { horizontal: [] , vertical: [] };
  15251. forEach(referenceWaypoints, function(p) {
  15252. // we snap on existing bendpoints only,
  15253. // not placeholders that are inserted during add
  15254. if (p) {
  15255. p = p.original || p;
  15256. snapPoints.horizontal.push(p.y);
  15257. snapPoints.vertical.push(p.x);
  15258. }
  15259. });
  15260. }
  15261. return snapPoints;
  15262. }
  15263. eventBus.on('bendpoint.move.start', function(event) {
  15264. event.context.snapStart = toPoint(event);
  15265. });
  15266. eventBus.on('bendpoint.move.move', 1500, function(event) {
  15267. var context = event.context,
  15268. snapPoints = getSnapPoints(context),
  15269. start = context.snapStart,
  15270. target = context.target,
  15271. targetMid = target && mid(target),
  15272. x = start.x + event.dx,
  15273. y = start.y + event.dy,
  15274. sx, sy;
  15275. if (!snapPoints) {
  15276. return;
  15277. }
  15278. // snap
  15279. sx = snapTo(targetMid ? snapPoints.vertical.concat([ targetMid.x ]) : snapPoints.vertical, x);
  15280. sy = snapTo(targetMid ? snapPoints.horizontal.concat([ targetMid.y ]) : snapPoints.horizontal, y);
  15281. // correction x/y
  15282. var cx = (x - sx),
  15283. cy = (y - sy);
  15284. // update delta
  15285. assign(event, {
  15286. dx: event.dx - cx,
  15287. dy: event.dy - cy,
  15288. x: event.x - cx,
  15289. y: event.y - cy
  15290. });
  15291. });
  15292. }
  15293. BendpointSnapping.$inject = [ 'eventBus' ];
  15294. module.exports = BendpointSnapping;
  15295. },{"200":200,"218":218,"339":339,"345":345}],94:[function(_dereq_,module,exports){
  15296. 'use strict';
  15297. var Events = _dereq_(187);
  15298. var BENDPOINT_CLS = module.exports.BENDPOINT_CLS = 'djs-bendpoint';
  15299. module.exports.toCanvasCoordinates = function(canvas, event) {
  15300. var position = Events.toPoint(event),
  15301. clientRect = canvas._container.getBoundingClientRect(),
  15302. offset;
  15303. // canvas relative position
  15304. offset = {
  15305. x: clientRect.left,
  15306. y: clientRect.top
  15307. };
  15308. // update actual event payload with canvas relative measures
  15309. var viewbox = canvas.viewbox();
  15310. return {
  15311. x: viewbox.x + (position.x - offset.x) / viewbox.scale,
  15312. y: viewbox.y + (position.y - offset.y) / viewbox.scale
  15313. };
  15314. };
  15315. module.exports.addBendpoint = function(parentGfx) {
  15316. var groupGfx = parentGfx.group().addClass(BENDPOINT_CLS);
  15317. groupGfx.circle(0, 0, 4).addClass('djs-visual');
  15318. groupGfx.circle(0, 0, 10).addClass('djs-hit');
  15319. return groupGfx;
  15320. };
  15321. },{"187":187}],95:[function(_dereq_,module,exports){
  15322. 'use strict';
  15323. var domEvent = _dereq_(357),
  15324. BendpointUtil = _dereq_(94);
  15325. var BENDPOINT_CLS = BendpointUtil.BENDPOINT_CLS;
  15326. var getApproxIntersection = _dereq_(191).getApproxIntersection;
  15327. /**
  15328. * A service that adds editable bendpoints to connections.
  15329. */
  15330. function Bendpoints(injector, eventBus, canvas, interactionEvents, bendpointMove) {
  15331. function getConnectionIntersection(waypoints, event) {
  15332. var localPosition = BendpointUtil.toCanvasCoordinates(canvas, event);
  15333. return getApproxIntersection(waypoints, localPosition);
  15334. }
  15335. function activateBendpointMove(event, connection) {
  15336. var waypoints = connection.waypoints,
  15337. intersection = getConnectionIntersection(waypoints, event);
  15338. if (!intersection) {
  15339. return;
  15340. }
  15341. bendpointMove.start(event, connection, intersection.index, !intersection.bendpoint);
  15342. }
  15343. function getBendpointsContainer(element, create) {
  15344. var layer = canvas.getLayer('overlays'),
  15345. gfx = layer.select('.djs-bendpoints[data-element-id=' + element.id + ']');
  15346. if (!gfx && create) {
  15347. gfx = layer.group().addClass('djs-bendpoints').attr('data-element-id', element.id);
  15348. domEvent.bind(gfx.node, 'mousedown', function(event) {
  15349. activateBendpointMove(event, element);
  15350. });
  15351. }
  15352. return gfx;
  15353. }
  15354. function createBendpoints(gfx, connection) {
  15355. connection.waypoints.forEach(function(p, idx) {
  15356. BendpointUtil.addBendpoint(gfx).translate(p.x, p.y);
  15357. });
  15358. // add floating bendpoint
  15359. BendpointUtil.addBendpoint(gfx).addClass('floating');
  15360. }
  15361. function clearBendpoints(gfx) {
  15362. gfx.selectAll('.' + BENDPOINT_CLS).forEach(function(s) {
  15363. s.remove();
  15364. });
  15365. }
  15366. function addBendpoints(connection) {
  15367. var gfx = getBendpointsContainer(connection);
  15368. if (!gfx) {
  15369. gfx = getBendpointsContainer(connection, true);
  15370. createBendpoints(gfx, connection);
  15371. }
  15372. return gfx;
  15373. }
  15374. function updateBendpoints(connection) {
  15375. var gfx = getBendpointsContainer(connection);
  15376. if (gfx) {
  15377. clearBendpoints(gfx);
  15378. createBendpoints(gfx, connection);
  15379. }
  15380. }
  15381. eventBus.on('connection.changed', function(event) {
  15382. updateBendpoints(event.element);
  15383. });
  15384. eventBus.on('connection.remove', function(event) {
  15385. var gfx = getBendpointsContainer(event.element);
  15386. if (gfx) {
  15387. gfx.remove();
  15388. }
  15389. });
  15390. eventBus.on('element.marker.update', function(event) {
  15391. var element = event.element,
  15392. bendpointsGfx;
  15393. if (!element.waypoints) {
  15394. return;
  15395. }
  15396. bendpointsGfx = addBendpoints(element);
  15397. bendpointsGfx[event.add ? 'addClass' : 'removeClass'](event.marker);
  15398. });
  15399. eventBus.on('element.mousemove', function(event) {
  15400. var element = event.element,
  15401. waypoints = element.waypoints,
  15402. bendpointsGfx,
  15403. floating,
  15404. intersection;
  15405. if (waypoints) {
  15406. bendpointsGfx = getBendpointsContainer(element, true);
  15407. floating = bendpointsGfx.select('.floating');
  15408. if (!floating) {
  15409. return;
  15410. }
  15411. intersection = getConnectionIntersection(waypoints, event.originalEvent);
  15412. if (intersection) {
  15413. floating.translate(intersection.point.x, intersection.point.y);
  15414. }
  15415. }
  15416. });
  15417. eventBus.on('element.mousedown', function(event) {
  15418. var originalEvent = event.originalEvent,
  15419. element = event.element,
  15420. waypoints = element.waypoints;
  15421. if (!waypoints) {
  15422. return;
  15423. }
  15424. activateBendpointMove(originalEvent, element, waypoints);
  15425. });
  15426. eventBus.on('selection.changed', function(event) {
  15427. var newSelection = event.newSelection,
  15428. primary = newSelection[0];
  15429. if (primary && primary.waypoints) {
  15430. addBendpoints(primary);
  15431. }
  15432. });
  15433. eventBus.on('element.hover', function(event) {
  15434. var element = event.element;
  15435. if (element.waypoints) {
  15436. addBendpoints(element);
  15437. interactionEvents.registerEvent(event.gfx.node, 'mousemove', 'element.mousemove');
  15438. }
  15439. });
  15440. eventBus.on('element.out', function(event) {
  15441. interactionEvents.unregisterEvent(event.gfx.node, 'mousemove', 'element.mousemove');
  15442. });
  15443. }
  15444. Bendpoints.$inject = [ 'injector', 'eventBus', 'canvas', 'interactionEvents', 'bendpointMove' ];
  15445. module.exports = Bendpoints;
  15446. },{"191":191,"357":357,"94":94}],96:[function(_dereq_,module,exports){
  15447. module.exports = {
  15448. __depends__: [ _dereq_(106), _dereq_(155) ],
  15449. __init__: [ 'bendpoints', 'bendpointSnapping' ],
  15450. bendpoints: [ 'type', _dereq_(95) ],
  15451. bendpointMove: [ 'type', _dereq_(92) ],
  15452. bendpointSnapping: [ 'type', _dereq_(93) ]
  15453. };
  15454. },{"106":106,"155":155,"92":92,"93":93,"95":95}],97:[function(_dereq_,module,exports){
  15455. 'use strict';
  15456. /**
  15457. * Adds change support to the diagram, including
  15458. *
  15459. * <ul>
  15460. * <li>redrawing shapes and connections on change</li>
  15461. * </ul>
  15462. *
  15463. * @param {EventBus} eventBus
  15464. * @param {ElementRegistry} elementRegistry
  15465. * @param {GraphicsFactory} graphicsFactory
  15466. */
  15467. function ChangeSupport(eventBus, elementRegistry, graphicsFactory) {
  15468. // redraw shapes / connections on change
  15469. eventBus.on('element.changed', function(event) {
  15470. var element = event.element;
  15471. if (!event.gfx) {
  15472. event.gfx = elementRegistry.getGraphics(element);
  15473. }
  15474. // shape + gfx may have been deleted
  15475. if (!event.gfx) {
  15476. return;
  15477. }
  15478. if (element.waypoints) {
  15479. eventBus.fire('connection.changed', event);
  15480. } else {
  15481. eventBus.fire('shape.changed', event);
  15482. }
  15483. });
  15484. eventBus.on('elements.changed', function(event) {
  15485. var elements = event.elements;
  15486. elements.forEach(function(e) {
  15487. eventBus.fire('element.changed', { element: e });
  15488. });
  15489. graphicsFactory.updateContainments(elements);
  15490. });
  15491. eventBus.on('shape.changed', function(event) {
  15492. graphicsFactory.update('shape', event.element, event.gfx);
  15493. });
  15494. eventBus.on('connection.changed', function(event) {
  15495. graphicsFactory.update('connection', event.element, event.gfx);
  15496. });
  15497. }
  15498. ChangeSupport.$inject = [ 'eventBus', 'elementRegistry', 'graphicsFactory' ];
  15499. module.exports = ChangeSupport;
  15500. },{}],98:[function(_dereq_,module,exports){
  15501. module.exports = {
  15502. __init__: [ 'changeSupport'],
  15503. changeSupport: [ 'type', _dereq_(97) ]
  15504. };
  15505. },{"97":97}],99:[function(_dereq_,module,exports){
  15506. 'use strict';
  15507. var LayoutUtil = _dereq_(174);
  15508. var MARKER_OK = 'connect-ok',
  15509. MARKER_NOT_OK = 'connect-not-ok';
  15510. function Connect(eventBus, dragging, modeling, rules, canvas, renderer) {
  15511. // TODO(nre): separate UI and events
  15512. // rules
  15513. function canConnect(source, target) {
  15514. return rules.allowed('connection.create', {
  15515. source: source,
  15516. target: target
  15517. });
  15518. }
  15519. // layouting
  15520. function crop(start, end, source, target) {
  15521. var sourcePath = renderer.getShapePath(source),
  15522. targetPath = target && renderer.getShapePath(target),
  15523. connectionPath = renderer.getConnectionPath({ waypoints: [ start, end ] });
  15524. start = LayoutUtil.getElementLineIntersection(sourcePath, connectionPath, true) || start;
  15525. end = (target && LayoutUtil.getElementLineIntersection(targetPath, connectionPath, false)) || end;
  15526. return [ start, end ];
  15527. }
  15528. // event handlers
  15529. eventBus.on('connect.move', function(event) {
  15530. var context = event.context,
  15531. source = context.source,
  15532. target = context.target,
  15533. visual = context.visual,
  15534. start, end, waypoints;
  15535. // update connection visuals during drag
  15536. start = LayoutUtil.getMid(source);
  15537. end = {
  15538. x: event.x,
  15539. y: event.y
  15540. };
  15541. waypoints = crop(start, end, source, target);
  15542. visual.attr('points', [ waypoints[0].x, waypoints[0].y, waypoints[1].x, waypoints[1].y ]);
  15543. });
  15544. eventBus.on('connect.hover', function(event) {
  15545. var context = event.context,
  15546. source = context.source,
  15547. hover = event.hover,
  15548. canExecute;
  15549. canExecute = context.canExecute = canConnect(source, hover);
  15550. // simply ignore hover
  15551. if (canExecute === null) {
  15552. return;
  15553. }
  15554. context.target = hover;
  15555. canvas.addMarker(hover, canExecute ? MARKER_OK : MARKER_NOT_OK);
  15556. });
  15557. eventBus.on([ 'connect.out', 'connect.cleanup' ], function(event) {
  15558. var context = event.context;
  15559. if (context.target) {
  15560. canvas.removeMarker(context.target, context.canExecute ? MARKER_OK : MARKER_NOT_OK);
  15561. }
  15562. context.target = null;
  15563. });
  15564. eventBus.on('connect.cleanup', function(event) {
  15565. var context = event.context;
  15566. if (context.visual) {
  15567. context.visual.remove();
  15568. }
  15569. });
  15570. eventBus.on('connect.start', function(event) {
  15571. var context = event.context,
  15572. visual;
  15573. visual = canvas.getDefaultLayer().polyline().attr({
  15574. 'stroke': '#333',
  15575. 'strokeDasharray': [ 1 ],
  15576. 'strokeWidth': 2,
  15577. 'pointer-events': 'none'
  15578. });
  15579. context.visual = visual;
  15580. });
  15581. eventBus.on('connect.end', function(event) {
  15582. var context = event.context,
  15583. source = context.source,
  15584. target = context.target,
  15585. canExecute = context.canExecute || canConnect(source, target);
  15586. if (!canExecute) {
  15587. return false;
  15588. }
  15589. modeling.connect(source, target);
  15590. });
  15591. // API
  15592. this.start = function(event, source, autoActivate) {
  15593. dragging.activate(event, 'connect', {
  15594. autoActivate: autoActivate,
  15595. data: {
  15596. shape: source,
  15597. context: {
  15598. source: source
  15599. }
  15600. }
  15601. });
  15602. };
  15603. }
  15604. Connect.$inject = [ 'eventBus', 'dragging', 'modeling', 'rules', 'canvas', 'renderer' ];
  15605. module.exports = Connect;
  15606. },{"174":174}],100:[function(_dereq_,module,exports){
  15607. module.exports = {
  15608. __depends__: [
  15609. _dereq_(159),
  15610. _dereq_(155),
  15611. _dereq_(106)
  15612. ],
  15613. connect: [ 'type', _dereq_(99) ]
  15614. };
  15615. },{"106":106,"155":155,"159":159,"99":99}],101:[function(_dereq_,module,exports){
  15616. 'use strict';
  15617. var isFunction = _dereq_(331),
  15618. forEach = _dereq_(218),
  15619. domDelegate = _dereq_(355),
  15620. domClear = _dereq_(353),
  15621. domEvent = _dereq_(357),
  15622. domAttr = _dereq_(351),
  15623. domQuery = _dereq_(359),
  15624. domClasses = _dereq_(352),
  15625. domify = _dereq_(356);
  15626. var entrySelector = '.entry';
  15627. /**
  15628. * A context pad that displays element specific, contextual actions next
  15629. * to a diagram element.
  15630. *
  15631. * @param {EventBus} eventBus
  15632. * @param {Overlays} overlays
  15633. */
  15634. function ContextPad(eventBus, overlays) {
  15635. this._providers = [];
  15636. this._eventBus = eventBus;
  15637. this._overlays = overlays;
  15638. this._current = null;
  15639. this._init();
  15640. }
  15641. ContextPad.$inject = [ 'eventBus', 'overlays' ];
  15642. /**
  15643. * Registers events needed for interaction with other components
  15644. */
  15645. ContextPad.prototype._init = function() {
  15646. var eventBus = this._eventBus;
  15647. var self = this;
  15648. eventBus.on('selection.changed', function(e) {
  15649. var selection = e.newSelection;
  15650. if (selection.length === 1) {
  15651. self.open(selection[0]);
  15652. } else {
  15653. self.close();
  15654. }
  15655. });
  15656. };
  15657. /**
  15658. * Register a provider with the context pad
  15659. *
  15660. * @param {ContextPadProvider} provider
  15661. */
  15662. ContextPad.prototype.registerProvider = function(provider) {
  15663. this._providers.push(provider);
  15664. };
  15665. /**
  15666. * Returns the context pad entries for a given element
  15667. *
  15668. * @param {djs.element.Base} element
  15669. *
  15670. * @return {Array<ContextPadEntryDescriptor>} list of entries
  15671. */
  15672. ContextPad.prototype.getEntries = function(element) {
  15673. var entries = {};
  15674. // loop through all providers and their entries.
  15675. // group entries by id so that overriding an entry is possible
  15676. forEach(this._providers, function(provider) {
  15677. var e = provider.getContextPadEntries(element);
  15678. forEach(e, function(entry, id) {
  15679. entries[id] = entry;
  15680. });
  15681. });
  15682. return entries;
  15683. };
  15684. /**
  15685. * Trigger an action available on the opened context pad
  15686. *
  15687. * @param {String} action
  15688. * @param {Event} event
  15689. * @param {Boolean} [autoActivate=false]
  15690. */
  15691. ContextPad.prototype.trigger = function(action, event, autoActivate) {
  15692. var current = this._current,
  15693. element = current.element,
  15694. entries = current.entries,
  15695. entry,
  15696. handler,
  15697. originalEvent,
  15698. button = event.delegateTarget || event.target;
  15699. if (!button) {
  15700. return event.preventDefault();
  15701. }
  15702. entry = entries[domAttr(button, 'data-action')];
  15703. handler = entry.action;
  15704. originalEvent = event.originalEvent || event;
  15705. // simple action (via callback function)
  15706. if (isFunction(handler)) {
  15707. if (action === 'click') {
  15708. return handler(originalEvent, element, autoActivate);
  15709. }
  15710. } else {
  15711. if (handler[action]) {
  15712. return handler[action](originalEvent, element, autoActivate);
  15713. }
  15714. }
  15715. // silence other actions
  15716. event.preventDefault();
  15717. };
  15718. /**
  15719. * Open the context pad for the given element
  15720. *
  15721. * @param {djs.model.Base} element
  15722. */
  15723. ContextPad.prototype.open = function(element) {
  15724. if (this._current && this._current.open) {
  15725. if (this._current.element === element) {
  15726. // no change needed
  15727. return;
  15728. }
  15729. this.close();
  15730. }
  15731. this._updateAndOpen(element);
  15732. };
  15733. ContextPad.prototype._updateAndOpen = function(element) {
  15734. var entries = this.getEntries(element),
  15735. pad = this.getPad(element),
  15736. html = pad.html;
  15737. domClear(html);
  15738. forEach(entries, function(entry, id) {
  15739. var grouping = entry.group || 'default',
  15740. control = domify(entry.html || '<div class="entry" draggable="true"></div>'),
  15741. container;
  15742. domAttr(control, 'data-action', id);
  15743. container = domQuery('[data-group=' + grouping + ']', html);
  15744. if (!container) {
  15745. container = domify('<div class="group" data-group="' + grouping + '"></div>');
  15746. html.appendChild(container);
  15747. }
  15748. container.appendChild(control);
  15749. if (entry.className) {
  15750. domClasses(control).add(entry.className);
  15751. }
  15752. if (entry.title) {
  15753. domAttr(control, 'title', entry.title);
  15754. }
  15755. if (entry.imageUrl) {
  15756. control.appendChild(domify('<img src="' + entry.imageUrl + '">'));
  15757. }
  15758. });
  15759. domClasses(html).add('open');
  15760. this._current = {
  15761. element: element,
  15762. pad: pad,
  15763. entries: entries,
  15764. open: true
  15765. };
  15766. this._eventBus.fire('contextPad.open', { current: this._current });
  15767. };
  15768. ContextPad.prototype.getPad = function(element) {
  15769. var self = this;
  15770. var overlays = this._overlays,
  15771. pads = overlays.get({ element: element, type: 'context-pad' });
  15772. // create context pad on demand if needed
  15773. if (!pads.length) {
  15774. var html = domify('<div class="djs-context-pad"></div>');
  15775. domDelegate.bind(html, entrySelector, 'click', function(event) {
  15776. self.trigger('click', event);
  15777. });
  15778. domDelegate.bind(html, entrySelector, 'dragstart', function(event) {
  15779. self.trigger('dragstart', event);
  15780. });
  15781. // stop propagation of mouse events
  15782. domEvent.bind(html, 'mousedown', function(event) {
  15783. event.stopPropagation();
  15784. });
  15785. overlays.add(element, 'context-pad', {
  15786. position: {
  15787. right: -9,
  15788. top: -6
  15789. },
  15790. html: html
  15791. });
  15792. pads = overlays.get({ element: element, type: 'context-pad' });
  15793. this._eventBus.fire('contextPad.create', { element: element, pad: pads[0] });
  15794. }
  15795. return pads[0];
  15796. };
  15797. /**
  15798. * Close the context pad
  15799. */
  15800. ContextPad.prototype.close = function() {
  15801. var html;
  15802. if (this._current) {
  15803. if (this._current.open) {
  15804. html = this._current.pad.html;
  15805. domClasses(html).remove('open');
  15806. }
  15807. this._current.open = false;
  15808. this._eventBus.fire('contextPad.close', { current: this._current });
  15809. }
  15810. };
  15811. /**
  15812. * Return the element the context pad is currently opened for,
  15813. * if it is opened.
  15814. *
  15815. * @example
  15816. *
  15817. * contextPad.open(shape1);
  15818. *
  15819. * if (contextPad.isOpen()) {
  15820. * // yes, we are open
  15821. * }
  15822. *
  15823. * @return {djs.model.Base} element
  15824. */
  15825. ContextPad.prototype.isOpen = function() {
  15826. return this._current && this._current.open;
  15827. };
  15828. module.exports = ContextPad;
  15829. },{"218":218,"331":331,"351":351,"352":352,"353":353,"355":355,"356":356,"357":357,"359":359}],102:[function(_dereq_,module,exports){
  15830. module.exports = {
  15831. __depends__: [
  15832. _dereq_(108),
  15833. _dereq_(143)
  15834. ],
  15835. contextPad: [ 'type', _dereq_(101) ]
  15836. };
  15837. },{"101":101,"108":108,"143":143}],103:[function(_dereq_,module,exports){
  15838. 'use strict';
  15839. var MARKER_OK = 'drop-ok',
  15840. MARKER_NOT_OK = 'drop-not-ok',
  15841. MARKER_ATTACH = 'attach-ok';
  15842. function Create(eventBus, dragging, rules, modeling, canvas, renderer, styles) {
  15843. // rules
  15844. function canCreate(shape, target, source, position) {
  15845. if (source) {
  15846. return rules.allowed('shape.append', {
  15847. source: source,
  15848. shape: shape,
  15849. target: target,
  15850. position: position
  15851. });
  15852. } else {
  15853. return rules.allowed('shape.create', {
  15854. shape: shape,
  15855. target: target,
  15856. position: position
  15857. });
  15858. }
  15859. }
  15860. /** set drop marker on an element */
  15861. function setMarker(element, marker) {
  15862. [ MARKER_ATTACH, MARKER_OK, MARKER_NOT_OK ].forEach(function(m) {
  15863. if (m === marker) {
  15864. canvas.addMarker(element, m);
  15865. } else {
  15866. canvas.removeMarker(element, m);
  15867. }
  15868. });
  15869. }
  15870. // visual helpers
  15871. function createVisual(shape) {
  15872. var group, preview, visual;
  15873. group = canvas.getDefaultLayer().group().attr(styles.cls('djs-drag-group', [ 'no-events' ]));
  15874. preview = group.group().addClass('djs-dragger');
  15875. preview.translate(shape.width / -2, shape.height / -2);
  15876. visual = preview.group().addClass('djs-visual');
  15877. // hijack renderer to draw preview
  15878. renderer.drawShape(visual, shape);
  15879. return group;
  15880. }
  15881. // event handlers
  15882. eventBus.on('create.move', function(event) {
  15883. var context = event.context,
  15884. shape = context.shape,
  15885. visual = context.visual;
  15886. // lazy init drag visual once we received the first real
  15887. // drag move event (this allows us to get the proper canvas local coordinates)
  15888. if (!visual) {
  15889. visual = context.visual = createVisual(shape);
  15890. }
  15891. visual.translate(event.x, event.y);
  15892. var hover = event.hover,
  15893. canExecute;
  15894. var position = {
  15895. x: event.x,
  15896. y: event.y
  15897. };
  15898. canExecute = context.canExecute = hover && canCreate(context.shape, hover, context.source, position);
  15899. // ignore hover visually if canExecute is null
  15900. if (hover && canExecute !== null) {
  15901. context.target = hover;
  15902. if (canExecute === 'attach') {
  15903. setMarker(hover, MARKER_ATTACH);
  15904. } else {
  15905. setMarker(hover, context.canExecute ? MARKER_OK : MARKER_NOT_OK);
  15906. }
  15907. }
  15908. });
  15909. eventBus.on([ 'create.end', 'create.out', 'create.cleanup' ], function(event) {
  15910. var context = event.context,
  15911. target = context.target;
  15912. if (target) {
  15913. setMarker(target, null);
  15914. }
  15915. });
  15916. eventBus.on('create.end', function(event) {
  15917. var context = event.context,
  15918. source = context.source,
  15919. shape = context.shape,
  15920. target = context.target,
  15921. canExecute = context.canExecute,
  15922. isAttach,
  15923. position = {
  15924. x: event.x,
  15925. y: event.y
  15926. };
  15927. if (!canExecute) {
  15928. return false;
  15929. }
  15930. if (source) {
  15931. shape = modeling.appendShape(source, shape, position, target);
  15932. } else {
  15933. isAttach = canExecute === 'attach';
  15934. shape = modeling.createShape(shape, position, target, isAttach);
  15935. }
  15936. // make sure we provide the actual attached
  15937. // shape with the context so that selection and
  15938. // other components can use it right after the create
  15939. // operation ends
  15940. context.shape = shape;
  15941. });
  15942. eventBus.on('create.cleanup', function(event) {
  15943. var context = event.context;
  15944. if (context.visual) {
  15945. context.visual.remove();
  15946. }
  15947. });
  15948. // API
  15949. this.start = function(event, shape, source) {
  15950. dragging.activate(event, 'create', {
  15951. cursor: 'grabbing',
  15952. autoActivate: true,
  15953. data: {
  15954. shape: shape,
  15955. context: {
  15956. shape: shape,
  15957. source: source
  15958. }
  15959. }
  15960. });
  15961. };
  15962. }
  15963. Create.$inject = [ 'eventBus', 'dragging', 'rules', 'modeling', 'canvas', 'renderer', 'styles' ];
  15964. module.exports = Create;
  15965. },{}],104:[function(_dereq_,module,exports){
  15966. module.exports = {
  15967. __depends__: [
  15968. _dereq_(106),
  15969. _dereq_(159),
  15970. _dereq_(155)
  15971. ],
  15972. create: [ 'type', _dereq_(103) ]
  15973. };
  15974. },{"103":103,"106":106,"155":155,"159":159}],105:[function(_dereq_,module,exports){
  15975. 'use strict';
  15976. /* global TouchEvent */
  15977. var round = Math.round;
  15978. var assign = _dereq_(339);
  15979. var domEvent = _dereq_(357),
  15980. Event = _dereq_(187),
  15981. ClickTrap = _dereq_(183),
  15982. Cursor = _dereq_(185);
  15983. var EventBusEvent = _dereq_(84).Event;
  15984. function suppressEvent(event) {
  15985. if (event instanceof MouseEvent) {
  15986. Event.stopEvent(event, true);
  15987. } else {
  15988. Event.preventDefault(event);
  15989. }
  15990. }
  15991. function getLength(point) {
  15992. return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
  15993. }
  15994. function substract(p1, p2) {
  15995. return {
  15996. x: p1.x - p2.x,
  15997. y: p1.y - p2.y
  15998. };
  15999. }
  16000. function add(p1, p2) {
  16001. return {
  16002. x: p1.x + p2.x,
  16003. y: p1.y + p2.y
  16004. };
  16005. }
  16006. /**
  16007. * A helper that fires canvas localized drag events and realizes
  16008. * the general "drag-and-drop" look and feel.
  16009. *
  16010. * Calling {@link Dragging#activate} activates dragging on a canvas.
  16011. *
  16012. * It provides the following:
  16013. *
  16014. * * emits the events `start`, `move`, `end`, `cancel` and `cleanup` via the {@link EventBus}.
  16015. * Each of the events is prefixed with a prefix that is assigned during activate.
  16016. * * sets and restores the cursor
  16017. * * sets and restores the selection
  16018. * * ensures there can be only one drag operation active at a time
  16019. *
  16020. * Dragging may be canceled manually by calling {@link Dragging#cancel} or by pressing ESC.
  16021. *
  16022. * @example
  16023. *
  16024. * function MyDragComponent(eventBus, dragging) {
  16025. *
  16026. * eventBus.on('mydrag.start', function(event) {
  16027. * console.log('yes, we start dragging');
  16028. * });
  16029. *
  16030. * eventBus.on('mydrag.move', function(event) {
  16031. * console.log('canvas local coordinates', event.x, event.y, event.dx, event.dy);
  16032. *
  16033. * // local drag data is passed with the event
  16034. * event.context.foo; // "BAR"
  16035. *
  16036. * // the original mouse event, too
  16037. * event.originalEvent; // MouseEvent(...)
  16038. * });
  16039. *
  16040. * eventBus.on('element.click', function(event) {
  16041. * dragging.activate(event, 'mydrag', {
  16042. * cursor: 'grabbing',
  16043. * data: {
  16044. * context: {
  16045. * foo: "BAR"
  16046. * }
  16047. * }
  16048. * });
  16049. * });
  16050. * }
  16051. */
  16052. function Dragging(eventBus, canvas, selection) {
  16053. var defaultOptions = {
  16054. threshold: 5
  16055. };
  16056. // the currently active drag operation
  16057. // dragging is active as soon as this context exists.
  16058. //
  16059. // it is visually _active_ only when a context.active flag is set to true.
  16060. var context;
  16061. /* convert a global event into local coordinates */
  16062. function toLocalPoint(globalPosition) {
  16063. var viewbox = canvas.viewbox();
  16064. var clientRect = canvas._container.getBoundingClientRect();
  16065. return {
  16066. x: viewbox.x + round((globalPosition.x - clientRect.left) / viewbox.scale),
  16067. y: viewbox.y + round((globalPosition.y - clientRect.top) / viewbox.scale)
  16068. };
  16069. }
  16070. /* scale point to local coordinates */
  16071. function inLocalScale(point) {
  16072. var viewbox = canvas.viewbox();
  16073. return {
  16074. x: round(point.x / viewbox.scale),
  16075. y: round(point.y / viewbox.scale)
  16076. };
  16077. }
  16078. // helpers
  16079. function fire(type) {
  16080. var event = assign(new EventBusEvent(), context.payload, context.data);
  16081. // default integration
  16082. if (eventBus.fire('drag.' + type, event) === false) {
  16083. return false;
  16084. }
  16085. return eventBus.fire(context.prefix + '.' + type, event);
  16086. }
  16087. // event listeners
  16088. function move(event, activate) {
  16089. var payload = context.payload,
  16090. globalStart = context.globalStart,
  16091. globalCurrent = Event.toPoint(event),
  16092. globalDelta = substract(globalCurrent, globalStart),
  16093. localStart = context.localStart,
  16094. localDelta = inLocalScale(globalDelta),
  16095. localCurrent = add(localStart, localDelta);
  16096. // activate context explicitly or once threshold is reached
  16097. if (!context.active && (activate || getLength(globalDelta) > context.threshold)) {
  16098. // fire start event with original
  16099. // starting coordinates
  16100. assign(payload, {
  16101. x: localStart.x,
  16102. y: localStart.y,
  16103. dx: 0,
  16104. dy: 0
  16105. }, { originalEvent: event });
  16106. if (false === fire('start')) {
  16107. return cancel();
  16108. }
  16109. context.active = true;
  16110. // unset selection and remember old selection
  16111. // the previous (old) selection will always passed
  16112. // with the event via the event.previousSelection property
  16113. if (!context.keepSelection) {
  16114. payload.previousSelection = selection.get();
  16115. selection.select(null);
  16116. }
  16117. // allow custom cursor
  16118. if (context.cursor) {
  16119. Cursor.set(context.cursor);
  16120. }
  16121. }
  16122. suppressEvent(event);
  16123. if (context.active) {
  16124. // update payload with actual coordinates
  16125. assign(payload, {
  16126. x: localCurrent.x,
  16127. y: localCurrent.y,
  16128. dx: localDelta.x,
  16129. dy: localDelta.y
  16130. }, { originalEvent: event });
  16131. // emit move event
  16132. fire('move');
  16133. }
  16134. }
  16135. function end(event) {
  16136. var returnValue = true;
  16137. if (context.active) {
  16138. if (event) {
  16139. context.payload.originalEvent = event;
  16140. // suppress original event (click, ...)
  16141. // because we just ended a drag operation
  16142. suppressEvent(event);
  16143. }
  16144. // implementations may stop restoring the
  16145. // original state (selections, ...) by preventing the
  16146. // end events default action
  16147. returnValue = fire('end');
  16148. }
  16149. if (returnValue === false) {
  16150. fire('rejected');
  16151. }
  16152. cleanup(returnValue !== true);
  16153. }
  16154. // cancel active drag operation if the user presses
  16155. // the ESC key on the keyboard
  16156. function checkCancel(event) {
  16157. if (event.which === 27) {
  16158. event.preventDefault();
  16159. cancel();
  16160. }
  16161. }
  16162. // prevent ghost click that might occur after a finished
  16163. // drag and drop session
  16164. function trapClickAndEnd(event) {
  16165. var untrap;
  16166. // trap the click in case we are part of an active
  16167. // drag operation. This will effectively prevent
  16168. // the ghost click that cannot be canceled otherwise.
  16169. if (context.active) {
  16170. untrap = ClickTrap.install();
  16171. setTimeout(untrap, 400);
  16172. }
  16173. end(event);
  16174. }
  16175. function trapTouch(event) {
  16176. move(event);
  16177. }
  16178. // update the drag events hover (djs.model.Base) and hoverGfx (Snap<SVGElement>)
  16179. // properties during hover and out and fire {prefix}.hover and {prefix}.out properties
  16180. // respectively
  16181. function hover(event) {
  16182. var payload = context.payload;
  16183. payload.hoverGfx = event.gfx;
  16184. payload.hover = event.element;
  16185. fire('hover');
  16186. }
  16187. function out(event) {
  16188. fire('out');
  16189. var payload = context.payload;
  16190. payload.hoverGfx = null;
  16191. payload.hover = null;
  16192. }
  16193. // life-cycle methods
  16194. function cancel(restore) {
  16195. if (!context) {
  16196. return;
  16197. }
  16198. if (context.active) {
  16199. fire('cancel');
  16200. }
  16201. cleanup(restore);
  16202. }
  16203. function cleanup(restore) {
  16204. fire('cleanup');
  16205. // reset cursor
  16206. Cursor.unset();
  16207. // reset dom listeners
  16208. domEvent.unbind(document, 'mousemove', move);
  16209. domEvent.unbind(document, 'mousedown', trapClickAndEnd, true);
  16210. domEvent.unbind(document, 'mouseup', trapClickAndEnd, true);
  16211. domEvent.unbind(document, 'keyup', checkCancel);
  16212. domEvent.unbind(document, 'touchstart', trapTouch, true);
  16213. domEvent.unbind(document, 'touchcancel', cancel, true);
  16214. domEvent.unbind(document, 'touchmove', move, true);
  16215. domEvent.unbind(document, 'touchend', end, true);
  16216. eventBus.off('element.hover', hover);
  16217. eventBus.off('element.out', out);
  16218. // restore selection, unless it has changed
  16219. var previousSelection = context.payload.previousSelection;
  16220. if (restore !== false && previousSelection && !selection.get().length) {
  16221. selection.select(previousSelection);
  16222. }
  16223. context = null;
  16224. }
  16225. /**
  16226. * Activate a drag operation.
  16227. *
  16228. * If `localPosition` is given, drag events will be emitted
  16229. * relative to it.
  16230. *
  16231. * @param {MouseEvent|TouchEvent} [event]
  16232. * @param {Point} [localPosition] actual diagram local position this drag operation should start at
  16233. * @param {String} prefix
  16234. * @param {Object} [options]
  16235. */
  16236. function activate(event, localPosition, prefix, options) {
  16237. // only one drag operation may be active, at a time
  16238. if (context) {
  16239. cancel(false);
  16240. }
  16241. if (typeof localPosition === 'string') {
  16242. options = prefix;
  16243. prefix = localPosition;
  16244. localPosition = null;
  16245. }
  16246. options = assign({}, defaultOptions, options || {});
  16247. var data = options.data || {},
  16248. originalEvent,
  16249. globalStart;
  16250. if (event) {
  16251. originalEvent = Event.getOriginal(event) || event;
  16252. globalStart = Event.toPoint(event);
  16253. suppressEvent(event);
  16254. } else {
  16255. originalEvent = null;
  16256. globalStart = { x: 0, y: 0 };
  16257. }
  16258. if (!localPosition) {
  16259. localPosition = toLocalPoint(globalStart);
  16260. }
  16261. context = assign({
  16262. prefix: prefix,
  16263. data: data,
  16264. payload: {},
  16265. globalStart: globalStart,
  16266. localStart: localPosition,
  16267. }, options);
  16268. // skip dom registration if trigger
  16269. // is set to manual (during testing)
  16270. if (!options.manual) {
  16271. // add dom listeners
  16272. // fixes TouchEvent not being available on desktop Firefox
  16273. if (typeof TouchEvent !== 'undefined' && originalEvent instanceof TouchEvent) {
  16274. domEvent.bind(document, 'touchstart', trapTouch, true);
  16275. domEvent.bind(document, 'touchcancel', cancel, true);
  16276. domEvent.bind(document, 'touchmove', move, true);
  16277. domEvent.bind(document, 'touchend', end, true);
  16278. } else {
  16279. // assume we use the mouse to interact per default
  16280. domEvent.bind(document, 'mousemove', move);
  16281. domEvent.bind(document, 'mousedown', trapClickAndEnd, true);
  16282. domEvent.bind(document, 'mouseup', trapClickAndEnd, true);
  16283. }
  16284. domEvent.bind(document, 'keyup', checkCancel);
  16285. eventBus.on('element.hover', hover);
  16286. eventBus.on('element.out', out);
  16287. }
  16288. fire('activate');
  16289. if (options.autoActivate) {
  16290. move(event, true);
  16291. }
  16292. }
  16293. // cancel on diagram destruction
  16294. eventBus.on('diagram.destroy', cancel);
  16295. // API
  16296. this.activate = activate;
  16297. this.move = move;
  16298. this.hover = hover;
  16299. this.out = out;
  16300. this.end = end;
  16301. this.cancel = cancel;
  16302. // for introspection
  16303. this.active = function() {
  16304. return context;
  16305. };
  16306. this.setOptions = function(options) {
  16307. assign(defaultOptions, options);
  16308. };
  16309. }
  16310. Dragging.$inject = [ 'eventBus', 'canvas', 'selection' ];
  16311. module.exports = Dragging;
  16312. },{"183":183,"185":185,"187":187,"339":339,"357":357,"84":84}],106:[function(_dereq_,module,exports){
  16313. module.exports = {
  16314. __depends__: [
  16315. _dereq_(159)
  16316. ],
  16317. dragging: [ 'type', _dereq_(105) ]
  16318. };
  16319. },{"105":105,"159":159}],107:[function(_dereq_,module,exports){
  16320. 'use strict';
  16321. var forEach = _dereq_(218),
  16322. domDelegate = _dereq_(355),
  16323. Renderer = _dereq_(87),
  16324. createLine = Renderer.createLine,
  16325. updateLine = Renderer.updateLine;
  16326. var isPrimaryButton = _dereq_(193).isPrimaryButton;
  16327. var Snap = _dereq_(200);
  16328. /**
  16329. * A plugin that provides interaction events for diagram elements.
  16330. *
  16331. * It emits the following events:
  16332. *
  16333. * * element.hover
  16334. * * element.out
  16335. * * element.click
  16336. * * element.dblclick
  16337. * * element.mousedown
  16338. *
  16339. * Each event is a tuple { element, gfx, originalEvent }.
  16340. *
  16341. * Canceling the event via Event#preventDefault() prevents the original DOM operation.
  16342. *
  16343. * @param {EventBus} eventBus
  16344. */
  16345. function InteractionEvents(eventBus, elementRegistry, styles) {
  16346. var HIT_STYLE = styles.cls('djs-hit', [ 'no-fill', 'no-border' ], {
  16347. stroke: 'white',
  16348. strokeWidth: 15
  16349. });
  16350. function fire(type, event) {
  16351. var target = event.delegateTarget || event.target,
  16352. gfx = target && new Snap(target),
  16353. element = elementRegistry.get(gfx),
  16354. returnValue;
  16355. if (!gfx || !element) {
  16356. return;
  16357. }
  16358. returnValue = eventBus.fire(type, { element: element, gfx: gfx, originalEvent: event });
  16359. if (returnValue === false) {
  16360. event.stopPropagation();
  16361. event.preventDefault();
  16362. }
  16363. }
  16364. var handlers = {};
  16365. function mouseHandler(type) {
  16366. var fn = handlers[type];
  16367. if (!fn) {
  16368. fn = handlers[type] = function(event) {
  16369. // only indicate left mouse button interactions
  16370. if (isPrimaryButton(event)) {
  16371. fire(type, event);
  16372. }
  16373. };
  16374. }
  16375. return fn;
  16376. }
  16377. var bindings = {
  16378. mouseover: 'element.hover',
  16379. mouseout: 'element.out',
  16380. click: 'element.click',
  16381. dblclick: 'element.dblclick',
  16382. mousedown: 'element.mousedown',
  16383. mouseup: 'element.mouseup'
  16384. };
  16385. var elementSelector = 'svg, .djs-element';
  16386. ///// event registration
  16387. function registerEvent(node, event, localEvent) {
  16388. var handler = mouseHandler(localEvent);
  16389. handler.$delegate = domDelegate.bind(node, elementSelector, event, handler);
  16390. }
  16391. function unregisterEvent(node, event, localEvent) {
  16392. domDelegate.unbind(node, event, mouseHandler(localEvent).$delegate);
  16393. }
  16394. function registerEvents(svg) {
  16395. forEach(bindings, function(val, key) {
  16396. registerEvent(svg.node, key, val);
  16397. });
  16398. }
  16399. function unregisterEvents(svg) {
  16400. forEach(bindings, function(val, key) {
  16401. unregisterEvent(svg.node, key, val);
  16402. });
  16403. }
  16404. eventBus.on('canvas.destroy', function(event) {
  16405. unregisterEvents(event.svg);
  16406. });
  16407. eventBus.on('canvas.init', function(event) {
  16408. registerEvents(event.svg);
  16409. });
  16410. eventBus.on([ 'shape.added', 'connection.added' ], function(event) {
  16411. var element = event.element,
  16412. gfx = event.gfx,
  16413. hit,
  16414. type;
  16415. if (element.waypoints) {
  16416. hit = createLine(element.waypoints);
  16417. type = 'connection';
  16418. } else {
  16419. hit = Snap.create('rect', { x: 0, y: 0, width: element.width, height: element.height });
  16420. type = 'shape';
  16421. }
  16422. hit.attr(HIT_STYLE).appendTo(gfx.node);
  16423. });
  16424. // update djs-hit on change
  16425. eventBus.on('shape.changed', function(event) {
  16426. var element = event.element,
  16427. gfx = event.gfx,
  16428. hit = gfx.select('.djs-hit');
  16429. hit.attr({
  16430. width: element.width,
  16431. height: element.height
  16432. });
  16433. });
  16434. eventBus.on('connection.changed', function(event) {
  16435. var element = event.element,
  16436. gfx = event.gfx,
  16437. hit = gfx.select('.djs-hit');
  16438. updateLine(hit, element.waypoints);
  16439. });
  16440. // API
  16441. this.fire = fire;
  16442. this.mouseHandler = mouseHandler;
  16443. this.registerEvent = registerEvent;
  16444. this.unregisterEvent = unregisterEvent;
  16445. }
  16446. InteractionEvents.$inject = [ 'eventBus', 'elementRegistry', 'styles' ];
  16447. module.exports = InteractionEvents;
  16448. /**
  16449. * An event indicating that the mouse hovered over an element
  16450. *
  16451. * @event element.hover
  16452. *
  16453. * @type {Object}
  16454. * @property {djs.model.Base} element
  16455. * @property {Snap<Element>} gfx
  16456. * @property {Event} originalEvent
  16457. */
  16458. /**
  16459. * An event indicating that the mouse has left an element
  16460. *
  16461. * @event element.out
  16462. *
  16463. * @type {Object}
  16464. * @property {djs.model.Base} element
  16465. * @property {Snap<Element>} gfx
  16466. * @property {Event} originalEvent
  16467. */
  16468. /**
  16469. * An event indicating that the mouse has clicked an element
  16470. *
  16471. * @event element.click
  16472. *
  16473. * @type {Object}
  16474. * @property {djs.model.Base} element
  16475. * @property {Snap<Element>} gfx
  16476. * @property {Event} originalEvent
  16477. */
  16478. /**
  16479. * An event indicating that the mouse has double clicked an element
  16480. *
  16481. * @event element.dblclick
  16482. *
  16483. * @type {Object}
  16484. * @property {djs.model.Base} element
  16485. * @property {Snap<Element>} gfx
  16486. * @property {Event} originalEvent
  16487. */
  16488. /**
  16489. * An event indicating that the mouse has gone down on an element.
  16490. *
  16491. * @event element.mousedown
  16492. *
  16493. * @type {Object}
  16494. * @property {djs.model.Base} element
  16495. * @property {Snap<Element>} gfx
  16496. * @property {Event} originalEvent
  16497. */
  16498. /**
  16499. * An event indicating that the mouse has gone up on an element.
  16500. *
  16501. * @event element.mouseup
  16502. *
  16503. * @type {Object}
  16504. * @property {djs.model.Base} element
  16505. * @property {Snap<Element>} gfx
  16506. * @property {Event} originalEvent
  16507. */
  16508. },{"193":193,"200":200,"218":218,"355":355,"87":87}],108:[function(_dereq_,module,exports){
  16509. module.exports = {
  16510. __init__: [ 'interactionEvents' ],
  16511. interactionEvents: [ 'type', _dereq_(107) ]
  16512. };
  16513. },{"107":107}],109:[function(_dereq_,module,exports){
  16514. 'use strict';
  16515. var domEvent = _dereq_(357),
  16516. domMatches = _dereq_(358);
  16517. /**
  16518. * A keyboard abstraction that may be activated and
  16519. * deactivated by users at will, consuming key events
  16520. * and triggering diagram actions.
  16521. *
  16522. * The implementation fires the following key events that allow
  16523. * other components to hook into key handling:
  16524. *
  16525. * - keyboard.bind
  16526. * - keyboard.unbind
  16527. * - keyboard.init
  16528. * - keyboard.destroy
  16529. *
  16530. * All events contain the fields (node, listeners).
  16531. *
  16532. * A default binding for the keyboard may be specified via the
  16533. * `keyboard.bindTo` configuration option.
  16534. *
  16535. * @param {EventBus} eventBus
  16536. * @param {CommandStack} commandStack
  16537. * @param {Modeling} modeling
  16538. * @param {Selection} selection
  16539. */
  16540. function Keyboard(config, eventBus, commandStack, modeling, selection, zoomScroll, canvas) {
  16541. var self = this;
  16542. this._commandStack = commandStack;
  16543. this._modeling = modeling;
  16544. this._selection = selection;
  16545. this._eventBus = eventBus;
  16546. this._zoomScroll = zoomScroll;
  16547. this._canvas = canvas;
  16548. this._listeners = [];
  16549. // our key handler is a singleton that passes
  16550. // (keycode, modifiers) to each listener.
  16551. //
  16552. // listeners must indicate that they handled a key event
  16553. // by returning true. This stops the event propagation.
  16554. //
  16555. this._keyHandler = function(event) {
  16556. var i, l,
  16557. target = event.target,
  16558. listeners = self._listeners,
  16559. code = event.keyCode || event.charCode || -1;
  16560. if (domMatches(target, 'input, textarea')) {
  16561. return;
  16562. }
  16563. for (i = 0; !!(l = listeners[i]); i++) {
  16564. if (l(code, event)) {
  16565. event.preventDefault();
  16566. event.stopPropagation();
  16567. }
  16568. }
  16569. };
  16570. // properly clean dom registrations
  16571. eventBus.on('diagram.destroy', function() {
  16572. self._fire('destroy');
  16573. self.unbind();
  16574. self._listeners = null;
  16575. });
  16576. eventBus.on('diagram.init', function() {
  16577. self._fire('init');
  16578. if (config && config.bindTo) {
  16579. self.bind(config.bindTo);
  16580. }
  16581. });
  16582. this._init();
  16583. }
  16584. Keyboard.$inject = [
  16585. 'config.keyboard',
  16586. 'eventBus',
  16587. 'commandStack',
  16588. 'modeling',
  16589. 'selection',
  16590. 'zoomScroll',
  16591. 'canvas'];
  16592. module.exports = Keyboard;
  16593. Keyboard.prototype.bind = function(node) {
  16594. this._node = node;
  16595. // bind key events
  16596. domEvent.bind(node, 'keydown', this._keyHandler, true);
  16597. this._fire('bind');
  16598. };
  16599. Keyboard.prototype.getBinding = function() {
  16600. return this._node;
  16601. };
  16602. Keyboard.prototype.unbind = function() {
  16603. var node = this._node;
  16604. if (node) {
  16605. this._fire('unbind');
  16606. // unbind key events
  16607. domEvent.unbind(node, 'keydown', this._keyHandler, true);
  16608. }
  16609. this._node = null;
  16610. };
  16611. Keyboard.prototype._fire = function(event) {
  16612. this._eventBus.fire('keyboard.' + event, { node: this._node, listeners: this._listeners });
  16613. };
  16614. Keyboard.prototype._init = function() {
  16615. var listeners = this._listeners,
  16616. commandStack = this._commandStack,
  16617. modeling = this._modeling,
  16618. selection = this._selection,
  16619. zoomScroll = this._zoomScroll,
  16620. canvas = this._canvas;
  16621. // init default listeners
  16622. // undo
  16623. // (CTRL|CMD) + Z
  16624. function undo(key, modifiers) {
  16625. if (isCmd(modifiers) && !isShift(modifiers) && key === 90) {
  16626. commandStack.undo();
  16627. return true;
  16628. }
  16629. }
  16630. // redo
  16631. // CTRL + Y
  16632. // CMD + SHIFT + Z
  16633. function redo(key, modifiers) {
  16634. if (isCmd(modifiers) && (key === 89 || (key === 90 && isShift(modifiers)))) {
  16635. commandStack.redo();
  16636. return true;
  16637. }
  16638. }
  16639. /**
  16640. * zoom in one step
  16641. * CTRL + +
  16642. *
  16643. * 107 = numpad plus
  16644. * 187 = regular plus
  16645. * 171 = regular plus in Firefox (german keyboard layout)
  16646. * 61 = regular plus in Firefox (US keyboard layout)
  16647. */
  16648. function zoomIn(key, modifiers) {
  16649. if ((key === 107 || key === 187 || key === 171 || key === 61) && isCmd(modifiers)) {
  16650. zoomScroll.stepZoom(1);
  16651. return true;
  16652. }
  16653. }
  16654. /**
  16655. * zoom out one step
  16656. * CTRL + -
  16657. *
  16658. * 109 = numpad minus
  16659. * 189 = regular minus
  16660. * 173 = regular minus in Firefox (US and german keyboard layout)
  16661. */
  16662. function zoomOut(key, modifiers) {
  16663. if ((key === 109 || key === 189 || key === 173) && isCmd(modifiers)) {
  16664. zoomScroll.stepZoom(-1);
  16665. return true;
  16666. }
  16667. }
  16668. /**
  16669. * zoom to the default level
  16670. * CTRL + 0
  16671. *
  16672. * 96 = numpad zero
  16673. * 48 = regular zero
  16674. */
  16675. function zoomDefault(key, modifiers) {
  16676. if ((key === 96 || key === 48) && isCmd(modifiers)) {
  16677. canvas.zoom(1);
  16678. return true;
  16679. }
  16680. }
  16681. // delete selected element
  16682. // DEL
  16683. function remove(key, modifiers) {
  16684. if (key === 46) {
  16685. var selectedElements = selection.get();
  16686. if (selectedElements.length) {
  16687. modeling.removeElements(selectedElements.slice());
  16688. }
  16689. return true;
  16690. }
  16691. }
  16692. listeners.push(undo);
  16693. listeners.push(redo);
  16694. listeners.push(remove);
  16695. listeners.push(zoomIn);
  16696. listeners.push(zoomOut);
  16697. listeners.push(zoomDefault);
  16698. };
  16699. /**
  16700. * Add a listener function that is notified with (key, modifiers) whenever
  16701. * the keyboard is bound and the user presses a key.
  16702. *
  16703. * @param {Function} listenerFn
  16704. */
  16705. Keyboard.prototype.addListener = function(listenerFn) {
  16706. this._listeners.push(listenerFn);
  16707. };
  16708. Keyboard.prototype.hasModifier = hasModifier;
  16709. Keyboard.prototype.isCmd = isCmd;
  16710. Keyboard.prototype.isShift = isShift;
  16711. function hasModifier(modifiers) {
  16712. return (modifiers.ctrlKey || modifiers.metaKey || modifiers.shiftKey || modifiers.altKey);
  16713. }
  16714. function isCmd(modifiers) {
  16715. return modifiers.ctrlKey || modifiers.metaKey;
  16716. }
  16717. function isShift(modifiers) {
  16718. return modifiers.shiftKey;
  16719. }
  16720. },{"357":357,"358":358}],110:[function(_dereq_,module,exports){
  16721. module.exports = {
  16722. __init__: [ 'keyboard' ],
  16723. keyboard: [ 'type', _dereq_(109) ]
  16724. };
  16725. },{"109":109}],111:[function(_dereq_,module,exports){
  16726. 'use strict';
  16727. var forEach = _dereq_(218),
  16728. filter = _dereq_(216),
  16729. inherits = _dereq_(207);
  16730. var LOW_PRIORITY = 250,
  16731. HIGH_PRIORITY = 1500;
  16732. var CommandInterceptor = _dereq_(78);
  16733. /**
  16734. * A handler that makes sure labels are properly moved with
  16735. * their label targets.
  16736. */
  16737. function LabelSupport(eventBus, modeling, moveVisuals) {
  16738. CommandInterceptor.call(this, eventBus);
  16739. // remove labels from the collection that are being
  16740. // moved with other elements anyway
  16741. eventBus.on('shape.move.start', HIGH_PRIORITY, function(e) {
  16742. var context = e.context,
  16743. shapes = context.shapes;
  16744. context.shapes = removeLabels(shapes);
  16745. });
  16746. // add labels to visual's group
  16747. eventBus.on('shape.move.start', LOW_PRIORITY, function(e) {
  16748. var context = e.context,
  16749. shapes = context.shapes;
  16750. var labels = [];
  16751. forEach(shapes, function(element) {
  16752. var label = element.label;
  16753. if (label && !label.hidden && context.shapes.indexOf(label) === -1) {
  16754. labels.push(label);
  16755. }
  16756. if (element.labelTarget) {
  16757. labels.push(element);
  16758. }
  16759. });
  16760. forEach(labels, function(label) {
  16761. moveVisuals.makeDraggable(context, label, true);
  16762. });
  16763. });
  16764. // move labels after the other shapes are done moving
  16765. this.postExecute([ 'shapes.move' ], function(e) {
  16766. var context = e.context,
  16767. closure = context.closure,
  16768. enclosedElements = closure.enclosedElements;
  16769. // ensure we move all labels with their respective elements
  16770. // if they have not been moved already
  16771. forEach(enclosedElements, function(e) {
  16772. if (e.label && !enclosedElements[e.label.id]) {
  16773. modeling.moveShape(e.label, context.delta, e.parent);
  16774. }
  16775. });
  16776. });
  16777. }
  16778. inherits(LabelSupport, CommandInterceptor);
  16779. LabelSupport.$inject = [ 'eventBus', 'modeling', 'moveVisuals' ];
  16780. module.exports = LabelSupport;
  16781. /**
  16782. * Return a filtered list of elements that do not
  16783. * contain attached elements with hosts being part
  16784. * of the selection.
  16785. *
  16786. * @param {Array<djs.model.Base>} elements
  16787. *
  16788. * @return {Array<djs.model.Base>} filtered
  16789. */
  16790. function removeLabels(elements) {
  16791. return filter(elements, function(element) {
  16792. // filter out labels that are move together
  16793. // with their label targets
  16794. return elements.indexOf(element.labelTarget) === -1;
  16795. });
  16796. }
  16797. },{"207":207,"216":216,"218":218,"78":78}],112:[function(_dereq_,module,exports){
  16798. module.exports = {
  16799. __depends__: [
  16800. _dereq_(139)
  16801. ],
  16802. __init__: [ 'labelSupport'],
  16803. labelSupport: [ 'type', _dereq_(111) ]
  16804. };
  16805. },{"111":111,"139":139}],113:[function(_dereq_,module,exports){
  16806. 'use strict';
  16807. var values = _dereq_(347);
  16808. var getEnclosedElements = _dereq_(186).getEnclosedElements;
  16809. var hasPrimaryModifier = _dereq_(193).hasPrimaryModifier;
  16810. var Snap = _dereq_(200);
  16811. function LassoTool(eventBus, canvas, dragging, elementRegistry, selection) {
  16812. this._selection = selection;
  16813. this._dragging = dragging;
  16814. var self = this;
  16815. // lasso visuals implementation
  16816. /**
  16817. * A helper that realizes the selection box visual
  16818. */
  16819. var visuals = {
  16820. create: function(context) {
  16821. var container = canvas.getDefaultLayer(),
  16822. frame;
  16823. frame = context.frame = Snap.create('rect', {
  16824. class: 'djs-lasso-overlay',
  16825. width: 1,
  16826. height: 1,
  16827. x: 0,
  16828. y: 0
  16829. });
  16830. frame.appendTo(container);
  16831. },
  16832. update: function(context) {
  16833. var frame = context.frame,
  16834. bbox = context.bbox;
  16835. frame.attr({
  16836. x: bbox.x,
  16837. y: bbox.y,
  16838. width: bbox.width,
  16839. height: bbox.height
  16840. });
  16841. },
  16842. remove: function(context) {
  16843. if (context.frame) {
  16844. context.frame.remove();
  16845. }
  16846. }
  16847. };
  16848. eventBus.on('lasso.selection.end', function(event) {
  16849. setTimeout(function() {
  16850. self.activateLasso(event.originalEvent, true);
  16851. });
  16852. });
  16853. // lasso interaction implementation
  16854. eventBus.on('lasso.end', function(event) {
  16855. var bbox = toBBox(event);
  16856. var elements = elementRegistry.filter(function(element) {
  16857. return element;
  16858. });
  16859. self.select(elements, bbox);
  16860. });
  16861. eventBus.on('lasso.start', function(event) {
  16862. var context = event.context;
  16863. context.bbox = toBBox(event);
  16864. visuals.create(context);
  16865. });
  16866. eventBus.on('lasso.move', function(event) {
  16867. var context = event.context;
  16868. context.bbox = toBBox(event);
  16869. visuals.update(context);
  16870. });
  16871. eventBus.on('lasso.end', function(event) {
  16872. var context = event.context;
  16873. visuals.remove(context);
  16874. });
  16875. eventBus.on('lasso.cleanup', function(event) {
  16876. var context = event.context;
  16877. visuals.remove(context);
  16878. });
  16879. // event integration
  16880. eventBus.on('element.mousedown', 1500, function(event) {
  16881. if (hasPrimaryModifier(event)) {
  16882. self.activateLasso(event.originalEvent);
  16883. event.stopPropagation();
  16884. }
  16885. });
  16886. }
  16887. LassoTool.$inject = [
  16888. 'eventBus',
  16889. 'canvas',
  16890. 'dragging',
  16891. 'elementRegistry',
  16892. 'selection'
  16893. ];
  16894. module.exports = LassoTool;
  16895. LassoTool.prototype.activateLasso = function(event, autoActivate) {
  16896. this._dragging.activate(event, 'lasso', {
  16897. autoActivate: autoActivate,
  16898. cursor: 'crosshair',
  16899. data: {
  16900. context: {}
  16901. }
  16902. });
  16903. };
  16904. LassoTool.prototype.activateSelection = function(event) {
  16905. this._dragging.activate(event, 'lasso.selection', {
  16906. cursor: 'crosshair'
  16907. });
  16908. };
  16909. LassoTool.prototype.select = function(elements, bbox) {
  16910. var selectedElements = getEnclosedElements(elements, bbox);
  16911. this._selection.select(values(selectedElements));
  16912. };
  16913. function toBBox(event) {
  16914. var start = {
  16915. x: event.x - event.dx,
  16916. y: event.y - event.dy
  16917. };
  16918. var end = {
  16919. x: event.x,
  16920. y: event.y
  16921. };
  16922. var bbox;
  16923. if ((start.x <= end.x && start.y < end.y) ||
  16924. (start.x < end.x && start.y <= end.y)) {
  16925. bbox = {
  16926. x: start.x,
  16927. y: start.y,
  16928. width: end.x - start.x,
  16929. height: end.y - start.y
  16930. };
  16931. } else if ((start.x >= end.x && start.y < end.y) ||
  16932. (start.x > end.x && start.y <= end.y)) {
  16933. bbox = {
  16934. x: end.x,
  16935. y: start.y,
  16936. width: start.x - end.x,
  16937. height: end.y - start.y
  16938. };
  16939. } else if ((start.x <= end.x && start.y > end.y) ||
  16940. (start.x < end.x && start.y >= end.y)) {
  16941. bbox = {
  16942. x: start.x,
  16943. y: end.y,
  16944. width: end.x - start.x,
  16945. height: start.y - end.y
  16946. };
  16947. } else if ((start.x >= end.x && start.y > end.y) ||
  16948. (start.x > end.x && start.y >= end.y)) {
  16949. bbox = {
  16950. x: end.x,
  16951. y: end.y,
  16952. width: start.x - end.x,
  16953. height: start.y - end.y
  16954. };
  16955. } else {
  16956. bbox = {
  16957. x: end.x,
  16958. y: end.y,
  16959. width: 0,
  16960. height: 0
  16961. };
  16962. }
  16963. return bbox;
  16964. }
  16965. },{"186":186,"193":193,"200":200,"347":347}],114:[function(_dereq_,module,exports){
  16966. 'use strict';
  16967. module.exports = {
  16968. __init__: [ 'lassoTool' ],
  16969. lassoTool: [ 'type', _dereq_(113) ]
  16970. };
  16971. },{"113":113}],115:[function(_dereq_,module,exports){
  16972. 'use strict';
  16973. var forEach = _dereq_(218);
  16974. var model = _dereq_(176);
  16975. /**
  16976. * The basic modeling entry point.
  16977. *
  16978. * @param {EventBus} eventBus
  16979. * @param {ElementFactory} elementFactory
  16980. * @param {CommandStack} commandStack
  16981. */
  16982. function Modeling(eventBus, elementFactory, commandStack) {
  16983. this._eventBus = eventBus;
  16984. this._elementFactory = elementFactory;
  16985. this._commandStack = commandStack;
  16986. var self = this;
  16987. eventBus.on('diagram.init', function() {
  16988. // register modeling handlers
  16989. self.registerHandlers(commandStack);
  16990. });
  16991. }
  16992. Modeling.$inject = [ 'eventBus', 'elementFactory', 'commandStack' ];
  16993. module.exports = Modeling;
  16994. Modeling.prototype.getHandlers = function() {
  16995. return {
  16996. 'shape.append': _dereq_(116),
  16997. 'shape.create': _dereq_(120),
  16998. 'shape.delete': _dereq_(123),
  16999. 'shape.move': _dereq_(126),
  17000. 'shape.attach': _dereq_(117),
  17001. 'shapes.move': _dereq_(127),
  17002. 'shape.resize': _dereq_(131),
  17003. 'shape.replace': _dereq_(130),
  17004. 'spaceTool': _dereq_(132),
  17005. 'label.create': _dereq_(119),
  17006. 'connection.create': _dereq_(118),
  17007. 'connection.delete': _dereq_(121),
  17008. 'connection.move': _dereq_(125),
  17009. 'connection.layout': _dereq_(124),
  17010. 'connection.updateWaypoints': _dereq_(134),
  17011. 'connection.reconnectStart': _dereq_(129),
  17012. 'connection.reconnectEnd': _dereq_(129),
  17013. 'elements.delete': _dereq_(122),
  17014. 'element.updateAnchors': _dereq_(133)
  17015. };
  17016. };
  17017. /**
  17018. * Register handlers with the command stack
  17019. *
  17020. * @param {CommandStack} commandStack
  17021. */
  17022. Modeling.prototype.registerHandlers = function(commandStack) {
  17023. forEach(this.getHandlers(), function(handler, id) {
  17024. commandStack.registerHandler(id, handler);
  17025. });
  17026. };
  17027. ///// modeling helpers /////////////////////////////////////////
  17028. Modeling.prototype.moveShape = function(shape, delta, newParent, hints) {
  17029. var context = {
  17030. shape: shape,
  17031. delta: delta,
  17032. newParent: newParent,
  17033. hints: hints || {}
  17034. };
  17035. this._commandStack.execute('shape.move', context);
  17036. };
  17037. /**
  17038. * Update the attachment of the given shape.
  17039. *
  17040. * @param {djs.mode.Base} shape
  17041. * @param {djs.model.Base} [newHost]
  17042. */
  17043. Modeling.prototype.updateAttachment = function(shape, newHost) {
  17044. var context = {
  17045. shape: shape,
  17046. newHost: newHost
  17047. };
  17048. this._commandStack.execute('shape.attach', context);
  17049. };
  17050. /**
  17051. * Move a number of shapes to a new target, either setting it as
  17052. * the new parent or attaching it.
  17053. *
  17054. * @param {Array<djs.mode.Base>} shapes
  17055. * @param {Point} delta
  17056. * @param {djs.model.Base} [target]
  17057. * @param {Boolean} [isAttach=false]
  17058. * @param {Object} [hints]
  17059. */
  17060. Modeling.prototype.moveShapes = function(shapes, delta, target, isAttach, hints) {
  17061. if (typeof isAttach === 'object') {
  17062. hints = isAttach;
  17063. isAttach = undefined;
  17064. }
  17065. var newParent = target,
  17066. newHost;
  17067. if (isAttach === true) {
  17068. newHost = target;
  17069. newParent = target.parent;
  17070. }
  17071. if (isAttach === false) {
  17072. newHost = null;
  17073. }
  17074. var context = {
  17075. shapes: shapes,
  17076. delta: delta,
  17077. newParent: newParent,
  17078. newHost: newHost,
  17079. hints: hints || {}
  17080. };
  17081. this._commandStack.execute('shapes.move', context);
  17082. };
  17083. /**
  17084. * Update the anchors on the element with the given delta movement
  17085. * @param {djs.model.Element} element
  17086. * @param {Point} delta
  17087. */
  17088. Modeling.prototype.updateAnchors = function(element, delta) {
  17089. var context = {
  17090. element: element,
  17091. delta: delta
  17092. };
  17093. this._commandStack.execute('element.updateAnchors', context);
  17094. };
  17095. Modeling.prototype.moveConnection = function(connection, delta, newParent, hints) {
  17096. var context = {
  17097. connection: connection,
  17098. delta: delta,
  17099. newParent: newParent,
  17100. hints: hints || {}
  17101. };
  17102. this._commandStack.execute('connection.move', context);
  17103. };
  17104. Modeling.prototype.layoutConnection = function(connection, hints) {
  17105. var context = {
  17106. connection: connection,
  17107. hints: hints || {}
  17108. };
  17109. this._commandStack.execute('connection.layout', context);
  17110. };
  17111. Modeling.prototype.createConnection = function(source, target, connection, parent) {
  17112. connection = this._create('connection', connection);
  17113. var context = {
  17114. source: source,
  17115. target: target,
  17116. parent: parent,
  17117. connection: connection
  17118. };
  17119. this._commandStack.execute('connection.create', context);
  17120. return context.connection;
  17121. };
  17122. Modeling.prototype.createShape = function(shape, position, target, isAttach) {
  17123. shape = this._create('shape', shape);
  17124. var context = {
  17125. position: position,
  17126. shape: shape,
  17127. parent: target,
  17128. host: shape.host
  17129. };
  17130. if (isAttach) {
  17131. context.parent = target.parent;
  17132. context.host = target;
  17133. }
  17134. this._commandStack.execute('shape.create', context);
  17135. return context.shape;
  17136. };
  17137. Modeling.prototype.createLabel = function(labelTarget, position, label, parent) {
  17138. label = this._create('label', label);
  17139. var context = {
  17140. labelTarget: labelTarget,
  17141. position: position,
  17142. parent: parent,
  17143. shape: label
  17144. };
  17145. this._commandStack.execute('label.create', context);
  17146. return context.shape;
  17147. };
  17148. Modeling.prototype.appendShape = function(source, shape, position, parent, connection, connectionParent) {
  17149. shape = this._create('shape', shape);
  17150. var context = {
  17151. source: source,
  17152. position: position,
  17153. parent: parent,
  17154. shape: shape,
  17155. connection: connection,
  17156. connectionParent: connectionParent
  17157. };
  17158. this._commandStack.execute('shape.append', context);
  17159. return context.shape;
  17160. };
  17161. Modeling.prototype.removeElements = function(elements) {
  17162. var context = {
  17163. elements: elements
  17164. };
  17165. this._commandStack.execute('elements.delete', context);
  17166. };
  17167. Modeling.prototype.removeShape = function(shape) {
  17168. var context = {
  17169. shape: shape
  17170. };
  17171. this._commandStack.execute('shape.delete', context);
  17172. };
  17173. Modeling.prototype.removeConnection = function(connection) {
  17174. var context = {
  17175. connection: connection
  17176. };
  17177. this._commandStack.execute('connection.delete', context);
  17178. };
  17179. Modeling.prototype.replaceShape = function(oldShape, newShape, options) {
  17180. var context = {
  17181. oldShape: oldShape,
  17182. newData: newShape,
  17183. options: options
  17184. };
  17185. this._commandStack.execute('shape.replace', context);
  17186. return context.newShape;
  17187. };
  17188. Modeling.prototype.resizeShape = function(shape, newBounds) {
  17189. var context = {
  17190. shape: shape,
  17191. newBounds: newBounds
  17192. };
  17193. this._commandStack.execute('shape.resize', context);
  17194. };
  17195. Modeling.prototype.createSpace = function(movingShapes, resizingShapes, delta, direction) {
  17196. var context = {
  17197. movingShapes: movingShapes,
  17198. resizingShapes: resizingShapes,
  17199. delta: delta,
  17200. direction: direction
  17201. };
  17202. this._commandStack.execute('spaceTool', context);
  17203. };
  17204. Modeling.prototype.updateWaypoints = function(connection, newWaypoints) {
  17205. var context = {
  17206. connection: connection,
  17207. newWaypoints: newWaypoints
  17208. };
  17209. this._commandStack.execute('connection.updateWaypoints', context);
  17210. };
  17211. Modeling.prototype.reconnectStart = function(connection, newSource, dockingOrPoints) {
  17212. var context = {
  17213. connection: connection,
  17214. newSource: newSource,
  17215. dockingOrPoints: dockingOrPoints
  17216. };
  17217. this._commandStack.execute('connection.reconnectStart', context);
  17218. };
  17219. Modeling.prototype.reconnectEnd = function(connection, newTarget, dockingOrPoints) {
  17220. var context = {
  17221. connection: connection,
  17222. newTarget: newTarget,
  17223. dockingOrPoints: dockingOrPoints
  17224. };
  17225. this._commandStack.execute('connection.reconnectEnd', context);
  17226. };
  17227. Modeling.prototype.connect = function(source, target, attrs) {
  17228. return this.createConnection(source, target, attrs || {}, source.parent);
  17229. };
  17230. Modeling.prototype._create = function(type, attrs) {
  17231. if (attrs instanceof model.Base) {
  17232. return attrs;
  17233. } else {
  17234. return this._elementFactory.create(type, attrs);
  17235. }
  17236. };
  17237. },{"116":116,"117":117,"118":118,"119":119,"120":120,"121":121,"122":122,"123":123,"124":124,"125":125,"126":126,"127":127,"129":129,"130":130,"131":131,"132":132,"133":133,"134":134,"176":176,"218":218}],116:[function(_dereq_,module,exports){
  17238. 'use strict';
  17239. var any = _dereq_(214);
  17240. var inherits = _dereq_(207);
  17241. /**
  17242. * A handler that implements reversible appending of shapes
  17243. * to a source shape.
  17244. *
  17245. * @param {canvas} Canvas
  17246. * @param {elementFactory} ElementFactory
  17247. * @param {modeling} Modeling
  17248. */
  17249. function AppendShapeHandler(modeling) {
  17250. this._modeling = modeling;
  17251. }
  17252. inherits(AppendShapeHandler, _dereq_(128));
  17253. AppendShapeHandler.$inject = [ 'modeling' ];
  17254. module.exports = AppendShapeHandler;
  17255. ////// api /////////////////////////////////////////////
  17256. /**
  17257. * Creates a new shape
  17258. *
  17259. * @param {Object} context
  17260. * @param {ElementDescriptor} context.shape the new shape
  17261. * @param {ElementDescriptor} context.source the source object
  17262. * @param {ElementDescriptor} context.parent the parent object
  17263. * @param {Point} context.position position of the new element
  17264. */
  17265. AppendShapeHandler.prototype.preExecute = function(context) {
  17266. if (!context.source) {
  17267. throw new Error('source required');
  17268. }
  17269. var parent = context.parent || context.source.parent,
  17270. shape = this._modeling.createShape(context.shape, context.position, parent);
  17271. context.shape = shape;
  17272. };
  17273. AppendShapeHandler.prototype.postExecute = function(context) {
  17274. var parent = context.connectionParent || context.shape.parent;
  17275. if (!existsConnection(context.source, context.shape)) {
  17276. // create connection
  17277. this._modeling.connect(context.source, context.shape, context.connection, parent);
  17278. }
  17279. };
  17280. function existsConnection(source, target) {
  17281. return any(source.outgoing, function(c) {
  17282. return c.target === target;
  17283. });
  17284. }
  17285. },{"128":128,"207":207,"214":214}],117:[function(_dereq_,module,exports){
  17286. 'use strict';
  17287. var forEach = _dereq_(218),
  17288. map = _dereq_(221);
  17289. /**
  17290. * A handler that implements reversible attaching/detaching of shapes.
  17291. */
  17292. function AttachShapeHandler(modeling) {
  17293. this._modeling = modeling;
  17294. }
  17295. module.exports = AttachShapeHandler;
  17296. AttachShapeHandler.$inject = [ 'modeling' ];
  17297. AttachShapeHandler.prototype.execute = function(context) {
  17298. var shape = context.shape,
  17299. newHost = context.newHost,
  17300. oldHost = shape.host;
  17301. // (0) detach from old host
  17302. context.oldHost = oldHost;
  17303. context.attacherIdx = removeAttacher(oldHost, shape);
  17304. // (1) attach to new host
  17305. addAttacher(newHost, shape);
  17306. // position attacher and it's label on top of host
  17307. positionOnTop(context);
  17308. // (2) update host
  17309. shape.host = newHost;
  17310. return shape;
  17311. };
  17312. AttachShapeHandler.prototype.revert = function(context) {
  17313. var shape = context.shape,
  17314. newHost = context.newHost,
  17315. oldHost = context.oldHost,
  17316. attacherIdx = context.attacherIdx;
  17317. // (2) update host
  17318. shape.host = oldHost;
  17319. // (1) attach to new host
  17320. removeAttacher(newHost, shape);
  17321. // (0) detach from old host
  17322. addAttacher(oldHost, shape, attacherIdx);
  17323. // position attacher and it's label on top of oldHost
  17324. reposition(context);
  17325. return shape;
  17326. };
  17327. function insertAfter(coll, a, b) {
  17328. // b comes after a
  17329. var aIdx = coll.indexOf(a),
  17330. bIdx = coll.indexOf(b);
  17331. if ((aIdx === -1 || bIdx === -1) || (bIdx > aIdx)) {
  17332. return;
  17333. }
  17334. coll.splice(bIdx, 1);
  17335. aIdx = coll.indexOf(a);
  17336. coll.splice(aIdx, 1, a, b);
  17337. }
  17338. function positionOnTop(context) {
  17339. var shape = context.shape,
  17340. newHost = context.newHost,
  17341. oldHost = context.oldHost,
  17342. parent = shape.parent,
  17343. children = parent.children,
  17344. label;
  17345. if (!newHost) {
  17346. return;
  17347. }
  17348. var elements = (label = shape.label) ? [ oldHost, shape, label ] : [ oldHost, shape ];
  17349. context.elements = map(elements, function(element) {
  17350. return {
  17351. shape: element,
  17352. idx: children.indexOf(element)
  17353. };
  17354. });
  17355. insertAfter(children, newHost, shape);
  17356. if (label) {
  17357. insertAfter(children, shape, label);
  17358. }
  17359. }
  17360. function reposition(context) {
  17361. var shape = context.shape,
  17362. oldHost = context.oldHost,
  17363. parent = shape.parent,
  17364. children = parent.children,
  17365. elements = context.elements;
  17366. if (!oldHost) {
  17367. return;
  17368. }
  17369. forEach(elements, function(element) {
  17370. children.splice(children.indexOf(element.shape), 1);
  17371. children.splice(element.idx, 0, element.shape);
  17372. });
  17373. }
  17374. function removeAttacher(host, attacher) {
  17375. var attachers = host && host.attachers;
  17376. var idx = -1;
  17377. if (attachers) {
  17378. idx = attachers.indexOf(attacher);
  17379. if (idx !== -1) {
  17380. attachers.splice(idx, 1);
  17381. }
  17382. }
  17383. return idx;
  17384. }
  17385. function addAttacher(host, attacher, idx) {
  17386. if (!host) {
  17387. return;
  17388. }
  17389. var attachers = host.attachers;
  17390. if (!attachers) {
  17391. host.attachers = attachers = [];
  17392. }
  17393. attachers.splice(idx || attachers.length, 0, attacher);
  17394. }
  17395. },{"218":218,"221":221}],118:[function(_dereq_,module,exports){
  17396. 'use strict';
  17397. function CreateConnectionHandler(canvas, layouter) {
  17398. this._canvas = canvas;
  17399. this._layouter = layouter;
  17400. }
  17401. CreateConnectionHandler.$inject = [ 'canvas', 'layouter' ];
  17402. module.exports = CreateConnectionHandler;
  17403. ////// api /////////////////////////////////////////
  17404. /**
  17405. * Appends a shape to a target shape
  17406. *
  17407. * @param {Object} context
  17408. * @param {djs.element.Base} context.source the source object
  17409. * @param {djs.element.Base} context.target the parent object
  17410. * @param {Point} context.position position of the new element
  17411. */
  17412. CreateConnectionHandler.prototype.execute = function(context) {
  17413. var source = context.source,
  17414. target = context.target,
  17415. parent = context.parent;
  17416. if (!source || !target) {
  17417. throw new Error('source and target required');
  17418. }
  17419. if (!parent) {
  17420. throw new Error('parent required');
  17421. }
  17422. var connection = context.connection;
  17423. connection.source = source;
  17424. connection.target = target;
  17425. if (!connection.waypoints) {
  17426. connection.waypoints = this._layouter.layoutConnection(connection);
  17427. }
  17428. // add connection
  17429. this._canvas.addConnection(connection, parent);
  17430. return connection;
  17431. };
  17432. CreateConnectionHandler.prototype.revert = function(context) {
  17433. var connection = context.connection;
  17434. this._canvas.removeConnection(connection);
  17435. connection.source = null;
  17436. connection.target = null;
  17437. };
  17438. },{}],119:[function(_dereq_,module,exports){
  17439. 'use strict';
  17440. var inherits = _dereq_(207);
  17441. var CreateShapeHandler = _dereq_(120);
  17442. /**
  17443. * A handler that attaches a label to a given target shape.
  17444. *
  17445. * @param {canvas} Canvas
  17446. */
  17447. function CreateLabelHandler(canvas) {
  17448. CreateShapeHandler.call(this, canvas);
  17449. }
  17450. inherits(CreateLabelHandler, CreateShapeHandler);
  17451. CreateLabelHandler.$inject = [ 'canvas' ];
  17452. module.exports = CreateLabelHandler;
  17453. ////// api /////////////////////////////////////////
  17454. var originalExecute = CreateShapeHandler.prototype.execute;
  17455. /**
  17456. * Appends a label to a target shape.
  17457. *
  17458. * @method CreateLabelHandler#execute
  17459. *
  17460. * @param {Object} context
  17461. * @param {ElementDescriptor} context.target the element the label is attached to
  17462. * @param {ElementDescriptor} context.parent the parent object
  17463. * @param {Point} context.position position of the new element
  17464. */
  17465. CreateLabelHandler.prototype.execute = function(context) {
  17466. this.ensureValidDimensions(context);
  17467. return originalExecute.call(this, context);
  17468. };
  17469. var originalRevert = CreateShapeHandler.prototype.revert;
  17470. /**
  17471. * Undo append by removing the shape
  17472. */
  17473. CreateLabelHandler.prototype.revert = function(context) {
  17474. context.shape.labelTarget = null;
  17475. return originalRevert.call(this, context);
  17476. };
  17477. ////// helpers /////////////////////////////////////////
  17478. CreateLabelHandler.prototype.ensureValidDimensions = function(context) {
  17479. var label = context.shape;
  17480. // make sure a label has valid { width, height } dimensions
  17481. [ 'width', 'height' ].forEach(function(prop) {
  17482. if (typeof label[prop] === 'undefined') {
  17483. label[prop] = 0;
  17484. }
  17485. });
  17486. };
  17487. CreateLabelHandler.prototype.getParent = function(context) {
  17488. return context.parent || context.labelTarget && context.labelTarget.parent;
  17489. };
  17490. CreateLabelHandler.prototype.addElement = function(shape, parent, context) {
  17491. shape.labelTarget = context.labelTarget;
  17492. this._canvas.addShape(shape, parent, true);
  17493. };
  17494. },{"120":120,"207":207}],120:[function(_dereq_,module,exports){
  17495. 'use strict';
  17496. var assign = _dereq_(339);
  17497. /**
  17498. * A handler that implements reversible addition of shapes.
  17499. *
  17500. * @param {canvas} Canvas
  17501. */
  17502. function CreateShapeHandler(canvas, modeling) {
  17503. this._canvas = canvas;
  17504. this._modeling = modeling;
  17505. }
  17506. CreateShapeHandler.$inject = [ 'canvas', 'modeling' ];
  17507. module.exports = CreateShapeHandler;
  17508. ////// api /////////////////////////////////////////
  17509. /**
  17510. * Appends a shape to a target shape
  17511. *
  17512. * @param {Object} context
  17513. * @param {djs.model.Base} context.parent the parent object
  17514. * @param {Point} context.position position of the new element
  17515. */
  17516. CreateShapeHandler.prototype.execute = function(context) {
  17517. var parent = this.getParent(context);
  17518. var shape = context.shape;
  17519. this.setPosition(shape, context);
  17520. this.addElement(shape, parent, context);
  17521. return shape;
  17522. };
  17523. /**
  17524. * Undo append by removing the shape
  17525. */
  17526. CreateShapeHandler.prototype.revert = function(context) {
  17527. this._canvas.removeShape(context.shape);
  17528. };
  17529. CreateShapeHandler.prototype.postExecute = function(context) {
  17530. var modeling = this._modeling;
  17531. var shape = context.shape,
  17532. host = context.host;
  17533. if (!host) {
  17534. return;
  17535. }
  17536. modeling.updateAttachment(shape, host, true);
  17537. };
  17538. ////// helpers /////////////////////////////////////////
  17539. CreateShapeHandler.prototype.getParent = function(context) {
  17540. var parent = context.parent;
  17541. if (!parent) {
  17542. throw new Error('parent required');
  17543. }
  17544. return parent;
  17545. };
  17546. CreateShapeHandler.prototype.getPosition = function(context) {
  17547. if (!context.position) {
  17548. throw new Error('no position given');
  17549. }
  17550. return context.position;
  17551. };
  17552. CreateShapeHandler.prototype.addElement = function(shape, parent) {
  17553. this._canvas.addShape(shape, parent);
  17554. };
  17555. CreateShapeHandler.prototype.setPosition = function(shape, context) {
  17556. var position = this.getPosition(context);
  17557. // update to center position
  17558. // specified in create context
  17559. assign(shape, {
  17560. x: position.x - shape.width / 2,
  17561. y: position.y - shape.height / 2
  17562. });
  17563. };
  17564. },{"339":339}],121:[function(_dereq_,module,exports){
  17565. 'use strict';
  17566. var Collections = _dereq_(184);
  17567. /**
  17568. * A handler that implements reversible deletion of Connections.
  17569. *
  17570. */
  17571. function DeleteConnectionHandler(canvas, modeling) {
  17572. this._canvas = canvas;
  17573. this._modeling = modeling;
  17574. }
  17575. DeleteConnectionHandler.$inject = [ 'canvas', 'modeling' ];
  17576. module.exports = DeleteConnectionHandler;
  17577. /**
  17578. * - Remove attached label
  17579. */
  17580. DeleteConnectionHandler.prototype.preExecute = function(context) {
  17581. var connection = context.connection;
  17582. // Remove label
  17583. if (connection.label) {
  17584. this._modeling.removeShape(connection.label);
  17585. }
  17586. };
  17587. DeleteConnectionHandler.prototype.execute = function(context) {
  17588. var connection = context.connection,
  17589. parent = connection.parent;
  17590. context.parent = parent;
  17591. context.parentIndex = Collections.indexOf(parent.children, connection);
  17592. context.source = connection.source;
  17593. context.target = connection.target;
  17594. this._canvas.removeConnection(connection);
  17595. connection.source = null;
  17596. connection.target = null;
  17597. connection.label = null;
  17598. };
  17599. /**
  17600. * Command revert implementation.
  17601. */
  17602. DeleteConnectionHandler.prototype.revert = function(context) {
  17603. var connection = context.connection,
  17604. parent = context.parent,
  17605. parentIndex = context.parentIndex;
  17606. connection.source = context.source;
  17607. connection.target = context.target;
  17608. // restore previous location in old parent
  17609. Collections.add(parent.children, connection, parentIndex);
  17610. this._canvas.addConnection(connection, parent);
  17611. };
  17612. },{"184":184}],122:[function(_dereq_,module,exports){
  17613. 'use strict';
  17614. var forEach = _dereq_(218),
  17615. inherits = _dereq_(207);
  17616. function DeleteElementsHandler(modeling, elementRegistry) {
  17617. this._modeling = modeling;
  17618. this._elementRegistry = elementRegistry;
  17619. }
  17620. inherits(DeleteElementsHandler, _dereq_(128));
  17621. DeleteElementsHandler.$inject = [ 'modeling', 'elementRegistry' ];
  17622. module.exports = DeleteElementsHandler;
  17623. DeleteElementsHandler.prototype.postExecute = function(context) {
  17624. var modeling = this._modeling,
  17625. elementRegistry = this._elementRegistry,
  17626. elements = context.elements;
  17627. forEach(elements, function(element) {
  17628. // element may have been removed with previous
  17629. // remove operations already (e.g. in case of nesting)
  17630. if (!elementRegistry.get(element.id)) {
  17631. return;
  17632. }
  17633. if (element.waypoints) {
  17634. modeling.removeConnection(element);
  17635. } else {
  17636. modeling.removeShape(element);
  17637. }
  17638. });
  17639. };
  17640. },{"128":128,"207":207,"218":218}],123:[function(_dereq_,module,exports){
  17641. 'use strict';
  17642. var forEach = _dereq_(218);
  17643. var Collections = _dereq_(184);
  17644. var saveClear = _dereq_(195).saveClear;
  17645. /**
  17646. * A handler that implements reversible deletion of shapes.
  17647. *
  17648. */
  17649. function DeleteShapeHandler(canvas, modeling) {
  17650. this._canvas = canvas;
  17651. this._modeling = modeling;
  17652. }
  17653. DeleteShapeHandler.$inject = [ 'canvas', 'modeling' ];
  17654. module.exports = DeleteShapeHandler;
  17655. /**
  17656. * - Remove connections
  17657. * - Remove all direct children
  17658. */
  17659. DeleteShapeHandler.prototype.preExecute = function(context) {
  17660. var modeling = this._modeling;
  17661. var shape = context.shape,
  17662. label = shape.label;
  17663. // Clean up on removeShape(label)
  17664. if (shape.labelTarget) {
  17665. context.labelTarget = shape.labelTarget;
  17666. shape.labelTarget = null;
  17667. }
  17668. // Remove label
  17669. if (label) {
  17670. this._modeling.removeShape(label);
  17671. }
  17672. // remove connections
  17673. saveClear(shape.incoming, function(connection) {
  17674. // To make sure that the connection isn't removed twice
  17675. // For example if a container is removed
  17676. modeling.removeConnection(connection);
  17677. });
  17678. saveClear(shape.outgoing, function(connection) {
  17679. modeling.removeConnection(connection);
  17680. });
  17681. // remove children
  17682. saveClear(shape.children, function(e) {
  17683. modeling.removeShape(e);
  17684. });
  17685. };
  17686. /**
  17687. * Remove shape and remember the parent
  17688. */
  17689. DeleteShapeHandler.prototype.execute = function(context) {
  17690. var canvas = this._canvas;
  17691. var shape = context.shape,
  17692. parent = shape.parent,
  17693. host = shape.host;
  17694. context.parent = parent;
  17695. context.parentIndex = Collections.indexOf(parent.children, shape);
  17696. if (host) {
  17697. context.hostIndex = Collections.indexOf(host.attachers, shape);
  17698. Collections.remove(host && host.attachers, shape);
  17699. }
  17700. shape.label = null;
  17701. canvas.removeShape(shape);
  17702. };
  17703. /**
  17704. * Command revert implementation
  17705. */
  17706. DeleteShapeHandler.prototype.revert = function(context) {
  17707. var canvas = this._canvas;
  17708. var shape = context.shape,
  17709. parent = context.parent,
  17710. parentIndex = context.parentIndex,
  17711. labelTarget = context.labelTarget,
  17712. attachers = shape.attachers,
  17713. host = shape.host;
  17714. // restore previous location in old parent
  17715. Collections.add(parent.children, shape, parentIndex);
  17716. if (host) {
  17717. Collections.add(host && host.attachers, shape, context.hostIndex);
  17718. }
  17719. if (labelTarget) {
  17720. labelTarget.label = shape;
  17721. }
  17722. canvas.addShape(shape, parent);
  17723. if (attachers) {
  17724. forEach(attachers, function(attacher) {
  17725. canvas.addShape(attacher, parent);
  17726. });
  17727. }
  17728. };
  17729. },{"184":184,"195":195,"218":218}],124:[function(_dereq_,module,exports){
  17730. 'use strict';
  17731. var assign = _dereq_(339);
  17732. /**
  17733. * A handler that implements reversible moving of shapes.
  17734. */
  17735. function LayoutConnectionHandler(layouter, canvas) {
  17736. this._layouter = layouter;
  17737. this._canvas = canvas;
  17738. }
  17739. LayoutConnectionHandler.$inject = [ 'layouter', 'canvas' ];
  17740. module.exports = LayoutConnectionHandler;
  17741. LayoutConnectionHandler.prototype.execute = function(context) {
  17742. var connection = context.connection,
  17743. parent = connection.parent,
  17744. connectionSiblings = parent.children;
  17745. var oldIndex = connectionSiblings.indexOf(connection);
  17746. assign(context, {
  17747. oldWaypoints: connection.waypoints,
  17748. oldIndex: oldIndex
  17749. });
  17750. sendToFront(connection);
  17751. connection.waypoints = this._layouter.layoutConnection(connection, context.hints);
  17752. return connection;
  17753. };
  17754. LayoutConnectionHandler.prototype.revert = function(context) {
  17755. var connection = context.connection,
  17756. parent = connection.parent,
  17757. connectionSiblings = parent.children,
  17758. currentIndex = connectionSiblings.indexOf(connection),
  17759. oldIndex = context.oldIndex;
  17760. connection.waypoints = context.oldWaypoints;
  17761. if (oldIndex !== currentIndex) {
  17762. // change position of connection in shape
  17763. connectionSiblings.splice(currentIndex, 1);
  17764. connectionSiblings.splice(oldIndex, 0, connection);
  17765. }
  17766. return connection;
  17767. };
  17768. // connections should have a higher z-order as there source and targets
  17769. function sendToFront(connection) {
  17770. var connectionSiblings = connection.parent.children;
  17771. var connectionIdx = connectionSiblings.indexOf(connection),
  17772. sourceIdx = findIndex(connectionSiblings, connection.source),
  17773. targetIdx = findIndex(connectionSiblings, connection.target),
  17774. // ensure we do not send the connection back
  17775. // if it is already in front
  17776. insertIndex = Math.max(sourceIdx + 1, targetIdx + 1, connectionIdx);
  17777. if (connectionIdx < insertIndex) {
  17778. connectionSiblings.splice(insertIndex, 0, connection); // add to new position
  17779. connectionSiblings.splice(connectionIdx, 1); // remove from old position
  17780. }
  17781. function findIndex(array, obj) {
  17782. var index = array.indexOf(obj);
  17783. if (index < 0 && obj) {
  17784. var parent = obj.parent;
  17785. index = findIndex(array, parent);
  17786. }
  17787. return index;
  17788. }
  17789. return insertIndex;
  17790. }
  17791. },{"339":339}],125:[function(_dereq_,module,exports){
  17792. 'use strict';
  17793. var forEach = _dereq_(218);
  17794. var Collections = _dereq_(184);
  17795. /**
  17796. * A handler that implements reversible moving of connections.
  17797. *
  17798. * The handler differs from the layout connection handler in a sense
  17799. * that it preserves the connection layout.
  17800. */
  17801. function MoveConnectionHandler() { }
  17802. module.exports = MoveConnectionHandler;
  17803. MoveConnectionHandler.prototype.execute = function(context) {
  17804. var updateAnchors = (context.hints.updateAnchors !== false);
  17805. var connection = context.connection,
  17806. delta = context.delta;
  17807. var newParent = this.getNewParent(connection, context),
  17808. oldParent = connection.parent;
  17809. // save old position + parent in context
  17810. context.oldParent = oldParent;
  17811. context.oldParentIndex = Collections.indexOf(oldParent.children, connection);
  17812. // update waypoint positions
  17813. forEach(connection.waypoints, function(p) {
  17814. p.x += delta.x;
  17815. p.y += delta.y;
  17816. if (updateAnchors && p.original) {
  17817. p.original.x += delta.x;
  17818. p.original.y += delta.y;
  17819. }
  17820. });
  17821. // update parent
  17822. connection.parent = newParent;
  17823. return connection;
  17824. };
  17825. MoveConnectionHandler.prototype.revert = function(context) {
  17826. var updateAnchors = (context.hints.updateAnchors !== false);
  17827. var connection = context.connection,
  17828. oldParent = context.oldParent,
  17829. oldParentIndex = context.oldParentIndex,
  17830. delta = context.delta;
  17831. // restore previous location in old parent
  17832. Collections.add(oldParent.children, connection, oldParentIndex);
  17833. // restore parent
  17834. connection.parent = oldParent;
  17835. // revert to old waypoint positions
  17836. forEach(connection.waypoints, function(p) {
  17837. p.x -= delta.x;
  17838. p.y -= delta.y;
  17839. if (updateAnchors && p.original) {
  17840. p.original.x -= delta.x;
  17841. p.original.y -= delta.y;
  17842. }
  17843. });
  17844. return connection;
  17845. };
  17846. MoveConnectionHandler.prototype.getNewParent = function(connection, context) {
  17847. return context.newParent || connection.parent;
  17848. };
  17849. },{"184":184,"218":218}],126:[function(_dereq_,module,exports){
  17850. 'use strict';
  17851. var assign = _dereq_(339),
  17852. forEach = _dereq_(218);
  17853. var MoveHelper = _dereq_(135),
  17854. Collections = _dereq_(184);
  17855. /**
  17856. * A handler that implements reversible moving of shapes.
  17857. */
  17858. function MoveShapeHandler(modeling) {
  17859. this._modeling = modeling;
  17860. this._helper = new MoveHelper(modeling);
  17861. }
  17862. MoveShapeHandler.$inject = [ 'modeling' ];
  17863. module.exports = MoveShapeHandler;
  17864. MoveShapeHandler.prototype.execute = function(context) {
  17865. var shape = context.shape,
  17866. delta = context.delta,
  17867. newParent = this.getNewParent(context),
  17868. oldParent = shape.parent;
  17869. // save old parent in context
  17870. context.oldParent = oldParent;
  17871. context.oldParentIndex = Collections.indexOf(oldParent.children, shape);
  17872. // update shape parent + position
  17873. assign(shape, {
  17874. parent: newParent,
  17875. x: shape.x + delta.x,
  17876. y: shape.y + delta.y
  17877. });
  17878. return shape;
  17879. };
  17880. MoveShapeHandler.prototype.postExecute = function(context) {
  17881. var shape = context.shape,
  17882. delta = context.delta;
  17883. var modeling = this._modeling;
  17884. if (context.hints.updateAnchors !== false) {
  17885. modeling.updateAnchors(shape, delta);
  17886. }
  17887. if (context.hints.layout !== false) {
  17888. forEach(shape.incoming, function(c) {
  17889. modeling.layoutConnection(c, { endChanged: true });
  17890. });
  17891. forEach(shape.outgoing, function(c) {
  17892. modeling.layoutConnection(c, { startChanged: true });
  17893. });
  17894. }
  17895. if (context.hints.recurse !== false) {
  17896. this.moveChildren(context);
  17897. }
  17898. };
  17899. MoveShapeHandler.prototype.revert = function(context) {
  17900. var shape = context.shape,
  17901. oldParent = context.oldParent,
  17902. oldParentIndex = context.oldParentIndex,
  17903. delta = context.delta;
  17904. // restore previous location in old parent
  17905. Collections.add(oldParent.children, shape, oldParentIndex);
  17906. // revert to old position and parent
  17907. assign(shape, {
  17908. parent: oldParent,
  17909. x: shape.x - delta.x,
  17910. y: shape.y - delta.y
  17911. });
  17912. return shape;
  17913. };
  17914. MoveShapeHandler.prototype.moveChildren = function(context) {
  17915. var delta = context.delta,
  17916. shape = context.shape;
  17917. this._helper.moveRecursive(shape.children, delta, null);
  17918. };
  17919. MoveShapeHandler.prototype.getNewParent = function(context) {
  17920. return context.newParent || context.shape.parent;
  17921. };
  17922. },{"135":135,"184":184,"218":218,"339":339}],127:[function(_dereq_,module,exports){
  17923. 'use strict';
  17924. var MoveHelper = _dereq_(135);
  17925. /**
  17926. * A handler that implements reversible moving of shapes.
  17927. */
  17928. function MoveShapesHandler(modeling) {
  17929. this._helper = new MoveHelper(modeling);
  17930. }
  17931. MoveShapesHandler.$inject = [ 'modeling' ];
  17932. module.exports = MoveShapesHandler;
  17933. MoveShapesHandler.prototype.preExecute = function(context) {
  17934. context.closure = this._helper.getClosure(context.shapes);
  17935. };
  17936. MoveShapesHandler.prototype.postExecute = function(context) {
  17937. this._helper.moveClosure(context.closure, context.delta, context.newParent, context.newHost);
  17938. };
  17939. MoveShapesHandler.prototype.execute = function(context) { };
  17940. MoveShapesHandler.prototype.revert = function(context) { };
  17941. },{"135":135}],128:[function(_dereq_,module,exports){
  17942. 'use strict';
  17943. function NoopHandler() {}
  17944. module.exports = NoopHandler;
  17945. NoopHandler.prototype.execute = function() {};
  17946. NoopHandler.prototype.revert = function() {};
  17947. },{}],129:[function(_dereq_,module,exports){
  17948. 'use strict';
  17949. var isArray = _dereq_(330);
  17950. /**
  17951. * Reconnect connection handler
  17952. */
  17953. function ReconnectConnectionHandler() { }
  17954. ReconnectConnectionHandler.$inject = [ ];
  17955. module.exports = ReconnectConnectionHandler;
  17956. ReconnectConnectionHandler.prototype.execute = function(context) {
  17957. var newSource = context.newSource,
  17958. newTarget = context.newTarget,
  17959. connection = context.connection,
  17960. dockingOrPoints = context.dockingOrPoints,
  17961. oldWaypoints = connection.waypoints,
  17962. newWaypoints;
  17963. if (!newSource && !newTarget) {
  17964. throw new Error('newSource or newTarget are required');
  17965. }
  17966. if (newSource && newTarget) {
  17967. throw new Error('must specify either newSource or newTarget');
  17968. }
  17969. context.oldWaypoints = oldWaypoints;
  17970. if (isArray(dockingOrPoints)) {
  17971. newWaypoints = dockingOrPoints;
  17972. } else {
  17973. newWaypoints = oldWaypoints.slice();
  17974. newWaypoints.splice(newSource ? 0 : -1, 1, dockingOrPoints);
  17975. }
  17976. if (newSource) {
  17977. context.oldSource = connection.source;
  17978. connection.source = newSource;
  17979. }
  17980. if (newTarget) {
  17981. context.oldTarget = connection.target;
  17982. connection.target = newTarget;
  17983. }
  17984. connection.waypoints = newWaypoints;
  17985. return connection;
  17986. };
  17987. ReconnectConnectionHandler.prototype.revert = function(context) {
  17988. var newSource = context.newSource,
  17989. newTarget = context.newTarget,
  17990. connection = context.connection;
  17991. if (newSource) {
  17992. connection.source = context.oldSource;
  17993. }
  17994. if (newTarget) {
  17995. connection.target = context.oldTarget;
  17996. }
  17997. connection.waypoints = context.oldWaypoints;
  17998. return connection;
  17999. };
  18000. },{"330":330}],130:[function(_dereq_,module,exports){
  18001. 'use strict';
  18002. var forEach = _dereq_(218);
  18003. /**
  18004. * A handler that implements reversible replacing of shapes.
  18005. * Internally the old shape will be removed and the new shape will be added.
  18006. *
  18007. *
  18008. * @class
  18009. * @constructor
  18010. *
  18011. * @param {canvas} Canvas
  18012. */
  18013. function ReplaceShapeHandler(modeling, rules) {
  18014. this._modeling = modeling;
  18015. this._rules = rules;
  18016. }
  18017. ReplaceShapeHandler.$inject = [ 'modeling', 'rules' ];
  18018. module.exports = ReplaceShapeHandler;
  18019. ////// api /////////////////////////////////////////
  18020. /**
  18021. * Replaces a shape with an replacement Element.
  18022. *
  18023. * The newData object should contain type, x, y.
  18024. *
  18025. * If possible also the incoming/outgoing connection
  18026. * will be restored.
  18027. *
  18028. * @param {Object} context
  18029. */
  18030. ReplaceShapeHandler.prototype.preExecute = function(context) {
  18031. var modeling = this._modeling,
  18032. rules = this._rules;
  18033. var oldShape = context.oldShape,
  18034. newData = context.newData,
  18035. newShape;
  18036. // (1) place a new shape at the given position
  18037. var position = {
  18038. x: newData.x,
  18039. y: newData.y
  18040. };
  18041. newShape = context.newShape = context.newShape || modeling.createShape(newData, position, oldShape.parent);
  18042. // (2) update the host
  18043. if (oldShape.host) {
  18044. modeling.updateAttachment(newShape, oldShape.host);
  18045. }
  18046. // (3) adopt all children from the old shape
  18047. modeling.moveShapes(oldShape.children, { x: 0, y: 0 }, newShape);
  18048. // (4) reconnect connections to the new shape (where allowed)
  18049. var incoming = oldShape.incoming.slice(),
  18050. outgoing = oldShape.outgoing.slice();
  18051. forEach(incoming, function(connection) {
  18052. var waypoints = connection.waypoints,
  18053. docking = waypoints[waypoints.length - 1],
  18054. allowed = rules.allowed('connection.reconnectEnd', {
  18055. source: connection.source,
  18056. target: newShape,
  18057. connection: connection
  18058. });
  18059. if (allowed) {
  18060. modeling.reconnectEnd(connection, newShape, docking);
  18061. }
  18062. });
  18063. forEach(outgoing, function(connection) {
  18064. var waypoints = connection.waypoints,
  18065. docking = waypoints[0],
  18066. allowed = rules.allowed('connection.reconnectStart', {
  18067. source: newShape,
  18068. target: connection.target,
  18069. connection: connection
  18070. });
  18071. if (allowed) {
  18072. modeling.reconnectStart(connection, newShape, docking);
  18073. }
  18074. });
  18075. };
  18076. ReplaceShapeHandler.prototype.postExecute = function(context) {
  18077. var modeling = this._modeling;
  18078. var oldShape = context.oldShape;
  18079. modeling.removeShape(oldShape);
  18080. };
  18081. ReplaceShapeHandler.prototype.execute = function(context) {};
  18082. ReplaceShapeHandler.prototype.revert = function(context) {};
  18083. },{"218":218}],131:[function(_dereq_,module,exports){
  18084. 'use strict';
  18085. var assign = _dereq_(339),
  18086. forEach = _dereq_(218);
  18087. /**
  18088. * A handler that implements reversible resizing of shapes.
  18089. *
  18090. */
  18091. function ResizeShapeHandler(modeling) {
  18092. this._modeling = modeling;
  18093. }
  18094. ResizeShapeHandler.$inject = [ 'modeling' ];
  18095. module.exports = ResizeShapeHandler;
  18096. /**
  18097. * {
  18098. * shape: {....}
  18099. * newBounds: {
  18100. * width: 20,
  18101. * height: 40,
  18102. * x: 5,
  18103. * y: 10
  18104. * }
  18105. *
  18106. * }
  18107. */
  18108. ResizeShapeHandler.prototype.execute = function(context) {
  18109. var shape = context.shape,
  18110. newBounds = context.newBounds;
  18111. if (newBounds.x === undefined || newBounds.y === undefined ||
  18112. newBounds.width === undefined || newBounds.height === undefined) {
  18113. throw new Error('newBounds must have {x, y, width, height} properties');
  18114. }
  18115. if (newBounds.width < 10 || newBounds.height < 10) {
  18116. throw new Error('width and height cannot be less than 10px');
  18117. }
  18118. // save old bbox in context
  18119. context.oldBounds = {
  18120. width: shape.width,
  18121. height: shape.height,
  18122. x: shape.x,
  18123. y: shape.y
  18124. };
  18125. // update shape
  18126. assign(shape, {
  18127. width: newBounds.width,
  18128. height: newBounds.height,
  18129. x: newBounds.x,
  18130. y: newBounds.y
  18131. });
  18132. return shape;
  18133. };
  18134. ResizeShapeHandler.prototype.postExecute = function(context) {
  18135. var shape = context.shape;
  18136. var modeling = this._modeling;
  18137. forEach(shape.incoming, function(c) {
  18138. modeling.layoutConnection(c, { endChanged: true });
  18139. });
  18140. forEach(shape.outgoing, function(c) {
  18141. modeling.layoutConnection(c, { startChanged: true });
  18142. });
  18143. };
  18144. ResizeShapeHandler.prototype.revert = function(context) {
  18145. var shape = context.shape,
  18146. oldBounds = context.oldBounds;
  18147. // restore previous bbox
  18148. assign(shape, {
  18149. width: oldBounds.width,
  18150. height: oldBounds.height,
  18151. x: oldBounds.x,
  18152. y: oldBounds.y
  18153. });
  18154. return shape;
  18155. };
  18156. },{"218":218,"339":339}],132:[function(_dereq_,module,exports){
  18157. 'use strict';
  18158. var forEach = _dereq_(218);
  18159. var SpaceUtil = _dereq_(165);
  18160. /**
  18161. * A handler that implements reversible creating and removing of space.
  18162. *
  18163. * It executes in two phases:
  18164. *
  18165. * (1) resize all affected resizeShapes
  18166. * (2) move all affected moveShapes
  18167. */
  18168. function SpaceToolHandler(modeling) {
  18169. this._modeling = modeling;
  18170. }
  18171. SpaceToolHandler.$inject = [ 'modeling' ];
  18172. module.exports = SpaceToolHandler;
  18173. SpaceToolHandler.prototype.preExecute = function(context) {
  18174. // resize
  18175. var modeling = this._modeling,
  18176. resizingShapes = context.resizingShapes,
  18177. delta = context.delta,
  18178. direction = context.direction;
  18179. forEach(resizingShapes, function(shape) {
  18180. var newBounds = SpaceUtil.resizeBounds(shape, direction, delta);
  18181. modeling.resizeShape(shape, newBounds);
  18182. });
  18183. };
  18184. SpaceToolHandler.prototype.postExecute = function(context) {
  18185. // move
  18186. var modeling = this._modeling,
  18187. movingShapes = context.movingShapes,
  18188. delta = context.delta;
  18189. modeling.moveShapes(movingShapes, delta);
  18190. };
  18191. SpaceToolHandler.prototype.execute = function(context) {};
  18192. SpaceToolHandler.prototype.revert = function(context) {};
  18193. },{"165":165,"218":218}],133:[function(_dereq_,module,exports){
  18194. 'use strict';
  18195. var forEach = _dereq_(218),
  18196. assign = _dereq_(339);
  18197. /**
  18198. * Update the anchors of
  18199. */
  18200. function UpdateAnchorsHandler() { }
  18201. module.exports = UpdateAnchorsHandler;
  18202. UpdateAnchorsHandler.prototype.execute = function(context) {
  18203. // update connection anchors
  18204. return this.updateAnchors(context.element, context.delta);
  18205. };
  18206. UpdateAnchorsHandler.prototype.revert = function(context) {
  18207. var delta = context.delta,
  18208. revertedDelta = { x: -1 * delta.x, y: -1 * delta.y };
  18209. // revert update connection anchors
  18210. return this.updateAnchors(context.element, revertedDelta);
  18211. };
  18212. /**
  18213. * Update anchors on the element according to the delta movement.
  18214. *
  18215. * @param {djs.model.Element} element
  18216. * @param {Point} delta
  18217. *
  18218. * @return Array<djs.model.Connection>
  18219. */
  18220. UpdateAnchorsHandler.prototype.updateAnchors = function(element, delta) {
  18221. function add(point, delta) {
  18222. return {
  18223. x: point.x + delta.x,
  18224. y: point.y + delta.y
  18225. };
  18226. }
  18227. function updateAnchor(waypoint) {
  18228. var original = waypoint.original;
  18229. waypoint.original = assign(original || {}, add(original || waypoint, delta));
  18230. }
  18231. var changed = [];
  18232. forEach(element.incoming, function(c) {
  18233. var waypoints = c.waypoints;
  18234. updateAnchor(waypoints[waypoints.length - 1]);
  18235. changed.push(c);
  18236. });
  18237. forEach(element.outgoing, function(c) {
  18238. var waypoints = c.waypoints;
  18239. updateAnchor(waypoints[0]);
  18240. changed.push(c);
  18241. });
  18242. return changed;
  18243. };
  18244. },{"218":218,"339":339}],134:[function(_dereq_,module,exports){
  18245. 'use strict';
  18246. function UpdateWaypointsHandler() { }
  18247. module.exports = UpdateWaypointsHandler;
  18248. UpdateWaypointsHandler.prototype.execute = function(context) {
  18249. var connection = context.connection,
  18250. newWaypoints = context.newWaypoints;
  18251. context.oldWaypoints = connection.waypoints;
  18252. connection.waypoints = newWaypoints;
  18253. return connection;
  18254. };
  18255. UpdateWaypointsHandler.prototype.revert = function(context) {
  18256. var connection = context.connection,
  18257. oldWaypoints = context.oldWaypoints;
  18258. connection.waypoints = oldWaypoints;
  18259. return connection;
  18260. };
  18261. },{}],135:[function(_dereq_,module,exports){
  18262. 'use strict';
  18263. var forEach = _dereq_(218);
  18264. var Elements = _dereq_(186);
  18265. /**
  18266. * A helper that is able to carry out serialized move operations on multiple elements.
  18267. *
  18268. * @param {Modeling} modeling
  18269. */
  18270. function MoveHelper(modeling) {
  18271. this._modeling = modeling;
  18272. }
  18273. module.exports = MoveHelper;
  18274. /**
  18275. * Move the specified elements and all children by the given delta.
  18276. *
  18277. * This moves all enclosed connections, too and layouts all affected
  18278. * external connections.
  18279. *
  18280. * @param {Array<djs.model.Base>} elements
  18281. * @param {Point} delta
  18282. * @param {djs.model.Base} newParent applied to the first level of shapes
  18283. *
  18284. * @return {Array<djs.model.Base>} list of touched elements
  18285. */
  18286. MoveHelper.prototype.moveRecursive = function(elements, delta, newParent) {
  18287. return this.moveClosure(this.getClosure(elements), delta, newParent);
  18288. };
  18289. /**
  18290. * Move the given closure of elmements.
  18291. *
  18292. * @param {Object} closure
  18293. * @param {Point} delta
  18294. * @param {djs.model.Base} [newParent]
  18295. * @param {djs.model.Base} [newHost]
  18296. */
  18297. MoveHelper.prototype.moveClosure = function(closure, delta, newParent, newHost) {
  18298. var modeling = this._modeling;
  18299. var allShapes = closure.allShapes,
  18300. allConnections = closure.allConnections,
  18301. enclosedConnections = closure.enclosedConnections,
  18302. topLevel = closure.topLevel;
  18303. // move all shapes
  18304. forEach(allShapes, function(s) {
  18305. // move the element according to the given delta
  18306. modeling.moveShape(s, delta, topLevel[s.id] && newParent, {
  18307. recurse: false,
  18308. layout: false
  18309. });
  18310. });
  18311. // move all child connections / layout external connections
  18312. forEach(allConnections, function(c) {
  18313. var startMoved = !!allShapes[c.source.id],
  18314. endMoved = !!allShapes[c.target.id];
  18315. if (enclosedConnections[c.id] && startMoved && endMoved) {
  18316. modeling.moveConnection(c, delta, topLevel[c.id] && newParent, { updateAnchors: false });
  18317. } else {
  18318. modeling.layoutConnection(c, {
  18319. startChanged: startMoved,
  18320. endChanged: endMoved
  18321. });
  18322. }
  18323. });
  18324. };
  18325. /**
  18326. * Returns the closure for the selected elements
  18327. *
  18328. * @param {Array<djs.model.Base>} elements
  18329. * @return {Object} closure
  18330. */
  18331. MoveHelper.prototype.getClosure = function(elements) {
  18332. return Elements.getClosure(elements);
  18333. };
  18334. },{"186":186,"218":218}],136:[function(_dereq_,module,exports){
  18335. module.exports = {
  18336. __depends__: [
  18337. _dereq_(80),
  18338. _dereq_(98),
  18339. _dereq_(155)
  18340. ],
  18341. __init__: [ 'modeling' ],
  18342. modeling: [ 'type', _dereq_(115) ],
  18343. layouter: [ 'type', _dereq_(172) ]
  18344. };
  18345. },{"115":115,"155":155,"172":172,"80":80,"98":98}],137:[function(_dereq_,module,exports){
  18346. 'use strict';
  18347. var assign = _dereq_(339),
  18348. filter = _dereq_(216),
  18349. groupBy = _dereq_(219);
  18350. var LOW_PRIORITY = 500,
  18351. MEDIUM_PRIORITY = 1250,
  18352. HIGH_PRIORITY = 1500;
  18353. var getOriginalEvent = _dereq_(187).getOriginal;
  18354. var round = Math.round;
  18355. function mid(element) {
  18356. return {
  18357. x: element.x + round(element.width / 2),
  18358. y: element.y + round(element.height / 2)
  18359. };
  18360. }
  18361. /**
  18362. * A plugin that makes shapes draggable / droppable.
  18363. *
  18364. * @param {EventBus} eventBus
  18365. * @param {Dragging} dragging
  18366. * @param {Modeling} modeling
  18367. * @param {Selection} selection
  18368. * @param {Rules} rules
  18369. */
  18370. function MoveEvents(eventBus, dragging, modeling, selection, rules) {
  18371. // rules
  18372. function canMove(shapes, delta, position, target) {
  18373. return rules.allowed('shapes.move', {
  18374. shapes: shapes,
  18375. delta: delta,
  18376. position: position,
  18377. target: target
  18378. });
  18379. }
  18380. // move events
  18381. // assign a high priority to this handler to setup the environment
  18382. // others may hook up later, e.g. at default priority and modify
  18383. // the move environment
  18384. //
  18385. eventBus.on('shape.move.start', HIGH_PRIORITY, function(event) {
  18386. var context = event.context,
  18387. shape = event.shape,
  18388. shapes = selection.get().slice();
  18389. // move only single shape if the dragged element
  18390. // is not part of the current selection
  18391. if (shapes.indexOf(shape) === -1) {
  18392. shapes = [ shape ];
  18393. }
  18394. // ensure we remove nested elements in the collection
  18395. // and add attachers for a proper dragger
  18396. shapes = removeNested(shapes);
  18397. // attach shapes to drag context
  18398. assign(context, {
  18399. shapes: shapes,
  18400. shape: shape
  18401. });
  18402. });
  18403. // assign a high priority to this handler to setup the environment
  18404. // others may hook up later, e.g. at default priority and modify
  18405. // the move environment
  18406. //
  18407. eventBus.on('shape.move.start', MEDIUM_PRIORITY, function(event) {
  18408. var context = event.context,
  18409. shapes = context.shapes,
  18410. canExecute;
  18411. canExecute = context.canExecute = canMove(shapes);
  18412. // check if we can move the elements
  18413. if (!canExecute) {
  18414. // suppress move operation
  18415. event.stopPropagation();
  18416. return false;
  18417. }
  18418. });
  18419. // assign a low priority to this handler
  18420. // to let others modify the move event before we update
  18421. // the context
  18422. //
  18423. eventBus.on('shape.move.move', LOW_PRIORITY, function(event) {
  18424. var context = event.context,
  18425. shapes = context.shapes,
  18426. hover = event.hover,
  18427. delta = { x: event.dx, y: event.dy },
  18428. position = { x: event.x, y: event.y },
  18429. canExecute;
  18430. // check if we can move the elements
  18431. canExecute = canMove(shapes, delta, position, hover);
  18432. context.delta = delta;
  18433. context.canExecute = canExecute;
  18434. // simply ignore move over
  18435. if (canExecute === null) {
  18436. context.target = null;
  18437. return;
  18438. }
  18439. context.target = hover;
  18440. });
  18441. eventBus.on('shape.move.end', function(event) {
  18442. var context = event.context;
  18443. var delta = context.delta,
  18444. canExecute = context.canExecute,
  18445. isAttach = canExecute === 'attach';
  18446. if (!canExecute) {
  18447. return false;
  18448. }
  18449. // ensure we have actual pixel values deltas
  18450. // (important when zoom level was > 1 during move)
  18451. delta.x = round(delta.x);
  18452. delta.y = round(delta.y);
  18453. modeling.moveShapes(context.shapes, delta, context.target, isAttach);
  18454. });
  18455. // move activation
  18456. eventBus.on('element.mousedown', function(event) {
  18457. var originalEvent = getOriginalEvent(event);
  18458. if (!originalEvent) {
  18459. throw new Error('must supply DOM mousedown event');
  18460. }
  18461. start(originalEvent, event.element);
  18462. });
  18463. function start(event, element, activate) {
  18464. // do not move connections or the root element
  18465. if (element.waypoints || !element.parent) {
  18466. return;
  18467. }
  18468. var startPosition = mid(element);
  18469. dragging.activate(event, startPosition, 'shape.move', {
  18470. cursor: 'grabbing',
  18471. autoActivate: activate,
  18472. data: {
  18473. shape: element,
  18474. context: {}
  18475. }
  18476. });
  18477. }
  18478. // API
  18479. this.start = start;
  18480. }
  18481. MoveEvents.$inject = [ 'eventBus', 'dragging', 'modeling', 'selection', 'rules' ];
  18482. module.exports = MoveEvents;
  18483. /**
  18484. * Return a filtered list of elements that do not contain
  18485. * those nested into others.
  18486. *
  18487. * @param {Array<djs.model.Base>} elements
  18488. *
  18489. * @return {Array<djs.model.Base>} filtered
  18490. */
  18491. function removeNested(elements) {
  18492. var ids = groupBy(elements, 'id');
  18493. return filter(elements, function(element) {
  18494. while (!!(element = element.parent)) {
  18495. // parent in selection
  18496. if (ids[element.id]) {
  18497. return false;
  18498. }
  18499. }
  18500. return true;
  18501. });
  18502. }
  18503. },{"187":187,"216":216,"219":219,"339":339}],138:[function(_dereq_,module,exports){
  18504. 'use strict';
  18505. var flatten = _dereq_(208),
  18506. forEach = _dereq_(218),
  18507. filter = _dereq_(216),
  18508. find = _dereq_(217),
  18509. map = _dereq_(221);
  18510. var Elements = _dereq_(186);
  18511. var LOW_PRIORITY = 500;
  18512. var MARKER_DRAGGING = 'djs-dragging',
  18513. MARKER_OK = 'drop-ok',
  18514. MARKER_NOT_OK = 'drop-not-ok',
  18515. MARKER_ATTACH = 'attach-ok';
  18516. /**
  18517. * A plugin that makes shapes draggable / droppable.
  18518. *
  18519. * @param {EventBus} eventBus
  18520. * @param {ElementRegistry} elementRegistry
  18521. * @param {Canvas} canvas
  18522. * @param {Styles} styles
  18523. */
  18524. function MoveVisuals(eventBus, elementRegistry, canvas, styles) {
  18525. function getGfx(e) {
  18526. return elementRegistry.getGraphics(e);
  18527. }
  18528. function getVisualDragShapes(shapes) {
  18529. var elements = Elements.selfAndDirectChildren(shapes, true);
  18530. var filteredElements = removeEdges(elements);
  18531. return filteredElements;
  18532. }
  18533. function getAllDraggedElements(shapes) {
  18534. var allShapes = Elements.selfAndAllChildren(shapes, true);
  18535. var allConnections = map(allShapes, function(shape) {
  18536. return (shape.incoming || []).concat(shape.outgoing || []);
  18537. });
  18538. return flatten(allShapes.concat(allConnections), true);
  18539. }
  18540. /** set drop marker on an element */
  18541. function setMarker(element, marker) {
  18542. [ MARKER_ATTACH, MARKER_OK, MARKER_NOT_OK ].forEach(function(m) {
  18543. if (m === marker) {
  18544. canvas.addMarker(element, m);
  18545. } else {
  18546. canvas.removeMarker(element, m);
  18547. }
  18548. });
  18549. }
  18550. /**
  18551. * Add a dragger for the given shape in the specific
  18552. * move context.
  18553. *
  18554. * @param {Object} context
  18555. * @param {djs.model.Base} element
  18556. */
  18557. function addDragger(context, element) {
  18558. var dragGroup = context.dragGroup;
  18559. if (!dragGroup) {
  18560. dragGroup = context.dragGroup =
  18561. canvas.getDefaultLayer()
  18562. .group()
  18563. .attr(styles.cls('djs-drag-group', [ 'no-events' ]));
  18564. }
  18565. var gfx = getGfx(element),
  18566. dragger = gfx.clone(),
  18567. bbox = gfx.getBBox();
  18568. dragger.attr(styles.cls('djs-dragger', [], {
  18569. x: bbox.x,
  18570. y: bbox.y
  18571. }));
  18572. dragGroup.add(dragger);
  18573. }
  18574. function makeDraggable(context, element, addMarker) {
  18575. addDragger(context, element);
  18576. if (addMarker) {
  18577. canvas.addMarker(element, MARKER_DRAGGING);
  18578. }
  18579. if (context.allDraggedElements) {
  18580. context.allDraggedElements.push(element);
  18581. } else {
  18582. context.allDraggedElements = [ element ];
  18583. }
  18584. }
  18585. // expose to other components
  18586. // that plug into the drag behavior
  18587. this.makeDraggable = makeDraggable;
  18588. // assign a low priority to this handler
  18589. // to let others modify the move context before
  18590. // we draw things
  18591. //
  18592. eventBus.on('shape.move.start', LOW_PRIORITY, function(event) {
  18593. var context = event.context,
  18594. dragShapes = context.shapes,
  18595. allDraggedElements = context.allDraggedElements;
  18596. var visuallyDraggedShapes = getVisualDragShapes(dragShapes);
  18597. visuallyDraggedShapes.forEach(function(shape) {
  18598. addDragger(context, shape);
  18599. });
  18600. // cache all dragged elements / gfx
  18601. // so that we can quickly undo their state changes later
  18602. if (!allDraggedElements) {
  18603. allDraggedElements = getAllDraggedElements(dragShapes);
  18604. } else {
  18605. allDraggedElements = flatten(allDraggedElements, getAllDraggedElements(dragShapes));
  18606. }
  18607. // add dragging marker
  18608. forEach(allDraggedElements, function(e) {
  18609. canvas.addMarker(e, MARKER_DRAGGING);
  18610. });
  18611. context.allDraggedElements = allDraggedElements;
  18612. });
  18613. // assign a low priority to this handler
  18614. // to let others modify the move context before
  18615. // we draw things
  18616. //
  18617. eventBus.on('shape.move.move', LOW_PRIORITY, function(event) {
  18618. var context = event.context,
  18619. dragGroup = context.dragGroup,
  18620. target = context.target,
  18621. canExecute = context.canExecute;
  18622. if (target) {
  18623. if (canExecute === 'attach') {
  18624. setMarker(target, MARKER_ATTACH);
  18625. } else {
  18626. setMarker(target, context.canExecute ? MARKER_OK : MARKER_NOT_OK);
  18627. }
  18628. }
  18629. dragGroup.translate(event.dx, event.dy);
  18630. });
  18631. eventBus.on([ 'shape.move.out', 'shape.move.cleanup' ], function(event) {
  18632. var context = event.context,
  18633. target = context.target;
  18634. if (target) {
  18635. setMarker(target, null);
  18636. }
  18637. });
  18638. eventBus.on('shape.move.cleanup', function(event) {
  18639. var context = event.context,
  18640. allDraggedElements = context.allDraggedElements,
  18641. dragGroup = context.dragGroup;
  18642. // remove dragging marker
  18643. forEach(allDraggedElements, function(e) {
  18644. canvas.removeMarker(e, MARKER_DRAGGING);
  18645. });
  18646. if (dragGroup) {
  18647. dragGroup.remove();
  18648. }
  18649. });
  18650. }
  18651. // returns elements minus all connections
  18652. // where source or target is not elements
  18653. function removeEdges(elements) {
  18654. var filteredElements = filter(elements, function(element) {
  18655. if (!element.waypoints) { // shapes
  18656. return true;
  18657. } else { // connections
  18658. var srcFound = find(elements, element.source);
  18659. var targetFound = find(elements, element.target);
  18660. return srcFound && targetFound;
  18661. }
  18662. });
  18663. return filteredElements;
  18664. }
  18665. MoveVisuals.$inject = [ 'eventBus', 'elementRegistry', 'canvas', 'styles' ];
  18666. module.exports = MoveVisuals;
  18667. },{"186":186,"208":208,"216":216,"217":217,"218":218,"221":221}],139:[function(_dereq_,module,exports){
  18668. module.exports = {
  18669. __depends__: [
  18670. _dereq_(108),
  18671. _dereq_(159),
  18672. _dereq_(141),
  18673. _dereq_(155),
  18674. _dereq_(106)
  18675. ],
  18676. __init__: [ 'move', 'moveVisuals' ],
  18677. move: [ 'type', _dereq_(137) ],
  18678. moveVisuals: [ 'type', _dereq_(138) ]
  18679. };
  18680. },{"106":106,"108":108,"137":137,"138":138,"141":141,"155":155,"159":159}],140:[function(_dereq_,module,exports){
  18681. 'use strict';
  18682. var getBBox = _dereq_(186).getBBox;
  18683. /**
  18684. * @class
  18685. *
  18686. * A plugin that adds an outline to shapes and connections that may be activated and styled
  18687. * via CSS classes.
  18688. *
  18689. * @param {EventBus} events the event bus
  18690. */
  18691. function Outline(eventBus, styles, elementRegistry) {
  18692. var OUTLINE_OFFSET = 6;
  18693. var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
  18694. function createOutline(gfx, bounds) {
  18695. return gfx.rect(10, 10, 0, 0).attr(OUTLINE_STYLE);
  18696. }
  18697. function updateShapeOutline(outline, bounds) {
  18698. outline.attr({
  18699. x: -OUTLINE_OFFSET,
  18700. y: -OUTLINE_OFFSET,
  18701. width: bounds.width + OUTLINE_OFFSET * 2,
  18702. height: bounds.height + OUTLINE_OFFSET * 2
  18703. });
  18704. }
  18705. function updateConnectionOutline(outline, connection) {
  18706. var bbox = getBBox(connection);
  18707. outline.attr({
  18708. x: bbox.x - OUTLINE_OFFSET,
  18709. y: bbox.y - OUTLINE_OFFSET,
  18710. width: bbox.width + OUTLINE_OFFSET * 2,
  18711. height: bbox.height + OUTLINE_OFFSET * 2
  18712. });
  18713. }
  18714. eventBus.on([ 'shape.added', 'shape.changed' ], function(event) {
  18715. var element = event.element,
  18716. gfx = event.gfx;
  18717. var outline = gfx.select('.djs-outline');
  18718. if (!outline) {
  18719. outline = createOutline(gfx, element);
  18720. }
  18721. updateShapeOutline(outline, element);
  18722. });
  18723. eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
  18724. var element = event.element,
  18725. gfx = event.gfx;
  18726. var outline = gfx.select('.djs-outline');
  18727. if (!outline) {
  18728. outline = createOutline(gfx, element);
  18729. }
  18730. updateConnectionOutline(outline, element);
  18731. });
  18732. }
  18733. Outline.$inject = ['eventBus', 'styles', 'elementRegistry'];
  18734. module.exports = Outline;
  18735. },{"186":186}],141:[function(_dereq_,module,exports){
  18736. 'use strict';
  18737. module.exports = {
  18738. __init__: [ 'outline' ],
  18739. outline: [ 'type', _dereq_(140) ]
  18740. };
  18741. },{"140":140}],142:[function(_dereq_,module,exports){
  18742. 'use strict';
  18743. var isArray = _dereq_(330),
  18744. isString = _dereq_(336),
  18745. isObject = _dereq_(334),
  18746. assign = _dereq_(339),
  18747. forEach = _dereq_(218),
  18748. filter = _dereq_(216),
  18749. debounce = _dereq_(228);
  18750. var domify = _dereq_(356),
  18751. domClasses = _dereq_(352),
  18752. domRemove = _dereq_(360);
  18753. var getBBox = _dereq_(186).getBBox;
  18754. // document wide unique overlay ids
  18755. var ids = new (_dereq_(190))('ov');
  18756. function createRoot(parent) {
  18757. var root = domify('<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />');
  18758. parent.insertBefore(root, parent.firstChild);
  18759. return root;
  18760. }
  18761. function setPosition(el, x, y) {
  18762. assign(el.style, { left: x + 'px', top: y + 'px' });
  18763. }
  18764. function setVisible(el, visible) {
  18765. el.style.display = visible === false ? 'none' : '';
  18766. }
  18767. /**
  18768. * A service that allows users to attach overlays to diagram elements.
  18769. *
  18770. * The overlay service will take care of overlay positioning during updates.
  18771. *
  18772. * @example
  18773. *
  18774. * // add a pink badge on the top left of the shape
  18775. * overlays.add(someShape, {
  18776. * position: {
  18777. * top: -5,
  18778. * left: -5
  18779. * },
  18780. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  18781. * });
  18782. *
  18783. * // or add via shape id
  18784. *
  18785. * overlays.add('some-element-id', {
  18786. * position: {
  18787. * top: -5,
  18788. * left: -5
  18789. * }
  18790. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  18791. * });
  18792. *
  18793. * // or add with optional type
  18794. *
  18795. * overlays.add(someShape, 'badge', {
  18796. * position: {
  18797. * top: -5,
  18798. * left: -5
  18799. * }
  18800. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  18801. * });
  18802. *
  18803. *
  18804. * // remove an overlay
  18805. *
  18806. * var id = overlays.add(...);
  18807. * overlays.remove(id);
  18808. *
  18809. * @param {EventBus} eventBus
  18810. * @param {Canvas} canvas
  18811. * @param {ElementRegistry} elementRegistry
  18812. */
  18813. function Overlays(config, eventBus, canvas, elementRegistry) {
  18814. this._eventBus = eventBus;
  18815. this._canvas = canvas;
  18816. this._elementRegistry = elementRegistry;
  18817. this._ids = ids;
  18818. this._overlayDefaults = {
  18819. show: {
  18820. minZoom: 0.7,
  18821. maxZoom: 5.0
  18822. }
  18823. };
  18824. /**
  18825. * Mapping overlayId -> overlay
  18826. */
  18827. this._overlays = {};
  18828. /**
  18829. * Mapping elementId -> overlay container
  18830. */
  18831. this._overlayContainers = {};
  18832. // root html element for all overlays
  18833. this._overlayRoot = createRoot(canvas.getContainer());
  18834. this._init(config);
  18835. }
  18836. Overlays.$inject = [ 'config.overlays', 'eventBus', 'canvas', 'elementRegistry' ];
  18837. module.exports = Overlays;
  18838. /**
  18839. * Returns the overlay with the specified id or a list of overlays
  18840. * for an element with a given type.
  18841. *
  18842. * @example
  18843. *
  18844. * // return the single overlay with the given id
  18845. * overlays.get('some-id');
  18846. *
  18847. * // return all overlays for the shape
  18848. * overlays.get({ element: someShape });
  18849. *
  18850. * // return all overlays on shape with type 'badge'
  18851. * overlays.get({ element: someShape, type: 'badge' });
  18852. *
  18853. * // shape can also be specified as id
  18854. * overlays.get({ element: 'element-id', type: 'badge' });
  18855. *
  18856. *
  18857. * @param {Object} search
  18858. * @param {String} [search.id]
  18859. * @param {String|djs.model.Base} [search.element]
  18860. * @param {String} [search.type]
  18861. *
  18862. * @return {Object|Array<Object>} the overlay(s)
  18863. */
  18864. Overlays.prototype.get = function(search) {
  18865. if (isString(search)) {
  18866. search = { id: search };
  18867. }
  18868. if (search.element) {
  18869. var container = this._getOverlayContainer(search.element, true);
  18870. // return a list of overlays when searching by element (+type)
  18871. if (container) {
  18872. return search.type ? filter(container.overlays, { type: search.type }) : container.overlays.slice();
  18873. } else {
  18874. return [];
  18875. }
  18876. } else
  18877. if (search.type) {
  18878. return filter(this._overlays, { type: search.type });
  18879. } else {
  18880. // return single element when searching by id
  18881. return search.id ? this._overlays[search.id] : null;
  18882. }
  18883. };
  18884. /**
  18885. * Adds a HTML overlay to an element.
  18886. *
  18887. * @param {String|djs.model.Base} element attach overlay to this shape
  18888. * @param {String} [type] optional type to assign to the overlay
  18889. * @param {Object} overlay the overlay configuration
  18890. *
  18891. * @param {String|DOMElement} overlay.html html element to use as an overlay
  18892. * @param {Object} [overlay.show] show configuration
  18893. * @param {Number} [overlay.show.minZoom] minimal zoom level to show the overlay
  18894. * @param {Number} [overlay.show.maxZoom] maximum zoom level to show the overlay
  18895. * @param {Object} overlay.position where to attach the overlay
  18896. * @param {Number} [overlay.position.left] relative to element bbox left attachment
  18897. * @param {Number} [overlay.position.top] relative to element bbox top attachment
  18898. * @param {Number} [overlay.position.bottom] relative to element bbox bottom attachment
  18899. * @param {Number} [overlay.position.right] relative to element bbox right attachment
  18900. *
  18901. * @return {String} id that may be used to reference the overlay for update or removal
  18902. */
  18903. Overlays.prototype.add = function(element, type, overlay) {
  18904. if (isObject(type)) {
  18905. overlay = type;
  18906. type = null;
  18907. }
  18908. if (!element.id) {
  18909. element = this._elementRegistry.get(element);
  18910. }
  18911. if (!overlay.position) {
  18912. throw new Error('must specifiy overlay position');
  18913. }
  18914. if (!overlay.html) {
  18915. throw new Error('must specifiy overlay html');
  18916. }
  18917. if (!element) {
  18918. throw new Error('invalid element specified');
  18919. }
  18920. var id = this._ids.next();
  18921. overlay = assign({}, this._overlayDefaults, overlay, {
  18922. id: id,
  18923. type: type,
  18924. element: element,
  18925. html: overlay.html
  18926. });
  18927. this._addOverlay(overlay);
  18928. return id;
  18929. };
  18930. /**
  18931. * Remove an overlay with the given id or all overlays matching the given filter.
  18932. *
  18933. * @see Overlays#get for filter options.
  18934. *
  18935. * @param {String} [id]
  18936. * @param {Object} [filter]
  18937. */
  18938. Overlays.prototype.remove = function(filter) {
  18939. var overlays = this.get(filter) || [];
  18940. if (!isArray(overlays)) {
  18941. overlays = [ overlays ];
  18942. }
  18943. var self = this;
  18944. forEach(overlays, function(overlay) {
  18945. var container = self._getOverlayContainer(overlay.element, true);
  18946. if (overlay) {
  18947. domRemove(overlay.html);
  18948. domRemove(overlay.htmlContainer);
  18949. delete overlay.htmlContainer;
  18950. delete overlay.element;
  18951. delete self._overlays[overlay.id];
  18952. }
  18953. if (container) {
  18954. var idx = container.overlays.indexOf(overlay);
  18955. if (idx !== -1) {
  18956. container.overlays.splice(idx, 1);
  18957. }
  18958. }
  18959. });
  18960. };
  18961. Overlays.prototype.show = function() {
  18962. setVisible(this._overlayRoot);
  18963. };
  18964. Overlays.prototype.hide = function() {
  18965. setVisible(this._overlayRoot, false);
  18966. };
  18967. Overlays.prototype._updateOverlayContainer = function(container) {
  18968. var element = container.element,
  18969. html = container.html;
  18970. // update container left,top according to the elements x,y coordinates
  18971. // this ensures we can attach child elements relative to this container
  18972. var x = element.x,
  18973. y = element.y;
  18974. if (element.waypoints) {
  18975. var bbox = getBBox(element);
  18976. x = bbox.x;
  18977. y = bbox.y;
  18978. }
  18979. setPosition(html, x, y);
  18980. };
  18981. Overlays.prototype._updateOverlay = function(overlay) {
  18982. var position = overlay.position,
  18983. htmlContainer = overlay.htmlContainer,
  18984. element = overlay.element;
  18985. // update overlay html relative to shape because
  18986. // it is already positioned on the element
  18987. // update relative
  18988. var left = position.left,
  18989. top = position.top;
  18990. if (position.right !== undefined) {
  18991. var width;
  18992. if (element.waypoints) {
  18993. width = getBBox(element).width;
  18994. } else {
  18995. width = element.width;
  18996. }
  18997. left = position.right * -1 + width;
  18998. }
  18999. if (position.bottom !== undefined) {
  19000. var height;
  19001. if (element.waypoints) {
  19002. height = getBBox(element).height;
  19003. } else {
  19004. height = element.height;
  19005. }
  19006. top = position.bottom * -1 + height;
  19007. }
  19008. setPosition(htmlContainer, left || 0, top || 0);
  19009. };
  19010. Overlays.prototype._createOverlayContainer = function(element) {
  19011. var html = domify('<div class="djs-overlays djs-overlays-' + element.id + '" style="position: absolute" />');
  19012. this._overlayRoot.appendChild(html);
  19013. var container = {
  19014. html: html,
  19015. element: element,
  19016. overlays: []
  19017. };
  19018. this._updateOverlayContainer(container);
  19019. return container;
  19020. };
  19021. Overlays.prototype._updateRoot = function(viewbox) {
  19022. var a = viewbox.scale || 1;
  19023. var d = viewbox.scale || 1;
  19024. var matrix = 'matrix(' + a + ',0,0,' + d + ',' + (-1 * viewbox.x * a) + ',' + (-1 * viewbox.y * d) + ')';
  19025. this._overlayRoot.style.transform = matrix;
  19026. this._overlayRoot.style['-ms-transform'] = matrix;
  19027. };
  19028. Overlays.prototype._getOverlayContainer = function(element, raw) {
  19029. var id = (element && element.id) || element;
  19030. var container = this._overlayContainers[id];
  19031. if (!container && !raw) {
  19032. container = this._overlayContainers[id] = this._createOverlayContainer(element);
  19033. }
  19034. return container;
  19035. };
  19036. Overlays.prototype._addOverlay = function(overlay) {
  19037. var id = overlay.id,
  19038. element = overlay.element,
  19039. html = overlay.html,
  19040. htmlContainer,
  19041. overlayContainer;
  19042. // unwrap jquery (for those who need it)
  19043. if (html.get) {
  19044. html = html.get(0);
  19045. }
  19046. // create proper html elements from
  19047. // overlay HTML strings
  19048. if (isString(html)) {
  19049. html = domify(html);
  19050. }
  19051. overlayContainer = this._getOverlayContainer(element);
  19052. htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '" style="position: absolute">');
  19053. htmlContainer.appendChild(html);
  19054. if (overlay.type) {
  19055. domClasses(htmlContainer).add('djs-overlay-' + overlay.type);
  19056. }
  19057. overlay.htmlContainer = htmlContainer;
  19058. overlayContainer.overlays.push(overlay);
  19059. overlayContainer.html.appendChild(htmlContainer);
  19060. this._overlays[id] = overlay;
  19061. this._updateOverlay(overlay);
  19062. };
  19063. Overlays.prototype._updateOverlayVisibilty = function(viewbox) {
  19064. forEach(this._overlays, function(overlay) {
  19065. var show = overlay.show,
  19066. htmlContainer = overlay.htmlContainer,
  19067. visible = true;
  19068. if (show) {
  19069. if (show.minZoom > viewbox.scale ||
  19070. show.maxZoom < viewbox.scale) {
  19071. visible = false;
  19072. }
  19073. setVisible(htmlContainer, visible);
  19074. }
  19075. });
  19076. };
  19077. Overlays.prototype._init = function(config) {
  19078. var eventBus = this._eventBus;
  19079. var self = this;
  19080. // scroll/zoom integration
  19081. var updateViewbox = function(viewbox) {
  19082. self._updateRoot(viewbox);
  19083. self._updateOverlayVisibilty(viewbox);
  19084. self.show();
  19085. };
  19086. if (!config || config.deferUpdate !== false) {
  19087. updateViewbox = debounce(updateViewbox, 300);
  19088. }
  19089. eventBus.on('canvas.viewbox.changed', function(event) {
  19090. self.hide();
  19091. updateViewbox(event.viewbox);
  19092. });
  19093. // remove integration
  19094. eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
  19095. var overlays = self.get({ element: e.element });
  19096. forEach(overlays, function(o) {
  19097. self.remove(o.id);
  19098. });
  19099. });
  19100. // move integration
  19101. eventBus.on([
  19102. 'element.changed'
  19103. ], function(e) {
  19104. var element = e.element;
  19105. var container = self._getOverlayContainer(element, true);
  19106. if (container) {
  19107. forEach(container.overlays, function(overlay) {
  19108. self._updateOverlay(overlay);
  19109. });
  19110. self._updateOverlayContainer(container);
  19111. }
  19112. });
  19113. // marker integration, simply add them on the overlays as classes, too.
  19114. eventBus.on('element.marker.update', function(e) {
  19115. var container = self._getOverlayContainer(e.element, true);
  19116. if (container) {
  19117. domClasses(container.html)[e.add ? 'add' : 'remove'](e.marker);
  19118. }
  19119. });
  19120. };
  19121. },{"186":186,"190":190,"216":216,"218":218,"228":228,"330":330,"334":334,"336":336,"339":339,"352":352,"356":356,"360":360}],143:[function(_dereq_,module,exports){
  19122. module.exports = {
  19123. __init__: [ 'overlays' ],
  19124. overlays: [ 'type', _dereq_(142) ]
  19125. };
  19126. },{"142":142}],144:[function(_dereq_,module,exports){
  19127. 'use strict';
  19128. var isFunction = _dereq_(331),
  19129. forEach = _dereq_(218);
  19130. var domify = _dereq_(356),
  19131. domQuery = _dereq_(359),
  19132. domAttr = _dereq_(351),
  19133. domClear = _dereq_(353),
  19134. domClasses = _dereq_(352),
  19135. domMatches = _dereq_(358),
  19136. domDelegate = _dereq_(355),
  19137. domEvent = _dereq_(357);
  19138. var toggleSelector = '.djs-palette-toggle',
  19139. entrySelector = '.entry',
  19140. elementSelector = toggleSelector + ', ' + entrySelector;
  19141. /**
  19142. * A palette containing modeling elements.
  19143. */
  19144. function Palette(eventBus, canvas) {
  19145. this._eventBus = eventBus;
  19146. this._canvas = canvas;
  19147. this._providers = [];
  19148. }
  19149. Palette.$inject = [ 'eventBus', 'canvas' ];
  19150. module.exports = Palette;
  19151. /**
  19152. * Register a provider with the palette
  19153. *
  19154. * @param {PaletteProvider} provider
  19155. */
  19156. Palette.prototype.registerProvider = function(provider) {
  19157. this._providers.push(provider);
  19158. if (!this._container) {
  19159. this._init();
  19160. }
  19161. this._update();
  19162. };
  19163. /**
  19164. * Returns the palette entries for a given element
  19165. *
  19166. * @return {Array<PaletteEntryDescriptor>} list of entries
  19167. */
  19168. Palette.prototype.getEntries = function() {
  19169. var entries = {};
  19170. // loop through all providers and their entries.
  19171. // group entries by id so that overriding an entry is possible
  19172. forEach(this._providers, function(provider) {
  19173. var e = provider.getPaletteEntries();
  19174. forEach(e, function(entry, id) {
  19175. entries[id] = entry;
  19176. });
  19177. });
  19178. return entries;
  19179. };
  19180. /**
  19181. * Initialize
  19182. */
  19183. Palette.prototype._init = function() {
  19184. var parent = this._canvas.getContainer(),
  19185. container = this._container = domify(Palette.HTML_MARKUP),
  19186. self = this;
  19187. parent.appendChild(container);
  19188. domDelegate.bind(container, elementSelector, 'click', function(event) {
  19189. var target = event.delegateTarget;
  19190. if (domMatches(target, toggleSelector)) {
  19191. return self.toggle();
  19192. }
  19193. self.trigger('click', event);
  19194. });
  19195. // prevent drag propagation
  19196. domEvent.bind(container, 'mousedown', function(event) {
  19197. event.stopPropagation();
  19198. });
  19199. // prevent drag propagation
  19200. domDelegate.bind(container, entrySelector, 'dragstart', function(event) {
  19201. self.trigger('dragstart', event);
  19202. });
  19203. this._eventBus.fire('palette.create', {
  19204. html: container
  19205. });
  19206. };
  19207. Palette.prototype._update = function() {
  19208. var entriesContainer = domQuery('.djs-palette-entries', this._container),
  19209. entries = this._entries = this.getEntries();
  19210. domClear(entriesContainer);
  19211. forEach(entries, function(entry, id) {
  19212. var grouping = entry.group || 'default';
  19213. var container = domQuery('[data-group=' + grouping + ']', entriesContainer);
  19214. if (!container) {
  19215. container = domify('<div class="group" data-group="' + grouping + '"></div>');
  19216. entriesContainer.appendChild(container);
  19217. }
  19218. var html = entry.html || (
  19219. entry.separator ?
  19220. '<hr class="separator" />' :
  19221. '<div class="entry" draggable="true"></div>');
  19222. var control = domify(html);
  19223. container.appendChild(control);
  19224. if (!entry.separator) {
  19225. domAttr(control, 'data-action', id);
  19226. if (entry.title) {
  19227. domAttr(control, 'title', entry.title);
  19228. }
  19229. if (entry.className) {
  19230. domClasses(control).add(entry.className);
  19231. }
  19232. if (entry.imageUrl) {
  19233. control.appendChild(domify('<img src="' + entry.imageUrl + '">'));
  19234. }
  19235. }
  19236. });
  19237. // open after update
  19238. this.open(true);
  19239. };
  19240. /**
  19241. * Trigger an action available on the palette
  19242. *
  19243. * @param {String} action
  19244. * @param {Event} event
  19245. */
  19246. Palette.prototype.trigger = function(action, event, autoActivate) {
  19247. var entries = this._entries,
  19248. entry,
  19249. handler,
  19250. originalEvent,
  19251. button = event.delegateTarget || event.target;
  19252. if (!button) {
  19253. return event.preventDefault();
  19254. }
  19255. entry = entries[domAttr(button, 'data-action')];
  19256. handler = entry.action;
  19257. originalEvent = event.originalEvent || event;
  19258. // simple action (via callback function)
  19259. if (isFunction(handler)) {
  19260. if (action === 'click') {
  19261. return handler(originalEvent, autoActivate);
  19262. }
  19263. } else {
  19264. if (handler[action]) {
  19265. return handler[action](originalEvent, autoActivate);
  19266. }
  19267. }
  19268. // silence other actions
  19269. event.preventDefault();
  19270. };
  19271. /**
  19272. * Close the palette
  19273. */
  19274. Palette.prototype.close = function() {
  19275. domClasses(this._container).remove('open');
  19276. };
  19277. /**
  19278. * Open the palette
  19279. */
  19280. Palette.prototype.open = function() {
  19281. domClasses(this._container).add('open');
  19282. };
  19283. Palette.prototype.toggle = function(open) {
  19284. if (this.isOpen()) {
  19285. this.close();
  19286. } else {
  19287. this.open();
  19288. }
  19289. };
  19290. /**
  19291. * Return true if the palette is opened.
  19292. *
  19293. * @example
  19294. *
  19295. * palette.open();
  19296. *
  19297. * if (palette.isOpen()) {
  19298. * // yes, we are open
  19299. * }
  19300. *
  19301. * @return {boolean} true if palette is opened
  19302. */
  19303. Palette.prototype.isOpen = function() {
  19304. return this._container && domClasses(this._container).has('open');
  19305. };
  19306. /* markup definition */
  19307. Palette.HTML_MARKUP =
  19308. '<div class="djs-palette">' +
  19309. '<div class="djs-palette-entries"></div>' +
  19310. '<div class="djs-palette-toggle"></div>' +
  19311. '</div>';
  19312. },{"218":218,"331":331,"351":351,"352":352,"353":353,"355":355,"356":356,"357":357,"358":358,"359":359}],145:[function(_dereq_,module,exports){
  19313. module.exports = {
  19314. __init__: [ 'palette' ],
  19315. palette: [ 'type', _dereq_(144) ]
  19316. };
  19317. },{"144":144}],146:[function(_dereq_,module,exports){
  19318. 'use strict';
  19319. var forEach = _dereq_(218),
  19320. assign = _dereq_(339),
  19321. find = _dereq_(217);
  19322. var domDelegate = _dereq_(355),
  19323. domify = _dereq_(356),
  19324. domClasses = _dereq_(352),
  19325. domAttr = _dereq_(351),
  19326. domRemove = _dereq_(360);
  19327. var DATA_REF = 'data-id';
  19328. /**
  19329. * A popup menu that can be used to display a list of actions anywhere in the canvas.
  19330. *
  19331. * {@link PopupMenu#open} is used to create and open the popup menu.
  19332. * With {@link PopupMenu#update} it is possible to update certain entries in the popup menu
  19333. * (see examples below).
  19334. *
  19335. * @example
  19336. *
  19337. * // create a basic popup menu
  19338. * popupMenu.open(
  19339. * {
  19340. * position: { x: 100, y: 100 },
  19341. * entries: [
  19342. * {
  19343. * id: 'entry-1',
  19344. * label: 'Entry 1',
  19345. * action: function(event, entry) {
  19346. * // do some stuff
  19347. * }
  19348. * },
  19349. * {
  19350. * id: 'entry-2',
  19351. * label: 'Entry 2'
  19352. * }
  19353. * ]
  19354. * }
  19355. * );
  19356. *
  19357. *
  19358. * @param {EventBus} eventBus
  19359. * @param {Canvas} canvas
  19360. *
  19361. * @class
  19362. * @constructor
  19363. */
  19364. function PopupMenu(eventBus, canvas, modeling) {
  19365. this._eventBus = eventBus;
  19366. this._canvas = canvas;
  19367. this._modeling = modeling;
  19368. }
  19369. PopupMenu.$inject = [ 'eventBus', 'canvas', 'modeling' ];
  19370. /**
  19371. * Creates the popup menu, adds entries and attaches it to the DOM.
  19372. *
  19373. * @param {Object} menu
  19374. * @param {Object} menu.position
  19375. * @param {String} [menu.className] a custom HTML class name for the popup menu
  19376. *
  19377. * @param {Array.<Object>} menu.entries
  19378. * @param {String} menu.entries[].id
  19379. * @param {String} menu.entries[].label
  19380. * @param {String} [menu.entries[].className] a custom HTML class name for the entry div element
  19381. * @param {Object} [menu.entries[].action] a handler function that will be called on a click on the entry
  19382. *
  19383. * @param {Array.<Object>} [menu.headerEntries]
  19384. * @param {String} menu.headerEntries[].id
  19385. * @param {String} [menu.headerEntries[].label]
  19386. * @param {String} [menu.headerEntries[].imageUrl]
  19387. * @param {String} [menu.headerEntries[].className] a custom HTML class name for the entry div element
  19388. * @param {Object} [menu.headerEntries[].action] a handler function that will be called on a click on the entry
  19389. *
  19390. * @return {PopupMenu}
  19391. */
  19392. PopupMenu.prototype.open = function(menu) {
  19393. var className = menu.className || 'popup-menu',
  19394. position = menu.position,
  19395. entries = menu.entries,
  19396. headerEntries = menu.headerEntries;
  19397. if (!position) {
  19398. throw new Error('the position argument is missing');
  19399. }
  19400. if (!entries) {
  19401. throw new Error('the entries argument is missing');
  19402. }
  19403. // make sure, only one popup menu is open at a time
  19404. if (this.isOpen()) {
  19405. this.close();
  19406. }
  19407. var canvas = this._canvas,
  19408. parent = canvas.getContainer(),
  19409. container = this._createContainer(className, position);
  19410. if (headerEntries) {
  19411. var headerEntriesContainer = this._createEntries(headerEntries, 'djs-popup-header');
  19412. container.appendChild(headerEntriesContainer);
  19413. }
  19414. var entriesContainer = this._createEntries(entries, 'djs-popup-body');
  19415. container.appendChild(entriesContainer);
  19416. this._attachContainer(container, parent);
  19417. this._current = {
  19418. container: container,
  19419. menu: menu
  19420. };
  19421. return this;
  19422. };
  19423. /**
  19424. * Removes the popup menu and unbinds the event handlers.
  19425. */
  19426. PopupMenu.prototype.close = function() {
  19427. if (!this.isOpen()) {
  19428. return;
  19429. }
  19430. this._unbindHandlers();
  19431. domRemove(this._current.container);
  19432. this._current = null;
  19433. };
  19434. /**
  19435. * Determines, if an open popup menu exist.
  19436. * @return {Boolean}
  19437. */
  19438. PopupMenu.prototype.isOpen = function() {
  19439. return !!this._current;
  19440. };
  19441. /**
  19442. * Trigger an action associated with an entry.
  19443. *
  19444. * @param {Object} event
  19445. */
  19446. PopupMenu.prototype.trigger = function(event) {
  19447. // silence other actions
  19448. event.preventDefault();
  19449. var element = event.delegateTarget || event.target,
  19450. entryId = domAttr(element, DATA_REF);
  19451. var entry = this._getEntry(entryId);
  19452. if (entry.action) {
  19453. var result = entry.action.call(null, event, entry);
  19454. this.close();
  19455. return result;
  19456. }
  19457. };
  19458. /**
  19459. * Gets an entry instance (either entry or headerEntry) by id.
  19460. *
  19461. * @param {String} entryId
  19462. *
  19463. * @return {Object} entry instance
  19464. */
  19465. PopupMenu.prototype._getEntry = function(entryId) {
  19466. var menu = this._current.menu,
  19467. search = { id: entryId };
  19468. var entry = find(menu.entries, search) || find(menu.headerEntries, search);
  19469. if (!entry) {
  19470. throw new Error('entry not found');
  19471. }
  19472. return entry;
  19473. };
  19474. /**
  19475. * Creates the popup menu container.
  19476. *
  19477. * @param {String} event
  19478. * @param {Object} position
  19479. */
  19480. PopupMenu.prototype._createContainer = function(className, position) {
  19481. var container = domify('<div class="djs-popup">');
  19482. assign(container.style, {
  19483. position: 'absolute',
  19484. left: position.x + 'px',
  19485. top: position.y + 'px'
  19486. });
  19487. domClasses(container).add(className);
  19488. return container;
  19489. };
  19490. /**
  19491. * Attaches the container to the DOM and binds the event handlers.
  19492. *
  19493. * @param {Object} container
  19494. * @param {Object} parent
  19495. */
  19496. PopupMenu.prototype._attachContainer = function(container, parent) {
  19497. var self = this;
  19498. // Event handler
  19499. domDelegate.bind(container, '.entry' ,'click', function(event) {
  19500. self.trigger(event);
  19501. });
  19502. // apply canvas zoom level
  19503. var zoom = this._canvas.zoom();
  19504. container.style.transformOrigin = 'top left';
  19505. container.style.transform = 'scale(' + zoom + ')';
  19506. // Attach to DOM
  19507. parent.appendChild(container);
  19508. // Add Handler
  19509. this._bindHandlers();
  19510. };
  19511. /**
  19512. * Creates and attaches entries to the popup menu.
  19513. *
  19514. * @param {Array<Object>} entries an array of entry objects
  19515. * @param {Object} container the parent DOM container
  19516. * @param {String} className the class name of the entry container
  19517. */
  19518. PopupMenu.prototype._createEntries = function(entries, className) {
  19519. var entriesContainer = domify('<div>'),
  19520. self = this;
  19521. domClasses(entriesContainer).add(className);
  19522. forEach(entries, function(entry) {
  19523. var entryContainer = self._createEntry(entry, entriesContainer);
  19524. entriesContainer.appendChild(entryContainer);
  19525. });
  19526. return entriesContainer;
  19527. };
  19528. /**
  19529. * Creates a single entry and attaches it to the specified DOM container.
  19530. *
  19531. * @param {Object} entry
  19532. * @param {Object} container
  19533. */
  19534. PopupMenu.prototype._createEntry = function(entry) {
  19535. if (!entry.id) {
  19536. throw new Error ('every entry must have the id property set');
  19537. }
  19538. var entryContainer = domify('<div>'),
  19539. entryClasses = domClasses(entryContainer);
  19540. entryClasses.add('entry');
  19541. if (entry.className) {
  19542. entryClasses.add(entry.className);
  19543. }
  19544. domAttr(entryContainer, DATA_REF, entry.id);
  19545. if (entry.label) {
  19546. var label = domify('<span>');
  19547. label.textContent = entry.label;
  19548. entryContainer.appendChild(label);
  19549. }
  19550. if (entry.imageUrl) {
  19551. entryContainer.appendChild(domify('<img src="' + entry.imageUrl + '" />'));
  19552. }
  19553. if (entry.active === true) {
  19554. entryClasses.add('active');
  19555. }
  19556. if (entry.disabled === true) {
  19557. entryClasses.add('disabled');
  19558. }
  19559. return entryContainer;
  19560. };
  19561. /**
  19562. * Binds the `close` method to 'contextPad.close' & 'canvas.viewbox.changed'.
  19563. */
  19564. PopupMenu.prototype._bindHandlers = function() {
  19565. var eventBus = this._eventBus,
  19566. self = this;
  19567. function close() {
  19568. self.close();
  19569. }
  19570. eventBus.once('contextPad.close', close);
  19571. eventBus.once('canvas.viewbox.changed', close);
  19572. eventBus.once('commandStack.changed', close);
  19573. };
  19574. /**
  19575. * Unbinds the `close` method to 'contextPad.close' & 'canvas.viewbox.changed'.
  19576. */
  19577. PopupMenu.prototype._unbindHandlers = function() {
  19578. var eventBus = this._eventBus,
  19579. self = this;
  19580. function close() {
  19581. self.close();
  19582. }
  19583. eventBus.off('contextPad.close', close);
  19584. eventBus.off('canvas.viewbox.changed', close);
  19585. eventBus.off('commandStack.changed', close);
  19586. };
  19587. module.exports = PopupMenu;
  19588. },{"217":217,"218":218,"339":339,"351":351,"352":352,"355":355,"356":356,"360":360}],147:[function(_dereq_,module,exports){
  19589. 'use strict';
  19590. module.exports = {
  19591. __init__: [ 'popupMenu' ],
  19592. popupMenu: [ 'type', _dereq_(146) ]
  19593. };
  19594. },{"146":146}],148:[function(_dereq_,module,exports){
  19595. 'use strict';
  19596. /**
  19597. * Service that allow replacing of elements.
  19598. *
  19599. *
  19600. * @class
  19601. * @constructor
  19602. */
  19603. function Replace(modeling) {
  19604. this._modeling = modeling;
  19605. }
  19606. module.exports = Replace;
  19607. Replace.$inject = [ 'modeling' ];
  19608. /**
  19609. * @param {Element} oldElement - Element to be replaced
  19610. * @param {Object} newElementData - Containing information about the new Element, for example height, width, type.
  19611. * @param {Object} options - Custom options that will be attached to the context. It can be used to inject data
  19612. * that is needed in the command chain. For example it could be used in
  19613. * eventbus.on('commandStack.shape.replace.postExecute') to change shape attributes after
  19614. * shape creation.
  19615. */
  19616. Replace.prototype.replaceElement = function(oldElement, newElementData, options) {
  19617. var modeling = this._modeling;
  19618. var newElement = null;
  19619. if (oldElement.waypoints) {
  19620. // TODO
  19621. // modeling.replaceConnection
  19622. } else {
  19623. // set center of element for modeling API
  19624. // if no new width / height is given use old elements size
  19625. newElementData.x = oldElement.x + (newElementData.width || oldElement.width) / 2;
  19626. newElementData.y = oldElement.y + (newElementData.height || oldElement.height) / 2;
  19627. newElement = modeling.replaceShape(oldElement, newElementData, options);
  19628. }
  19629. return newElement;
  19630. };
  19631. },{}],149:[function(_dereq_,module,exports){
  19632. 'use strict';
  19633. module.exports = {
  19634. __init__: [ 'replace' ],
  19635. replace: [ 'type', _dereq_(148) ]
  19636. };
  19637. },{"148":148}],150:[function(_dereq_,module,exports){
  19638. 'use strict';
  19639. var forEach = _dereq_(218),
  19640. filter = _dereq_(216),
  19641. pick = _dereq_(345),
  19642. assign = _dereq_(339);
  19643. var ResizeUtil = _dereq_(151),
  19644. domEvent = _dereq_(357),
  19645. Elements = _dereq_(186);
  19646. var isPrimaryButton = _dereq_(193).isPrimaryButton;
  19647. var round = Math.round;
  19648. var Snap = _dereq_(200);
  19649. var HANDLE_OFFSET = -2,
  19650. HANDLE_SIZE = 5,
  19651. HANDLE_HIT_SIZE = 20;
  19652. var MARKER_RESIZING = 'djs-resizing',
  19653. MARKER_RESIZE_NOT_OK = 'resize-not-ok',
  19654. CLS_RESIZER = 'djs-resizer';
  19655. var DEFAULT_MIN_WIDTH = 10;
  19656. var DEFAULT_CHILD_BOX_PADDING = 20;
  19657. /**
  19658. * A component that provides resizing of shapes on the canvas.
  19659. *
  19660. * The following components are part of shape resize:
  19661. *
  19662. * * adding resize handles,
  19663. * * creating a visual during resize
  19664. * * checking resize rules
  19665. * * committing a change once finished
  19666. *
  19667. *
  19668. * ## Customizing
  19669. *
  19670. * It's possible to customize the resizing behaviour by intercepting 'resize.start'
  19671. * and providing the following parameters through the 'context':
  19672. *
  19673. * * minDimensions ({ width, height }): minimum shape dimensions
  19674. *
  19675. * * childrenBoxPadding ({ left, top, bottom, right } || number):
  19676. * gap between the minimum bounding box and the container
  19677. *
  19678. * f.ex:
  19679. *
  19680. * ```javascript
  19681. * eventBus.on('resize.start', 1500, function(event) {
  19682. * var context = event.context,
  19683. *
  19684. * context.minDimensions = { width: 140, height: 120 };
  19685. *
  19686. * // Passing general padding
  19687. * context.childrenBoxPadding = 30;
  19688. *
  19689. * // Passing padding to a specific side
  19690. * context.childrenBoxPadding.left = 20;
  19691. * });
  19692. * ```
  19693. */
  19694. function Resize(eventBus, elementRegistry, rules, modeling, canvas, selection, dragging) {
  19695. function canResize(context) {
  19696. var ctx = pick(context, [ 'newBounds', 'shape', 'delta', 'direction' ]);
  19697. return rules.allowed('shape.resize', ctx);
  19698. }
  19699. // resizing implementation //////////////////////////////////
  19700. /**
  19701. * A helper that realizes the resize visuals
  19702. */
  19703. var visuals = {
  19704. create: function(context) {
  19705. var container = canvas.getDefaultLayer(),
  19706. shape = context.shape,
  19707. frame;
  19708. frame = context.frame = Snap.create('rect', {
  19709. class: 'djs-resize-overlay',
  19710. width: shape.width + 10,
  19711. height: shape.height + 10,
  19712. x: shape.x -5,
  19713. y: shape.y -5
  19714. });
  19715. frame.appendTo(container);
  19716. },
  19717. update: function(context) {
  19718. var frame = context.frame,
  19719. bounds = context.newBounds;
  19720. if (bounds.width > 5) {
  19721. frame.attr({
  19722. x: bounds.x,
  19723. width: bounds.width
  19724. });
  19725. }
  19726. if (bounds.height > 5) {
  19727. frame.attr({
  19728. y: bounds.y,
  19729. height: bounds.height
  19730. });
  19731. }
  19732. frame[context.canExecute ? 'removeClass' : 'addClass'](MARKER_RESIZE_NOT_OK);
  19733. },
  19734. remove: function(context) {
  19735. if (context.frame) {
  19736. context.frame.remove();
  19737. }
  19738. }
  19739. };
  19740. /**
  19741. * is the given element part of the
  19742. * resize targets min boundary box
  19743. *
  19744. * @param {djs.model.Base} element
  19745. */
  19746. function isBBoxChild(element) {
  19747. // exclude connections
  19748. if (element.waypoints) {
  19749. return false;
  19750. }
  19751. // labels
  19752. if (element.type === 'label') {
  19753. return false;
  19754. }
  19755. return true;
  19756. }
  19757. function addPadding(bbox, padding) {
  19758. var left, right, top, bottom;
  19759. if (typeof padding === 'object') {
  19760. left = padding.left || DEFAULT_CHILD_BOX_PADDING;
  19761. right = padding.right || DEFAULT_CHILD_BOX_PADDING;
  19762. top = padding.top || DEFAULT_CHILD_BOX_PADDING;
  19763. bottom = padding.bottom || DEFAULT_CHILD_BOX_PADDING;
  19764. } else {
  19765. left = right = top = bottom = padding || DEFAULT_CHILD_BOX_PADDING;
  19766. }
  19767. return {
  19768. x: bbox.x - left,
  19769. y: bbox.y - top,
  19770. width: bbox.width + left + right,
  19771. height: bbox.height + top + bottom
  19772. };
  19773. }
  19774. function computeChildrenBBox(shape, padding) {
  19775. // grab all the children that are part of the
  19776. // parents children box
  19777. var children = filter(shape.children, isBBoxChild);
  19778. if (children.length) {
  19779. return addPadding(Elements.getBBox(children), padding);
  19780. }
  19781. }
  19782. function computeMinResizeBox(context) {
  19783. var shape = context.shape,
  19784. direction = context.direction,
  19785. childrenBounds;
  19786. // get children bounds
  19787. childrenBounds = computeChildrenBBox(shape, context.childrenBoxPadding);
  19788. // get correct minimum bounds from given resize direction
  19789. // basically ensures that the minBounds is max(childrenBounds, minDimensions)
  19790. return ResizeUtil.getMinResizeBounds(direction, shape, context.minDimensions || {
  19791. width: DEFAULT_MIN_WIDTH,
  19792. height: DEFAULT_MIN_WIDTH
  19793. }, childrenBounds);
  19794. }
  19795. eventBus.on('resize.start', function(event) {
  19796. var context = event.context,
  19797. shape = context.shape,
  19798. minBounds = context.minBounds;
  19799. if (minBounds === undefined) {
  19800. context.minBounds = computeMinResizeBox(context);
  19801. }
  19802. // add resizable indicator
  19803. canvas.addMarker(shape, MARKER_RESIZING);
  19804. visuals.create(context);
  19805. });
  19806. eventBus.on('resize.move', function(event) {
  19807. var context = event.context,
  19808. shape = context.shape,
  19809. direction = context.direction,
  19810. minBounds = context.minBounds,
  19811. delta;
  19812. delta = {
  19813. x: event.dx,
  19814. y: event.dy
  19815. };
  19816. context.delta = delta;
  19817. context.newBounds = ResizeUtil.resizeBounds(shape, direction, delta);
  19818. if (minBounds) {
  19819. context.newBounds = ResizeUtil.ensureMinBounds(context.newBounds, minBounds);
  19820. }
  19821. // update + cache executable state
  19822. context.canExecute = canResize(context);
  19823. // update resize frame visuals
  19824. visuals.update(context);
  19825. });
  19826. eventBus.on('resize.end', function(event) {
  19827. var context = event.context,
  19828. shape = context.shape;
  19829. var newBounds = context.newBounds;
  19830. // ensure we have actual pixel values for new bounds
  19831. // (important when zoom level was > 1 during move)
  19832. newBounds.x = round(newBounds.x);
  19833. newBounds.y = round(newBounds.y);
  19834. newBounds.width = round(newBounds.width);
  19835. newBounds.height = round(newBounds.height);
  19836. // perform the actual resize
  19837. if (context.canExecute) {
  19838. modeling.resizeShape(shape, context.newBounds);
  19839. }
  19840. });
  19841. eventBus.on('resize.cleanup', function(event) {
  19842. var context = event.context,
  19843. shape = context.shape;
  19844. // remove resizable indicator
  19845. canvas.removeMarker(shape, MARKER_RESIZING);
  19846. // remove frame + destroy context
  19847. visuals.remove(context);
  19848. });
  19849. /**
  19850. * Activate a resize operation
  19851. *
  19852. * You may specify additional contextual information and must specify a
  19853. * resize direction during activation of the resize event.
  19854. *
  19855. * @param {MouseEvent} event
  19856. * @param {djs.model.Shape} shape
  19857. * @param {Object|String} contextOrDirection
  19858. */
  19859. function activate(event, shape, contextOrDirection) {
  19860. var context,
  19861. direction;
  19862. if (typeof contextOrDirection === 'string') {
  19863. contextOrDirection = {
  19864. direction: contextOrDirection
  19865. };
  19866. }
  19867. context = assign({ shape: shape }, contextOrDirection);
  19868. direction = context.direction;
  19869. if (!direction) {
  19870. throw new Error('must provide a direction (nw|se|ne|sw)');
  19871. }
  19872. dragging.activate(event, 'resize', {
  19873. autoActivate: true,
  19874. cursor: 'resize-' + (/nw|se/.test(direction) ? 'nwse' : 'nesw'),
  19875. data: {
  19876. shape: shape,
  19877. context: context
  19878. }
  19879. });
  19880. }
  19881. function makeDraggable(element, gfx, direction) {
  19882. function listener(event) {
  19883. // only trigger on left mouse button
  19884. if (isPrimaryButton(event)) {
  19885. activate(event, element, direction);
  19886. }
  19887. }
  19888. domEvent.bind(gfx.node, 'mousedown', listener);
  19889. domEvent.bind(gfx.node, 'touchstart', listener);
  19890. }
  19891. function __createResizer(gfx, x, y, rotation, direction) {
  19892. var group = gfx.group().addClass(CLS_RESIZER).addClass(CLS_RESIZER + '-' + direction);
  19893. var origin = -HANDLE_SIZE + HANDLE_OFFSET;
  19894. // Create four drag indicators on the outline
  19895. group.rect(origin, origin, HANDLE_SIZE, HANDLE_SIZE).addClass(CLS_RESIZER + '-visual');
  19896. group.rect(origin, origin, HANDLE_HIT_SIZE, HANDLE_HIT_SIZE).addClass(CLS_RESIZER + '-hit');
  19897. var matrix = new Snap.Matrix().translate(x, y).rotate(rotation, 0, 0);
  19898. group.transform(matrix);
  19899. return group;
  19900. }
  19901. function createResizer(element, gfx, direction) {
  19902. var resizer;
  19903. if (direction === 'nw') {
  19904. resizer = __createResizer(gfx, 0, 0, 0, direction);
  19905. } else if (direction === 'ne') {
  19906. resizer = __createResizer(gfx, element.width, 0, 90, direction);
  19907. } else if (direction === 'se') {
  19908. resizer = __createResizer(gfx, element.width, element.height, 180, direction);
  19909. } else {
  19910. resizer = __createResizer(gfx, 0, element.height, 270, direction);
  19911. }
  19912. makeDraggable(element, resizer, direction);
  19913. }
  19914. // resize handles implementation ///////////////////////////////
  19915. function addResize(shape) {
  19916. if (!canResize({ shape: shape })) {
  19917. return;
  19918. }
  19919. var gfx = elementRegistry.getGraphics(shape);
  19920. createResizer(shape, gfx, 'nw');
  19921. createResizer(shape, gfx, 'ne');
  19922. createResizer(shape, gfx, 'se');
  19923. createResizer(shape, gfx, 'sw');
  19924. }
  19925. function removeResize(shape) {
  19926. var gfx = elementRegistry.getGraphics(shape);
  19927. var resizers = gfx.selectAll('.' + CLS_RESIZER);
  19928. forEach(resizers, function(resizer){
  19929. resizer.remove();
  19930. });
  19931. }
  19932. eventBus.on('selection.changed', function(e) {
  19933. var oldSelection = e.oldSelection,
  19934. newSelection = e.newSelection;
  19935. // remove old selection markers
  19936. forEach(oldSelection, removeResize);
  19937. // add new selection markers ONLY if single selection
  19938. if (newSelection.length === 1) {
  19939. forEach(newSelection, addResize);
  19940. }
  19941. });
  19942. eventBus.on('shape.changed', function(e) {
  19943. var shape = e.element;
  19944. removeResize(shape);
  19945. if (selection.isSelected(shape)) {
  19946. addResize(shape);
  19947. }
  19948. });
  19949. // API
  19950. this.activate = activate;
  19951. }
  19952. Resize.$inject = [ 'eventBus', 'elementRegistry', 'rules', 'modeling', 'canvas', 'selection', 'dragging' ];
  19953. module.exports = Resize;
  19954. },{"151":151,"186":186,"193":193,"200":200,"216":216,"218":218,"339":339,"345":345,"357":357}],151:[function(_dereq_,module,exports){
  19955. 'use strict';
  19956. var max = Math.max,
  19957. min = Math.min;
  19958. /**
  19959. * Resize the given bounds by the specified delta from a given anchor point.
  19960. *
  19961. * @param {Bounds} bounds the bounding box that should be resized
  19962. * @param {String} direction in which the element is resized (nw, ne, se, sw)
  19963. * @param {Point} delta of the resize operation
  19964. *
  19965. * @return {Bounds} resized bounding box
  19966. */
  19967. module.exports.resizeBounds = function(bounds, direction, delta) {
  19968. var dx = delta.x,
  19969. dy = delta.y;
  19970. switch (direction) {
  19971. case 'nw':
  19972. return {
  19973. x: bounds.x + dx,
  19974. y: bounds.y + dy,
  19975. width: bounds.width - dx,
  19976. height: bounds.height - dy
  19977. };
  19978. case 'sw':
  19979. return {
  19980. x: bounds.x + dx,
  19981. y: bounds.y,
  19982. width: bounds.width - dx,
  19983. height: bounds.height + dy
  19984. };
  19985. case 'ne':
  19986. return {
  19987. x: bounds.x,
  19988. y: bounds.y + dy,
  19989. width: bounds.width + dx,
  19990. height: bounds.height - dy
  19991. };
  19992. case 'se':
  19993. return {
  19994. x: bounds.x,
  19995. y: bounds.y,
  19996. width: bounds.width + dx,
  19997. height: bounds.height + dy
  19998. };
  19999. default:
  20000. throw new Error('unrecognized direction: ' + direction);
  20001. }
  20002. };
  20003. module.exports.reattachPoint = function(bounds, newBounds, point) {
  20004. var sx = bounds.width / newBounds.width,
  20005. sy = bounds.height / newBounds.height;
  20006. return {
  20007. x: Math.round((newBounds.x + newBounds.width / 2)) - Math.floor(((bounds.x + bounds.width / 2) - point.x) / sx),
  20008. y: Math.round((newBounds.y + newBounds.height / 2)) - Math.floor(((bounds.y + bounds.height / 2) - point.y) / sy)
  20009. };
  20010. };
  20011. module.exports.ensureMinBounds = function(currentBounds, minBounds) {
  20012. var topLeft = {
  20013. x: Math.min(currentBounds.x, minBounds.x),
  20014. y: Math.min(currentBounds.y, minBounds.y)
  20015. };
  20016. var bottomRight = {
  20017. x: Math.max(currentBounds.x + currentBounds.width, minBounds.x + minBounds.width),
  20018. y: Math.max(currentBounds.y + currentBounds.height, minBounds.y + minBounds.height)
  20019. };
  20020. return {
  20021. x: topLeft.x,
  20022. y: topLeft.y,
  20023. width: bottomRight.x - topLeft.x,
  20024. height: bottomRight.y - topLeft.y
  20025. };
  20026. };
  20027. function toTLBR(bounds) {
  20028. return {
  20029. top: bounds.y,
  20030. left: bounds.x,
  20031. bottom: bounds.y + bounds.height,
  20032. right: bounds.x + bounds.width
  20033. };
  20034. }
  20035. module.exports.getMinResizeBounds = function(direction, currentBounds, minDimensions, childrenBounds) {
  20036. var currentBox = toTLBR(currentBounds);
  20037. var minBox = {
  20038. top: /n/.test(direction) ? currentBox.bottom - minDimensions.height : currentBox.top,
  20039. left: /w/.test(direction) ? currentBox.right - minDimensions.width : currentBox.left,
  20040. bottom: /s/.test(direction) ? currentBox.top + minDimensions.height : currentBox.bottom,
  20041. right: /e/.test(direction) ? currentBox.left + minDimensions.width : currentBox.right
  20042. };
  20043. var childrenBox = childrenBounds ? toTLBR(childrenBounds) : minBox;
  20044. var combinedBox = {
  20045. top: min(minBox.top, childrenBox.top),
  20046. left: min(minBox.left, childrenBox.left),
  20047. bottom: max(minBox.bottom, childrenBox.bottom),
  20048. right: max(minBox.right, childrenBox.right),
  20049. };
  20050. return {
  20051. x: combinedBox.left,
  20052. y: combinedBox.top,
  20053. width: combinedBox.right - combinedBox.left,
  20054. height: combinedBox.bottom - combinedBox.top
  20055. };
  20056. };
  20057. },{}],152:[function(_dereq_,module,exports){
  20058. module.exports = {
  20059. __depends__: [
  20060. _dereq_(136),
  20061. _dereq_(155),
  20062. _dereq_(106)
  20063. ],
  20064. __init__: [ 'resize' ],
  20065. resize: [ 'type', _dereq_(150) ]
  20066. };
  20067. },{"106":106,"136":136,"150":150,"155":155}],153:[function(_dereq_,module,exports){
  20068. 'use strict';
  20069. var inherits = _dereq_(207);
  20070. var CommandInterceptor = _dereq_(78);
  20071. /**
  20072. * A basic provider that may be extended to implement modeling rules.
  20073. *
  20074. * Extensions should implement the init method to actually add their custom
  20075. * modeling checks. Checks may be added via the #addRule(action, fn) method.
  20076. *
  20077. * @param {EventBus} eventBus
  20078. */
  20079. function RuleProvider(eventBus) {
  20080. CommandInterceptor.call(this, eventBus);
  20081. this.init();
  20082. }
  20083. RuleProvider.$inject = [ 'eventBus' ];
  20084. inherits(RuleProvider, CommandInterceptor);
  20085. module.exports = RuleProvider;
  20086. /**
  20087. * Adds a modeling rule for the given action, implemented through a callback function.
  20088. *
  20089. * The function will receive the modeling specific action context to perform its check.
  20090. * It must return false or null to disallow the action from happening.
  20091. *
  20092. * Returning <code>null</code> may encode simply ignoring the action.
  20093. *
  20094. * @example
  20095. *
  20096. * ResizableRules.prototype.init = function() {
  20097. *
  20098. * this.addRule('shape.resize', function(context) {
  20099. *
  20100. * var shape = context.shape;
  20101. *
  20102. * if (!context.newBounds) {
  20103. * // check general resizability
  20104. * if (!shape.resizable) {
  20105. * return false;
  20106. * }
  20107. * } else {
  20108. * // element must have minimum size of 10*10 points
  20109. * return context.newBounds.width > 10 && context.newBounds.height > 10;
  20110. * }
  20111. * });
  20112. * };
  20113. *
  20114. * @param {String|Array<String>} actions the identifier for the modeling action to check
  20115. * @param {Number} [priority] the priority at which this rule is being applied
  20116. * @param {Function} fn the callback function that performs the actual check
  20117. */
  20118. RuleProvider.prototype.addRule = function(actions, priority, fn) {
  20119. var self = this;
  20120. if (typeof actions === 'string') {
  20121. actions = [ actions ];
  20122. }
  20123. actions.forEach(function(action) {
  20124. self.canExecute(action, priority, function(context, action, event) {
  20125. return fn(context);
  20126. }, true);
  20127. });
  20128. };
  20129. },{"207":207,"78":78}],154:[function(_dereq_,module,exports){
  20130. 'use strict';
  20131. /**
  20132. * A service that provides rules for certain diagram actions.
  20133. *
  20134. * @param {CommandStack} commandStack
  20135. */
  20136. function Rules(commandStack) {
  20137. this._commandStack = commandStack;
  20138. }
  20139. Rules.$inject = [ 'commandStack' ];
  20140. module.exports = Rules;
  20141. /**
  20142. * This method can be queried to ask whether certain modeling actions
  20143. * are allowed or not.
  20144. *
  20145. * @param {String} action the action to be checked
  20146. * @param {Object} [context] the context to check the action in
  20147. *
  20148. * @return {Boolean} returns true, false or null depending on whether the
  20149. * operation is allowed, not allowed or should be ignored.
  20150. */
  20151. Rules.prototype.allowed = function(action, context) {
  20152. var allowed = this._commandStack.canExecute(action, context);
  20153. // map undefined to true, i.e. no rules
  20154. return allowed === undefined ? true : allowed;
  20155. };
  20156. },{}],155:[function(_dereq_,module,exports){
  20157. module.exports = {
  20158. __depends__: [ _dereq_(80) ],
  20159. __init__: [ 'rules' ],
  20160. rules: [ 'type', _dereq_(154) ]
  20161. };
  20162. },{"154":154,"80":80}],156:[function(_dereq_,module,exports){
  20163. 'use strict';
  20164. var isArray = _dereq_(330),
  20165. forEach = _dereq_(218);
  20166. /**
  20167. * A service that offers the current selection in a diagram.
  20168. * Offers the api to control the selection, too.
  20169. *
  20170. * @class
  20171. *
  20172. * @param {EventBus} eventBus the event bus
  20173. */
  20174. function Selection(eventBus) {
  20175. this._eventBus = eventBus;
  20176. this._selectedElements = [];
  20177. var self = this;
  20178. eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
  20179. var element = e.element;
  20180. self.deselect(element);
  20181. });
  20182. }
  20183. Selection.$inject = [ 'eventBus' ];
  20184. module.exports = Selection;
  20185. Selection.prototype.deselect = function(element) {
  20186. var selectedElements = this._selectedElements;
  20187. var idx = selectedElements.indexOf(element);
  20188. if (idx !== -1) {
  20189. var oldSelection = selectedElements.slice();
  20190. selectedElements.splice(idx, 1);
  20191. this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
  20192. }
  20193. };
  20194. Selection.prototype.get = function() {
  20195. return this._selectedElements;
  20196. };
  20197. Selection.prototype.isSelected = function(element) {
  20198. return this._selectedElements.indexOf(element) !== -1;
  20199. };
  20200. /**
  20201. * This method selects one or more elements on the diagram.
  20202. *
  20203. * By passing an additional add parameter you can decide whether or not the element(s)
  20204. * should be added to the already existing selection or not.
  20205. *
  20206. * @method Selection#select
  20207. *
  20208. * @param {Object|Object[]} elements element or array of elements to be selected
  20209. * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false
  20210. */
  20211. Selection.prototype.select = function(elements, add) {
  20212. var selectedElements = this._selectedElements,
  20213. oldSelection = selectedElements.slice();
  20214. if (!isArray(elements)) {
  20215. elements = elements ? [ elements ] : [];
  20216. }
  20217. // selection may be cleared by passing an empty array or null
  20218. // to the method
  20219. if (add) {
  20220. forEach(elements, function(element) {
  20221. if (selectedElements.indexOf(element) !== -1) {
  20222. // already selected
  20223. return;
  20224. } else {
  20225. selectedElements.push(element);
  20226. }
  20227. });
  20228. } else {
  20229. this._selectedElements = selectedElements = elements.slice();
  20230. }
  20231. this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
  20232. };
  20233. },{"218":218,"330":330}],157:[function(_dereq_,module,exports){
  20234. 'use strict';
  20235. var hasPrimaryModifier = _dereq_(193).hasPrimaryModifier;
  20236. function SelectionBehavior(eventBus, selection, canvas) {
  20237. eventBus.on('create.end', 500, function(e) {
  20238. // select the created shape after a
  20239. // successful create operation
  20240. if (e.context.canExecute) {
  20241. selection.select(e.context.shape);
  20242. }
  20243. });
  20244. eventBus.on('connect.end', 500, function(e) {
  20245. // select the connect end target
  20246. // after a connect operation
  20247. if (e.context.canExecute && e.context.target) {
  20248. selection.select(e.context.target);
  20249. }
  20250. });
  20251. eventBus.on('shape.move.end', 500, function(e) {
  20252. var previousSelection = e.previousSelection || [];
  20253. var shape = e.context.shape;
  20254. // make sure at least the main moved element is being
  20255. // selected after a move operation
  20256. if (previousSelection.indexOf(shape) === -1) {
  20257. selection.select(shape);
  20258. }
  20259. });
  20260. // Shift + click selection
  20261. eventBus.on('element.click', function(event) {
  20262. var element = event.element;
  20263. // do not select the root element
  20264. // or connections
  20265. if (element === canvas.getRootElement()) {
  20266. element = null;
  20267. }
  20268. var isSelected = selection.isSelected(element),
  20269. isMultiSelect = selection.get().length > 1;
  20270. // mouse-event: SELECTION_KEY
  20271. var add = hasPrimaryModifier(event);
  20272. // select OR deselect element in multi selection
  20273. if (isSelected && isMultiSelect) {
  20274. if (add) {
  20275. return selection.deselect(element);
  20276. } else {
  20277. return selection.select(element);
  20278. }
  20279. } else
  20280. if (!isSelected) {
  20281. selection.select(element, add);
  20282. } else {
  20283. selection.deselect(element);
  20284. }
  20285. });
  20286. }
  20287. SelectionBehavior.$inject = [ 'eventBus', 'selection', 'canvas' ];
  20288. module.exports = SelectionBehavior;
  20289. },{"193":193}],158:[function(_dereq_,module,exports){
  20290. 'use strict';
  20291. var forEach = _dereq_(218);
  20292. var MARKER_HOVER = 'hover',
  20293. MARKER_SELECTED = 'selected';
  20294. /**
  20295. * A plugin that adds a visible selection UI to shapes and connections
  20296. * by appending the <code>hover</code> and <code>selected</code> classes to them.
  20297. *
  20298. * @class
  20299. *
  20300. * Makes elements selectable, too.
  20301. *
  20302. * @param {EventBus} events
  20303. * @param {SelectionService} selection
  20304. * @param {Canvas} canvas
  20305. */
  20306. function SelectionVisuals(events, canvas, selection, graphicsFactory, styles) {
  20307. this._multiSelectionBox = null;
  20308. function addMarker(e, cls) {
  20309. canvas.addMarker(e, cls);
  20310. }
  20311. function removeMarker(e, cls) {
  20312. canvas.removeMarker(e, cls);
  20313. }
  20314. events.on('element.hover', function(event) {
  20315. addMarker(event.element, MARKER_HOVER);
  20316. });
  20317. events.on('element.out', function(event) {
  20318. removeMarker(event.element, MARKER_HOVER);
  20319. });
  20320. events.on('selection.changed', function(event) {
  20321. function deselect(s) {
  20322. removeMarker(s, MARKER_SELECTED);
  20323. }
  20324. function select(s) {
  20325. addMarker(s, MARKER_SELECTED);
  20326. }
  20327. var oldSelection = event.oldSelection,
  20328. newSelection = event.newSelection;
  20329. forEach(oldSelection, function(e) {
  20330. if (newSelection.indexOf(e) === -1) {
  20331. deselect(e);
  20332. }
  20333. });
  20334. forEach(newSelection, function(e) {
  20335. if (oldSelection.indexOf(e) === -1) {
  20336. select(e);
  20337. }
  20338. });
  20339. });
  20340. }
  20341. SelectionVisuals.$inject = [
  20342. 'eventBus',
  20343. 'canvas',
  20344. 'selection',
  20345. 'graphicsFactory',
  20346. 'styles'
  20347. ];
  20348. module.exports = SelectionVisuals;
  20349. },{"218":218}],159:[function(_dereq_,module,exports){
  20350. module.exports = {
  20351. __init__: [ 'selectionVisuals', 'selectionBehavior' ],
  20352. __depends__: [
  20353. _dereq_(108),
  20354. _dereq_(141)
  20355. ],
  20356. selection: [ 'type', _dereq_(156) ],
  20357. selectionVisuals: [ 'type', _dereq_(158) ],
  20358. selectionBehavior: [ 'type', _dereq_(157) ]
  20359. };
  20360. },{"108":108,"141":141,"156":156,"157":157,"158":158}],160:[function(_dereq_,module,exports){
  20361. 'use strict';
  20362. var forEach = _dereq_(218);
  20363. var snapTo = _dereq_(161).snapTo;
  20364. /**
  20365. * A snap context, containing the (possibly incomplete)
  20366. * mappings of drop targets (to identify the snapping)
  20367. * to computed snap points.
  20368. */
  20369. function SnapContext() {
  20370. /**
  20371. * Map<String, SnapPoints> mapping drop targets to
  20372. * a list of possible snappings.
  20373. *
  20374. * @type {Object}
  20375. */
  20376. this._targets = {};
  20377. /**
  20378. * Map<String, Point> initial positioning of element
  20379. * regarding various snap directions.
  20380. *
  20381. * @type {Object}
  20382. */
  20383. this._snapOrigins = {};
  20384. /**
  20385. * List of snap locations
  20386. *
  20387. * @type {Array<String>}
  20388. */
  20389. this._snapLocations = [];
  20390. /**
  20391. * Map<String, Array<Point>> of default snapping locations
  20392. *
  20393. * @type {Object}
  20394. */
  20395. this._defaultSnaps = {};
  20396. }
  20397. SnapContext.prototype.getSnapOrigin = function(snapLocation) {
  20398. return this._snapOrigins[snapLocation];
  20399. };
  20400. SnapContext.prototype.setSnapOrigin = function(snapLocation, initialValue) {
  20401. this._snapOrigins[snapLocation] = initialValue;
  20402. if (this._snapLocations.indexOf(snapLocation) === -1) {
  20403. this._snapLocations.push(snapLocation);
  20404. }
  20405. };
  20406. SnapContext.prototype.addDefaultSnap = function(type, point) {
  20407. var snapValues = this._defaultSnaps[type];
  20408. if (!snapValues) {
  20409. snapValues = this._defaultSnaps[type] = [];
  20410. }
  20411. snapValues.push(point);
  20412. };
  20413. /**
  20414. * Return a number of initialized snaps, i.e. snap locations such as
  20415. * top-left, mid, bottom-right and so forth.
  20416. *
  20417. * @return {Array<String>} snapLocations
  20418. */
  20419. SnapContext.prototype.getSnapLocations = function() {
  20420. return this._snapLocations;
  20421. };
  20422. /**
  20423. * Set the snap locations for this context.
  20424. *
  20425. * The order of locations determines precedence.
  20426. *
  20427. * @param {Array<String>} snapLocations
  20428. */
  20429. SnapContext.prototype.setSnapLocations = function(snapLocations) {
  20430. this._snapLocations = snapLocations;
  20431. };
  20432. /**
  20433. * Get snap points for a given target
  20434. *
  20435. * @param {Element|String} target
  20436. */
  20437. SnapContext.prototype.pointsForTarget = function(target) {
  20438. var targetId = target.id || target;
  20439. var snapPoints = this._targets[targetId];
  20440. if (!snapPoints) {
  20441. snapPoints = this._targets[targetId] = new SnapPoints();
  20442. snapPoints.initDefaults(this._defaultSnaps);
  20443. }
  20444. return snapPoints;
  20445. };
  20446. module.exports = SnapContext;
  20447. /**
  20448. * Creates the snap points and initializes them with the
  20449. * given default values.
  20450. *
  20451. * @param {Object<String, Array<Point>>} [defaultPoints]
  20452. */
  20453. function SnapPoints(defaultSnaps) {
  20454. /**
  20455. * Map<String, Map<(x|y), Array<Number>>> mapping snap locations,
  20456. * i.e. top-left, bottom-right, center to actual snap values.
  20457. *
  20458. * @type {Object}
  20459. */
  20460. this._snapValues = {};
  20461. }
  20462. SnapPoints.prototype.add = function(snapLocation, point) {
  20463. var snapValues = this._snapValues[snapLocation];
  20464. if (!snapValues) {
  20465. snapValues = this._snapValues[snapLocation] = { x: [], y: [] };
  20466. }
  20467. if (snapValues.x.indexOf(point.x) === -1) {
  20468. snapValues.x.push(point.x);
  20469. }
  20470. if (snapValues.y.indexOf(point.y) === -1) {
  20471. snapValues.y.push(point.y);
  20472. }
  20473. };
  20474. SnapPoints.prototype.snap = function(point, snapLocation, axis, tolerance) {
  20475. var snappingValues = this._snapValues[snapLocation];
  20476. return snappingValues && snapTo(point[axis], snappingValues[axis], tolerance);
  20477. };
  20478. /**
  20479. * Initialize a number of default snapping points.
  20480. *
  20481. * @param {Object} defaultSnaps
  20482. */
  20483. SnapPoints.prototype.initDefaults = function(defaultSnaps) {
  20484. var self = this;
  20485. forEach(defaultSnaps || {}, function(snapPoints, snapLocation) {
  20486. forEach(snapPoints, function(point) {
  20487. self.add(snapLocation, point);
  20488. });
  20489. });
  20490. };
  20491. },{"161":161,"218":218}],161:[function(_dereq_,module,exports){
  20492. 'use strict';
  20493. var abs = Math.abs,
  20494. round = Math.round;
  20495. /**
  20496. * Snap value to a collection of reference values.
  20497. *
  20498. * @param {Number} value
  20499. * @param {Array<Number>} values
  20500. * @param {Number} [tolerance=10]
  20501. *
  20502. * @return {Number} the value we snapped to or null, if none snapped
  20503. */
  20504. function snapTo(value, values, tolerance) {
  20505. tolerance = tolerance === undefined ? 10 : tolerance;
  20506. var idx, snapValue;
  20507. for (idx = 0; idx < values.length; idx++) {
  20508. snapValue = values[idx];
  20509. if (abs(snapValue - value) <= tolerance) {
  20510. return snapValue;
  20511. }
  20512. }
  20513. }
  20514. module.exports.snapTo = snapTo;
  20515. function topLeft(bounds) {
  20516. return {
  20517. x: bounds.x,
  20518. y: bounds.y
  20519. };
  20520. }
  20521. module.exports.topLeft = topLeft;
  20522. function mid(bounds, defaultValue) {
  20523. if (!bounds || isNaN(bounds.x) || isNaN(bounds.y)) {
  20524. return defaultValue;
  20525. }
  20526. return {
  20527. x: round(bounds.x + bounds.width / 2),
  20528. y: round(bounds.y + bounds.height / 2)
  20529. };
  20530. }
  20531. module.exports.mid = mid;
  20532. function bottomRight(bounds) {
  20533. return {
  20534. x: bounds.x + bounds.width,
  20535. y: bounds.y + bounds.height
  20536. };
  20537. }
  20538. module.exports.bottomRight = bottomRight;
  20539. /**
  20540. * Retrieve the snap state of the given event.
  20541. *
  20542. * @param {Event} event
  20543. * @param {String} axis
  20544. *
  20545. * @return {Boolean} the snapped state
  20546. *
  20547. */
  20548. module.exports.isSnapped = function(event, axis) {
  20549. var snapped = event.snapped;
  20550. if (!snapped) {
  20551. return false;
  20552. }
  20553. if (typeof axis === 'string') {
  20554. return snapped[axis];
  20555. }
  20556. return snapped.x && snapped.y;
  20557. };
  20558. /**
  20559. * Set the given event as snapped.
  20560. *
  20561. * @param {Event} event
  20562. * @param {String} axis
  20563. * @param {Number|Boolean} value
  20564. *
  20565. * @return {Number} old value
  20566. */
  20567. module.exports.setSnapped = function(event, axis, value) {
  20568. if (typeof axis !== 'string') {
  20569. throw new Error('axis must be in [x, y]');
  20570. }
  20571. if (typeof value !== 'number' && value !== false) {
  20572. throw new Error('value must be Number or false');
  20573. }
  20574. var delta,
  20575. previousValue = event[axis];
  20576. var snapped = event.snapped = (event.snapped || {});
  20577. if (value === false) {
  20578. snapped[axis] = false;
  20579. } else {
  20580. snapped[axis] = true;
  20581. delta = value - previousValue;
  20582. event[axis] += delta;
  20583. event['d' + axis] += delta;
  20584. }
  20585. return previousValue;
  20586. };
  20587. },{}],162:[function(_dereq_,module,exports){
  20588. 'use strict';
  20589. var filter = _dereq_(216),
  20590. forEach = _dereq_(218),
  20591. debounce = _dereq_(228);
  20592. var mid = _dereq_(161).mid;
  20593. var SnapContext = _dereq_(160);
  20594. var SnapUtil = _dereq_(161);
  20595. var isSnapped = SnapUtil.isSnapped,
  20596. setSnapped = SnapUtil.setSnapped;
  20597. /**
  20598. * A general purpose snapping component for diagram elements.
  20599. *
  20600. * @param {EventBus} eventBus
  20601. * @param {Canvas} canvas
  20602. */
  20603. function Snapping(eventBus, canvas) {
  20604. this._canvas = canvas;
  20605. var self = this;
  20606. eventBus.on([ 'shape.move.start', 'create.start' ], function(event) {
  20607. self.initSnap(event);
  20608. });
  20609. eventBus.on([ 'shape.move.move', 'shape.move.end', 'create.move', 'create.end' ], function(event) {
  20610. if (event.originalEvent && event.originalEvent.ctrlKey) {
  20611. return;
  20612. }
  20613. if (isSnapped(event)) {
  20614. return;
  20615. }
  20616. self.snap(event);
  20617. });
  20618. eventBus.on([ 'shape.move.cleanup', 'create.cleanup' ], function(event) {
  20619. self.hide();
  20620. });
  20621. // delay hide by 1000 seconds since last match
  20622. this._asyncHide = debounce(this.hide, 1000);
  20623. }
  20624. Snapping.$inject = [ 'eventBus', 'canvas' ];
  20625. module.exports = Snapping;
  20626. Snapping.prototype.initSnap = function(event) {
  20627. var context = event.context,
  20628. shape = context.shape,
  20629. snapContext = context.snapContext;
  20630. if (!snapContext) {
  20631. snapContext = context.snapContext = new SnapContext();
  20632. }
  20633. var snapMid = mid(shape, event);
  20634. snapContext.setSnapOrigin('mid', {
  20635. x: snapMid.x - event.x,
  20636. y: snapMid.y - event.y
  20637. });
  20638. return snapContext;
  20639. };
  20640. Snapping.prototype.snap = function(event) {
  20641. var context = event.context,
  20642. snapContext = context.snapContext,
  20643. shape = context.shape,
  20644. target = context.target,
  20645. snapLocations = snapContext.getSnapLocations();
  20646. if (!target) {
  20647. return;
  20648. }
  20649. var snapPoints = snapContext.pointsForTarget(target);
  20650. if (!snapPoints.initialized) {
  20651. this.addTargetSnaps(snapPoints, shape, target);
  20652. snapPoints.initialized = true;
  20653. }
  20654. var snapping = {
  20655. x: isSnapped(event, 'x'),
  20656. y: isSnapped(event, 'y')
  20657. };
  20658. forEach(snapLocations, function(location) {
  20659. var snapOrigin = snapContext.getSnapOrigin(location);
  20660. var snapCurrent = {
  20661. x: event.x + snapOrigin.x,
  20662. y: event.y + snapOrigin.y
  20663. };
  20664. // snap on both axis, if not snapped already
  20665. forEach([ 'x', 'y' ], function(axis) {
  20666. var locationSnapping;
  20667. if (!snapping[axis]) {
  20668. locationSnapping = snapPoints.snap(snapCurrent, location, axis, 7);
  20669. if (locationSnapping !== undefined) {
  20670. snapping[axis] = {
  20671. value: locationSnapping,
  20672. originValue: locationSnapping - snapOrigin[axis]
  20673. };
  20674. }
  20675. }
  20676. });
  20677. // no more need to snap, drop out of interation
  20678. if (snapping.x && snapping.y) {
  20679. return false;
  20680. }
  20681. });
  20682. // show snap visuals
  20683. this.showSnapLine('vertical', snapping.x && snapping.x.value);
  20684. this.showSnapLine('horizontal', snapping.y && snapping.y.value);
  20685. // adjust event { x, y, dx, dy } and mark as snapping
  20686. forEach([ 'x', 'y' ], function(axis) {
  20687. var axisSnapping = snapping[axis];
  20688. if (typeof axisSnapping === 'object') {
  20689. setSnapped(event, axis, axisSnapping.originValue);
  20690. }
  20691. });
  20692. };
  20693. Snapping.prototype._createLine = function(orientation) {
  20694. var root = this._canvas.getLayer('snap');
  20695. var line = root.path('M0,0 L0,0').addClass('djs-snap-line');
  20696. return {
  20697. update: function(position) {
  20698. if (typeof position !== 'number') {
  20699. line.attr({ display: 'none' });
  20700. } else {
  20701. if (orientation === 'horizontal') {
  20702. line.attr({
  20703. path: 'M-100000,' + position + ' L+100000,' + position,
  20704. display: ''
  20705. });
  20706. } else {
  20707. line.attr({
  20708. path: 'M ' + position + ',-100000 L ' + position + ', +100000',
  20709. display: ''
  20710. });
  20711. }
  20712. }
  20713. }
  20714. };
  20715. };
  20716. Snapping.prototype._createSnapLines = function() {
  20717. this._snapLines = {
  20718. horizontal: this._createLine('horizontal'),
  20719. vertical: this._createLine('vertical')
  20720. };
  20721. };
  20722. Snapping.prototype.showSnapLine = function(orientation, position) {
  20723. var line = this.getSnapLine(orientation);
  20724. if (line) {
  20725. line.update(position);
  20726. }
  20727. this._asyncHide();
  20728. };
  20729. Snapping.prototype.getSnapLine = function(orientation) {
  20730. if (!this._snapLines) {
  20731. this._createSnapLines();
  20732. }
  20733. return this._snapLines[orientation];
  20734. };
  20735. Snapping.prototype.hide = function() {
  20736. forEach(this._snapLines, function(l) {
  20737. l.update();
  20738. });
  20739. };
  20740. Snapping.prototype.addTargetSnaps = function(snapPoints, shape, target) {
  20741. var siblings = this.getSiblings(shape, target);
  20742. forEach(siblings, function(s) {
  20743. snapPoints.add('mid', mid(s));
  20744. });
  20745. };
  20746. Snapping.prototype.getSiblings = function(element, target) {
  20747. // snap to all non connection siblings
  20748. return target && filter(target.children, function(e) {
  20749. return !e.hidden && !e.labelTarget && !e.waypoints && e.host !== element && e !== element;
  20750. });
  20751. };
  20752. },{"160":160,"161":161,"216":216,"218":218,"228":228}],163:[function(_dereq_,module,exports){
  20753. 'use strict';
  20754. var SpaceUtil = _dereq_(165);
  20755. var Cursor = _dereq_(185);
  20756. var hasPrimaryModifier = _dereq_(193).hasPrimaryModifier;
  20757. var abs = Math.abs,
  20758. round = Math.round;
  20759. var HIGH_PRIORITY = 1500;
  20760. /**
  20761. * A tool that allows users to create and remove space in a diagram.
  20762. *
  20763. * The tool needs to be activated manually via {@link SpaceTool#activate(MouseEvent)}.
  20764. */
  20765. function SpaceTool(eventBus, dragging, elementRegistry, modeling, rules) {
  20766. function canResize(shape) {
  20767. var ctx = { shape: shape };
  20768. return rules.allowed('shape.resize', ctx);
  20769. }
  20770. function activateSelection(event, autoActivate) {
  20771. dragging.activate(event, 'spaceTool.selection', {
  20772. cursor: 'crosshair',
  20773. autoActivate: autoActivate,
  20774. data: {
  20775. context: {
  20776. crosshair: {}
  20777. }
  20778. }
  20779. });
  20780. }
  20781. function activateMakeSpace(event) {
  20782. dragging.activate(event, 'spaceTool', {
  20783. autoActivate: true,
  20784. cursor: 'crosshair',
  20785. data: {
  20786. context: {}
  20787. }
  20788. });
  20789. }
  20790. eventBus.on('spaceTool.selection.end', function(event) {
  20791. setTimeout(function() {
  20792. activateMakeSpace(event.originalEvent);
  20793. });
  20794. });
  20795. var AXIS_TO_DIMENSION = { x: 'width', y: 'height' },
  20796. AXIS_INVERTED = { x: 'y', y: 'x' };
  20797. function initializeMakeSpace(event, context) {
  20798. var axis = abs(event.dx) > abs(event.dy) ? 'x' : 'y',
  20799. offset = event['d' + axis],
  20800. // start point of create space operation
  20801. spacePos = event[axis] - offset,
  20802. // list of moving shapes
  20803. movingShapes = [],
  20804. // list of resizing shapes
  20805. resizingShapes = [];
  20806. if (abs(offset) < 5) {
  20807. return false;
  20808. }
  20809. // inverts the offset to choose the shapes
  20810. // on the opposite side of the resizer if
  20811. // a key modifier is pressed
  20812. if (hasPrimaryModifier(event)) {
  20813. offset *= -1;
  20814. }
  20815. // collect all elements that need to be moved _AND_
  20816. // resized given on the initial create space position
  20817. elementRegistry.forEach(function (shape) {
  20818. var shapeStart = shape[ [ axis ]],
  20819. shapeEnd = shapeStart + shape[ AXIS_TO_DIMENSION[ axis ]];
  20820. // checking if it's root
  20821. if (!shape.parent) {
  20822. return;
  20823. }
  20824. // checking if it's a shape
  20825. if (shape.waypoints) {
  20826. return;
  20827. }
  20828. // shape after spacePos
  20829. if (offset > 0 && shapeStart > spacePos) {
  20830. return movingShapes.push(shape);
  20831. }
  20832. // shape before spacePos
  20833. if (offset < 0 && shapeEnd < spacePos) {
  20834. return movingShapes.push(shape);
  20835. }
  20836. // shape on top of spacePos, resize only if allowed
  20837. if (shapeStart < spacePos && shapeEnd > spacePos && canResize(shape)) {
  20838. return resizingShapes.push(shape);
  20839. }
  20840. });
  20841. // store data in context
  20842. context.axis = axis;
  20843. context.direction = SpaceUtil.getDirection(axis, offset);
  20844. context.movingShapes = movingShapes;
  20845. context.resizingShapes = resizingShapes;
  20846. Cursor.set('resize-' + (axis === 'x' ? 'ew' : 'ns'));
  20847. return true;
  20848. }
  20849. eventBus.on('spaceTool.move', HIGH_PRIORITY , function(event) {
  20850. var context = event.context;
  20851. if (!context.initialized) {
  20852. context.initialized = initializeMakeSpace(event, context);
  20853. }
  20854. });
  20855. eventBus.on('spaceTool.end', function(event) {
  20856. var context = event.context,
  20857. axis = context.axis,
  20858. direction = context.direction,
  20859. movingShapes = context.movingShapes,
  20860. resizingShapes = context.resizingShapes;
  20861. // skip if create space has not been initialized yet
  20862. if (!context.initialized) {
  20863. return;
  20864. }
  20865. var delta = { x: round(event.dx), y: round(event.dy) };
  20866. delta[ AXIS_INVERTED[ axis ] ] = 0;
  20867. return modeling.createSpace(movingShapes, resizingShapes, delta, direction);
  20868. });
  20869. // API
  20870. this.activateSelection = activateSelection;
  20871. this.activateMakeSpace = activateMakeSpace;
  20872. }
  20873. SpaceTool.$inject = ['eventBus', 'dragging', 'elementRegistry', 'modeling', 'rules'];
  20874. module.exports = SpaceTool;
  20875. },{"165":165,"185":185,"193":193}],164:[function(_dereq_,module,exports){
  20876. 'use strict';
  20877. var forEach = _dereq_(218);
  20878. var MARKER_DRAGGING = 'djs-dragging';
  20879. /**
  20880. * A plugin that makes shapes draggable / droppable.
  20881. *
  20882. * @param {EventBus} eventBus
  20883. * @param {ElementRegistry} elementRegistry
  20884. * @param {Canvas} canvas
  20885. * @param {Styles} styles
  20886. */
  20887. function SpaceToolVisuals(eventBus, elementRegistry, canvas, styles) {
  20888. function getGfx(e) {
  20889. return elementRegistry.getGraphics(e);
  20890. }
  20891. function addDragger(shape, dragGroup) {
  20892. var gfx = getGfx(shape);
  20893. var dragger = gfx.clone();
  20894. var bbox = gfx.getBBox();
  20895. dragger.attr(styles.cls('djs-dragger', [], {
  20896. x: bbox.x,
  20897. y: bbox.y
  20898. }));
  20899. dragGroup.add(dragger);
  20900. }
  20901. eventBus.on('spaceTool.selection.start', function(event) {
  20902. var space = canvas.getLayer('space'),
  20903. context = event.context;
  20904. var orientation = {
  20905. x: 'M 0,-10000 L 0,10000',
  20906. y: 'M -10000,0 L 10000,0'
  20907. };
  20908. var crosshairGroup = space.group().attr(styles.cls('djs-crosshair-group', [ 'no-events' ]));
  20909. crosshairGroup.path(orientation.x).addClass('djs-crosshair');
  20910. crosshairGroup.path(orientation.y).addClass('djs-crosshair');
  20911. context.crosshairGroup = crosshairGroup;
  20912. });
  20913. eventBus.on('spaceTool.selection.move', function(event) {
  20914. var crosshairGroup = event.context.crosshairGroup;
  20915. crosshairGroup.translate(event.x, event.y);
  20916. });
  20917. eventBus.on('spaceTool.selection.cleanup', function(event) {
  20918. var context = event.context,
  20919. crosshairGroup = context.crosshairGroup;
  20920. if (crosshairGroup) {
  20921. crosshairGroup.remove();
  20922. }
  20923. });
  20924. // assign a low priority to this handler
  20925. // to let others modify the move context before
  20926. // we draw things
  20927. eventBus.on('spaceTool.move', function(event) {
  20928. /*
  20929. TODO (Ricardo): extend connections while adding space
  20930. */
  20931. var context = event.context,
  20932. line = context.line,
  20933. axis = context.axis,
  20934. dragShapes = context.movingShapes;
  20935. if (!context.initialized) {
  20936. return;
  20937. }
  20938. if (!context.dragGroup) {
  20939. var spaceLayer = canvas.getLayer('space');
  20940. line = spaceLayer.path('M0,0 L0,0').addClass('djs-crosshair');
  20941. context.line = line;
  20942. var dragGroup = canvas.getDefaultLayer().group().attr(styles.cls('djs-drag-group', [ 'no-events' ]));
  20943. forEach(dragShapes, function(shape) {
  20944. addDragger(shape, dragGroup);
  20945. canvas.addMarker(shape, MARKER_DRAGGING);
  20946. });
  20947. context.dragGroup = dragGroup;
  20948. }
  20949. var orientation = {
  20950. x: 'M' + event.x + ', -10000 L' + event.x + ', 10000',
  20951. y: 'M -10000, ' + event.y + ' L 10000, ' + event.y
  20952. };
  20953. line.attr({
  20954. path: orientation[ axis ],
  20955. display: ''
  20956. });
  20957. var opposite = { x: 'y', y: 'x' };
  20958. var delta = { x: event.dx, y: event.dy };
  20959. delta[ opposite[ context.axis ] ] = 0;
  20960. context.dragGroup.translate(delta.x, delta.y);
  20961. });
  20962. eventBus.on('spaceTool.cleanup', function(event) {
  20963. var context = event.context,
  20964. shapes = context.movingShapes,
  20965. line = context.line,
  20966. dragGroup = context.dragGroup;
  20967. // remove dragging marker
  20968. forEach(shapes, function(e) {
  20969. canvas.removeMarker(e, MARKER_DRAGGING);
  20970. });
  20971. if (dragGroup) {
  20972. line.remove();
  20973. dragGroup.remove();
  20974. }
  20975. });
  20976. }
  20977. SpaceToolVisuals.$inject = [ 'eventBus', 'elementRegistry', 'canvas', 'styles' ];
  20978. module.exports = SpaceToolVisuals;
  20979. },{"218":218}],165:[function(_dereq_,module,exports){
  20980. 'use strict';
  20981. /**
  20982. * Get Resize direction given axis + offset
  20983. *
  20984. * @param {String} axis (x|y)
  20985. * @param {Number} offset
  20986. *
  20987. * @return {String} (e|w|n|s)
  20988. */
  20989. function getDirection(axis, offset) {
  20990. if (axis === 'x') {
  20991. if (offset > 0) {
  20992. return 'e';
  20993. }
  20994. if (offset < 0) {
  20995. return 'w';
  20996. }
  20997. }
  20998. if (axis === 'y') {
  20999. if (offset > 0) {
  21000. return 's';
  21001. }
  21002. if (offset < 0) {
  21003. return 'n';
  21004. }
  21005. }
  21006. return null;
  21007. }
  21008. module.exports.getDirection = getDirection;
  21009. /**
  21010. * Resize the given bounds by the specified delta from a given anchor point.
  21011. *
  21012. * @param {Bounds} bounds the bounding box that should be resized
  21013. * @param {String} direction in which the element is resized (n, s, e, w)
  21014. * @param {Point} delta of the resize operation
  21015. *
  21016. * @return {Bounds} resized bounding box
  21017. */
  21018. module.exports.resizeBounds = function(bounds, direction, delta) {
  21019. var dx = delta.x,
  21020. dy = delta.y;
  21021. switch (direction) {
  21022. case 'n':
  21023. return {
  21024. x: bounds.x,
  21025. y: bounds.y + dy,
  21026. width: bounds.width,
  21027. height: bounds.height - dy
  21028. };
  21029. case 's':
  21030. return {
  21031. x: bounds.x,
  21032. y: bounds.y,
  21033. width: bounds.width,
  21034. height: bounds.height + dy
  21035. };
  21036. case 'w':
  21037. return {
  21038. x: bounds.x + dx,
  21039. y: bounds.y,
  21040. width: bounds.width - dx,
  21041. height: bounds.height
  21042. };
  21043. case 'e':
  21044. return {
  21045. x: bounds.x,
  21046. y: bounds.y,
  21047. width: bounds.width + dx,
  21048. height: bounds.height
  21049. };
  21050. default:
  21051. throw new Error('unrecognized direction: ' + direction);
  21052. }
  21053. };
  21054. },{}],166:[function(_dereq_,module,exports){
  21055. module.exports = {
  21056. __init__: ['spaceToolVisuals'],
  21057. __depends__: [_dereq_(106), _dereq_(136), _dereq_(155) ],
  21058. spaceTool: ['type', _dereq_(163)],
  21059. spaceToolVisuals: ['type', _dereq_(164) ]
  21060. };
  21061. },{"106":106,"136":136,"155":155,"163":163,"164":164}],167:[function(_dereq_,module,exports){
  21062. 'use strict';
  21063. var isString = _dereq_(336),
  21064. assign = _dereq_(339),
  21065. forEach = _dereq_(218),
  21066. debounce = _dereq_(228);
  21067. var domify = _dereq_(356),
  21068. domAttr = _dereq_(351),
  21069. domClasses = _dereq_(352),
  21070. domRemove = _dereq_(360),
  21071. domDelegate = _dereq_(355);
  21072. // document wide unique tooltip ids
  21073. var ids = new (_dereq_(190))('tt');
  21074. function createRoot(parent) {
  21075. var root = domify('<div class="djs-tooltip-container" style="position: absolute; width: 0; height: 0;" />');
  21076. parent.insertBefore(root, parent.firstChild);
  21077. return root;
  21078. }
  21079. function setPosition(el, x, y) {
  21080. assign(el.style, { left: x + 'px', top: y + 'px' });
  21081. }
  21082. function setVisible(el, visible) {
  21083. el.style.display = visible === false ? 'none' : '';
  21084. }
  21085. var tooltipClass = 'djs-tooltip',
  21086. tooltipSelector = '.' + tooltipClass;
  21087. /**
  21088. * A service that allows users to render tool tips on the diagram.
  21089. *
  21090. * The tooltip service will take care of updating the tooltip positioning
  21091. * during navigation + zooming.
  21092. *
  21093. * @example
  21094. *
  21095. * ```javascript
  21096. *
  21097. * // add a pink badge on the top left of the shape
  21098. * tooltips.add({
  21099. * position: {
  21100. * x: 50,
  21101. * y: 100
  21102. * },
  21103. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  21104. * });
  21105. *
  21106. * // or with optional life span
  21107. * tooltips.add({
  21108. * position: {
  21109. * top: -5,
  21110. * left: -5
  21111. * },
  21112. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>',
  21113. * ttl: 2000
  21114. * });
  21115. *
  21116. * // remove a tool tip
  21117. * var id = tooltips.add(...);
  21118. * tooltips.remove(id);
  21119. * ```
  21120. *
  21121. * @param {Object} config
  21122. * @param {EventBus} eventBus
  21123. * @param {Canvas} canvas
  21124. */
  21125. function Tooltips(config, eventBus, canvas) {
  21126. this._eventBus = eventBus;
  21127. this._canvas = canvas;
  21128. this._ids = ids;
  21129. this._tooltipDefaults = {
  21130. show: {
  21131. minZoom: 0.7,
  21132. maxZoom: 5.0
  21133. }
  21134. };
  21135. /**
  21136. * Mapping tooltipId -> tooltip
  21137. */
  21138. this._tooltips = {};
  21139. // root html element for all tooltips
  21140. this._tooltipRoot = createRoot(canvas.getContainer());
  21141. var self = this;
  21142. domDelegate.bind(this._tooltipRoot, tooltipSelector, 'mousedown', function(event) {
  21143. event.stopPropagation();
  21144. });
  21145. domDelegate.bind(this._tooltipRoot, tooltipSelector, 'mouseover', function(event) {
  21146. self.trigger('mouseover', event);
  21147. });
  21148. domDelegate.bind(this._tooltipRoot, tooltipSelector, 'mouseout', function(event) {
  21149. self.trigger('mouseout', event);
  21150. });
  21151. this._init(config);
  21152. }
  21153. Tooltips.$inject = [ 'config.tooltips', 'eventBus', 'canvas' ];
  21154. module.exports = Tooltips;
  21155. /**
  21156. * Adds a HTML tooltip to the diagram
  21157. *
  21158. * @param {Object} tooltip the tooltip configuration
  21159. *
  21160. * @param {String|DOMElement} tooltip.html html element to use as an tooltip
  21161. * @param {Object} [tooltip.show] show configuration
  21162. * @param {Number} [tooltip.show.minZoom] minimal zoom level to show the tooltip
  21163. * @param {Number} [tooltip.show.maxZoom] maximum zoom level to show the tooltip
  21164. * @param {Object} tooltip.position where to attach the tooltip
  21165. * @param {Number} [tooltip.position.left] relative to element bbox left attachment
  21166. * @param {Number} [tooltip.position.top] relative to element bbox top attachment
  21167. * @param {Number} [tooltip.position.bottom] relative to element bbox bottom attachment
  21168. * @param {Number} [tooltip.position.right] relative to element bbox right attachment
  21169. * @param {Number} [tooltip.timeout=-1]
  21170. *
  21171. * @return {String} id that may be used to reference the tooltip for update or removal
  21172. */
  21173. Tooltips.prototype.add = function(tooltip) {
  21174. if (!tooltip.position) {
  21175. throw new Error('must specifiy tooltip position');
  21176. }
  21177. if (!tooltip.html) {
  21178. throw new Error('must specifiy tooltip html');
  21179. }
  21180. var id = this._ids.next();
  21181. tooltip = assign({}, this._tooltipDefaults, tooltip, {
  21182. id: id
  21183. });
  21184. this._addTooltip(tooltip);
  21185. if (tooltip.timeout) {
  21186. this.setTimeout(tooltip);
  21187. }
  21188. return id;
  21189. };
  21190. Tooltips.prototype.trigger = function(action, event) {
  21191. var node = event.delegateTarget || event.target;
  21192. var tooltip = this.get(domAttr(node, 'data-tooltip-id'));
  21193. if (!tooltip) {
  21194. return;
  21195. }
  21196. if (action === 'mouseover' && tooltip.timeout) {
  21197. this.clearTimeout(tooltip);
  21198. }
  21199. if (action === 'mouseout' && tooltip.timeout) {
  21200. // cut timeout after mouse out
  21201. tooltip.timeout = 1000;
  21202. this.setTimeout(tooltip);
  21203. }
  21204. };
  21205. /**
  21206. * Get a tooltip with the given id
  21207. *
  21208. * @param {String} id
  21209. */
  21210. Tooltips.prototype.get = function(id) {
  21211. if (typeof id !== 'string') {
  21212. id = id.id;
  21213. }
  21214. return this._tooltips[id];
  21215. };
  21216. Tooltips.prototype.clearTimeout = function(tooltip) {
  21217. tooltip = this.get(tooltip);
  21218. if (!tooltip) {
  21219. return;
  21220. }
  21221. var removeTimer = tooltip.removeTimer;
  21222. if (removeTimer) {
  21223. clearTimeout(removeTimer);
  21224. tooltip.removeTimer = null;
  21225. }
  21226. };
  21227. Tooltips.prototype.setTimeout = function(tooltip) {
  21228. tooltip = this.get(tooltip);
  21229. if (!tooltip) {
  21230. return;
  21231. }
  21232. this.clearTimeout(tooltip);
  21233. var self = this;
  21234. tooltip.removeTimer = setTimeout(function() {
  21235. self.remove(tooltip);
  21236. }, tooltip.timeout);
  21237. };
  21238. /**
  21239. * Remove an tooltip with the given id
  21240. *
  21241. * @param {String} id
  21242. */
  21243. Tooltips.prototype.remove = function(id) {
  21244. var tooltip = this.get(id);
  21245. if (tooltip) {
  21246. domRemove(tooltip.html);
  21247. domRemove(tooltip.htmlContainer);
  21248. delete tooltip.htmlContainer;
  21249. delete this._tooltips[tooltip.id];
  21250. }
  21251. };
  21252. Tooltips.prototype.show = function() {
  21253. setVisible(this._tooltipRoot);
  21254. };
  21255. Tooltips.prototype.hide = function() {
  21256. setVisible(this._tooltipRoot, false);
  21257. };
  21258. Tooltips.prototype._updateRoot = function(viewbox) {
  21259. var a = viewbox.scale || 1;
  21260. var d = viewbox.scale || 1;
  21261. var matrix = 'matrix(' + a + ',0,0,' + d + ',' + (-1 * viewbox.x * a) + ',' + (-1 * viewbox.y * d) + ')';
  21262. this._tooltipRoot.style.transform = matrix;
  21263. this._tooltipRoot.style['-ms-transform'] = matrix;
  21264. };
  21265. Tooltips.prototype._addTooltip = function(tooltip) {
  21266. var id = tooltip.id,
  21267. html = tooltip.html,
  21268. htmlContainer,
  21269. tooltipRoot = this._tooltipRoot;
  21270. // unwrap jquery (for those who need it)
  21271. if (html.get) {
  21272. html = html.get(0);
  21273. }
  21274. // create proper html elements from
  21275. // tooltip HTML strings
  21276. if (isString(html)) {
  21277. html = domify(html);
  21278. }
  21279. htmlContainer = domify('<div data-tooltip-id="' + id + '" class="' + tooltipClass + '" style="position: absolute">');
  21280. htmlContainer.appendChild(html);
  21281. if (tooltip.type) {
  21282. domClasses(htmlContainer).add('djs-tooltip-' + tooltip.type);
  21283. }
  21284. if (tooltip.className) {
  21285. domClasses(htmlContainer).add(tooltip.className);
  21286. }
  21287. tooltip.htmlContainer = htmlContainer;
  21288. tooltipRoot.appendChild(htmlContainer);
  21289. this._tooltips[id] = tooltip;
  21290. this._updateTooltip(tooltip);
  21291. };
  21292. Tooltips.prototype._updateTooltip = function(tooltip) {
  21293. var position = tooltip.position,
  21294. htmlContainer = tooltip.htmlContainer;
  21295. // update overlay html based on tooltip x, y
  21296. setPosition(htmlContainer, position.x, position.y);
  21297. };
  21298. Tooltips.prototype._updateTooltipVisibilty = function(viewbox) {
  21299. forEach(this._tooltips, function(tooltip) {
  21300. var show = tooltip.show,
  21301. htmlContainer = tooltip.htmlContainer,
  21302. visible = true;
  21303. if (show) {
  21304. if (show.minZoom > viewbox.scale ||
  21305. show.maxZoom < viewbox.scale) {
  21306. visible = false;
  21307. }
  21308. setVisible(htmlContainer, visible);
  21309. }
  21310. });
  21311. };
  21312. Tooltips.prototype._init = function(config) {
  21313. var self = this;
  21314. // scroll/zoom integration
  21315. var updateViewbox = function(viewbox) {
  21316. self._updateRoot(viewbox);
  21317. self._updateTooltipVisibilty(viewbox);
  21318. self.show();
  21319. };
  21320. if (!config || config.deferUpdate !== false) {
  21321. updateViewbox = debounce(updateViewbox, 300);
  21322. }
  21323. this._eventBus.on('canvas.viewbox.changed', function(event) {
  21324. self.hide();
  21325. updateViewbox(event.viewbox);
  21326. });
  21327. };
  21328. },{"190":190,"218":218,"228":228,"336":336,"339":339,"351":351,"352":352,"355":355,"356":356,"360":360}],168:[function(_dereq_,module,exports){
  21329. module.exports = {
  21330. __init__: [ 'tooltips' ],
  21331. tooltips: [ 'type', _dereq_(167) ]
  21332. };
  21333. },{"167":167}],169:[function(_dereq_,module,exports){
  21334. 'use strict';
  21335. function TouchFix(canvas, eventBus) {
  21336. var self = this;
  21337. eventBus.on('canvas.init', function(e) {
  21338. self.addBBoxMarker(e.svg);
  21339. });
  21340. }
  21341. TouchFix.$inject = [ 'canvas', 'eventBus' ];
  21342. module.exports = TouchFix;
  21343. /**
  21344. * Safari mobile (iOS 7) does not fire touchstart event in <SVG> element
  21345. * if there is no shape between 0,0 and viewport elements origin.
  21346. *
  21347. * So touchstart event is only fired when the <g class="viewport"> element was hit.
  21348. * Putting an element over and below the 'viewport' fixes that behavior.
  21349. */
  21350. TouchFix.prototype.addBBoxMarker = function(paper) {
  21351. var markerStyle = {
  21352. fill: 'none',
  21353. class: 'outer-bound-marker'
  21354. };
  21355. paper.rect(-10000, -10000, 10, 10).attr(markerStyle);
  21356. paper.rect(10000, 10000, 10, 10).attr(markerStyle);
  21357. };
  21358. },{}],170:[function(_dereq_,module,exports){
  21359. 'use strict';
  21360. var forEach = _dereq_(218),
  21361. domEvent = _dereq_(357),
  21362. domClosest = _dereq_(354),
  21363. Hammer = _dereq_(198),
  21364. Snap = _dereq_(200),
  21365. Event = _dereq_(187);
  21366. var MIN_ZOOM = 0.2,
  21367. MAX_ZOOM = 4;
  21368. var mouseEvents = [
  21369. 'mousedown',
  21370. 'mouseup',
  21371. 'mouseover',
  21372. 'mouseout',
  21373. 'click',
  21374. 'dblclick'
  21375. ];
  21376. function log() {
  21377. if (false) {
  21378. console.log.apply(console, arguments);
  21379. }
  21380. }
  21381. function get(service, injector) {
  21382. try {
  21383. return injector.get(service);
  21384. } catch (e) {
  21385. return null;
  21386. }
  21387. }
  21388. function createTouchRecognizer(node) {
  21389. function stopEvent(event) {
  21390. Event.stopEvent(event, true);
  21391. }
  21392. function stopMouse(event) {
  21393. forEach(mouseEvents, function(e) {
  21394. domEvent.bind(node, e, stopEvent, true);
  21395. });
  21396. }
  21397. function allowMouse(event) {
  21398. setTimeout(function() {
  21399. forEach(mouseEvents, function(e) {
  21400. domEvent.unbind(node, e, stopEvent, true);
  21401. });
  21402. }, 500);
  21403. }
  21404. domEvent.bind(node, 'touchstart', stopMouse, true);
  21405. domEvent.bind(node, 'touchend', allowMouse, true);
  21406. domEvent.bind(node, 'touchcancel', allowMouse, true);
  21407. // A touch event recognizer that handles
  21408. // touch events only (we know, we can already handle
  21409. // mouse events out of the box)
  21410. var recognizer = new Hammer.Manager(node, {
  21411. inputClass: Hammer.TouchInput,
  21412. recognizers: []
  21413. });
  21414. var tap = new Hammer.Tap();
  21415. var pan = new Hammer.Pan({ threshold: 10 });
  21416. var press = new Hammer.Press();
  21417. var pinch = new Hammer.Pinch();
  21418. var doubleTap = new Hammer.Tap({ event: 'doubletap', taps: 2 });
  21419. pinch.requireFailure(pan);
  21420. pinch.requireFailure(press);
  21421. recognizer.add([ pan, press, pinch, doubleTap, tap ]);
  21422. recognizer.reset = function(force) {
  21423. var recognizers = this.recognizers,
  21424. session = this.session;
  21425. if (session.stopped) {
  21426. return;
  21427. }
  21428. log('recognizer', 'stop');
  21429. recognizer.stop(force);
  21430. setTimeout(function() {
  21431. var i, r;
  21432. log('recognizer', 'reset');
  21433. for (i = 0; !!(r = recognizers[i]); i++) {
  21434. r.reset();
  21435. r.state = 8; // FAILED STATE
  21436. }
  21437. session.curRecognizer = null;
  21438. }, 0);
  21439. };
  21440. recognizer.on('hammer.input', function(event) {
  21441. if (event.srcEvent.defaultPrevented) {
  21442. recognizer.reset(true);
  21443. }
  21444. });
  21445. return recognizer;
  21446. }
  21447. /**
  21448. * A plugin that provides touch events for elements.
  21449. *
  21450. * @param {EventBus} eventBus
  21451. * @param {InteractionEvents} interactionEvents
  21452. */
  21453. function TouchInteractionEvents(injector, canvas, eventBus, elementRegistry, interactionEvents, snap) {
  21454. // optional integrations
  21455. var dragging = get('dragging', injector),
  21456. move = get('move', injector),
  21457. contextPad = get('contextPad', injector),
  21458. palette = get('palette', injector);
  21459. // the touch recognizer
  21460. var recognizer;
  21461. function handler(type) {
  21462. return function(event) {
  21463. log('element', type, event);
  21464. interactionEvents.fire(type, event);
  21465. };
  21466. }
  21467. function getGfx(target) {
  21468. var node = domClosest(target, 'svg, .djs-element', true);
  21469. return node && new Snap(node);
  21470. }
  21471. function initEvents(svg) {
  21472. // touch recognizer
  21473. recognizer = createTouchRecognizer(svg);
  21474. recognizer.on('doubletap', handler('element.dblclick'));
  21475. recognizer.on('tap', handler('element.click'));
  21476. function startGrabCanvas(event) {
  21477. log('canvas', 'grab start');
  21478. var lx = 0, ly = 0;
  21479. function update(e) {
  21480. var dx = e.deltaX - lx,
  21481. dy = e.deltaY - ly;
  21482. canvas.scroll({ dx: dx, dy: dy });
  21483. lx = e.deltaX;
  21484. ly = e.deltaY;
  21485. }
  21486. function end(e) {
  21487. recognizer.off('panmove', update);
  21488. recognizer.off('panend', end);
  21489. recognizer.off('pancancel', end);
  21490. log('canvas', 'grab end');
  21491. }
  21492. recognizer.on('panmove', update);
  21493. recognizer.on('panend', end);
  21494. recognizer.on('pancancel', end);
  21495. }
  21496. function startGrab(event) {
  21497. var gfx = getGfx(event.target),
  21498. element = gfx && elementRegistry.get(gfx);
  21499. // recognizer
  21500. if (move && canvas.getRootElement() !== element) {
  21501. log('element', 'move start', element, event, true);
  21502. return move.start(event, element, true);
  21503. } else {
  21504. startGrabCanvas(event);
  21505. }
  21506. }
  21507. function startZoom(e) {
  21508. log('canvas', 'zoom start');
  21509. var zoom = canvas.zoom(),
  21510. mid = e.center;
  21511. function update(e) {
  21512. var ratio = 1 - (1 - e.scale) / 1.50,
  21513. newZoom = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, ratio * zoom));
  21514. canvas.zoom(newZoom, mid);
  21515. Event.stopEvent(e, true);
  21516. }
  21517. function end(e) {
  21518. recognizer.off('pinchmove', update);
  21519. recognizer.off('pinchend', end);
  21520. recognizer.off('pinchcancel', end);
  21521. recognizer.reset(true);
  21522. log('canvas', 'zoom end');
  21523. }
  21524. recognizer.on('pinchmove', update);
  21525. recognizer.on('pinchend', end);
  21526. recognizer.on('pinchcancel', end);
  21527. }
  21528. recognizer.on('panstart', startGrab);
  21529. recognizer.on('press', startGrab);
  21530. recognizer.on('pinchstart', startZoom);
  21531. }
  21532. if (dragging) {
  21533. // simulate hover during dragging
  21534. eventBus.on('drag.move', function(event) {
  21535. var position = Event.toPoint(event.originalEvent);
  21536. var node = document.elementFromPoint(position.x, position.y),
  21537. gfx = getGfx(node),
  21538. element = gfx && elementRegistry.get(gfx);
  21539. if (element !== event.hover) {
  21540. if (event.hover) {
  21541. dragging.out(event);
  21542. }
  21543. if (element) {
  21544. dragging.hover({ element: element, gfx: gfx });
  21545. event.hover = element;
  21546. event.hoverGfx = gfx;
  21547. }
  21548. }
  21549. });
  21550. }
  21551. if (contextPad) {
  21552. eventBus.on('contextPad.create', function(event) {
  21553. var node = event.pad.html;
  21554. // touch recognizer
  21555. var padRecognizer = createTouchRecognizer(node);
  21556. padRecognizer.on('panstart', function(event) {
  21557. log('context-pad', 'panstart', event);
  21558. contextPad.trigger('dragstart', event, true);
  21559. });
  21560. padRecognizer.on('press', function(event) {
  21561. log('context-pad', 'press', event);
  21562. contextPad.trigger('dragstart', event, true);
  21563. });
  21564. padRecognizer.on('tap', function(event) {
  21565. log('context-pad', 'tap', event);
  21566. contextPad.trigger('click', event);
  21567. });
  21568. });
  21569. }
  21570. if (palette) {
  21571. eventBus.on('palette.create', function(event) {
  21572. var node = event.html;
  21573. // touch recognizer
  21574. var padRecognizer = createTouchRecognizer(node);
  21575. padRecognizer.on('panstart', function(event) {
  21576. log('palette', 'panstart', event);
  21577. palette.trigger('dragstart', event, true);
  21578. });
  21579. padRecognizer.on('press', function(event) {
  21580. log('palette', 'press', event);
  21581. palette.trigger('dragstart', event, true);
  21582. });
  21583. padRecognizer.on('tap', function(event) {
  21584. log('palette', 'tap', event);
  21585. palette.trigger('click', event);
  21586. });
  21587. });
  21588. }
  21589. eventBus.on('canvas.init', function(event) {
  21590. initEvents(event.svg.node);
  21591. });
  21592. }
  21593. TouchInteractionEvents.$inject = [
  21594. 'injector',
  21595. 'canvas',
  21596. 'eventBus',
  21597. 'elementRegistry',
  21598. 'interactionEvents',
  21599. 'touchFix'
  21600. ];
  21601. module.exports = TouchInteractionEvents;
  21602. },{"187":187,"198":198,"200":200,"218":218,"354":354,"357":357}],171:[function(_dereq_,module,exports){
  21603. module.exports = {
  21604. __depends__: [ _dereq_(108) ],
  21605. __init__: [ 'touchInteractionEvents' ],
  21606. touchInteractionEvents: [ 'type', _dereq_(170) ],
  21607. touchFix: [ 'type', _dereq_(169) ]
  21608. };
  21609. },{"108":108,"169":169,"170":170}],172:[function(_dereq_,module,exports){
  21610. 'use strict';
  21611. var getMid = _dereq_(174).getMid;
  21612. /**
  21613. * A base connection layouter implementation
  21614. * that layouts the connection by directly connecting
  21615. * mid(source) + mid(target).
  21616. */
  21617. function BaseLayouter() {}
  21618. module.exports = BaseLayouter;
  21619. /**
  21620. * Return the new layouted waypoints for the given connection.
  21621. *
  21622. * @param {djs.model.Connection} connection
  21623. * @param {Object} hints
  21624. * @param {Boolean} [hints.movedStart=false]
  21625. * @param {Boolean} [hints.movedEnd=false]
  21626. *
  21627. * @return {Array<Point>} the layouted connection waypoints
  21628. */
  21629. BaseLayouter.prototype.layoutConnection = function(connection, hints) {
  21630. return [
  21631. getMid(connection.source),
  21632. getMid(connection.target)
  21633. ];
  21634. };
  21635. },{"174":174}],173:[function(_dereq_,module,exports){
  21636. 'use strict';
  21637. var assign = _dereq_(339);
  21638. var LayoutUtil = _dereq_(174);
  21639. function dockingToPoint(docking) {
  21640. // use the dockings actual point and
  21641. // retain the original docking
  21642. return assign({ original: docking.point.original || docking.point }, docking.actual);
  21643. }
  21644. /**
  21645. * A {@link ConnectionDocking} that crops connection waypoints based on
  21646. * the path(s) of the connection source and target.
  21647. *
  21648. * @param {djs.core.ElementRegistry} elementRegistry
  21649. */
  21650. function CroppingConnectionDocking(elementRegistry, renderer) {
  21651. this._elementRegistry = elementRegistry;
  21652. this._renderer = renderer;
  21653. }
  21654. CroppingConnectionDocking.$inject = [ 'elementRegistry', 'renderer' ];
  21655. module.exports = CroppingConnectionDocking;
  21656. /**
  21657. * @inheritDoc ConnectionDocking#getCroppedWaypoints
  21658. */
  21659. CroppingConnectionDocking.prototype.getCroppedWaypoints = function(connection, source, target) {
  21660. source = source || connection.source;
  21661. target = target || connection.target;
  21662. var sourceDocking = this.getDockingPoint(connection, source, true),
  21663. targetDocking = this.getDockingPoint(connection, target);
  21664. var croppedWaypoints = connection.waypoints.slice(sourceDocking.idx + 1, targetDocking.idx);
  21665. croppedWaypoints.unshift(dockingToPoint(sourceDocking));
  21666. croppedWaypoints.push(dockingToPoint(targetDocking));
  21667. return croppedWaypoints;
  21668. };
  21669. /**
  21670. * Return the connection docking point on the specified shape
  21671. *
  21672. * @inheritDoc ConnectionDocking#getDockingPoint
  21673. */
  21674. CroppingConnectionDocking.prototype.getDockingPoint = function(connection, shape, dockStart) {
  21675. var waypoints = connection.waypoints,
  21676. dockingIdx,
  21677. dockingPoint,
  21678. croppedPoint;
  21679. dockingIdx = dockStart ? 0 : waypoints.length - 1;
  21680. dockingPoint = waypoints[dockingIdx];
  21681. croppedPoint = this._getIntersection(shape, connection, dockStart);
  21682. return {
  21683. point: dockingPoint,
  21684. actual: croppedPoint || dockingPoint,
  21685. idx: dockingIdx
  21686. };
  21687. };
  21688. ////// helper methods ///////////////////////////////////////////////////
  21689. CroppingConnectionDocking.prototype._getIntersection = function(shape, connection, takeFirst) {
  21690. var shapePath = this._getShapePath(shape),
  21691. connectionPath = this._getConnectionPath(connection);
  21692. return LayoutUtil.getElementLineIntersection(shapePath, connectionPath, takeFirst);
  21693. };
  21694. CroppingConnectionDocking.prototype._getConnectionPath = function(connection) {
  21695. return this._renderer.getConnectionPath(connection);
  21696. };
  21697. CroppingConnectionDocking.prototype._getShapePath = function(shape) {
  21698. return this._renderer.getShapePath(shape);
  21699. };
  21700. CroppingConnectionDocking.prototype._getGfx = function(element) {
  21701. return this._elementRegistry.getGraphics(element);
  21702. };
  21703. },{"174":174,"339":339}],174:[function(_dereq_,module,exports){
  21704. 'use strict';
  21705. var isArray = _dereq_(330),
  21706. isObject = _dereq_(334),
  21707. sortBy = _dereq_(225);
  21708. var Snap = _dereq_(200);
  21709. var ALIGNED_THRESHOLD = 2;
  21710. /**
  21711. * Returns whether two points are in a horizontal or vertical line.
  21712. *
  21713. * @param {Point} a
  21714. * @param {Point} b
  21715. *
  21716. * @return {String|Boolean} returns false if the points are not
  21717. * aligned or 'h|v' if they are aligned
  21718. * horizontally / vertically.
  21719. */
  21720. function pointsAligned(a, b) {
  21721. if (Math.abs(a.x - b.x) <= ALIGNED_THRESHOLD) {
  21722. return 'h';
  21723. }
  21724. if (Math.abs(a.y - b.y) <= ALIGNED_THRESHOLD) {
  21725. return 'v';
  21726. }
  21727. return false;
  21728. }
  21729. module.exports.pointsAligned = pointsAligned;
  21730. function roundPoint(point) {
  21731. return {
  21732. x: Math.round(point.x),
  21733. y: Math.round(point.y)
  21734. };
  21735. }
  21736. module.exports.roundPoint = roundPoint;
  21737. function pointsEqual(a, b) {
  21738. return a.x === b.x && a.y === b.y;
  21739. }
  21740. module.exports.pointsEqual = pointsEqual;
  21741. function pointDistance(a, b) {
  21742. return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
  21743. }
  21744. module.exports.pointDistance = pointDistance;
  21745. /**
  21746. * Convert the given bounds to a { top, left, bottom, right } descriptor.
  21747. *
  21748. * @param {Bounds|Point} bounds
  21749. *
  21750. * @return {Object}
  21751. */
  21752. function asTRBL(bounds) {
  21753. return {
  21754. top: bounds.y,
  21755. right: bounds.x + (bounds.width || 0),
  21756. bottom: bounds.y + (bounds.height || 0),
  21757. left: bounds.x
  21758. };
  21759. }
  21760. module.exports.asTRBL = asTRBL;
  21761. /**
  21762. * Get the mid of the given bounds or point.
  21763. *
  21764. * @param {Bounds|Point} bounds
  21765. *
  21766. * @return {Point}
  21767. */
  21768. function getMid(bounds) {
  21769. return roundPoint({
  21770. x: bounds.x + (bounds.width || 0) / 2,
  21771. y: bounds.y + (bounds.height || 0) / 2
  21772. });
  21773. }
  21774. module.exports.getMid = getMid;
  21775. ////// orientation utils //////////////////////////////
  21776. /**
  21777. * Get orientation of the given rectangle with respect to
  21778. * the reference rectangle.
  21779. *
  21780. * A padding (positive or negative) may be passed to influence
  21781. * horizontal / vertical orientation and intersection.
  21782. *
  21783. * @param {Bounds} rect
  21784. * @param {Bounds} reference
  21785. * @param {Point|Number} padding
  21786. *
  21787. * @return {String} the orientation; one of top, top-left, left, ..., bottom, right or intersect.
  21788. */
  21789. function getOrientation(rect, reference, padding) {
  21790. padding = padding || 0;
  21791. // make sure we can use an object, too
  21792. // for individual { x, y } padding
  21793. if (!isObject(padding)) {
  21794. padding = { x: padding, y: padding };
  21795. }
  21796. var rectOrientation = asTRBL(rect),
  21797. referenceOrientation = asTRBL(reference);
  21798. var top = rectOrientation.bottom + padding.y <= referenceOrientation.top,
  21799. right = rectOrientation.left - padding.x >= referenceOrientation.right,
  21800. bottom = rectOrientation.top - padding.y >= referenceOrientation.bottom,
  21801. left = rectOrientation.right + padding.x <= referenceOrientation.left;
  21802. var vertical = top ? 'top' : (bottom ? 'bottom' : null),
  21803. horizontal = left ? 'left' : (right ? 'right' : null);
  21804. if (horizontal && vertical) {
  21805. return vertical + '-' + horizontal;
  21806. } else {
  21807. return horizontal || vertical || 'intersect';
  21808. }
  21809. }
  21810. module.exports.getOrientation = getOrientation;
  21811. function hasAnyOrientation(rect, reference, pointDistance, locations) {
  21812. if (isArray(pointDistance)) {
  21813. locations = pointDistance;
  21814. pointDistance = 0;
  21815. }
  21816. var orientation = getOrientation(rect, reference, pointDistance);
  21817. return locations.indexOf(orientation) !== -1;
  21818. }
  21819. module.exports.hasAnyOrientation = hasAnyOrientation;
  21820. ////// intersection utils //////////////////////////////
  21821. function getElementLineIntersection(elementPath, linePath, cropStart) {
  21822. var intersections = getIntersections(elementPath, linePath);
  21823. // recognize intersections
  21824. // only one -> choose
  21825. // two close together -> choose first
  21826. // two or more distinct -> pull out appropriate one
  21827. // none -> ok (fallback to point itself)
  21828. if (intersections.length === 1) {
  21829. return roundPoint(intersections[0]);
  21830. } else if (intersections.length === 2 && pointDistance(intersections[0], intersections[1]) < 1) {
  21831. return roundPoint(intersections[0]);
  21832. } else if (intersections.length > 1) {
  21833. // sort by intersections based on connection segment +
  21834. // distance from start
  21835. intersections = sortBy(intersections, function(i) {
  21836. var distance = Math.floor(i.t2 * 100) || 1;
  21837. distance = 100 - distance;
  21838. distance = (distance < 10 ? '0' : '') + distance;
  21839. // create a sort string that makes sure we sort
  21840. // line segment ASC + line segment position DESC (for cropStart)
  21841. // line segment ASC + line segment position ASC (for cropEnd)
  21842. return i.segment2 + '#' + distance;
  21843. });
  21844. return roundPoint(intersections[cropStart ? 0 : intersections.length - 1]);
  21845. }
  21846. return null;
  21847. }
  21848. module.exports.getElementLineIntersection = getElementLineIntersection;
  21849. function getIntersections(a, b) {
  21850. return Snap.path.intersection(a, b);
  21851. }
  21852. module.exports.getIntersections = getIntersections;
  21853. },{"200":200,"225":225,"330":330,"334":334}],175:[function(_dereq_,module,exports){
  21854. 'use strict';
  21855. var isArray = _dereq_(330),
  21856. find = _dereq_(217),
  21857. without = _dereq_(212),
  21858. assign = _dereq_(339);
  21859. var LayoutUtil = _dereq_(174),
  21860. Geometry = _dereq_(188);
  21861. var getOrientation = LayoutUtil.getOrientation,
  21862. getMid = LayoutUtil.getMid,
  21863. pointsAligned = LayoutUtil.pointsAligned;
  21864. var pointInRect = Geometry.pointInRect,
  21865. pointDistance = Geometry.pointDistance;
  21866. var INTERSECTION_THRESHOLD = 20,
  21867. ORIENTATION_THRESHOLD = {
  21868. 'h:h': 20,
  21869. 'v:v': 20,
  21870. 'h:v': -10,
  21871. 'v:h': -10
  21872. };
  21873. /**
  21874. * Returns the mid points for a manhattan connection between two points.
  21875. *
  21876. * @example
  21877. *
  21878. * [a]----[x]
  21879. * |
  21880. * [x]----[b]
  21881. *
  21882. * @example
  21883. *
  21884. * [a]----[x]
  21885. * |
  21886. * [b]
  21887. *
  21888. * @param {Point} a
  21889. * @param {Point} b
  21890. * @param {String} directions
  21891. *
  21892. * @return {Array<Point>}
  21893. */
  21894. module.exports.getBendpoints = function(a, b, directions) {
  21895. directions = directions || 'h:h';
  21896. var xmid, ymid;
  21897. // one point, next to a
  21898. if (directions === 'h:v') {
  21899. return [ { x: b.x, y: a.y } ];
  21900. } else
  21901. // one point, above a
  21902. if (directions === 'v:h') {
  21903. return [ { x: a.x, y: b.y } ];
  21904. } else
  21905. // vertical edge xmid
  21906. if (directions === 'h:h') {
  21907. xmid = Math.round((b.x - a.x) / 2 + a.x);
  21908. return [
  21909. { x: xmid, y: a.y },
  21910. { x: xmid, y: b.y }
  21911. ];
  21912. } else
  21913. // horizontal edge ymid
  21914. if (directions === 'v:v') {
  21915. ymid = Math.round((b.y - a.y) / 2 + a.y);
  21916. return [
  21917. { x: a.x, y: ymid },
  21918. { x: b.x, y: ymid }
  21919. ];
  21920. } else {
  21921. throw new Error(
  21922. 'unknown directions: <' + directions + '>: ' +
  21923. 'directions must be specified as {a direction}:{b direction} (direction in h|v)');
  21924. }
  21925. };
  21926. /**
  21927. * Create a connection between the two points according
  21928. * to the manhattan layout (only horizontal and vertical) edges.
  21929. *
  21930. * @param {Point} a
  21931. * @param {Point} b
  21932. *
  21933. * @param {String} [directions='h:h'] specifies manhattan directions for each point as {adirection}:{bdirection}.
  21934. A directionfor a point is either `h` (horizontal) or `v` (vertical)
  21935. *
  21936. * @return {Array<Point>}
  21937. */
  21938. module.exports.connectPoints = function(a, b, directions) {
  21939. var points = [];
  21940. if (!pointsAligned(a, b)) {
  21941. points = this.getBendpoints(a, b, directions);
  21942. }
  21943. points.unshift(a);
  21944. points.push(b);
  21945. return points;
  21946. };
  21947. /**
  21948. * Connect two rectangles using a manhattan layouted connection.
  21949. *
  21950. * @param {Bounds} source source rectangle
  21951. * @param {Bounds} target target rectangle
  21952. * @param {Point} [start] source docking
  21953. * @param {Point} [end] target docking
  21954. *
  21955. * @param {Object} [hints]
  21956. * @param {Array<String>} [hints.preferredLayouts]
  21957. *
  21958. * @return {Array<Point>} connection points
  21959. */
  21960. module.exports.connectRectangles = function(source, target, start, end, hints) {
  21961. var preferredLayouts = hints && hints.preferredLayouts || [];
  21962. var preferredLayout = without(preferredLayouts, 'straight')[0] || 'h:h';
  21963. var threshold = ORIENTATION_THRESHOLD[preferredLayout] || 0;
  21964. var orientation = getOrientation(source, target, threshold);
  21965. var directions = getDirections(orientation, preferredLayout);
  21966. start = start || getMid(source);
  21967. end = end || getMid(target);
  21968. // overlapping elements
  21969. if (!directions) {
  21970. return;
  21971. }
  21972. if (directions === 'h:h') {
  21973. switch (orientation) {
  21974. case 'top-right':
  21975. case 'right':
  21976. case 'bottom-right':
  21977. start = { original: start, x: source.x, y: start.y };
  21978. end = { original: end, x: target.x + target.width, y: end.y };
  21979. break;
  21980. case 'top-left':
  21981. case 'left':
  21982. case 'bottom-left':
  21983. start = { original: start, x: source.x + source.width, y: start.y };
  21984. end = { original: end, x: target.x, y: end.y };
  21985. break;
  21986. }
  21987. }
  21988. if (directions === 'v:v') {
  21989. switch (orientation) {
  21990. case 'top-left':
  21991. case 'top':
  21992. case 'top-right':
  21993. start = { original: start, x: start.x, y: source.y + source.height };
  21994. end = { original: end, x: end.x, y: target.y };
  21995. break;
  21996. case 'bottom-left':
  21997. case 'bottom':
  21998. case 'bottom-right':
  21999. start = { original: start, x: start.x, y: source.y };
  22000. end = { original: end, x: end.x, y: target.y + target.height };
  22001. break;
  22002. }
  22003. }
  22004. return this.connectPoints(start, end, directions);
  22005. };
  22006. /**
  22007. * Repair the connection between two rectangles, of which one has been updated.
  22008. *
  22009. * @param {Bounds} source
  22010. * @param {Bounds} target
  22011. * @param {Point} [start]
  22012. * @param {Point} [end]
  22013. * @param {Array<Point>} waypoints
  22014. * @param {Object} [hints]
  22015. * @param {Array<String>} [hints.preferredLayouts] list of preferred layouts
  22016. * @param {Boolean} [hints.startChanged]
  22017. * @param {Boolean} [hints.endChanged]
  22018. *
  22019. * @return {Array<Point>} repaired waypoints
  22020. */
  22021. module.exports.repairConnection = function(source, target, start, end, waypoints, hints) {
  22022. if (isArray(start)) {
  22023. waypoints = start;
  22024. hints = end;
  22025. start = getMid(source);
  22026. end = getMid(target);
  22027. }
  22028. hints = assign({ preferredLayouts: [] }, hints);
  22029. var preferredLayouts = hints.preferredLayouts,
  22030. layoutStraight = preferredLayouts.indexOf('straight') !== -1,
  22031. repairedWaypoints;
  22032. // just layout non-existing or simple connections
  22033. // attempt to render straight lines, if required
  22034. if (!waypoints || waypoints.length < 3) {
  22035. if (layoutStraight) {
  22036. // attempt to layout a straight line
  22037. repairedWaypoints = this.layoutStraight(source, target, start, end, hints);
  22038. }
  22039. } else {
  22040. // check if we layout from start or end
  22041. if (hints.endChanged) {
  22042. repairedWaypoints = this._repairConnectionSide(target, source, end, waypoints.slice().reverse());
  22043. repairedWaypoints = repairedWaypoints && repairedWaypoints.reverse();
  22044. } else
  22045. if (hints.startChanged) {
  22046. repairedWaypoints = this._repairConnectionSide(source, target, start, waypoints);
  22047. }
  22048. // or whether nothing seems to have changed
  22049. else {
  22050. repairedWaypoints = waypoints;
  22051. }
  22052. }
  22053. // simply reconnect if nothing else worked
  22054. if (!repairedWaypoints) {
  22055. repairedWaypoints = this.connectRectangles(source, target, start, end, hints);
  22056. }
  22057. return repairedWaypoints;
  22058. };
  22059. var max = Math.max,
  22060. min = Math.min;
  22061. function inRange(a, start, end) {
  22062. return a >= start && a <= end;
  22063. }
  22064. module.exports.layoutStraight = function(source, target, start, end, hints) {
  22065. var startX, endX, x,
  22066. startY, endY, y;
  22067. startX = max(source.x + 10, target.x + 10);
  22068. endX = min(source.x + source.width - 10, target.x + target.width - 10);
  22069. if (startX < endX) {
  22070. if (source.width === target.width) {
  22071. if (hints.endChanged && inRange(end.x, startX, endX)) {
  22072. x = end.x;
  22073. } else
  22074. if (inRange(start.x, startX, endX)) {
  22075. x = start.x;
  22076. }
  22077. }
  22078. if (x === undefined) {
  22079. if (source.width < target.width && inRange(start.x, startX, endX)) {
  22080. x = start.x;
  22081. } else
  22082. if (source.width > target.width && inRange(end.x, startX, endX)) {
  22083. x = end.x;
  22084. } else {
  22085. x = (startX + endX) / 2;
  22086. }
  22087. }
  22088. }
  22089. startY = max(source.y + 10, target.y + 10);
  22090. endY = min(source.y + source.height - 10, target.y + target.height - 10);
  22091. if (startY < endY) {
  22092. if (source.height === target.height) {
  22093. if (hints.endChanged && inRange(end.y, startY, endY)) {
  22094. y = end.y;
  22095. } else
  22096. if (inRange(start.y, startY, endY)) {
  22097. y = start.y;
  22098. }
  22099. }
  22100. if (y === undefined) {
  22101. if (source.height <= target.height && inRange(start.y, startY, endY)) {
  22102. y = start.y;
  22103. } else
  22104. if (target.height <= source.height && inRange(end.y, startY, endY)) {
  22105. y = end.y;
  22106. } else {
  22107. y = (startY + endY) / 2;
  22108. }
  22109. }
  22110. }
  22111. // cannot layout straight
  22112. if (x === undefined && y === undefined) {
  22113. return null;
  22114. }
  22115. return [
  22116. {
  22117. x: x !== undefined ? x : start.x,
  22118. y: y !== undefined ? y : start.y
  22119. },
  22120. {
  22121. x: x !== undefined ? x : end.x,
  22122. y: y !== undefined ? y : end.y
  22123. }
  22124. ];
  22125. };
  22126. /**
  22127. * Repair a connection from one side that moved.
  22128. *
  22129. * @param {Bounds} moved
  22130. * @param {Bounds} other
  22131. * @param {Point} newDocking
  22132. * @param {Array<Point>} points originalPoints from moved to other
  22133. *
  22134. * @return {Array<Point>} the repaired points between the two rectangles
  22135. */
  22136. module.exports._repairConnectionSide = function(moved, other, newDocking, points) {
  22137. function needsRelayout(moved, other, points) {
  22138. if (points.length < 3) {
  22139. return true;
  22140. }
  22141. if (points.length > 4) {
  22142. return false;
  22143. }
  22144. // relayout if two points overlap
  22145. // this is most likely due to
  22146. return !!find(points, function(p, idx) {
  22147. var q = points[idx - 1];
  22148. return q && pointDistance(p, q) < 3;
  22149. });
  22150. }
  22151. function repairBendpoint(candidate, oldPeer, newPeer) {
  22152. var alignment = pointsAligned(oldPeer, candidate);
  22153. switch (alignment) {
  22154. case 'v':
  22155. // repair vertical alignment
  22156. return { x: candidate.x, y: newPeer.y };
  22157. case 'h':
  22158. // repair horizontal alignment
  22159. return { x: newPeer.x, y: candidate.y };
  22160. }
  22161. return { x: candidate.x, y: candidate. y };
  22162. }
  22163. function removeOverlapping(points, a, b) {
  22164. var i;
  22165. for (i = points.length - 2; i !== 0; i--) {
  22166. // intersects (?) break, remove all bendpoints up to this one and relayout
  22167. if (pointInRect(points[i], a, INTERSECTION_THRESHOLD) ||
  22168. pointInRect(points[i], b, INTERSECTION_THRESHOLD)) {
  22169. // return sliced old connection
  22170. return points.slice(i);
  22171. }
  22172. }
  22173. return points;
  22174. }
  22175. // (0) only repair what has layoutable bendpoints
  22176. // (1) if only one bendpoint and on shape moved onto other shapes axis
  22177. // (horizontally / vertically), relayout
  22178. if (needsRelayout(moved, other, points)) {
  22179. return null;
  22180. }
  22181. var oldDocking = points[0],
  22182. newPoints = points.slice(),
  22183. slicedPoints;
  22184. // (2) repair only last line segment and only if it was layouted before
  22185. newPoints[0] = newDocking;
  22186. newPoints[1] = repairBendpoint(newPoints[1], oldDocking, newDocking);
  22187. // (3) if shape intersects with any bendpoint after repair,
  22188. // remove all segments up to this bendpoint and repair from there
  22189. slicedPoints = removeOverlapping(newPoints, moved, other);
  22190. if (slicedPoints !== newPoints) {
  22191. return this._repairConnectionSide(moved, other, newDocking, slicedPoints);
  22192. }
  22193. return newPoints;
  22194. };
  22195. /**
  22196. * Returns the manhattan directions connecting two rectangles
  22197. * with the given orientation.
  22198. *
  22199. * @example
  22200. *
  22201. * getDirections('top'); // -> 'v:v'
  22202. *
  22203. * getDirections('top-right', 'v:h'); // -> 'v:h'
  22204. * getDirections('top-right', 'h:h'); // -> 'h:h'
  22205. *
  22206. *
  22207. * @param {String} orientation
  22208. * @param {String} defaultLayout
  22209. *
  22210. * @return {String}
  22211. */
  22212. function getDirections(orientation, defaultLayout) {
  22213. switch (orientation) {
  22214. case 'intersect':
  22215. return null;
  22216. case 'top':
  22217. case 'bottom':
  22218. return 'v:v';
  22219. case 'left':
  22220. case 'right':
  22221. return 'h:h';
  22222. // 'top-left'
  22223. // 'top-right'
  22224. // 'bottom-left'
  22225. // 'bottom-right'
  22226. default:
  22227. return defaultLayout;
  22228. }
  22229. }
  22230. },{"174":174,"188":188,"212":212,"217":217,"330":330,"339":339}],176:[function(_dereq_,module,exports){
  22231. 'use strict';
  22232. var assign = _dereq_(339),
  22233. inherits = _dereq_(207);
  22234. var Refs = _dereq_(369);
  22235. var parentRefs = new Refs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
  22236. labelRefs = new Refs({ name: 'label', enumerable: true }, { name: 'labelTarget' }),
  22237. attacherRefs = new Refs({ name: 'attachers', collection: true }, { name: 'host' }),
  22238. outgoingRefs = new Refs({ name: 'outgoing', collection: true }, { name: 'source' }),
  22239. incomingRefs = new Refs({ name: 'incoming', collection: true }, { name: 'target' });
  22240. /**
  22241. * @namespace djs.model
  22242. */
  22243. /**
  22244. * @memberOf djs.model
  22245. */
  22246. /**
  22247. * The basic graphical representation
  22248. *
  22249. * @class
  22250. *
  22251. * @abstract
  22252. */
  22253. function Base() {
  22254. /**
  22255. * The object that backs up the shape
  22256. *
  22257. * @name Base#businessObject
  22258. * @type Object
  22259. */
  22260. Object.defineProperty(this, 'businessObject', {
  22261. writable: true
  22262. });
  22263. /**
  22264. * The parent shape
  22265. *
  22266. * @name Base#parent
  22267. * @type Shape
  22268. */
  22269. parentRefs.bind(this, 'parent');
  22270. /**
  22271. * @name Base#label
  22272. * @type Label
  22273. */
  22274. labelRefs.bind(this, 'label');
  22275. /**
  22276. * The list of outgoing connections
  22277. *
  22278. * @name Base#outgoing
  22279. * @type Array<Connection>
  22280. */
  22281. outgoingRefs.bind(this, 'outgoing');
  22282. /**
  22283. * The list of outgoing connections
  22284. *
  22285. * @name Base#incoming
  22286. * @type Array<Connection>
  22287. */
  22288. incomingRefs.bind(this, 'incoming');
  22289. }
  22290. /**
  22291. * A graphical object
  22292. *
  22293. * @class
  22294. * @constructor
  22295. *
  22296. * @extends Base
  22297. */
  22298. function Shape() {
  22299. Base.call(this);
  22300. /**
  22301. * The list of children
  22302. *
  22303. * @name Shape#children
  22304. * @type Array<Base>
  22305. */
  22306. parentRefs.bind(this, 'children');
  22307. /**
  22308. * @name Shape#host
  22309. * @type Shape
  22310. */
  22311. attacherRefs.bind(this, 'host');
  22312. /**
  22313. * @name Shape#attachers
  22314. * @type Shape
  22315. */
  22316. attacherRefs.bind(this, 'attachers');
  22317. }
  22318. inherits(Shape, Base);
  22319. /**
  22320. * A root graphical object
  22321. *
  22322. * @class
  22323. * @constructor
  22324. *
  22325. * @extends Shape
  22326. */
  22327. function Root() {
  22328. Shape.call(this);
  22329. }
  22330. inherits(Root, Shape);
  22331. /**
  22332. * A label for an element
  22333. *
  22334. * @class
  22335. * @constructor
  22336. *
  22337. * @extends Shape
  22338. */
  22339. function Label() {
  22340. Shape.call(this);
  22341. /**
  22342. * The labeled element
  22343. *
  22344. * @name Label#labelTarget
  22345. * @type Base
  22346. */
  22347. labelRefs.bind(this, 'labelTarget');
  22348. }
  22349. inherits(Label, Shape);
  22350. /**
  22351. * A connection between two elements
  22352. *
  22353. * @class
  22354. * @constructor
  22355. *
  22356. * @extends Base
  22357. */
  22358. function Connection() {
  22359. Base.call(this);
  22360. /**
  22361. * The element this connection originates from
  22362. *
  22363. * @name Connection#source
  22364. * @type Base
  22365. */
  22366. outgoingRefs.bind(this, 'source');
  22367. /**
  22368. * The element this connection points to
  22369. *
  22370. * @name Connection#target
  22371. * @type Base
  22372. */
  22373. incomingRefs.bind(this, 'target');
  22374. }
  22375. inherits(Connection, Base);
  22376. var types = {
  22377. connection: Connection,
  22378. shape: Shape,
  22379. label: Label,
  22380. root: Root
  22381. };
  22382. /**
  22383. * Creates a new model element of the specified type
  22384. *
  22385. * @method create
  22386. *
  22387. * @example
  22388. *
  22389. * var shape1 = Model.create('shape', { x: 10, y: 10, width: 100, height: 100 });
  22390. * var shape2 = Model.create('shape', { x: 210, y: 210, width: 100, height: 100 });
  22391. *
  22392. * var connection = Model.create('connection', { waypoints: [ { x: 110, y: 55 }, {x: 210, y: 55 } ] });
  22393. *
  22394. * @param {String} type lower-cased model name
  22395. * @param {Object} attrs attributes to initialize the new model instance with
  22396. *
  22397. * @return {Base} the new model instance
  22398. */
  22399. module.exports.create = function(type, attrs) {
  22400. var Type = types[type];
  22401. if (!Type) {
  22402. throw new Error('unknown type: <' + type + '>');
  22403. }
  22404. return assign(new Type(), attrs);
  22405. };
  22406. module.exports.Base = Base;
  22407. module.exports.Root = Root;
  22408. module.exports.Shape = Shape;
  22409. module.exports.Connection = Connection;
  22410. module.exports.Label = Label;
  22411. },{"207":207,"339":339,"369":369}],177:[function(_dereq_,module,exports){
  22412. 'use strict';
  22413. var Cursor = _dereq_(185),
  22414. ClickTrap = _dereq_(183),
  22415. domEvent = _dereq_(357),
  22416. Event = _dereq_(187);
  22417. function substract(p1, p2) {
  22418. return {
  22419. x: p1.x - p2.x,
  22420. y: p1.y - p2.y
  22421. };
  22422. }
  22423. function length(point) {
  22424. return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
  22425. }
  22426. var THRESHOLD = 15;
  22427. function MoveCanvas(eventBus, canvas) {
  22428. var container = canvas._container,
  22429. context;
  22430. function handleMove(event) {
  22431. var start = context.start,
  22432. position = Event.toPoint(event),
  22433. delta = substract(position, start);
  22434. if (!context.dragging && length(delta) > THRESHOLD) {
  22435. context.dragging = true;
  22436. // prevent mouse click in this
  22437. // interaction sequence
  22438. ClickTrap.install();
  22439. Cursor.set('move');
  22440. }
  22441. if (context.dragging) {
  22442. var lastPosition = context.last || context.start;
  22443. delta = substract(position, lastPosition);
  22444. canvas.scroll({
  22445. dx: delta.x,
  22446. dy: delta.y
  22447. });
  22448. context.last = position;
  22449. }
  22450. // prevent select
  22451. event.preventDefault();
  22452. }
  22453. function handleEnd(event) {
  22454. domEvent.unbind(document, 'mousemove', handleMove);
  22455. domEvent.unbind(document, 'mouseup', handleEnd);
  22456. context = null;
  22457. Cursor.unset();
  22458. // prevent select
  22459. Event.stopEvent(event);
  22460. }
  22461. function handleStart(event) {
  22462. // reject non-left left mouse button or modifier key
  22463. if (event.button || event.ctrlKey || event.shiftKey || event.altKey) {
  22464. return;
  22465. }
  22466. context = {
  22467. start: Event.toPoint(event)
  22468. };
  22469. domEvent.bind(document, 'mousemove', handleMove);
  22470. domEvent.bind(document, 'mouseup', handleEnd);
  22471. // prevent select
  22472. Event.stopEvent(event);
  22473. }
  22474. domEvent.bind(container, 'mousedown', handleStart);
  22475. }
  22476. MoveCanvas.$inject = [ 'eventBus', 'canvas' ];
  22477. module.exports = MoveCanvas;
  22478. },{"183":183,"185":185,"187":187,"357":357}],178:[function(_dereq_,module,exports){
  22479. module.exports = {
  22480. __init__: [ 'moveCanvas' ],
  22481. moveCanvas: [ 'type', _dereq_(177) ]
  22482. };
  22483. },{"177":177}],179:[function(_dereq_,module,exports){
  22484. module.exports = {
  22485. __depends__: [ _dereq_(171) ]
  22486. };
  22487. },{"171":171}],180:[function(_dereq_,module,exports){
  22488. 'use strict';
  22489. var domEvent = _dereq_(357);
  22490. var hasPrimaryModifier = _dereq_(193).hasPrimaryModifier,
  22491. hasSecondaryModifier = _dereq_(193).hasSecondaryModifier;
  22492. var isMac = _dereq_(194).isMac;
  22493. var getStepRange = _dereq_(181).getStepRange,
  22494. cap = _dereq_(181).cap;
  22495. var log10 = _dereq_(192).log10;
  22496. var RANGE = { min: 0.2, max: 4 },
  22497. NUM_STEPS = 10;
  22498. /**
  22499. * An implementation of zooming and scrolling within the {@link Canvas}.
  22500. *
  22501. * @param {EventBus} eventBus
  22502. * @param {Canvas} canvas
  22503. */
  22504. function ZoomScroll(eventBus, canvas) {
  22505. this._canvas = canvas;
  22506. var self = this;
  22507. eventBus.on('canvas.init', function(e) {
  22508. self._init(canvas._container);
  22509. });
  22510. }
  22511. ZoomScroll.prototype.scroll = function scroll(delta) {
  22512. this._canvas.scroll(delta);
  22513. };
  22514. ZoomScroll.prototype.reset = function reset() {
  22515. this._canvas.zoom('fit-viewport');
  22516. };
  22517. ZoomScroll.prototype.zoom = function zoom(direction, position) {
  22518. var canvas = this._canvas;
  22519. var currentZoom = canvas.zoom();
  22520. var factor = Math.pow(1 + Math.abs(direction) , direction > 0 ? 1 : -1);
  22521. canvas.zoom(cap(RANGE, currentZoom * factor), position);
  22522. };
  22523. /**
  22524. * Zoom along fixed zoom steps
  22525. *
  22526. * @param {Integer} direction zoom direction (1 for zooming in, -1 for out)
  22527. */
  22528. ZoomScroll.prototype.stepZoom = function stepZoom(direction, position) {
  22529. var canvas = this._canvas,
  22530. stepRange = getStepRange(RANGE, NUM_STEPS);
  22531. direction = direction > 0 ? 1 : -1;
  22532. var currentLinearZoomLevel = log10(canvas.zoom());
  22533. // snap to a proximate zoom step
  22534. var newLinearZoomLevel = Math.round(currentLinearZoomLevel / stepRange) * stepRange;
  22535. // increase or decrease one zoom step in the given direction
  22536. newLinearZoomLevel += stepRange * direction;
  22537. // calculate the absolute logarithmic zoom level based on the linear zoom level
  22538. // (e.g. 2 for an absolute x2 zoom)
  22539. var newLogZoomLevel = Math.pow(10, newLinearZoomLevel);
  22540. canvas.zoom(cap(RANGE, newLogZoomLevel), position);
  22541. };
  22542. ZoomScroll.prototype._init = function(element) {
  22543. var self = this;
  22544. domEvent.bind(element, 'wheel', function(event) {
  22545. event.preventDefault();
  22546. // mouse-event: SELECTION_KEY
  22547. // mouse-event: AND_KEY
  22548. var isVerticalScroll = hasPrimaryModifier(event),
  22549. isHorizontalScroll = hasSecondaryModifier(event);
  22550. var factor;
  22551. if (isVerticalScroll || isHorizontalScroll) {
  22552. if (isMac) {
  22553. factor = event.deltaMode === 0 ? 1.25 : 50;
  22554. } else {
  22555. factor = event.deltaMode === 0 ? 1/40 : 1/2;
  22556. }
  22557. var delta = {};
  22558. if (isHorizontalScroll) {
  22559. delta.dx = (factor * (event.deltaX || event.deltaY));
  22560. } else {
  22561. delta.dy = (factor * event.deltaY);
  22562. }
  22563. self.scroll(delta);
  22564. } else {
  22565. factor = (event.deltaMode === 0 ? 1/40 : 1/2);
  22566. var elementRect = element.getBoundingClientRect();
  22567. var offset = {
  22568. x: event.clientX - elementRect.left,
  22569. y: event.clientY - elementRect.top
  22570. };
  22571. // zoom in relative to diagram {x,y} coordinates
  22572. self.zoom(event.deltaY * factor / (-5), offset);
  22573. }
  22574. });
  22575. };
  22576. ZoomScroll.$inject = [ 'eventBus', 'canvas' ];
  22577. module.exports = ZoomScroll;
  22578. },{"181":181,"192":192,"193":193,"194":194,"357":357}],181:[function(_dereq_,module,exports){
  22579. 'use strict';
  22580. var log10 = _dereq_(192).log10;
  22581. /**
  22582. * Get the linear range between two zoom steps based on the
  22583. * total number of zoom steps (defined as NUM_STEPS)
  22584. */
  22585. module.exports.getStepRange = function(range, steps) {
  22586. var minLinearRange = log10(range.min),
  22587. maxLinearRange = log10(range.max);
  22588. var absoluteLinearRange = Math.abs(minLinearRange) + Math.abs(maxLinearRange);
  22589. return absoluteLinearRange / steps;
  22590. };
  22591. module.exports.cap = function(range, scale) {
  22592. return Math.max(range.min, Math.min(range.max, scale));
  22593. };
  22594. },{"192":192}],182:[function(_dereq_,module,exports){
  22595. module.exports = {
  22596. __init__: [ 'zoomScroll' ],
  22597. zoomScroll: [ 'type', _dereq_(180) ]
  22598. };
  22599. },{"180":180}],183:[function(_dereq_,module,exports){
  22600. 'use strict';
  22601. var domEvent = _dereq_(357),
  22602. stopEvent = _dereq_(187).stopEvent;
  22603. function trap(event) {
  22604. stopEvent(event);
  22605. toggle(false);
  22606. }
  22607. function toggle(active) {
  22608. domEvent[active ? 'bind' : 'unbind'](document.body, 'click', trap, true);
  22609. }
  22610. /**
  22611. * Installs a click trap that prevents a ghost click following a dragging operation.
  22612. *
  22613. * @return {Function} a function to immediately remove the installed trap.
  22614. */
  22615. function install() {
  22616. toggle(true);
  22617. return function() {
  22618. toggle(false);
  22619. };
  22620. }
  22621. module.exports.install = install;
  22622. },{"187":187,"357":357}],184:[function(_dereq_,module,exports){
  22623. 'use strict';
  22624. /**
  22625. * Failsafe remove an element from a collection
  22626. *
  22627. * @param {Array<Object>} [collection]
  22628. * @param {Object} [element]
  22629. *
  22630. * @return {Object} the element that got removed or undefined
  22631. */
  22632. module.exports.remove = function(collection, element) {
  22633. if (!collection || !element) {
  22634. return;
  22635. }
  22636. var idx = collection.indexOf(element);
  22637. if (idx === -1) {
  22638. return;
  22639. }
  22640. collection.splice(idx, 1);
  22641. return element;
  22642. };
  22643. /**
  22644. * Fail save add an element to the given connection, ensuring
  22645. * it does not yet exist.
  22646. *
  22647. * @param {Array<Object>} collection
  22648. * @param {Object} element
  22649. * @param {Number} idx
  22650. */
  22651. module.exports.add = function(collection, element, idx) {
  22652. if (!collection || !element) {
  22653. return;
  22654. }
  22655. if (isNaN(idx)) {
  22656. idx = -1;
  22657. }
  22658. var currentIdx = collection.indexOf(element);
  22659. if (currentIdx !== -1) {
  22660. if (currentIdx === idx) {
  22661. // nothing to do, position has not changed
  22662. return;
  22663. } else {
  22664. if (idx !== -1) {
  22665. // remove from current position
  22666. collection.splice(currentIdx, 1);
  22667. } else {
  22668. // already exists in collection
  22669. return;
  22670. }
  22671. }
  22672. }
  22673. if (idx !== -1) {
  22674. // insert at specified position
  22675. collection.splice(idx, 0, element);
  22676. } else {
  22677. // push to end
  22678. collection.push(element);
  22679. }
  22680. };
  22681. /**
  22682. * Fail get the index of an element in a collection.
  22683. *
  22684. * @param {Array<Object>} collection
  22685. * @param {Object} element
  22686. *
  22687. * @return {Number} the index or -1 if collection or element do
  22688. * not exist or the element is not contained.
  22689. */
  22690. module.exports.indexOf = function(collection, element) {
  22691. if (!collection || !element) {
  22692. return -1;
  22693. }
  22694. return collection.indexOf(element);
  22695. };
  22696. },{}],185:[function(_dereq_,module,exports){
  22697. 'use strict';
  22698. var domClasses = _dereq_(352);
  22699. var CURSOR_CLS_PATTERN = /^djs-cursor-.*$/;
  22700. module.exports.set = function(mode) {
  22701. var classes = domClasses(document.body);
  22702. classes.removeMatching(CURSOR_CLS_PATTERN);
  22703. if (mode) {
  22704. classes.add('djs-cursor-' + mode);
  22705. }
  22706. };
  22707. module.exports.unset = function() {
  22708. this.set(null);
  22709. };
  22710. },{"352":352}],186:[function(_dereq_,module,exports){
  22711. 'use strict';
  22712. var isArray = _dereq_(330),
  22713. isNumber = _dereq_(333),
  22714. groupBy = _dereq_(219),
  22715. forEach = _dereq_(218);
  22716. /**
  22717. * Adds an element to a collection and returns true if the
  22718. * element was added.
  22719. *
  22720. * @param {Array<Object>} elements
  22721. * @param {Object} e
  22722. * @param {Boolean} unique
  22723. */
  22724. function add(elements, e, unique) {
  22725. var canAdd = !unique || elements.indexOf(e) === -1;
  22726. if (canAdd) {
  22727. elements.push(e);
  22728. }
  22729. return canAdd;
  22730. }
  22731. function eachElement(elements, fn, depth) {
  22732. depth = depth || 0;
  22733. forEach(elements, function(s, i) {
  22734. var filter = fn(s, i, depth);
  22735. if (isArray(filter) && filter.length) {
  22736. eachElement(filter, fn, depth + 1);
  22737. }
  22738. });
  22739. }
  22740. /**
  22741. * Collects self + child elements up to a given depth from a list of elements.
  22742. *
  22743. * @param {Array<djs.model.Base>} elements the elements to select the children from
  22744. * @param {Boolean} unique whether to return a unique result set (no duplicates)
  22745. * @param {Number} maxDepth the depth to search through or -1 for infinite
  22746. *
  22747. * @return {Array<djs.model.Base>} found elements
  22748. */
  22749. function selfAndChildren(elements, unique, maxDepth) {
  22750. var result = [],
  22751. processedChildren = [];
  22752. eachElement(elements, function(element, i, depth) {
  22753. add(result, element, unique);
  22754. var children = element.children;
  22755. // max traversal depth not reached yet
  22756. if (maxDepth === -1 || depth < maxDepth) {
  22757. // children exist && children not yet processed
  22758. if (children && add(processedChildren, children, unique)) {
  22759. return children;
  22760. }
  22761. }
  22762. });
  22763. return result;
  22764. }
  22765. /**
  22766. * Return self + direct children for a number of elements
  22767. *
  22768. * @param {Array<djs.model.Base>} elements to query
  22769. * @param {Boolean} allowDuplicates to allow duplicates in the result set
  22770. *
  22771. * @return {Array<djs.model.Base>} the collected elements
  22772. */
  22773. function selfAndDirectChildren(elements, allowDuplicates) {
  22774. return selfAndChildren(elements, !allowDuplicates, 1);
  22775. }
  22776. /**
  22777. * Return self + ALL children for a number of elements
  22778. *
  22779. * @param {Array<djs.model.Base>} elements to query
  22780. * @param {Boolean} allowDuplicates to allow duplicates in the result set
  22781. *
  22782. * @return {Array<djs.model.Base>} the collected elements
  22783. */
  22784. function selfAndAllChildren(elements, allowDuplicates) {
  22785. return selfAndChildren(elements, !allowDuplicates, -1);
  22786. }
  22787. /**
  22788. * Gets the the closure fo all selected elements,
  22789. * their connections and
  22790. *
  22791. * @param {Array<djs.model.Base>} elements
  22792. * @return {Object} enclosure
  22793. */
  22794. function getClosure(elements) {
  22795. // original elements passed to this function
  22796. var topLevel = groupBy(elements, function(e) { return e.id; });
  22797. var allShapes = {},
  22798. allConnections = {},
  22799. enclosedElements = {},
  22800. enclosedConnections = {};
  22801. function handleConnection(c) {
  22802. if (topLevel[c.source.id] && topLevel[c.target.id]) {
  22803. topLevel[c.id] = c;
  22804. }
  22805. // not enclosed as a child, but maybe logically
  22806. // (connecting two moved elements?)
  22807. if (allShapes[c.source.id] && allShapes[c.target.id]) {
  22808. enclosedConnections[c.id] = enclosedElements[c.id] = c;
  22809. }
  22810. allConnections[c.id] = c;
  22811. }
  22812. function handleElement(element) {
  22813. enclosedElements[element.id] = element;
  22814. if (element.waypoints) {
  22815. // remember connection
  22816. enclosedConnections[element.id] = allConnections[element.id] = element;
  22817. } else {
  22818. // remember shape
  22819. allShapes[element.id] = element;
  22820. // remember all connections
  22821. forEach(element.incoming, handleConnection);
  22822. forEach(element.outgoing, handleConnection);
  22823. // recurse into children
  22824. return element.children;
  22825. }
  22826. }
  22827. eachElement(elements, handleElement);
  22828. return {
  22829. allShapes: allShapes,
  22830. allConnections: allConnections,
  22831. topLevel: topLevel,
  22832. enclosedConnections: enclosedConnections,
  22833. enclosedElements: enclosedElements
  22834. };
  22835. }
  22836. /**
  22837. * Returns the surrounding bbox for all elements in the array or the element primitive.
  22838. */
  22839. function getBBox(elements, stopRecursion) {
  22840. stopRecursion = !!stopRecursion;
  22841. if (!isArray(elements)) {
  22842. elements = [elements];
  22843. }
  22844. var minX,
  22845. minY,
  22846. maxX,
  22847. maxY;
  22848. forEach(elements, function(element) {
  22849. // If element is a connection the bbox must be computed first
  22850. var bbox = element;
  22851. if (element.waypoints && !stopRecursion) {
  22852. bbox = getBBox(element.waypoints, true);
  22853. }
  22854. var x = bbox.x,
  22855. y = bbox.y,
  22856. height = bbox.height || 0,
  22857. width = bbox.width || 0;
  22858. if (x < minX || minX === undefined) {
  22859. minX = x;
  22860. }
  22861. if (y < minY || minY === undefined) {
  22862. minY = y;
  22863. }
  22864. if ((x + width) > maxX || maxX === undefined) {
  22865. maxX = x + width;
  22866. }
  22867. if ((y + height) > maxY || maxY === undefined) {
  22868. maxY = y + height;
  22869. }
  22870. });
  22871. return {
  22872. x: minX,
  22873. y: minY,
  22874. height: maxY - minY,
  22875. width: maxX - minX
  22876. };
  22877. }
  22878. /**
  22879. * Returns all elements that are enclosed from the bounding box.
  22880. *
  22881. * @param {Array<Object>} elements List of Elements to search through
  22882. * @param {Object} bbox the enclosing bbox.
  22883. * <ul>
  22884. * <li>If bbox.(width|height) is not specified
  22885. * the method returns all elements with element.x/y &gt; bbox.x/y
  22886. * </li>
  22887. * <li>If only bbox.x or bbox.y is specified, method return all elements with
  22888. * e.x &gt; bbox.x or e.y &gt; bbox.y.</li>
  22889. * </ul>
  22890. *
  22891. */
  22892. function getEnclosedElements(elements, bbox) {
  22893. var filteredElements = {};
  22894. forEach(elements, function(element) {
  22895. var e = element;
  22896. if (e.waypoints) {
  22897. e = getBBox(e);
  22898. }
  22899. if (!isNumber(bbox.y) && (e.x > bbox.x)) {
  22900. filteredElements[element.id] = element;
  22901. }
  22902. if (!isNumber(bbox.x) && (e.y > bbox.y)) {
  22903. filteredElements[element.id] = element;
  22904. }
  22905. if (e.x > bbox.x && e.y > bbox.y) {
  22906. if (isNumber(bbox.width) && isNumber(bbox.height) &&
  22907. e.width + e.x < bbox.width + bbox.x &&
  22908. e.height + e.y < bbox.height + bbox.y) {
  22909. filteredElements[element.id] = element;
  22910. } else if (!isNumber(bbox.width) || !isNumber(bbox.height)) {
  22911. filteredElements[element.id] = element;
  22912. }
  22913. }
  22914. });
  22915. return filteredElements;
  22916. }
  22917. module.exports.eachElement = eachElement;
  22918. module.exports.selfAndDirectChildren = selfAndDirectChildren;
  22919. module.exports.selfAndAllChildren = selfAndAllChildren;
  22920. module.exports.getBBox = getBBox;
  22921. module.exports.getEnclosedElements = getEnclosedElements;
  22922. module.exports.getClosure = getClosure;
  22923. },{"218":218,"219":219,"330":330,"333":333}],187:[function(_dereq_,module,exports){
  22924. 'use strict';
  22925. function __preventDefault(event) {
  22926. return event && event.preventDefault();
  22927. }
  22928. function __stopPropagation(event, immediate) {
  22929. if (!event) {
  22930. return;
  22931. }
  22932. if (event.stopPropagation) {
  22933. event.stopPropagation();
  22934. }
  22935. if (immediate && event.stopImmediatePropagation) {
  22936. event.stopImmediatePropagation();
  22937. }
  22938. }
  22939. function getOriginal(event) {
  22940. return event.originalEvent || event.srcEvent;
  22941. }
  22942. module.exports.getOriginal = getOriginal;
  22943. function stopEvent(event, immediate) {
  22944. stopPropagation(event, immediate);
  22945. preventDefault(event);
  22946. }
  22947. module.exports.stopEvent = stopEvent;
  22948. function preventDefault(event) {
  22949. __preventDefault(event);
  22950. __preventDefault(getOriginal(event));
  22951. }
  22952. module.exports.preventDefault = preventDefault;
  22953. function stopPropagation(event, immediate) {
  22954. __stopPropagation(event, immediate);
  22955. __stopPropagation(getOriginal(event), immediate);
  22956. }
  22957. module.exports.stopPropagation = stopPropagation;
  22958. function toPoint(event) {
  22959. if (event.pointers && event.pointers.length) {
  22960. event = event.pointers[0];
  22961. }
  22962. if (event.touches && event.touches.length) {
  22963. event = event.touches[0];
  22964. }
  22965. return event ? {
  22966. x: event.clientX,
  22967. y: event.clientY
  22968. } : null;
  22969. }
  22970. module.exports.toPoint = toPoint;
  22971. },{}],188:[function(_dereq_,module,exports){
  22972. 'use strict';
  22973. /**
  22974. * Computes the distance between two points
  22975. *
  22976. * @param {Point} p
  22977. * @param {Point} q
  22978. *
  22979. * @return {Number} distance
  22980. */
  22981. var pointDistance = module.exports.pointDistance = function(p, q) {
  22982. return Math.sqrt(Math.pow(q.x - p.x, 2) + Math.pow(q.y - p.y, 2));
  22983. };
  22984. /**
  22985. * Returns true if the point r is on the line between p and y
  22986. *
  22987. * @param {Point} p
  22988. * @param {Point} q
  22989. * @param {Point} r
  22990. *
  22991. * @return {Boolean}
  22992. */
  22993. module.exports.pointsOnLine = function(p, q, r) {
  22994. if (!p || !q || !r) {
  22995. return false;
  22996. }
  22997. var val = (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x),
  22998. dist = pointDistance(p, q);
  22999. // @see http://stackoverflow.com/a/907491/412190
  23000. return Math.abs(val / dist) < 5;
  23001. };
  23002. module.exports.pointInRect = function(p, rect, tolerance) {
  23003. tolerance = tolerance || 0;
  23004. return p.x > rect.x - tolerance &&
  23005. p.y > rect.y - tolerance &&
  23006. p.x < rect.x + rect.width + tolerance &&
  23007. p.y < rect.y + rect.height + tolerance;
  23008. };
  23009. },{}],189:[function(_dereq_,module,exports){
  23010. 'use strict';
  23011. /**
  23012. * SVGs for elements are generated by the {@link GraphicsFactory}.
  23013. *
  23014. * This utility gives quick access to the important semantic
  23015. * parts of an element.
  23016. */
  23017. /**
  23018. * Returns the visual part of a diagram element
  23019. *
  23020. * @param {Snap<SVGElement>} gfx
  23021. *
  23022. * @return {Snap<SVGElement>}
  23023. */
  23024. function getVisual(gfx) {
  23025. return gfx.select('.djs-visual');
  23026. }
  23027. /**
  23028. * Returns the children for a given diagram element.
  23029. *
  23030. * @param {Snap<SVGElement>} gfx
  23031. * @return {Snap<SVGElement>}
  23032. */
  23033. function getChildren(gfx) {
  23034. return gfx.parent().children()[1];
  23035. }
  23036. /**
  23037. * Returns the visual bbox of an element
  23038. *
  23039. * @param {Snap<SVGElement>} gfx
  23040. *
  23041. * @return {Bounds}
  23042. */
  23043. function getBBox(gfx) {
  23044. return getVisual(gfx).select('*').getBBox();
  23045. }
  23046. module.exports.getVisual = getVisual;
  23047. module.exports.getChildren = getChildren;
  23048. module.exports.getBBox = getBBox;
  23049. },{}],190:[function(_dereq_,module,exports){
  23050. 'use strict';
  23051. /**
  23052. * Util that provides unique IDs.
  23053. *
  23054. * @class djs.util.IdGenerator
  23055. * @constructor
  23056. * @memberOf djs.util
  23057. *
  23058. * The ids can be customized via a given prefix and contain a random value to avoid collisions.
  23059. *
  23060. * @param {String} prefix a prefix to prepend to generated ids (for better readability)
  23061. */
  23062. function IdGenerator(prefix) {
  23063. this._counter = 0;
  23064. this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-';
  23065. }
  23066. module.exports = IdGenerator;
  23067. /**
  23068. * Returns a next unique ID.
  23069. *
  23070. * @method djs.util.IdGenerator#next
  23071. *
  23072. * @returns {String} the id
  23073. */
  23074. IdGenerator.prototype.next = function() {
  23075. return this._prefix + (++this._counter);
  23076. };
  23077. },{}],191:[function(_dereq_,module,exports){
  23078. 'use strict';
  23079. var pointDistance = _dereq_(188).pointDistance;
  23080. var Snap = _dereq_(200);
  23081. var round = Math.round,
  23082. max = Math.max;
  23083. function circlePath(center, r) {
  23084. var x = center.x,
  23085. y = center.y;
  23086. return [
  23087. ['M', x, y],
  23088. ['m', 0, -r],
  23089. ['a', r, r, 0, 1, 1, 0, 2 * r],
  23090. ['a', r, r, 0, 1, 1, 0, -2 * r],
  23091. ['z']
  23092. ];
  23093. }
  23094. function linePath(points) {
  23095. var segments = [];
  23096. points.forEach(function(p, idx) {
  23097. segments.push([ idx === 0 ? 'M' : 'L', p.x, p.y ]);
  23098. });
  23099. return segments;
  23100. }
  23101. var INTERSECTION_THRESHOLD = 10;
  23102. function getBendpointIntersection(waypoints, reference) {
  23103. var i, w;
  23104. for (i = 0; !!(w = waypoints[i]); i++) {
  23105. if (pointDistance(w, reference) <= INTERSECTION_THRESHOLD) {
  23106. return {
  23107. point: waypoints[i],
  23108. bendpoint: true,
  23109. index: i
  23110. };
  23111. }
  23112. }
  23113. return null;
  23114. }
  23115. function getPathIntersection(waypoints, reference) {
  23116. var intersections = Snap.path.intersection(circlePath(reference, INTERSECTION_THRESHOLD), linePath(waypoints));
  23117. var a = intersections[0],
  23118. b = intersections[intersections.length - 1],
  23119. idx;
  23120. if (!a) {
  23121. // no intersection
  23122. return null;
  23123. }
  23124. if (a !== b) {
  23125. if (a.segment2 !== b.segment2) {
  23126. // we use the bendpoint in between both segments
  23127. // as the intersection point
  23128. idx = max(a.segment2, b.segment2) - 1;
  23129. return {
  23130. point: waypoints[idx],
  23131. bendpoint: true,
  23132. index: idx
  23133. };
  23134. }
  23135. return {
  23136. point: {
  23137. x: (round(a.x + b.x) / 2),
  23138. y: (round(a.y + b.y) / 2)
  23139. },
  23140. index: a.segment2
  23141. };
  23142. }
  23143. return {
  23144. point: {
  23145. x: round(a.x),
  23146. y: round(a.y)
  23147. },
  23148. index: a.segment2
  23149. };
  23150. }
  23151. /**
  23152. * Returns the closest point on the connection towards a given reference point.
  23153. *
  23154. * @param {Array<Point>} waypoints
  23155. * @param {Point} reference
  23156. *
  23157. * @return {Object} intersection data (segment, point)
  23158. */
  23159. module.exports.getApproxIntersection = function(waypoints, reference) {
  23160. return getBendpointIntersection(waypoints, reference) || getPathIntersection(waypoints, reference);
  23161. };
  23162. },{"188":188,"200":200}],192:[function(_dereq_,module,exports){
  23163. 'use strict';
  23164. /**
  23165. * Get the logarithm of x with base 10
  23166. * @param {Integer} value
  23167. */
  23168. function log10(x) {
  23169. return Math.log(x) / Math.log(10);
  23170. }
  23171. module.exports.log10 = log10;
  23172. },{}],193:[function(_dereq_,module,exports){
  23173. 'use strict';
  23174. var getOriginalEvent = _dereq_(187).getOriginal;
  23175. var isMac = _dereq_(194).isMac;
  23176. function isPrimaryButton(event) {
  23177. // button === 0 -> left áka primary mouse button
  23178. return !(getOriginalEvent(event) || event).button;
  23179. }
  23180. module.exports.isPrimaryButton = isPrimaryButton;
  23181. module.exports.isMac = isMac;
  23182. module.exports.hasPrimaryModifier = function(event) {
  23183. var originalEvent = getOriginalEvent(event) || event;
  23184. if (!isPrimaryButton(event)) {
  23185. return false;
  23186. }
  23187. // Use alt as primary modifier key for mac OS
  23188. if (isMac()) {
  23189. return originalEvent.altKey;
  23190. } else {
  23191. return originalEvent.ctrlKey;
  23192. }
  23193. };
  23194. module.exports.hasSecondaryModifier = function(event) {
  23195. var originalEvent = getOriginalEvent(event) || event;
  23196. return isPrimaryButton(event) && originalEvent.shiftKey;
  23197. };
  23198. },{"187":187,"194":194}],194:[function(_dereq_,module,exports){
  23199. 'use strict';
  23200. module.exports.isMac = function isMac() {
  23201. return (/mac/i).test(navigator.platform);
  23202. };
  23203. },{}],195:[function(_dereq_,module,exports){
  23204. 'use strict';
  23205. /**
  23206. * Remove from the beginning of a collection until it is empty.
  23207. *
  23208. * This is a null-safe operation that ensures elements
  23209. * are being removed from the given collection until the
  23210. * collection is empty.
  23211. *
  23212. * The implementation deals with the fact that a remove operation
  23213. * may touch, i.e. remove multiple elements in the collection
  23214. * at a time.
  23215. *
  23216. * @param {Array<Object>} [collection]
  23217. * @param {Function} removeFn
  23218. *
  23219. * @return {Array<Object>} the cleared collection
  23220. */
  23221. module.exports.saveClear = function(collection, removeFn) {
  23222. if (typeof removeFn !== 'function') {
  23223. throw new Error('removeFn iterator must be a function');
  23224. }
  23225. if (!collection) {
  23226. return;
  23227. }
  23228. var e;
  23229. while (!!(e = collection[0])) {
  23230. removeFn(e);
  23231. }
  23232. return collection;
  23233. };
  23234. },{}],196:[function(_dereq_,module,exports){
  23235. 'use strict';
  23236. var isObject = _dereq_(334),
  23237. assign = _dereq_(339),
  23238. pick = _dereq_(345),
  23239. forEach = _dereq_(218),
  23240. reduce = _dereq_(222),
  23241. merge = _dereq_(342);
  23242. var Snap = _dereq_(200);
  23243. var DEFAULT_BOX_PADDING = 0;
  23244. var DEFAULT_LABEL_SIZE = {
  23245. width: 150,
  23246. height: 50
  23247. };
  23248. function parseAlign(align) {
  23249. var parts = align.split('-');
  23250. return {
  23251. horizontal: parts[0] || 'center',
  23252. vertical: parts[1] || 'top'
  23253. };
  23254. }
  23255. function parsePadding(padding) {
  23256. if (isObject(padding)) {
  23257. return assign({ top: 0, left: 0, right: 0, bottom: 0 }, padding);
  23258. } else {
  23259. return {
  23260. top: padding,
  23261. left: padding,
  23262. right: padding,
  23263. bottom: padding
  23264. };
  23265. }
  23266. }
  23267. function getTextBBox(text, fakeText) {
  23268. fakeText.textContent = text;
  23269. return pick(fakeText.getBBox(), [ 'width', 'height' ]);
  23270. }
  23271. /**
  23272. * Layout the next line and return the layouted element.
  23273. *
  23274. * Alters the lines passed.
  23275. *
  23276. * @param {Array<String>} lines
  23277. * @return {Object} the line descriptor, an object { width, height, text }
  23278. */
  23279. function layoutNext(lines, maxWidth, fakeText) {
  23280. var originalLine = lines.shift(),
  23281. fitLine = originalLine;
  23282. var textBBox;
  23283. while (true) {
  23284. textBBox = getTextBBox(fitLine, fakeText);
  23285. textBBox.width = fitLine ? textBBox.width : 0;
  23286. // try to fit
  23287. if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 4) {
  23288. return fit(lines, fitLine, originalLine, textBBox);
  23289. }
  23290. fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
  23291. }
  23292. }
  23293. function fit(lines, fitLine, originalLine, textBBox) {
  23294. if (fitLine.length < originalLine.length) {
  23295. var nextLine = lines[0] || '',
  23296. remainder = originalLine.slice(fitLine.length).trim();
  23297. if (/-\s*$/.test(remainder)) {
  23298. nextLine = remainder.replace(/-\s*$/, '') + nextLine.replace(/^\s+/, '');
  23299. } else {
  23300. nextLine = remainder + ' ' + nextLine;
  23301. }
  23302. lines[0] = nextLine;
  23303. }
  23304. return { width: textBBox.width, height: textBBox.height, text: fitLine };
  23305. }
  23306. /**
  23307. * Shortens a line based on spacing and hyphens.
  23308. * Returns the shortened result on success.
  23309. *
  23310. * @param {String} line
  23311. * @param {Number} maxLength the maximum characters of the string
  23312. * @return {String} the shortened string
  23313. */
  23314. function semanticShorten(line, maxLength) {
  23315. var parts = line.split(/(\s|-)/g),
  23316. part,
  23317. shortenedParts = [],
  23318. length = 0;
  23319. // try to shorten via spaces + hyphens
  23320. if (parts.length > 1) {
  23321. while ((part = parts.shift())) {
  23322. if (part.length + length < maxLength) {
  23323. shortenedParts.push(part);
  23324. length += part.length;
  23325. } else {
  23326. // remove previous part, too if hyphen does not fit anymore
  23327. if (part === '-') {
  23328. shortenedParts.pop();
  23329. }
  23330. break;
  23331. }
  23332. }
  23333. }
  23334. return shortenedParts.join('');
  23335. }
  23336. function shortenLine(line, width, maxWidth) {
  23337. var length = Math.max(line.length * (maxWidth / width), 1);
  23338. // try to shorten semantically (i.e. based on spaces and hyphens)
  23339. var shortenedLine = semanticShorten(line, length);
  23340. if (!shortenedLine) {
  23341. // force shorten by cutting the long word
  23342. shortenedLine = line.slice(0, Math.max(Math.round(length - 1), 1));
  23343. }
  23344. return shortenedLine;
  23345. }
  23346. /**
  23347. * Creates a new label utility
  23348. *
  23349. * @param {Object} config
  23350. * @param {Dimensions} config.size
  23351. * @param {Number} config.padding
  23352. * @param {Object} config.style
  23353. * @param {String} config.align
  23354. */
  23355. function Text(config) {
  23356. this._config = assign({}, {
  23357. size: DEFAULT_LABEL_SIZE,
  23358. padding: DEFAULT_BOX_PADDING,
  23359. style: {},
  23360. align: 'center-top'
  23361. }, config || {});
  23362. }
  23363. /**
  23364. * Create a label in the parent node.
  23365. *
  23366. * @method Text#createText
  23367. *
  23368. * @param {SVGElement} parent the parent to draw the label on
  23369. * @param {String} text the text to render on the label
  23370. * @param {Object} options
  23371. * @param {String} options.align how to align in the bounding box.
  23372. * Any of { 'center-middle', 'center-top' }, defaults to 'center-top'.
  23373. * @param {String} options.style style to be applied to the text
  23374. *
  23375. * @return {SVGText} the text element created
  23376. */
  23377. Text.prototype.createText = function(parent, text, options) {
  23378. var box = merge({}, this._config.size, options.box || {}),
  23379. style = merge({}, this._config.style, options.style || {}),
  23380. align = parseAlign(options.align || this._config.align),
  23381. padding = parsePadding(options.padding !== undefined ? options.padding : this._config.padding);
  23382. var lines = text.split(/\r?\n/g),
  23383. layouted = [];
  23384. var maxWidth = box.width - padding.left - padding.right;
  23385. // FF regression: ensure text is shown during rendering
  23386. // by attaching it directly to the body
  23387. var fakeText = parent.paper.text(0, 0, '').attr(style).node;
  23388. while (lines.length) {
  23389. layouted.push(layoutNext(lines, maxWidth, fakeText));
  23390. }
  23391. var totalHeight = reduce(layouted, function(sum, line, idx) {
  23392. return sum + line.height;
  23393. }, 0);
  23394. // the y position of the next line
  23395. var y, x;
  23396. switch (align.vertical) {
  23397. case 'middle':
  23398. y = (box.height - totalHeight) / 2 - layouted[0].height / 4;
  23399. break;
  23400. default:
  23401. y = padding.top;
  23402. }
  23403. var textElement = parent.text().attr(style);
  23404. forEach(layouted, function(line) {
  23405. y += line.height;
  23406. switch (align.horizontal) {
  23407. case 'left':
  23408. x = padding.left;
  23409. break;
  23410. case 'right':
  23411. x = (maxWidth - padding.right - line.width);
  23412. break;
  23413. default:
  23414. // aka center
  23415. x = Math.max(((maxWidth - line.width) / 2 + padding.left), 0);
  23416. }
  23417. var tspan = Snap.create('tspan', { x: x, y: y }).node;
  23418. tspan.textContent = line.text;
  23419. textElement.append(tspan);
  23420. });
  23421. // remove fake text
  23422. fakeText.parentNode.removeChild(fakeText);
  23423. return textElement;
  23424. };
  23425. module.exports = Text;
  23426. },{"200":200,"218":218,"222":222,"334":334,"339":339,"342":342,"345":345}],197:[function(_dereq_,module,exports){
  23427. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  23428. //
  23429. // Licensed under the Apache License, Version 2.0 (the "License");
  23430. // you may not use this file except in compliance with the License.
  23431. // You may obtain a copy of the License at
  23432. //
  23433. // http://www.apache.org/licenses/LICENSE-2.0
  23434. //
  23435. // Unless required by applicable law or agreed to in writing, software
  23436. // distributed under the License is distributed on an "AS IS" BASIS,
  23437. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23438. // See the License for the specific language governing permissions and
  23439. // limitations under the License.
  23440. // ┌────────────────────────────────────────────────────────────┐ \\
  23441. // │ Eve 0.4.2 - JavaScript Events Library │ \\
  23442. // ├────────────────────────────────────────────────────────────┤ \\
  23443. // │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\
  23444. // └────────────────────────────────────────────────────────────┘ \\
  23445. (function (glob) {
  23446. var version = "0.4.2",
  23447. has = "hasOwnProperty",
  23448. separator = /[\.\/]/,
  23449. comaseparator = /\s*,\s*/,
  23450. wildcard = "*",
  23451. fun = function () {},
  23452. numsort = function (a, b) {
  23453. return a - b;
  23454. },
  23455. current_event,
  23456. stop,
  23457. events = {n: {}},
  23458. firstDefined = function () {
  23459. for (var i = 0, ii = this.length; i < ii; i++) {
  23460. if (typeof this[i] != "undefined") {
  23461. return this[i];
  23462. }
  23463. }
  23464. },
  23465. lastDefined = function () {
  23466. var i = this.length;
  23467. while (--i) {
  23468. if (typeof this[i] != "undefined") {
  23469. return this[i];
  23470. }
  23471. }
  23472. },
  23473. /*\
  23474. * eve
  23475. [ method ]
  23476. * Fires event with given `name`, given scope and other parameters.
  23477. > Arguments
  23478. - name (string) name of the *event*, dot (`.`) or slash (`/`) separated
  23479. - scope (object) context for the event handlers
  23480. - varargs (...) the rest of arguments will be sent to event handlers
  23481. = (object) array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value.
  23482. \*/
  23483. eve = function (name, scope) {
  23484. name = String(name);
  23485. var e = events,
  23486. oldstop = stop,
  23487. args = Array.prototype.slice.call(arguments, 2),
  23488. listeners = eve.listeners(name),
  23489. z = 0,
  23490. f = false,
  23491. l,
  23492. indexed = [],
  23493. queue = {},
  23494. out = [],
  23495. ce = current_event,
  23496. errors = [];
  23497. out.firstDefined = firstDefined;
  23498. out.lastDefined = lastDefined;
  23499. current_event = name;
  23500. stop = 0;
  23501. for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) {
  23502. indexed.push(listeners[i].zIndex);
  23503. if (listeners[i].zIndex < 0) {
  23504. queue[listeners[i].zIndex] = listeners[i];
  23505. }
  23506. }
  23507. indexed.sort(numsort);
  23508. while (indexed[z] < 0) {
  23509. l = queue[indexed[z++]];
  23510. out.push(l.apply(scope, args));
  23511. if (stop) {
  23512. stop = oldstop;
  23513. return out;
  23514. }
  23515. }
  23516. for (i = 0; i < ii; i++) {
  23517. l = listeners[i];
  23518. if ("zIndex" in l) {
  23519. if (l.zIndex == indexed[z]) {
  23520. out.push(l.apply(scope, args));
  23521. if (stop) {
  23522. break;
  23523. }
  23524. do {
  23525. z++;
  23526. l = queue[indexed[z]];
  23527. l && out.push(l.apply(scope, args));
  23528. if (stop) {
  23529. break;
  23530. }
  23531. } while (l)
  23532. } else {
  23533. queue[l.zIndex] = l;
  23534. }
  23535. } else {
  23536. out.push(l.apply(scope, args));
  23537. if (stop) {
  23538. break;
  23539. }
  23540. }
  23541. }
  23542. stop = oldstop;
  23543. current_event = ce;
  23544. return out;
  23545. };
  23546. // Undocumented. Debug only.
  23547. eve._events = events;
  23548. /*\
  23549. * eve.listeners
  23550. [ method ]
  23551. * Internal method which gives you array of all event handlers that will be triggered by the given `name`.
  23552. > Arguments
  23553. - name (string) name of the event, dot (`.`) or slash (`/`) separated
  23554. = (array) array of event handlers
  23555. \*/
  23556. eve.listeners = function (name) {
  23557. var names = name.split(separator),
  23558. e = events,
  23559. item,
  23560. items,
  23561. k,
  23562. i,
  23563. ii,
  23564. j,
  23565. jj,
  23566. nes,
  23567. es = [e],
  23568. out = [];
  23569. for (i = 0, ii = names.length; i < ii; i++) {
  23570. nes = [];
  23571. for (j = 0, jj = es.length; j < jj; j++) {
  23572. e = es[j].n;
  23573. items = [e[names[i]], e[wildcard]];
  23574. k = 2;
  23575. while (k--) {
  23576. item = items[k];
  23577. if (item) {
  23578. nes.push(item);
  23579. out = out.concat(item.f || []);
  23580. }
  23581. }
  23582. }
  23583. es = nes;
  23584. }
  23585. return out;
  23586. };
  23587. /*\
  23588. * eve.on
  23589. [ method ]
  23590. **
  23591. * Binds given event handler with a given name. You can use wildcards “`*`” for the names:
  23592. | eve.on("*.under.*", f);
  23593. | eve("mouse.under.floor"); // triggers f
  23594. * Use @eve to trigger the listener.
  23595. **
  23596. > Arguments
  23597. **
  23598. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  23599. - f (function) event handler function
  23600. **
  23601. = (function) returned function accepts a single numeric parameter that represents z-index of the handler. It is an optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment.
  23602. > Example:
  23603. | eve.on("mouse", eatIt)(2);
  23604. | eve.on("mouse", scream);
  23605. | eve.on("mouse", catchIt)(1);
  23606. * This will ensure that `catchIt` function will be called before `eatIt`.
  23607. *
  23608. * If you want to put your handler before non-indexed handlers, specify a negative value.
  23609. * Note: I assume most of the time you don’t need to worry about z-index, but it’s nice to have this feature “just in case”.
  23610. \*/
  23611. eve.on = function (name, f) {
  23612. name = String(name);
  23613. if (typeof f != "function") {
  23614. return function () {};
  23615. }
  23616. var names = name.split(comaseparator);
  23617. for (var i = 0, ii = names.length; i < ii; i++) {
  23618. (function (name) {
  23619. var names = name.split(separator),
  23620. e = events,
  23621. exist;
  23622. for (var i = 0, ii = names.length; i < ii; i++) {
  23623. e = e.n;
  23624. e = e.hasOwnProperty(names[i]) && e[names[i]] || (e[names[i]] = {n: {}});
  23625. }
  23626. e.f = e.f || [];
  23627. for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
  23628. exist = true;
  23629. break;
  23630. }
  23631. !exist && e.f.push(f);
  23632. }(names[i]));
  23633. }
  23634. return function (zIndex) {
  23635. if (+zIndex == +zIndex) {
  23636. f.zIndex = +zIndex;
  23637. }
  23638. };
  23639. };
  23640. /*\
  23641. * eve.f
  23642. [ method ]
  23643. **
  23644. * Returns function that will fire given event with optional arguments.
  23645. * Arguments that will be passed to the result function will be also
  23646. * concated to the list of final arguments.
  23647. | el.onclick = eve.f("click", 1, 2);
  23648. | eve.on("click", function (a, b, c) {
  23649. | console.log(a, b, c); // 1, 2, [event object]
  23650. | });
  23651. > Arguments
  23652. - event (string) event name
  23653. - varargs (…) and any other arguments
  23654. = (function) possible event handler function
  23655. \*/
  23656. eve.f = function (event) {
  23657. var attrs = [].slice.call(arguments, 1);
  23658. return function () {
  23659. eve.apply(null, [event, null].concat(attrs).concat([].slice.call(arguments, 0)));
  23660. };
  23661. };
  23662. /*\
  23663. * eve.stop
  23664. [ method ]
  23665. **
  23666. * Is used inside an event handler to stop the event, preventing any subsequent listeners from firing.
  23667. \*/
  23668. eve.stop = function () {
  23669. stop = 1;
  23670. };
  23671. /*\
  23672. * eve.nt
  23673. [ method ]
  23674. **
  23675. * Could be used inside event handler to figure out actual name of the event.
  23676. **
  23677. > Arguments
  23678. **
  23679. - subname (string) #optional subname of the event
  23680. **
  23681. = (string) name of the event, if `subname` is not specified
  23682. * or
  23683. = (boolean) `true`, if current event’s name contains `subname`
  23684. \*/
  23685. eve.nt = function (subname) {
  23686. if (subname) {
  23687. return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event);
  23688. }
  23689. return current_event;
  23690. };
  23691. /*\
  23692. * eve.nts
  23693. [ method ]
  23694. **
  23695. * Could be used inside event handler to figure out actual name of the event.
  23696. **
  23697. **
  23698. = (array) names of the event
  23699. \*/
  23700. eve.nts = function () {
  23701. return current_event.split(separator);
  23702. };
  23703. /*\
  23704. * eve.off
  23705. [ method ]
  23706. **
  23707. * Removes given function from the list of event listeners assigned to given name.
  23708. * If no arguments specified all the events will be cleared.
  23709. **
  23710. > Arguments
  23711. **
  23712. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  23713. - f (function) event handler function
  23714. \*/
  23715. /*\
  23716. * eve.unbind
  23717. [ method ]
  23718. **
  23719. * See @eve.off
  23720. \*/
  23721. eve.off = eve.unbind = function (name, f) {
  23722. if (!name) {
  23723. eve._events = events = {n: {}};
  23724. return;
  23725. }
  23726. var names = name.split(comaseparator);
  23727. if (names.length > 1) {
  23728. for (var i = 0, ii = names.length; i < ii; i++) {
  23729. eve.off(names[i], f);
  23730. }
  23731. return;
  23732. }
  23733. names = name.split(separator);
  23734. var e,
  23735. key,
  23736. splice,
  23737. i, ii, j, jj,
  23738. cur = [events];
  23739. for (i = 0, ii = names.length; i < ii; i++) {
  23740. for (j = 0; j < cur.length; j += splice.length - 2) {
  23741. splice = [j, 1];
  23742. e = cur[j].n;
  23743. if (names[i] != wildcard) {
  23744. if (e[names[i]]) {
  23745. splice.push(e[names[i]]);
  23746. }
  23747. } else {
  23748. for (key in e) if (e[has](key)) {
  23749. splice.push(e[key]);
  23750. }
  23751. }
  23752. cur.splice.apply(cur, splice);
  23753. }
  23754. }
  23755. for (i = 0, ii = cur.length; i < ii; i++) {
  23756. e = cur[i];
  23757. while (e.n) {
  23758. if (f) {
  23759. if (e.f) {
  23760. for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) {
  23761. e.f.splice(j, 1);
  23762. break;
  23763. }
  23764. !e.f.length && delete e.f;
  23765. }
  23766. for (key in e.n) if (e.n[has](key) && e.n[key].f) {
  23767. var funcs = e.n[key].f;
  23768. for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) {
  23769. funcs.splice(j, 1);
  23770. break;
  23771. }
  23772. !funcs.length && delete e.n[key].f;
  23773. }
  23774. } else {
  23775. delete e.f;
  23776. for (key in e.n) if (e.n[has](key) && e.n[key].f) {
  23777. delete e.n[key].f;
  23778. }
  23779. }
  23780. e = e.n;
  23781. }
  23782. }
  23783. };
  23784. /*\
  23785. * eve.once
  23786. [ method ]
  23787. **
  23788. * Binds given event handler with a given name to only run once then unbind itself.
  23789. | eve.once("login", f);
  23790. | eve("login"); // triggers f
  23791. | eve("login"); // no listeners
  23792. * Use @eve to trigger the listener.
  23793. **
  23794. > Arguments
  23795. **
  23796. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  23797. - f (function) event handler function
  23798. **
  23799. = (function) same return function as @eve.on
  23800. \*/
  23801. eve.once = function (name, f) {
  23802. var f2 = function () {
  23803. eve.unbind(name, f2);
  23804. return f.apply(this, arguments);
  23805. };
  23806. return eve.on(name, f2);
  23807. };
  23808. /*\
  23809. * eve.version
  23810. [ property (string) ]
  23811. **
  23812. * Current version of the library.
  23813. \*/
  23814. eve.version = version;
  23815. eve.toString = function () {
  23816. return "You are running Eve " + version;
  23817. };
  23818. (typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define === "function" && define.amd ? (define("eve", [], function() { return eve; })) : (glob.eve = eve));
  23819. })(this);
  23820. },{}],198:[function(_dereq_,module,exports){
  23821. /*! Hammer.JS - v2.0.4 - 2014-09-28
  23822. * http://hammerjs.github.io/
  23823. *
  23824. * Copyright (c) 2014 Jorik Tangelder;
  23825. * Licensed under the MIT license */
  23826. (function(window, document, exportName, undefined) {
  23827. 'use strict';
  23828. var VENDOR_PREFIXES = ['', 'webkit', 'moz', 'MS', 'ms', 'o'];
  23829. var TEST_ELEMENT = document.createElement('div');
  23830. var TYPE_FUNCTION = 'function';
  23831. var round = Math.round;
  23832. var abs = Math.abs;
  23833. var now = Date.now;
  23834. /**
  23835. * set a timeout with a given scope
  23836. * @param {Function} fn
  23837. * @param {Number} timeout
  23838. * @param {Object} context
  23839. * @returns {number}
  23840. */
  23841. function setTimeoutContext(fn, timeout, context) {
  23842. return setTimeout(bindFn(fn, context), timeout);
  23843. }
  23844. /**
  23845. * if the argument is an array, we want to execute the fn on each entry
  23846. * if it aint an array we don't want to do a thing.
  23847. * this is used by all the methods that accept a single and array argument.
  23848. * @param {*|Array} arg
  23849. * @param {String} fn
  23850. * @param {Object} [context]
  23851. * @returns {Boolean}
  23852. */
  23853. function invokeArrayArg(arg, fn, context) {
  23854. if (Array.isArray(arg)) {
  23855. each(arg, context[fn], context);
  23856. return true;
  23857. }
  23858. return false;
  23859. }
  23860. /**
  23861. * walk objects and arrays
  23862. * @param {Object} obj
  23863. * @param {Function} iterator
  23864. * @param {Object} context
  23865. */
  23866. function each(obj, iterator, context) {
  23867. var i;
  23868. if (!obj) {
  23869. return;
  23870. }
  23871. if (obj.forEach) {
  23872. obj.forEach(iterator, context);
  23873. } else if (obj.length !== undefined) {
  23874. i = 0;
  23875. while (i < obj.length) {
  23876. iterator.call(context, obj[i], i, obj);
  23877. i++;
  23878. }
  23879. } else {
  23880. for (i in obj) {
  23881. obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
  23882. }
  23883. }
  23884. }
  23885. /**
  23886. * extend object.
  23887. * means that properties in dest will be overwritten by the ones in src.
  23888. * @param {Object} dest
  23889. * @param {Object} src
  23890. * @param {Boolean} [merge]
  23891. * @returns {Object} dest
  23892. */
  23893. function extend(dest, src, merge) {
  23894. var keys = Object.keys(src);
  23895. var i = 0;
  23896. while (i < keys.length) {
  23897. if (!merge || (merge && dest[keys[i]] === undefined)) {
  23898. dest[keys[i]] = src[keys[i]];
  23899. }
  23900. i++;
  23901. }
  23902. return dest;
  23903. }
  23904. /**
  23905. * merge the values from src in the dest.
  23906. * means that properties that exist in dest will not be overwritten by src
  23907. * @param {Object} dest
  23908. * @param {Object} src
  23909. * @returns {Object} dest
  23910. */
  23911. function merge(dest, src) {
  23912. return extend(dest, src, true);
  23913. }
  23914. /**
  23915. * simple class inheritance
  23916. * @param {Function} child
  23917. * @param {Function} base
  23918. * @param {Object} [properties]
  23919. */
  23920. function inherit(child, base, properties) {
  23921. var baseP = base.prototype,
  23922. childP;
  23923. childP = child.prototype = Object.create(baseP);
  23924. childP.constructor = child;
  23925. childP._super = baseP;
  23926. if (properties) {
  23927. extend(childP, properties);
  23928. }
  23929. }
  23930. /**
  23931. * simple function bind
  23932. * @param {Function} fn
  23933. * @param {Object} context
  23934. * @returns {Function}
  23935. */
  23936. function bindFn(fn, context) {
  23937. return function boundFn() {
  23938. return fn.apply(context, arguments);
  23939. };
  23940. }
  23941. /**
  23942. * let a boolean value also be a function that must return a boolean
  23943. * this first item in args will be used as the context
  23944. * @param {Boolean|Function} val
  23945. * @param {Array} [args]
  23946. * @returns {Boolean}
  23947. */
  23948. function boolOrFn(val, args) {
  23949. if (typeof val == TYPE_FUNCTION) {
  23950. return val.apply(args ? args[0] || undefined : undefined, args);
  23951. }
  23952. return val;
  23953. }
  23954. /**
  23955. * use the val2 when val1 is undefined
  23956. * @param {*} val1
  23957. * @param {*} val2
  23958. * @returns {*}
  23959. */
  23960. function ifUndefined(val1, val2) {
  23961. return (val1 === undefined) ? val2 : val1;
  23962. }
  23963. /**
  23964. * addEventListener with multiple events at once
  23965. * @param {EventTarget} target
  23966. * @param {String} types
  23967. * @param {Function} handler
  23968. */
  23969. function addEventListeners(target, types, handler) {
  23970. each(splitStr(types), function(type) {
  23971. target.addEventListener(type, handler, false);
  23972. });
  23973. }
  23974. /**
  23975. * removeEventListener with multiple events at once
  23976. * @param {EventTarget} target
  23977. * @param {String} types
  23978. * @param {Function} handler
  23979. */
  23980. function removeEventListeners(target, types, handler) {
  23981. each(splitStr(types), function(type) {
  23982. target.removeEventListener(type, handler, false);
  23983. });
  23984. }
  23985. /**
  23986. * find if a node is in the given parent
  23987. * @method hasParent
  23988. * @param {HTMLElement} node
  23989. * @param {HTMLElement} parent
  23990. * @return {Boolean} found
  23991. */
  23992. function hasParent(node, parent) {
  23993. while (node) {
  23994. if (node == parent) {
  23995. return true;
  23996. }
  23997. node = node.parentNode;
  23998. }
  23999. return false;
  24000. }
  24001. /**
  24002. * small indexOf wrapper
  24003. * @param {String} str
  24004. * @param {String} find
  24005. * @returns {Boolean} found
  24006. */
  24007. function inStr(str, find) {
  24008. return str.indexOf(find) > -1;
  24009. }
  24010. /**
  24011. * split string on whitespace
  24012. * @param {String} str
  24013. * @returns {Array} words
  24014. */
  24015. function splitStr(str) {
  24016. return str.trim().split(/\s+/g);
  24017. }
  24018. /**
  24019. * find if a array contains the object using indexOf or a simple polyFill
  24020. * @param {Array} src
  24021. * @param {String} find
  24022. * @param {String} [findByKey]
  24023. * @return {Boolean|Number} false when not found, or the index
  24024. */
  24025. function inArray(src, find, findByKey) {
  24026. if (src.indexOf && !findByKey) {
  24027. return src.indexOf(find);
  24028. } else {
  24029. var i = 0;
  24030. while (i < src.length) {
  24031. if ((findByKey && src[i][findByKey] == find) || (!findByKey && src[i] === find)) {
  24032. return i;
  24033. }
  24034. i++;
  24035. }
  24036. return -1;
  24037. }
  24038. }
  24039. /**
  24040. * convert array-like objects to real arrays
  24041. * @param {Object} obj
  24042. * @returns {Array}
  24043. */
  24044. function toArray(obj) {
  24045. return Array.prototype.slice.call(obj, 0);
  24046. }
  24047. /**
  24048. * unique array with objects based on a key (like 'id') or just by the array's value
  24049. * @param {Array} src [{id:1},{id:2},{id:1}]
  24050. * @param {String} [key]
  24051. * @param {Boolean} [sort=False]
  24052. * @returns {Array} [{id:1},{id:2}]
  24053. */
  24054. function uniqueArray(src, key, sort) {
  24055. var results = [];
  24056. var values = [];
  24057. var i = 0;
  24058. while (i < src.length) {
  24059. var val = key ? src[i][key] : src[i];
  24060. if (inArray(values, val) < 0) {
  24061. results.push(src[i]);
  24062. }
  24063. values[i] = val;
  24064. i++;
  24065. }
  24066. if (sort) {
  24067. if (!key) {
  24068. results = results.sort();
  24069. } else {
  24070. results = results.sort(function sortUniqueArray(a, b) {
  24071. return a[key] > b[key];
  24072. });
  24073. }
  24074. }
  24075. return results;
  24076. }
  24077. /**
  24078. * get the prefixed property
  24079. * @param {Object} obj
  24080. * @param {String} property
  24081. * @returns {String|Undefined} prefixed
  24082. */
  24083. function prefixed(obj, property) {
  24084. var prefix, prop;
  24085. var camelProp = property[0].toUpperCase() + property.slice(1);
  24086. var i = 0;
  24087. while (i < VENDOR_PREFIXES.length) {
  24088. prefix = VENDOR_PREFIXES[i];
  24089. prop = (prefix) ? prefix + camelProp : property;
  24090. if (prop in obj) {
  24091. return prop;
  24092. }
  24093. i++;
  24094. }
  24095. return undefined;
  24096. }
  24097. /**
  24098. * get a unique id
  24099. * @returns {number} uniqueId
  24100. */
  24101. var _uniqueId = 1;
  24102. function uniqueId() {
  24103. return _uniqueId++;
  24104. }
  24105. /**
  24106. * get the window object of an element
  24107. * @param {HTMLElement} element
  24108. * @returns {DocumentView|Window}
  24109. */
  24110. function getWindowForElement(element) {
  24111. var doc = element.ownerDocument;
  24112. return (doc.defaultView || doc.parentWindow);
  24113. }
  24114. var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
  24115. var SUPPORT_TOUCH = ('ontouchstart' in window);
  24116. var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined;
  24117. var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
  24118. var INPUT_TYPE_TOUCH = 'touch';
  24119. var INPUT_TYPE_PEN = 'pen';
  24120. var INPUT_TYPE_MOUSE = 'mouse';
  24121. var INPUT_TYPE_KINECT = 'kinect';
  24122. var COMPUTE_INTERVAL = 25;
  24123. var INPUT_START = 1;
  24124. var INPUT_MOVE = 2;
  24125. var INPUT_END = 4;
  24126. var INPUT_CANCEL = 8;
  24127. var DIRECTION_NONE = 1;
  24128. var DIRECTION_LEFT = 2;
  24129. var DIRECTION_RIGHT = 4;
  24130. var DIRECTION_UP = 8;
  24131. var DIRECTION_DOWN = 16;
  24132. var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
  24133. var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
  24134. var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
  24135. var PROPS_XY = ['x', 'y'];
  24136. var PROPS_CLIENT_XY = ['clientX', 'clientY'];
  24137. /**
  24138. * create new input type manager
  24139. * @param {Manager} manager
  24140. * @param {Function} callback
  24141. * @returns {Input}
  24142. * @constructor
  24143. */
  24144. function Input(manager, callback) {
  24145. var self = this;
  24146. this.manager = manager;
  24147. this.callback = callback;
  24148. this.element = manager.element;
  24149. this.target = manager.options.inputTarget;
  24150. // smaller wrapper around the handler, for the scope and the enabled state of the manager,
  24151. // so when disabled the input events are completely bypassed.
  24152. this.domHandler = function(ev) {
  24153. if (boolOrFn(manager.options.enable, [manager])) {
  24154. self.handler(ev);
  24155. }
  24156. };
  24157. this.init();
  24158. }
  24159. Input.prototype = {
  24160. /**
  24161. * should handle the inputEvent data and trigger the callback
  24162. * @virtual
  24163. */
  24164. handler: function() { },
  24165. /**
  24166. * bind the events
  24167. */
  24168. init: function() {
  24169. this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
  24170. this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
  24171. this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
  24172. },
  24173. /**
  24174. * unbind the events
  24175. */
  24176. destroy: function() {
  24177. this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
  24178. this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
  24179. this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
  24180. }
  24181. };
  24182. /**
  24183. * create new input type manager
  24184. * called by the Manager constructor
  24185. * @param {Hammer} manager
  24186. * @returns {Input}
  24187. */
  24188. function createInputInstance(manager) {
  24189. var Type;
  24190. var inputClass = manager.options.inputClass;
  24191. if (inputClass) {
  24192. Type = inputClass;
  24193. } else if (SUPPORT_POINTER_EVENTS) {
  24194. Type = PointerEventInput;
  24195. } else if (SUPPORT_ONLY_TOUCH) {
  24196. Type = TouchInput;
  24197. } else if (!SUPPORT_TOUCH) {
  24198. Type = MouseInput;
  24199. } else {
  24200. Type = TouchMouseInput;
  24201. }
  24202. return new (Type)(manager, inputHandler);
  24203. }
  24204. /**
  24205. * handle input events
  24206. * @param {Manager} manager
  24207. * @param {String} eventType
  24208. * @param {Object} input
  24209. */
  24210. function inputHandler(manager, eventType, input) {
  24211. var pointersLen = input.pointers.length;
  24212. var changedPointersLen = input.changedPointers.length;
  24213. var isFirst = (eventType & INPUT_START && (pointersLen - changedPointersLen === 0));
  24214. var isFinal = (eventType & (INPUT_END | INPUT_CANCEL) && (pointersLen - changedPointersLen === 0));
  24215. input.isFirst = !!isFirst;
  24216. input.isFinal = !!isFinal;
  24217. if (isFirst) {
  24218. manager.session = {};
  24219. }
  24220. // source event is the normalized value of the domEvents
  24221. // like 'touchstart, mouseup, pointerdown'
  24222. input.eventType = eventType;
  24223. // compute scale, rotation etc
  24224. computeInputData(manager, input);
  24225. // emit secret event
  24226. manager.emit('hammer.input', input);
  24227. manager.recognize(input);
  24228. manager.session.prevInput = input;
  24229. }
  24230. /**
  24231. * extend the data with some usable properties like scale, rotate, velocity etc
  24232. * @param {Object} manager
  24233. * @param {Object} input
  24234. */
  24235. function computeInputData(manager, input) {
  24236. var session = manager.session;
  24237. var pointers = input.pointers;
  24238. var pointersLength = pointers.length;
  24239. // store the first input to calculate the distance and direction
  24240. if (!session.firstInput) {
  24241. session.firstInput = simpleCloneInputData(input);
  24242. }
  24243. // to compute scale and rotation we need to store the multiple touches
  24244. if (pointersLength > 1 && !session.firstMultiple) {
  24245. session.firstMultiple = simpleCloneInputData(input);
  24246. } else if (pointersLength === 1) {
  24247. session.firstMultiple = false;
  24248. }
  24249. var firstInput = session.firstInput;
  24250. var firstMultiple = session.firstMultiple;
  24251. var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
  24252. var center = input.center = getCenter(pointers);
  24253. input.timeStamp = now();
  24254. input.deltaTime = input.timeStamp - firstInput.timeStamp;
  24255. input.angle = getAngle(offsetCenter, center);
  24256. input.distance = getDistance(offsetCenter, center);
  24257. computeDeltaXY(session, input);
  24258. input.offsetDirection = getDirection(input.deltaX, input.deltaY);
  24259. input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
  24260. input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
  24261. computeIntervalInputData(session, input);
  24262. // find the correct target
  24263. var target = manager.element;
  24264. if (hasParent(input.srcEvent.target, target)) {
  24265. target = input.srcEvent.target;
  24266. }
  24267. input.target = target;
  24268. }
  24269. function computeDeltaXY(session, input) {
  24270. var center = input.center;
  24271. var offset = session.offsetDelta || {};
  24272. var prevDelta = session.prevDelta || {};
  24273. var prevInput = session.prevInput || {};
  24274. if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
  24275. prevDelta = session.prevDelta = {
  24276. x: prevInput.deltaX || 0,
  24277. y: prevInput.deltaY || 0
  24278. };
  24279. offset = session.offsetDelta = {
  24280. x: center.x,
  24281. y: center.y
  24282. };
  24283. }
  24284. input.deltaX = prevDelta.x + (center.x - offset.x);
  24285. input.deltaY = prevDelta.y + (center.y - offset.y);
  24286. }
  24287. /**
  24288. * velocity is calculated every x ms
  24289. * @param {Object} session
  24290. * @param {Object} input
  24291. */
  24292. function computeIntervalInputData(session, input) {
  24293. var last = session.lastInterval || input,
  24294. deltaTime = input.timeStamp - last.timeStamp,
  24295. velocity, velocityX, velocityY, direction;
  24296. if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
  24297. var deltaX = last.deltaX - input.deltaX;
  24298. var deltaY = last.deltaY - input.deltaY;
  24299. var v = getVelocity(deltaTime, deltaX, deltaY);
  24300. velocityX = v.x;
  24301. velocityY = v.y;
  24302. velocity = (abs(v.x) > abs(v.y)) ? v.x : v.y;
  24303. direction = getDirection(deltaX, deltaY);
  24304. session.lastInterval = input;
  24305. } else {
  24306. // use latest velocity info if it doesn't overtake a minimum period
  24307. velocity = last.velocity;
  24308. velocityX = last.velocityX;
  24309. velocityY = last.velocityY;
  24310. direction = last.direction;
  24311. }
  24312. input.velocity = velocity;
  24313. input.velocityX = velocityX;
  24314. input.velocityY = velocityY;
  24315. input.direction = direction;
  24316. }
  24317. /**
  24318. * create a simple clone from the input used for storage of firstInput and firstMultiple
  24319. * @param {Object} input
  24320. * @returns {Object} clonedInputData
  24321. */
  24322. function simpleCloneInputData(input) {
  24323. // make a simple copy of the pointers because we will get a reference if we don't
  24324. // we only need clientXY for the calculations
  24325. var pointers = [];
  24326. var i = 0;
  24327. while (i < input.pointers.length) {
  24328. pointers[i] = {
  24329. clientX: round(input.pointers[i].clientX),
  24330. clientY: round(input.pointers[i].clientY)
  24331. };
  24332. i++;
  24333. }
  24334. return {
  24335. timeStamp: now(),
  24336. pointers: pointers,
  24337. center: getCenter(pointers),
  24338. deltaX: input.deltaX,
  24339. deltaY: input.deltaY
  24340. };
  24341. }
  24342. /**
  24343. * get the center of all the pointers
  24344. * @param {Array} pointers
  24345. * @return {Object} center contains `x` and `y` properties
  24346. */
  24347. function getCenter(pointers) {
  24348. var pointersLength = pointers.length;
  24349. // no need to loop when only one touch
  24350. if (pointersLength === 1) {
  24351. return {
  24352. x: round(pointers[0].clientX),
  24353. y: round(pointers[0].clientY)
  24354. };
  24355. }
  24356. var x = 0, y = 0, i = 0;
  24357. while (i < pointersLength) {
  24358. x += pointers[i].clientX;
  24359. y += pointers[i].clientY;
  24360. i++;
  24361. }
  24362. return {
  24363. x: round(x / pointersLength),
  24364. y: round(y / pointersLength)
  24365. };
  24366. }
  24367. /**
  24368. * calculate the velocity between two points. unit is in px per ms.
  24369. * @param {Number} deltaTime
  24370. * @param {Number} x
  24371. * @param {Number} y
  24372. * @return {Object} velocity `x` and `y`
  24373. */
  24374. function getVelocity(deltaTime, x, y) {
  24375. return {
  24376. x: x / deltaTime || 0,
  24377. y: y / deltaTime || 0
  24378. };
  24379. }
  24380. /**
  24381. * get the direction between two points
  24382. * @param {Number} x
  24383. * @param {Number} y
  24384. * @return {Number} direction
  24385. */
  24386. function getDirection(x, y) {
  24387. if (x === y) {
  24388. return DIRECTION_NONE;
  24389. }
  24390. if (abs(x) >= abs(y)) {
  24391. return x > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
  24392. }
  24393. return y > 0 ? DIRECTION_UP : DIRECTION_DOWN;
  24394. }
  24395. /**
  24396. * calculate the absolute distance between two points
  24397. * @param {Object} p1 {x, y}
  24398. * @param {Object} p2 {x, y}
  24399. * @param {Array} [props] containing x and y keys
  24400. * @return {Number} distance
  24401. */
  24402. function getDistance(p1, p2, props) {
  24403. if (!props) {
  24404. props = PROPS_XY;
  24405. }
  24406. var x = p2[props[0]] - p1[props[0]],
  24407. y = p2[props[1]] - p1[props[1]];
  24408. return Math.sqrt((x * x) + (y * y));
  24409. }
  24410. /**
  24411. * calculate the angle between two coordinates
  24412. * @param {Object} p1
  24413. * @param {Object} p2
  24414. * @param {Array} [props] containing x and y keys
  24415. * @return {Number} angle
  24416. */
  24417. function getAngle(p1, p2, props) {
  24418. if (!props) {
  24419. props = PROPS_XY;
  24420. }
  24421. var x = p2[props[0]] - p1[props[0]],
  24422. y = p2[props[1]] - p1[props[1]];
  24423. return Math.atan2(y, x) * 180 / Math.PI;
  24424. }
  24425. /**
  24426. * calculate the rotation degrees between two pointersets
  24427. * @param {Array} start array of pointers
  24428. * @param {Array} end array of pointers
  24429. * @return {Number} rotation
  24430. */
  24431. function getRotation(start, end) {
  24432. return getAngle(end[1], end[0], PROPS_CLIENT_XY) - getAngle(start[1], start[0], PROPS_CLIENT_XY);
  24433. }
  24434. /**
  24435. * calculate the scale factor between two pointersets
  24436. * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
  24437. * @param {Array} start array of pointers
  24438. * @param {Array} end array of pointers
  24439. * @return {Number} scale
  24440. */
  24441. function getScale(start, end) {
  24442. return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
  24443. }
  24444. var MOUSE_INPUT_MAP = {
  24445. mousedown: INPUT_START,
  24446. mousemove: INPUT_MOVE,
  24447. mouseup: INPUT_END
  24448. };
  24449. var MOUSE_ELEMENT_EVENTS = 'mousedown';
  24450. var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
  24451. /**
  24452. * Mouse events input
  24453. * @constructor
  24454. * @extends Input
  24455. */
  24456. function MouseInput() {
  24457. this.evEl = MOUSE_ELEMENT_EVENTS;
  24458. this.evWin = MOUSE_WINDOW_EVENTS;
  24459. this.allow = true; // used by Input.TouchMouse to disable mouse events
  24460. this.pressed = false; // mousedown state
  24461. Input.apply(this, arguments);
  24462. }
  24463. inherit(MouseInput, Input, {
  24464. /**
  24465. * handle mouse events
  24466. * @param {Object} ev
  24467. */
  24468. handler: function MEhandler(ev) {
  24469. var eventType = MOUSE_INPUT_MAP[ev.type];
  24470. // on start we want to have the left mouse button down
  24471. if (eventType & INPUT_START && ev.button === 0) {
  24472. this.pressed = true;
  24473. }
  24474. if (eventType & INPUT_MOVE && ev.which !== 1) {
  24475. eventType = INPUT_END;
  24476. }
  24477. // mouse must be down, and mouse events are allowed (see the TouchMouse input)
  24478. if (!this.pressed || !this.allow) {
  24479. return;
  24480. }
  24481. if (eventType & INPUT_END) {
  24482. this.pressed = false;
  24483. }
  24484. this.callback(this.manager, eventType, {
  24485. pointers: [ev],
  24486. changedPointers: [ev],
  24487. pointerType: INPUT_TYPE_MOUSE,
  24488. srcEvent: ev
  24489. });
  24490. }
  24491. });
  24492. var POINTER_INPUT_MAP = {
  24493. pointerdown: INPUT_START,
  24494. pointermove: INPUT_MOVE,
  24495. pointerup: INPUT_END,
  24496. pointercancel: INPUT_CANCEL,
  24497. pointerout: INPUT_CANCEL
  24498. };
  24499. // in IE10 the pointer types is defined as an enum
  24500. var IE10_POINTER_TYPE_ENUM = {
  24501. 2: INPUT_TYPE_TOUCH,
  24502. 3: INPUT_TYPE_PEN,
  24503. 4: INPUT_TYPE_MOUSE,
  24504. 5: INPUT_TYPE_KINECT // see https://twitter.com/jacobrossi/status/480596438489890816
  24505. };
  24506. var POINTER_ELEMENT_EVENTS = 'pointerdown';
  24507. var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
  24508. // IE10 has prefixed support, and case-sensitive
  24509. if (window.MSPointerEvent) {
  24510. POINTER_ELEMENT_EVENTS = 'MSPointerDown';
  24511. POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
  24512. }
  24513. /**
  24514. * Pointer events input
  24515. * @constructor
  24516. * @extends Input
  24517. */
  24518. function PointerEventInput() {
  24519. this.evEl = POINTER_ELEMENT_EVENTS;
  24520. this.evWin = POINTER_WINDOW_EVENTS;
  24521. Input.apply(this, arguments);
  24522. this.store = (this.manager.session.pointerEvents = []);
  24523. }
  24524. inherit(PointerEventInput, Input, {
  24525. /**
  24526. * handle mouse events
  24527. * @param {Object} ev
  24528. */
  24529. handler: function PEhandler(ev) {
  24530. var store = this.store;
  24531. var removePointer = false;
  24532. var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
  24533. var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
  24534. var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
  24535. var isTouch = (pointerType == INPUT_TYPE_TOUCH);
  24536. // get index of the event in the store
  24537. var storeIndex = inArray(store, ev.pointerId, 'pointerId');
  24538. // start and mouse must be down
  24539. if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
  24540. if (storeIndex < 0) {
  24541. store.push(ev);
  24542. storeIndex = store.length - 1;
  24543. }
  24544. } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
  24545. removePointer = true;
  24546. }
  24547. // it not found, so the pointer hasn't been down (so it's probably a hover)
  24548. if (storeIndex < 0) {
  24549. return;
  24550. }
  24551. // update the event in the store
  24552. store[storeIndex] = ev;
  24553. this.callback(this.manager, eventType, {
  24554. pointers: store,
  24555. changedPointers: [ev],
  24556. pointerType: pointerType,
  24557. srcEvent: ev
  24558. });
  24559. if (removePointer) {
  24560. // remove from the store
  24561. store.splice(storeIndex, 1);
  24562. }
  24563. }
  24564. });
  24565. var SINGLE_TOUCH_INPUT_MAP = {
  24566. touchstart: INPUT_START,
  24567. touchmove: INPUT_MOVE,
  24568. touchend: INPUT_END,
  24569. touchcancel: INPUT_CANCEL
  24570. };
  24571. var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
  24572. var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
  24573. /**
  24574. * Touch events input
  24575. * @constructor
  24576. * @extends Input
  24577. */
  24578. function SingleTouchInput() {
  24579. this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
  24580. this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
  24581. this.started = false;
  24582. Input.apply(this, arguments);
  24583. }
  24584. inherit(SingleTouchInput, Input, {
  24585. handler: function TEhandler(ev) {
  24586. var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
  24587. // should we handle the touch events?
  24588. if (type === INPUT_START) {
  24589. this.started = true;
  24590. }
  24591. if (!this.started) {
  24592. return;
  24593. }
  24594. var touches = normalizeSingleTouches.call(this, ev, type);
  24595. // when done, reset the started state
  24596. if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
  24597. this.started = false;
  24598. }
  24599. this.callback(this.manager, type, {
  24600. pointers: touches[0],
  24601. changedPointers: touches[1],
  24602. pointerType: INPUT_TYPE_TOUCH,
  24603. srcEvent: ev
  24604. });
  24605. }
  24606. });
  24607. /**
  24608. * @this {TouchInput}
  24609. * @param {Object} ev
  24610. * @param {Number} type flag
  24611. * @returns {undefined|Array} [all, changed]
  24612. */
  24613. function normalizeSingleTouches(ev, type) {
  24614. var all = toArray(ev.touches);
  24615. var changed = toArray(ev.changedTouches);
  24616. if (type & (INPUT_END | INPUT_CANCEL)) {
  24617. all = uniqueArray(all.concat(changed), 'identifier', true);
  24618. }
  24619. return [all, changed];
  24620. }
  24621. var TOUCH_INPUT_MAP = {
  24622. touchstart: INPUT_START,
  24623. touchmove: INPUT_MOVE,
  24624. touchend: INPUT_END,
  24625. touchcancel: INPUT_CANCEL
  24626. };
  24627. var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
  24628. /**
  24629. * Multi-user touch events input
  24630. * @constructor
  24631. * @extends Input
  24632. */
  24633. function TouchInput() {
  24634. this.evTarget = TOUCH_TARGET_EVENTS;
  24635. this.targetIds = {};
  24636. Input.apply(this, arguments);
  24637. }
  24638. inherit(TouchInput, Input, {
  24639. handler: function MTEhandler(ev) {
  24640. var type = TOUCH_INPUT_MAP[ev.type];
  24641. var touches = getTouches.call(this, ev, type);
  24642. if (!touches) {
  24643. return;
  24644. }
  24645. this.callback(this.manager, type, {
  24646. pointers: touches[0],
  24647. changedPointers: touches[1],
  24648. pointerType: INPUT_TYPE_TOUCH,
  24649. srcEvent: ev
  24650. });
  24651. }
  24652. });
  24653. /**
  24654. * @this {TouchInput}
  24655. * @param {Object} ev
  24656. * @param {Number} type flag
  24657. * @returns {undefined|Array} [all, changed]
  24658. */
  24659. function getTouches(ev, type) {
  24660. var allTouches = toArray(ev.touches);
  24661. var targetIds = this.targetIds;
  24662. // when there is only one touch, the process can be simplified
  24663. if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
  24664. targetIds[allTouches[0].identifier] = true;
  24665. return [allTouches, allTouches];
  24666. }
  24667. var i,
  24668. targetTouches,
  24669. changedTouches = toArray(ev.changedTouches),
  24670. changedTargetTouches = [],
  24671. target = this.target;
  24672. // get target touches from touches
  24673. targetTouches = allTouches.filter(function(touch) {
  24674. return hasParent(touch.target, target);
  24675. });
  24676. // collect touches
  24677. if (type === INPUT_START) {
  24678. i = 0;
  24679. while (i < targetTouches.length) {
  24680. targetIds[targetTouches[i].identifier] = true;
  24681. i++;
  24682. }
  24683. }
  24684. // filter changed touches to only contain touches that exist in the collected target ids
  24685. i = 0;
  24686. while (i < changedTouches.length) {
  24687. if (targetIds[changedTouches[i].identifier]) {
  24688. changedTargetTouches.push(changedTouches[i]);
  24689. }
  24690. // cleanup removed touches
  24691. if (type & (INPUT_END | INPUT_CANCEL)) {
  24692. delete targetIds[changedTouches[i].identifier];
  24693. }
  24694. i++;
  24695. }
  24696. if (!changedTargetTouches.length) {
  24697. return;
  24698. }
  24699. return [
  24700. // merge targetTouches with changedTargetTouches so it contains ALL touches, including 'end' and 'cancel'
  24701. uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true),
  24702. changedTargetTouches
  24703. ];
  24704. }
  24705. /**
  24706. * Combined touch and mouse input
  24707. *
  24708. * Touch has a higher priority then mouse, and while touching no mouse events are allowed.
  24709. * This because touch devices also emit mouse events while doing a touch.
  24710. *
  24711. * @constructor
  24712. * @extends Input
  24713. */
  24714. function TouchMouseInput() {
  24715. Input.apply(this, arguments);
  24716. var handler = bindFn(this.handler, this);
  24717. this.touch = new TouchInput(this.manager, handler);
  24718. this.mouse = new MouseInput(this.manager, handler);
  24719. }
  24720. inherit(TouchMouseInput, Input, {
  24721. /**
  24722. * handle mouse and touch events
  24723. * @param {Hammer} manager
  24724. * @param {String} inputEvent
  24725. * @param {Object} inputData
  24726. */
  24727. handler: function TMEhandler(manager, inputEvent, inputData) {
  24728. var isTouch = (inputData.pointerType == INPUT_TYPE_TOUCH),
  24729. isMouse = (inputData.pointerType == INPUT_TYPE_MOUSE);
  24730. // when we're in a touch event, so block all upcoming mouse events
  24731. // most mobile browser also emit mouseevents, right after touchstart
  24732. if (isTouch) {
  24733. this.mouse.allow = false;
  24734. } else if (isMouse && !this.mouse.allow) {
  24735. return;
  24736. }
  24737. // reset the allowMouse when we're done
  24738. if (inputEvent & (INPUT_END | INPUT_CANCEL)) {
  24739. this.mouse.allow = true;
  24740. }
  24741. this.callback(manager, inputEvent, inputData);
  24742. },
  24743. /**
  24744. * remove the event listeners
  24745. */
  24746. destroy: function destroy() {
  24747. this.touch.destroy();
  24748. this.mouse.destroy();
  24749. }
  24750. });
  24751. var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
  24752. var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
  24753. // magical touchAction value
  24754. var TOUCH_ACTION_COMPUTE = 'compute';
  24755. var TOUCH_ACTION_AUTO = 'auto';
  24756. var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented
  24757. var TOUCH_ACTION_NONE = 'none';
  24758. var TOUCH_ACTION_PAN_X = 'pan-x';
  24759. var TOUCH_ACTION_PAN_Y = 'pan-y';
  24760. /**
  24761. * Touch Action
  24762. * sets the touchAction property or uses the js alternative
  24763. * @param {Manager} manager
  24764. * @param {String} value
  24765. * @constructor
  24766. */
  24767. function TouchAction(manager, value) {
  24768. this.manager = manager;
  24769. this.set(value);
  24770. }
  24771. TouchAction.prototype = {
  24772. /**
  24773. * set the touchAction value on the element or enable the polyfill
  24774. * @param {String} value
  24775. */
  24776. set: function(value) {
  24777. // find out the touch-action by the event handlers
  24778. if (value == TOUCH_ACTION_COMPUTE) {
  24779. value = this.compute();
  24780. }
  24781. if (NATIVE_TOUCH_ACTION) {
  24782. this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
  24783. }
  24784. this.actions = value.toLowerCase().trim();
  24785. },
  24786. /**
  24787. * just re-set the touchAction value
  24788. */
  24789. update: function() {
  24790. this.set(this.manager.options.touchAction);
  24791. },
  24792. /**
  24793. * compute the value for the touchAction property based on the recognizer's settings
  24794. * @returns {String} value
  24795. */
  24796. compute: function() {
  24797. var actions = [];
  24798. each(this.manager.recognizers, function(recognizer) {
  24799. if (boolOrFn(recognizer.options.enable, [recognizer])) {
  24800. actions = actions.concat(recognizer.getTouchAction());
  24801. }
  24802. });
  24803. return cleanTouchActions(actions.join(' '));
  24804. },
  24805. /**
  24806. * this method is called on each input cycle and provides the preventing of the browser behavior
  24807. * @param {Object} input
  24808. */
  24809. preventDefaults: function(input) {
  24810. // not needed with native support for the touchAction property
  24811. if (NATIVE_TOUCH_ACTION) {
  24812. return;
  24813. }
  24814. var srcEvent = input.srcEvent;
  24815. var direction = input.offsetDirection;
  24816. // if the touch action did prevented once this session
  24817. if (this.manager.session.prevented) {
  24818. srcEvent.preventDefault();
  24819. return;
  24820. }
  24821. var actions = this.actions;
  24822. var hasNone = inStr(actions, TOUCH_ACTION_NONE);
  24823. var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
  24824. var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
  24825. if (hasNone ||
  24826. (hasPanY && direction & DIRECTION_HORIZONTAL) ||
  24827. (hasPanX && direction & DIRECTION_VERTICAL)) {
  24828. return this.preventSrc(srcEvent);
  24829. }
  24830. },
  24831. /**
  24832. * call preventDefault to prevent the browser's default behavior (scrolling in most cases)
  24833. * @param {Object} srcEvent
  24834. */
  24835. preventSrc: function(srcEvent) {
  24836. this.manager.session.prevented = true;
  24837. srcEvent.preventDefault();
  24838. }
  24839. };
  24840. /**
  24841. * when the touchActions are collected they are not a valid value, so we need to clean things up. *
  24842. * @param {String} actions
  24843. * @returns {*}
  24844. */
  24845. function cleanTouchActions(actions) {
  24846. // none
  24847. if (inStr(actions, TOUCH_ACTION_NONE)) {
  24848. return TOUCH_ACTION_NONE;
  24849. }
  24850. var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
  24851. var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
  24852. // pan-x and pan-y can be combined
  24853. if (hasPanX && hasPanY) {
  24854. return TOUCH_ACTION_PAN_X + ' ' + TOUCH_ACTION_PAN_Y;
  24855. }
  24856. // pan-x OR pan-y
  24857. if (hasPanX || hasPanY) {
  24858. return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
  24859. }
  24860. // manipulation
  24861. if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
  24862. return TOUCH_ACTION_MANIPULATION;
  24863. }
  24864. return TOUCH_ACTION_AUTO;
  24865. }
  24866. /**
  24867. * Recognizer flow explained; *
  24868. * All recognizers have the initial state of POSSIBLE when a input session starts.
  24869. * The definition of a input session is from the first input until the last input, with all it's movement in it. *
  24870. * Example session for mouse-input: mousedown -> mousemove -> mouseup
  24871. *
  24872. * On each recognizing cycle (see Manager.recognize) the .recognize() method is executed
  24873. * which determines with state it should be.
  24874. *
  24875. * If the recognizer has the state FAILED, CANCELLED or RECOGNIZED (equals ENDED), it is reset to
  24876. * POSSIBLE to give it another change on the next cycle.
  24877. *
  24878. * Possible
  24879. * |
  24880. * +-----+---------------+
  24881. * | |
  24882. * +-----+-----+ |
  24883. * | | |
  24884. * Failed Cancelled |
  24885. * +-------+------+
  24886. * | |
  24887. * Recognized Began
  24888. * |
  24889. * Changed
  24890. * |
  24891. * Ended/Recognized
  24892. */
  24893. var STATE_POSSIBLE = 1;
  24894. var STATE_BEGAN = 2;
  24895. var STATE_CHANGED = 4;
  24896. var STATE_ENDED = 8;
  24897. var STATE_RECOGNIZED = STATE_ENDED;
  24898. var STATE_CANCELLED = 16;
  24899. var STATE_FAILED = 32;
  24900. /**
  24901. * Recognizer
  24902. * Every recognizer needs to extend from this class.
  24903. * @constructor
  24904. * @param {Object} options
  24905. */
  24906. function Recognizer(options) {
  24907. this.id = uniqueId();
  24908. this.manager = null;
  24909. this.options = merge(options || {}, this.defaults);
  24910. // default is enable true
  24911. this.options.enable = ifUndefined(this.options.enable, true);
  24912. this.state = STATE_POSSIBLE;
  24913. this.simultaneous = {};
  24914. this.requireFail = [];
  24915. }
  24916. Recognizer.prototype = {
  24917. /**
  24918. * @virtual
  24919. * @type {Object}
  24920. */
  24921. defaults: {},
  24922. /**
  24923. * set options
  24924. * @param {Object} options
  24925. * @return {Recognizer}
  24926. */
  24927. set: function(options) {
  24928. extend(this.options, options);
  24929. // also update the touchAction, in case something changed about the directions/enabled state
  24930. this.manager && this.manager.touchAction.update();
  24931. return this;
  24932. },
  24933. /**
  24934. * recognize simultaneous with an other recognizer.
  24935. * @param {Recognizer} otherRecognizer
  24936. * @returns {Recognizer} this
  24937. */
  24938. recognizeWith: function(otherRecognizer) {
  24939. if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
  24940. return this;
  24941. }
  24942. var simultaneous = this.simultaneous;
  24943. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  24944. if (!simultaneous[otherRecognizer.id]) {
  24945. simultaneous[otherRecognizer.id] = otherRecognizer;
  24946. otherRecognizer.recognizeWith(this);
  24947. }
  24948. return this;
  24949. },
  24950. /**
  24951. * drop the simultaneous link. it doesnt remove the link on the other recognizer.
  24952. * @param {Recognizer} otherRecognizer
  24953. * @returns {Recognizer} this
  24954. */
  24955. dropRecognizeWith: function(otherRecognizer) {
  24956. if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
  24957. return this;
  24958. }
  24959. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  24960. delete this.simultaneous[otherRecognizer.id];
  24961. return this;
  24962. },
  24963. /**
  24964. * recognizer can only run when an other is failing
  24965. * @param {Recognizer} otherRecognizer
  24966. * @returns {Recognizer} this
  24967. */
  24968. requireFailure: function(otherRecognizer) {
  24969. if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
  24970. return this;
  24971. }
  24972. var requireFail = this.requireFail;
  24973. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  24974. if (inArray(requireFail, otherRecognizer) === -1) {
  24975. requireFail.push(otherRecognizer);
  24976. otherRecognizer.requireFailure(this);
  24977. }
  24978. return this;
  24979. },
  24980. /**
  24981. * drop the requireFailure link. it does not remove the link on the other recognizer.
  24982. * @param {Recognizer} otherRecognizer
  24983. * @returns {Recognizer} this
  24984. */
  24985. dropRequireFailure: function(otherRecognizer) {
  24986. if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
  24987. return this;
  24988. }
  24989. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  24990. var index = inArray(this.requireFail, otherRecognizer);
  24991. if (index > -1) {
  24992. this.requireFail.splice(index, 1);
  24993. }
  24994. return this;
  24995. },
  24996. /**
  24997. * has require failures boolean
  24998. * @returns {boolean}
  24999. */
  25000. hasRequireFailures: function() {
  25001. return this.requireFail.length > 0;
  25002. },
  25003. /**
  25004. * if the recognizer can recognize simultaneous with an other recognizer
  25005. * @param {Recognizer} otherRecognizer
  25006. * @returns {Boolean}
  25007. */
  25008. canRecognizeWith: function(otherRecognizer) {
  25009. return !!this.simultaneous[otherRecognizer.id];
  25010. },
  25011. /**
  25012. * You should use `tryEmit` instead of `emit` directly to check
  25013. * that all the needed recognizers has failed before emitting.
  25014. * @param {Object} input
  25015. */
  25016. emit: function(input) {
  25017. var self = this;
  25018. var state = this.state;
  25019. function emit(withState) {
  25020. self.manager.emit(self.options.event + (withState ? stateStr(state) : ''), input);
  25021. }
  25022. // 'panstart' and 'panmove'
  25023. if (state < STATE_ENDED) {
  25024. emit(true);
  25025. }
  25026. emit(); // simple 'eventName' events
  25027. // panend and pancancel
  25028. if (state >= STATE_ENDED) {
  25029. emit(true);
  25030. }
  25031. },
  25032. /**
  25033. * Check that all the require failure recognizers has failed,
  25034. * if true, it emits a gesture event,
  25035. * otherwise, setup the state to FAILED.
  25036. * @param {Object} input
  25037. */
  25038. tryEmit: function(input) {
  25039. if (this.canEmit()) {
  25040. return this.emit(input);
  25041. }
  25042. // it's failing anyway
  25043. this.state = STATE_FAILED;
  25044. },
  25045. /**
  25046. * can we emit?
  25047. * @returns {boolean}
  25048. */
  25049. canEmit: function() {
  25050. var i = 0;
  25051. while (i < this.requireFail.length) {
  25052. if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
  25053. return false;
  25054. }
  25055. i++;
  25056. }
  25057. return true;
  25058. },
  25059. /**
  25060. * update the recognizer
  25061. * @param {Object} inputData
  25062. */
  25063. recognize: function(inputData) {
  25064. // make a new copy of the inputData
  25065. // so we can change the inputData without messing up the other recognizers
  25066. var inputDataClone = extend({}, inputData);
  25067. // is is enabled and allow recognizing?
  25068. if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
  25069. this.reset();
  25070. this.state = STATE_FAILED;
  25071. return;
  25072. }
  25073. // reset when we've reached the end
  25074. if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
  25075. this.state = STATE_POSSIBLE;
  25076. }
  25077. this.state = this.process(inputDataClone);
  25078. // the recognizer has recognized a gesture
  25079. // so trigger an event
  25080. if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
  25081. this.tryEmit(inputDataClone);
  25082. }
  25083. },
  25084. /**
  25085. * return the state of the recognizer
  25086. * the actual recognizing happens in this method
  25087. * @virtual
  25088. * @param {Object} inputData
  25089. * @returns {Const} STATE
  25090. */
  25091. process: function(inputData) { }, // jshint ignore:line
  25092. /**
  25093. * return the preferred touch-action
  25094. * @virtual
  25095. * @returns {Array}
  25096. */
  25097. getTouchAction: function() { },
  25098. /**
  25099. * called when the gesture isn't allowed to recognize
  25100. * like when another is being recognized or it is disabled
  25101. * @virtual
  25102. */
  25103. reset: function() { }
  25104. };
  25105. /**
  25106. * get a usable string, used as event postfix
  25107. * @param {Const} state
  25108. * @returns {String} state
  25109. */
  25110. function stateStr(state) {
  25111. if (state & STATE_CANCELLED) {
  25112. return 'cancel';
  25113. } else if (state & STATE_ENDED) {
  25114. return 'end';
  25115. } else if (state & STATE_CHANGED) {
  25116. return 'move';
  25117. } else if (state & STATE_BEGAN) {
  25118. return 'start';
  25119. }
  25120. return '';
  25121. }
  25122. /**
  25123. * direction cons to string
  25124. * @param {Const} direction
  25125. * @returns {String}
  25126. */
  25127. function directionStr(direction) {
  25128. if (direction == DIRECTION_DOWN) {
  25129. return 'down';
  25130. } else if (direction == DIRECTION_UP) {
  25131. return 'up';
  25132. } else if (direction == DIRECTION_LEFT) {
  25133. return 'left';
  25134. } else if (direction == DIRECTION_RIGHT) {
  25135. return 'right';
  25136. }
  25137. return '';
  25138. }
  25139. /**
  25140. * get a recognizer by name if it is bound to a manager
  25141. * @param {Recognizer|String} otherRecognizer
  25142. * @param {Recognizer} recognizer
  25143. * @returns {Recognizer}
  25144. */
  25145. function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
  25146. var manager = recognizer.manager;
  25147. if (manager) {
  25148. return manager.get(otherRecognizer);
  25149. }
  25150. return otherRecognizer;
  25151. }
  25152. /**
  25153. * This recognizer is just used as a base for the simple attribute recognizers.
  25154. * @constructor
  25155. * @extends Recognizer
  25156. */
  25157. function AttrRecognizer() {
  25158. Recognizer.apply(this, arguments);
  25159. }
  25160. inherit(AttrRecognizer, Recognizer, {
  25161. /**
  25162. * @namespace
  25163. * @memberof AttrRecognizer
  25164. */
  25165. defaults: {
  25166. /**
  25167. * @type {Number}
  25168. * @default 1
  25169. */
  25170. pointers: 1
  25171. },
  25172. /**
  25173. * Used to check if it the recognizer receives valid input, like input.distance > 10.
  25174. * @memberof AttrRecognizer
  25175. * @param {Object} input
  25176. * @returns {Boolean} recognized
  25177. */
  25178. attrTest: function(input) {
  25179. var optionPointers = this.options.pointers;
  25180. return optionPointers === 0 || input.pointers.length === optionPointers;
  25181. },
  25182. /**
  25183. * Process the input and return the state for the recognizer
  25184. * @memberof AttrRecognizer
  25185. * @param {Object} input
  25186. * @returns {*} State
  25187. */
  25188. process: function(input) {
  25189. var state = this.state;
  25190. var eventType = input.eventType;
  25191. var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
  25192. var isValid = this.attrTest(input);
  25193. // on cancel input and we've recognized before, return STATE_CANCELLED
  25194. if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
  25195. return state | STATE_CANCELLED;
  25196. } else if (isRecognized || isValid) {
  25197. if (eventType & INPUT_END) {
  25198. return state | STATE_ENDED;
  25199. } else if (!(state & STATE_BEGAN)) {
  25200. return STATE_BEGAN;
  25201. }
  25202. return state | STATE_CHANGED;
  25203. }
  25204. return STATE_FAILED;
  25205. }
  25206. });
  25207. /**
  25208. * Pan
  25209. * Recognized when the pointer is down and moved in the allowed direction.
  25210. * @constructor
  25211. * @extends AttrRecognizer
  25212. */
  25213. function PanRecognizer() {
  25214. AttrRecognizer.apply(this, arguments);
  25215. this.pX = null;
  25216. this.pY = null;
  25217. }
  25218. inherit(PanRecognizer, AttrRecognizer, {
  25219. /**
  25220. * @namespace
  25221. * @memberof PanRecognizer
  25222. */
  25223. defaults: {
  25224. event: 'pan',
  25225. threshold: 10,
  25226. pointers: 1,
  25227. direction: DIRECTION_ALL
  25228. },
  25229. getTouchAction: function() {
  25230. var direction = this.options.direction;
  25231. var actions = [];
  25232. if (direction & DIRECTION_HORIZONTAL) {
  25233. actions.push(TOUCH_ACTION_PAN_Y);
  25234. }
  25235. if (direction & DIRECTION_VERTICAL) {
  25236. actions.push(TOUCH_ACTION_PAN_X);
  25237. }
  25238. return actions;
  25239. },
  25240. directionTest: function(input) {
  25241. var options = this.options;
  25242. var hasMoved = true;
  25243. var distance = input.distance;
  25244. var direction = input.direction;
  25245. var x = input.deltaX;
  25246. var y = input.deltaY;
  25247. // lock to axis?
  25248. if (!(direction & options.direction)) {
  25249. if (options.direction & DIRECTION_HORIZONTAL) {
  25250. direction = (x === 0) ? DIRECTION_NONE : (x < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT;
  25251. hasMoved = x != this.pX;
  25252. distance = Math.abs(input.deltaX);
  25253. } else {
  25254. direction = (y === 0) ? DIRECTION_NONE : (y < 0) ? DIRECTION_UP : DIRECTION_DOWN;
  25255. hasMoved = y != this.pY;
  25256. distance = Math.abs(input.deltaY);
  25257. }
  25258. }
  25259. input.direction = direction;
  25260. return hasMoved && distance > options.threshold && direction & options.direction;
  25261. },
  25262. attrTest: function(input) {
  25263. return AttrRecognizer.prototype.attrTest.call(this, input) &&
  25264. (this.state & STATE_BEGAN || (!(this.state & STATE_BEGAN) && this.directionTest(input)));
  25265. },
  25266. emit: function(input) {
  25267. this.pX = input.deltaX;
  25268. this.pY = input.deltaY;
  25269. var direction = directionStr(input.direction);
  25270. if (direction) {
  25271. this.manager.emit(this.options.event + direction, input);
  25272. }
  25273. this._super.emit.call(this, input);
  25274. }
  25275. });
  25276. /**
  25277. * Pinch
  25278. * Recognized when two or more pointers are moving toward (zoom-in) or away from each other (zoom-out).
  25279. * @constructor
  25280. * @extends AttrRecognizer
  25281. */
  25282. function PinchRecognizer() {
  25283. AttrRecognizer.apply(this, arguments);
  25284. }
  25285. inherit(PinchRecognizer, AttrRecognizer, {
  25286. /**
  25287. * @namespace
  25288. * @memberof PinchRecognizer
  25289. */
  25290. defaults: {
  25291. event: 'pinch',
  25292. threshold: 0,
  25293. pointers: 2
  25294. },
  25295. getTouchAction: function() {
  25296. return [TOUCH_ACTION_NONE];
  25297. },
  25298. attrTest: function(input) {
  25299. return this._super.attrTest.call(this, input) &&
  25300. (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
  25301. },
  25302. emit: function(input) {
  25303. this._super.emit.call(this, input);
  25304. if (input.scale !== 1) {
  25305. var inOut = input.scale < 1 ? 'in' : 'out';
  25306. this.manager.emit(this.options.event + inOut, input);
  25307. }
  25308. }
  25309. });
  25310. /**
  25311. * Press
  25312. * Recognized when the pointer is down for x ms without any movement.
  25313. * @constructor
  25314. * @extends Recognizer
  25315. */
  25316. function PressRecognizer() {
  25317. Recognizer.apply(this, arguments);
  25318. this._timer = null;
  25319. this._input = null;
  25320. }
  25321. inherit(PressRecognizer, Recognizer, {
  25322. /**
  25323. * @namespace
  25324. * @memberof PressRecognizer
  25325. */
  25326. defaults: {
  25327. event: 'press',
  25328. pointers: 1,
  25329. time: 500, // minimal time of the pointer to be pressed
  25330. threshold: 5 // a minimal movement is ok, but keep it low
  25331. },
  25332. getTouchAction: function() {
  25333. return [TOUCH_ACTION_AUTO];
  25334. },
  25335. process: function(input) {
  25336. var options = this.options;
  25337. var validPointers = input.pointers.length === options.pointers;
  25338. var validMovement = input.distance < options.threshold;
  25339. var validTime = input.deltaTime > options.time;
  25340. this._input = input;
  25341. // we only allow little movement
  25342. // and we've reached an end event, so a tap is possible
  25343. if (!validMovement || !validPointers || (input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime)) {
  25344. this.reset();
  25345. } else if (input.eventType & INPUT_START) {
  25346. this.reset();
  25347. this._timer = setTimeoutContext(function() {
  25348. this.state = STATE_RECOGNIZED;
  25349. this.tryEmit();
  25350. }, options.time, this);
  25351. } else if (input.eventType & INPUT_END) {
  25352. return STATE_RECOGNIZED;
  25353. }
  25354. return STATE_FAILED;
  25355. },
  25356. reset: function() {
  25357. clearTimeout(this._timer);
  25358. },
  25359. emit: function(input) {
  25360. if (this.state !== STATE_RECOGNIZED) {
  25361. return;
  25362. }
  25363. if (input && (input.eventType & INPUT_END)) {
  25364. this.manager.emit(this.options.event + 'up', input);
  25365. } else {
  25366. this._input.timeStamp = now();
  25367. this.manager.emit(this.options.event, this._input);
  25368. }
  25369. }
  25370. });
  25371. /**
  25372. * Rotate
  25373. * Recognized when two or more pointer are moving in a circular motion.
  25374. * @constructor
  25375. * @extends AttrRecognizer
  25376. */
  25377. function RotateRecognizer() {
  25378. AttrRecognizer.apply(this, arguments);
  25379. }
  25380. inherit(RotateRecognizer, AttrRecognizer, {
  25381. /**
  25382. * @namespace
  25383. * @memberof RotateRecognizer
  25384. */
  25385. defaults: {
  25386. event: 'rotate',
  25387. threshold: 0,
  25388. pointers: 2
  25389. },
  25390. getTouchAction: function() {
  25391. return [TOUCH_ACTION_NONE];
  25392. },
  25393. attrTest: function(input) {
  25394. return this._super.attrTest.call(this, input) &&
  25395. (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
  25396. }
  25397. });
  25398. /**
  25399. * Swipe
  25400. * Recognized when the pointer is moving fast (velocity), with enough distance in the allowed direction.
  25401. * @constructor
  25402. * @extends AttrRecognizer
  25403. */
  25404. function SwipeRecognizer() {
  25405. AttrRecognizer.apply(this, arguments);
  25406. }
  25407. inherit(SwipeRecognizer, AttrRecognizer, {
  25408. /**
  25409. * @namespace
  25410. * @memberof SwipeRecognizer
  25411. */
  25412. defaults: {
  25413. event: 'swipe',
  25414. threshold: 10,
  25415. velocity: 0.65,
  25416. direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
  25417. pointers: 1
  25418. },
  25419. getTouchAction: function() {
  25420. return PanRecognizer.prototype.getTouchAction.call(this);
  25421. },
  25422. attrTest: function(input) {
  25423. var direction = this.options.direction;
  25424. var velocity;
  25425. if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
  25426. velocity = input.velocity;
  25427. } else if (direction & DIRECTION_HORIZONTAL) {
  25428. velocity = input.velocityX;
  25429. } else if (direction & DIRECTION_VERTICAL) {
  25430. velocity = input.velocityY;
  25431. }
  25432. return this._super.attrTest.call(this, input) &&
  25433. direction & input.direction &&
  25434. input.distance > this.options.threshold &&
  25435. abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
  25436. },
  25437. emit: function(input) {
  25438. var direction = directionStr(input.direction);
  25439. if (direction) {
  25440. this.manager.emit(this.options.event + direction, input);
  25441. }
  25442. this.manager.emit(this.options.event, input);
  25443. }
  25444. });
  25445. /**
  25446. * A tap is ecognized when the pointer is doing a small tap/click. Multiple taps are recognized if they occur
  25447. * between the given interval and position. The delay option can be used to recognize multi-taps without firing
  25448. * a single tap.
  25449. *
  25450. * The eventData from the emitted event contains the property `tapCount`, which contains the amount of
  25451. * multi-taps being recognized.
  25452. * @constructor
  25453. * @extends Recognizer
  25454. */
  25455. function TapRecognizer() {
  25456. Recognizer.apply(this, arguments);
  25457. // previous time and center,
  25458. // used for tap counting
  25459. this.pTime = false;
  25460. this.pCenter = false;
  25461. this._timer = null;
  25462. this._input = null;
  25463. this.count = 0;
  25464. }
  25465. inherit(TapRecognizer, Recognizer, {
  25466. /**
  25467. * @namespace
  25468. * @memberof PinchRecognizer
  25469. */
  25470. defaults: {
  25471. event: 'tap',
  25472. pointers: 1,
  25473. taps: 1,
  25474. interval: 300, // max time between the multi-tap taps
  25475. time: 250, // max time of the pointer to be down (like finger on the screen)
  25476. threshold: 2, // a minimal movement is ok, but keep it low
  25477. posThreshold: 10 // a multi-tap can be a bit off the initial position
  25478. },
  25479. getTouchAction: function() {
  25480. return [TOUCH_ACTION_MANIPULATION];
  25481. },
  25482. process: function(input) {
  25483. var options = this.options;
  25484. var validPointers = input.pointers.length === options.pointers;
  25485. var validMovement = input.distance < options.threshold;
  25486. var validTouchTime = input.deltaTime < options.time;
  25487. this.reset();
  25488. if ((input.eventType & INPUT_START) && (this.count === 0)) {
  25489. return this.failTimeout();
  25490. }
  25491. // we only allow little movement
  25492. // and we've reached an end event, so a tap is possible
  25493. if (validMovement && validTouchTime && validPointers) {
  25494. if (input.eventType != INPUT_END) {
  25495. return this.failTimeout();
  25496. }
  25497. var validInterval = this.pTime ? (input.timeStamp - this.pTime < options.interval) : true;
  25498. var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
  25499. this.pTime = input.timeStamp;
  25500. this.pCenter = input.center;
  25501. if (!validMultiTap || !validInterval) {
  25502. this.count = 1;
  25503. } else {
  25504. this.count += 1;
  25505. }
  25506. this._input = input;
  25507. // if tap count matches we have recognized it,
  25508. // else it has began recognizing...
  25509. var tapCount = this.count % options.taps;
  25510. if (tapCount === 0) {
  25511. // no failing requirements, immediately trigger the tap event
  25512. // or wait as long as the multitap interval to trigger
  25513. if (!this.hasRequireFailures()) {
  25514. return STATE_RECOGNIZED;
  25515. } else {
  25516. this._timer = setTimeoutContext(function() {
  25517. this.state = STATE_RECOGNIZED;
  25518. this.tryEmit();
  25519. }, options.interval, this);
  25520. return STATE_BEGAN;
  25521. }
  25522. }
  25523. }
  25524. return STATE_FAILED;
  25525. },
  25526. failTimeout: function() {
  25527. this._timer = setTimeoutContext(function() {
  25528. this.state = STATE_FAILED;
  25529. }, this.options.interval, this);
  25530. return STATE_FAILED;
  25531. },
  25532. reset: function() {
  25533. clearTimeout(this._timer);
  25534. },
  25535. emit: function() {
  25536. if (this.state == STATE_RECOGNIZED ) {
  25537. this._input.tapCount = this.count;
  25538. this.manager.emit(this.options.event, this._input);
  25539. }
  25540. }
  25541. });
  25542. /**
  25543. * Simple way to create an manager with a default set of recognizers.
  25544. * @param {HTMLElement} element
  25545. * @param {Object} [options]
  25546. * @constructor
  25547. */
  25548. function Hammer(element, options) {
  25549. options = options || {};
  25550. options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
  25551. return new Manager(element, options);
  25552. }
  25553. /**
  25554. * @const {string}
  25555. */
  25556. Hammer.VERSION = '2.0.4';
  25557. /**
  25558. * default settings
  25559. * @namespace
  25560. */
  25561. Hammer.defaults = {
  25562. /**
  25563. * set if DOM events are being triggered.
  25564. * But this is slower and unused by simple implementations, so disabled by default.
  25565. * @type {Boolean}
  25566. * @default false
  25567. */
  25568. domEvents: false,
  25569. /**
  25570. * The value for the touchAction property/fallback.
  25571. * When set to `compute` it will magically set the correct value based on the added recognizers.
  25572. * @type {String}
  25573. * @default compute
  25574. */
  25575. touchAction: TOUCH_ACTION_COMPUTE,
  25576. /**
  25577. * @type {Boolean}
  25578. * @default true
  25579. */
  25580. enable: true,
  25581. /**
  25582. * EXPERIMENTAL FEATURE -- can be removed/changed
  25583. * Change the parent input target element.
  25584. * If Null, then it is being set the to main element.
  25585. * @type {Null|EventTarget}
  25586. * @default null
  25587. */
  25588. inputTarget: null,
  25589. /**
  25590. * force an input class
  25591. * @type {Null|Function}
  25592. * @default null
  25593. */
  25594. inputClass: null,
  25595. /**
  25596. * Default recognizer setup when calling `Hammer()`
  25597. * When creating a new Manager these will be skipped.
  25598. * @type {Array}
  25599. */
  25600. preset: [
  25601. // RecognizerClass, options, [recognizeWith, ...], [requireFailure, ...]
  25602. [RotateRecognizer, { enable: false }],
  25603. [PinchRecognizer, { enable: false }, ['rotate']],
  25604. [SwipeRecognizer,{ direction: DIRECTION_HORIZONTAL }],
  25605. [PanRecognizer, { direction: DIRECTION_HORIZONTAL }, ['swipe']],
  25606. [TapRecognizer],
  25607. [TapRecognizer, { event: 'doubletap', taps: 2 }, ['tap']],
  25608. [PressRecognizer]
  25609. ],
  25610. /**
  25611. * Some CSS properties can be used to improve the working of Hammer.
  25612. * Add them to this method and they will be set when creating a new Manager.
  25613. * @namespace
  25614. */
  25615. cssProps: {
  25616. /**
  25617. * Disables text selection to improve the dragging gesture. Mainly for desktop browsers.
  25618. * @type {String}
  25619. * @default 'none'
  25620. */
  25621. userSelect: 'none',
  25622. /**
  25623. * Disable the Windows Phone grippers when pressing an element.
  25624. * @type {String}
  25625. * @default 'none'
  25626. */
  25627. touchSelect: 'none',
  25628. /**
  25629. * Disables the default callout shown when you touch and hold a touch target.
  25630. * On iOS, when you touch and hold a touch target such as a link, Safari displays
  25631. * a callout containing information about the link. This property allows you to disable that callout.
  25632. * @type {String}
  25633. * @default 'none'
  25634. */
  25635. touchCallout: 'none',
  25636. /**
  25637. * Specifies whether zooming is enabled. Used by IE10>
  25638. * @type {String}
  25639. * @default 'none'
  25640. */
  25641. contentZooming: 'none',
  25642. /**
  25643. * Specifies that an entire element should be draggable instead of its contents. Mainly for desktop browsers.
  25644. * @type {String}
  25645. * @default 'none'
  25646. */
  25647. userDrag: 'none',
  25648. /**
  25649. * Overrides the highlight color shown when the user taps a link or a JavaScript
  25650. * clickable element in iOS. This property obeys the alpha value, if specified.
  25651. * @type {String}
  25652. * @default 'rgba(0,0,0,0)'
  25653. */
  25654. tapHighlightColor: 'rgba(0,0,0,0)'
  25655. }
  25656. };
  25657. var STOP = 1;
  25658. var FORCED_STOP = 2;
  25659. /**
  25660. * Manager
  25661. * @param {HTMLElement} element
  25662. * @param {Object} [options]
  25663. * @constructor
  25664. */
  25665. function Manager(element, options) {
  25666. options = options || {};
  25667. this.options = merge(options, Hammer.defaults);
  25668. this.options.inputTarget = this.options.inputTarget || element;
  25669. this.handlers = {};
  25670. this.session = {};
  25671. this.recognizers = [];
  25672. this.element = element;
  25673. this.input = createInputInstance(this);
  25674. this.touchAction = new TouchAction(this, this.options.touchAction);
  25675. toggleCssProps(this, true);
  25676. each(options.recognizers, function(item) {
  25677. var recognizer = this.add(new (item[0])(item[1]));
  25678. item[2] && recognizer.recognizeWith(item[2]);
  25679. item[3] && recognizer.requireFailure(item[3]);
  25680. }, this);
  25681. }
  25682. Manager.prototype = {
  25683. /**
  25684. * set options
  25685. * @param {Object} options
  25686. * @returns {Manager}
  25687. */
  25688. set: function(options) {
  25689. extend(this.options, options);
  25690. // Options that need a little more setup
  25691. if (options.touchAction) {
  25692. this.touchAction.update();
  25693. }
  25694. if (options.inputTarget) {
  25695. // Clean up existing event listeners and reinitialize
  25696. this.input.destroy();
  25697. this.input.target = options.inputTarget;
  25698. this.input.init();
  25699. }
  25700. return this;
  25701. },
  25702. /**
  25703. * stop recognizing for this session.
  25704. * This session will be discarded, when a new [input]start event is fired.
  25705. * When forced, the recognizer cycle is stopped immediately.
  25706. * @param {Boolean} [force]
  25707. */
  25708. stop: function(force) {
  25709. this.session.stopped = force ? FORCED_STOP : STOP;
  25710. },
  25711. /**
  25712. * run the recognizers!
  25713. * called by the inputHandler function on every movement of the pointers (touches)
  25714. * it walks through all the recognizers and tries to detect the gesture that is being made
  25715. * @param {Object} inputData
  25716. */
  25717. recognize: function(inputData) {
  25718. var session = this.session;
  25719. if (session.stopped) {
  25720. return;
  25721. }
  25722. // run the touch-action polyfill
  25723. this.touchAction.preventDefaults(inputData);
  25724. var recognizer;
  25725. var recognizers = this.recognizers;
  25726. // this holds the recognizer that is being recognized.
  25727. // so the recognizer's state needs to be BEGAN, CHANGED, ENDED or RECOGNIZED
  25728. // if no recognizer is detecting a thing, it is set to `null`
  25729. var curRecognizer = session.curRecognizer;
  25730. // reset when the last recognizer is recognized
  25731. // or when we're in a new session
  25732. if (!curRecognizer || (curRecognizer && curRecognizer.state & STATE_RECOGNIZED)) {
  25733. curRecognizer = session.curRecognizer = null;
  25734. }
  25735. var i = 0;
  25736. while (i < recognizers.length) {
  25737. recognizer = recognizers[i];
  25738. // find out if we are allowed try to recognize the input for this one.
  25739. // 1. allow if the session is NOT forced stopped (see the .stop() method)
  25740. // 2. allow if we still haven't recognized a gesture in this session, or the this recognizer is the one
  25741. // that is being recognized.
  25742. // 3. allow if the recognizer is allowed to run simultaneous with the current recognized recognizer.
  25743. // this can be setup with the `recognizeWith()` method on the recognizer.
  25744. if (session.stopped !== FORCED_STOP && ( // 1
  25745. !curRecognizer || recognizer == curRecognizer || // 2
  25746. recognizer.canRecognizeWith(curRecognizer))) { // 3
  25747. recognizer.recognize(inputData);
  25748. } else {
  25749. recognizer.reset();
  25750. }
  25751. // if the recognizer has been recognizing the input as a valid gesture, we want to store this one as the
  25752. // current active recognizer. but only if we don't already have an active recognizer
  25753. if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
  25754. curRecognizer = session.curRecognizer = recognizer;
  25755. }
  25756. i++;
  25757. }
  25758. },
  25759. /**
  25760. * get a recognizer by its event name.
  25761. * @param {Recognizer|String} recognizer
  25762. * @returns {Recognizer|Null}
  25763. */
  25764. get: function(recognizer) {
  25765. if (recognizer instanceof Recognizer) {
  25766. return recognizer;
  25767. }
  25768. var recognizers = this.recognizers;
  25769. for (var i = 0; i < recognizers.length; i++) {
  25770. if (recognizers[i].options.event == recognizer) {
  25771. return recognizers[i];
  25772. }
  25773. }
  25774. return null;
  25775. },
  25776. /**
  25777. * add a recognizer to the manager
  25778. * existing recognizers with the same event name will be removed
  25779. * @param {Recognizer} recognizer
  25780. * @returns {Recognizer|Manager}
  25781. */
  25782. add: function(recognizer) {
  25783. if (invokeArrayArg(recognizer, 'add', this)) {
  25784. return this;
  25785. }
  25786. // remove existing
  25787. var existing = this.get(recognizer.options.event);
  25788. if (existing) {
  25789. this.remove(existing);
  25790. }
  25791. this.recognizers.push(recognizer);
  25792. recognizer.manager = this;
  25793. this.touchAction.update();
  25794. return recognizer;
  25795. },
  25796. /**
  25797. * remove a recognizer by name or instance
  25798. * @param {Recognizer|String} recognizer
  25799. * @returns {Manager}
  25800. */
  25801. remove: function(recognizer) {
  25802. if (invokeArrayArg(recognizer, 'remove', this)) {
  25803. return this;
  25804. }
  25805. var recognizers = this.recognizers;
  25806. recognizer = this.get(recognizer);
  25807. recognizers.splice(inArray(recognizers, recognizer), 1);
  25808. this.touchAction.update();
  25809. return this;
  25810. },
  25811. /**
  25812. * bind event
  25813. * @param {String} events
  25814. * @param {Function} handler
  25815. * @returns {EventEmitter} this
  25816. */
  25817. on: function(events, handler) {
  25818. var handlers = this.handlers;
  25819. each(splitStr(events), function(event) {
  25820. handlers[event] = handlers[event] || [];
  25821. handlers[event].push(handler);
  25822. });
  25823. return this;
  25824. },
  25825. /**
  25826. * unbind event, leave emit blank to remove all handlers
  25827. * @param {String} events
  25828. * @param {Function} [handler]
  25829. * @returns {EventEmitter} this
  25830. */
  25831. off: function(events, handler) {
  25832. var handlers = this.handlers;
  25833. each(splitStr(events), function(event) {
  25834. if (!handler) {
  25835. delete handlers[event];
  25836. } else {
  25837. handlers[event].splice(inArray(handlers[event], handler), 1);
  25838. }
  25839. });
  25840. return this;
  25841. },
  25842. /**
  25843. * emit event to the listeners
  25844. * @param {String} event
  25845. * @param {Object} data
  25846. */
  25847. emit: function(event, data) {
  25848. // we also want to trigger dom events
  25849. if (this.options.domEvents) {
  25850. triggerDomEvent(event, data);
  25851. }
  25852. // no handlers, so skip it all
  25853. var handlers = this.handlers[event] && this.handlers[event].slice();
  25854. if (!handlers || !handlers.length) {
  25855. return;
  25856. }
  25857. data.type = event;
  25858. data.preventDefault = function() {
  25859. data.srcEvent.preventDefault();
  25860. };
  25861. var i = 0;
  25862. while (i < handlers.length) {
  25863. handlers[i](data);
  25864. i++;
  25865. }
  25866. },
  25867. /**
  25868. * destroy the manager and unbinds all events
  25869. * it doesn't unbind dom events, that is the user own responsibility
  25870. */
  25871. destroy: function() {
  25872. this.element && toggleCssProps(this, false);
  25873. this.handlers = {};
  25874. this.session = {};
  25875. this.input.destroy();
  25876. this.element = null;
  25877. }
  25878. };
  25879. /**
  25880. * add/remove the css properties as defined in manager.options.cssProps
  25881. * @param {Manager} manager
  25882. * @param {Boolean} add
  25883. */
  25884. function toggleCssProps(manager, add) {
  25885. var element = manager.element;
  25886. each(manager.options.cssProps, function(value, name) {
  25887. element.style[prefixed(element.style, name)] = add ? value : '';
  25888. });
  25889. }
  25890. /**
  25891. * trigger dom event
  25892. * @param {String} event
  25893. * @param {Object} data
  25894. */
  25895. function triggerDomEvent(event, data) {
  25896. var gestureEvent = document.createEvent('Event');
  25897. gestureEvent.initEvent(event, true, true);
  25898. gestureEvent.gesture = data;
  25899. data.target.dispatchEvent(gestureEvent);
  25900. }
  25901. extend(Hammer, {
  25902. INPUT_START: INPUT_START,
  25903. INPUT_MOVE: INPUT_MOVE,
  25904. INPUT_END: INPUT_END,
  25905. INPUT_CANCEL: INPUT_CANCEL,
  25906. STATE_POSSIBLE: STATE_POSSIBLE,
  25907. STATE_BEGAN: STATE_BEGAN,
  25908. STATE_CHANGED: STATE_CHANGED,
  25909. STATE_ENDED: STATE_ENDED,
  25910. STATE_RECOGNIZED: STATE_RECOGNIZED,
  25911. STATE_CANCELLED: STATE_CANCELLED,
  25912. STATE_FAILED: STATE_FAILED,
  25913. DIRECTION_NONE: DIRECTION_NONE,
  25914. DIRECTION_LEFT: DIRECTION_LEFT,
  25915. DIRECTION_RIGHT: DIRECTION_RIGHT,
  25916. DIRECTION_UP: DIRECTION_UP,
  25917. DIRECTION_DOWN: DIRECTION_DOWN,
  25918. DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
  25919. DIRECTION_VERTICAL: DIRECTION_VERTICAL,
  25920. DIRECTION_ALL: DIRECTION_ALL,
  25921. Manager: Manager,
  25922. Input: Input,
  25923. TouchAction: TouchAction,
  25924. TouchInput: TouchInput,
  25925. MouseInput: MouseInput,
  25926. PointerEventInput: PointerEventInput,
  25927. TouchMouseInput: TouchMouseInput,
  25928. SingleTouchInput: SingleTouchInput,
  25929. Recognizer: Recognizer,
  25930. AttrRecognizer: AttrRecognizer,
  25931. Tap: TapRecognizer,
  25932. Pan: PanRecognizer,
  25933. Swipe: SwipeRecognizer,
  25934. Pinch: PinchRecognizer,
  25935. Rotate: RotateRecognizer,
  25936. Press: PressRecognizer,
  25937. on: addEventListeners,
  25938. off: removeEventListeners,
  25939. each: each,
  25940. merge: merge,
  25941. extend: extend,
  25942. inherit: inherit,
  25943. bindFn: bindFn,
  25944. prefixed: prefixed
  25945. });
  25946. if (typeof define == TYPE_FUNCTION && define.amd) {
  25947. define(function() {
  25948. return Hammer;
  25949. });
  25950. } else if (typeof module != 'undefined' && module.exports) {
  25951. module.exports = Hammer;
  25952. } else {
  25953. window[exportName] = Hammer;
  25954. }
  25955. })(window, document, 'Hammer');
  25956. },{}],199:[function(_dereq_,module,exports){
  25957. // Snap.svg 0.3.0
  25958. //
  25959. // Copyright (c) 2013 – 2014 Adobe Systems Incorporated. All rights reserved.
  25960. //
  25961. // Licensed under the Apache License, Version 2.0 (the "License");
  25962. // you may not use this file except in compliance with the License.
  25963. // You may obtain a copy of the License at
  25964. //
  25965. // http://www.apache.org/licenses/LICENSE-2.0
  25966. //
  25967. // Unless required by applicable law or agreed to in writing, software
  25968. // distributed under the License is distributed on an "AS IS" BASIS,
  25969. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25970. // See the License for the specific language governing permissions and
  25971. // limitations under the License.
  25972. //
  25973. // build: 2014-09-08
  25974. (function (glob, factory) {
  25975. // AMD support
  25976. if (typeof define === "function" && define.amd) {
  25977. // Define as an anonymous module
  25978. define(["eve"], function( eve ) {
  25979. return factory(glob, eve);
  25980. });
  25981. } else if (typeof exports !== 'undefined') {
  25982. // Next for Node.js or CommonJS
  25983. var eve = _dereq_(197);
  25984. module.exports = factory(glob, eve);
  25985. } else {
  25986. // Browser globals (glob is window)
  25987. // Snap adds itself to window
  25988. factory(glob, glob.eve);
  25989. }
  25990. }(window || this, function (window, eve) {
  25991. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  25992. //
  25993. // Licensed under the Apache License, Version 2.0 (the "License");
  25994. // you may not use this file except in compliance with the License.
  25995. // You may obtain a copy of the License at
  25996. //
  25997. // http://www.apache.org/licenses/LICENSE-2.0
  25998. //
  25999. // Unless required by applicable law or agreed to in writing, software
  26000. // distributed under the License is distributed on an "AS IS" BASIS,
  26001. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  26002. // See the License for the specific language governing permissions and
  26003. // limitations under the License.
  26004. var mina = (function (eve) {
  26005. var animations = {},
  26006. requestAnimFrame = window.requestAnimationFrame ||
  26007. window.webkitRequestAnimationFrame ||
  26008. window.mozRequestAnimationFrame ||
  26009. window.oRequestAnimationFrame ||
  26010. window.msRequestAnimationFrame ||
  26011. function (callback) {
  26012. setTimeout(callback, 16);
  26013. },
  26014. isArray = Array.isArray || function (a) {
  26015. return a instanceof Array ||
  26016. Object.prototype.toString.call(a) == "[object Array]";
  26017. },
  26018. idgen = 0,
  26019. idprefix = "M" + (+new Date).toString(36),
  26020. ID = function () {
  26021. return idprefix + (idgen++).toString(36);
  26022. },
  26023. diff = function (a, b, A, B) {
  26024. if (isArray(a)) {
  26025. res = [];
  26026. for (var i = 0, ii = a.length; i < ii; i++) {
  26027. res[i] = diff(a[i], b, A[i], B);
  26028. }
  26029. return res;
  26030. }
  26031. var dif = (A - a) / (B - b);
  26032. return function (bb) {
  26033. return a + dif * (bb - b);
  26034. };
  26035. },
  26036. timer = Date.now || function () {
  26037. return +new Date;
  26038. },
  26039. sta = function (val) {
  26040. var a = this;
  26041. if (val == null) {
  26042. return a.s;
  26043. }
  26044. var ds = a.s - val;
  26045. a.b += a.dur * ds;
  26046. a.B += a.dur * ds;
  26047. a.s = val;
  26048. },
  26049. speed = function (val) {
  26050. var a = this;
  26051. if (val == null) {
  26052. return a.spd;
  26053. }
  26054. a.spd = val;
  26055. },
  26056. duration = function (val) {
  26057. var a = this;
  26058. if (val == null) {
  26059. return a.dur;
  26060. }
  26061. a.s = a.s * val / a.dur;
  26062. a.dur = val;
  26063. },
  26064. stopit = function () {
  26065. var a = this;
  26066. delete animations[a.id];
  26067. a.update();
  26068. eve("mina.stop." + a.id, a);
  26069. },
  26070. pause = function () {
  26071. var a = this;
  26072. if (a.pdif) {
  26073. return;
  26074. }
  26075. delete animations[a.id];
  26076. a.update();
  26077. a.pdif = a.get() - a.b;
  26078. },
  26079. resume = function () {
  26080. var a = this;
  26081. if (!a.pdif) {
  26082. return;
  26083. }
  26084. a.b = a.get() - a.pdif;
  26085. delete a.pdif;
  26086. animations[a.id] = a;
  26087. },
  26088. update = function () {
  26089. var a = this,
  26090. res;
  26091. if (isArray(a.start)) {
  26092. res = [];
  26093. for (var j = 0, jj = a.start.length; j < jj; j++) {
  26094. res[j] = +a.start[j] +
  26095. (a.end[j] - a.start[j]) * a.easing(a.s);
  26096. }
  26097. } else {
  26098. res = +a.start + (a.end - a.start) * a.easing(a.s);
  26099. }
  26100. a.set(res);
  26101. },
  26102. frame = function () {
  26103. var len = 0;
  26104. for (var i in animations) if (animations.hasOwnProperty(i)) {
  26105. var a = animations[i],
  26106. b = a.get(),
  26107. res;
  26108. len++;
  26109. a.s = (b - a.b) / (a.dur / a.spd);
  26110. if (a.s >= 1) {
  26111. delete animations[i];
  26112. a.s = 1;
  26113. len--;
  26114. (function (a) {
  26115. setTimeout(function () {
  26116. eve("mina.finish." + a.id, a);
  26117. });
  26118. }(a));
  26119. }
  26120. a.update();
  26121. }
  26122. len && requestAnimFrame(frame);
  26123. },
  26124. /*\
  26125. * mina
  26126. [ method ]
  26127. **
  26128. * Generic animation of numbers
  26129. **
  26130. - a (number) start _slave_ number
  26131. - A (number) end _slave_ number
  26132. - b (number) start _master_ number (start time in general case)
  26133. - B (number) end _master_ number (end time in gereal case)
  26134. - get (function) getter of _master_ number (see @mina.time)
  26135. - set (function) setter of _slave_ number
  26136. - easing (function) #optional easing function, default is @mina.linear
  26137. = (object) animation descriptor
  26138. o {
  26139. o id (string) animation id,
  26140. o start (number) start _slave_ number,
  26141. o end (number) end _slave_ number,
  26142. o b (number) start _master_ number,
  26143. o s (number) animation status (0..1),
  26144. o dur (number) animation duration,
  26145. o spd (number) animation speed,
  26146. o get (function) getter of _master_ number (see @mina.time),
  26147. o set (function) setter of _slave_ number,
  26148. o easing (function) easing function, default is @mina.linear,
  26149. o status (function) status getter/setter,
  26150. o speed (function) speed getter/setter,
  26151. o duration (function) duration getter/setter,
  26152. o stop (function) animation stopper
  26153. o pause (function) pauses the animation
  26154. o resume (function) resumes the animation
  26155. o update (function) calles setter with the right value of the animation
  26156. o }
  26157. \*/
  26158. mina = function (a, A, b, B, get, set, easing) {
  26159. var anim = {
  26160. id: ID(),
  26161. start: a,
  26162. end: A,
  26163. b: b,
  26164. s: 0,
  26165. dur: B - b,
  26166. spd: 1,
  26167. get: get,
  26168. set: set,
  26169. easing: easing || mina.linear,
  26170. status: sta,
  26171. speed: speed,
  26172. duration: duration,
  26173. stop: stopit,
  26174. pause: pause,
  26175. resume: resume,
  26176. update: update
  26177. };
  26178. animations[anim.id] = anim;
  26179. var len = 0, i;
  26180. for (i in animations) if (animations.hasOwnProperty(i)) {
  26181. len++;
  26182. if (len == 2) {
  26183. break;
  26184. }
  26185. }
  26186. len == 1 && requestAnimFrame(frame);
  26187. return anim;
  26188. };
  26189. /*\
  26190. * mina.time
  26191. [ method ]
  26192. **
  26193. * Returns the current time. Equivalent to:
  26194. | function () {
  26195. | return (new Date).getTime();
  26196. | }
  26197. \*/
  26198. mina.time = timer;
  26199. /*\
  26200. * mina.getById
  26201. [ method ]
  26202. **
  26203. * Returns an animation by its id
  26204. - id (string) animation's id
  26205. = (object) See @mina
  26206. \*/
  26207. mina.getById = function (id) {
  26208. return animations[id] || null;
  26209. };
  26210. /*\
  26211. * mina.linear
  26212. [ method ]
  26213. **
  26214. * Default linear easing
  26215. - n (number) input 0..1
  26216. = (number) output 0..1
  26217. \*/
  26218. mina.linear = function (n) {
  26219. return n;
  26220. };
  26221. /*\
  26222. * mina.easeout
  26223. [ method ]
  26224. **
  26225. * Easeout easing
  26226. - n (number) input 0..1
  26227. = (number) output 0..1
  26228. \*/
  26229. mina.easeout = function (n) {
  26230. return Math.pow(n, 1.7);
  26231. };
  26232. /*\
  26233. * mina.easein
  26234. [ method ]
  26235. **
  26236. * Easein easing
  26237. - n (number) input 0..1
  26238. = (number) output 0..1
  26239. \*/
  26240. mina.easein = function (n) {
  26241. return Math.pow(n, .48);
  26242. };
  26243. /*\
  26244. * mina.easeinout
  26245. [ method ]
  26246. **
  26247. * Easeinout easing
  26248. - n (number) input 0..1
  26249. = (number) output 0..1
  26250. \*/
  26251. mina.easeinout = function (n) {
  26252. if (n == 1) {
  26253. return 1;
  26254. }
  26255. if (n == 0) {
  26256. return 0;
  26257. }
  26258. var q = .48 - n / 1.04,
  26259. Q = Math.sqrt(.1734 + q * q),
  26260. x = Q - q,
  26261. X = Math.pow(Math.abs(x), 1 / 3) * (x < 0 ? -1 : 1),
  26262. y = -Q - q,
  26263. Y = Math.pow(Math.abs(y), 1 / 3) * (y < 0 ? -1 : 1),
  26264. t = X + Y + .5;
  26265. return (1 - t) * 3 * t * t + t * t * t;
  26266. };
  26267. /*\
  26268. * mina.backin
  26269. [ method ]
  26270. **
  26271. * Backin easing
  26272. - n (number) input 0..1
  26273. = (number) output 0..1
  26274. \*/
  26275. mina.backin = function (n) {
  26276. if (n == 1) {
  26277. return 1;
  26278. }
  26279. var s = 1.70158;
  26280. return n * n * ((s + 1) * n - s);
  26281. };
  26282. /*\
  26283. * mina.backout
  26284. [ method ]
  26285. **
  26286. * Backout easing
  26287. - n (number) input 0..1
  26288. = (number) output 0..1
  26289. \*/
  26290. mina.backout = function (n) {
  26291. if (n == 0) {
  26292. return 0;
  26293. }
  26294. n = n - 1;
  26295. var s = 1.70158;
  26296. return n * n * ((s + 1) * n + s) + 1;
  26297. };
  26298. /*\
  26299. * mina.elastic
  26300. [ method ]
  26301. **
  26302. * Elastic easing
  26303. - n (number) input 0..1
  26304. = (number) output 0..1
  26305. \*/
  26306. mina.elastic = function (n) {
  26307. if (n == !!n) {
  26308. return n;
  26309. }
  26310. return Math.pow(2, -10 * n) * Math.sin((n - .075) *
  26311. (2 * Math.PI) / .3) + 1;
  26312. };
  26313. /*\
  26314. * mina.bounce
  26315. [ method ]
  26316. **
  26317. * Bounce easing
  26318. - n (number) input 0..1
  26319. = (number) output 0..1
  26320. \*/
  26321. mina.bounce = function (n) {
  26322. var s = 7.5625,
  26323. p = 2.75,
  26324. l;
  26325. if (n < (1 / p)) {
  26326. l = s * n * n;
  26327. } else {
  26328. if (n < (2 / p)) {
  26329. n -= (1.5 / p);
  26330. l = s * n * n + .75;
  26331. } else {
  26332. if (n < (2.5 / p)) {
  26333. n -= (2.25 / p);
  26334. l = s * n * n + .9375;
  26335. } else {
  26336. n -= (2.625 / p);
  26337. l = s * n * n + .984375;
  26338. }
  26339. }
  26340. }
  26341. return l;
  26342. };
  26343. window.mina = mina;
  26344. return mina;
  26345. })(typeof eve == "undefined" ? function () {} : eve);
  26346. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  26347. //
  26348. // Licensed under the Apache License, Version 2.0 (the "License");
  26349. // you may not use this file except in compliance with the License.
  26350. // You may obtain a copy of the License at
  26351. //
  26352. // http://www.apache.org/licenses/LICENSE-2.0
  26353. //
  26354. // Unless required by applicable law or agreed to in writing, software
  26355. // distributed under the License is distributed on an "AS IS" BASIS,
  26356. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  26357. // See the License for the specific language governing permissions and
  26358. // limitations under the License.
  26359. var Snap = (function(root) {
  26360. Snap.version = "0.3.0";
  26361. /*\
  26362. * Snap
  26363. [ method ]
  26364. **
  26365. * Creates a drawing surface or wraps existing SVG element.
  26366. **
  26367. - width (number|string) width of surface
  26368. - height (number|string) height of surface
  26369. * or
  26370. - DOM (SVGElement) element to be wrapped into Snap structure
  26371. * or
  26372. - array (array) array of elements (will return set of elements)
  26373. * or
  26374. - query (string) CSS query selector
  26375. = (object) @Element
  26376. \*/
  26377. function Snap(w, h) {
  26378. if (w) {
  26379. if (w.tagName) {
  26380. return wrap(w);
  26381. }
  26382. if (is(w, "array") && Snap.set) {
  26383. return Snap.set.apply(Snap, w);
  26384. }
  26385. if (w instanceof Element) {
  26386. return w;
  26387. }
  26388. if (h == null) {
  26389. w = glob.doc.querySelector(w);
  26390. return wrap(w);
  26391. }
  26392. }
  26393. w = w == null ? "100%" : w;
  26394. h = h == null ? "100%" : h;
  26395. return new Paper(w, h);
  26396. }
  26397. Snap.toString = function () {
  26398. return "Snap v" + this.version;
  26399. };
  26400. Snap._ = {};
  26401. var glob = {
  26402. win: root.window,
  26403. doc: root.window.document
  26404. };
  26405. Snap._.glob = glob;
  26406. var has = "hasOwnProperty",
  26407. Str = String,
  26408. toFloat = parseFloat,
  26409. toInt = parseInt,
  26410. math = Math,
  26411. mmax = math.max,
  26412. mmin = math.min,
  26413. abs = math.abs,
  26414. pow = math.pow,
  26415. PI = math.PI,
  26416. round = math.round,
  26417. E = "",
  26418. S = " ",
  26419. objectToString = Object.prototype.toString,
  26420. ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
  26421. colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?%?)\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?%?)\s*\))\s*$/i,
  26422. bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
  26423. reURLValue = /^url\(#?([^)]+)\)$/,
  26424. separator = Snap._.separator = /[,\s]+/,
  26425. whitespace = /[\s]/g,
  26426. commaSpaces = /[\s]*,[\s]*/,
  26427. hsrg = {hs: 1, rg: 1},
  26428. pathCommand = /([a-z])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\s]*,?[\s]*)+)/ig,
  26429. tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\s]*,?[\s]*)+)/ig,
  26430. pathValues = /(-?\d*\.?\d*(?:e[\-+]?\\d+)?)[\s]*,?[\s]*/ig,
  26431. idgen = 0,
  26432. idprefix = "S" + (+new Date).toString(36),
  26433. ID = function (el) {
  26434. return (el && el.type ? el.type : E) + idprefix + (idgen++).toString(36);
  26435. },
  26436. xlink = "http://www.w3.org/1999/xlink",
  26437. xmlns = "http://www.w3.org/2000/svg",
  26438. hub = {},
  26439. URL = Snap.url = function (url) {
  26440. return "url('#" + url + "')";
  26441. };
  26442. function $(el, attr) {
  26443. if (attr) {
  26444. if (el == "#text") {
  26445. el = glob.doc.createTextNode(attr.text || "");
  26446. }
  26447. if (typeof el == "string") {
  26448. el = $(el);
  26449. }
  26450. if (typeof attr == "string") {
  26451. if (attr.substring(0, 6) == "xlink:") {
  26452. return el.getAttributeNS(xlink, attr.substring(6));
  26453. }
  26454. if (attr.substring(0, 4) == "xml:") {
  26455. return el.getAttributeNS(xmlns, attr.substring(4));
  26456. }
  26457. return el.getAttribute(attr);
  26458. }
  26459. for (var key in attr) if (attr[has](key)) {
  26460. var val = Str(attr[key]);
  26461. if (val) {
  26462. if (key.substring(0, 6) == "xlink:") {
  26463. el.setAttributeNS(xlink, key.substring(6), val);
  26464. } else if (key.substring(0, 4) == "xml:") {
  26465. el.setAttributeNS(xmlns, key.substring(4), val);
  26466. } else {
  26467. el.setAttribute(key, val);
  26468. }
  26469. } else {
  26470. el.removeAttribute(key);
  26471. }
  26472. }
  26473. } else {
  26474. el = glob.doc.createElementNS(xmlns, el);
  26475. }
  26476. return el;
  26477. }
  26478. Snap._.$ = $;
  26479. Snap._.id = ID;
  26480. function getAttrs(el) {
  26481. var attrs = el.attributes,
  26482. name,
  26483. out = {};
  26484. for (var i = 0; i < attrs.length; i++) {
  26485. if (attrs[i].namespaceURI == xlink) {
  26486. name = "xlink:";
  26487. } else {
  26488. name = "";
  26489. }
  26490. name += attrs[i].name;
  26491. out[name] = attrs[i].textContent;
  26492. }
  26493. return out;
  26494. }
  26495. function is(o, type) {
  26496. type = Str.prototype.toLowerCase.call(type);
  26497. if (type == "finite") {
  26498. return isFinite(o);
  26499. }
  26500. if (type == "array" &&
  26501. (o instanceof Array || Array.isArray && Array.isArray(o))) {
  26502. return true;
  26503. }
  26504. return (type == "null" && o === null) ||
  26505. (type == typeof o && o !== null) ||
  26506. (type == "object" && o === Object(o)) ||
  26507. objectToString.call(o).slice(8, -1).toLowerCase() == type;
  26508. }
  26509. /*\
  26510. * Snap.format
  26511. [ method ]
  26512. **
  26513. * Replaces construction of type `{<name>}` to the corresponding argument
  26514. **
  26515. - token (string) string to format
  26516. - json (object) object which properties are used as a replacement
  26517. = (string) formatted string
  26518. > Usage
  26519. | // this draws a rectangular shape equivalent to "M10,20h40v50h-40z"
  26520. | paper.path(Snap.format("M{x},{y}h{dim.width}v{dim.height}h{dim['negative width']}z", {
  26521. | x: 10,
  26522. | y: 20,
  26523. | dim: {
  26524. | width: 40,
  26525. | height: 50,
  26526. | "negative width": -40
  26527. | }
  26528. | }));
  26529. \*/
  26530. Snap.format = (function () {
  26531. var tokenRegex = /\{([^\}]+)\}/g,
  26532. objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties
  26533. replacer = function (all, key, obj) {
  26534. var res = obj;
  26535. key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) {
  26536. name = name || quotedName;
  26537. if (res) {
  26538. if (name in res) {
  26539. res = res[name];
  26540. }
  26541. typeof res == "function" && isFunc && (res = res());
  26542. }
  26543. });
  26544. res = (res == null || res == obj ? all : res) + "";
  26545. return res;
  26546. };
  26547. return function (str, obj) {
  26548. return Str(str).replace(tokenRegex, function (all, key) {
  26549. return replacer(all, key, obj);
  26550. });
  26551. };
  26552. })();
  26553. function clone(obj) {
  26554. if (typeof obj == "function" || Object(obj) !== obj) {
  26555. return obj;
  26556. }
  26557. var res = new obj.constructor;
  26558. for (var key in obj) if (obj[has](key)) {
  26559. res[key] = clone(obj[key]);
  26560. }
  26561. return res;
  26562. }
  26563. Snap._.clone = clone;
  26564. function repush(array, item) {
  26565. for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
  26566. return array.push(array.splice(i, 1)[0]);
  26567. }
  26568. }
  26569. function cacher(f, scope, postprocessor) {
  26570. function newf() {
  26571. var arg = Array.prototype.slice.call(arguments, 0),
  26572. args = arg.join("\u2400"),
  26573. cache = newf.cache = newf.cache || {},
  26574. count = newf.count = newf.count || [];
  26575. if (cache[has](args)) {
  26576. repush(count, args);
  26577. return postprocessor ? postprocessor(cache[args]) : cache[args];
  26578. }
  26579. count.length >= 1e3 && delete cache[count.shift()];
  26580. count.push(args);
  26581. cache[args] = f.apply(scope, arg);
  26582. return postprocessor ? postprocessor(cache[args]) : cache[args];
  26583. }
  26584. return newf;
  26585. }
  26586. Snap._.cacher = cacher;
  26587. function angle(x1, y1, x2, y2, x3, y3) {
  26588. if (x3 == null) {
  26589. var x = x1 - x2,
  26590. y = y1 - y2;
  26591. if (!x && !y) {
  26592. return 0;
  26593. }
  26594. return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
  26595. } else {
  26596. return angle(x1, y1, x3, y3) - angle(x2, y2, x3, y3);
  26597. }
  26598. }
  26599. function rad(deg) {
  26600. return deg % 360 * PI / 180;
  26601. }
  26602. function deg(rad) {
  26603. return rad * 180 / PI % 360;
  26604. }
  26605. function x_y() {
  26606. return this.x + S + this.y;
  26607. }
  26608. function x_y_w_h() {
  26609. return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
  26610. }
  26611. /*\
  26612. * Snap.rad
  26613. [ method ]
  26614. **
  26615. * Transform angle to radians
  26616. - deg (number) angle in degrees
  26617. = (number) angle in radians
  26618. \*/
  26619. Snap.rad = rad;
  26620. /*\
  26621. * Snap.deg
  26622. [ method ]
  26623. **
  26624. * Transform angle to degrees
  26625. - rad (number) angle in radians
  26626. = (number) angle in degrees
  26627. \*/
  26628. Snap.deg = deg;
  26629. /*\
  26630. * Snap.angle
  26631. [ method ]
  26632. **
  26633. * Returns an angle between two or three points
  26634. > Parameters
  26635. - x1 (number) x coord of first point
  26636. - y1 (number) y coord of first point
  26637. - x2 (number) x coord of second point
  26638. - y2 (number) y coord of second point
  26639. - x3 (number) #optional x coord of third point
  26640. - y3 (number) #optional y coord of third point
  26641. = (number) angle in degrees
  26642. \*/
  26643. Snap.angle = angle;
  26644. /*\
  26645. * Snap.is
  26646. [ method ]
  26647. **
  26648. * Handy replacement for the `typeof` operator
  26649. - o (…) any object or primitive
  26650. - type (string) name of the type, e.g., `string`, `function`, `number`, etc.
  26651. = (boolean) `true` if given value is of given type
  26652. \*/
  26653. Snap.is = is;
  26654. /*\
  26655. * Snap.snapTo
  26656. [ method ]
  26657. **
  26658. * Snaps given value to given grid
  26659. - values (array|number) given array of values or step of the grid
  26660. - value (number) value to adjust
  26661. - tolerance (number) #optional maximum distance to the target value that would trigger the snap. Default is `10`.
  26662. = (number) adjusted value
  26663. \*/
  26664. Snap.snapTo = function (values, value, tolerance) {
  26665. tolerance = is(tolerance, "finite") ? tolerance : 10;
  26666. if (is(values, "array")) {
  26667. var i = values.length;
  26668. while (i--) if (abs(values[i] - value) <= tolerance) {
  26669. return values[i];
  26670. }
  26671. } else {
  26672. values = +values;
  26673. var rem = value % values;
  26674. if (rem < tolerance) {
  26675. return value - rem;
  26676. }
  26677. if (rem > values - tolerance) {
  26678. return value - rem + values;
  26679. }
  26680. }
  26681. return value;
  26682. };
  26683. // Colour
  26684. /*\
  26685. * Snap.getRGB
  26686. [ method ]
  26687. **
  26688. * Parses color string as RGB object
  26689. - color (string) color string in one of the following formats:
  26690. # <ul>
  26691. # <li>Color name (<code>red</code>, <code>green</code>, <code>cornflowerblue</code>, etc)</li>
  26692. # <li>#••• — shortened HTML color: (<code>#000</code>, <code>#fc0</code>, etc.)</li>
  26693. # <li>#•••••• — full length HTML color: (<code>#000000</code>, <code>#bd2300</code>)</li>
  26694. # <li>rgb(•••, •••, •••) — red, green and blue channels values: (<code>rgb(200,&nbsp;100,&nbsp;0)</code>)</li>
  26695. # <li>rgba(•••, •••, •••, •••) — also with opacity</li>
  26696. # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>)</li>
  26697. # <li>rgba(•••%, •••%, •••%, •••%) — also with opacity</li>
  26698. # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>)</li>
  26699. # <li>hsba(•••, •••, •••, •••) — also with opacity</li>
  26700. # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
  26701. # <li>hsba(•••%, •••%, •••%, •••%) — also with opacity</li>
  26702. # <li>hsl(•••, •••, •••) — hue, saturation and luminosity values: (<code>hsb(0.5,&nbsp;0.25,&nbsp;0.5)</code>)</li>
  26703. # <li>hsla(•••, •••, •••, •••) — also with opacity</li>
  26704. # <li>hsl(•••%, •••%, •••%) — same as above, but in %</li>
  26705. # <li>hsla(•••%, •••%, •••%, •••%) — also with opacity</li>
  26706. # </ul>
  26707. * Note that `%` can be used any time: `rgb(20%, 255, 50%)`.
  26708. = (object) RGB object in the following format:
  26709. o {
  26710. o r (number) red,
  26711. o g (number) green,
  26712. o b (number) blue,
  26713. o hex (string) color in HTML/CSS format: #••••••,
  26714. o error (boolean) true if string can't be parsed
  26715. o }
  26716. \*/
  26717. Snap.getRGB = cacher(function (colour) {
  26718. if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
  26719. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: rgbtoString};
  26720. }
  26721. if (colour == "none") {
  26722. return {r: -1, g: -1, b: -1, hex: "none", toString: rgbtoString};
  26723. }
  26724. !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
  26725. if (!colour) {
  26726. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: rgbtoString};
  26727. }
  26728. var res,
  26729. red,
  26730. green,
  26731. blue,
  26732. opacity,
  26733. t,
  26734. values,
  26735. rgb = colour.match(colourRegExp);
  26736. if (rgb) {
  26737. if (rgb[2]) {
  26738. blue = toInt(rgb[2].substring(5), 16);
  26739. green = toInt(rgb[2].substring(3, 5), 16);
  26740. red = toInt(rgb[2].substring(1, 3), 16);
  26741. }
  26742. if (rgb[3]) {
  26743. blue = toInt((t = rgb[3].charAt(3)) + t, 16);
  26744. green = toInt((t = rgb[3].charAt(2)) + t, 16);
  26745. red = toInt((t = rgb[3].charAt(1)) + t, 16);
  26746. }
  26747. if (rgb[4]) {
  26748. values = rgb[4].split(commaSpaces);
  26749. red = toFloat(values[0]);
  26750. values[0].slice(-1) == "%" && (red *= 2.55);
  26751. green = toFloat(values[1]);
  26752. values[1].slice(-1) == "%" && (green *= 2.55);
  26753. blue = toFloat(values[2]);
  26754. values[2].slice(-1) == "%" && (blue *= 2.55);
  26755. rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
  26756. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  26757. }
  26758. if (rgb[5]) {
  26759. values = rgb[5].split(commaSpaces);
  26760. red = toFloat(values[0]);
  26761. values[0].slice(-1) == "%" && (red /= 100);
  26762. green = toFloat(values[1]);
  26763. values[1].slice(-1) == "%" && (green /= 100);
  26764. blue = toFloat(values[2]);
  26765. values[2].slice(-1) == "%" && (blue /= 100);
  26766. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  26767. rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
  26768. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  26769. return Snap.hsb2rgb(red, green, blue, opacity);
  26770. }
  26771. if (rgb[6]) {
  26772. values = rgb[6].split(commaSpaces);
  26773. red = toFloat(values[0]);
  26774. values[0].slice(-1) == "%" && (red /= 100);
  26775. green = toFloat(values[1]);
  26776. values[1].slice(-1) == "%" && (green /= 100);
  26777. blue = toFloat(values[2]);
  26778. values[2].slice(-1) == "%" && (blue /= 100);
  26779. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  26780. rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
  26781. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  26782. return Snap.hsl2rgb(red, green, blue, opacity);
  26783. }
  26784. red = mmin(math.round(red), 255);
  26785. green = mmin(math.round(green), 255);
  26786. blue = mmin(math.round(blue), 255);
  26787. opacity = mmin(mmax(opacity, 0), 1);
  26788. rgb = {r: red, g: green, b: blue, toString: rgbtoString};
  26789. rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
  26790. rgb.opacity = is(opacity, "finite") ? opacity : 1;
  26791. return rgb;
  26792. }
  26793. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: rgbtoString};
  26794. }, Snap);
  26795. // SIERRA It seems odd that the following 3 conversion methods are not expressed as .this2that(), like the others.
  26796. /*\
  26797. * Snap.hsb
  26798. [ method ]
  26799. **
  26800. * Converts HSB values to a hex representation of the color
  26801. - h (number) hue
  26802. - s (number) saturation
  26803. - b (number) value or brightness
  26804. = (string) hex representation of the color
  26805. \*/
  26806. Snap.hsb = cacher(function (h, s, b) {
  26807. return Snap.hsb2rgb(h, s, b).hex;
  26808. });
  26809. /*\
  26810. * Snap.hsl
  26811. [ method ]
  26812. **
  26813. * Converts HSL values to a hex representation of the color
  26814. - h (number) hue
  26815. - s (number) saturation
  26816. - l (number) luminosity
  26817. = (string) hex representation of the color
  26818. \*/
  26819. Snap.hsl = cacher(function (h, s, l) {
  26820. return Snap.hsl2rgb(h, s, l).hex;
  26821. });
  26822. /*\
  26823. * Snap.rgb
  26824. [ method ]
  26825. **
  26826. * Converts RGB values to a hex representation of the color
  26827. - r (number) red
  26828. - g (number) green
  26829. - b (number) blue
  26830. = (string) hex representation of the color
  26831. \*/
  26832. Snap.rgb = cacher(function (r, g, b, o) {
  26833. if (is(o, "finite")) {
  26834. var round = math.round;
  26835. return "rgba(" + [round(r), round(g), round(b), +o.toFixed(2)] + ")";
  26836. }
  26837. return "#" + (16777216 | b | (g << 8) | (r << 16)).toString(16).slice(1);
  26838. });
  26839. var toHex = function (color) {
  26840. var i = glob.doc.getElementsByTagName("head")[0] || glob.doc.getElementsByTagName("svg")[0],
  26841. red = "rgb(255, 0, 0)";
  26842. toHex = cacher(function (color) {
  26843. if (color.toLowerCase() == "red") {
  26844. return red;
  26845. }
  26846. i.style.color = red;
  26847. i.style.color = color;
  26848. var out = glob.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
  26849. return out == red ? null : out;
  26850. });
  26851. return toHex(color);
  26852. },
  26853. hsbtoString = function () {
  26854. return "hsb(" + [this.h, this.s, this.b] + ")";
  26855. },
  26856. hsltoString = function () {
  26857. return "hsl(" + [this.h, this.s, this.l] + ")";
  26858. },
  26859. rgbtoString = function () {
  26860. return this.opacity == 1 || this.opacity == null ?
  26861. this.hex :
  26862. "rgba(" + [this.r, this.g, this.b, this.opacity] + ")";
  26863. },
  26864. prepareRGB = function (r, g, b) {
  26865. if (g == null && is(r, "object") && "r" in r && "g" in r && "b" in r) {
  26866. b = r.b;
  26867. g = r.g;
  26868. r = r.r;
  26869. }
  26870. if (g == null && is(r, string)) {
  26871. var clr = Snap.getRGB(r);
  26872. r = clr.r;
  26873. g = clr.g;
  26874. b = clr.b;
  26875. }
  26876. if (r > 1 || g > 1 || b > 1) {
  26877. r /= 255;
  26878. g /= 255;
  26879. b /= 255;
  26880. }
  26881. return [r, g, b];
  26882. },
  26883. packageRGB = function (r, g, b, o) {
  26884. r = math.round(r * 255);
  26885. g = math.round(g * 255);
  26886. b = math.round(b * 255);
  26887. var rgb = {
  26888. r: r,
  26889. g: g,
  26890. b: b,
  26891. opacity: is(o, "finite") ? o : 1,
  26892. hex: Snap.rgb(r, g, b),
  26893. toString: rgbtoString
  26894. };
  26895. is(o, "finite") && (rgb.opacity = o);
  26896. return rgb;
  26897. };
  26898. // SIERRA Clarify if Snap does not support consolidated HSLA/RGBA colors. E.g., can you specify a semi-transparent value for Snap.filter.shadow()?
  26899. /*\
  26900. * Snap.color
  26901. [ method ]
  26902. **
  26903. * Parses the color string and returns an object featuring the color's component values
  26904. - clr (string) color string in one of the supported formats (see @Snap.getRGB)
  26905. = (object) Combined RGB/HSB object in the following format:
  26906. o {
  26907. o r (number) red,
  26908. o g (number) green,
  26909. o b (number) blue,
  26910. o hex (string) color in HTML/CSS format: #••••••,
  26911. o error (boolean) `true` if string can't be parsed,
  26912. o h (number) hue,
  26913. o s (number) saturation,
  26914. o v (number) value (brightness),
  26915. o l (number) lightness
  26916. o }
  26917. \*/
  26918. Snap.color = function (clr) {
  26919. var rgb;
  26920. if (is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
  26921. rgb = Snap.hsb2rgb(clr);
  26922. clr.r = rgb.r;
  26923. clr.g = rgb.g;
  26924. clr.b = rgb.b;
  26925. clr.opacity = 1;
  26926. clr.hex = rgb.hex;
  26927. } else if (is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
  26928. rgb = Snap.hsl2rgb(clr);
  26929. clr.r = rgb.r;
  26930. clr.g = rgb.g;
  26931. clr.b = rgb.b;
  26932. clr.opacity = 1;
  26933. clr.hex = rgb.hex;
  26934. } else {
  26935. if (is(clr, "string")) {
  26936. clr = Snap.getRGB(clr);
  26937. }
  26938. if (is(clr, "object") && "r" in clr && "g" in clr && "b" in clr && !("error" in clr)) {
  26939. rgb = Snap.rgb2hsl(clr);
  26940. clr.h = rgb.h;
  26941. clr.s = rgb.s;
  26942. clr.l = rgb.l;
  26943. rgb = Snap.rgb2hsb(clr);
  26944. clr.v = rgb.b;
  26945. } else {
  26946. clr = {hex: "none"};
  26947. clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
  26948. clr.error = 1;
  26949. }
  26950. }
  26951. clr.toString = rgbtoString;
  26952. return clr;
  26953. };
  26954. /*\
  26955. * Snap.hsb2rgb
  26956. [ method ]
  26957. **
  26958. * Converts HSB values to an RGB object
  26959. - h (number) hue
  26960. - s (number) saturation
  26961. - v (number) value or brightness
  26962. = (object) RGB object in the following format:
  26963. o {
  26964. o r (number) red,
  26965. o g (number) green,
  26966. o b (number) blue,
  26967. o hex (string) color in HTML/CSS format: #••••••
  26968. o }
  26969. \*/
  26970. Snap.hsb2rgb = function (h, s, v, o) {
  26971. if (is(h, "object") && "h" in h && "s" in h && "b" in h) {
  26972. v = h.b;
  26973. s = h.s;
  26974. h = h.h;
  26975. o = h.o;
  26976. }
  26977. h *= 360;
  26978. var R, G, B, X, C;
  26979. h = (h % 360) / 60;
  26980. C = v * s;
  26981. X = C * (1 - abs(h % 2 - 1));
  26982. R = G = B = v - C;
  26983. h = ~~h;
  26984. R += [C, X, 0, 0, X, C][h];
  26985. G += [X, C, C, X, 0, 0][h];
  26986. B += [0, 0, X, C, C, X][h];
  26987. return packageRGB(R, G, B, o);
  26988. };
  26989. /*\
  26990. * Snap.hsl2rgb
  26991. [ method ]
  26992. **
  26993. * Converts HSL values to an RGB object
  26994. - h (number) hue
  26995. - s (number) saturation
  26996. - l (number) luminosity
  26997. = (object) RGB object in the following format:
  26998. o {
  26999. o r (number) red,
  27000. o g (number) green,
  27001. o b (number) blue,
  27002. o hex (string) color in HTML/CSS format: #••••••
  27003. o }
  27004. \*/
  27005. Snap.hsl2rgb = function (h, s, l, o) {
  27006. if (is(h, "object") && "h" in h && "s" in h && "l" in h) {
  27007. l = h.l;
  27008. s = h.s;
  27009. h = h.h;
  27010. }
  27011. if (h > 1 || s > 1 || l > 1) {
  27012. h /= 360;
  27013. s /= 100;
  27014. l /= 100;
  27015. }
  27016. h *= 360;
  27017. var R, G, B, X, C;
  27018. h = (h % 360) / 60;
  27019. C = 2 * s * (l < .5 ? l : 1 - l);
  27020. X = C * (1 - abs(h % 2 - 1));
  27021. R = G = B = l - C / 2;
  27022. h = ~~h;
  27023. R += [C, X, 0, 0, X, C][h];
  27024. G += [X, C, C, X, 0, 0][h];
  27025. B += [0, 0, X, C, C, X][h];
  27026. return packageRGB(R, G, B, o);
  27027. };
  27028. /*\
  27029. * Snap.rgb2hsb
  27030. [ method ]
  27031. **
  27032. * Converts RGB values to an HSB object
  27033. - r (number) red
  27034. - g (number) green
  27035. - b (number) blue
  27036. = (object) HSB object in the following format:
  27037. o {
  27038. o h (number) hue,
  27039. o s (number) saturation,
  27040. o b (number) brightness
  27041. o }
  27042. \*/
  27043. Snap.rgb2hsb = function (r, g, b) {
  27044. b = prepareRGB(r, g, b);
  27045. r = b[0];
  27046. g = b[1];
  27047. b = b[2];
  27048. var H, S, V, C;
  27049. V = mmax(r, g, b);
  27050. C = V - mmin(r, g, b);
  27051. H = (C == 0 ? null :
  27052. V == r ? (g - b) / C :
  27053. V == g ? (b - r) / C + 2 :
  27054. (r - g) / C + 4
  27055. );
  27056. H = ((H + 360) % 6) * 60 / 360;
  27057. S = C == 0 ? 0 : C / V;
  27058. return {h: H, s: S, b: V, toString: hsbtoString};
  27059. };
  27060. /*\
  27061. * Snap.rgb2hsl
  27062. [ method ]
  27063. **
  27064. * Converts RGB values to an HSL object
  27065. - r (number) red
  27066. - g (number) green
  27067. - b (number) blue
  27068. = (object) HSL object in the following format:
  27069. o {
  27070. o h (number) hue,
  27071. o s (number) saturation,
  27072. o l (number) luminosity
  27073. o }
  27074. \*/
  27075. Snap.rgb2hsl = function (r, g, b) {
  27076. b = prepareRGB(r, g, b);
  27077. r = b[0];
  27078. g = b[1];
  27079. b = b[2];
  27080. var H, S, L, M, m, C;
  27081. M = mmax(r, g, b);
  27082. m = mmin(r, g, b);
  27083. C = M - m;
  27084. H = (C == 0 ? null :
  27085. M == r ? (g - b) / C :
  27086. M == g ? (b - r) / C + 2 :
  27087. (r - g) / C + 4);
  27088. H = ((H + 360) % 6) * 60 / 360;
  27089. L = (M + m) / 2;
  27090. S = (C == 0 ? 0 :
  27091. L < .5 ? C / (2 * L) :
  27092. C / (2 - 2 * L));
  27093. return {h: H, s: S, l: L, toString: hsltoString};
  27094. };
  27095. // Transformations
  27096. // SIERRA Snap.parsePathString(): By _array of arrays,_ I assume you mean a format like this for two separate segments? [ ["M10,10","L90,90"], ["M90,10","L10,90"] ] Otherwise how is each command structured?
  27097. /*\
  27098. * Snap.parsePathString
  27099. [ method ]
  27100. **
  27101. * Utility method
  27102. **
  27103. * Parses given path string into an array of arrays of path segments
  27104. - pathString (string|array) path string or array of segments (in the last case it is returned straight away)
  27105. = (array) array of segments
  27106. \*/
  27107. Snap.parsePathString = function (pathString) {
  27108. if (!pathString) {
  27109. return null;
  27110. }
  27111. var pth = Snap.path(pathString);
  27112. if (pth.arr) {
  27113. return Snap.path.clone(pth.arr);
  27114. }
  27115. var paramCounts = {a: 7, c: 6, o: 2, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, u: 3, z: 0},
  27116. data = [];
  27117. if (is(pathString, "array") && is(pathString[0], "array")) { // rough assumption
  27118. data = Snap.path.clone(pathString);
  27119. }
  27120. if (!data.length) {
  27121. Str(pathString).replace(pathCommand, function (a, b, c) {
  27122. var params = [],
  27123. name = b.toLowerCase();
  27124. c.replace(pathValues, function (a, b) {
  27125. b && params.push(+b);
  27126. });
  27127. if (name == "m" && params.length > 2) {
  27128. data.push([b].concat(params.splice(0, 2)));
  27129. name = "l";
  27130. b = b == "m" ? "l" : "L";
  27131. }
  27132. if (name == "o" && params.length == 1) {
  27133. data.push([b, params[0]]);
  27134. }
  27135. if (name == "r") {
  27136. data.push([b].concat(params));
  27137. } else while (params.length >= paramCounts[name]) {
  27138. data.push([b].concat(params.splice(0, paramCounts[name])));
  27139. if (!paramCounts[name]) {
  27140. break;
  27141. }
  27142. }
  27143. });
  27144. }
  27145. data.toString = Snap.path.toString;
  27146. pth.arr = Snap.path.clone(data);
  27147. return data;
  27148. };
  27149. /*\
  27150. * Snap.parseTransformString
  27151. [ method ]
  27152. **
  27153. * Utility method
  27154. **
  27155. * Parses given transform string into an array of transformations
  27156. - TString (string|array) transform string or array of transformations (in the last case it is returned straight away)
  27157. = (array) array of transformations
  27158. \*/
  27159. var parseTransformString = Snap.parseTransformString = function (TString) {
  27160. if (!TString) {
  27161. return null;
  27162. }
  27163. var paramCounts = {r: 3, s: 4, t: 2, m: 6},
  27164. data = [];
  27165. if (is(TString, "array") && is(TString[0], "array")) { // rough assumption
  27166. data = Snap.path.clone(TString);
  27167. }
  27168. if (!data.length) {
  27169. Str(TString).replace(tCommand, function (a, b, c) {
  27170. var params = [],
  27171. name = b.toLowerCase();
  27172. c.replace(pathValues, function (a, b) {
  27173. b && params.push(+b);
  27174. });
  27175. data.push([b].concat(params));
  27176. });
  27177. }
  27178. data.toString = Snap.path.toString;
  27179. return data;
  27180. };
  27181. function svgTransform2string(tstr) {
  27182. var res = [];
  27183. tstr = tstr.replace(/(?:^|\s)(\w+)\(([^)]+)\)/g, function (all, name, params) {
  27184. params = params.split(/\s*,\s*|\s+/);
  27185. if (name == "rotate" && params.length == 1) {
  27186. params.push(0, 0);
  27187. }
  27188. if (name == "scale") {
  27189. if (params.length > 2) {
  27190. params = params.slice(0, 2);
  27191. } else if (params.length == 2) {
  27192. params.push(0, 0);
  27193. }
  27194. if (params.length == 1) {
  27195. params.push(params[0], 0, 0);
  27196. }
  27197. }
  27198. if (name == "skewX") {
  27199. res.push(["m", 1, 0, math.tan(rad(params[0])), 1, 0, 0]);
  27200. } else if (name == "skewY") {
  27201. res.push(["m", 1, math.tan(rad(params[0])), 0, 1, 0, 0]);
  27202. } else {
  27203. res.push([name.charAt(0)].concat(params));
  27204. }
  27205. return all;
  27206. });
  27207. return res;
  27208. }
  27209. Snap._.svgTransform2string = svgTransform2string;
  27210. Snap._.rgTransform = /^[a-z][\s]*-?\.?\d/i;
  27211. function transform2matrix(tstr, bbox) {
  27212. var tdata = parseTransformString(tstr),
  27213. m = new Snap.Matrix;
  27214. if (tdata) {
  27215. for (var i = 0, ii = tdata.length; i < ii; i++) {
  27216. var t = tdata[i],
  27217. tlen = t.length,
  27218. command = Str(t[0]).toLowerCase(),
  27219. absolute = t[0] != command,
  27220. inver = absolute ? m.invert() : 0,
  27221. x1,
  27222. y1,
  27223. x2,
  27224. y2,
  27225. bb;
  27226. if (command == "t" && tlen == 2){
  27227. m.translate(t[1], 0);
  27228. } else if (command == "t" && tlen == 3) {
  27229. if (absolute) {
  27230. x1 = inver.x(0, 0);
  27231. y1 = inver.y(0, 0);
  27232. x2 = inver.x(t[1], t[2]);
  27233. y2 = inver.y(t[1], t[2]);
  27234. m.translate(x2 - x1, y2 - y1);
  27235. } else {
  27236. m.translate(t[1], t[2]);
  27237. }
  27238. } else if (command == "r") {
  27239. if (tlen == 2) {
  27240. bb = bb || bbox;
  27241. m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  27242. } else if (tlen == 4) {
  27243. if (absolute) {
  27244. x2 = inver.x(t[2], t[3]);
  27245. y2 = inver.y(t[2], t[3]);
  27246. m.rotate(t[1], x2, y2);
  27247. } else {
  27248. m.rotate(t[1], t[2], t[3]);
  27249. }
  27250. }
  27251. } else if (command == "s") {
  27252. if (tlen == 2 || tlen == 3) {
  27253. bb = bb || bbox;
  27254. m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  27255. } else if (tlen == 4) {
  27256. if (absolute) {
  27257. x2 = inver.x(t[2], t[3]);
  27258. y2 = inver.y(t[2], t[3]);
  27259. m.scale(t[1], t[1], x2, y2);
  27260. } else {
  27261. m.scale(t[1], t[1], t[2], t[3]);
  27262. }
  27263. } else if (tlen == 5) {
  27264. if (absolute) {
  27265. x2 = inver.x(t[3], t[4]);
  27266. y2 = inver.y(t[3], t[4]);
  27267. m.scale(t[1], t[2], x2, y2);
  27268. } else {
  27269. m.scale(t[1], t[2], t[3], t[4]);
  27270. }
  27271. }
  27272. } else if (command == "m" && tlen == 7) {
  27273. m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
  27274. }
  27275. }
  27276. }
  27277. return m;
  27278. }
  27279. Snap._.transform2matrix = transform2matrix;
  27280. Snap._unit2px = unit2px;
  27281. var contains = glob.doc.contains || glob.doc.compareDocumentPosition ?
  27282. function (a, b) {
  27283. var adown = a.nodeType == 9 ? a.documentElement : a,
  27284. bup = b && b.parentNode;
  27285. return a == bup || !!(bup && bup.nodeType == 1 && (
  27286. adown.contains ?
  27287. adown.contains(bup) :
  27288. a.compareDocumentPosition && a.compareDocumentPosition(bup) & 16
  27289. ));
  27290. } :
  27291. function (a, b) {
  27292. if (b) {
  27293. while (b) {
  27294. b = b.parentNode;
  27295. if (b == a) {
  27296. return true;
  27297. }
  27298. }
  27299. }
  27300. return false;
  27301. };
  27302. function getSomeDefs(el) {
  27303. var p = (el.node.ownerSVGElement && wrap(el.node.ownerSVGElement)) ||
  27304. (el.node.parentNode && wrap(el.node.parentNode)) ||
  27305. Snap.select("svg") ||
  27306. Snap(0, 0),
  27307. pdefs = p.select("defs"),
  27308. defs = pdefs == null ? false : pdefs.node;
  27309. if (!defs) {
  27310. defs = make("defs", p.node).node;
  27311. }
  27312. return defs;
  27313. }
  27314. function getSomeSVG(el) {
  27315. return el.node.ownerSVGElement && wrap(el.node.ownerSVGElement) || Snap.select("svg");
  27316. }
  27317. Snap._.getSomeDefs = getSomeDefs;
  27318. Snap._.getSomeSVG = getSomeSVG;
  27319. function unit2px(el, name, value) {
  27320. var svg = getSomeSVG(el).node,
  27321. out = {},
  27322. mgr = svg.querySelector(".svg---mgr");
  27323. if (!mgr) {
  27324. mgr = $("rect");
  27325. $(mgr, {x: -9e9, y: -9e9, width: 10, height: 10, "class": "svg---mgr", fill: "none"});
  27326. svg.appendChild(mgr);
  27327. }
  27328. function getW(val) {
  27329. if (val == null) {
  27330. return E;
  27331. }
  27332. if (val == +val) {
  27333. return val;
  27334. }
  27335. $(mgr, {width: val});
  27336. try {
  27337. return mgr.getBBox().width;
  27338. } catch (e) {
  27339. return 0;
  27340. }
  27341. }
  27342. function getH(val) {
  27343. if (val == null) {
  27344. return E;
  27345. }
  27346. if (val == +val) {
  27347. return val;
  27348. }
  27349. $(mgr, {height: val});
  27350. try {
  27351. return mgr.getBBox().height;
  27352. } catch (e) {
  27353. return 0;
  27354. }
  27355. }
  27356. function set(nam, f) {
  27357. if (name == null) {
  27358. out[nam] = f(el.attr(nam) || 0);
  27359. } else if (nam == name) {
  27360. out = f(value == null ? el.attr(nam) || 0 : value);
  27361. }
  27362. }
  27363. switch (el.type) {
  27364. case "rect":
  27365. set("rx", getW);
  27366. set("ry", getH);
  27367. case "image":
  27368. set("width", getW);
  27369. set("height", getH);
  27370. case "text":
  27371. set("x", getW);
  27372. set("y", getH);
  27373. break;
  27374. case "circle":
  27375. set("cx", getW);
  27376. set("cy", getH);
  27377. set("r", getW);
  27378. break;
  27379. case "ellipse":
  27380. set("cx", getW);
  27381. set("cy", getH);
  27382. set("rx", getW);
  27383. set("ry", getH);
  27384. break;
  27385. case "line":
  27386. set("x1", getW);
  27387. set("x2", getW);
  27388. set("y1", getH);
  27389. set("y2", getH);
  27390. break;
  27391. case "marker":
  27392. set("refX", getW);
  27393. set("markerWidth", getW);
  27394. set("refY", getH);
  27395. set("markerHeight", getH);
  27396. break;
  27397. case "radialGradient":
  27398. set("fx", getW);
  27399. set("fy", getH);
  27400. break;
  27401. case "tspan":
  27402. set("dx", getW);
  27403. set("dy", getH);
  27404. break;
  27405. default:
  27406. set(name, getW);
  27407. }
  27408. svg.removeChild(mgr);
  27409. return out;
  27410. }
  27411. /*\
  27412. * Snap.select
  27413. [ method ]
  27414. **
  27415. * Wraps a DOM element specified by CSS selector as @Element
  27416. - query (string) CSS selector of the element
  27417. = (Element) the current element
  27418. \*/
  27419. Snap.select = function (query) {
  27420. query = Str(query).replace(/([^\\]):/g, "$1\\:");
  27421. return wrap(glob.doc.querySelector(query));
  27422. };
  27423. /*\
  27424. * Snap.selectAll
  27425. [ method ]
  27426. **
  27427. * Wraps DOM elements specified by CSS selector as set or array of @Element
  27428. - query (string) CSS selector of the element
  27429. = (Element) the current element
  27430. \*/
  27431. Snap.selectAll = function (query) {
  27432. var nodelist = glob.doc.querySelectorAll(query),
  27433. set = (Snap.set || Array)();
  27434. for (var i = 0; i < nodelist.length; i++) {
  27435. set.push(wrap(nodelist[i]));
  27436. }
  27437. return set;
  27438. };
  27439. function add2group(list) {
  27440. if (!is(list, "array")) {
  27441. list = Array.prototype.slice.call(arguments, 0);
  27442. }
  27443. var i = 0,
  27444. j = 0,
  27445. node = this.node;
  27446. while (this[i]) delete this[i++];
  27447. for (i = 0; i < list.length; i++) {
  27448. if (list[i].type == "set") {
  27449. list[i].forEach(function (el) {
  27450. node.appendChild(el.node);
  27451. });
  27452. } else {
  27453. node.appendChild(list[i].node);
  27454. }
  27455. }
  27456. var children = node.childNodes;
  27457. for (i = 0; i < children.length; i++) {
  27458. this[j++] = wrap(children[i]);
  27459. }
  27460. return this;
  27461. }
  27462. // Hub garbage collector every 10s
  27463. setInterval(function () {
  27464. for (var key in hub) if (hub[has](key)) {
  27465. var el = hub[key],
  27466. node = el.node;
  27467. if (el.type != "svg" && !node.ownerSVGElement || el.type == "svg" && (!node.parentNode || "ownerSVGElement" in node.parentNode && !node.ownerSVGElement)) {
  27468. delete hub[key];
  27469. }
  27470. }
  27471. }, 1e4);
  27472. function Element(el) {
  27473. if (el.snap in hub) {
  27474. return hub[el.snap];
  27475. }
  27476. var svg;
  27477. try {
  27478. svg = el.ownerSVGElement;
  27479. } catch(e) {}
  27480. /*\
  27481. * Element.node
  27482. [ property (object) ]
  27483. **
  27484. * Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
  27485. > Usage
  27486. | // draw a circle at coordinate 10,10 with radius of 10
  27487. | var c = paper.circle(10, 10, 10);
  27488. | c.node.onclick = function () {
  27489. | c.attr("fill", "red");
  27490. | };
  27491. \*/
  27492. this.node = el;
  27493. if (svg) {
  27494. this.paper = new Paper(svg);
  27495. }
  27496. /*\
  27497. * Element.type
  27498. [ property (string) ]
  27499. **
  27500. * SVG tag name of the given element.
  27501. \*/
  27502. this.type = el.tagName;
  27503. var id = this.id = ID(this);
  27504. this.anims = {};
  27505. this._ = {
  27506. transform: []
  27507. };
  27508. el.snap = id;
  27509. hub[id] = this;
  27510. if (this.type == "g") {
  27511. this.add = add2group;
  27512. }
  27513. if (this.type in {g: 1, mask: 1, pattern: 1, symbol: 1}) {
  27514. for (var method in Paper.prototype) if (Paper.prototype[has](method)) {
  27515. this[method] = Paper.prototype[method];
  27516. }
  27517. }
  27518. }
  27519. /*\
  27520. * Element.attr
  27521. [ method ]
  27522. **
  27523. * Gets or sets given attributes of the element.
  27524. **
  27525. - params (object) contains key-value pairs of attributes you want to set
  27526. * or
  27527. - param (string) name of the attribute
  27528. = (Element) the current element
  27529. * or
  27530. = (string) value of attribute
  27531. > Usage
  27532. | el.attr({
  27533. | fill: "#fc0",
  27534. | stroke: "#000",
  27535. | strokeWidth: 2, // CamelCase...
  27536. | "fill-opacity": 0.5, // or dash-separated names
  27537. | width: "*=2" // prefixed values
  27538. | });
  27539. | console.log(el.attr("fill")); // #fc0
  27540. * Prefixed values in format `"+=10"` supported. All four operations
  27541. * (`+`, `-`, `*` and `/`) could be used. Optionally you can use units for `+`
  27542. * and `-`: `"+=2em"`.
  27543. \*/
  27544. Element.prototype.attr = function (params, value) {
  27545. var el = this,
  27546. node = el.node;
  27547. if (!params) {
  27548. return el;
  27549. }
  27550. if (is(params, "string")) {
  27551. if (arguments.length > 1) {
  27552. var json = {};
  27553. json[params] = value;
  27554. params = json;
  27555. } else {
  27556. return eve("snap.util.getattr." + params, el).firstDefined();
  27557. }
  27558. }
  27559. for (var att in params) {
  27560. if (params[has](att)) {
  27561. eve("snap.util.attr." + att, el, params[att]);
  27562. }
  27563. }
  27564. return el;
  27565. };
  27566. /*\
  27567. * Snap.parse
  27568. [ method ]
  27569. **
  27570. * Parses SVG fragment and converts it into a @Fragment
  27571. **
  27572. - svg (string) SVG string
  27573. = (Fragment) the @Fragment
  27574. \*/
  27575. Snap.parse = function (svg) {
  27576. var f = glob.doc.createDocumentFragment(),
  27577. full = true,
  27578. div = glob.doc.createElement("div");
  27579. svg = Str(svg);
  27580. if (!svg.match(/^\s*<\s*svg(?:\s|>)/)) {
  27581. svg = "<svg>" + svg + "</svg>";
  27582. full = false;
  27583. }
  27584. div.innerHTML = svg;
  27585. svg = div.getElementsByTagName("svg")[0];
  27586. if (svg) {
  27587. if (full) {
  27588. f = svg;
  27589. } else {
  27590. while (svg.firstChild) {
  27591. f.appendChild(svg.firstChild);
  27592. }
  27593. div.innerHTML = E;
  27594. }
  27595. }
  27596. return new Fragment(f);
  27597. };
  27598. function Fragment(frag) {
  27599. this.node = frag;
  27600. }
  27601. // SIERRA Snap.fragment() could especially use a code example
  27602. /*\
  27603. * Snap.fragment
  27604. [ method ]
  27605. **
  27606. * Creates a DOM fragment from a given list of elements or strings
  27607. **
  27608. - varargs (…) SVG string
  27609. = (Fragment) the @Fragment
  27610. \*/
  27611. Snap.fragment = function () {
  27612. var args = Array.prototype.slice.call(arguments, 0),
  27613. f = glob.doc.createDocumentFragment();
  27614. for (var i = 0, ii = args.length; i < ii; i++) {
  27615. var item = args[i];
  27616. if (item.node && item.node.nodeType) {
  27617. f.appendChild(item.node);
  27618. }
  27619. if (item.nodeType) {
  27620. f.appendChild(item);
  27621. }
  27622. if (typeof item == "string") {
  27623. f.appendChild(Snap.parse(item).node);
  27624. }
  27625. }
  27626. return new Fragment(f);
  27627. };
  27628. function make(name, parent) {
  27629. var res = $(name);
  27630. parent.appendChild(res);
  27631. var el = wrap(res);
  27632. return el;
  27633. }
  27634. function Paper(w, h) {
  27635. var res,
  27636. desc,
  27637. defs,
  27638. proto = Paper.prototype;
  27639. if (w && w.tagName == "svg") {
  27640. if (w.snap in hub) {
  27641. return hub[w.snap];
  27642. }
  27643. var doc = w.ownerDocument;
  27644. res = new Element(w);
  27645. desc = w.getElementsByTagName("desc")[0];
  27646. defs = w.getElementsByTagName("defs")[0];
  27647. if (!desc) {
  27648. desc = $("desc");
  27649. desc.appendChild(doc.createTextNode("Created with Snap"));
  27650. res.node.appendChild(desc);
  27651. }
  27652. if (!defs) {
  27653. defs = $("defs");
  27654. res.node.appendChild(defs);
  27655. }
  27656. res.defs = defs;
  27657. for (var key in proto) if (proto[has](key)) {
  27658. res[key] = proto[key];
  27659. }
  27660. res.paper = res.root = res;
  27661. } else {
  27662. res = make("svg", glob.doc.body);
  27663. $(res.node, {
  27664. height: h,
  27665. version: 1.1,
  27666. width: w,
  27667. xmlns: xmlns
  27668. });
  27669. }
  27670. return res;
  27671. }
  27672. function wrap(dom) {
  27673. if (!dom) {
  27674. return dom;
  27675. }
  27676. if (dom instanceof Element || dom instanceof Fragment) {
  27677. return dom;
  27678. }
  27679. if (dom.tagName && dom.tagName.toLowerCase() == "svg") {
  27680. return new Paper(dom);
  27681. }
  27682. if (dom.tagName && dom.tagName.toLowerCase() == "object" && dom.type == "image/svg+xml") {
  27683. return new Paper(dom.contentDocument.getElementsByTagName("svg")[0]);
  27684. }
  27685. return new Element(dom);
  27686. }
  27687. Snap._.make = make;
  27688. Snap._.wrap = wrap;
  27689. /*\
  27690. * Paper.el
  27691. [ method ]
  27692. **
  27693. * Creates an element on paper with a given name and no attributes
  27694. **
  27695. - name (string) tag name
  27696. - attr (object) attributes
  27697. = (Element) the current element
  27698. > Usage
  27699. | var c = paper.circle(10, 10, 10); // is the same as...
  27700. | var c = paper.el("circle").attr({
  27701. | cx: 10,
  27702. | cy: 10,
  27703. | r: 10
  27704. | });
  27705. | // and the same as
  27706. | var c = paper.el("circle", {
  27707. | cx: 10,
  27708. | cy: 10,
  27709. | r: 10
  27710. | });
  27711. \*/
  27712. Paper.prototype.el = function (name, attr) {
  27713. var el = make(name, this.node);
  27714. attr && el.attr(attr);
  27715. return el;
  27716. };
  27717. // default
  27718. eve.on("snap.util.getattr", function () {
  27719. var att = eve.nt();
  27720. att = att.substring(att.lastIndexOf(".") + 1);
  27721. var css = att.replace(/[A-Z]/g, function (letter) {
  27722. return "-" + letter.toLowerCase();
  27723. });
  27724. if (cssAttr[has](css)) {
  27725. return this.node.ownerDocument.defaultView.getComputedStyle(this.node, null).getPropertyValue(css);
  27726. } else {
  27727. return $(this.node, att);
  27728. }
  27729. });
  27730. var cssAttr = {
  27731. "alignment-baseline": 0,
  27732. "baseline-shift": 0,
  27733. "clip": 0,
  27734. "clip-path": 0,
  27735. "clip-rule": 0,
  27736. "color": 0,
  27737. "color-interpolation": 0,
  27738. "color-interpolation-filters": 0,
  27739. "color-profile": 0,
  27740. "color-rendering": 0,
  27741. "cursor": 0,
  27742. "direction": 0,
  27743. "display": 0,
  27744. "dominant-baseline": 0,
  27745. "enable-background": 0,
  27746. "fill": 0,
  27747. "fill-opacity": 0,
  27748. "fill-rule": 0,
  27749. "filter": 0,
  27750. "flood-color": 0,
  27751. "flood-opacity": 0,
  27752. "font": 0,
  27753. "font-family": 0,
  27754. "font-size": 0,
  27755. "font-size-adjust": 0,
  27756. "font-stretch": 0,
  27757. "font-style": 0,
  27758. "font-variant": 0,
  27759. "font-weight": 0,
  27760. "glyph-orientation-horizontal": 0,
  27761. "glyph-orientation-vertical": 0,
  27762. "image-rendering": 0,
  27763. "kerning": 0,
  27764. "letter-spacing": 0,
  27765. "lighting-color": 0,
  27766. "marker": 0,
  27767. "marker-end": 0,
  27768. "marker-mid": 0,
  27769. "marker-start": 0,
  27770. "mask": 0,
  27771. "opacity": 0,
  27772. "overflow": 0,
  27773. "pointer-events": 0,
  27774. "shape-rendering": 0,
  27775. "stop-color": 0,
  27776. "stop-opacity": 0,
  27777. "stroke": 0,
  27778. "stroke-dasharray": 0,
  27779. "stroke-dashoffset": 0,
  27780. "stroke-linecap": 0,
  27781. "stroke-linejoin": 0,
  27782. "stroke-miterlimit": 0,
  27783. "stroke-opacity": 0,
  27784. "stroke-width": 0,
  27785. "text-anchor": 0,
  27786. "text-decoration": 0,
  27787. "text-rendering": 0,
  27788. "unicode-bidi": 0,
  27789. "visibility": 0,
  27790. "word-spacing": 0,
  27791. "writing-mode": 0
  27792. };
  27793. eve.on("snap.util.attr", function (value) {
  27794. var att = eve.nt(),
  27795. attr = {};
  27796. att = att.substring(att.lastIndexOf(".") + 1);
  27797. attr[att] = value;
  27798. var style = att.replace(/-(\w)/gi, function (all, letter) {
  27799. return letter.toUpperCase();
  27800. }),
  27801. css = att.replace(/[A-Z]/g, function (letter) {
  27802. return "-" + letter.toLowerCase();
  27803. });
  27804. if (cssAttr[has](css)) {
  27805. this.node.style[style] = value == null ? E : value;
  27806. } else {
  27807. $(this.node, attr);
  27808. }
  27809. });
  27810. (function (proto) {}(Paper.prototype));
  27811. // simple ajax
  27812. /*\
  27813. * Snap.ajax
  27814. [ method ]
  27815. **
  27816. * Simple implementation of Ajax
  27817. **
  27818. - url (string) URL
  27819. - postData (object|string) data for post request
  27820. - callback (function) callback
  27821. - scope (object) #optional scope of callback
  27822. * or
  27823. - url (string) URL
  27824. - callback (function) callback
  27825. - scope (object) #optional scope of callback
  27826. = (XMLHttpRequest) the XMLHttpRequest object, just in case
  27827. \*/
  27828. Snap.ajax = function (url, postData, callback, scope){
  27829. var req = new XMLHttpRequest,
  27830. id = ID();
  27831. if (req) {
  27832. if (is(postData, "function")) {
  27833. scope = callback;
  27834. callback = postData;
  27835. postData = null;
  27836. } else if (is(postData, "object")) {
  27837. var pd = [];
  27838. for (var key in postData) if (postData.hasOwnProperty(key)) {
  27839. pd.push(encodeURIComponent(key) + "=" + encodeURIComponent(postData[key]));
  27840. }
  27841. postData = pd.join("&");
  27842. }
  27843. req.open((postData ? "POST" : "GET"), url, true);
  27844. if (postData) {
  27845. req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  27846. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  27847. }
  27848. if (callback) {
  27849. eve.once("snap.ajax." + id + ".0", callback);
  27850. eve.once("snap.ajax." + id + ".200", callback);
  27851. eve.once("snap.ajax." + id + ".304", callback);
  27852. }
  27853. req.onreadystatechange = function() {
  27854. if (req.readyState != 4) return;
  27855. eve("snap.ajax." + id + "." + req.status, scope, req);
  27856. };
  27857. if (req.readyState == 4) {
  27858. return req;
  27859. }
  27860. req.send(postData);
  27861. return req;
  27862. }
  27863. };
  27864. /*\
  27865. * Snap.load
  27866. [ method ]
  27867. **
  27868. * Loads external SVG file as a @Fragment (see @Snap.ajax for more advanced AJAX)
  27869. **
  27870. - url (string) URL
  27871. - callback (function) callback
  27872. - scope (object) #optional scope of callback
  27873. \*/
  27874. Snap.load = function (url, callback, scope) {
  27875. Snap.ajax(url, function (req) {
  27876. var f = Snap.parse(req.responseText);
  27877. scope ? callback.call(scope, f) : callback(f);
  27878. });
  27879. };
  27880. var getOffset = function (elem) {
  27881. var box = elem.getBoundingClientRect(),
  27882. doc = elem.ownerDocument,
  27883. body = doc.body,
  27884. docElem = doc.documentElement,
  27885. clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
  27886. top = box.top + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
  27887. left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
  27888. return {
  27889. y: top,
  27890. x: left
  27891. };
  27892. };
  27893. /*\
  27894. * Snap.getElementByPoint
  27895. [ method ]
  27896. **
  27897. * Returns you topmost element under given point.
  27898. **
  27899. = (object) Snap element object
  27900. - x (number) x coordinate from the top left corner of the window
  27901. - y (number) y coordinate from the top left corner of the window
  27902. > Usage
  27903. | Snap.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"});
  27904. \*/
  27905. Snap.getElementByPoint = function (x, y) {
  27906. var paper = this,
  27907. svg = paper.canvas,
  27908. target = glob.doc.elementFromPoint(x, y);
  27909. if (glob.win.opera && target.tagName == "svg") {
  27910. var so = getOffset(target),
  27911. sr = target.createSVGRect();
  27912. sr.x = x - so.x;
  27913. sr.y = y - so.y;
  27914. sr.width = sr.height = 1;
  27915. var hits = target.getIntersectionList(sr, null);
  27916. if (hits.length) {
  27917. target = hits[hits.length - 1];
  27918. }
  27919. }
  27920. if (!target) {
  27921. return null;
  27922. }
  27923. return wrap(target);
  27924. };
  27925. /*\
  27926. * Snap.plugin
  27927. [ method ]
  27928. **
  27929. * Let you write plugins. You pass in a function with four arguments, like this:
  27930. | Snap.plugin(function (Snap, Element, Paper, global, Fragment) {
  27931. | Snap.newmethod = function () {};
  27932. | Element.prototype.newmethod = function () {};
  27933. | Paper.prototype.newmethod = function () {};
  27934. | });
  27935. * Inside the function you have access to all main objects (and their
  27936. * prototypes). This allow you to extend anything you want.
  27937. **
  27938. - f (function) your plugin body
  27939. \*/
  27940. Snap.plugin = function (f) {
  27941. f(Snap, Element, Paper, glob, Fragment);
  27942. };
  27943. glob.win.Snap = Snap;
  27944. return Snap;
  27945. }(window || this));
  27946. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  27947. //
  27948. // Licensed under the Apache License, Version 2.0 (the "License");
  27949. // you may not use this file except in compliance with the License.
  27950. // You may obtain a copy of the License at
  27951. //
  27952. // http://www.apache.org/licenses/LICENSE-2.0
  27953. //
  27954. // Unless required by applicable law or agreed to in writing, software
  27955. // distributed under the License is distributed on an "AS IS" BASIS,
  27956. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  27957. // See the License for the specific language governing permissions and
  27958. // limitations under the License.
  27959. Snap.plugin(function (Snap, Element, Paper, glob, Fragment) {
  27960. var elproto = Element.prototype,
  27961. is = Snap.is,
  27962. Str = String,
  27963. unit2px = Snap._unit2px,
  27964. $ = Snap._.$,
  27965. make = Snap._.make,
  27966. getSomeDefs = Snap._.getSomeDefs,
  27967. has = "hasOwnProperty",
  27968. wrap = Snap._.wrap;
  27969. /*\
  27970. * Element.getBBox
  27971. [ method ]
  27972. **
  27973. * Returns the bounding box descriptor for the given element
  27974. **
  27975. = (object) bounding box descriptor:
  27976. o {
  27977. o cx: (number) x of the center,
  27978. o cy: (number) x of the center,
  27979. o h: (number) height,
  27980. o height: (number) height,
  27981. o path: (string) path command for the box,
  27982. o r0: (number) radius of a circle that fully encloses the box,
  27983. o r1: (number) radius of the smallest circle that can be enclosed,
  27984. o r2: (number) radius of the largest circle that can be enclosed,
  27985. o vb: (string) box as a viewbox command,
  27986. o w: (number) width,
  27987. o width: (number) width,
  27988. o x2: (number) x of the right side,
  27989. o x: (number) x of the left side,
  27990. o y2: (number) y of the bottom edge,
  27991. o y: (number) y of the top edge
  27992. o }
  27993. \*/
  27994. elproto.getBBox = function (isWithoutTransform) {
  27995. if (!Snap.Matrix || !Snap.path) {
  27996. return this.node.getBBox();
  27997. }
  27998. var el = this,
  27999. m = new Snap.Matrix;
  28000. if (el.removed) {
  28001. return Snap._.box();
  28002. }
  28003. while (el.type == "use") {
  28004. if (!isWithoutTransform) {
  28005. m = m.add(el.transform().localMatrix.translate(el.attr("x") || 0, el.attr("y") || 0));
  28006. }
  28007. if (el.original) {
  28008. el = el.original;
  28009. } else {
  28010. var href = el.attr("xlink:href");
  28011. el = el.original = el.node.ownerDocument.getElementById(href.substring(href.indexOf("#") + 1));
  28012. }
  28013. }
  28014. var _ = el._,
  28015. pathfinder = Snap.path.get[el.type] || Snap.path.get.deflt;
  28016. try {
  28017. if (isWithoutTransform) {
  28018. _.bboxwt = pathfinder ? Snap.path.getBBox(el.realPath = pathfinder(el)) : Snap._.box(el.node.getBBox());
  28019. return Snap._.box(_.bboxwt);
  28020. } else {
  28021. el.realPath = pathfinder(el);
  28022. el.matrix = el.transform().localMatrix;
  28023. _.bbox = Snap.path.getBBox(Snap.path.map(el.realPath, m.add(el.matrix)));
  28024. return Snap._.box(_.bbox);
  28025. }
  28026. } catch (e) {
  28027. // Firefox doesn’t give you bbox of hidden element
  28028. return Snap._.box();
  28029. }
  28030. };
  28031. var propString = function () {
  28032. return this.string;
  28033. };
  28034. function extractTransform(el, tstr) {
  28035. if (tstr == null) {
  28036. var doReturn = true;
  28037. if (el.type == "linearGradient" || el.type == "radialGradient") {
  28038. tstr = el.node.getAttribute("gradientTransform");
  28039. } else if (el.type == "pattern") {
  28040. tstr = el.node.getAttribute("patternTransform");
  28041. } else {
  28042. tstr = el.node.getAttribute("transform");
  28043. }
  28044. if (!tstr) {
  28045. return new Snap.Matrix;
  28046. }
  28047. tstr = Snap._.svgTransform2string(tstr);
  28048. } else {
  28049. if (!Snap._.rgTransform.test(tstr)) {
  28050. tstr = Snap._.svgTransform2string(tstr);
  28051. } else {
  28052. tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
  28053. }
  28054. if (is(tstr, "array")) {
  28055. tstr = Snap.path ? Snap.path.toString.call(tstr) : Str(tstr);
  28056. }
  28057. el._.transform = tstr;
  28058. }
  28059. var m = Snap._.transform2matrix(tstr, el.getBBox(1));
  28060. if (doReturn) {
  28061. return m;
  28062. } else {
  28063. el.matrix = m;
  28064. }
  28065. }
  28066. /*\
  28067. * Element.transform
  28068. [ method ]
  28069. **
  28070. * Gets or sets transformation of the element
  28071. **
  28072. - tstr (string) transform string in Snap or SVG format
  28073. = (Element) the current element
  28074. * or
  28075. = (object) transformation descriptor:
  28076. o {
  28077. o string (string) transform string,
  28078. o globalMatrix (Matrix) matrix of all transformations applied to element or its parents,
  28079. o localMatrix (Matrix) matrix of transformations applied only to the element,
  28080. o diffMatrix (Matrix) matrix of difference between global and local transformations,
  28081. o global (string) global transformation as string,
  28082. o local (string) local transformation as string,
  28083. o toString (function) returns `string` property
  28084. o }
  28085. \*/
  28086. elproto.transform = function (tstr) {
  28087. var _ = this._;
  28088. if (tstr == null) {
  28089. var papa = this,
  28090. global = new Snap.Matrix(this.node.getCTM()),
  28091. local = extractTransform(this),
  28092. ms = [local],
  28093. m = new Snap.Matrix,
  28094. i,
  28095. localString = local.toTransformString(),
  28096. string = Str(local) == Str(this.matrix) ?
  28097. Str(_.transform) : localString;
  28098. while (papa.type != "svg" && (papa = papa.parent())) {
  28099. ms.push(extractTransform(papa));
  28100. }
  28101. i = ms.length;
  28102. while (i--) {
  28103. m.add(ms[i]);
  28104. }
  28105. return {
  28106. string: string,
  28107. globalMatrix: global,
  28108. totalMatrix: m,
  28109. localMatrix: local,
  28110. diffMatrix: global.clone().add(local.invert()),
  28111. global: global.toTransformString(),
  28112. total: m.toTransformString(),
  28113. local: localString,
  28114. toString: propString
  28115. };
  28116. }
  28117. if (tstr instanceof Snap.Matrix) {
  28118. this.matrix = tstr;
  28119. this._.transform = tstr.toTransformString();
  28120. } else {
  28121. extractTransform(this, tstr);
  28122. }
  28123. if (this.node) {
  28124. if (this.type == "linearGradient" || this.type == "radialGradient") {
  28125. $(this.node, {gradientTransform: this.matrix});
  28126. } else if (this.type == "pattern") {
  28127. $(this.node, {patternTransform: this.matrix});
  28128. } else {
  28129. $(this.node, {transform: this.matrix});
  28130. }
  28131. }
  28132. return this;
  28133. };
  28134. /*\
  28135. * Element.parent
  28136. [ method ]
  28137. **
  28138. * Returns the element's parent
  28139. **
  28140. = (Element) the parent element
  28141. \*/
  28142. elproto.parent = function () {
  28143. return wrap(this.node.parentNode);
  28144. };
  28145. /*\
  28146. * Element.append
  28147. [ method ]
  28148. **
  28149. * Appends the given element to current one
  28150. **
  28151. - el (Element|Set) element to append
  28152. = (Element) the parent element
  28153. \*/
  28154. /*\
  28155. * Element.add
  28156. [ method ]
  28157. **
  28158. * See @Element.append
  28159. \*/
  28160. elproto.append = elproto.add = function (el) {
  28161. if (el) {
  28162. if (el.type == "set") {
  28163. var it = this;
  28164. el.forEach(function (el) {
  28165. it.add(el);
  28166. });
  28167. return this;
  28168. }
  28169. el = wrap(el);
  28170. this.node.appendChild(el.node);
  28171. el.paper = this.paper;
  28172. }
  28173. return this;
  28174. };
  28175. /*\
  28176. * Element.appendTo
  28177. [ method ]
  28178. **
  28179. * Appends the current element to the given one
  28180. **
  28181. - el (Element) parent element to append to
  28182. = (Element) the child element
  28183. \*/
  28184. elproto.appendTo = function (el) {
  28185. if (el) {
  28186. el = wrap(el);
  28187. el.append(this);
  28188. }
  28189. return this;
  28190. };
  28191. /*\
  28192. * Element.prepend
  28193. [ method ]
  28194. **
  28195. * Prepends the given element to the current one
  28196. **
  28197. - el (Element) element to prepend
  28198. = (Element) the parent element
  28199. \*/
  28200. elproto.prepend = function (el) {
  28201. if (el) {
  28202. if (el.type == "set") {
  28203. var it = this,
  28204. first;
  28205. el.forEach(function (el) {
  28206. if (first) {
  28207. first.after(el);
  28208. } else {
  28209. it.prepend(el);
  28210. }
  28211. first = el;
  28212. });
  28213. return this;
  28214. }
  28215. el = wrap(el);
  28216. var parent = el.parent();
  28217. this.node.insertBefore(el.node, this.node.firstChild);
  28218. this.add && this.add();
  28219. el.paper = this.paper;
  28220. this.parent() && this.parent().add();
  28221. parent && parent.add();
  28222. }
  28223. return this;
  28224. };
  28225. /*\
  28226. * Element.prependTo
  28227. [ method ]
  28228. **
  28229. * Prepends the current element to the given one
  28230. **
  28231. - el (Element) parent element to prepend to
  28232. = (Element) the child element
  28233. \*/
  28234. elproto.prependTo = function (el) {
  28235. el = wrap(el);
  28236. el.prepend(this);
  28237. return this;
  28238. };
  28239. /*\
  28240. * Element.before
  28241. [ method ]
  28242. **
  28243. * Inserts given element before the current one
  28244. **
  28245. - el (Element) element to insert
  28246. = (Element) the parent element
  28247. \*/
  28248. elproto.before = function (el) {
  28249. if (el.type == "set") {
  28250. var it = this;
  28251. el.forEach(function (el) {
  28252. var parent = el.parent();
  28253. it.node.parentNode.insertBefore(el.node, it.node);
  28254. parent && parent.add();
  28255. });
  28256. this.parent().add();
  28257. return this;
  28258. }
  28259. el = wrap(el);
  28260. var parent = el.parent();
  28261. this.node.parentNode.insertBefore(el.node, this.node);
  28262. this.parent() && this.parent().add();
  28263. parent && parent.add();
  28264. el.paper = this.paper;
  28265. return this;
  28266. };
  28267. /*\
  28268. * Element.after
  28269. [ method ]
  28270. **
  28271. * Inserts given element after the current one
  28272. **
  28273. - el (Element) element to insert
  28274. = (Element) the parent element
  28275. \*/
  28276. elproto.after = function (el) {
  28277. el = wrap(el);
  28278. var parent = el.parent();
  28279. if (this.node.nextSibling) {
  28280. this.node.parentNode.insertBefore(el.node, this.node.nextSibling);
  28281. } else {
  28282. this.node.parentNode.appendChild(el.node);
  28283. }
  28284. this.parent() && this.parent().add();
  28285. parent && parent.add();
  28286. el.paper = this.paper;
  28287. return this;
  28288. };
  28289. /*\
  28290. * Element.insertBefore
  28291. [ method ]
  28292. **
  28293. * Inserts the element after the given one
  28294. **
  28295. - el (Element) element next to whom insert to
  28296. = (Element) the parent element
  28297. \*/
  28298. elproto.insertBefore = function (el) {
  28299. el = wrap(el);
  28300. var parent = this.parent();
  28301. el.node.parentNode.insertBefore(this.node, el.node);
  28302. this.paper = el.paper;
  28303. parent && parent.add();
  28304. el.parent() && el.parent().add();
  28305. return this;
  28306. };
  28307. /*\
  28308. * Element.insertAfter
  28309. [ method ]
  28310. **
  28311. * Inserts the element after the given one
  28312. **
  28313. - el (Element) element next to whom insert to
  28314. = (Element) the parent element
  28315. \*/
  28316. elproto.insertAfter = function (el) {
  28317. el = wrap(el);
  28318. var parent = this.parent();
  28319. el.node.parentNode.insertBefore(this.node, el.node.nextSibling);
  28320. this.paper = el.paper;
  28321. parent && parent.add();
  28322. el.parent() && el.parent().add();
  28323. return this;
  28324. };
  28325. /*\
  28326. * Element.remove
  28327. [ method ]
  28328. **
  28329. * Removes element from the DOM
  28330. = (Element) the detached element
  28331. \*/
  28332. elproto.remove = function () {
  28333. var parent = this.parent();
  28334. this.node.parentNode && this.node.parentNode.removeChild(this.node);
  28335. delete this.paper;
  28336. this.removed = true;
  28337. parent && parent.add();
  28338. return this;
  28339. };
  28340. /*\
  28341. * Element.select
  28342. [ method ]
  28343. **
  28344. * Gathers the nested @Element matching the given set of CSS selectors
  28345. **
  28346. - query (string) CSS selector
  28347. = (Element) result of query selection
  28348. \*/
  28349. elproto.select = function (query) {
  28350. query = Str(query).replace(/([^\\]):/g, "$1\\:");
  28351. return wrap(this.node.querySelector(query));
  28352. };
  28353. /*\
  28354. * Element.selectAll
  28355. [ method ]
  28356. **
  28357. * Gathers nested @Element objects matching the given set of CSS selectors
  28358. **
  28359. - query (string) CSS selector
  28360. = (Set|array) result of query selection
  28361. \*/
  28362. elproto.selectAll = function (query) {
  28363. var nodelist = this.node.querySelectorAll(query),
  28364. set = (Snap.set || Array)();
  28365. for (var i = 0; i < nodelist.length; i++) {
  28366. set.push(wrap(nodelist[i]));
  28367. }
  28368. return set;
  28369. };
  28370. /*\
  28371. * Element.asPX
  28372. [ method ]
  28373. **
  28374. * Returns given attribute of the element as a `px` value (not %, em, etc.)
  28375. **
  28376. - attr (string) attribute name
  28377. - value (string) #optional attribute value
  28378. = (Element) result of query selection
  28379. \*/
  28380. elproto.asPX = function (attr, value) {
  28381. if (value == null) {
  28382. value = this.attr(attr);
  28383. }
  28384. return +unit2px(this, attr, value);
  28385. };
  28386. // SIERRA Element.use(): I suggest adding a note about how to access the original element the returned <use> instantiates. It's a part of SVG with which ordinary web developers may be least familiar.
  28387. /*\
  28388. * Element.use
  28389. [ method ]
  28390. **
  28391. * Creates a `<use>` element linked to the current element
  28392. **
  28393. = (Element) the `<use>` element
  28394. \*/
  28395. elproto.use = function () {
  28396. var use,
  28397. id = this.node.id;
  28398. if (!id) {
  28399. id = this.id;
  28400. $(this.node, {
  28401. id: id
  28402. });
  28403. }
  28404. if (this.type == "linearGradient" || this.type == "radialGradient" ||
  28405. this.type == "pattern") {
  28406. use = make(this.type, this.node.parentNode);
  28407. } else {
  28408. use = make("use", this.node.parentNode);
  28409. }
  28410. $(use.node, {
  28411. "xlink:href": "#" + id
  28412. });
  28413. use.original = this;
  28414. return use;
  28415. };
  28416. function fixids(el) {
  28417. var els = el.selectAll("*"),
  28418. it,
  28419. url = /^\s*url\(("|'|)(.*)\1\)\s*$/,
  28420. ids = [],
  28421. uses = {};
  28422. function urltest(it, name) {
  28423. var val = $(it.node, name);
  28424. val = val && val.match(url);
  28425. val = val && val[2];
  28426. if (val && val.charAt() == "#") {
  28427. val = val.substring(1);
  28428. } else {
  28429. return;
  28430. }
  28431. if (val) {
  28432. uses[val] = (uses[val] || []).concat(function (id) {
  28433. var attr = {};
  28434. attr[name] = URL(id);
  28435. $(it.node, attr);
  28436. });
  28437. }
  28438. }
  28439. function linktest(it) {
  28440. var val = $(it.node, "xlink:href");
  28441. if (val && val.charAt() == "#") {
  28442. val = val.substring(1);
  28443. } else {
  28444. return;
  28445. }
  28446. if (val) {
  28447. uses[val] = (uses[val] || []).concat(function (id) {
  28448. it.attr("xlink:href", "#" + id);
  28449. });
  28450. }
  28451. }
  28452. for (var i = 0, ii = els.length; i < ii; i++) {
  28453. it = els[i];
  28454. urltest(it, "fill");
  28455. urltest(it, "stroke");
  28456. urltest(it, "filter");
  28457. urltest(it, "mask");
  28458. urltest(it, "clip-path");
  28459. linktest(it);
  28460. var oldid = $(it.node, "id");
  28461. if (oldid) {
  28462. $(it.node, {id: it.id});
  28463. ids.push({
  28464. old: oldid,
  28465. id: it.id
  28466. });
  28467. }
  28468. }
  28469. for (i = 0, ii = ids.length; i < ii; i++) {
  28470. var fs = uses[ids[i].old];
  28471. if (fs) {
  28472. for (var j = 0, jj = fs.length; j < jj; j++) {
  28473. fs[j](ids[i].id);
  28474. }
  28475. }
  28476. }
  28477. }
  28478. /*\
  28479. * Element.clone
  28480. [ method ]
  28481. **
  28482. * Creates a clone of the element and inserts it after the element
  28483. **
  28484. = (Element) the clone
  28485. \*/
  28486. elproto.clone = function () {
  28487. var clone = wrap(this.node.cloneNode(true));
  28488. if ($(clone.node, "id")) {
  28489. $(clone.node, {id: clone.id});
  28490. }
  28491. fixids(clone);
  28492. clone.insertAfter(this);
  28493. return clone;
  28494. };
  28495. /*\
  28496. * Element.toDefs
  28497. [ method ]
  28498. **
  28499. * Moves element to the shared `<defs>` area
  28500. **
  28501. = (Element) the element
  28502. \*/
  28503. elproto.toDefs = function () {
  28504. var defs = getSomeDefs(this);
  28505. defs.appendChild(this.node);
  28506. return this;
  28507. };
  28508. /*\
  28509. * Element.toPattern
  28510. [ method ]
  28511. **
  28512. * Creates a `<pattern>` element from the current element
  28513. **
  28514. * To create a pattern you have to specify the pattern rect:
  28515. - x (string|number)
  28516. - y (string|number)
  28517. - width (string|number)
  28518. - height (string|number)
  28519. = (Element) the `<pattern>` element
  28520. * You can use pattern later on as an argument for `fill` attribute:
  28521. | var p = paper.path("M10-5-10,15M15,0,0,15M0-5-20,15").attr({
  28522. | fill: "none",
  28523. | stroke: "#bada55",
  28524. | strokeWidth: 5
  28525. | }).pattern(0, 0, 10, 10),
  28526. | c = paper.circle(200, 200, 100);
  28527. | c.attr({
  28528. | fill: p
  28529. | });
  28530. \*/
  28531. elproto.pattern = elproto.toPattern = function (x, y, width, height) {
  28532. var p = make("pattern", getSomeDefs(this));
  28533. if (x == null) {
  28534. x = this.getBBox();
  28535. }
  28536. if (is(x, "object") && "x" in x) {
  28537. y = x.y;
  28538. width = x.width;
  28539. height = x.height;
  28540. x = x.x;
  28541. }
  28542. $(p.node, {
  28543. x: x,
  28544. y: y,
  28545. width: width,
  28546. height: height,
  28547. patternUnits: "userSpaceOnUse",
  28548. id: p.id,
  28549. viewBox: [x, y, width, height].join(" ")
  28550. });
  28551. p.node.appendChild(this.node);
  28552. return p;
  28553. };
  28554. // SIERRA Element.marker(): clarify what a reference point is. E.g., helps you offset the object from its edge such as when centering it over a path.
  28555. // SIERRA Element.marker(): I suggest the method should accept default reference point values. Perhaps centered with (refX = width/2) and (refY = height/2)? Also, couldn't it assume the element's current _width_ and _height_? And please specify what _x_ and _y_ mean: offsets? If so, from where? Couldn't they also be assigned default values?
  28556. /*\
  28557. * Element.marker
  28558. [ method ]
  28559. **
  28560. * Creates a `<marker>` element from the current element
  28561. **
  28562. * To create a marker you have to specify the bounding rect and reference point:
  28563. - x (number)
  28564. - y (number)
  28565. - width (number)
  28566. - height (number)
  28567. - refX (number)
  28568. - refY (number)
  28569. = (Element) the `<marker>` element
  28570. * You can specify the marker later as an argument for `marker-start`, `marker-end`, `marker-mid`, and `marker` attributes. The `marker` attribute places the marker at every point along the path, and `marker-mid` places them at every point except the start and end.
  28571. \*/
  28572. // TODO add usage for markers
  28573. elproto.marker = function (x, y, width, height, refX, refY) {
  28574. var p = make("marker", getSomeDefs(this));
  28575. if (x == null) {
  28576. x = this.getBBox();
  28577. }
  28578. if (is(x, "object") && "x" in x) {
  28579. y = x.y;
  28580. width = x.width;
  28581. height = x.height;
  28582. refX = x.refX || x.cx;
  28583. refY = x.refY || x.cy;
  28584. x = x.x;
  28585. }
  28586. $(p.node, {
  28587. viewBox: [x, y, width, height].join(" "),
  28588. markerWidth: width,
  28589. markerHeight: height,
  28590. orient: "auto",
  28591. refX: refX || 0,
  28592. refY: refY || 0,
  28593. id: p.id
  28594. });
  28595. p.node.appendChild(this.node);
  28596. return p;
  28597. };
  28598. // animation
  28599. function slice(from, to, f) {
  28600. return function (arr) {
  28601. var res = arr.slice(from, to);
  28602. if (res.length == 1) {
  28603. res = res[0];
  28604. }
  28605. return f ? f(res) : res;
  28606. };
  28607. }
  28608. var Animation = function (attr, ms, easing, callback) {
  28609. if (typeof easing == "function" && !easing.length) {
  28610. callback = easing;
  28611. easing = mina.linear;
  28612. }
  28613. this.attr = attr;
  28614. this.dur = ms;
  28615. easing && (this.easing = easing);
  28616. callback && (this.callback = callback);
  28617. };
  28618. Snap._.Animation = Animation;
  28619. /*\
  28620. * Snap.animation
  28621. [ method ]
  28622. **
  28623. * Creates an animation object
  28624. **
  28625. - attr (object) attributes of final destination
  28626. - duration (number) duration of the animation, in milliseconds
  28627. - easing (function) #optional one of easing functions of @mina or custom one
  28628. - callback (function) #optional callback function that fires when animation ends
  28629. = (object) animation object
  28630. \*/
  28631. Snap.animation = function (attr, ms, easing, callback) {
  28632. return new Animation(attr, ms, easing, callback);
  28633. };
  28634. /*\
  28635. * Element.inAnim
  28636. [ method ]
  28637. **
  28638. * Returns a set of animations that may be able to manipulate the current element
  28639. **
  28640. = (object) in format:
  28641. o {
  28642. o anim (object) animation object,
  28643. o mina (object) @mina object,
  28644. o curStatus (number) 0..1 — status of the animation: 0 — just started, 1 — just finished,
  28645. o status (function) gets or sets the status of the animation,
  28646. o stop (function) stops the animation
  28647. o }
  28648. \*/
  28649. elproto.inAnim = function () {
  28650. var el = this,
  28651. res = [];
  28652. for (var id in el.anims) if (el.anims[has](id)) {
  28653. (function (a) {
  28654. res.push({
  28655. anim: new Animation(a._attrs, a.dur, a.easing, a._callback),
  28656. mina: a,
  28657. curStatus: a.status(),
  28658. status: function (val) {
  28659. return a.status(val);
  28660. },
  28661. stop: function () {
  28662. a.stop();
  28663. }
  28664. });
  28665. }(el.anims[id]));
  28666. }
  28667. return res;
  28668. };
  28669. /*\
  28670. * Snap.animate
  28671. [ method ]
  28672. **
  28673. * Runs generic animation of one number into another with a caring function
  28674. **
  28675. - from (number|array) number or array of numbers
  28676. - to (number|array) number or array of numbers
  28677. - setter (function) caring function that accepts one number argument
  28678. - duration (number) duration, in milliseconds
  28679. - easing (function) #optional easing function from @mina or custom
  28680. - callback (function) #optional callback function to execute when animation ends
  28681. = (object) animation object in @mina format
  28682. o {
  28683. o id (string) animation id, consider it read-only,
  28684. o duration (function) gets or sets the duration of the animation,
  28685. o easing (function) easing,
  28686. o speed (function) gets or sets the speed of the animation,
  28687. o status (function) gets or sets the status of the animation,
  28688. o stop (function) stops the animation
  28689. o }
  28690. | var rect = Snap().rect(0, 0, 10, 10);
  28691. | Snap.animate(0, 10, function (val) {
  28692. | rect.attr({
  28693. | x: val
  28694. | });
  28695. | }, 1000);
  28696. | // in given context is equivalent to
  28697. | rect.animate({x: 10}, 1000);
  28698. \*/
  28699. Snap.animate = function (from, to, setter, ms, easing, callback) {
  28700. if (typeof easing == "function" && !easing.length) {
  28701. callback = easing;
  28702. easing = mina.linear;
  28703. }
  28704. var now = mina.time(),
  28705. anim = mina(from, to, now, now + ms, mina.time, setter, easing);
  28706. callback && eve.once("mina.finish." + anim.id, callback);
  28707. return anim;
  28708. };
  28709. /*\
  28710. * Element.stop
  28711. [ method ]
  28712. **
  28713. * Stops all the animations for the current element
  28714. **
  28715. = (Element) the current element
  28716. \*/
  28717. elproto.stop = function () {
  28718. var anims = this.inAnim();
  28719. for (var i = 0, ii = anims.length; i < ii; i++) {
  28720. anims[i].stop();
  28721. }
  28722. return this;
  28723. };
  28724. /*\
  28725. * Element.animate
  28726. [ method ]
  28727. **
  28728. * Animates the given attributes of the element
  28729. **
  28730. - attrs (object) key-value pairs of destination attributes
  28731. - duration (number) duration of the animation in milliseconds
  28732. - easing (function) #optional easing function from @mina or custom
  28733. - callback (function) #optional callback function that executes when the animation ends
  28734. = (Element) the current element
  28735. \*/
  28736. elproto.animate = function (attrs, ms, easing, callback) {
  28737. if (typeof easing == "function" && !easing.length) {
  28738. callback = easing;
  28739. easing = mina.linear;
  28740. }
  28741. if (attrs instanceof Animation) {
  28742. callback = attrs.callback;
  28743. easing = attrs.easing;
  28744. ms = easing.dur;
  28745. attrs = attrs.attr;
  28746. }
  28747. var fkeys = [], tkeys = [], keys = {}, from, to, f, eq,
  28748. el = this;
  28749. for (var key in attrs) if (attrs[has](key)) {
  28750. if (el.equal) {
  28751. eq = el.equal(key, Str(attrs[key]));
  28752. from = eq.from;
  28753. to = eq.to;
  28754. f = eq.f;
  28755. } else {
  28756. from = +el.attr(key);
  28757. to = +attrs[key];
  28758. }
  28759. var len = is(from, "array") ? from.length : 1;
  28760. keys[key] = slice(fkeys.length, fkeys.length + len, f);
  28761. fkeys = fkeys.concat(from);
  28762. tkeys = tkeys.concat(to);
  28763. }
  28764. var now = mina.time(),
  28765. anim = mina(fkeys, tkeys, now, now + ms, mina.time, function (val) {
  28766. var attr = {};
  28767. for (var key in keys) if (keys[has](key)) {
  28768. attr[key] = keys[key](val);
  28769. }
  28770. el.attr(attr);
  28771. }, easing);
  28772. el.anims[anim.id] = anim;
  28773. anim._attrs = attrs;
  28774. anim._callback = callback;
  28775. eve("snap.animcreated." + el.id, anim);
  28776. eve.once("mina.finish." + anim.id, function () {
  28777. delete el.anims[anim.id];
  28778. callback && callback.call(el);
  28779. });
  28780. eve.once("mina.stop." + anim.id, function () {
  28781. delete el.anims[anim.id];
  28782. });
  28783. return el;
  28784. };
  28785. var eldata = {};
  28786. /*\
  28787. * Element.data
  28788. [ method ]
  28789. **
  28790. * Adds or retrieves given value associated with given key. (Don’t confuse
  28791. * with `data-` attributes)
  28792. *
  28793. * See also @Element.removeData
  28794. - key (string) key to store data
  28795. - value (any) #optional value to store
  28796. = (object) @Element
  28797. * or, if value is not specified:
  28798. = (any) value
  28799. > Usage
  28800. | for (var i = 0, i < 5, i++) {
  28801. | paper.circle(10 + 15 * i, 10, 10)
  28802. | .attr({fill: "#000"})
  28803. | .data("i", i)
  28804. | .click(function () {
  28805. | alert(this.data("i"));
  28806. | });
  28807. | }
  28808. \*/
  28809. elproto.data = function (key, value) {
  28810. var data = eldata[this.id] = eldata[this.id] || {};
  28811. if (arguments.length == 0){
  28812. eve("snap.data.get." + this.id, this, data, null);
  28813. return data;
  28814. }
  28815. if (arguments.length == 1) {
  28816. if (Snap.is(key, "object")) {
  28817. for (var i in key) if (key[has](i)) {
  28818. this.data(i, key[i]);
  28819. }
  28820. return this;
  28821. }
  28822. eve("snap.data.get." + this.id, this, data[key], key);
  28823. return data[key];
  28824. }
  28825. data[key] = value;
  28826. eve("snap.data.set." + this.id, this, value, key);
  28827. return this;
  28828. };
  28829. /*\
  28830. * Element.removeData
  28831. [ method ]
  28832. **
  28833. * Removes value associated with an element by given key.
  28834. * If key is not provided, removes all the data of the element.
  28835. - key (string) #optional key
  28836. = (object) @Element
  28837. \*/
  28838. elproto.removeData = function (key) {
  28839. if (key == null) {
  28840. eldata[this.id] = {};
  28841. } else {
  28842. eldata[this.id] && delete eldata[this.id][key];
  28843. }
  28844. return this;
  28845. };
  28846. /*\
  28847. * Element.outerSVG
  28848. [ method ]
  28849. **
  28850. * Returns SVG code for the element, equivalent to HTML's `outerHTML`.
  28851. *
  28852. * See also @Element.innerSVG
  28853. = (string) SVG code for the element
  28854. \*/
  28855. /*\
  28856. * Element.toString
  28857. [ method ]
  28858. **
  28859. * See @Element.outerSVG
  28860. \*/
  28861. elproto.outerSVG = elproto.toString = toString(1);
  28862. /*\
  28863. * Element.innerSVG
  28864. [ method ]
  28865. **
  28866. * Returns SVG code for the element's contents, equivalent to HTML's `innerHTML`
  28867. = (string) SVG code for the element
  28868. \*/
  28869. elproto.innerSVG = toString();
  28870. function toString(type) {
  28871. return function () {
  28872. var res = type ? "<" + this.type : "",
  28873. attr = this.node.attributes,
  28874. chld = this.node.childNodes;
  28875. if (type) {
  28876. for (var i = 0, ii = attr.length; i < ii; i++) {
  28877. res += " " + attr[i].name + '="' +
  28878. attr[i].value.replace(/"/g, '\\"') + '"';
  28879. }
  28880. }
  28881. if (chld.length) {
  28882. type && (res += ">");
  28883. for (i = 0, ii = chld.length; i < ii; i++) {
  28884. if (chld[i].nodeType == 3) {
  28885. res += chld[i].nodeValue;
  28886. } else if (chld[i].nodeType == 1) {
  28887. res += wrap(chld[i]).toString();
  28888. }
  28889. }
  28890. type && (res += "</" + this.type + ">");
  28891. } else {
  28892. type && (res += "/>");
  28893. }
  28894. return res;
  28895. };
  28896. }
  28897. elproto.toDataURL = function () {
  28898. if (window && window.btoa) {
  28899. var bb = this.getBBox(),
  28900. svg = Snap.format('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="{width}" height="{height}" viewBox="{x} {y} {width} {height}">{contents}</svg>', {
  28901. x: +bb.x.toFixed(3),
  28902. y: +bb.y.toFixed(3),
  28903. width: +bb.width.toFixed(3),
  28904. height: +bb.height.toFixed(3),
  28905. contents: this.outerSVG()
  28906. });
  28907. return "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svg)));
  28908. }
  28909. };
  28910. /*\
  28911. * Fragment.select
  28912. [ method ]
  28913. **
  28914. * See @Element.select
  28915. \*/
  28916. Fragment.prototype.select = elproto.select;
  28917. /*\
  28918. * Fragment.selectAll
  28919. [ method ]
  28920. **
  28921. * See @Element.selectAll
  28922. \*/
  28923. Fragment.prototype.selectAll = elproto.selectAll;
  28924. });
  28925. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  28926. //
  28927. // Licensed under the Apache License, Version 2.0 (the "License");
  28928. // you may not use this file except in compliance with the License.
  28929. // You may obtain a copy of the License at
  28930. //
  28931. // http://www.apache.org/licenses/LICENSE-2.0
  28932. //
  28933. // Unless required by applicable law or agreed to in writing, software
  28934. // distributed under the License is distributed on an "AS IS" BASIS,
  28935. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  28936. // See the License for the specific language governing permissions and
  28937. // limitations under the License.
  28938. Snap.plugin(function (Snap, Element, Paper, glob, Fragment) {
  28939. var objectToString = Object.prototype.toString,
  28940. Str = String,
  28941. math = Math,
  28942. E = "";
  28943. function Matrix(a, b, c, d, e, f) {
  28944. if (b == null && objectToString.call(a) == "[object SVGMatrix]") {
  28945. this.a = a.a;
  28946. this.b = a.b;
  28947. this.c = a.c;
  28948. this.d = a.d;
  28949. this.e = a.e;
  28950. this.f = a.f;
  28951. return;
  28952. }
  28953. if (a != null) {
  28954. this.a = +a;
  28955. this.b = +b;
  28956. this.c = +c;
  28957. this.d = +d;
  28958. this.e = +e;
  28959. this.f = +f;
  28960. } else {
  28961. this.a = 1;
  28962. this.b = 0;
  28963. this.c = 0;
  28964. this.d = 1;
  28965. this.e = 0;
  28966. this.f = 0;
  28967. }
  28968. }
  28969. (function (matrixproto) {
  28970. /*\
  28971. * Matrix.add
  28972. [ method ]
  28973. **
  28974. * Adds the given matrix to existing one
  28975. - a (number)
  28976. - b (number)
  28977. - c (number)
  28978. - d (number)
  28979. - e (number)
  28980. - f (number)
  28981. * or
  28982. - matrix (object) @Matrix
  28983. \*/
  28984. matrixproto.add = function (a, b, c, d, e, f) {
  28985. var out = [[], [], []],
  28986. m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
  28987. matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
  28988. x, y, z, res;
  28989. if (a && a instanceof Matrix) {
  28990. matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
  28991. }
  28992. for (x = 0; x < 3; x++) {
  28993. for (y = 0; y < 3; y++) {
  28994. res = 0;
  28995. for (z = 0; z < 3; z++) {
  28996. res += m[x][z] * matrix[z][y];
  28997. }
  28998. out[x][y] = res;
  28999. }
  29000. }
  29001. this.a = out[0][0];
  29002. this.b = out[1][0];
  29003. this.c = out[0][1];
  29004. this.d = out[1][1];
  29005. this.e = out[0][2];
  29006. this.f = out[1][2];
  29007. return this;
  29008. };
  29009. /*\
  29010. * Matrix.invert
  29011. [ method ]
  29012. **
  29013. * Returns an inverted version of the matrix
  29014. = (object) @Matrix
  29015. \*/
  29016. matrixproto.invert = function () {
  29017. var me = this,
  29018. x = me.a * me.d - me.b * me.c;
  29019. return new Matrix(me.d / x, -me.b / x, -me.c / x, me.a / x, (me.c * me.f - me.d * me.e) / x, (me.b * me.e - me.a * me.f) / x);
  29020. };
  29021. /*\
  29022. * Matrix.clone
  29023. [ method ]
  29024. **
  29025. * Returns a copy of the matrix
  29026. = (object) @Matrix
  29027. \*/
  29028. matrixproto.clone = function () {
  29029. return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
  29030. };
  29031. /*\
  29032. * Matrix.translate
  29033. [ method ]
  29034. **
  29035. * Translate the matrix
  29036. - x (number) horizontal offset distance
  29037. - y (number) vertical offset distance
  29038. \*/
  29039. matrixproto.translate = function (x, y) {
  29040. return this.add(1, 0, 0, 1, x, y);
  29041. };
  29042. /*\
  29043. * Matrix.scale
  29044. [ method ]
  29045. **
  29046. * Scales the matrix
  29047. - x (number) amount to be scaled, with `1` resulting in no change
  29048. - y (number) #optional amount to scale along the vertical axis. (Otherwise `x` applies to both axes.)
  29049. - cx (number) #optional horizontal origin point from which to scale
  29050. - cy (number) #optional vertical origin point from which to scale
  29051. * Default cx, cy is the middle point of the element.
  29052. \*/
  29053. matrixproto.scale = function (x, y, cx, cy) {
  29054. y == null && (y = x);
  29055. (cx || cy) && this.add(1, 0, 0, 1, cx, cy);
  29056. this.add(x, 0, 0, y, 0, 0);
  29057. (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy);
  29058. return this;
  29059. };
  29060. /*\
  29061. * Matrix.rotate
  29062. [ method ]
  29063. **
  29064. * Rotates the matrix
  29065. - a (number) angle of rotation, in degrees
  29066. - x (number) horizontal origin point from which to rotate
  29067. - y (number) vertical origin point from which to rotate
  29068. \*/
  29069. matrixproto.rotate = function (a, x, y) {
  29070. a = Snap.rad(a);
  29071. x = x || 0;
  29072. y = y || 0;
  29073. var cos = +math.cos(a).toFixed(9),
  29074. sin = +math.sin(a).toFixed(9);
  29075. this.add(cos, sin, -sin, cos, x, y);
  29076. return this.add(1, 0, 0, 1, -x, -y);
  29077. };
  29078. /*\
  29079. * Matrix.x
  29080. [ method ]
  29081. **
  29082. * Returns x coordinate for given point after transformation described by the matrix. See also @Matrix.y
  29083. - x (number)
  29084. - y (number)
  29085. = (number) x
  29086. \*/
  29087. matrixproto.x = function (x, y) {
  29088. return x * this.a + y * this.c + this.e;
  29089. };
  29090. /*\
  29091. * Matrix.y
  29092. [ method ]
  29093. **
  29094. * Returns y coordinate for given point after transformation described by the matrix. See also @Matrix.x
  29095. - x (number)
  29096. - y (number)
  29097. = (number) y
  29098. \*/
  29099. matrixproto.y = function (x, y) {
  29100. return x * this.b + y * this.d + this.f;
  29101. };
  29102. matrixproto.get = function (i) {
  29103. return +this[Str.fromCharCode(97 + i)].toFixed(4);
  29104. };
  29105. matrixproto.toString = function () {
  29106. return "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")";
  29107. };
  29108. matrixproto.offset = function () {
  29109. return [this.e.toFixed(4), this.f.toFixed(4)];
  29110. };
  29111. function norm(a) {
  29112. return a[0] * a[0] + a[1] * a[1];
  29113. }
  29114. function normalize(a) {
  29115. var mag = math.sqrt(norm(a));
  29116. a[0] && (a[0] /= mag);
  29117. a[1] && (a[1] /= mag);
  29118. }
  29119. /*\
  29120. * Matrix.determinant
  29121. [ method ]
  29122. **
  29123. * Finds determinant of the given matrix.
  29124. = (number) determinant
  29125. \*/
  29126. matrixproto.determinant = function () {
  29127. return this.a * this.d - this.b * this.c;
  29128. };
  29129. /*\
  29130. * Matrix.split
  29131. [ method ]
  29132. **
  29133. * Splits matrix into primitive transformations
  29134. = (object) in format:
  29135. o dx (number) translation by x
  29136. o dy (number) translation by y
  29137. o scalex (number) scale by x
  29138. o scaley (number) scale by y
  29139. o shear (number) shear
  29140. o rotate (number) rotation in deg
  29141. o isSimple (boolean) could it be represented via simple transformations
  29142. \*/
  29143. matrixproto.split = function () {
  29144. var out = {};
  29145. // translation
  29146. out.dx = this.e;
  29147. out.dy = this.f;
  29148. // scale and shear
  29149. var row = [[this.a, this.c], [this.b, this.d]];
  29150. out.scalex = math.sqrt(norm(row[0]));
  29151. normalize(row[0]);
  29152. out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
  29153. row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
  29154. out.scaley = math.sqrt(norm(row[1]));
  29155. normalize(row[1]);
  29156. out.shear /= out.scaley;
  29157. if (this.determinant() < 0) {
  29158. out.scalex = -out.scalex;
  29159. }
  29160. // rotation
  29161. var sin = -row[0][1],
  29162. cos = row[1][1];
  29163. if (cos < 0) {
  29164. out.rotate = Snap.deg(math.acos(cos));
  29165. if (sin < 0) {
  29166. out.rotate = 360 - out.rotate;
  29167. }
  29168. } else {
  29169. out.rotate = Snap.deg(math.asin(sin));
  29170. }
  29171. out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
  29172. out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
  29173. out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
  29174. return out;
  29175. };
  29176. /*\
  29177. * Matrix.toTransformString
  29178. [ method ]
  29179. **
  29180. * Returns transform string that represents given matrix
  29181. = (string) transform string
  29182. \*/
  29183. matrixproto.toTransformString = function (shorter) {
  29184. var s = shorter || this.split();
  29185. if (!+s.shear.toFixed(9)) {
  29186. s.scalex = +s.scalex.toFixed(4);
  29187. s.scaley = +s.scaley.toFixed(4);
  29188. s.rotate = +s.rotate.toFixed(4);
  29189. return (s.dx || s.dy ? "t" + [+s.dx.toFixed(4), +s.dy.toFixed(4)] : E) +
  29190. (s.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) +
  29191. (s.rotate ? "r" + [+s.rotate.toFixed(4), 0, 0] : E);
  29192. } else {
  29193. return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
  29194. }
  29195. };
  29196. })(Matrix.prototype);
  29197. /*\
  29198. * Snap.Matrix
  29199. [ method ]
  29200. **
  29201. * Matrix constructor, extend on your own risk.
  29202. * To create matrices use @Snap.matrix.
  29203. \*/
  29204. Snap.Matrix = Matrix;
  29205. /*\
  29206. * Snap.matrix
  29207. [ method ]
  29208. **
  29209. * Utility method
  29210. **
  29211. * Returns a matrix based on the given parameters
  29212. - a (number)
  29213. - b (number)
  29214. - c (number)
  29215. - d (number)
  29216. - e (number)
  29217. - f (number)
  29218. * or
  29219. - svgMatrix (SVGMatrix)
  29220. = (object) @Matrix
  29221. \*/
  29222. Snap.matrix = function (a, b, c, d, e, f) {
  29223. return new Matrix(a, b, c, d, e, f);
  29224. };
  29225. });
  29226. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  29227. //
  29228. // Licensed under the Apache License, Version 2.0 (the "License");
  29229. // you may not use this file except in compliance with the License.
  29230. // You may obtain a copy of the License at
  29231. //
  29232. // http://www.apache.org/licenses/LICENSE-2.0
  29233. //
  29234. // Unless required by applicable law or agreed to in writing, software
  29235. // distributed under the License is distributed on an "AS IS" BASIS,
  29236. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29237. // See the License for the specific language governing permissions and
  29238. // limitations under the License.
  29239. Snap.plugin(function (Snap, Element, Paper, glob, Fragment) {
  29240. var has = "hasOwnProperty",
  29241. make = Snap._.make,
  29242. wrap = Snap._.wrap,
  29243. is = Snap.is,
  29244. getSomeDefs = Snap._.getSomeDefs,
  29245. reURLValue = /^url\(#?([^)]+)\)$/,
  29246. $ = Snap._.$,
  29247. URL = Snap.url,
  29248. Str = String,
  29249. separator = Snap._.separator,
  29250. E = "";
  29251. // Attributes event handlers
  29252. eve.on("snap.util.attr.mask", function (value) {
  29253. if (value instanceof Element || value instanceof Fragment) {
  29254. eve.stop();
  29255. if (value instanceof Fragment && value.node.childNodes.length == 1) {
  29256. value = value.node.firstChild;
  29257. getSomeDefs(this).appendChild(value);
  29258. value = wrap(value);
  29259. }
  29260. if (value.type == "mask") {
  29261. var mask = value;
  29262. } else {
  29263. mask = make("mask", getSomeDefs(this));
  29264. mask.node.appendChild(value.node);
  29265. }
  29266. !mask.node.id && $(mask.node, {
  29267. id: mask.id
  29268. });
  29269. $(this.node, {
  29270. mask: URL(mask.id)
  29271. });
  29272. }
  29273. });
  29274. (function (clipIt) {
  29275. eve.on("snap.util.attr.clip", clipIt);
  29276. eve.on("snap.util.attr.clip-path", clipIt);
  29277. eve.on("snap.util.attr.clipPath", clipIt);
  29278. }(function (value) {
  29279. if (value instanceof Element || value instanceof Fragment) {
  29280. eve.stop();
  29281. if (value.type == "clipPath") {
  29282. var clip = value;
  29283. } else {
  29284. clip = make("clipPath", getSomeDefs(this));
  29285. clip.node.appendChild(value.node);
  29286. !clip.node.id && $(clip.node, {
  29287. id: clip.id
  29288. });
  29289. }
  29290. $(this.node, {
  29291. "clip-path": URL(clip.node.id || clip.id)
  29292. });
  29293. }
  29294. }));
  29295. function fillStroke(name) {
  29296. return function (value) {
  29297. eve.stop();
  29298. if (value instanceof Fragment && value.node.childNodes.length == 1 &&
  29299. (value.node.firstChild.tagName == "radialGradient" ||
  29300. value.node.firstChild.tagName == "linearGradient" ||
  29301. value.node.firstChild.tagName == "pattern")) {
  29302. value = value.node.firstChild;
  29303. getSomeDefs(this).appendChild(value);
  29304. value = wrap(value);
  29305. }
  29306. if (value instanceof Element) {
  29307. if (value.type == "radialGradient" || value.type == "linearGradient"
  29308. || value.type == "pattern") {
  29309. if (!value.node.id) {
  29310. $(value.node, {
  29311. id: value.id
  29312. });
  29313. }
  29314. var fill = URL(value.node.id);
  29315. } else {
  29316. fill = value.attr(name);
  29317. }
  29318. } else {
  29319. fill = Snap.color(value);
  29320. if (fill.error) {
  29321. var grad = Snap(getSomeDefs(this).ownerSVGElement).gradient(value);
  29322. if (grad) {
  29323. if (!grad.node.id) {
  29324. $(grad.node, {
  29325. id: grad.id
  29326. });
  29327. }
  29328. fill = URL(grad.node.id);
  29329. } else {
  29330. fill = value;
  29331. }
  29332. } else {
  29333. fill = Str(fill);
  29334. }
  29335. }
  29336. var attrs = {};
  29337. attrs[name] = fill;
  29338. $(this.node, attrs);
  29339. this.node.style[name] = E;
  29340. };
  29341. }
  29342. eve.on("snap.util.attr.fill", fillStroke("fill"));
  29343. eve.on("snap.util.attr.stroke", fillStroke("stroke"));
  29344. var gradrg = /^([lr])(?:\(([^)]*)\))?(.*)$/i;
  29345. eve.on("snap.util.grad.parse", function parseGrad(string) {
  29346. string = Str(string);
  29347. var tokens = string.match(gradrg);
  29348. if (!tokens) {
  29349. return null;
  29350. }
  29351. var type = tokens[1],
  29352. params = tokens[2],
  29353. stops = tokens[3];
  29354. params = params.split(/\s*,\s*/).map(function (el) {
  29355. return +el == el ? +el : el;
  29356. });
  29357. if (params.length == 1 && params[0] == 0) {
  29358. params = [];
  29359. }
  29360. stops = stops.split("-");
  29361. stops = stops.map(function (el) {
  29362. el = el.split(":");
  29363. var out = {
  29364. color: el[0]
  29365. };
  29366. if (el[1]) {
  29367. out.offset = parseFloat(el[1]);
  29368. }
  29369. return out;
  29370. });
  29371. return {
  29372. type: type,
  29373. params: params,
  29374. stops: stops
  29375. };
  29376. });
  29377. eve.on("snap.util.attr.d", function (value) {
  29378. eve.stop();
  29379. if (is(value, "array") && is(value[0], "array")) {
  29380. value = Snap.path.toString.call(value);
  29381. }
  29382. value = Str(value);
  29383. if (value.match(/[ruo]/i)) {
  29384. value = Snap.path.toAbsolute(value);
  29385. }
  29386. $(this.node, {d: value});
  29387. })(-1);
  29388. eve.on("snap.util.attr.#text", function (value) {
  29389. eve.stop();
  29390. value = Str(value);
  29391. var txt = glob.doc.createTextNode(value);
  29392. while (this.node.firstChild) {
  29393. this.node.removeChild(this.node.firstChild);
  29394. }
  29395. this.node.appendChild(txt);
  29396. })(-1);
  29397. eve.on("snap.util.attr.path", function (value) {
  29398. eve.stop();
  29399. this.attr({d: value});
  29400. })(-1);
  29401. eve.on("snap.util.attr.class", function (value) {
  29402. eve.stop();
  29403. this.node.className.baseVal = value;
  29404. })(-1);
  29405. eve.on("snap.util.attr.viewBox", function (value) {
  29406. var vb;
  29407. if (is(value, "object") && "x" in value) {
  29408. vb = [value.x, value.y, value.width, value.height].join(" ");
  29409. } else if (is(value, "array")) {
  29410. vb = value.join(" ");
  29411. } else {
  29412. vb = value;
  29413. }
  29414. $(this.node, {
  29415. viewBox: vb
  29416. });
  29417. eve.stop();
  29418. })(-1);
  29419. eve.on("snap.util.attr.transform", function (value) {
  29420. this.transform(value);
  29421. eve.stop();
  29422. })(-1);
  29423. eve.on("snap.util.attr.r", function (value) {
  29424. if (this.type == "rect") {
  29425. eve.stop();
  29426. $(this.node, {
  29427. rx: value,
  29428. ry: value
  29429. });
  29430. }
  29431. })(-1);
  29432. eve.on("snap.util.attr.textpath", function (value) {
  29433. eve.stop();
  29434. if (this.type == "text") {
  29435. var id, tp, node;
  29436. if (!value && this.textPath) {
  29437. tp = this.textPath;
  29438. while (tp.node.firstChild) {
  29439. this.node.appendChild(tp.node.firstChild);
  29440. }
  29441. tp.remove();
  29442. delete this.textPath;
  29443. return;
  29444. }
  29445. if (is(value, "string")) {
  29446. var defs = getSomeDefs(this),
  29447. path = wrap(defs.parentNode).path(value);
  29448. defs.appendChild(path.node);
  29449. id = path.id;
  29450. path.attr({id: id});
  29451. } else {
  29452. value = wrap(value);
  29453. if (value instanceof Element) {
  29454. id = value.attr("id");
  29455. if (!id) {
  29456. id = value.id;
  29457. value.attr({id: id});
  29458. }
  29459. }
  29460. }
  29461. if (id) {
  29462. tp = this.textPath;
  29463. node = this.node;
  29464. if (tp) {
  29465. tp.attr({"xlink:href": "#" + id});
  29466. } else {
  29467. tp = $("textPath", {
  29468. "xlink:href": "#" + id
  29469. });
  29470. while (node.firstChild) {
  29471. tp.appendChild(node.firstChild);
  29472. }
  29473. node.appendChild(tp);
  29474. this.textPath = wrap(tp);
  29475. }
  29476. }
  29477. }
  29478. })(-1);
  29479. eve.on("snap.util.attr.text", function (value) {
  29480. if (this.type == "text") {
  29481. var i = 0,
  29482. node = this.node,
  29483. tuner = function (chunk) {
  29484. var out = $("tspan");
  29485. if (is(chunk, "array")) {
  29486. for (var i = 0; i < chunk.length; i++) {
  29487. out.appendChild(tuner(chunk[i]));
  29488. }
  29489. } else {
  29490. out.appendChild(glob.doc.createTextNode(chunk));
  29491. }
  29492. out.normalize && out.normalize();
  29493. return out;
  29494. };
  29495. while (node.firstChild) {
  29496. node.removeChild(node.firstChild);
  29497. }
  29498. var tuned = tuner(value);
  29499. while (tuned.firstChild) {
  29500. node.appendChild(tuned.firstChild);
  29501. }
  29502. }
  29503. eve.stop();
  29504. })(-1);
  29505. function setFontSize(value) {
  29506. eve.stop();
  29507. if (value == +value) {
  29508. value += "px";
  29509. }
  29510. this.node.style.fontSize = value;
  29511. }
  29512. eve.on("snap.util.attr.fontSize", setFontSize)(-1);
  29513. eve.on("snap.util.attr.font-size", setFontSize)(-1);
  29514. eve.on("snap.util.getattr.transform", function () {
  29515. eve.stop();
  29516. return this.transform();
  29517. })(-1);
  29518. eve.on("snap.util.getattr.textpath", function () {
  29519. eve.stop();
  29520. return this.textPath;
  29521. })(-1);
  29522. // Markers
  29523. (function () {
  29524. function getter(end) {
  29525. return function () {
  29526. eve.stop();
  29527. var style = glob.doc.defaultView.getComputedStyle(this.node, null).getPropertyValue("marker-" + end);
  29528. if (style == "none") {
  29529. return style;
  29530. } else {
  29531. return Snap(glob.doc.getElementById(style.match(reURLValue)[1]));
  29532. }
  29533. };
  29534. }
  29535. function setter(end) {
  29536. return function (value) {
  29537. eve.stop();
  29538. var name = "marker" + end.charAt(0).toUpperCase() + end.substring(1);
  29539. if (value == "" || !value) {
  29540. this.node.style[name] = "none";
  29541. return;
  29542. }
  29543. if (value.type == "marker") {
  29544. var id = value.node.id;
  29545. if (!id) {
  29546. $(value.node, {id: value.id});
  29547. }
  29548. this.node.style[name] = URL(id);
  29549. return;
  29550. }
  29551. };
  29552. }
  29553. eve.on("snap.util.getattr.marker-end", getter("end"))(-1);
  29554. eve.on("snap.util.getattr.markerEnd", getter("end"))(-1);
  29555. eve.on("snap.util.getattr.marker-start", getter("start"))(-1);
  29556. eve.on("snap.util.getattr.markerStart", getter("start"))(-1);
  29557. eve.on("snap.util.getattr.marker-mid", getter("mid"))(-1);
  29558. eve.on("snap.util.getattr.markerMid", getter("mid"))(-1);
  29559. eve.on("snap.util.attr.marker-end", setter("end"))(-1);
  29560. eve.on("snap.util.attr.markerEnd", setter("end"))(-1);
  29561. eve.on("snap.util.attr.marker-start", setter("start"))(-1);
  29562. eve.on("snap.util.attr.markerStart", setter("start"))(-1);
  29563. eve.on("snap.util.attr.marker-mid", setter("mid"))(-1);
  29564. eve.on("snap.util.attr.markerMid", setter("mid"))(-1);
  29565. }());
  29566. eve.on("snap.util.getattr.r", function () {
  29567. if (this.type == "rect" && $(this.node, "rx") == $(this.node, "ry")) {
  29568. eve.stop();
  29569. return $(this.node, "rx");
  29570. }
  29571. })(-1);
  29572. function textExtract(node) {
  29573. var out = [];
  29574. var children = node.childNodes;
  29575. for (var i = 0, ii = children.length; i < ii; i++) {
  29576. var chi = children[i];
  29577. if (chi.nodeType == 3) {
  29578. out.push(chi.nodeValue);
  29579. }
  29580. if (chi.tagName == "tspan") {
  29581. if (chi.childNodes.length == 1 && chi.firstChild.nodeType == 3) {
  29582. out.push(chi.firstChild.nodeValue);
  29583. } else {
  29584. out.push(textExtract(chi));
  29585. }
  29586. }
  29587. }
  29588. return out;
  29589. }
  29590. eve.on("snap.util.getattr.text", function () {
  29591. if (this.type == "text" || this.type == "tspan") {
  29592. eve.stop();
  29593. var out = textExtract(this.node);
  29594. return out.length == 1 ? out[0] : out;
  29595. }
  29596. })(-1);
  29597. eve.on("snap.util.getattr.#text", function () {
  29598. return this.node.textContent;
  29599. })(-1);
  29600. eve.on("snap.util.getattr.viewBox", function () {
  29601. eve.stop();
  29602. var vb = $(this.node, "viewBox");
  29603. if (vb) {
  29604. vb = vb.split(separator);
  29605. return Snap._.box(+vb[0], +vb[1], +vb[2], +vb[3]);
  29606. } else {
  29607. return;
  29608. }
  29609. })(-1);
  29610. eve.on("snap.util.getattr.points", function () {
  29611. var p = $(this.node, "points");
  29612. eve.stop();
  29613. if (p) {
  29614. return p.split(separator);
  29615. } else {
  29616. return;
  29617. }
  29618. })(-1);
  29619. eve.on("snap.util.getattr.path", function () {
  29620. var p = $(this.node, "d");
  29621. eve.stop();
  29622. return p;
  29623. })(-1);
  29624. eve.on("snap.util.getattr.class", function () {
  29625. return this.node.className.baseVal;
  29626. })(-1);
  29627. function getFontSize() {
  29628. eve.stop();
  29629. return this.node.style.fontSize;
  29630. }
  29631. eve.on("snap.util.getattr.fontSize", getFontSize)(-1);
  29632. eve.on("snap.util.getattr.font-size", getFontSize)(-1);
  29633. });
  29634. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  29635. //
  29636. // Licensed under the Apache License, Version 2.0 (the "License");
  29637. // you may not use this file except in compliance with the License.
  29638. // You may obtain a copy of the License at
  29639. //
  29640. // http://www.apache.org/licenses/LICENSE-2.0
  29641. //
  29642. // Unless required by applicable law or agreed to in writing, software
  29643. // distributed under the License is distributed on an "AS IS" BASIS,
  29644. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29645. // See the License for the specific language governing permissions and
  29646. // limitations under the License.
  29647. Snap.plugin(function (Snap, Element, Paper, glob, Fragment) {
  29648. var proto = Paper.prototype,
  29649. is = Snap.is;
  29650. /*\
  29651. * Paper.rect
  29652. [ method ]
  29653. *
  29654. * Draws a rectangle
  29655. **
  29656. - x (number) x coordinate of the top left corner
  29657. - y (number) y coordinate of the top left corner
  29658. - width (number) width
  29659. - height (number) height
  29660. - rx (number) #optional horizontal radius for rounded corners, default is 0
  29661. - ry (number) #optional vertical radius for rounded corners, default is rx or 0
  29662. = (object) the `rect` element
  29663. **
  29664. > Usage
  29665. | // regular rectangle
  29666. | var c = paper.rect(10, 10, 50, 50);
  29667. | // rectangle with rounded corners
  29668. | var c = paper.rect(40, 40, 50, 50, 10);
  29669. \*/
  29670. proto.rect = function (x, y, w, h, rx, ry) {
  29671. var attr;
  29672. if (ry == null) {
  29673. ry = rx;
  29674. }
  29675. if (is(x, "object") && x == "[object Object]") {
  29676. attr = x;
  29677. } else if (x != null) {
  29678. attr = {
  29679. x: x,
  29680. y: y,
  29681. width: w,
  29682. height: h
  29683. };
  29684. if (rx != null) {
  29685. attr.rx = rx;
  29686. attr.ry = ry;
  29687. }
  29688. }
  29689. return this.el("rect", attr);
  29690. };
  29691. /*\
  29692. * Paper.circle
  29693. [ method ]
  29694. **
  29695. * Draws a circle
  29696. **
  29697. - x (number) x coordinate of the centre
  29698. - y (number) y coordinate of the centre
  29699. - r (number) radius
  29700. = (object) the `circle` element
  29701. **
  29702. > Usage
  29703. | var c = paper.circle(50, 50, 40);
  29704. \*/
  29705. proto.circle = function (cx, cy, r) {
  29706. var attr;
  29707. if (is(cx, "object") && cx == "[object Object]") {
  29708. attr = cx;
  29709. } else if (cx != null) {
  29710. attr = {
  29711. cx: cx,
  29712. cy: cy,
  29713. r: r
  29714. };
  29715. }
  29716. return this.el("circle", attr);
  29717. };
  29718. var preload = (function () {
  29719. function onerror() {
  29720. this.parentNode.removeChild(this);
  29721. }
  29722. return function (src, f) {
  29723. var img = glob.doc.createElement("img"),
  29724. body = glob.doc.body;
  29725. img.style.cssText = "position:absolute;left:-9999em;top:-9999em";
  29726. img.onload = function () {
  29727. f.call(img);
  29728. img.onload = img.onerror = null;
  29729. body.removeChild(img);
  29730. };
  29731. img.onerror = onerror;
  29732. body.appendChild(img);
  29733. img.src = src;
  29734. };
  29735. }());
  29736. /*\
  29737. * Paper.image
  29738. [ method ]
  29739. **
  29740. * Places an image on the surface
  29741. **
  29742. - src (string) URI of the source image
  29743. - x (number) x offset position
  29744. - y (number) y offset position
  29745. - width (number) width of the image
  29746. - height (number) height of the image
  29747. = (object) the `image` element
  29748. * or
  29749. = (object) Snap element object with type `image`
  29750. **
  29751. > Usage
  29752. | var c = paper.image("apple.png", 10, 10, 80, 80);
  29753. \*/
  29754. proto.image = function (src, x, y, width, height) {
  29755. var el = this.el("image");
  29756. if (is(src, "object") && "src" in src) {
  29757. el.attr(src);
  29758. } else if (src != null) {
  29759. var set = {
  29760. "xlink:href": src,
  29761. preserveAspectRatio: "none"
  29762. };
  29763. if (x != null && y != null) {
  29764. set.x = x;
  29765. set.y = y;
  29766. }
  29767. if (width != null && height != null) {
  29768. set.width = width;
  29769. set.height = height;
  29770. } else {
  29771. preload(src, function () {
  29772. Snap._.$(el.node, {
  29773. width: this.offsetWidth,
  29774. height: this.offsetHeight
  29775. });
  29776. });
  29777. }
  29778. Snap._.$(el.node, set);
  29779. }
  29780. return el;
  29781. };
  29782. /*\
  29783. * Paper.ellipse
  29784. [ method ]
  29785. **
  29786. * Draws an ellipse
  29787. **
  29788. - x (number) x coordinate of the centre
  29789. - y (number) y coordinate of the centre
  29790. - rx (number) horizontal radius
  29791. - ry (number) vertical radius
  29792. = (object) the `ellipse` element
  29793. **
  29794. > Usage
  29795. | var c = paper.ellipse(50, 50, 40, 20);
  29796. \*/
  29797. proto.ellipse = function (cx, cy, rx, ry) {
  29798. var attr;
  29799. if (is(cx, "object") && cx == "[object Object]") {
  29800. attr = cx;
  29801. } else if (cx != null) {
  29802. attr ={
  29803. cx: cx,
  29804. cy: cy,
  29805. rx: rx,
  29806. ry: ry
  29807. };
  29808. }
  29809. return this.el("ellipse", attr);
  29810. };
  29811. // SIERRA Paper.path(): Unclear from the link what a Catmull-Rom curveto is, and why it would make life any easier.
  29812. /*\
  29813. * Paper.path
  29814. [ method ]
  29815. **
  29816. * Creates a `<path>` element using the given string as the path's definition
  29817. - pathString (string) #optional path string in SVG format
  29818. * Path string consists of one-letter commands, followed by comma seprarated arguments in numerical form. Example:
  29819. | "M10,20L30,40"
  29820. * This example features two commands: `M`, with arguments `(10, 20)` and `L` with arguments `(30, 40)`. Uppercase letter commands express coordinates in absolute terms, while lowercase commands express them in relative terms from the most recently declared coordinates.
  29821. *
  29822. # <p>Here is short list of commands available, for more details see <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path's data attribute's format are described in the SVG specification.">SVG path string format</a> or <a href="https://developer.mozilla.org/en/SVG/Tutorial/Paths">article about path strings at MDN</a>.</p>
  29823. # <table><thead><tr><th>Command</th><th>Name</th><th>Parameters</th></tr></thead><tbody>
  29824. # <tr><td>M</td><td>moveto</td><td>(x y)+</td></tr>
  29825. # <tr><td>Z</td><td>closepath</td><td>(none)</td></tr>
  29826. # <tr><td>L</td><td>lineto</td><td>(x y)+</td></tr>
  29827. # <tr><td>H</td><td>horizontal lineto</td><td>x+</td></tr>
  29828. # <tr><td>V</td><td>vertical lineto</td><td>y+</td></tr>
  29829. # <tr><td>C</td><td>curveto</td><td>(x1 y1 x2 y2 x y)+</td></tr>
  29830. # <tr><td>S</td><td>smooth curveto</td><td>(x2 y2 x y)+</td></tr>
  29831. # <tr><td>Q</td><td>quadratic Bézier curveto</td><td>(x1 y1 x y)+</td></tr>
  29832. # <tr><td>T</td><td>smooth quadratic Bézier curveto</td><td>(x y)+</td></tr>
  29833. # <tr><td>A</td><td>elliptical arc</td><td>(rx ry x-axis-rotation large-arc-flag sweep-flag x y)+</td></tr>
  29834. # <tr><td>R</td><td><a href="http://en.wikipedia.org/wiki/Catmull–Rom_spline#Catmull.E2.80.93Rom_spline">Catmull-Rom curveto</a>*</td><td>x1 y1 (x y)+</td></tr></tbody></table>
  29835. * * _Catmull-Rom curveto_ is a not standard SVG command and added to make life easier.
  29836. * Note: there is a special case when a path consists of only three commands: `M10,10R…z`. In this case the path connects back to its starting point.
  29837. > Usage
  29838. | var c = paper.path("M10 10L90 90");
  29839. | // draw a diagonal line:
  29840. | // move to 10,10, line to 90,90
  29841. \*/
  29842. proto.path = function (d) {
  29843. var attr;
  29844. if (is(d, "object") && !is(d, "array")) {
  29845. attr = d;
  29846. } else if (d) {
  29847. attr = {d: d};
  29848. }
  29849. return this.el("path", attr);
  29850. };
  29851. /*\
  29852. * Paper.g
  29853. [ method ]
  29854. **
  29855. * Creates a group element
  29856. **
  29857. - varargs (…) #optional elements to nest within the group
  29858. = (object) the `g` element
  29859. **
  29860. > Usage
  29861. | var c1 = paper.circle(),
  29862. | c2 = paper.rect(),
  29863. | g = paper.g(c2, c1); // note that the order of elements is different
  29864. * or
  29865. | var c1 = paper.circle(),
  29866. | c2 = paper.rect(),
  29867. | g = paper.g();
  29868. | g.add(c2, c1);
  29869. \*/
  29870. /*\
  29871. * Paper.group
  29872. [ method ]
  29873. **
  29874. * See @Paper.g
  29875. \*/
  29876. proto.group = proto.g = function (first) {
  29877. var attr,
  29878. el = this.el("g");
  29879. if (arguments.length == 1 && first && !first.type) {
  29880. el.attr(first);
  29881. } else if (arguments.length) {
  29882. el.add(Array.prototype.slice.call(arguments, 0));
  29883. }
  29884. return el;
  29885. };
  29886. /*\
  29887. * Paper.svg
  29888. [ method ]
  29889. **
  29890. * Creates a nested SVG element.
  29891. - x (number) @optional X of the element
  29892. - y (number) @optional Y of the element
  29893. - width (number) @optional width of the element
  29894. - height (number) @optional height of the element
  29895. - vbx (number) @optional viewbox X
  29896. - vby (number) @optional viewbox Y
  29897. - vbw (number) @optional viewbox width
  29898. - vbh (number) @optional viewbox height
  29899. **
  29900. = (object) the `svg` element
  29901. **
  29902. \*/
  29903. proto.svg = function (x, y, width, height, vbx, vby, vbw, vbh) {
  29904. var attrs = {};
  29905. if (is(x, "object") && y == null) {
  29906. attrs = x;
  29907. } else {
  29908. if (x != null) {
  29909. attrs.x = x;
  29910. }
  29911. if (y != null) {
  29912. attrs.y = y;
  29913. }
  29914. if (width != null) {
  29915. attrs.width = width;
  29916. }
  29917. if (height != null) {
  29918. attrs.height = height;
  29919. }
  29920. if (vbx != null && vby != null && vbw != null && vbh != null) {
  29921. attrs.viewBox = [vbx, vby, vbw, vbh];
  29922. }
  29923. }
  29924. return this.el("svg", attrs);
  29925. };
  29926. /*\
  29927. * Paper.mask
  29928. [ method ]
  29929. **
  29930. * Equivalent in behaviour to @Paper.g, except it’s a mask.
  29931. **
  29932. = (object) the `mask` element
  29933. **
  29934. \*/
  29935. proto.mask = function (first) {
  29936. var attr,
  29937. el = this.el("mask");
  29938. if (arguments.length == 1 && first && !first.type) {
  29939. el.attr(first);
  29940. } else if (arguments.length) {
  29941. el.add(Array.prototype.slice.call(arguments, 0));
  29942. }
  29943. return el;
  29944. };
  29945. /*\
  29946. * Paper.ptrn
  29947. [ method ]
  29948. **
  29949. * Equivalent in behaviour to @Paper.g, except it’s a pattern.
  29950. - x (number) @optional X of the element
  29951. - y (number) @optional Y of the element
  29952. - width (number) @optional width of the element
  29953. - height (number) @optional height of the element
  29954. - vbx (number) @optional viewbox X
  29955. - vby (number) @optional viewbox Y
  29956. - vbw (number) @optional viewbox width
  29957. - vbh (number) @optional viewbox height
  29958. **
  29959. = (object) the `pattern` element
  29960. **
  29961. \*/
  29962. proto.ptrn = function (x, y, width, height, vx, vy, vw, vh) {
  29963. if (is(x, "object")) {
  29964. var attr = x;
  29965. } else {
  29966. attr = {patternUnits: "userSpaceOnUse"};
  29967. if (x) {
  29968. attr.x = x;
  29969. }
  29970. if (y) {
  29971. attr.y = y;
  29972. }
  29973. if (width != null) {
  29974. attr.width = width;
  29975. }
  29976. if (height != null) {
  29977. attr.height = height;
  29978. }
  29979. if (vx != null && vy != null && vw != null && vh != null) {
  29980. attr.viewBox = [vx, vy, vw, vh];
  29981. }
  29982. }
  29983. return this.el("pattern", attr);
  29984. };
  29985. /*\
  29986. * Paper.use
  29987. [ method ]
  29988. **
  29989. * Creates a <use> element.
  29990. - id (string) @optional id of element to link
  29991. * or
  29992. - id (Element) @optional element to link
  29993. **
  29994. = (object) the `use` element
  29995. **
  29996. \*/
  29997. proto.use = function (id) {
  29998. if (id != null) {
  29999. if (id instanceof Element) {
  30000. if (!id.attr("id")) {
  30001. id.attr({id: Snap._.id(id)});
  30002. }
  30003. id = id.attr("id");
  30004. }
  30005. if (String(id).charAt() == "#") {
  30006. id = id.substring(1);
  30007. }
  30008. return this.el("use", {"xlink:href": "#" + id});
  30009. } else {
  30010. return Element.prototype.use.call(this);
  30011. }
  30012. };
  30013. /*\
  30014. * Paper.symbol
  30015. [ method ]
  30016. **
  30017. * Creates a <symbol> element.
  30018. - vbx (number) @optional viewbox X
  30019. - vby (number) @optional viewbox Y
  30020. - vbw (number) @optional viewbox width
  30021. - vbh (number) @optional viewbox height
  30022. = (object) the `symbol` element
  30023. **
  30024. \*/
  30025. proto.symbol = function (vx, vy, vw, vh) {
  30026. var attr = {};
  30027. if (vx != null && vy != null && vw != null && vh != null) {
  30028. attr.viewBox = [vx, vy, vw, vh];
  30029. }
  30030. return this.el("symbol", attr);
  30031. };
  30032. /*\
  30033. * Paper.text
  30034. [ method ]
  30035. **
  30036. * Draws a text string
  30037. **
  30038. - x (number) x coordinate position
  30039. - y (number) y coordinate position
  30040. - text (string|array) The text string to draw or array of strings to nest within separate `<tspan>` elements
  30041. = (object) the `text` element
  30042. **
  30043. > Usage
  30044. | var t1 = paper.text(50, 50, "Snap");
  30045. | var t2 = paper.text(50, 50, ["S","n","a","p"]);
  30046. | // Text path usage
  30047. | t1.attr({textpath: "M10,10L100,100"});
  30048. | // or
  30049. | var pth = paper.path("M10,10L100,100");
  30050. | t1.attr({textpath: pth});
  30051. \*/
  30052. proto.text = function (x, y, text) {
  30053. var attr = {};
  30054. if (is(x, "object")) {
  30055. attr = x;
  30056. } else if (x != null) {
  30057. attr = {
  30058. x: x,
  30059. y: y,
  30060. text: text || ""
  30061. };
  30062. }
  30063. return this.el("text", attr);
  30064. };
  30065. /*\
  30066. * Paper.line
  30067. [ method ]
  30068. **
  30069. * Draws a line
  30070. **
  30071. - x1 (number) x coordinate position of the start
  30072. - y1 (number) y coordinate position of the start
  30073. - x2 (number) x coordinate position of the end
  30074. - y2 (number) y coordinate position of the end
  30075. = (object) the `line` element
  30076. **
  30077. > Usage
  30078. | var t1 = paper.line(50, 50, 100, 100);
  30079. \*/
  30080. proto.line = function (x1, y1, x2, y2) {
  30081. var attr = {};
  30082. if (is(x1, "object")) {
  30083. attr = x1;
  30084. } else if (x1 != null) {
  30085. attr = {
  30086. x1: x1,
  30087. x2: x2,
  30088. y1: y1,
  30089. y2: y2
  30090. };
  30091. }
  30092. return this.el("line", attr);
  30093. };
  30094. /*\
  30095. * Paper.polyline
  30096. [ method ]
  30097. **
  30098. * Draws a polyline
  30099. **
  30100. - points (array) array of points
  30101. * or
  30102. - varargs (…) points
  30103. = (object) the `polyline` element
  30104. **
  30105. > Usage
  30106. | var p1 = paper.polyline([10, 10, 100, 100]);
  30107. | var p2 = paper.polyline(10, 10, 100, 100);
  30108. \*/
  30109. proto.polyline = function (points) {
  30110. if (arguments.length > 1) {
  30111. points = Array.prototype.slice.call(arguments, 0);
  30112. }
  30113. var attr = {};
  30114. if (is(points, "object") && !is(points, "array")) {
  30115. attr = points;
  30116. } else if (points != null) {
  30117. attr = {points: points};
  30118. }
  30119. return this.el("polyline", attr);
  30120. };
  30121. /*\
  30122. * Paper.polygon
  30123. [ method ]
  30124. **
  30125. * Draws a polygon. See @Paper.polyline
  30126. \*/
  30127. proto.polygon = function (points) {
  30128. if (arguments.length > 1) {
  30129. points = Array.prototype.slice.call(arguments, 0);
  30130. }
  30131. var attr = {};
  30132. if (is(points, "object") && !is(points, "array")) {
  30133. attr = points;
  30134. } else if (points != null) {
  30135. attr = {points: points};
  30136. }
  30137. return this.el("polygon", attr);
  30138. };
  30139. // gradients
  30140. (function () {
  30141. var $ = Snap._.$;
  30142. // gradients' helpers
  30143. function Gstops() {
  30144. return this.selectAll("stop");
  30145. }
  30146. function GaddStop(color, offset) {
  30147. var stop = $("stop"),
  30148. attr = {
  30149. offset: +offset + "%"
  30150. };
  30151. color = Snap.color(color);
  30152. attr["stop-color"] = color.hex;
  30153. if (color.opacity < 1) {
  30154. attr["stop-opacity"] = color.opacity;
  30155. }
  30156. $(stop, attr);
  30157. this.node.appendChild(stop);
  30158. return this;
  30159. }
  30160. function GgetBBox() {
  30161. if (this.type == "linearGradient") {
  30162. var x1 = $(this.node, "x1") || 0,
  30163. x2 = $(this.node, "x2") || 1,
  30164. y1 = $(this.node, "y1") || 0,
  30165. y2 = $(this.node, "y2") || 0;
  30166. return Snap._.box(x1, y1, math.abs(x2 - x1), math.abs(y2 - y1));
  30167. } else {
  30168. var cx = this.node.cx || .5,
  30169. cy = this.node.cy || .5,
  30170. r = this.node.r || 0;
  30171. return Snap._.box(cx - r, cy - r, r * 2, r * 2);
  30172. }
  30173. }
  30174. function gradient(defs, str) {
  30175. var grad = eve("snap.util.grad.parse", null, str).firstDefined(),
  30176. el;
  30177. if (!grad) {
  30178. return null;
  30179. }
  30180. grad.params.unshift(defs);
  30181. if (grad.type.toLowerCase() == "l") {
  30182. el = gradientLinear.apply(0, grad.params);
  30183. } else {
  30184. el = gradientRadial.apply(0, grad.params);
  30185. }
  30186. if (grad.type != grad.type.toLowerCase()) {
  30187. $(el.node, {
  30188. gradientUnits: "userSpaceOnUse"
  30189. });
  30190. }
  30191. var stops = grad.stops,
  30192. len = stops.length,
  30193. start = 0,
  30194. j = 0;
  30195. function seed(i, end) {
  30196. var step = (end - start) / (i - j);
  30197. for (var k = j; k < i; k++) {
  30198. stops[k].offset = +(+start + step * (k - j)).toFixed(2);
  30199. }
  30200. j = i;
  30201. start = end;
  30202. }
  30203. len--;
  30204. for (var i = 0; i < len; i++) if ("offset" in stops[i]) {
  30205. seed(i, stops[i].offset);
  30206. }
  30207. stops[len].offset = stops[len].offset || 100;
  30208. seed(len, stops[len].offset);
  30209. for (i = 0; i <= len; i++) {
  30210. var stop = stops[i];
  30211. el.addStop(stop.color, stop.offset);
  30212. }
  30213. return el;
  30214. }
  30215. function gradientLinear(defs, x1, y1, x2, y2) {
  30216. var el = Snap._.make("linearGradient", defs);
  30217. el.stops = Gstops;
  30218. el.addStop = GaddStop;
  30219. el.getBBox = GgetBBox;
  30220. if (x1 != null) {
  30221. $(el.node, {
  30222. x1: x1,
  30223. y1: y1,
  30224. x2: x2,
  30225. y2: y2
  30226. });
  30227. }
  30228. return el;
  30229. }
  30230. function gradientRadial(defs, cx, cy, r, fx, fy) {
  30231. var el = Snap._.make("radialGradient", defs);
  30232. el.stops = Gstops;
  30233. el.addStop = GaddStop;
  30234. el.getBBox = GgetBBox;
  30235. if (cx != null) {
  30236. $(el.node, {
  30237. cx: cx,
  30238. cy: cy,
  30239. r: r
  30240. });
  30241. }
  30242. if (fx != null && fy != null) {
  30243. $(el.node, {
  30244. fx: fx,
  30245. fy: fy
  30246. });
  30247. }
  30248. return el;
  30249. }
  30250. /*\
  30251. * Paper.gradient
  30252. [ method ]
  30253. **
  30254. * Creates a gradient element
  30255. **
  30256. - gradient (string) gradient descriptor
  30257. > Gradient Descriptor
  30258. * The gradient descriptor is an expression formatted as
  30259. * follows: `<type>(<coords>)<colors>`. The `<type>` can be
  30260. * either linear or radial. The uppercase `L` or `R` letters
  30261. * indicate absolute coordinates offset from the SVG surface.
  30262. * Lowercase `l` or `r` letters indicate coordinates
  30263. * calculated relative to the element to which the gradient is
  30264. * applied. Coordinates specify a linear gradient vector as
  30265. * `x1`, `y1`, `x2`, `y2`, or a radial gradient as `cx`, `cy`,
  30266. * `r` and optional `fx`, `fy` specifying a focal point away
  30267. * from the center of the circle. Specify `<colors>` as a list
  30268. * of dash-separated CSS color values. Each color may be
  30269. * followed by a custom offset value, separated with a colon
  30270. * character.
  30271. > Examples
  30272. * Linear gradient, relative from top-left corner to bottom-right
  30273. * corner, from black through red to white:
  30274. | var g = paper.gradient("l(0, 0, 1, 1)#000-#f00-#fff");
  30275. * Linear gradient, absolute from (0, 0) to (100, 100), from black
  30276. * through red at 25% to white:
  30277. | var g = paper.gradient("L(0, 0, 100, 100)#000-#f00:25-#fff");
  30278. * Radial gradient, relative from the center of the element with radius
  30279. * half the width, from black to white:
  30280. | var g = paper.gradient("r(0.5, 0.5, 0.5)#000-#fff");
  30281. * To apply the gradient:
  30282. | paper.circle(50, 50, 40).attr({
  30283. | fill: g
  30284. | });
  30285. = (object) the `gradient` element
  30286. \*/
  30287. proto.gradient = function (str) {
  30288. return gradient(this.defs, str);
  30289. };
  30290. proto.gradientLinear = function (x1, y1, x2, y2) {
  30291. return gradientLinear(this.defs, x1, y1, x2, y2);
  30292. };
  30293. proto.gradientRadial = function (cx, cy, r, fx, fy) {
  30294. return gradientRadial(this.defs, cx, cy, r, fx, fy);
  30295. };
  30296. /*\
  30297. * Paper.toString
  30298. [ method ]
  30299. **
  30300. * Returns SVG code for the @Paper
  30301. = (string) SVG code for the @Paper
  30302. \*/
  30303. proto.toString = function () {
  30304. var doc = this.node.ownerDocument,
  30305. f = doc.createDocumentFragment(),
  30306. d = doc.createElement("div"),
  30307. svg = this.node.cloneNode(true),
  30308. res;
  30309. f.appendChild(d);
  30310. d.appendChild(svg);
  30311. Snap._.$(svg, {xmlns: "http://www.w3.org/2000/svg"});
  30312. res = d.innerHTML;
  30313. f.removeChild(f.firstChild);
  30314. return res;
  30315. };
  30316. /*\
  30317. * Paper.toDataURL
  30318. [ method ]
  30319. **
  30320. * Returns SVG code for the @Paper as Data URI string.
  30321. = (string) Data URI string
  30322. \*/
  30323. proto.toDataURL = function () {
  30324. if (window && window.btoa) {
  30325. return "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(this)));
  30326. }
  30327. };
  30328. /*\
  30329. * Paper.clear
  30330. [ method ]
  30331. **
  30332. * Removes all child nodes of the paper, except <defs>.
  30333. \*/
  30334. proto.clear = function () {
  30335. var node = this.node.firstChild,
  30336. next;
  30337. while (node) {
  30338. next = node.nextSibling;
  30339. if (node.tagName != "defs") {
  30340. node.parentNode.removeChild(node);
  30341. } else {
  30342. proto.clear.call({node: node});
  30343. }
  30344. node = next;
  30345. }
  30346. };
  30347. }());
  30348. });
  30349. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  30350. //
  30351. // Licensed under the Apache License, Version 2.0 (the "License");
  30352. // you may not use this file except in compliance with the License.
  30353. // You may obtain a copy of the License at
  30354. //
  30355. // http://www.apache.org/licenses/LICENSE-2.0
  30356. //
  30357. // Unless required by applicable law or agreed to in writing, software
  30358. // distributed under the License is distributed on an "AS IS" BASIS,
  30359. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  30360. // See the License for the specific language governing permissions and
  30361. // limitations under the License.
  30362. Snap.plugin(function (Snap, Element, Paper, glob) {
  30363. var elproto = Element.prototype,
  30364. is = Snap.is,
  30365. clone = Snap._.clone,
  30366. has = "hasOwnProperty",
  30367. p2s = /,?([a-z]),?/gi,
  30368. toFloat = parseFloat,
  30369. math = Math,
  30370. PI = math.PI,
  30371. mmin = math.min,
  30372. mmax = math.max,
  30373. pow = math.pow,
  30374. abs = math.abs;
  30375. function paths(ps) {
  30376. var p = paths.ps = paths.ps || {};
  30377. if (p[ps]) {
  30378. p[ps].sleep = 100;
  30379. } else {
  30380. p[ps] = {
  30381. sleep: 100
  30382. };
  30383. }
  30384. setTimeout(function () {
  30385. for (var key in p) if (p[has](key) && key != ps) {
  30386. p[key].sleep--;
  30387. !p[key].sleep && delete p[key];
  30388. }
  30389. });
  30390. return p[ps];
  30391. }
  30392. function box(x, y, width, height) {
  30393. if (x == null) {
  30394. x = y = width = height = 0;
  30395. }
  30396. if (y == null) {
  30397. y = x.y;
  30398. width = x.width;
  30399. height = x.height;
  30400. x = x.x;
  30401. }
  30402. return {
  30403. x: x,
  30404. y: y,
  30405. width: width,
  30406. w: width,
  30407. height: height,
  30408. h: height,
  30409. x2: x + width,
  30410. y2: y + height,
  30411. cx: x + width / 2,
  30412. cy: y + height / 2,
  30413. r1: math.min(width, height) / 2,
  30414. r2: math.max(width, height) / 2,
  30415. r0: math.sqrt(width * width + height * height) / 2,
  30416. path: rectPath(x, y, width, height),
  30417. vb: [x, y, width, height].join(" ")
  30418. };
  30419. }
  30420. function toString() {
  30421. return this.join(",").replace(p2s, "$1");
  30422. }
  30423. function pathClone(pathArray) {
  30424. var res = clone(pathArray);
  30425. res.toString = toString;
  30426. return res;
  30427. }
  30428. function getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
  30429. if (length == null) {
  30430. return bezlen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
  30431. } else {
  30432. return findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y,
  30433. getTotLen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length));
  30434. }
  30435. }
  30436. function getLengthFactory(istotal, subpath) {
  30437. function O(val) {
  30438. return +(+val).toFixed(3);
  30439. }
  30440. return Snap._.cacher(function (path, length, onlystart) {
  30441. if (path instanceof Element) {
  30442. path = path.attr("d");
  30443. }
  30444. path = path2curve(path);
  30445. var x, y, p, l, sp = "", subpaths = {}, point,
  30446. len = 0;
  30447. for (var i = 0, ii = path.length; i < ii; i++) {
  30448. p = path[i];
  30449. if (p[0] == "M") {
  30450. x = +p[1];
  30451. y = +p[2];
  30452. } else {
  30453. l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  30454. if (len + l > length) {
  30455. if (subpath && !subpaths.start) {
  30456. point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  30457. sp += [
  30458. "C" + O(point.start.x),
  30459. O(point.start.y),
  30460. O(point.m.x),
  30461. O(point.m.y),
  30462. O(point.x),
  30463. O(point.y)
  30464. ];
  30465. if (onlystart) {return sp;}
  30466. subpaths.start = sp;
  30467. sp = [
  30468. "M" + O(point.x),
  30469. O(point.y) + "C" + O(point.n.x),
  30470. O(point.n.y),
  30471. O(point.end.x),
  30472. O(point.end.y),
  30473. O(p[5]),
  30474. O(p[6])
  30475. ].join();
  30476. len += l;
  30477. x = +p[5];
  30478. y = +p[6];
  30479. continue;
  30480. }
  30481. if (!istotal && !subpath) {
  30482. point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  30483. return point;
  30484. }
  30485. }
  30486. len += l;
  30487. x = +p[5];
  30488. y = +p[6];
  30489. }
  30490. sp += p.shift() + p;
  30491. }
  30492. subpaths.end = sp;
  30493. point = istotal ? len : subpath ? subpaths : findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1);
  30494. return point;
  30495. }, null, Snap._.clone);
  30496. }
  30497. var getTotalLength = getLengthFactory(1),
  30498. getPointAtLength = getLengthFactory(),
  30499. getSubpathsAtLength = getLengthFactory(0, 1);
  30500. function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  30501. var t1 = 1 - t,
  30502. t13 = pow(t1, 3),
  30503. t12 = pow(t1, 2),
  30504. t2 = t * t,
  30505. t3 = t2 * t,
  30506. x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
  30507. y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
  30508. mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
  30509. my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
  30510. nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
  30511. ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
  30512. ax = t1 * p1x + t * c1x,
  30513. ay = t1 * p1y + t * c1y,
  30514. cx = t1 * c2x + t * p2x,
  30515. cy = t1 * c2y + t * p2y,
  30516. alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
  30517. // (mx > nx || my < ny) && (alpha += 180);
  30518. return {
  30519. x: x,
  30520. y: y,
  30521. m: {x: mx, y: my},
  30522. n: {x: nx, y: ny},
  30523. start: {x: ax, y: ay},
  30524. end: {x: cx, y: cy},
  30525. alpha: alpha
  30526. };
  30527. }
  30528. function bezierBBox(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  30529. if (!Snap.is(p1x, "array")) {
  30530. p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y];
  30531. }
  30532. var bbox = curveDim.apply(null, p1x);
  30533. return box(
  30534. bbox.min.x,
  30535. bbox.min.y,
  30536. bbox.max.x - bbox.min.x,
  30537. bbox.max.y - bbox.min.y
  30538. );
  30539. }
  30540. function isPointInsideBBox(bbox, x, y) {
  30541. return x >= bbox.x &&
  30542. x <= bbox.x + bbox.width &&
  30543. y >= bbox.y &&
  30544. y <= bbox.y + bbox.height;
  30545. }
  30546. function isBBoxIntersect(bbox1, bbox2) {
  30547. bbox1 = box(bbox1);
  30548. bbox2 = box(bbox2);
  30549. return isPointInsideBBox(bbox2, bbox1.x, bbox1.y)
  30550. || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y)
  30551. || isPointInsideBBox(bbox2, bbox1.x, bbox1.y2)
  30552. || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y2)
  30553. || isPointInsideBBox(bbox1, bbox2.x, bbox2.y)
  30554. || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y)
  30555. || isPointInsideBBox(bbox1, bbox2.x, bbox2.y2)
  30556. || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y2)
  30557. || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x
  30558. || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x)
  30559. && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y
  30560. || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
  30561. }
  30562. function base3(t, p1, p2, p3, p4) {
  30563. var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
  30564. t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
  30565. return t * t2 - 3 * p1 + 3 * p2;
  30566. }
  30567. function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
  30568. if (z == null) {
  30569. z = 1;
  30570. }
  30571. z = z > 1 ? 1 : z < 0 ? 0 : z;
  30572. var z2 = z / 2,
  30573. n = 12,
  30574. Tvalues = [-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],
  30575. Cvalues = [0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472],
  30576. sum = 0;
  30577. for (var i = 0; i < n; i++) {
  30578. var ct = z2 * Tvalues[i] + z2,
  30579. xbase = base3(ct, x1, x2, x3, x4),
  30580. ybase = base3(ct, y1, y2, y3, y4),
  30581. comb = xbase * xbase + ybase * ybase;
  30582. sum += Cvalues[i] * math.sqrt(comb);
  30583. }
  30584. return z2 * sum;
  30585. }
  30586. function getTotLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) {
  30587. if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) {
  30588. return;
  30589. }
  30590. var t = 1,
  30591. step = t / 2,
  30592. t2 = t - step,
  30593. l,
  30594. e = .01;
  30595. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  30596. while (abs(l - ll) > e) {
  30597. step /= 2;
  30598. t2 += (l < ll ? 1 : -1) * step;
  30599. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  30600. }
  30601. return t2;
  30602. }
  30603. function intersect(x1, y1, x2, y2, x3, y3, x4, y4) {
  30604. if (
  30605. mmax(x1, x2) < mmin(x3, x4) ||
  30606. mmin(x1, x2) > mmax(x3, x4) ||
  30607. mmax(y1, y2) < mmin(y3, y4) ||
  30608. mmin(y1, y2) > mmax(y3, y4)
  30609. ) {
  30610. return;
  30611. }
  30612. var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
  30613. ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
  30614. denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  30615. if (!denominator) {
  30616. return;
  30617. }
  30618. var px = nx / denominator,
  30619. py = ny / denominator,
  30620. px2 = +px.toFixed(2),
  30621. py2 = +py.toFixed(2);
  30622. if (
  30623. px2 < +mmin(x1, x2).toFixed(2) ||
  30624. px2 > +mmax(x1, x2).toFixed(2) ||
  30625. px2 < +mmin(x3, x4).toFixed(2) ||
  30626. px2 > +mmax(x3, x4).toFixed(2) ||
  30627. py2 < +mmin(y1, y2).toFixed(2) ||
  30628. py2 > +mmax(y1, y2).toFixed(2) ||
  30629. py2 < +mmin(y3, y4).toFixed(2) ||
  30630. py2 > +mmax(y3, y4).toFixed(2)
  30631. ) {
  30632. return;
  30633. }
  30634. return {x: px, y: py};
  30635. }
  30636. function inter(bez1, bez2) {
  30637. return interHelper(bez1, bez2);
  30638. }
  30639. function interCount(bez1, bez2) {
  30640. return interHelper(bez1, bez2, 1);
  30641. }
  30642. function interHelper(bez1, bez2, justCount) {
  30643. var bbox1 = bezierBBox(bez1),
  30644. bbox2 = bezierBBox(bez2);
  30645. if (!isBBoxIntersect(bbox1, bbox2)) {
  30646. return justCount ? 0 : [];
  30647. }
  30648. var l1 = bezlen.apply(0, bez1),
  30649. l2 = bezlen.apply(0, bez2),
  30650. n1 = ~~(l1 / 8),
  30651. n2 = ~~(l2 / 8),
  30652. dots1 = [],
  30653. dots2 = [],
  30654. xy = {},
  30655. res = justCount ? 0 : [];
  30656. for (var i = 0; i < n1 + 1; i++) {
  30657. var p = findDotsAtSegment.apply(0, bez1.concat(i / n1));
  30658. dots1.push({x: p.x, y: p.y, t: i / n1});
  30659. }
  30660. for (i = 0; i < n2 + 1; i++) {
  30661. p = findDotsAtSegment.apply(0, bez2.concat(i / n2));
  30662. dots2.push({x: p.x, y: p.y, t: i / n2});
  30663. }
  30664. for (i = 0; i < n1; i++) {
  30665. for (var j = 0; j < n2; j++) {
  30666. var di = dots1[i],
  30667. di1 = dots1[i + 1],
  30668. dj = dots2[j],
  30669. dj1 = dots2[j + 1],
  30670. ci = abs(di1.x - di.x) < .001 ? "y" : "x",
  30671. cj = abs(dj1.x - dj.x) < .001 ? "y" : "x",
  30672. is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
  30673. if (is) {
  30674. if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {
  30675. continue;
  30676. }
  30677. xy[is.x.toFixed(4)] = is.y.toFixed(4);
  30678. var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),
  30679. t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
  30680. if (t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1) {
  30681. if (justCount) {
  30682. res++;
  30683. } else {
  30684. res.push({
  30685. x: is.x,
  30686. y: is.y,
  30687. t1: t1,
  30688. t2: t2
  30689. });
  30690. }
  30691. }
  30692. }
  30693. }
  30694. }
  30695. return res;
  30696. }
  30697. function pathIntersection(path1, path2) {
  30698. return interPathHelper(path1, path2);
  30699. }
  30700. function pathIntersectionNumber(path1, path2) {
  30701. return interPathHelper(path1, path2, 1);
  30702. }
  30703. function interPathHelper(path1, path2, justCount) {
  30704. path1 = path2curve(path1);
  30705. path2 = path2curve(path2);
  30706. var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2,
  30707. res = justCount ? 0 : [];
  30708. for (var i = 0, ii = path1.length; i < ii; i++) {
  30709. var pi = path1[i];
  30710. if (pi[0] == "M") {
  30711. x1 = x1m = pi[1];
  30712. y1 = y1m = pi[2];
  30713. } else {
  30714. if (pi[0] == "C") {
  30715. bez1 = [x1, y1].concat(pi.slice(1));
  30716. x1 = bez1[6];
  30717. y1 = bez1[7];
  30718. } else {
  30719. bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
  30720. x1 = x1m;
  30721. y1 = y1m;
  30722. }
  30723. for (var j = 0, jj = path2.length; j < jj; j++) {
  30724. var pj = path2[j];
  30725. if (pj[0] == "M") {
  30726. x2 = x2m = pj[1];
  30727. y2 = y2m = pj[2];
  30728. } else {
  30729. if (pj[0] == "C") {
  30730. bez2 = [x2, y2].concat(pj.slice(1));
  30731. x2 = bez2[6];
  30732. y2 = bez2[7];
  30733. } else {
  30734. bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
  30735. x2 = x2m;
  30736. y2 = y2m;
  30737. }
  30738. var intr = interHelper(bez1, bez2, justCount);
  30739. if (justCount) {
  30740. res += intr;
  30741. } else {
  30742. for (var k = 0, kk = intr.length; k < kk; k++) {
  30743. intr[k].segment1 = i;
  30744. intr[k].segment2 = j;
  30745. intr[k].bez1 = bez1;
  30746. intr[k].bez2 = bez2;
  30747. }
  30748. res = res.concat(intr);
  30749. }
  30750. }
  30751. }
  30752. }
  30753. }
  30754. return res;
  30755. }
  30756. function isPointInsidePath(path, x, y) {
  30757. var bbox = pathBBox(path);
  30758. return isPointInsideBBox(bbox, x, y) &&
  30759. interPathHelper(path, [["M", x, y], ["H", bbox.x2 + 10]], 1) % 2 == 1;
  30760. }
  30761. function pathBBox(path) {
  30762. var pth = paths(path);
  30763. if (pth.bbox) {
  30764. return clone(pth.bbox);
  30765. }
  30766. if (!path) {
  30767. return box();
  30768. }
  30769. path = path2curve(path);
  30770. var x = 0,
  30771. y = 0,
  30772. X = [],
  30773. Y = [],
  30774. p;
  30775. for (var i = 0, ii = path.length; i < ii; i++) {
  30776. p = path[i];
  30777. if (p[0] == "M") {
  30778. x = p[1];
  30779. y = p[2];
  30780. X.push(x);
  30781. Y.push(y);
  30782. } else {
  30783. var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  30784. X = X.concat(dim.min.x, dim.max.x);
  30785. Y = Y.concat(dim.min.y, dim.max.y);
  30786. x = p[5];
  30787. y = p[6];
  30788. }
  30789. }
  30790. var xmin = mmin.apply(0, X),
  30791. ymin = mmin.apply(0, Y),
  30792. xmax = mmax.apply(0, X),
  30793. ymax = mmax.apply(0, Y),
  30794. bb = box(xmin, ymin, xmax - xmin, ymax - ymin);
  30795. pth.bbox = clone(bb);
  30796. return bb;
  30797. }
  30798. function rectPath(x, y, w, h, r) {
  30799. if (r) {
  30800. return [
  30801. ["M", +x + (+r), y],
  30802. ["l", w - r * 2, 0],
  30803. ["a", r, r, 0, 0, 1, r, r],
  30804. ["l", 0, h - r * 2],
  30805. ["a", r, r, 0, 0, 1, -r, r],
  30806. ["l", r * 2 - w, 0],
  30807. ["a", r, r, 0, 0, 1, -r, -r],
  30808. ["l", 0, r * 2 - h],
  30809. ["a", r, r, 0, 0, 1, r, -r],
  30810. ["z"]
  30811. ];
  30812. }
  30813. var res = [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
  30814. res.toString = toString;
  30815. return res;
  30816. }
  30817. function ellipsePath(x, y, rx, ry, a) {
  30818. if (a == null && ry == null) {
  30819. ry = rx;
  30820. }
  30821. x = +x;
  30822. y = +y;
  30823. rx = +rx;
  30824. ry = +ry;
  30825. if (a != null) {
  30826. var rad = Math.PI / 180,
  30827. x1 = x + rx * Math.cos(-ry * rad),
  30828. x2 = x + rx * Math.cos(-a * rad),
  30829. y1 = y + rx * Math.sin(-ry * rad),
  30830. y2 = y + rx * Math.sin(-a * rad),
  30831. res = [["M", x1, y1], ["A", rx, rx, 0, +(a - ry > 180), 0, x2, y2]];
  30832. } else {
  30833. res = [
  30834. ["M", x, y],
  30835. ["m", 0, -ry],
  30836. ["a", rx, ry, 0, 1, 1, 0, 2 * ry],
  30837. ["a", rx, ry, 0, 1, 1, 0, -2 * ry],
  30838. ["z"]
  30839. ];
  30840. }
  30841. res.toString = toString;
  30842. return res;
  30843. }
  30844. var unit2px = Snap._unit2px,
  30845. getPath = {
  30846. path: function (el) {
  30847. return el.attr("path");
  30848. },
  30849. circle: function (el) {
  30850. var attr = unit2px(el);
  30851. return ellipsePath(attr.cx, attr.cy, attr.r);
  30852. },
  30853. ellipse: function (el) {
  30854. var attr = unit2px(el);
  30855. return ellipsePath(attr.cx || 0, attr.cy || 0, attr.rx, attr.ry);
  30856. },
  30857. rect: function (el) {
  30858. var attr = unit2px(el);
  30859. return rectPath(attr.x || 0, attr.y || 0, attr.width, attr.height, attr.rx, attr.ry);
  30860. },
  30861. image: function (el) {
  30862. var attr = unit2px(el);
  30863. return rectPath(attr.x || 0, attr.y || 0, attr.width, attr.height);
  30864. },
  30865. line: function (el) {
  30866. return "M" + [el.attr("x1") || 0, el.attr("y1") || 0, el.attr("x2"), el.attr("y2")];
  30867. },
  30868. polyline: function (el) {
  30869. return "M" + el.attr("points");
  30870. },
  30871. polygon: function (el) {
  30872. return "M" + el.attr("points") + "z";
  30873. },
  30874. deflt: function (el) {
  30875. var bbox = el.node.getBBox();
  30876. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  30877. }
  30878. };
  30879. function pathToRelative(pathArray) {
  30880. var pth = paths(pathArray),
  30881. lowerCase = String.prototype.toLowerCase;
  30882. if (pth.rel) {
  30883. return pathClone(pth.rel);
  30884. }
  30885. if (!Snap.is(pathArray, "array") || !Snap.is(pathArray && pathArray[0], "array")) {
  30886. pathArray = Snap.parsePathString(pathArray);
  30887. }
  30888. var res = [],
  30889. x = 0,
  30890. y = 0,
  30891. mx = 0,
  30892. my = 0,
  30893. start = 0;
  30894. if (pathArray[0][0] == "M") {
  30895. x = pathArray[0][1];
  30896. y = pathArray[0][2];
  30897. mx = x;
  30898. my = y;
  30899. start++;
  30900. res.push(["M", x, y]);
  30901. }
  30902. for (var i = start, ii = pathArray.length; i < ii; i++) {
  30903. var r = res[i] = [],
  30904. pa = pathArray[i];
  30905. if (pa[0] != lowerCase.call(pa[0])) {
  30906. r[0] = lowerCase.call(pa[0]);
  30907. switch (r[0]) {
  30908. case "a":
  30909. r[1] = pa[1];
  30910. r[2] = pa[2];
  30911. r[3] = pa[3];
  30912. r[4] = pa[4];
  30913. r[5] = pa[5];
  30914. r[6] = +(pa[6] - x).toFixed(3);
  30915. r[7] = +(pa[7] - y).toFixed(3);
  30916. break;
  30917. case "v":
  30918. r[1] = +(pa[1] - y).toFixed(3);
  30919. break;
  30920. case "m":
  30921. mx = pa[1];
  30922. my = pa[2];
  30923. default:
  30924. for (var j = 1, jj = pa.length; j < jj; j++) {
  30925. r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
  30926. }
  30927. }
  30928. } else {
  30929. r = res[i] = [];
  30930. if (pa[0] == "m") {
  30931. mx = pa[1] + x;
  30932. my = pa[2] + y;
  30933. }
  30934. for (var k = 0, kk = pa.length; k < kk; k++) {
  30935. res[i][k] = pa[k];
  30936. }
  30937. }
  30938. var len = res[i].length;
  30939. switch (res[i][0]) {
  30940. case "z":
  30941. x = mx;
  30942. y = my;
  30943. break;
  30944. case "h":
  30945. x += +res[i][len - 1];
  30946. break;
  30947. case "v":
  30948. y += +res[i][len - 1];
  30949. break;
  30950. default:
  30951. x += +res[i][len - 2];
  30952. y += +res[i][len - 1];
  30953. }
  30954. }
  30955. res.toString = toString;
  30956. pth.rel = pathClone(res);
  30957. return res;
  30958. }
  30959. function pathToAbsolute(pathArray) {
  30960. var pth = paths(pathArray);
  30961. if (pth.abs) {
  30962. return pathClone(pth.abs);
  30963. }
  30964. if (!is(pathArray, "array") || !is(pathArray && pathArray[0], "array")) { // rough assumption
  30965. pathArray = Snap.parsePathString(pathArray);
  30966. }
  30967. if (!pathArray || !pathArray.length) {
  30968. return [["M", 0, 0]];
  30969. }
  30970. var res = [],
  30971. x = 0,
  30972. y = 0,
  30973. mx = 0,
  30974. my = 0,
  30975. start = 0,
  30976. pa0;
  30977. if (pathArray[0][0] == "M") {
  30978. x = +pathArray[0][1];
  30979. y = +pathArray[0][2];
  30980. mx = x;
  30981. my = y;
  30982. start++;
  30983. res[0] = ["M", x, y];
  30984. }
  30985. var crz = pathArray.length == 3 &&
  30986. pathArray[0][0] == "M" &&
  30987. pathArray[1][0].toUpperCase() == "R" &&
  30988. pathArray[2][0].toUpperCase() == "Z";
  30989. for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  30990. res.push(r = []);
  30991. pa = pathArray[i];
  30992. pa0 = pa[0];
  30993. if (pa0 != pa0.toUpperCase()) {
  30994. r[0] = pa0.toUpperCase();
  30995. switch (r[0]) {
  30996. case "A":
  30997. r[1] = pa[1];
  30998. r[2] = pa[2];
  30999. r[3] = pa[3];
  31000. r[4] = pa[4];
  31001. r[5] = pa[5];
  31002. r[6] = +pa[6] + x;
  31003. r[7] = +pa[7] + y;
  31004. break;
  31005. case "V":
  31006. r[1] = +pa[1] + y;
  31007. break;
  31008. case "H":
  31009. r[1] = +pa[1] + x;
  31010. break;
  31011. case "R":
  31012. var dots = [x, y].concat(pa.slice(1));
  31013. for (var j = 2, jj = dots.length; j < jj; j++) {
  31014. dots[j] = +dots[j] + x;
  31015. dots[++j] = +dots[j] + y;
  31016. }
  31017. res.pop();
  31018. res = res.concat(catmullRom2bezier(dots, crz));
  31019. break;
  31020. case "O":
  31021. res.pop();
  31022. dots = ellipsePath(x, y, pa[1], pa[2]);
  31023. dots.push(dots[0]);
  31024. res = res.concat(dots);
  31025. break;
  31026. case "U":
  31027. res.pop();
  31028. res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3]));
  31029. r = ["U"].concat(res[res.length - 1].slice(-2));
  31030. break;
  31031. case "M":
  31032. mx = +pa[1] + x;
  31033. my = +pa[2] + y;
  31034. default:
  31035. for (j = 1, jj = pa.length; j < jj; j++) {
  31036. r[j] = +pa[j] + ((j % 2) ? x : y);
  31037. }
  31038. }
  31039. } else if (pa0 == "R") {
  31040. dots = [x, y].concat(pa.slice(1));
  31041. res.pop();
  31042. res = res.concat(catmullRom2bezier(dots, crz));
  31043. r = ["R"].concat(pa.slice(-2));
  31044. } else if (pa0 == "O") {
  31045. res.pop();
  31046. dots = ellipsePath(x, y, pa[1], pa[2]);
  31047. dots.push(dots[0]);
  31048. res = res.concat(dots);
  31049. } else if (pa0 == "U") {
  31050. res.pop();
  31051. res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3]));
  31052. r = ["U"].concat(res[res.length - 1].slice(-2));
  31053. } else {
  31054. for (var k = 0, kk = pa.length; k < kk; k++) {
  31055. r[k] = pa[k];
  31056. }
  31057. }
  31058. pa0 = pa0.toUpperCase();
  31059. if (pa0 != "O") {
  31060. switch (r[0]) {
  31061. case "Z":
  31062. x = +mx;
  31063. y = +my;
  31064. break;
  31065. case "H":
  31066. x = r[1];
  31067. break;
  31068. case "V":
  31069. y = r[1];
  31070. break;
  31071. case "M":
  31072. mx = r[r.length - 2];
  31073. my = r[r.length - 1];
  31074. default:
  31075. x = r[r.length - 2];
  31076. y = r[r.length - 1];
  31077. }
  31078. }
  31079. }
  31080. res.toString = toString;
  31081. pth.abs = pathClone(res);
  31082. return res;
  31083. }
  31084. function l2c(x1, y1, x2, y2) {
  31085. return [x1, y1, x2, y2, x2, y2];
  31086. }
  31087. function q2c(x1, y1, ax, ay, x2, y2) {
  31088. var _13 = 1 / 3,
  31089. _23 = 2 / 3;
  31090. return [
  31091. _13 * x1 + _23 * ax,
  31092. _13 * y1 + _23 * ay,
  31093. _13 * x2 + _23 * ax,
  31094. _13 * y2 + _23 * ay,
  31095. x2,
  31096. y2
  31097. ];
  31098. }
  31099. function a2c(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
  31100. // for more information of where this math came from visit:
  31101. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  31102. var _120 = PI * 120 / 180,
  31103. rad = PI / 180 * (+angle || 0),
  31104. res = [],
  31105. xy,
  31106. rotate = Snap._.cacher(function (x, y, rad) {
  31107. var X = x * math.cos(rad) - y * math.sin(rad),
  31108. Y = x * math.sin(rad) + y * math.cos(rad);
  31109. return {x: X, y: Y};
  31110. });
  31111. if (!recursive) {
  31112. xy = rotate(x1, y1, -rad);
  31113. x1 = xy.x;
  31114. y1 = xy.y;
  31115. xy = rotate(x2, y2, -rad);
  31116. x2 = xy.x;
  31117. y2 = xy.y;
  31118. var cos = math.cos(PI / 180 * angle),
  31119. sin = math.sin(PI / 180 * angle),
  31120. x = (x1 - x2) / 2,
  31121. y = (y1 - y2) / 2;
  31122. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  31123. if (h > 1) {
  31124. h = math.sqrt(h);
  31125. rx = h * rx;
  31126. ry = h * ry;
  31127. }
  31128. var rx2 = rx * rx,
  31129. ry2 = ry * ry,
  31130. k = (large_arc_flag == sweep_flag ? -1 : 1) *
  31131. math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
  31132. cx = k * rx * y / ry + (x1 + x2) / 2,
  31133. cy = k * -ry * x / rx + (y1 + y2) / 2,
  31134. f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
  31135. f2 = math.asin(((y2 - cy) / ry).toFixed(9));
  31136. f1 = x1 < cx ? PI - f1 : f1;
  31137. f2 = x2 < cx ? PI - f2 : f2;
  31138. f1 < 0 && (f1 = PI * 2 + f1);
  31139. f2 < 0 && (f2 = PI * 2 + f2);
  31140. if (sweep_flag && f1 > f2) {
  31141. f1 = f1 - PI * 2;
  31142. }
  31143. if (!sweep_flag && f2 > f1) {
  31144. f2 = f2 - PI * 2;
  31145. }
  31146. } else {
  31147. f1 = recursive[0];
  31148. f2 = recursive[1];
  31149. cx = recursive[2];
  31150. cy = recursive[3];
  31151. }
  31152. var df = f2 - f1;
  31153. if (abs(df) > _120) {
  31154. var f2old = f2,
  31155. x2old = x2,
  31156. y2old = y2;
  31157. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  31158. x2 = cx + rx * math.cos(f2);
  31159. y2 = cy + ry * math.sin(f2);
  31160. res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
  31161. }
  31162. df = f2 - f1;
  31163. var c1 = math.cos(f1),
  31164. s1 = math.sin(f1),
  31165. c2 = math.cos(f2),
  31166. s2 = math.sin(f2),
  31167. t = math.tan(df / 4),
  31168. hx = 4 / 3 * rx * t,
  31169. hy = 4 / 3 * ry * t,
  31170. m1 = [x1, y1],
  31171. m2 = [x1 + hx * s1, y1 - hy * c1],
  31172. m3 = [x2 + hx * s2, y2 - hy * c2],
  31173. m4 = [x2, y2];
  31174. m2[0] = 2 * m1[0] - m2[0];
  31175. m2[1] = 2 * m1[1] - m2[1];
  31176. if (recursive) {
  31177. return [m2, m3, m4].concat(res);
  31178. } else {
  31179. res = [m2, m3, m4].concat(res).join().split(",");
  31180. var newres = [];
  31181. for (var i = 0, ii = res.length; i < ii; i++) {
  31182. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  31183. }
  31184. return newres;
  31185. }
  31186. }
  31187. function findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  31188. var t1 = 1 - t;
  31189. return {
  31190. x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
  31191. y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
  31192. };
  31193. }
  31194. // Returns bounding box of cubic bezier curve.
  31195. // Source: http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html
  31196. // Original version: NISHIO Hirokazu
  31197. // Modifications: https://github.com/timo22345
  31198. function curveDim(x0, y0, x1, y1, x2, y2, x3, y3) {
  31199. var tvalues = [],
  31200. bounds = [[], []],
  31201. a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  31202. for (var i = 0; i < 2; ++i) {
  31203. if (i == 0) {
  31204. b = 6 * x0 - 12 * x1 + 6 * x2;
  31205. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  31206. c = 3 * x1 - 3 * x0;
  31207. } else {
  31208. b = 6 * y0 - 12 * y1 + 6 * y2;
  31209. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  31210. c = 3 * y1 - 3 * y0;
  31211. }
  31212. if (abs(a) < 1e-12) {
  31213. if (abs(b) < 1e-12) {
  31214. continue;
  31215. }
  31216. t = -c / b;
  31217. if (0 < t && t < 1) {
  31218. tvalues.push(t);
  31219. }
  31220. continue;
  31221. }
  31222. b2ac = b * b - 4 * c * a;
  31223. sqrtb2ac = math.sqrt(b2ac);
  31224. if (b2ac < 0) {
  31225. continue;
  31226. }
  31227. t1 = (-b + sqrtb2ac) / (2 * a);
  31228. if (0 < t1 && t1 < 1) {
  31229. tvalues.push(t1);
  31230. }
  31231. t2 = (-b - sqrtb2ac) / (2 * a);
  31232. if (0 < t2 && t2 < 1) {
  31233. tvalues.push(t2);
  31234. }
  31235. }
  31236. var x, y, j = tvalues.length,
  31237. jlen = j,
  31238. mt;
  31239. while (j--) {
  31240. t = tvalues[j];
  31241. mt = 1 - t;
  31242. bounds[0][j] = (mt * mt * mt * x0) + (3 * mt * mt * t * x1) + (3 * mt * t * t * x2) + (t * t * t * x3);
  31243. bounds[1][j] = (mt * mt * mt * y0) + (3 * mt * mt * t * y1) + (3 * mt * t * t * y2) + (t * t * t * y3);
  31244. }
  31245. bounds[0][jlen] = x0;
  31246. bounds[1][jlen] = y0;
  31247. bounds[0][jlen + 1] = x3;
  31248. bounds[1][jlen + 1] = y3;
  31249. bounds[0].length = bounds[1].length = jlen + 2;
  31250. return {
  31251. min: {x: mmin.apply(0, bounds[0]), y: mmin.apply(0, bounds[1])},
  31252. max: {x: mmax.apply(0, bounds[0]), y: mmax.apply(0, bounds[1])}
  31253. };
  31254. }
  31255. function path2curve(path, path2) {
  31256. var pth = !path2 && paths(path);
  31257. if (!path2 && pth.curve) {
  31258. return pathClone(pth.curve);
  31259. }
  31260. var p = pathToAbsolute(path),
  31261. p2 = path2 && pathToAbsolute(path2),
  31262. attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  31263. attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  31264. processPath = function (path, d, pcom) {
  31265. var nx, ny;
  31266. if (!path) {
  31267. return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
  31268. }
  31269. !(path[0] in {T: 1, Q: 1}) && (d.qx = d.qy = null);
  31270. switch (path[0]) {
  31271. case "M":
  31272. d.X = path[1];
  31273. d.Y = path[2];
  31274. break;
  31275. case "A":
  31276. path = ["C"].concat(a2c.apply(0, [d.x, d.y].concat(path.slice(1))));
  31277. break;
  31278. case "S":
  31279. if (pcom == "C" || pcom == "S") { // In "S" case we have to take into account, if the previous command is C/S.
  31280. nx = d.x * 2 - d.bx; // And reflect the previous
  31281. ny = d.y * 2 - d.by; // command's control point relative to the current point.
  31282. }
  31283. else { // or some else or nothing
  31284. nx = d.x;
  31285. ny = d.y;
  31286. }
  31287. path = ["C", nx, ny].concat(path.slice(1));
  31288. break;
  31289. case "T":
  31290. if (pcom == "Q" || pcom == "T") { // In "T" case we have to take into account, if the previous command is Q/T.
  31291. d.qx = d.x * 2 - d.qx; // And make a reflection similar
  31292. d.qy = d.y * 2 - d.qy; // to case "S".
  31293. }
  31294. else { // or something else or nothing
  31295. d.qx = d.x;
  31296. d.qy = d.y;
  31297. }
  31298. path = ["C"].concat(q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
  31299. break;
  31300. case "Q":
  31301. d.qx = path[1];
  31302. d.qy = path[2];
  31303. path = ["C"].concat(q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
  31304. break;
  31305. case "L":
  31306. path = ["C"].concat(l2c(d.x, d.y, path[1], path[2]));
  31307. break;
  31308. case "H":
  31309. path = ["C"].concat(l2c(d.x, d.y, path[1], d.y));
  31310. break;
  31311. case "V":
  31312. path = ["C"].concat(l2c(d.x, d.y, d.x, path[1]));
  31313. break;
  31314. case "Z":
  31315. path = ["C"].concat(l2c(d.x, d.y, d.X, d.Y));
  31316. break;
  31317. }
  31318. return path;
  31319. },
  31320. fixArc = function (pp, i) {
  31321. if (pp[i].length > 7) {
  31322. pp[i].shift();
  31323. var pi = pp[i];
  31324. while (pi.length) {
  31325. pcoms1[i] = "A"; // if created multiple C:s, their original seg is saved
  31326. p2 && (pcoms2[i] = "A"); // the same as above
  31327. pp.splice(i++, 0, ["C"].concat(pi.splice(0, 6)));
  31328. }
  31329. pp.splice(i, 1);
  31330. ii = mmax(p.length, p2 && p2.length || 0);
  31331. }
  31332. },
  31333. fixM = function (path1, path2, a1, a2, i) {
  31334. if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
  31335. path2.splice(i, 0, ["M", a2.x, a2.y]);
  31336. a1.bx = 0;
  31337. a1.by = 0;
  31338. a1.x = path1[i][1];
  31339. a1.y = path1[i][2];
  31340. ii = mmax(p.length, p2 && p2.length || 0);
  31341. }
  31342. },
  31343. pcoms1 = [], // path commands of original path p
  31344. pcoms2 = [], // path commands of original path p2
  31345. pfirst = "", // temporary holder for original path command
  31346. pcom = ""; // holder for previous path command of original path
  31347. for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
  31348. p[i] && (pfirst = p[i][0]); // save current path command
  31349. if (pfirst != "C") // C is not saved yet, because it may be result of conversion
  31350. {
  31351. pcoms1[i] = pfirst; // Save current path command
  31352. i && ( pcom = pcoms1[i - 1]); // Get previous path command pcom
  31353. }
  31354. p[i] = processPath(p[i], attrs, pcom); // Previous path command is inputted to processPath
  31355. if (pcoms1[i] != "A" && pfirst == "C") pcoms1[i] = "C"; // A is the only command
  31356. // which may produce multiple C:s
  31357. // so we have to make sure that C is also C in original path
  31358. fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1
  31359. if (p2) { // the same procedures is done to p2
  31360. p2[i] && (pfirst = p2[i][0]);
  31361. if (pfirst != "C") {
  31362. pcoms2[i] = pfirst;
  31363. i && (pcom = pcoms2[i - 1]);
  31364. }
  31365. p2[i] = processPath(p2[i], attrs2, pcom);
  31366. if (pcoms2[i] != "A" && pfirst == "C") {
  31367. pcoms2[i] = "C";
  31368. }
  31369. fixArc(p2, i);
  31370. }
  31371. fixM(p, p2, attrs, attrs2, i);
  31372. fixM(p2, p, attrs2, attrs, i);
  31373. var seg = p[i],
  31374. seg2 = p2 && p2[i],
  31375. seglen = seg.length,
  31376. seg2len = p2 && seg2.length;
  31377. attrs.x = seg[seglen - 2];
  31378. attrs.y = seg[seglen - 1];
  31379. attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
  31380. attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
  31381. attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
  31382. attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
  31383. attrs2.x = p2 && seg2[seg2len - 2];
  31384. attrs2.y = p2 && seg2[seg2len - 1];
  31385. }
  31386. if (!p2) {
  31387. pth.curve = pathClone(p);
  31388. }
  31389. return p2 ? [p, p2] : p;
  31390. }
  31391. function mapPath(path, matrix) {
  31392. if (!matrix) {
  31393. return path;
  31394. }
  31395. var x, y, i, j, ii, jj, pathi;
  31396. path = path2curve(path);
  31397. for (i = 0, ii = path.length; i < ii; i++) {
  31398. pathi = path[i];
  31399. for (j = 1, jj = pathi.length; j < jj; j += 2) {
  31400. x = matrix.x(pathi[j], pathi[j + 1]);
  31401. y = matrix.y(pathi[j], pathi[j + 1]);
  31402. pathi[j] = x;
  31403. pathi[j + 1] = y;
  31404. }
  31405. }
  31406. return path;
  31407. }
  31408. // http://schepers.cc/getting-to-the-point
  31409. function catmullRom2bezier(crp, z) {
  31410. var d = [];
  31411. for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) {
  31412. var p = [
  31413. {x: +crp[i - 2], y: +crp[i - 1]},
  31414. {x: +crp[i], y: +crp[i + 1]},
  31415. {x: +crp[i + 2], y: +crp[i + 3]},
  31416. {x: +crp[i + 4], y: +crp[i + 5]}
  31417. ];
  31418. if (z) {
  31419. if (!i) {
  31420. p[0] = {x: +crp[iLen - 2], y: +crp[iLen - 1]};
  31421. } else if (iLen - 4 == i) {
  31422. p[3] = {x: +crp[0], y: +crp[1]};
  31423. } else if (iLen - 2 == i) {
  31424. p[2] = {x: +crp[0], y: +crp[1]};
  31425. p[3] = {x: +crp[2], y: +crp[3]};
  31426. }
  31427. } else {
  31428. if (iLen - 4 == i) {
  31429. p[3] = p[2];
  31430. } else if (!i) {
  31431. p[0] = {x: +crp[i], y: +crp[i + 1]};
  31432. }
  31433. }
  31434. d.push(["C",
  31435. (-p[0].x + 6 * p[1].x + p[2].x) / 6,
  31436. (-p[0].y + 6 * p[1].y + p[2].y) / 6,
  31437. (p[1].x + 6 * p[2].x - p[3].x) / 6,
  31438. (p[1].y + 6*p[2].y - p[3].y) / 6,
  31439. p[2].x,
  31440. p[2].y
  31441. ]);
  31442. }
  31443. return d;
  31444. }
  31445. // export
  31446. Snap.path = paths;
  31447. /*\
  31448. * Snap.path.getTotalLength
  31449. [ method ]
  31450. **
  31451. * Returns the length of the given path in pixels
  31452. **
  31453. - path (string) SVG path string
  31454. **
  31455. = (number) length
  31456. \*/
  31457. Snap.path.getTotalLength = getTotalLength;
  31458. /*\
  31459. * Snap.path.getPointAtLength
  31460. [ method ]
  31461. **
  31462. * Returns the coordinates of the point located at the given length along the given path
  31463. **
  31464. - path (string) SVG path string
  31465. - length (number) length, in pixels, from the start of the path, excluding non-rendering jumps
  31466. **
  31467. = (object) representation of the point:
  31468. o {
  31469. o x: (number) x coordinate,
  31470. o y: (number) y coordinate,
  31471. o alpha: (number) angle of derivative
  31472. o }
  31473. \*/
  31474. Snap.path.getPointAtLength = getPointAtLength;
  31475. /*\
  31476. * Snap.path.getSubpath
  31477. [ method ]
  31478. **
  31479. * Returns the subpath of a given path between given start and end lengths
  31480. **
  31481. - path (string) SVG path string
  31482. - from (number) length, in pixels, from the start of the path to the start of the segment
  31483. - to (number) length, in pixels, from the start of the path to the end of the segment
  31484. **
  31485. = (string) path string definition for the segment
  31486. \*/
  31487. Snap.path.getSubpath = function (path, from, to) {
  31488. if (this.getTotalLength(path) - to < 1e-6) {
  31489. return getSubpathsAtLength(path, from).end;
  31490. }
  31491. var a = getSubpathsAtLength(path, to, 1);
  31492. return from ? getSubpathsAtLength(a, from).end : a;
  31493. };
  31494. /*\
  31495. * Element.getTotalLength
  31496. [ method ]
  31497. **
  31498. * Returns the length of the path in pixels (only works for `path` elements)
  31499. = (number) length
  31500. \*/
  31501. elproto.getTotalLength = function () {
  31502. if (this.node.getTotalLength) {
  31503. return this.node.getTotalLength();
  31504. }
  31505. };
  31506. // SIERRA Element.getPointAtLength()/Element.getTotalLength(): If a <path> is broken into different segments, is the jump distance to the new coordinates set by the _M_ or _m_ commands calculated as part of the path's total length?
  31507. /*\
  31508. * Element.getPointAtLength
  31509. [ method ]
  31510. **
  31511. * Returns coordinates of the point located at the given length on the given path (only works for `path` elements)
  31512. **
  31513. - length (number) length, in pixels, from the start of the path, excluding non-rendering jumps
  31514. **
  31515. = (object) representation of the point:
  31516. o {
  31517. o x: (number) x coordinate,
  31518. o y: (number) y coordinate,
  31519. o alpha: (number) angle of derivative
  31520. o }
  31521. \*/
  31522. elproto.getPointAtLength = function (length) {
  31523. return getPointAtLength(this.attr("d"), length);
  31524. };
  31525. // SIERRA Element.getSubpath(): Similar to the problem for Element.getPointAtLength(). Unclear how this would work for a segmented path. Overall, the concept of _subpath_ and what I'm calling a _segment_ (series of non-_M_ or _Z_ commands) is unclear.
  31526. /*\
  31527. * Element.getSubpath
  31528. [ method ]
  31529. **
  31530. * Returns subpath of a given element from given start and end lengths (only works for `path` elements)
  31531. **
  31532. - from (number) length, in pixels, from the start of the path to the start of the segment
  31533. - to (number) length, in pixels, from the start of the path to the end of the segment
  31534. **
  31535. = (string) path string definition for the segment
  31536. \*/
  31537. elproto.getSubpath = function (from, to) {
  31538. return Snap.path.getSubpath(this.attr("d"), from, to);
  31539. };
  31540. Snap._.box = box;
  31541. /*\
  31542. * Snap.path.findDotsAtSegment
  31543. [ method ]
  31544. **
  31545. * Utility method
  31546. **
  31547. * Finds dot coordinates on the given cubic beziér curve at the given t
  31548. - p1x (number) x of the first point of the curve
  31549. - p1y (number) y of the first point of the curve
  31550. - c1x (number) x of the first anchor of the curve
  31551. - c1y (number) y of the first anchor of the curve
  31552. - c2x (number) x of the second anchor of the curve
  31553. - c2y (number) y of the second anchor of the curve
  31554. - p2x (number) x of the second point of the curve
  31555. - p2y (number) y of the second point of the curve
  31556. - t (number) position on the curve (0..1)
  31557. = (object) point information in format:
  31558. o {
  31559. o x: (number) x coordinate of the point,
  31560. o y: (number) y coordinate of the point,
  31561. o m: {
  31562. o x: (number) x coordinate of the left anchor,
  31563. o y: (number) y coordinate of the left anchor
  31564. o },
  31565. o n: {
  31566. o x: (number) x coordinate of the right anchor,
  31567. o y: (number) y coordinate of the right anchor
  31568. o },
  31569. o start: {
  31570. o x: (number) x coordinate of the start of the curve,
  31571. o y: (number) y coordinate of the start of the curve
  31572. o },
  31573. o end: {
  31574. o x: (number) x coordinate of the end of the curve,
  31575. o y: (number) y coordinate of the end of the curve
  31576. o },
  31577. o alpha: (number) angle of the curve derivative at the point
  31578. o }
  31579. \*/
  31580. Snap.path.findDotsAtSegment = findDotsAtSegment;
  31581. /*\
  31582. * Snap.path.bezierBBox
  31583. [ method ]
  31584. **
  31585. * Utility method
  31586. **
  31587. * Returns the bounding box of a given cubic beziér curve
  31588. - p1x (number) x of the first point of the curve
  31589. - p1y (number) y of the first point of the curve
  31590. - c1x (number) x of the first anchor of the curve
  31591. - c1y (number) y of the first anchor of the curve
  31592. - c2x (number) x of the second anchor of the curve
  31593. - c2y (number) y of the second anchor of the curve
  31594. - p2x (number) x of the second point of the curve
  31595. - p2y (number) y of the second point of the curve
  31596. * or
  31597. - bez (array) array of six points for beziér curve
  31598. = (object) bounding box
  31599. o {
  31600. o x: (number) x coordinate of the left top point of the box,
  31601. o y: (number) y coordinate of the left top point of the box,
  31602. o x2: (number) x coordinate of the right bottom point of the box,
  31603. o y2: (number) y coordinate of the right bottom point of the box,
  31604. o width: (number) width of the box,
  31605. o height: (number) height of the box
  31606. o }
  31607. \*/
  31608. Snap.path.bezierBBox = bezierBBox;
  31609. /*\
  31610. * Snap.path.isPointInsideBBox
  31611. [ method ]
  31612. **
  31613. * Utility method
  31614. **
  31615. * Returns `true` if given point is inside bounding box
  31616. - bbox (string) bounding box
  31617. - x (string) x coordinate of the point
  31618. - y (string) y coordinate of the point
  31619. = (boolean) `true` if point is inside
  31620. \*/
  31621. Snap.path.isPointInsideBBox = isPointInsideBBox;
  31622. /*\
  31623. * Snap.path.isBBoxIntersect
  31624. [ method ]
  31625. **
  31626. * Utility method
  31627. **
  31628. * Returns `true` if two bounding boxes intersect
  31629. - bbox1 (string) first bounding box
  31630. - bbox2 (string) second bounding box
  31631. = (boolean) `true` if bounding boxes intersect
  31632. \*/
  31633. Snap.path.isBBoxIntersect = isBBoxIntersect;
  31634. /*\
  31635. * Snap.path.intersection
  31636. [ method ]
  31637. **
  31638. * Utility method
  31639. **
  31640. * Finds intersections of two paths
  31641. - path1 (string) path string
  31642. - path2 (string) path string
  31643. = (array) dots of intersection
  31644. o [
  31645. o {
  31646. o x: (number) x coordinate of the point,
  31647. o y: (number) y coordinate of the point,
  31648. o t1: (number) t value for segment of path1,
  31649. o t2: (number) t value for segment of path2,
  31650. o segment1: (number) order number for segment of path1,
  31651. o segment2: (number) order number for segment of path2,
  31652. o bez1: (array) eight coordinates representing beziér curve for the segment of path1,
  31653. o bez2: (array) eight coordinates representing beziér curve for the segment of path2
  31654. o }
  31655. o ]
  31656. \*/
  31657. Snap.path.intersection = pathIntersection;
  31658. Snap.path.intersectionNumber = pathIntersectionNumber;
  31659. /*\
  31660. * Snap.path.isPointInside
  31661. [ method ]
  31662. **
  31663. * Utility method
  31664. **
  31665. * Returns `true` if given point is inside a given closed path.
  31666. *
  31667. * Note: fill mode doesn’t affect the result of this method.
  31668. - path (string) path string
  31669. - x (number) x of the point
  31670. - y (number) y of the point
  31671. = (boolean) `true` if point is inside the path
  31672. \*/
  31673. Snap.path.isPointInside = isPointInsidePath;
  31674. /*\
  31675. * Snap.path.getBBox
  31676. [ method ]
  31677. **
  31678. * Utility method
  31679. **
  31680. * Returns the bounding box of a given path
  31681. - path (string) path string
  31682. = (object) bounding box
  31683. o {
  31684. o x: (number) x coordinate of the left top point of the box,
  31685. o y: (number) y coordinate of the left top point of the box,
  31686. o x2: (number) x coordinate of the right bottom point of the box,
  31687. o y2: (number) y coordinate of the right bottom point of the box,
  31688. o width: (number) width of the box,
  31689. o height: (number) height of the box
  31690. o }
  31691. \*/
  31692. Snap.path.getBBox = pathBBox;
  31693. Snap.path.get = getPath;
  31694. /*\
  31695. * Snap.path.toRelative
  31696. [ method ]
  31697. **
  31698. * Utility method
  31699. **
  31700. * Converts path coordinates into relative values
  31701. - path (string) path string
  31702. = (array) path string
  31703. \*/
  31704. Snap.path.toRelative = pathToRelative;
  31705. /*\
  31706. * Snap.path.toAbsolute
  31707. [ method ]
  31708. **
  31709. * Utility method
  31710. **
  31711. * Converts path coordinates into absolute values
  31712. - path (string) path string
  31713. = (array) path string
  31714. \*/
  31715. Snap.path.toAbsolute = pathToAbsolute;
  31716. /*\
  31717. * Snap.path.toCubic
  31718. [ method ]
  31719. **
  31720. * Utility method
  31721. **
  31722. * Converts path to a new path where all segments are cubic beziér curves
  31723. - pathString (string|array) path string or array of segments
  31724. = (array) array of segments
  31725. \*/
  31726. Snap.path.toCubic = path2curve;
  31727. /*\
  31728. * Snap.path.map
  31729. [ method ]
  31730. **
  31731. * Transform the path string with the given matrix
  31732. - path (string) path string
  31733. - matrix (object) see @Matrix
  31734. = (string) transformed path string
  31735. \*/
  31736. Snap.path.map = mapPath;
  31737. Snap.path.toString = toString;
  31738. Snap.path.clone = pathClone;
  31739. });
  31740. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  31741. //
  31742. // Licensed under the Apache License, Version 2.0 (the "License");
  31743. // you may not use this file except in compliance with the License.
  31744. // You may obtain a copy of the License at
  31745. //
  31746. // http://www.apache.org/licenses/LICENSE-2.0
  31747. //
  31748. // Unless required by applicable law or agreed to in writing, software
  31749. // distributed under the License is distributed on an "AS IS" BASIS,
  31750. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  31751. // See the License for the specific language governing permissions and
  31752. // limitations under the License.
  31753. Snap.plugin(function (Snap, Element, Paper, glob) {
  31754. var elproto = Element.prototype,
  31755. has = "hasOwnProperty",
  31756. supportsTouch = "createTouch" in glob.doc,
  31757. events = [
  31758. "click", "dblclick", "mousedown", "mousemove", "mouseout",
  31759. "mouseover", "mouseup", "touchstart", "touchmove", "touchend",
  31760. "touchcancel"
  31761. ],
  31762. touchMap = {
  31763. mousedown: "touchstart",
  31764. mousemove: "touchmove",
  31765. mouseup: "touchend"
  31766. },
  31767. getScroll = function (xy, el) {
  31768. var name = xy == "y" ? "scrollTop" : "scrollLeft",
  31769. doc = el && el.node ? el.node.ownerDocument : glob.doc;
  31770. return doc[name in doc.documentElement ? "documentElement" : "body"][name];
  31771. },
  31772. preventDefault = function () {
  31773. this.returnValue = false;
  31774. },
  31775. preventTouch = function () {
  31776. return this.originalEvent.preventDefault();
  31777. },
  31778. stopPropagation = function () {
  31779. this.cancelBubble = true;
  31780. },
  31781. stopTouch = function () {
  31782. return this.originalEvent.stopPropagation();
  31783. },
  31784. addEvent = (function () {
  31785. if (glob.doc.addEventListener) {
  31786. return function (obj, type, fn, element) {
  31787. var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
  31788. f = function (e) {
  31789. var scrollY = getScroll("y", element),
  31790. scrollX = getScroll("x", element);
  31791. if (supportsTouch && touchMap[has](type)) {
  31792. for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
  31793. if (e.targetTouches[i].target == obj || obj.contains(e.targetTouches[i].target)) {
  31794. var olde = e;
  31795. e = e.targetTouches[i];
  31796. e.originalEvent = olde;
  31797. e.preventDefault = preventTouch;
  31798. e.stopPropagation = stopTouch;
  31799. break;
  31800. }
  31801. }
  31802. }
  31803. var x = e.clientX + scrollX,
  31804. y = e.clientY + scrollY;
  31805. return fn.call(element, e, x, y);
  31806. };
  31807. if (type !== realName) {
  31808. obj.addEventListener(type, f, false);
  31809. }
  31810. obj.addEventListener(realName, f, false);
  31811. return function () {
  31812. if (type !== realName) {
  31813. obj.removeEventListener(type, f, false);
  31814. }
  31815. obj.removeEventListener(realName, f, false);
  31816. return true;
  31817. };
  31818. };
  31819. } else if (glob.doc.attachEvent) {
  31820. return function (obj, type, fn, element) {
  31821. var f = function (e) {
  31822. e = e || element.node.ownerDocument.window.event;
  31823. var scrollY = getScroll("y", element),
  31824. scrollX = getScroll("x", element),
  31825. x = e.clientX + scrollX,
  31826. y = e.clientY + scrollY;
  31827. e.preventDefault = e.preventDefault || preventDefault;
  31828. e.stopPropagation = e.stopPropagation || stopPropagation;
  31829. return fn.call(element, e, x, y);
  31830. };
  31831. obj.attachEvent("on" + type, f);
  31832. var detacher = function () {
  31833. obj.detachEvent("on" + type, f);
  31834. return true;
  31835. };
  31836. return detacher;
  31837. };
  31838. }
  31839. })(),
  31840. drag = [],
  31841. dragMove = function (e) {
  31842. var x = e.clientX,
  31843. y = e.clientY,
  31844. scrollY = getScroll("y"),
  31845. scrollX = getScroll("x"),
  31846. dragi,
  31847. j = drag.length;
  31848. while (j--) {
  31849. dragi = drag[j];
  31850. if (supportsTouch) {
  31851. var i = e.touches && e.touches.length,
  31852. touch;
  31853. while (i--) {
  31854. touch = e.touches[i];
  31855. if (touch.identifier == dragi.el._drag.id || dragi.el.node.contains(touch.target)) {
  31856. x = touch.clientX;
  31857. y = touch.clientY;
  31858. (e.originalEvent ? e.originalEvent : e).preventDefault();
  31859. break;
  31860. }
  31861. }
  31862. } else {
  31863. e.preventDefault();
  31864. }
  31865. var node = dragi.el.node,
  31866. o,
  31867. next = node.nextSibling,
  31868. parent = node.parentNode,
  31869. display = node.style.display;
  31870. // glob.win.opera && parent.removeChild(node);
  31871. // node.style.display = "none";
  31872. // o = dragi.el.paper.getElementByPoint(x, y);
  31873. // node.style.display = display;
  31874. // glob.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
  31875. // o && eve("snap.drag.over." + dragi.el.id, dragi.el, o);
  31876. x += scrollX;
  31877. y += scrollY;
  31878. eve("snap.drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
  31879. }
  31880. },
  31881. dragUp = function (e) {
  31882. Snap.unmousemove(dragMove).unmouseup(dragUp);
  31883. var i = drag.length,
  31884. dragi;
  31885. while (i--) {
  31886. dragi = drag[i];
  31887. dragi.el._drag = {};
  31888. eve("snap.drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
  31889. }
  31890. drag = [];
  31891. };
  31892. /*\
  31893. * Element.click
  31894. [ method ]
  31895. **
  31896. * Adds a click event handler to the element
  31897. - handler (function) handler for the event
  31898. = (object) @Element
  31899. \*/
  31900. /*\
  31901. * Element.unclick
  31902. [ method ]
  31903. **
  31904. * Removes a click event handler from the element
  31905. - handler (function) handler for the event
  31906. = (object) @Element
  31907. \*/
  31908. /*\
  31909. * Element.dblclick
  31910. [ method ]
  31911. **
  31912. * Adds a double click event handler to the element
  31913. - handler (function) handler for the event
  31914. = (object) @Element
  31915. \*/
  31916. /*\
  31917. * Element.undblclick
  31918. [ method ]
  31919. **
  31920. * Removes a double click event handler from the element
  31921. - handler (function) handler for the event
  31922. = (object) @Element
  31923. \*/
  31924. /*\
  31925. * Element.mousedown
  31926. [ method ]
  31927. **
  31928. * Adds a mousedown event handler to the element
  31929. - handler (function) handler for the event
  31930. = (object) @Element
  31931. \*/
  31932. /*\
  31933. * Element.unmousedown
  31934. [ method ]
  31935. **
  31936. * Removes a mousedown event handler from the element
  31937. - handler (function) handler for the event
  31938. = (object) @Element
  31939. \*/
  31940. /*\
  31941. * Element.mousemove
  31942. [ method ]
  31943. **
  31944. * Adds a mousemove event handler to the element
  31945. - handler (function) handler for the event
  31946. = (object) @Element
  31947. \*/
  31948. /*\
  31949. * Element.unmousemove
  31950. [ method ]
  31951. **
  31952. * Removes a mousemove event handler from the element
  31953. - handler (function) handler for the event
  31954. = (object) @Element
  31955. \*/
  31956. /*\
  31957. * Element.mouseout
  31958. [ method ]
  31959. **
  31960. * Adds a mouseout event handler to the element
  31961. - handler (function) handler for the event
  31962. = (object) @Element
  31963. \*/
  31964. /*\
  31965. * Element.unmouseout
  31966. [ method ]
  31967. **
  31968. * Removes a mouseout event handler from the element
  31969. - handler (function) handler for the event
  31970. = (object) @Element
  31971. \*/
  31972. /*\
  31973. * Element.mouseover
  31974. [ method ]
  31975. **
  31976. * Adds a mouseover event handler to the element
  31977. - handler (function) handler for the event
  31978. = (object) @Element
  31979. \*/
  31980. /*\
  31981. * Element.unmouseover
  31982. [ method ]
  31983. **
  31984. * Removes a mouseover event handler from the element
  31985. - handler (function) handler for the event
  31986. = (object) @Element
  31987. \*/
  31988. /*\
  31989. * Element.mouseup
  31990. [ method ]
  31991. **
  31992. * Adds a mouseup event handler to the element
  31993. - handler (function) handler for the event
  31994. = (object) @Element
  31995. \*/
  31996. /*\
  31997. * Element.unmouseup
  31998. [ method ]
  31999. **
  32000. * Removes a mouseup event handler from the element
  32001. - handler (function) handler for the event
  32002. = (object) @Element
  32003. \*/
  32004. /*\
  32005. * Element.touchstart
  32006. [ method ]
  32007. **
  32008. * Adds a touchstart event handler to the element
  32009. - handler (function) handler for the event
  32010. = (object) @Element
  32011. \*/
  32012. /*\
  32013. * Element.untouchstart
  32014. [ method ]
  32015. **
  32016. * Removes a touchstart event handler from the element
  32017. - handler (function) handler for the event
  32018. = (object) @Element
  32019. \*/
  32020. /*\
  32021. * Element.touchmove
  32022. [ method ]
  32023. **
  32024. * Adds a touchmove event handler to the element
  32025. - handler (function) handler for the event
  32026. = (object) @Element
  32027. \*/
  32028. /*\
  32029. * Element.untouchmove
  32030. [ method ]
  32031. **
  32032. * Removes a touchmove event handler from the element
  32033. - handler (function) handler for the event
  32034. = (object) @Element
  32035. \*/
  32036. /*\
  32037. * Element.touchend
  32038. [ method ]
  32039. **
  32040. * Adds a touchend event handler to the element
  32041. - handler (function) handler for the event
  32042. = (object) @Element
  32043. \*/
  32044. /*\
  32045. * Element.untouchend
  32046. [ method ]
  32047. **
  32048. * Removes a touchend event handler from the element
  32049. - handler (function) handler for the event
  32050. = (object) @Element
  32051. \*/
  32052. /*\
  32053. * Element.touchcancel
  32054. [ method ]
  32055. **
  32056. * Adds a touchcancel event handler to the element
  32057. - handler (function) handler for the event
  32058. = (object) @Element
  32059. \*/
  32060. /*\
  32061. * Element.untouchcancel
  32062. [ method ]
  32063. **
  32064. * Removes a touchcancel event handler from the element
  32065. - handler (function) handler for the event
  32066. = (object) @Element
  32067. \*/
  32068. for (var i = events.length; i--;) {
  32069. (function (eventName) {
  32070. Snap[eventName] = elproto[eventName] = function (fn, scope) {
  32071. if (Snap.is(fn, "function")) {
  32072. this.events = this.events || [];
  32073. this.events.push({
  32074. name: eventName,
  32075. f: fn,
  32076. unbind: addEvent(this.node || document, eventName, fn, scope || this)
  32077. });
  32078. }
  32079. return this;
  32080. };
  32081. Snap["un" + eventName] =
  32082. elproto["un" + eventName] = function (fn) {
  32083. var events = this.events || [],
  32084. l = events.length;
  32085. while (l--) if (events[l].name == eventName &&
  32086. (events[l].f == fn || !fn)) {
  32087. events[l].unbind();
  32088. events.splice(l, 1);
  32089. !events.length && delete this.events;
  32090. return this;
  32091. }
  32092. return this;
  32093. };
  32094. })(events[i]);
  32095. }
  32096. /*\
  32097. * Element.hover
  32098. [ method ]
  32099. **
  32100. * Adds hover event handlers to the element
  32101. - f_in (function) handler for hover in
  32102. - f_out (function) handler for hover out
  32103. - icontext (object) #optional context for hover in handler
  32104. - ocontext (object) #optional context for hover out handler
  32105. = (object) @Element
  32106. \*/
  32107. elproto.hover = function (f_in, f_out, scope_in, scope_out) {
  32108. return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
  32109. };
  32110. /*\
  32111. * Element.unhover
  32112. [ method ]
  32113. **
  32114. * Removes hover event handlers from the element
  32115. - f_in (function) handler for hover in
  32116. - f_out (function) handler for hover out
  32117. = (object) @Element
  32118. \*/
  32119. elproto.unhover = function (f_in, f_out) {
  32120. return this.unmouseover(f_in).unmouseout(f_out);
  32121. };
  32122. var draggable = [];
  32123. // SIERRA unclear what _context_ refers to for starting, ending, moving the drag gesture.
  32124. // SIERRA Element.drag(): _x position of the mouse_: Where are the x/y values offset from?
  32125. // SIERRA Element.drag(): much of this member's doc appears to be duplicated for some reason.
  32126. // SIERRA Unclear about this sentence: _Additionally following drag events will be triggered: drag.start.<id> on start, drag.end.<id> on end and drag.move.<id> on every move._ Is there a global _drag_ object to which you can assign handlers keyed by an element's ID?
  32127. /*\
  32128. * Element.drag
  32129. [ method ]
  32130. **
  32131. * Adds event handlers for an element's drag gesture
  32132. **
  32133. - onmove (function) handler for moving
  32134. - onstart (function) handler for drag start
  32135. - onend (function) handler for drag end
  32136. - mcontext (object) #optional context for moving handler
  32137. - scontext (object) #optional context for drag start handler
  32138. - econtext (object) #optional context for drag end handler
  32139. * Additionaly following `drag` events are triggered: `drag.start.<id>` on start,
  32140. * `drag.end.<id>` on end and `drag.move.<id>` on every move. When element is dragged over another element
  32141. * `drag.over.<id>` fires as well.
  32142. *
  32143. * Start event and start handler are called in specified context or in context of the element with following parameters:
  32144. o x (number) x position of the mouse
  32145. o y (number) y position of the mouse
  32146. o event (object) DOM event object
  32147. * Move event and move handler are called in specified context or in context of the element with following parameters:
  32148. o dx (number) shift by x from the start point
  32149. o dy (number) shift by y from the start point
  32150. o x (number) x position of the mouse
  32151. o y (number) y position of the mouse
  32152. o event (object) DOM event object
  32153. * End event and end handler are called in specified context or in context of the element with following parameters:
  32154. o event (object) DOM event object
  32155. = (object) @Element
  32156. \*/
  32157. elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
  32158. if (!arguments.length) {
  32159. var origTransform;
  32160. return this.drag(function (dx, dy) {
  32161. this.attr({
  32162. transform: origTransform + (origTransform ? "T" : "t") + [dx, dy]
  32163. });
  32164. }, function () {
  32165. origTransform = this.transform().local;
  32166. });
  32167. }
  32168. function start(e, x, y) {
  32169. (e.originalEvent || e).preventDefault();
  32170. this._drag.x = x;
  32171. this._drag.y = y;
  32172. this._drag.id = e.identifier;
  32173. !drag.length && Snap.mousemove(dragMove).mouseup(dragUp);
  32174. drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
  32175. onstart && eve.on("snap.drag.start." + this.id, onstart);
  32176. onmove && eve.on("snap.drag.move." + this.id, onmove);
  32177. onend && eve.on("snap.drag.end." + this.id, onend);
  32178. eve("snap.drag.start." + this.id, start_scope || move_scope || this, x, y, e);
  32179. }
  32180. this._drag = {};
  32181. draggable.push({el: this, start: start});
  32182. this.mousedown(start);
  32183. return this;
  32184. };
  32185. /*
  32186. * Element.onDragOver
  32187. [ method ]
  32188. **
  32189. * Shortcut to assign event handler for `drag.over.<id>` event, where `id` is the element's `id` (see @Element.id)
  32190. - f (function) handler for event, first argument would be the element you are dragging over
  32191. \*/
  32192. // elproto.onDragOver = function (f) {
  32193. // f ? eve.on("snap.drag.over." + this.id, f) : eve.unbind("snap.drag.over." + this.id);
  32194. // };
  32195. /*\
  32196. * Element.undrag
  32197. [ method ]
  32198. **
  32199. * Removes all drag event handlers from the given element
  32200. \*/
  32201. elproto.undrag = function () {
  32202. var i = draggable.length;
  32203. while (i--) if (draggable[i].el == this) {
  32204. this.unmousedown(draggable[i].start);
  32205. draggable.splice(i, 1);
  32206. eve.unbind("snap.drag.*." + this.id);
  32207. }
  32208. !draggable.length && Snap.unmousemove(dragMove).unmouseup(dragUp);
  32209. return this;
  32210. };
  32211. });
  32212. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  32213. //
  32214. // Licensed under the Apache License, Version 2.0 (the "License");
  32215. // you may not use this file except in compliance with the License.
  32216. // You may obtain a copy of the License at
  32217. //
  32218. // http://www.apache.org/licenses/LICENSE-2.0
  32219. //
  32220. // Unless required by applicable law or agreed to in writing, software
  32221. // distributed under the License is distributed on an "AS IS" BASIS,
  32222. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  32223. // See the License for the specific language governing permissions and
  32224. // limitations under the License.
  32225. Snap.plugin(function (Snap, Element, Paper, glob) {
  32226. var elproto = Element.prototype,
  32227. pproto = Paper.prototype,
  32228. rgurl = /^\s*url\((.+)\)/,
  32229. Str = String,
  32230. $ = Snap._.$;
  32231. Snap.filter = {};
  32232. /*\
  32233. * Paper.filter
  32234. [ method ]
  32235. **
  32236. * Creates a `<filter>` element
  32237. **
  32238. - filstr (string) SVG fragment of filter provided as a string
  32239. = (object) @Element
  32240. * Note: It is recommended to use filters embedded into the page inside an empty SVG element.
  32241. > Usage
  32242. | var f = paper.filter('<feGaussianBlur stdDeviation="2"/>'),
  32243. | c = paper.circle(10, 10, 10).attr({
  32244. | filter: f
  32245. | });
  32246. \*/
  32247. pproto.filter = function (filstr) {
  32248. var paper = this;
  32249. if (paper.type != "svg") {
  32250. paper = paper.paper;
  32251. }
  32252. var f = Snap.parse(Str(filstr)),
  32253. id = Snap._.id(),
  32254. width = paper.node.offsetWidth,
  32255. height = paper.node.offsetHeight,
  32256. filter = $("filter");
  32257. $(filter, {
  32258. id: id,
  32259. filterUnits: "userSpaceOnUse"
  32260. });
  32261. filter.appendChild(f.node);
  32262. paper.defs.appendChild(filter);
  32263. return new Element(filter);
  32264. };
  32265. eve.on("snap.util.getattr.filter", function () {
  32266. eve.stop();
  32267. var p = $(this.node, "filter");
  32268. if (p) {
  32269. var match = Str(p).match(rgurl);
  32270. return match && Snap.select(match[1]);
  32271. }
  32272. });
  32273. eve.on("snap.util.attr.filter", function (value) {
  32274. if (value instanceof Element && value.type == "filter") {
  32275. eve.stop();
  32276. var id = value.node.id;
  32277. if (!id) {
  32278. $(value.node, {id: value.id});
  32279. id = value.id;
  32280. }
  32281. $(this.node, {
  32282. filter: Snap.url(id)
  32283. });
  32284. }
  32285. if (!value || value == "none") {
  32286. eve.stop();
  32287. this.node.removeAttribute("filter");
  32288. }
  32289. });
  32290. /*\
  32291. * Snap.filter.blur
  32292. [ method ]
  32293. **
  32294. * Returns an SVG markup string for the blur filter
  32295. **
  32296. - x (number) amount of horizontal blur, in pixels
  32297. - y (number) #optional amount of vertical blur, in pixels
  32298. = (string) filter representation
  32299. > Usage
  32300. | var f = paper.filter(Snap.filter.blur(5, 10)),
  32301. | c = paper.circle(10, 10, 10).attr({
  32302. | filter: f
  32303. | });
  32304. \*/
  32305. Snap.filter.blur = function (x, y) {
  32306. if (x == null) {
  32307. x = 2;
  32308. }
  32309. var def = y == null ? x : [x, y];
  32310. return Snap.format('\<feGaussianBlur stdDeviation="{def}"/>', {
  32311. def: def
  32312. });
  32313. };
  32314. Snap.filter.blur.toString = function () {
  32315. return this();
  32316. };
  32317. /*\
  32318. * Snap.filter.shadow
  32319. [ method ]
  32320. **
  32321. * Returns an SVG markup string for the shadow filter
  32322. **
  32323. - dx (number) #optional horizontal shift of the shadow, in pixels
  32324. - dy (number) #optional vertical shift of the shadow, in pixels
  32325. - blur (number) #optional amount of blur
  32326. - color (string) #optional color of the shadow
  32327. - opacity (number) #optional `0..1` opacity of the shadow
  32328. * or
  32329. - dx (number) #optional horizontal shift of the shadow, in pixels
  32330. - dy (number) #optional vertical shift of the shadow, in pixels
  32331. - color (string) #optional color of the shadow
  32332. - opacity (number) #optional `0..1` opacity of the shadow
  32333. * which makes blur default to `4`. Or
  32334. - dx (number) #optional horizontal shift of the shadow, in pixels
  32335. - dy (number) #optional vertical shift of the shadow, in pixels
  32336. - opacity (number) #optional `0..1` opacity of the shadow
  32337. = (string) filter representation
  32338. > Usage
  32339. | var f = paper.filter(Snap.filter.shadow(0, 2, 3)),
  32340. | c = paper.circle(10, 10, 10).attr({
  32341. | filter: f
  32342. | });
  32343. \*/
  32344. Snap.filter.shadow = function (dx, dy, blur, color, opacity) {
  32345. if (typeof blur == "string") {
  32346. color = blur;
  32347. opacity = color;
  32348. blur = 4;
  32349. }
  32350. if (typeof color != "string") {
  32351. opacity = color;
  32352. color = "#000";
  32353. }
  32354. color = color || "#000";
  32355. if (blur == null) {
  32356. blur = 4;
  32357. }
  32358. if (opacity == null) {
  32359. opacity = 1;
  32360. }
  32361. if (dx == null) {
  32362. dx = 0;
  32363. dy = 2;
  32364. }
  32365. if (dy == null) {
  32366. dy = dx;
  32367. }
  32368. color = Snap.color(color);
  32369. return Snap.format('<feGaussianBlur in="SourceAlpha" stdDeviation="{blur}"/><feOffset dx="{dx}" dy="{dy}" result="offsetblur"/><feFlood flood-color="{color}"/><feComposite in2="offsetblur" operator="in"/><feComponentTransfer><feFuncA type="linear" slope="{opacity}"/></feComponentTransfer><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>', {
  32370. color: color,
  32371. dx: dx,
  32372. dy: dy,
  32373. blur: blur,
  32374. opacity: opacity
  32375. });
  32376. };
  32377. Snap.filter.shadow.toString = function () {
  32378. return this();
  32379. };
  32380. /*\
  32381. * Snap.filter.grayscale
  32382. [ method ]
  32383. **
  32384. * Returns an SVG markup string for the grayscale filter
  32385. **
  32386. - amount (number) amount of filter (`0..1`)
  32387. = (string) filter representation
  32388. \*/
  32389. Snap.filter.grayscale = function (amount) {
  32390. if (amount == null) {
  32391. amount = 1;
  32392. }
  32393. return Snap.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {b} {h} 0 0 0 0 0 1 0"/>', {
  32394. a: 0.2126 + 0.7874 * (1 - amount),
  32395. b: 0.7152 - 0.7152 * (1 - amount),
  32396. c: 0.0722 - 0.0722 * (1 - amount),
  32397. d: 0.2126 - 0.2126 * (1 - amount),
  32398. e: 0.7152 + 0.2848 * (1 - amount),
  32399. f: 0.0722 - 0.0722 * (1 - amount),
  32400. g: 0.2126 - 0.2126 * (1 - amount),
  32401. h: 0.0722 + 0.9278 * (1 - amount)
  32402. });
  32403. };
  32404. Snap.filter.grayscale.toString = function () {
  32405. return this();
  32406. };
  32407. /*\
  32408. * Snap.filter.sepia
  32409. [ method ]
  32410. **
  32411. * Returns an SVG markup string for the sepia filter
  32412. **
  32413. - amount (number) amount of filter (`0..1`)
  32414. = (string) filter representation
  32415. \*/
  32416. Snap.filter.sepia = function (amount) {
  32417. if (amount == null) {
  32418. amount = 1;
  32419. }
  32420. return Snap.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {h} {i} 0 0 0 0 0 1 0"/>', {
  32421. a: 0.393 + 0.607 * (1 - amount),
  32422. b: 0.769 - 0.769 * (1 - amount),
  32423. c: 0.189 - 0.189 * (1 - amount),
  32424. d: 0.349 - 0.349 * (1 - amount),
  32425. e: 0.686 + 0.314 * (1 - amount),
  32426. f: 0.168 - 0.168 * (1 - amount),
  32427. g: 0.272 - 0.272 * (1 - amount),
  32428. h: 0.534 - 0.534 * (1 - amount),
  32429. i: 0.131 + 0.869 * (1 - amount)
  32430. });
  32431. };
  32432. Snap.filter.sepia.toString = function () {
  32433. return this();
  32434. };
  32435. /*\
  32436. * Snap.filter.saturate
  32437. [ method ]
  32438. **
  32439. * Returns an SVG markup string for the saturate filter
  32440. **
  32441. - amount (number) amount of filter (`0..1`)
  32442. = (string) filter representation
  32443. \*/
  32444. Snap.filter.saturate = function (amount) {
  32445. if (amount == null) {
  32446. amount = 1;
  32447. }
  32448. return Snap.format('<feColorMatrix type="saturate" values="{amount}"/>', {
  32449. amount: 1 - amount
  32450. });
  32451. };
  32452. Snap.filter.saturate.toString = function () {
  32453. return this();
  32454. };
  32455. /*\
  32456. * Snap.filter.hueRotate
  32457. [ method ]
  32458. **
  32459. * Returns an SVG markup string for the hue-rotate filter
  32460. **
  32461. - angle (number) angle of rotation
  32462. = (string) filter representation
  32463. \*/
  32464. Snap.filter.hueRotate = function (angle) {
  32465. angle = angle || 0;
  32466. return Snap.format('<feColorMatrix type="hueRotate" values="{angle}"/>', {
  32467. angle: angle
  32468. });
  32469. };
  32470. Snap.filter.hueRotate.toString = function () {
  32471. return this();
  32472. };
  32473. /*\
  32474. * Snap.filter.invert
  32475. [ method ]
  32476. **
  32477. * Returns an SVG markup string for the invert filter
  32478. **
  32479. - amount (number) amount of filter (`0..1`)
  32480. = (string) filter representation
  32481. \*/
  32482. Snap.filter.invert = function (amount) {
  32483. if (amount == null) {
  32484. amount = 1;
  32485. }
  32486. return Snap.format('<feComponentTransfer><feFuncR type="table" tableValues="{amount} {amount2}"/><feFuncG type="table" tableValues="{amount} {amount2}"/><feFuncB type="table" tableValues="{amount} {amount2}"/></feComponentTransfer>', {
  32487. amount: amount,
  32488. amount2: 1 - amount
  32489. });
  32490. };
  32491. Snap.filter.invert.toString = function () {
  32492. return this();
  32493. };
  32494. /*\
  32495. * Snap.filter.brightness
  32496. [ method ]
  32497. **
  32498. * Returns an SVG markup string for the brightness filter
  32499. **
  32500. - amount (number) amount of filter (`0..1`)
  32501. = (string) filter representation
  32502. \*/
  32503. Snap.filter.brightness = function (amount) {
  32504. if (amount == null) {
  32505. amount = 1;
  32506. }
  32507. return Snap.format('<feComponentTransfer><feFuncR type="linear" slope="{amount}"/><feFuncG type="linear" slope="{amount}"/><feFuncB type="linear" slope="{amount}"/></feComponentTransfer>', {
  32508. amount: amount
  32509. });
  32510. };
  32511. Snap.filter.brightness.toString = function () {
  32512. return this();
  32513. };
  32514. /*\
  32515. * Snap.filter.contrast
  32516. [ method ]
  32517. **
  32518. * Returns an SVG markup string for the contrast filter
  32519. **
  32520. - amount (number) amount of filter (`0..1`)
  32521. = (string) filter representation
  32522. \*/
  32523. Snap.filter.contrast = function (amount) {
  32524. if (amount == null) {
  32525. amount = 1;
  32526. }
  32527. return Snap.format('<feComponentTransfer><feFuncR type="linear" slope="{amount}" intercept="{amount2}"/><feFuncG type="linear" slope="{amount}" intercept="{amount2}"/><feFuncB type="linear" slope="{amount}" intercept="{amount2}"/></feComponentTransfer>', {
  32528. amount: amount,
  32529. amount2: .5 - amount / 2
  32530. });
  32531. };
  32532. Snap.filter.contrast.toString = function () {
  32533. return this();
  32534. };
  32535. });
  32536. return Snap;
  32537. }));
  32538. },{"197":197}],200:[function(_dereq_,module,exports){
  32539. 'use strict';
  32540. var snapsvg = module.exports = _dereq_(199);
  32541. snapsvg.plugin(function(Snap, Element) {
  32542. /*\
  32543. * Element.children
  32544. [ method ]
  32545. **
  32546. * Returns array of all the children of the element.
  32547. = (array) array of Elements
  32548. \*/
  32549. Element.prototype.children = function () {
  32550. var out = [],
  32551. ch = this.node.childNodes;
  32552. for (var i = 0, ii = ch.length; i < ii; i++) {
  32553. out[i] = new Snap(ch[i]);
  32554. }
  32555. return out;
  32556. };
  32557. });
  32558. /**
  32559. * @class ClassPlugin
  32560. *
  32561. * Extends snapsvg with methods to add and remove classes
  32562. */
  32563. snapsvg.plugin(function (Snap, Element, Paper, global) {
  32564. function split(str) {
  32565. return str.split(/\s+/);
  32566. }
  32567. function join(array) {
  32568. return array.join(' ');
  32569. }
  32570. function getClasses(e) {
  32571. return split(e.attr('class') || '');
  32572. }
  32573. function setClasses(e, classes) {
  32574. e.attr('class', join(classes));
  32575. }
  32576. /**
  32577. * @method snapsvg.Element#addClass
  32578. *
  32579. * @example
  32580. *
  32581. * e.attr('class', 'selector');
  32582. *
  32583. * e.addClass('foo bar'); // adds classes foo and bar
  32584. * e.attr('class'); // -> 'selector foo bar'
  32585. *
  32586. * e.addClass('fooBar');
  32587. * e.attr('class'); // -> 'selector foo bar fooBar'
  32588. *
  32589. * @param {String} cls classes to be added to the element
  32590. *
  32591. * @return {snapsvg.Element} the element (this)
  32592. */
  32593. Element.prototype.addClass = function(cls) {
  32594. var current = getClasses(this),
  32595. add = split(cls),
  32596. i, e;
  32597. for (i = 0, e; !!(e = add[i]); i++) {
  32598. if (current.indexOf(e) === -1) {
  32599. current.push(e);
  32600. }
  32601. }
  32602. setClasses(this, current);
  32603. return this;
  32604. };
  32605. /**
  32606. * @method snapsvg.Element#hasClass
  32607. *
  32608. * @param {String} cls the class to query for
  32609. * @return {Boolean} returns true if the element has the given class
  32610. */
  32611. Element.prototype.hasClass = function(cls) {
  32612. if (!cls) {
  32613. throw new Error('[snapsvg] syntax: hasClass(clsStr)');
  32614. }
  32615. return getClasses(this).indexOf(cls) !== -1;
  32616. };
  32617. /**
  32618. * @method snapsvg.Element#removeClass
  32619. *
  32620. * @example
  32621. *
  32622. * e.attr('class', 'foo bar');
  32623. *
  32624. * e.removeClass('foo');
  32625. * e.attr('class'); // -> 'bar'
  32626. *
  32627. * e.removeClass('foo bar'); // removes classes foo and bar
  32628. * e.attr('class'); // -> ''
  32629. *
  32630. * @param {String} cls classes to be removed from element
  32631. *
  32632. * @return {snapsvg.Element} the element (this)
  32633. */
  32634. Element.prototype.removeClass = function(cls) {
  32635. var current = getClasses(this),
  32636. remove = split(cls),
  32637. i, e, idx;
  32638. for (i = 0, e; !!(e = remove[i]); i++) {
  32639. idx = current.indexOf(e);
  32640. if (idx !== -1) {
  32641. // remove element from array
  32642. current.splice(idx, 1);
  32643. }
  32644. }
  32645. setClasses(this, current);
  32646. return this;
  32647. };
  32648. });
  32649. /**
  32650. * @class TranslatePlugin
  32651. *
  32652. * Extends snapsvg with methods to translate elements
  32653. */
  32654. snapsvg.plugin(function (Snap, Element, Paper, global) {
  32655. /*
  32656. * @method snapsvg.Element#translate
  32657. *
  32658. * @example
  32659. *
  32660. * e.translate(10, 20);
  32661. *
  32662. * // sets transform matrix to translate(10, 20)
  32663. *
  32664. * @param {Number} x translation
  32665. * @param {Number} y translation
  32666. *
  32667. * @return {snapsvg.Element} the element (this)
  32668. */
  32669. Element.prototype.translate = function(x, y) {
  32670. var matrix = new Snap.Matrix();
  32671. matrix.translate(x, y);
  32672. return this.transform(matrix);
  32673. };
  32674. });
  32675. /**
  32676. * @class CreatePlugin
  32677. *
  32678. * Create an svg element without attaching it to the dom
  32679. */
  32680. snapsvg.plugin(function(Snap) {
  32681. Snap.create = function(name, attrs) {
  32682. return Snap._.wrap(Snap._.$(name, attrs));
  32683. };
  32684. });
  32685. /**
  32686. * @class CreatSnapAtPlugin
  32687. *
  32688. * Extends snap.svg with a method to create a SVG element
  32689. * at a specific position in the DOM.
  32690. */
  32691. snapsvg.plugin(function(Snap, Element, Paper, global) {
  32692. /*
  32693. * @method snapsvg.createSnapAt
  32694. *
  32695. * @example
  32696. *
  32697. * snapsvg.createSnapAt(parentNode, 200, 200);
  32698. *
  32699. * @param {Number} width of svg
  32700. * @param {Number} height of svg
  32701. * @param {Object} parentNode svg Element will be child of this
  32702. *
  32703. * @return {snapsvg.Element} the newly created wrapped SVG element instance
  32704. */
  32705. Snap.createSnapAt = function(width, height, parentNode) {
  32706. var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  32707. svg.setAttribute('width', width);
  32708. svg.setAttribute('height', height);
  32709. if (!parentNode) {
  32710. parentNode = document.body;
  32711. }
  32712. parentNode.appendChild(svg);
  32713. return new Snap(svg);
  32714. };
  32715. });
  32716. },{"199":199}],201:[function(_dereq_,module,exports){
  32717. var isArray = function(obj) {
  32718. return Object.prototype.toString.call(obj) === '[object Array]';
  32719. };
  32720. var annotate = function() {
  32721. var args = Array.prototype.slice.call(arguments);
  32722. if (args.length === 1 && isArray(args[0])) {
  32723. args = args[0];
  32724. }
  32725. var fn = args.pop();
  32726. fn.$inject = args;
  32727. return fn;
  32728. };
  32729. // Current limitations:
  32730. // - can't put into "function arg" comments
  32731. // function /* (no parenthesis like this) */ (){}
  32732. // function abc( /* xx (no parenthesis like this) */ a, b) {}
  32733. //
  32734. // Just put the comment before function or inside:
  32735. // /* (((this is fine))) */ function(a, b) {}
  32736. // function abc(a) { /* (((this is fine))) */}
  32737. var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
  32738. var FN_ARG = /\/\*([^\*]*)\*\//m;
  32739. var parse = function(fn) {
  32740. if (typeof fn !== 'function') {
  32741. throw new Error('Cannot annotate "' + fn + '". Expected a function!');
  32742. }
  32743. var match = fn.toString().match(FN_ARGS);
  32744. return match[1] && match[1].split(',').map(function(arg) {
  32745. match = arg.match(FN_ARG);
  32746. return match ? match[1].trim() : arg.trim();
  32747. }) || [];
  32748. };
  32749. exports.annotate = annotate;
  32750. exports.parse = parse;
  32751. exports.isArray = isArray;
  32752. },{}],202:[function(_dereq_,module,exports){
  32753. module.exports = {
  32754. annotate: _dereq_(201).annotate,
  32755. Module: _dereq_(204),
  32756. Injector: _dereq_(203)
  32757. };
  32758. },{"201":201,"203":203,"204":204}],203:[function(_dereq_,module,exports){
  32759. var Module = _dereq_(204);
  32760. var autoAnnotate = _dereq_(201).parse;
  32761. var annotate = _dereq_(201).annotate;
  32762. var isArray = _dereq_(201).isArray;
  32763. var Injector = function(modules, parent) {
  32764. parent = parent || {
  32765. get: function(name) {
  32766. currentlyResolving.push(name);
  32767. throw error('No provider for "' + name + '"!');
  32768. }
  32769. };
  32770. var currentlyResolving = [];
  32771. var providers = this._providers = Object.create(parent._providers || null);
  32772. var instances = this._instances = Object.create(null);
  32773. var self = instances.injector = this;
  32774. var error = function(msg) {
  32775. var stack = currentlyResolving.join(' -> ');
  32776. currentlyResolving.length = 0;
  32777. return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
  32778. };
  32779. var get = function(name) {
  32780. if (!providers[name] && name.indexOf('.') !== -1) {
  32781. var parts = name.split('.');
  32782. var pivot = get(parts.shift());
  32783. while(parts.length) {
  32784. pivot = pivot[parts.shift()];
  32785. }
  32786. return pivot;
  32787. }
  32788. if (Object.hasOwnProperty.call(instances, name)) {
  32789. return instances[name];
  32790. }
  32791. if (Object.hasOwnProperty.call(providers, name)) {
  32792. if (currentlyResolving.indexOf(name) !== -1) {
  32793. currentlyResolving.push(name);
  32794. throw error('Cannot resolve circular dependency!');
  32795. }
  32796. currentlyResolving.push(name);
  32797. instances[name] = providers[name][0](providers[name][1]);
  32798. currentlyResolving.pop();
  32799. return instances[name];
  32800. }
  32801. return parent.get(name);
  32802. };
  32803. var instantiate = function(Type) {
  32804. var instance = Object.create(Type.prototype);
  32805. var returned = invoke(Type, instance);
  32806. return typeof returned === 'object' ? returned : instance;
  32807. };
  32808. var invoke = function(fn, context) {
  32809. if (typeof fn !== 'function') {
  32810. if (isArray(fn)) {
  32811. fn = annotate(fn.slice());
  32812. } else {
  32813. throw new Error('Cannot invoke "' + fn + '". Expected a function!');
  32814. }
  32815. }
  32816. var inject = fn.$inject && fn.$inject || autoAnnotate(fn);
  32817. var dependencies = inject.map(function(dep) {
  32818. return get(dep);
  32819. });
  32820. // TODO(vojta): optimize without apply
  32821. return fn.apply(context, dependencies);
  32822. };
  32823. var createPrivateInjectorFactory = function(privateChildInjector) {
  32824. return annotate(function(key) {
  32825. return privateChildInjector.get(key);
  32826. });
  32827. };
  32828. var createChild = function(modules, forceNewInstances) {
  32829. if (forceNewInstances && forceNewInstances.length) {
  32830. var fromParentModule = Object.create(null);
  32831. var matchedScopes = Object.create(null);
  32832. var privateInjectorsCache = [];
  32833. var privateChildInjectors = [];
  32834. var privateChildFactories = [];
  32835. var provider;
  32836. var cacheIdx;
  32837. var privateChildInjector;
  32838. var privateChildInjectorFactory;
  32839. for (var name in providers) {
  32840. provider = providers[name];
  32841. if (forceNewInstances.indexOf(name) !== -1) {
  32842. if (provider[2] === 'private') {
  32843. cacheIdx = privateInjectorsCache.indexOf(provider[3]);
  32844. if (cacheIdx === -1) {
  32845. privateChildInjector = provider[3].createChild([], forceNewInstances);
  32846. privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
  32847. privateInjectorsCache.push(provider[3]);
  32848. privateChildInjectors.push(privateChildInjector);
  32849. privateChildFactories.push(privateChildInjectorFactory);
  32850. fromParentModule[name] = [privateChildInjectorFactory, name, 'private', privateChildInjector];
  32851. } else {
  32852. fromParentModule[name] = [privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx]];
  32853. }
  32854. } else {
  32855. fromParentModule[name] = [provider[2], provider[1]];
  32856. }
  32857. matchedScopes[name] = true;
  32858. }
  32859. if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
  32860. forceNewInstances.forEach(function(scope) {
  32861. if (provider[1].$scope.indexOf(scope) !== -1) {
  32862. fromParentModule[name] = [provider[2], provider[1]];
  32863. matchedScopes[scope] = true;
  32864. }
  32865. });
  32866. }
  32867. }
  32868. forceNewInstances.forEach(function(scope) {
  32869. if (!matchedScopes[scope]) {
  32870. throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
  32871. }
  32872. });
  32873. modules.unshift(fromParentModule);
  32874. }
  32875. return new Injector(modules, self);
  32876. };
  32877. var factoryMap = {
  32878. factory: invoke,
  32879. type: instantiate,
  32880. value: function(value) {
  32881. return value;
  32882. }
  32883. };
  32884. modules.forEach(function(module) {
  32885. function arrayUnwrap(type, value) {
  32886. if (type !== 'value' && isArray(value)) {
  32887. value = annotate(value.slice());
  32888. }
  32889. return value;
  32890. }
  32891. // TODO(vojta): handle wrong inputs (modules)
  32892. if (module instanceof Module) {
  32893. module.forEach(function(provider) {
  32894. var name = provider[0];
  32895. var type = provider[1];
  32896. var value = provider[2];
  32897. providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
  32898. });
  32899. } else if (typeof module === 'object') {
  32900. if (module.__exports__) {
  32901. var clonedModule = Object.keys(module).reduce(function(m, key) {
  32902. if (key.substring(0, 2) !== '__') {
  32903. m[key] = module[key];
  32904. }
  32905. return m;
  32906. }, Object.create(null));
  32907. var privateInjector = new Injector((module.__modules__ || []).concat([clonedModule]), self);
  32908. var getFromPrivateInjector = annotate(function(key) {
  32909. return privateInjector.get(key);
  32910. });
  32911. module.__exports__.forEach(function(key) {
  32912. providers[key] = [getFromPrivateInjector, key, 'private', privateInjector];
  32913. });
  32914. } else {
  32915. Object.keys(module).forEach(function(name) {
  32916. if (module[name][2] === 'private') {
  32917. providers[name] = module[name];
  32918. return;
  32919. }
  32920. var type = module[name][0];
  32921. var value = module[name][1];
  32922. providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
  32923. });
  32924. }
  32925. }
  32926. });
  32927. // public API
  32928. this.get = get;
  32929. this.invoke = invoke;
  32930. this.instantiate = instantiate;
  32931. this.createChild = createChild;
  32932. };
  32933. module.exports = Injector;
  32934. },{"201":201,"204":204}],204:[function(_dereq_,module,exports){
  32935. var Module = function() {
  32936. var providers = [];
  32937. this.factory = function(name, factory) {
  32938. providers.push([name, 'factory', factory]);
  32939. return this;
  32940. };
  32941. this.value = function(name, value) {
  32942. providers.push([name, 'value', value]);
  32943. return this;
  32944. };
  32945. this.type = function(name, type) {
  32946. providers.push([name, 'type', type]);
  32947. return this;
  32948. };
  32949. this.forEach = function(iterator) {
  32950. providers.forEach(iterator);
  32951. };
  32952. };
  32953. module.exports = Module;
  32954. },{}],205:[function(_dereq_,module,exports){
  32955. 'use strict';
  32956. var hat = _dereq_(206);
  32957. /**
  32958. * Create a new id generator / cache instance.
  32959. *
  32960. * You may optionally provide a seed that is used internally.
  32961. *
  32962. * @param {Seed} seed
  32963. */
  32964. function Ids(seed) {
  32965. seed = seed || [ 128, 36, 1 ];
  32966. this._seed = seed.length ? hat.rack(seed[0], seed[1], seed[2]) : seed;
  32967. }
  32968. module.exports = Ids;
  32969. /**
  32970. * Generate a next id.
  32971. *
  32972. * @param {Object} [element] element to bind the id to
  32973. *
  32974. * @return {String} id
  32975. */
  32976. Ids.prototype.next = function(element) {
  32977. return this._seed(element || true);
  32978. };
  32979. /**
  32980. * Generate a next id with a given prefix.
  32981. *
  32982. * @param {Object} [element] element to bind the id to
  32983. *
  32984. * @return {String} id
  32985. */
  32986. Ids.prototype.nextPrefixed = function(prefix, element) {
  32987. var id;
  32988. do {
  32989. id = prefix + this.next(true);
  32990. } while (this.assigned(id));
  32991. // claim {prefix}{random}
  32992. this.claim(id, element);
  32993. // return
  32994. return id;
  32995. };
  32996. /**
  32997. * Manually claim an existing id.
  32998. *
  32999. * @param {String} id
  33000. * @param {String} [element] element the id is claimed by
  33001. */
  33002. Ids.prototype.claim = function(id, element) {
  33003. this._seed.set(id, element || true);
  33004. };
  33005. /**
  33006. * Returns true if the given id has already been assigned.
  33007. *
  33008. * @param {String} id
  33009. * @return {Boolean}
  33010. */
  33011. Ids.prototype.assigned = function(id) {
  33012. return this._seed.get(id) || false;
  33013. };
  33014. },{"206":206}],206:[function(_dereq_,module,exports){
  33015. var hat = module.exports = function (bits, base) {
  33016. if (!base) base = 16;
  33017. if (bits === undefined) bits = 128;
  33018. if (bits <= 0) return '0';
  33019. var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
  33020. for (var i = 2; digits === Infinity; i *= 2) {
  33021. digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
  33022. }
  33023. var rem = digits - Math.floor(digits);
  33024. var res = '';
  33025. for (var i = 0; i < Math.floor(digits); i++) {
  33026. var x = Math.floor(Math.random() * base).toString(base);
  33027. res = x + res;
  33028. }
  33029. if (rem) {
  33030. var b = Math.pow(base, rem);
  33031. var x = Math.floor(Math.random() * b).toString(base);
  33032. res = x + res;
  33033. }
  33034. var parsed = parseInt(res, base);
  33035. if (parsed !== Infinity && parsed >= Math.pow(2, bits)) {
  33036. return hat(bits, base)
  33037. }
  33038. else return res;
  33039. };
  33040. hat.rack = function (bits, base, expandBy) {
  33041. var fn = function (data) {
  33042. var iters = 0;
  33043. do {
  33044. if (iters ++ > 10) {
  33045. if (expandBy) bits += expandBy;
  33046. else throw new Error('too many ID collisions, use more bits')
  33047. }
  33048. var id = hat(bits, base);
  33049. } while (Object.hasOwnProperty.call(hats, id));
  33050. hats[id] = data;
  33051. return id;
  33052. };
  33053. var hats = fn.hats = {};
  33054. fn.get = function (id) {
  33055. return fn.hats[id];
  33056. };
  33057. fn.set = function (id, value) {
  33058. fn.hats[id] = value;
  33059. return fn;
  33060. };
  33061. fn.bits = bits || 128;
  33062. fn.base = base || 16;
  33063. return fn;
  33064. };
  33065. },{}],207:[function(_dereq_,module,exports){
  33066. if (typeof Object.create === 'function') {
  33067. // implementation from standard node.js 'util' module
  33068. module.exports = function inherits(ctor, superCtor) {
  33069. ctor.super_ = superCtor
  33070. ctor.prototype = Object.create(superCtor.prototype, {
  33071. constructor: {
  33072. value: ctor,
  33073. enumerable: false,
  33074. writable: true,
  33075. configurable: true
  33076. }
  33077. });
  33078. };
  33079. } else {
  33080. // old school shim for old browsers
  33081. module.exports = function inherits(ctor, superCtor) {
  33082. ctor.super_ = superCtor
  33083. var TempCtor = function () {}
  33084. TempCtor.prototype = superCtor.prototype
  33085. ctor.prototype = new TempCtor()
  33086. ctor.prototype.constructor = ctor
  33087. }
  33088. }
  33089. },{}],208:[function(_dereq_,module,exports){
  33090. var baseFlatten = _dereq_(255),
  33091. isIterateeCall = _dereq_(310);
  33092. /**
  33093. * Flattens a nested array. If `isDeep` is `true` the array is recursively
  33094. * flattened, otherwise it's only flattened a single level.
  33095. *
  33096. * @static
  33097. * @memberOf _
  33098. * @category Array
  33099. * @param {Array} array The array to flatten.
  33100. * @param {boolean} [isDeep] Specify a deep flatten.
  33101. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  33102. * @returns {Array} Returns the new flattened array.
  33103. * @example
  33104. *
  33105. * _.flatten([1, [2, 3, [4]]]);
  33106. * // => [1, 2, 3, [4]]
  33107. *
  33108. * // using `isDeep`
  33109. * _.flatten([1, [2, 3, [4]]], true);
  33110. * // => [1, 2, 3, 4]
  33111. */
  33112. function flatten(array, isDeep, guard) {
  33113. var length = array ? array.length : 0;
  33114. if (guard && isIterateeCall(array, isDeep, guard)) {
  33115. isDeep = false;
  33116. }
  33117. return length ? baseFlatten(array, isDeep) : [];
  33118. }
  33119. module.exports = flatten;
  33120. },{"255":255,"310":310}],209:[function(_dereq_,module,exports){
  33121. /**
  33122. * Gets the last element of `array`.
  33123. *
  33124. * @static
  33125. * @memberOf _
  33126. * @category Array
  33127. * @param {Array} array The array to query.
  33128. * @returns {*} Returns the last element of `array`.
  33129. * @example
  33130. *
  33131. * _.last([1, 2, 3]);
  33132. * // => 3
  33133. */
  33134. function last(array) {
  33135. var length = array ? array.length : 0;
  33136. return length ? array[length - 1] : undefined;
  33137. }
  33138. module.exports = last;
  33139. },{}],210:[function(_dereq_,module,exports){
  33140. var baseCallback = _dereq_(244),
  33141. baseUniq = _dereq_(278),
  33142. isIterateeCall = _dereq_(310),
  33143. sortedUniq = _dereq_(325);
  33144. /**
  33145. * Creates a duplicate-free version of an array, using
  33146. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  33147. * for equality comparisons, in which only the first occurence of each element
  33148. * is kept. Providing `true` for `isSorted` performs a faster search algorithm
  33149. * for sorted arrays. If an iteratee function is provided it's invoked for
  33150. * each element in the array to generate the criterion by which uniqueness
  33151. * is computed. The `iteratee` is bound to `thisArg` and invoked with three
  33152. * arguments: (value, index, array).
  33153. *
  33154. * If a property name is provided for `iteratee` the created `_.property`
  33155. * style callback returns the property value of the given element.
  33156. *
  33157. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  33158. * style callback returns `true` for elements that have a matching property
  33159. * value, else `false`.
  33160. *
  33161. * If an object is provided for `iteratee` the created `_.matches` style
  33162. * callback returns `true` for elements that have the properties of the given
  33163. * object, else `false`.
  33164. *
  33165. * @static
  33166. * @memberOf _
  33167. * @alias unique
  33168. * @category Array
  33169. * @param {Array} array The array to inspect.
  33170. * @param {boolean} [isSorted] Specify the array is sorted.
  33171. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  33172. * @param {*} [thisArg] The `this` binding of `iteratee`.
  33173. * @returns {Array} Returns the new duplicate-value-free array.
  33174. * @example
  33175. *
  33176. * _.uniq([2, 1, 2]);
  33177. * // => [2, 1]
  33178. *
  33179. * // using `isSorted`
  33180. * _.uniq([1, 1, 2], true);
  33181. * // => [1, 2]
  33182. *
  33183. * // using an iteratee function
  33184. * _.uniq([1, 2.5, 1.5, 2], function(n) {
  33185. * return this.floor(n);
  33186. * }, Math);
  33187. * // => [1, 2.5]
  33188. *
  33189. * // using the `_.property` callback shorthand
  33190. * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  33191. * // => [{ 'x': 1 }, { 'x': 2 }]
  33192. */
  33193. function uniq(array, isSorted, iteratee, thisArg) {
  33194. var length = array ? array.length : 0;
  33195. if (!length) {
  33196. return [];
  33197. }
  33198. if (isSorted != null && typeof isSorted != 'boolean') {
  33199. thisArg = iteratee;
  33200. iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
  33201. isSorted = false;
  33202. }
  33203. iteratee = iteratee == null ? iteratee : baseCallback(iteratee, thisArg, 3);
  33204. return (isSorted)
  33205. ? sortedUniq(array, iteratee)
  33206. : baseUniq(array, iteratee);
  33207. }
  33208. module.exports = uniq;
  33209. },{"244":244,"278":278,"310":310,"325":325}],211:[function(_dereq_,module,exports){
  33210. module.exports = _dereq_(210);
  33211. },{"210":210}],212:[function(_dereq_,module,exports){
  33212. var baseDifference = _dereq_(249),
  33213. isArrayLike = _dereq_(308),
  33214. restParam = _dereq_(230);
  33215. /**
  33216. * Creates an array excluding all provided values using
  33217. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  33218. * for equality comparisons.
  33219. *
  33220. * @static
  33221. * @memberOf _
  33222. * @category Array
  33223. * @param {Array} array The array to filter.
  33224. * @param {...*} [values] The values to exclude.
  33225. * @returns {Array} Returns the new array of filtered values.
  33226. * @example
  33227. *
  33228. * _.without([1, 2, 1, 3], 1, 2);
  33229. * // => [3]
  33230. */
  33231. var without = restParam(function(array, values) {
  33232. return isArrayLike(array)
  33233. ? baseDifference(array, values)
  33234. : [];
  33235. });
  33236. module.exports = without;
  33237. },{"230":230,"249":249,"308":308}],213:[function(_dereq_,module,exports){
  33238. var LazyWrapper = _dereq_(231),
  33239. LodashWrapper = _dereq_(232),
  33240. baseLodash = _dereq_(264),
  33241. isArray = _dereq_(330),
  33242. isObjectLike = _dereq_(314),
  33243. wrapperClone = _dereq_(328);
  33244. /** Used for native method references. */
  33245. var objectProto = Object.prototype;
  33246. /** Used to check objects for own properties. */
  33247. var hasOwnProperty = objectProto.hasOwnProperty;
  33248. /**
  33249. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  33250. * Methods that operate on and return arrays, collections, and functions can
  33251. * be chained together. Methods that retrieve a single value or may return a
  33252. * primitive value will automatically end the chain returning the unwrapped
  33253. * value. Explicit chaining may be enabled using `_.chain`. The execution of
  33254. * chained methods is lazy, that is, execution is deferred until `_#value`
  33255. * is implicitly or explicitly called.
  33256. *
  33257. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  33258. * fusion is an optimization strategy which merge iteratee calls; this can help
  33259. * to avoid the creation of intermediate data structures and greatly reduce the
  33260. * number of iteratee executions.
  33261. *
  33262. * Chaining is supported in custom builds as long as the `_#value` method is
  33263. * directly or indirectly included in the build.
  33264. *
  33265. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  33266. *
  33267. * The wrapper `Array` methods are:
  33268. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
  33269. * `splice`, and `unshift`
  33270. *
  33271. * The wrapper `String` methods are:
  33272. * `replace` and `split`
  33273. *
  33274. * The wrapper methods that support shortcut fusion are:
  33275. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  33276. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  33277. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  33278. * and `where`
  33279. *
  33280. * The chainable wrapper methods are:
  33281. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  33282. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  33283. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
  33284. * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
  33285. * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
  33286. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  33287. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  33288. * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
  33289. * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
  33290. * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  33291. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  33292. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
  33293. * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
  33294. * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
  33295. * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
  33296. * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
  33297. * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
  33298. *
  33299. * The wrapper methods that are **not** chainable by default are:
  33300. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
  33301. * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
  33302. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
  33303. * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
  33304. * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  33305. * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
  33306. * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
  33307. * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
  33308. * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
  33309. * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
  33310. * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
  33311. * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
  33312. * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
  33313. * `unescape`, `uniqueId`, `value`, and `words`
  33314. *
  33315. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  33316. * otherwise an unwrapped value is returned.
  33317. *
  33318. * @name _
  33319. * @constructor
  33320. * @category Chain
  33321. * @param {*} value The value to wrap in a `lodash` instance.
  33322. * @returns {Object} Returns the new `lodash` wrapper instance.
  33323. * @example
  33324. *
  33325. * var wrapped = _([1, 2, 3]);
  33326. *
  33327. * // returns an unwrapped value
  33328. * wrapped.reduce(function(total, n) {
  33329. * return total + n;
  33330. * });
  33331. * // => 6
  33332. *
  33333. * // returns a wrapped value
  33334. * var squares = wrapped.map(function(n) {
  33335. * return n * n;
  33336. * });
  33337. *
  33338. * _.isArray(squares);
  33339. * // => false
  33340. *
  33341. * _.isArray(squares.value());
  33342. * // => true
  33343. */
  33344. function lodash(value) {
  33345. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  33346. if (value instanceof LodashWrapper) {
  33347. return value;
  33348. }
  33349. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  33350. return wrapperClone(value);
  33351. }
  33352. }
  33353. return new LodashWrapper(value);
  33354. }
  33355. // Ensure wrappers are instances of `baseLodash`.
  33356. lodash.prototype = baseLodash.prototype;
  33357. module.exports = lodash;
  33358. },{"231":231,"232":232,"264":264,"314":314,"328":328,"330":330}],214:[function(_dereq_,module,exports){
  33359. module.exports = _dereq_(224);
  33360. },{"224":224}],215:[function(_dereq_,module,exports){
  33361. var arrayEvery = _dereq_(236),
  33362. baseCallback = _dereq_(244),
  33363. baseEvery = _dereq_(251),
  33364. isArray = _dereq_(330),
  33365. isIterateeCall = _dereq_(310);
  33366. /**
  33367. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  33368. * The predicate is bound to `thisArg` and invoked with three arguments:
  33369. * (value, index|key, collection).
  33370. *
  33371. * If a property name is provided for `predicate` the created `_.property`
  33372. * style callback returns the property value of the given element.
  33373. *
  33374. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  33375. * style callback returns `true` for elements that have a matching property
  33376. * value, else `false`.
  33377. *
  33378. * If an object is provided for `predicate` the created `_.matches` style
  33379. * callback returns `true` for elements that have the properties of the given
  33380. * object, else `false`.
  33381. *
  33382. * @static
  33383. * @memberOf _
  33384. * @alias all
  33385. * @category Collection
  33386. * @param {Array|Object|string} collection The collection to iterate over.
  33387. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  33388. * per iteration.
  33389. * @param {*} [thisArg] The `this` binding of `predicate`.
  33390. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  33391. * else `false`.
  33392. * @example
  33393. *
  33394. * _.every([true, 1, null, 'yes'], Boolean);
  33395. * // => false
  33396. *
  33397. * var users = [
  33398. * { 'user': 'barney', 'active': false },
  33399. * { 'user': 'fred', 'active': false }
  33400. * ];
  33401. *
  33402. * // using the `_.matches` callback shorthand
  33403. * _.every(users, { 'user': 'barney', 'active': false });
  33404. * // => false
  33405. *
  33406. * // using the `_.matchesProperty` callback shorthand
  33407. * _.every(users, 'active', false);
  33408. * // => true
  33409. *
  33410. * // using the `_.property` callback shorthand
  33411. * _.every(users, 'active');
  33412. * // => false
  33413. */
  33414. function every(collection, predicate, thisArg) {
  33415. var func = isArray(collection) ? arrayEvery : baseEvery;
  33416. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  33417. predicate = undefined;
  33418. }
  33419. if (typeof predicate != 'function' || thisArg !== undefined) {
  33420. predicate = baseCallback(predicate, thisArg, 3);
  33421. }
  33422. return func(collection, predicate);
  33423. }
  33424. module.exports = every;
  33425. },{"236":236,"244":244,"251":251,"310":310,"330":330}],216:[function(_dereq_,module,exports){
  33426. var arrayFilter = _dereq_(237),
  33427. baseCallback = _dereq_(244),
  33428. baseFilter = _dereq_(252),
  33429. isArray = _dereq_(330);
  33430. /**
  33431. * Iterates over elements of `collection`, returning an array of all elements
  33432. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  33433. * invoked with three arguments: (value, index|key, collection).
  33434. *
  33435. * If a property name is provided for `predicate` the created `_.property`
  33436. * style callback returns the property value of the given element.
  33437. *
  33438. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  33439. * style callback returns `true` for elements that have a matching property
  33440. * value, else `false`.
  33441. *
  33442. * If an object is provided for `predicate` the created `_.matches` style
  33443. * callback returns `true` for elements that have the properties of the given
  33444. * object, else `false`.
  33445. *
  33446. * @static
  33447. * @memberOf _
  33448. * @alias select
  33449. * @category Collection
  33450. * @param {Array|Object|string} collection The collection to iterate over.
  33451. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  33452. * per iteration.
  33453. * @param {*} [thisArg] The `this` binding of `predicate`.
  33454. * @returns {Array} Returns the new filtered array.
  33455. * @example
  33456. *
  33457. * _.filter([4, 5, 6], function(n) {
  33458. * return n % 2 == 0;
  33459. * });
  33460. * // => [4, 6]
  33461. *
  33462. * var users = [
  33463. * { 'user': 'barney', 'age': 36, 'active': true },
  33464. * { 'user': 'fred', 'age': 40, 'active': false }
  33465. * ];
  33466. *
  33467. * // using the `_.matches` callback shorthand
  33468. * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
  33469. * // => ['barney']
  33470. *
  33471. * // using the `_.matchesProperty` callback shorthand
  33472. * _.pluck(_.filter(users, 'active', false), 'user');
  33473. * // => ['fred']
  33474. *
  33475. * // using the `_.property` callback shorthand
  33476. * _.pluck(_.filter(users, 'active'), 'user');
  33477. * // => ['barney']
  33478. */
  33479. function filter(collection, predicate, thisArg) {
  33480. var func = isArray(collection) ? arrayFilter : baseFilter;
  33481. predicate = baseCallback(predicate, thisArg, 3);
  33482. return func(collection, predicate);
  33483. }
  33484. module.exports = filter;
  33485. },{"237":237,"244":244,"252":252,"330":330}],217:[function(_dereq_,module,exports){
  33486. var baseEach = _dereq_(250),
  33487. createFind = _dereq_(293);
  33488. /**
  33489. * Iterates over elements of `collection`, returning the first element
  33490. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  33491. * invoked with three arguments: (value, index|key, collection).
  33492. *
  33493. * If a property name is provided for `predicate` the created `_.property`
  33494. * style callback returns the property value of the given element.
  33495. *
  33496. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  33497. * style callback returns `true` for elements that have a matching property
  33498. * value, else `false`.
  33499. *
  33500. * If an object is provided for `predicate` the created `_.matches` style
  33501. * callback returns `true` for elements that have the properties of the given
  33502. * object, else `false`.
  33503. *
  33504. * @static
  33505. * @memberOf _
  33506. * @alias detect
  33507. * @category Collection
  33508. * @param {Array|Object|string} collection The collection to search.
  33509. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  33510. * per iteration.
  33511. * @param {*} [thisArg] The `this` binding of `predicate`.
  33512. * @returns {*} Returns the matched element, else `undefined`.
  33513. * @example
  33514. *
  33515. * var users = [
  33516. * { 'user': 'barney', 'age': 36, 'active': true },
  33517. * { 'user': 'fred', 'age': 40, 'active': false },
  33518. * { 'user': 'pebbles', 'age': 1, 'active': true }
  33519. * ];
  33520. *
  33521. * _.result(_.find(users, function(chr) {
  33522. * return chr.age < 40;
  33523. * }), 'user');
  33524. * // => 'barney'
  33525. *
  33526. * // using the `_.matches` callback shorthand
  33527. * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
  33528. * // => 'pebbles'
  33529. *
  33530. * // using the `_.matchesProperty` callback shorthand
  33531. * _.result(_.find(users, 'active', false), 'user');
  33532. * // => 'fred'
  33533. *
  33534. * // using the `_.property` callback shorthand
  33535. * _.result(_.find(users, 'active'), 'user');
  33536. * // => 'barney'
  33537. */
  33538. var find = createFind(baseEach);
  33539. module.exports = find;
  33540. },{"250":250,"293":293}],218:[function(_dereq_,module,exports){
  33541. var arrayEach = _dereq_(235),
  33542. baseEach = _dereq_(250),
  33543. createForEach = _dereq_(294);
  33544. /**
  33545. * Iterates over elements of `collection` invoking `iteratee` for each element.
  33546. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  33547. * (value, index|key, collection). Iteratee functions may exit iteration early
  33548. * by explicitly returning `false`.
  33549. *
  33550. * **Note:** As with other "Collections" methods, objects with a "length" property
  33551. * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
  33552. * may be used for object iteration.
  33553. *
  33554. * @static
  33555. * @memberOf _
  33556. * @alias each
  33557. * @category Collection
  33558. * @param {Array|Object|string} collection The collection to iterate over.
  33559. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  33560. * @param {*} [thisArg] The `this` binding of `iteratee`.
  33561. * @returns {Array|Object|string} Returns `collection`.
  33562. * @example
  33563. *
  33564. * _([1, 2]).forEach(function(n) {
  33565. * console.log(n);
  33566. * }).value();
  33567. * // => logs each value from left to right and returns the array
  33568. *
  33569. * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
  33570. * console.log(n, key);
  33571. * });
  33572. * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
  33573. */
  33574. var forEach = createForEach(arrayEach, baseEach);
  33575. module.exports = forEach;
  33576. },{"235":235,"250":250,"294":294}],219:[function(_dereq_,module,exports){
  33577. var createAggregator = _dereq_(286);
  33578. /** Used for native method references. */
  33579. var objectProto = Object.prototype;
  33580. /** Used to check objects for own properties. */
  33581. var hasOwnProperty = objectProto.hasOwnProperty;
  33582. /**
  33583. * Creates an object composed of keys generated from the results of running
  33584. * each element of `collection` through `iteratee`. The corresponding value
  33585. * of each key is an array of the elements responsible for generating the key.
  33586. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  33587. * (value, index|key, collection).
  33588. *
  33589. * If a property name is provided for `iteratee` the created `_.property`
  33590. * style callback returns the property value of the given element.
  33591. *
  33592. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  33593. * style callback returns `true` for elements that have a matching property
  33594. * value, else `false`.
  33595. *
  33596. * If an object is provided for `iteratee` the created `_.matches` style
  33597. * callback returns `true` for elements that have the properties of the given
  33598. * object, else `false`.
  33599. *
  33600. * @static
  33601. * @memberOf _
  33602. * @category Collection
  33603. * @param {Array|Object|string} collection The collection to iterate over.
  33604. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  33605. * per iteration.
  33606. * @param {*} [thisArg] The `this` binding of `iteratee`.
  33607. * @returns {Object} Returns the composed aggregate object.
  33608. * @example
  33609. *
  33610. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  33611. * return Math.floor(n);
  33612. * });
  33613. * // => { '4': [4.2], '6': [6.1, 6.4] }
  33614. *
  33615. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  33616. * return this.floor(n);
  33617. * }, Math);
  33618. * // => { '4': [4.2], '6': [6.1, 6.4] }
  33619. *
  33620. * // using the `_.property` callback shorthand
  33621. * _.groupBy(['one', 'two', 'three'], 'length');
  33622. * // => { '3': ['one', 'two'], '5': ['three'] }
  33623. */
  33624. var groupBy = createAggregator(function(result, value, key) {
  33625. if (hasOwnProperty.call(result, key)) {
  33626. result[key].push(value);
  33627. } else {
  33628. result[key] = [value];
  33629. }
  33630. });
  33631. module.exports = groupBy;
  33632. },{"286":286}],220:[function(_dereq_,module,exports){
  33633. var baseIndexOf = _dereq_(260),
  33634. getLength = _dereq_(304),
  33635. isArray = _dereq_(330),
  33636. isIterateeCall = _dereq_(310),
  33637. isLength = _dereq_(313),
  33638. isString = _dereq_(336),
  33639. values = _dereq_(347);
  33640. /* Native method references for those with the same name as other `lodash` methods. */
  33641. var nativeMax = Math.max;
  33642. /**
  33643. * Checks if `target` is in `collection` using
  33644. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  33645. * for equality comparisons. If `fromIndex` is negative, it's used as the offset
  33646. * from the end of `collection`.
  33647. *
  33648. * @static
  33649. * @memberOf _
  33650. * @alias contains, include
  33651. * @category Collection
  33652. * @param {Array|Object|string} collection The collection to search.
  33653. * @param {*} target The value to search for.
  33654. * @param {number} [fromIndex=0] The index to search from.
  33655. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  33656. * @returns {boolean} Returns `true` if a matching element is found, else `false`.
  33657. * @example
  33658. *
  33659. * _.includes([1, 2, 3], 1);
  33660. * // => true
  33661. *
  33662. * _.includes([1, 2, 3], 1, 2);
  33663. * // => false
  33664. *
  33665. * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  33666. * // => true
  33667. *
  33668. * _.includes('pebbles', 'eb');
  33669. * // => true
  33670. */
  33671. function includes(collection, target, fromIndex, guard) {
  33672. var length = collection ? getLength(collection) : 0;
  33673. if (!isLength(length)) {
  33674. collection = values(collection);
  33675. length = collection.length;
  33676. }
  33677. if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
  33678. fromIndex = 0;
  33679. } else {
  33680. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
  33681. }
  33682. return (typeof collection == 'string' || !isArray(collection) && isString(collection))
  33683. ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
  33684. : (!!length && baseIndexOf(collection, target, fromIndex) > -1);
  33685. }
  33686. module.exports = includes;
  33687. },{"260":260,"304":304,"310":310,"313":313,"330":330,"336":336,"347":347}],221:[function(_dereq_,module,exports){
  33688. var arrayMap = _dereq_(238),
  33689. baseCallback = _dereq_(244),
  33690. baseMap = _dereq_(265),
  33691. isArray = _dereq_(330);
  33692. /**
  33693. * Creates an array of values by running each element in `collection` through
  33694. * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
  33695. * arguments: (value, index|key, collection).
  33696. *
  33697. * If a property name is provided for `iteratee` the created `_.property`
  33698. * style callback returns the property value of the given element.
  33699. *
  33700. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  33701. * style callback returns `true` for elements that have a matching property
  33702. * value, else `false`.
  33703. *
  33704. * If an object is provided for `iteratee` the created `_.matches` style
  33705. * callback returns `true` for elements that have the properties of the given
  33706. * object, else `false`.
  33707. *
  33708. * Many lodash methods are guarded to work as iteratees for methods like
  33709. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  33710. *
  33711. * The guarded methods are:
  33712. * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
  33713. * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
  33714. * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
  33715. * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
  33716. * `sum`, `uniq`, and `words`
  33717. *
  33718. * @static
  33719. * @memberOf _
  33720. * @alias collect
  33721. * @category Collection
  33722. * @param {Array|Object|string} collection The collection to iterate over.
  33723. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  33724. * per iteration.
  33725. * @param {*} [thisArg] The `this` binding of `iteratee`.
  33726. * @returns {Array} Returns the new mapped array.
  33727. * @example
  33728. *
  33729. * function timesThree(n) {
  33730. * return n * 3;
  33731. * }
  33732. *
  33733. * _.map([1, 2], timesThree);
  33734. * // => [3, 6]
  33735. *
  33736. * _.map({ 'a': 1, 'b': 2 }, timesThree);
  33737. * // => [3, 6] (iteration order is not guaranteed)
  33738. *
  33739. * var users = [
  33740. * { 'user': 'barney' },
  33741. * { 'user': 'fred' }
  33742. * ];
  33743. *
  33744. * // using the `_.property` callback shorthand
  33745. * _.map(users, 'user');
  33746. * // => ['barney', 'fred']
  33747. */
  33748. function map(collection, iteratee, thisArg) {
  33749. var func = isArray(collection) ? arrayMap : baseMap;
  33750. iteratee = baseCallback(iteratee, thisArg, 3);
  33751. return func(collection, iteratee);
  33752. }
  33753. module.exports = map;
  33754. },{"238":238,"244":244,"265":265,"330":330}],222:[function(_dereq_,module,exports){
  33755. var arrayReduce = _dereq_(240),
  33756. baseEach = _dereq_(250),
  33757. createReduce = _dereq_(297);
  33758. /**
  33759. * Reduces `collection` to a value which is the accumulated result of running
  33760. * each element in `collection` through `iteratee`, where each successive
  33761. * invocation is supplied the return value of the previous. If `accumulator`
  33762. * is not provided the first element of `collection` is used as the initial
  33763. * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
  33764. * (accumulator, value, index|key, collection).
  33765. *
  33766. * Many lodash methods are guarded to work as iteratees for methods like
  33767. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  33768. *
  33769. * The guarded methods are:
  33770. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
  33771. * and `sortByOrder`
  33772. *
  33773. * @static
  33774. * @memberOf _
  33775. * @alias foldl, inject
  33776. * @category Collection
  33777. * @param {Array|Object|string} collection The collection to iterate over.
  33778. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  33779. * @param {*} [accumulator] The initial value.
  33780. * @param {*} [thisArg] The `this` binding of `iteratee`.
  33781. * @returns {*} Returns the accumulated value.
  33782. * @example
  33783. *
  33784. * _.reduce([1, 2], function(total, n) {
  33785. * return total + n;
  33786. * });
  33787. * // => 3
  33788. *
  33789. * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
  33790. * result[key] = n * 3;
  33791. * return result;
  33792. * }, {});
  33793. * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
  33794. */
  33795. var reduce = createReduce(arrayReduce, baseEach);
  33796. module.exports = reduce;
  33797. },{"240":240,"250":250,"297":297}],223:[function(_dereq_,module,exports){
  33798. var getLength = _dereq_(304),
  33799. isLength = _dereq_(313),
  33800. keys = _dereq_(340);
  33801. /**
  33802. * Gets the size of `collection` by returning its length for array-like
  33803. * values or the number of own enumerable properties for objects.
  33804. *
  33805. * @static
  33806. * @memberOf _
  33807. * @category Collection
  33808. * @param {Array|Object|string} collection The collection to inspect.
  33809. * @returns {number} Returns the size of `collection`.
  33810. * @example
  33811. *
  33812. * _.size([1, 2, 3]);
  33813. * // => 3
  33814. *
  33815. * _.size({ 'a': 1, 'b': 2 });
  33816. * // => 2
  33817. *
  33818. * _.size('pebbles');
  33819. * // => 7
  33820. */
  33821. function size(collection) {
  33822. var length = collection ? getLength(collection) : 0;
  33823. return isLength(length) ? length : keys(collection).length;
  33824. }
  33825. module.exports = size;
  33826. },{"304":304,"313":313,"340":340}],224:[function(_dereq_,module,exports){
  33827. var arraySome = _dereq_(241),
  33828. baseCallback = _dereq_(244),
  33829. baseSome = _dereq_(275),
  33830. isArray = _dereq_(330),
  33831. isIterateeCall = _dereq_(310);
  33832. /**
  33833. * Checks if `predicate` returns truthy for **any** element of `collection`.
  33834. * The function returns as soon as it finds a passing value and does not iterate
  33835. * over the entire collection. The predicate is bound to `thisArg` and invoked
  33836. * with three arguments: (value, index|key, collection).
  33837. *
  33838. * If a property name is provided for `predicate` the created `_.property`
  33839. * style callback returns the property value of the given element.
  33840. *
  33841. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  33842. * style callback returns `true` for elements that have a matching property
  33843. * value, else `false`.
  33844. *
  33845. * If an object is provided for `predicate` the created `_.matches` style
  33846. * callback returns `true` for elements that have the properties of the given
  33847. * object, else `false`.
  33848. *
  33849. * @static
  33850. * @memberOf _
  33851. * @alias any
  33852. * @category Collection
  33853. * @param {Array|Object|string} collection The collection to iterate over.
  33854. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  33855. * per iteration.
  33856. * @param {*} [thisArg] The `this` binding of `predicate`.
  33857. * @returns {boolean} Returns `true` if any element passes the predicate check,
  33858. * else `false`.
  33859. * @example
  33860. *
  33861. * _.some([null, 0, 'yes', false], Boolean);
  33862. * // => true
  33863. *
  33864. * var users = [
  33865. * { 'user': 'barney', 'active': true },
  33866. * { 'user': 'fred', 'active': false }
  33867. * ];
  33868. *
  33869. * // using the `_.matches` callback shorthand
  33870. * _.some(users, { 'user': 'barney', 'active': false });
  33871. * // => false
  33872. *
  33873. * // using the `_.matchesProperty` callback shorthand
  33874. * _.some(users, 'active', false);
  33875. * // => true
  33876. *
  33877. * // using the `_.property` callback shorthand
  33878. * _.some(users, 'active');
  33879. * // => true
  33880. */
  33881. function some(collection, predicate, thisArg) {
  33882. var func = isArray(collection) ? arraySome : baseSome;
  33883. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  33884. predicate = undefined;
  33885. }
  33886. if (typeof predicate != 'function' || thisArg !== undefined) {
  33887. predicate = baseCallback(predicate, thisArg, 3);
  33888. }
  33889. return func(collection, predicate);
  33890. }
  33891. module.exports = some;
  33892. },{"241":241,"244":244,"275":275,"310":310,"330":330}],225:[function(_dereq_,module,exports){
  33893. var baseCallback = _dereq_(244),
  33894. baseMap = _dereq_(265),
  33895. baseSortBy = _dereq_(276),
  33896. compareAscending = _dereq_(283),
  33897. isIterateeCall = _dereq_(310);
  33898. /**
  33899. * Creates an array of elements, sorted in ascending order by the results of
  33900. * running each element in a collection through `iteratee`. This method performs
  33901. * a stable sort, that is, it preserves the original sort order of equal elements.
  33902. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  33903. * (value, index|key, collection).
  33904. *
  33905. * If a property name is provided for `iteratee` the created `_.property`
  33906. * style callback returns the property value of the given element.
  33907. *
  33908. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  33909. * style callback returns `true` for elements that have a matching property
  33910. * value, else `false`.
  33911. *
  33912. * If an object is provided for `iteratee` the created `_.matches` style
  33913. * callback returns `true` for elements that have the properties of the given
  33914. * object, else `false`.
  33915. *
  33916. * @static
  33917. * @memberOf _
  33918. * @category Collection
  33919. * @param {Array|Object|string} collection The collection to iterate over.
  33920. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  33921. * per iteration.
  33922. * @param {*} [thisArg] The `this` binding of `iteratee`.
  33923. * @returns {Array} Returns the new sorted array.
  33924. * @example
  33925. *
  33926. * _.sortBy([1, 2, 3], function(n) {
  33927. * return Math.sin(n);
  33928. * });
  33929. * // => [3, 1, 2]
  33930. *
  33931. * _.sortBy([1, 2, 3], function(n) {
  33932. * return this.sin(n);
  33933. * }, Math);
  33934. * // => [3, 1, 2]
  33935. *
  33936. * var users = [
  33937. * { 'user': 'fred' },
  33938. * { 'user': 'pebbles' },
  33939. * { 'user': 'barney' }
  33940. * ];
  33941. *
  33942. * // using the `_.property` callback shorthand
  33943. * _.pluck(_.sortBy(users, 'user'), 'user');
  33944. * // => ['barney', 'fred', 'pebbles']
  33945. */
  33946. function sortBy(collection, iteratee, thisArg) {
  33947. if (collection == null) {
  33948. return [];
  33949. }
  33950. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  33951. iteratee = undefined;
  33952. }
  33953. var index = -1;
  33954. iteratee = baseCallback(iteratee, thisArg, 3);
  33955. var result = baseMap(collection, function(value, key, collection) {
  33956. return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
  33957. });
  33958. return baseSortBy(result, compareAscending);
  33959. }
  33960. module.exports = sortBy;
  33961. },{"244":244,"265":265,"276":276,"283":283,"310":310}],226:[function(_dereq_,module,exports){
  33962. var getNative = _dereq_(306);
  33963. /* Native method references for those with the same name as other `lodash` methods. */
  33964. var nativeNow = getNative(Date, 'now');
  33965. /**
  33966. * Gets the number of milliseconds that have elapsed since the Unix epoch
  33967. * (1 January 1970 00:00:00 UTC).
  33968. *
  33969. * @static
  33970. * @memberOf _
  33971. * @category Date
  33972. * @example
  33973. *
  33974. * _.defer(function(stamp) {
  33975. * console.log(_.now() - stamp);
  33976. * }, _.now());
  33977. * // => logs the number of milliseconds it took for the deferred function to be invoked
  33978. */
  33979. var now = nativeNow || function() {
  33980. return new Date().getTime();
  33981. };
  33982. module.exports = now;
  33983. },{"306":306}],227:[function(_dereq_,module,exports){
  33984. var createWrapper = _dereq_(298),
  33985. replaceHolders = _dereq_(322),
  33986. restParam = _dereq_(230);
  33987. /** Used to compose bitmasks for wrapper metadata. */
  33988. var BIND_FLAG = 1,
  33989. PARTIAL_FLAG = 32;
  33990. /**
  33991. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  33992. * and prepends any additional `_.bind` arguments to those provided to the
  33993. * bound function.
  33994. *
  33995. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  33996. * may be used as a placeholder for partially applied arguments.
  33997. *
  33998. * **Note:** Unlike native `Function#bind` this method does not set the "length"
  33999. * property of bound functions.
  34000. *
  34001. * @static
  34002. * @memberOf _
  34003. * @category Function
  34004. * @param {Function} func The function to bind.
  34005. * @param {*} thisArg The `this` binding of `func`.
  34006. * @param {...*} [partials] The arguments to be partially applied.
  34007. * @returns {Function} Returns the new bound function.
  34008. * @example
  34009. *
  34010. * var greet = function(greeting, punctuation) {
  34011. * return greeting + ' ' + this.user + punctuation;
  34012. * };
  34013. *
  34014. * var object = { 'user': 'fred' };
  34015. *
  34016. * var bound = _.bind(greet, object, 'hi');
  34017. * bound('!');
  34018. * // => 'hi fred!'
  34019. *
  34020. * // using placeholders
  34021. * var bound = _.bind(greet, object, _, '!');
  34022. * bound('hi');
  34023. * // => 'hi fred!'
  34024. */
  34025. var bind = restParam(function(func, thisArg, partials) {
  34026. var bitmask = BIND_FLAG;
  34027. if (partials.length) {
  34028. var holders = replaceHolders(partials, bind.placeholder);
  34029. bitmask |= PARTIAL_FLAG;
  34030. }
  34031. return createWrapper(func, bitmask, thisArg, partials, holders);
  34032. });
  34033. // Assign default placeholders.
  34034. bind.placeholder = {};
  34035. module.exports = bind;
  34036. },{"230":230,"298":298,"322":322}],228:[function(_dereq_,module,exports){
  34037. var isObject = _dereq_(334),
  34038. now = _dereq_(226);
  34039. /** Used as the `TypeError` message for "Functions" methods. */
  34040. var FUNC_ERROR_TEXT = 'Expected a function';
  34041. /* Native method references for those with the same name as other `lodash` methods. */
  34042. var nativeMax = Math.max;
  34043. /**
  34044. * Creates a debounced function that delays invoking `func` until after `wait`
  34045. * milliseconds have elapsed since the last time the debounced function was
  34046. * invoked. The debounced function comes with a `cancel` method to cancel
  34047. * delayed invocations. Provide an options object to indicate that `func`
  34048. * should be invoked on the leading and/or trailing edge of the `wait` timeout.
  34049. * Subsequent calls to the debounced function return the result of the last
  34050. * `func` invocation.
  34051. *
  34052. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  34053. * on the trailing edge of the timeout only if the the debounced function is
  34054. * invoked more than once during the `wait` timeout.
  34055. *
  34056. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  34057. * for details over the differences between `_.debounce` and `_.throttle`.
  34058. *
  34059. * @static
  34060. * @memberOf _
  34061. * @category Function
  34062. * @param {Function} func The function to debounce.
  34063. * @param {number} [wait=0] The number of milliseconds to delay.
  34064. * @param {Object} [options] The options object.
  34065. * @param {boolean} [options.leading=false] Specify invoking on the leading
  34066. * edge of the timeout.
  34067. * @param {number} [options.maxWait] The maximum time `func` is allowed to be
  34068. * delayed before it's invoked.
  34069. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  34070. * edge of the timeout.
  34071. * @returns {Function} Returns the new debounced function.
  34072. * @example
  34073. *
  34074. * // avoid costly calculations while the window size is in flux
  34075. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  34076. *
  34077. * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
  34078. * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
  34079. * 'leading': true,
  34080. * 'trailing': false
  34081. * }));
  34082. *
  34083. * // ensure `batchLog` is invoked once after 1 second of debounced calls
  34084. * var source = new EventSource('/stream');
  34085. * jQuery(source).on('message', _.debounce(batchLog, 250, {
  34086. * 'maxWait': 1000
  34087. * }));
  34088. *
  34089. * // cancel a debounced call
  34090. * var todoChanges = _.debounce(batchLog, 1000);
  34091. * Object.observe(models.todo, todoChanges);
  34092. *
  34093. * Object.observe(models, function(changes) {
  34094. * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
  34095. * todoChanges.cancel();
  34096. * }
  34097. * }, ['delete']);
  34098. *
  34099. * // ...at some point `models.todo` is changed
  34100. * models.todo.completed = true;
  34101. *
  34102. * // ...before 1 second has passed `models.todo` is deleted
  34103. * // which cancels the debounced `todoChanges` call
  34104. * delete models.todo;
  34105. */
  34106. function debounce(func, wait, options) {
  34107. var args,
  34108. maxTimeoutId,
  34109. result,
  34110. stamp,
  34111. thisArg,
  34112. timeoutId,
  34113. trailingCall,
  34114. lastCalled = 0,
  34115. maxWait = false,
  34116. trailing = true;
  34117. if (typeof func != 'function') {
  34118. throw new TypeError(FUNC_ERROR_TEXT);
  34119. }
  34120. wait = wait < 0 ? 0 : (+wait || 0);
  34121. if (options === true) {
  34122. var leading = true;
  34123. trailing = false;
  34124. } else if (isObject(options)) {
  34125. leading = !!options.leading;
  34126. maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
  34127. trailing = 'trailing' in options ? !!options.trailing : trailing;
  34128. }
  34129. function cancel() {
  34130. if (timeoutId) {
  34131. clearTimeout(timeoutId);
  34132. }
  34133. if (maxTimeoutId) {
  34134. clearTimeout(maxTimeoutId);
  34135. }
  34136. lastCalled = 0;
  34137. maxTimeoutId = timeoutId = trailingCall = undefined;
  34138. }
  34139. function complete(isCalled, id) {
  34140. if (id) {
  34141. clearTimeout(id);
  34142. }
  34143. maxTimeoutId = timeoutId = trailingCall = undefined;
  34144. if (isCalled) {
  34145. lastCalled = now();
  34146. result = func.apply(thisArg, args);
  34147. if (!timeoutId && !maxTimeoutId) {
  34148. args = thisArg = undefined;
  34149. }
  34150. }
  34151. }
  34152. function delayed() {
  34153. var remaining = wait - (now() - stamp);
  34154. if (remaining <= 0 || remaining > wait) {
  34155. complete(trailingCall, maxTimeoutId);
  34156. } else {
  34157. timeoutId = setTimeout(delayed, remaining);
  34158. }
  34159. }
  34160. function maxDelayed() {
  34161. complete(trailing, timeoutId);
  34162. }
  34163. function debounced() {
  34164. args = arguments;
  34165. stamp = now();
  34166. thisArg = this;
  34167. trailingCall = trailing && (timeoutId || !leading);
  34168. if (maxWait === false) {
  34169. var leadingCall = leading && !timeoutId;
  34170. } else {
  34171. if (!maxTimeoutId && !leading) {
  34172. lastCalled = stamp;
  34173. }
  34174. var remaining = maxWait - (stamp - lastCalled),
  34175. isCalled = remaining <= 0 || remaining > maxWait;
  34176. if (isCalled) {
  34177. if (maxTimeoutId) {
  34178. maxTimeoutId = clearTimeout(maxTimeoutId);
  34179. }
  34180. lastCalled = stamp;
  34181. result = func.apply(thisArg, args);
  34182. }
  34183. else if (!maxTimeoutId) {
  34184. maxTimeoutId = setTimeout(maxDelayed, remaining);
  34185. }
  34186. }
  34187. if (isCalled && timeoutId) {
  34188. timeoutId = clearTimeout(timeoutId);
  34189. }
  34190. else if (!timeoutId && wait !== maxWait) {
  34191. timeoutId = setTimeout(delayed, wait);
  34192. }
  34193. if (leadingCall) {
  34194. isCalled = true;
  34195. result = func.apply(thisArg, args);
  34196. }
  34197. if (isCalled && !timeoutId && !maxTimeoutId) {
  34198. args = thisArg = undefined;
  34199. }
  34200. return result;
  34201. }
  34202. debounced.cancel = cancel;
  34203. return debounced;
  34204. }
  34205. module.exports = debounce;
  34206. },{"226":226,"334":334}],229:[function(_dereq_,module,exports){
  34207. var baseDelay = _dereq_(248),
  34208. restParam = _dereq_(230);
  34209. /**
  34210. * Defers invoking the `func` until the current call stack has cleared. Any
  34211. * additional arguments are provided to `func` when it's invoked.
  34212. *
  34213. * @static
  34214. * @memberOf _
  34215. * @category Function
  34216. * @param {Function} func The function to defer.
  34217. * @param {...*} [args] The arguments to invoke the function with.
  34218. * @returns {number} Returns the timer id.
  34219. * @example
  34220. *
  34221. * _.defer(function(text) {
  34222. * console.log(text);
  34223. * }, 'deferred');
  34224. * // logs 'deferred' after one or more milliseconds
  34225. */
  34226. var defer = restParam(function(func, args) {
  34227. return baseDelay(func, 1, args);
  34228. });
  34229. module.exports = defer;
  34230. },{"230":230,"248":248}],230:[function(_dereq_,module,exports){
  34231. /** Used as the `TypeError` message for "Functions" methods. */
  34232. var FUNC_ERROR_TEXT = 'Expected a function';
  34233. /* Native method references for those with the same name as other `lodash` methods. */
  34234. var nativeMax = Math.max;
  34235. /**
  34236. * Creates a function that invokes `func` with the `this` binding of the
  34237. * created function and arguments from `start` and beyond provided as an array.
  34238. *
  34239. * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
  34240. *
  34241. * @static
  34242. * @memberOf _
  34243. * @category Function
  34244. * @param {Function} func The function to apply a rest parameter to.
  34245. * @param {number} [start=func.length-1] The start position of the rest parameter.
  34246. * @returns {Function} Returns the new function.
  34247. * @example
  34248. *
  34249. * var say = _.restParam(function(what, names) {
  34250. * return what + ' ' + _.initial(names).join(', ') +
  34251. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  34252. * });
  34253. *
  34254. * say('hello', 'fred', 'barney', 'pebbles');
  34255. * // => 'hello fred, barney, & pebbles'
  34256. */
  34257. function restParam(func, start) {
  34258. if (typeof func != 'function') {
  34259. throw new TypeError(FUNC_ERROR_TEXT);
  34260. }
  34261. start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
  34262. return function() {
  34263. var args = arguments,
  34264. index = -1,
  34265. length = nativeMax(args.length - start, 0),
  34266. rest = Array(length);
  34267. while (++index < length) {
  34268. rest[index] = args[start + index];
  34269. }
  34270. switch (start) {
  34271. case 0: return func.call(this, rest);
  34272. case 1: return func.call(this, args[0], rest);
  34273. case 2: return func.call(this, args[0], args[1], rest);
  34274. }
  34275. var otherArgs = Array(start + 1);
  34276. index = -1;
  34277. while (++index < start) {
  34278. otherArgs[index] = args[index];
  34279. }
  34280. otherArgs[start] = rest;
  34281. return func.apply(this, otherArgs);
  34282. };
  34283. }
  34284. module.exports = restParam;
  34285. },{}],231:[function(_dereq_,module,exports){
  34286. var baseCreate = _dereq_(247),
  34287. baseLodash = _dereq_(264);
  34288. /** Used as references for `-Infinity` and `Infinity`. */
  34289. var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  34290. /**
  34291. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  34292. *
  34293. * @private
  34294. * @param {*} value The value to wrap.
  34295. */
  34296. function LazyWrapper(value) {
  34297. this.__wrapped__ = value;
  34298. this.__actions__ = [];
  34299. this.__dir__ = 1;
  34300. this.__filtered__ = false;
  34301. this.__iteratees__ = [];
  34302. this.__takeCount__ = POSITIVE_INFINITY;
  34303. this.__views__ = [];
  34304. }
  34305. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  34306. LazyWrapper.prototype.constructor = LazyWrapper;
  34307. module.exports = LazyWrapper;
  34308. },{"247":247,"264":264}],232:[function(_dereq_,module,exports){
  34309. var baseCreate = _dereq_(247),
  34310. baseLodash = _dereq_(264);
  34311. /**
  34312. * The base constructor for creating `lodash` wrapper objects.
  34313. *
  34314. * @private
  34315. * @param {*} value The value to wrap.
  34316. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  34317. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  34318. */
  34319. function LodashWrapper(value, chainAll, actions) {
  34320. this.__wrapped__ = value;
  34321. this.__actions__ = actions || [];
  34322. this.__chain__ = !!chainAll;
  34323. }
  34324. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  34325. LodashWrapper.prototype.constructor = LodashWrapper;
  34326. module.exports = LodashWrapper;
  34327. },{"247":247,"264":264}],233:[function(_dereq_,module,exports){
  34328. (function (global){
  34329. var cachePush = _dereq_(282),
  34330. getNative = _dereq_(306);
  34331. /** Native method references. */
  34332. var Set = getNative(global, 'Set');
  34333. /* Native method references for those with the same name as other `lodash` methods. */
  34334. var nativeCreate = getNative(Object, 'create');
  34335. /**
  34336. *
  34337. * Creates a cache object to store unique values.
  34338. *
  34339. * @private
  34340. * @param {Array} [values] The values to cache.
  34341. */
  34342. function SetCache(values) {
  34343. var length = values ? values.length : 0;
  34344. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  34345. while (length--) {
  34346. this.push(values[length]);
  34347. }
  34348. }
  34349. // Add functions to the `Set` cache.
  34350. SetCache.prototype.push = cachePush;
  34351. module.exports = SetCache;
  34352. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  34353. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9sb2Rhc2gvaW50ZXJuYWwvU2V0Q2FjaGUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSIsImZpbGUiOiJnZW5lcmF0ZWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlc0NvbnRlbnQiOlsidmFyIGNhY2hlUHVzaCA9IHJlcXVpcmUoJy4vY2FjaGVQdXNoJyksXG4gICAgZ2V0TmF0aXZlID0gcmVxdWlyZSgnLi9nZXROYXRpdmUnKTtcblxuLyoqIE5hdGl2ZSBtZXRob2QgcmVmZXJlbmNlcy4gKi9cbnZhciBTZXQgPSBnZXROYXRpdmUoZ2xvYmFsLCAnU2V0Jyk7XG5cbi8qIE5hdGl2ZSBtZXRob2QgcmVmZXJlbmNlcyBmb3IgdGhvc2Ugd2l0aCB0aGUgc2FtZSBuYW1lIGFzIG90aGVyIGBsb2Rhc2hgIG1ldGhvZHMuICovXG52YXIgbmF0aXZlQ3JlYXRlID0gZ2V0TmF0aXZlKE9iamVjdCwgJ2NyZWF0ZScpO1xuXG4vKipcbiAqXG4gKiBDcmVhdGVzIGEgY2FjaGUgb2JqZWN0IHRvIHN0b3JlIHVuaXF1ZSB2YWx1ZXMuXG4gKlxuICogQHByaXZhdGVcbiAqIEBwYXJhbSB7QXJyYXl9IFt2YWx1ZXNdIFRoZSB2YWx1ZXMgdG8gY2FjaGUuXG4gKi9cbmZ1bmN0aW9uIFNldENhY2hlKHZhbHVlcykge1xuICB2YXIgbGVuZ3RoID0gdmFsdWVzID8gdmFsdWVzLmxlbmd0aCA6IDA7XG5cbiAgdGhpcy5kYXRhID0geyAnaGFzaCc6IG5hdGl2ZUNyZWF0ZShudWxsKSwgJ3NldCc6IG5ldyBTZXQgfTtcbiAgd2hpbGUgKGxlbmd0aC0tKSB7XG4gICAgdGhpcy5wdXNoKHZhbHVlc1tsZW5ndGhdKTtcbiAgfVxufVxuXG4vLyBBZGQgZnVuY3Rpb25zIHRvIHRoZSBgU2V0YCBjYWNoZS5cblNldENhY2hlLnByb3RvdHlwZS5wdXNoID0gY2FjaGVQdXNoO1xuXG5tb2R1bGUuZXhwb3J0cyA9IFNldENhY2hlO1xuIl19
  34354. },{"282":282,"306":306}],234:[function(_dereq_,module,exports){
  34355. /**
  34356. * Copies the values of `source` to `array`.
  34357. *
  34358. * @private
  34359. * @param {Array} source The array to copy values from.
  34360. * @param {Array} [array=[]] The array to copy values to.
  34361. * @returns {Array} Returns `array`.
  34362. */
  34363. function arrayCopy(source, array) {
  34364. var index = -1,
  34365. length = source.length;
  34366. array || (array = Array(length));
  34367. while (++index < length) {
  34368. array[index] = source[index];
  34369. }
  34370. return array;
  34371. }
  34372. module.exports = arrayCopy;
  34373. },{}],235:[function(_dereq_,module,exports){
  34374. /**
  34375. * A specialized version of `_.forEach` for arrays without support for callback
  34376. * shorthands and `this` binding.
  34377. *
  34378. * @private
  34379. * @param {Array} array The array to iterate over.
  34380. * @param {Function} iteratee The function invoked per iteration.
  34381. * @returns {Array} Returns `array`.
  34382. */
  34383. function arrayEach(array, iteratee) {
  34384. var index = -1,
  34385. length = array.length;
  34386. while (++index < length) {
  34387. if (iteratee(array[index], index, array) === false) {
  34388. break;
  34389. }
  34390. }
  34391. return array;
  34392. }
  34393. module.exports = arrayEach;
  34394. },{}],236:[function(_dereq_,module,exports){
  34395. /**
  34396. * A specialized version of `_.every` for arrays without support for callback
  34397. * shorthands and `this` binding.
  34398. *
  34399. * @private
  34400. * @param {Array} array The array to iterate over.
  34401. * @param {Function} predicate The function invoked per iteration.
  34402. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  34403. * else `false`.
  34404. */
  34405. function arrayEvery(array, predicate) {
  34406. var index = -1,
  34407. length = array.length;
  34408. while (++index < length) {
  34409. if (!predicate(array[index], index, array)) {
  34410. return false;
  34411. }
  34412. }
  34413. return true;
  34414. }
  34415. module.exports = arrayEvery;
  34416. },{}],237:[function(_dereq_,module,exports){
  34417. /**
  34418. * A specialized version of `_.filter` for arrays without support for callback
  34419. * shorthands and `this` binding.
  34420. *
  34421. * @private
  34422. * @param {Array} array The array to iterate over.
  34423. * @param {Function} predicate The function invoked per iteration.
  34424. * @returns {Array} Returns the new filtered array.
  34425. */
  34426. function arrayFilter(array, predicate) {
  34427. var index = -1,
  34428. length = array.length,
  34429. resIndex = -1,
  34430. result = [];
  34431. while (++index < length) {
  34432. var value = array[index];
  34433. if (predicate(value, index, array)) {
  34434. result[++resIndex] = value;
  34435. }
  34436. }
  34437. return result;
  34438. }
  34439. module.exports = arrayFilter;
  34440. },{}],238:[function(_dereq_,module,exports){
  34441. /**
  34442. * A specialized version of `_.map` for arrays without support for callback
  34443. * shorthands and `this` binding.
  34444. *
  34445. * @private
  34446. * @param {Array} array The array to iterate over.
  34447. * @param {Function} iteratee The function invoked per iteration.
  34448. * @returns {Array} Returns the new mapped array.
  34449. */
  34450. function arrayMap(array, iteratee) {
  34451. var index = -1,
  34452. length = array.length,
  34453. result = Array(length);
  34454. while (++index < length) {
  34455. result[index] = iteratee(array[index], index, array);
  34456. }
  34457. return result;
  34458. }
  34459. module.exports = arrayMap;
  34460. },{}],239:[function(_dereq_,module,exports){
  34461. /**
  34462. * Appends the elements of `values` to `array`.
  34463. *
  34464. * @private
  34465. * @param {Array} array The array to modify.
  34466. * @param {Array} values The values to append.
  34467. * @returns {Array} Returns `array`.
  34468. */
  34469. function arrayPush(array, values) {
  34470. var index = -1,
  34471. length = values.length,
  34472. offset = array.length;
  34473. while (++index < length) {
  34474. array[offset + index] = values[index];
  34475. }
  34476. return array;
  34477. }
  34478. module.exports = arrayPush;
  34479. },{}],240:[function(_dereq_,module,exports){
  34480. /**
  34481. * A specialized version of `_.reduce` for arrays without support for callback
  34482. * shorthands and `this` binding.
  34483. *
  34484. * @private
  34485. * @param {Array} array The array to iterate over.
  34486. * @param {Function} iteratee The function invoked per iteration.
  34487. * @param {*} [accumulator] The initial value.
  34488. * @param {boolean} [initFromArray] Specify using the first element of `array`
  34489. * as the initial value.
  34490. * @returns {*} Returns the accumulated value.
  34491. */
  34492. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  34493. var index = -1,
  34494. length = array.length;
  34495. if (initFromArray && length) {
  34496. accumulator = array[++index];
  34497. }
  34498. while (++index < length) {
  34499. accumulator = iteratee(accumulator, array[index], index, array);
  34500. }
  34501. return accumulator;
  34502. }
  34503. module.exports = arrayReduce;
  34504. },{}],241:[function(_dereq_,module,exports){
  34505. /**
  34506. * A specialized version of `_.some` for arrays without support for callback
  34507. * shorthands and `this` binding.
  34508. *
  34509. * @private
  34510. * @param {Array} array The array to iterate over.
  34511. * @param {Function} predicate The function invoked per iteration.
  34512. * @returns {boolean} Returns `true` if any element passes the predicate check,
  34513. * else `false`.
  34514. */
  34515. function arraySome(array, predicate) {
  34516. var index = -1,
  34517. length = array.length;
  34518. while (++index < length) {
  34519. if (predicate(array[index], index, array)) {
  34520. return true;
  34521. }
  34522. }
  34523. return false;
  34524. }
  34525. module.exports = arraySome;
  34526. },{}],242:[function(_dereq_,module,exports){
  34527. var keys = _dereq_(340);
  34528. /**
  34529. * A specialized version of `_.assign` for customizing assigned values without
  34530. * support for argument juggling, multiple sources, and `this` binding `customizer`
  34531. * functions.
  34532. *
  34533. * @private
  34534. * @param {Object} object The destination object.
  34535. * @param {Object} source The source object.
  34536. * @param {Function} customizer The function to customize assigned values.
  34537. * @returns {Object} Returns `object`.
  34538. */
  34539. function assignWith(object, source, customizer) {
  34540. var index = -1,
  34541. props = keys(source),
  34542. length = props.length;
  34543. while (++index < length) {
  34544. var key = props[index],
  34545. value = object[key],
  34546. result = customizer(value, source[key], key, object, source);
  34547. if ((result === result ? (result !== value) : (value === value)) ||
  34548. (value === undefined && !(key in object))) {
  34549. object[key] = result;
  34550. }
  34551. }
  34552. return object;
  34553. }
  34554. module.exports = assignWith;
  34555. },{"340":340}],243:[function(_dereq_,module,exports){
  34556. var baseCopy = _dereq_(246),
  34557. keys = _dereq_(340);
  34558. /**
  34559. * The base implementation of `_.assign` without support for argument juggling,
  34560. * multiple sources, and `customizer` functions.
  34561. *
  34562. * @private
  34563. * @param {Object} object The destination object.
  34564. * @param {Object} source The source object.
  34565. * @returns {Object} Returns `object`.
  34566. */
  34567. function baseAssign(object, source) {
  34568. return source == null
  34569. ? object
  34570. : baseCopy(source, keys(source), object);
  34571. }
  34572. module.exports = baseAssign;
  34573. },{"246":246,"340":340}],244:[function(_dereq_,module,exports){
  34574. var baseMatches = _dereq_(266),
  34575. baseMatchesProperty = _dereq_(267),
  34576. bindCallback = _dereq_(280),
  34577. identity = _dereq_(348),
  34578. property = _dereq_(350);
  34579. /**
  34580. * The base implementation of `_.callback` which supports specifying the
  34581. * number of arguments to provide to `func`.
  34582. *
  34583. * @private
  34584. * @param {*} [func=_.identity] The value to convert to a callback.
  34585. * @param {*} [thisArg] The `this` binding of `func`.
  34586. * @param {number} [argCount] The number of arguments to provide to `func`.
  34587. * @returns {Function} Returns the callback.
  34588. */
  34589. function baseCallback(func, thisArg, argCount) {
  34590. var type = typeof func;
  34591. if (type == 'function') {
  34592. return thisArg === undefined
  34593. ? func
  34594. : bindCallback(func, thisArg, argCount);
  34595. }
  34596. if (func == null) {
  34597. return identity;
  34598. }
  34599. if (type == 'object') {
  34600. return baseMatches(func);
  34601. }
  34602. return thisArg === undefined
  34603. ? property(func)
  34604. : baseMatchesProperty(func, thisArg);
  34605. }
  34606. module.exports = baseCallback;
  34607. },{"266":266,"267":267,"280":280,"348":348,"350":350}],245:[function(_dereq_,module,exports){
  34608. /**
  34609. * The base implementation of `compareAscending` which compares values and
  34610. * sorts them in ascending order without guaranteeing a stable sort.
  34611. *
  34612. * @private
  34613. * @param {*} value The value to compare.
  34614. * @param {*} other The other value to compare.
  34615. * @returns {number} Returns the sort order indicator for `value`.
  34616. */
  34617. function baseCompareAscending(value, other) {
  34618. if (value !== other) {
  34619. var valIsNull = value === null,
  34620. valIsUndef = value === undefined,
  34621. valIsReflexive = value === value;
  34622. var othIsNull = other === null,
  34623. othIsUndef = other === undefined,
  34624. othIsReflexive = other === other;
  34625. if ((value > other && !othIsNull) || !valIsReflexive ||
  34626. (valIsNull && !othIsUndef && othIsReflexive) ||
  34627. (valIsUndef && othIsReflexive)) {
  34628. return 1;
  34629. }
  34630. if ((value < other && !valIsNull) || !othIsReflexive ||
  34631. (othIsNull && !valIsUndef && valIsReflexive) ||
  34632. (othIsUndef && valIsReflexive)) {
  34633. return -1;
  34634. }
  34635. }
  34636. return 0;
  34637. }
  34638. module.exports = baseCompareAscending;
  34639. },{}],246:[function(_dereq_,module,exports){
  34640. /**
  34641. * Copies properties of `source` to `object`.
  34642. *
  34643. * @private
  34644. * @param {Object} source The object to copy properties from.
  34645. * @param {Array} props The property names to copy.
  34646. * @param {Object} [object={}] The object to copy properties to.
  34647. * @returns {Object} Returns `object`.
  34648. */
  34649. function baseCopy(source, props, object) {
  34650. object || (object = {});
  34651. var index = -1,
  34652. length = props.length;
  34653. while (++index < length) {
  34654. var key = props[index];
  34655. object[key] = source[key];
  34656. }
  34657. return object;
  34658. }
  34659. module.exports = baseCopy;
  34660. },{}],247:[function(_dereq_,module,exports){
  34661. var isObject = _dereq_(334);
  34662. /**
  34663. * The base implementation of `_.create` without support for assigning
  34664. * properties to the created object.
  34665. *
  34666. * @private
  34667. * @param {Object} prototype The object to inherit from.
  34668. * @returns {Object} Returns the new object.
  34669. */
  34670. var baseCreate = (function() {
  34671. function object() {}
  34672. return function(prototype) {
  34673. if (isObject(prototype)) {
  34674. object.prototype = prototype;
  34675. var result = new object;
  34676. object.prototype = undefined;
  34677. }
  34678. return result || {};
  34679. };
  34680. }());
  34681. module.exports = baseCreate;
  34682. },{"334":334}],248:[function(_dereq_,module,exports){
  34683. /** Used as the `TypeError` message for "Functions" methods. */
  34684. var FUNC_ERROR_TEXT = 'Expected a function';
  34685. /**
  34686. * The base implementation of `_.delay` and `_.defer` which accepts an index
  34687. * of where to slice the arguments to provide to `func`.
  34688. *
  34689. * @private
  34690. * @param {Function} func The function to delay.
  34691. * @param {number} wait The number of milliseconds to delay invocation.
  34692. * @param {Object} args The arguments provide to `func`.
  34693. * @returns {number} Returns the timer id.
  34694. */
  34695. function baseDelay(func, wait, args) {
  34696. if (typeof func != 'function') {
  34697. throw new TypeError(FUNC_ERROR_TEXT);
  34698. }
  34699. return setTimeout(function() { func.apply(undefined, args); }, wait);
  34700. }
  34701. module.exports = baseDelay;
  34702. },{}],249:[function(_dereq_,module,exports){
  34703. var baseIndexOf = _dereq_(260),
  34704. cacheIndexOf = _dereq_(281),
  34705. createCache = _dereq_(291);
  34706. /** Used as the size to enable large array optimizations. */
  34707. var LARGE_ARRAY_SIZE = 200;
  34708. /**
  34709. * The base implementation of `_.difference` which accepts a single array
  34710. * of values to exclude.
  34711. *
  34712. * @private
  34713. * @param {Array} array The array to inspect.
  34714. * @param {Array} values The values to exclude.
  34715. * @returns {Array} Returns the new array of filtered values.
  34716. */
  34717. function baseDifference(array, values) {
  34718. var length = array ? array.length : 0,
  34719. result = [];
  34720. if (!length) {
  34721. return result;
  34722. }
  34723. var index = -1,
  34724. indexOf = baseIndexOf,
  34725. isCommon = true,
  34726. cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
  34727. valuesLength = values.length;
  34728. if (cache) {
  34729. indexOf = cacheIndexOf;
  34730. isCommon = false;
  34731. values = cache;
  34732. }
  34733. outer:
  34734. while (++index < length) {
  34735. var value = array[index];
  34736. if (isCommon && value === value) {
  34737. var valuesIndex = valuesLength;
  34738. while (valuesIndex--) {
  34739. if (values[valuesIndex] === value) {
  34740. continue outer;
  34741. }
  34742. }
  34743. result.push(value);
  34744. }
  34745. else if (indexOf(values, value, 0) < 0) {
  34746. result.push(value);
  34747. }
  34748. }
  34749. return result;
  34750. }
  34751. module.exports = baseDifference;
  34752. },{"260":260,"281":281,"291":291}],250:[function(_dereq_,module,exports){
  34753. var baseForOwn = _dereq_(258),
  34754. createBaseEach = _dereq_(288);
  34755. /**
  34756. * The base implementation of `_.forEach` without support for callback
  34757. * shorthands and `this` binding.
  34758. *
  34759. * @private
  34760. * @param {Array|Object|string} collection The collection to iterate over.
  34761. * @param {Function} iteratee The function invoked per iteration.
  34762. * @returns {Array|Object|string} Returns `collection`.
  34763. */
  34764. var baseEach = createBaseEach(baseForOwn);
  34765. module.exports = baseEach;
  34766. },{"258":258,"288":288}],251:[function(_dereq_,module,exports){
  34767. var baseEach = _dereq_(250);
  34768. /**
  34769. * The base implementation of `_.every` without support for callback
  34770. * shorthands and `this` binding.
  34771. *
  34772. * @private
  34773. * @param {Array|Object|string} collection The collection to iterate over.
  34774. * @param {Function} predicate The function invoked per iteration.
  34775. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  34776. * else `false`
  34777. */
  34778. function baseEvery(collection, predicate) {
  34779. var result = true;
  34780. baseEach(collection, function(value, index, collection) {
  34781. result = !!predicate(value, index, collection);
  34782. return result;
  34783. });
  34784. return result;
  34785. }
  34786. module.exports = baseEvery;
  34787. },{"250":250}],252:[function(_dereq_,module,exports){
  34788. var baseEach = _dereq_(250);
  34789. /**
  34790. * The base implementation of `_.filter` without support for callback
  34791. * shorthands and `this` binding.
  34792. *
  34793. * @private
  34794. * @param {Array|Object|string} collection The collection to iterate over.
  34795. * @param {Function} predicate The function invoked per iteration.
  34796. * @returns {Array} Returns the new filtered array.
  34797. */
  34798. function baseFilter(collection, predicate) {
  34799. var result = [];
  34800. baseEach(collection, function(value, index, collection) {
  34801. if (predicate(value, index, collection)) {
  34802. result.push(value);
  34803. }
  34804. });
  34805. return result;
  34806. }
  34807. module.exports = baseFilter;
  34808. },{"250":250}],253:[function(_dereq_,module,exports){
  34809. /**
  34810. * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
  34811. * without support for callback shorthands and `this` binding, which iterates
  34812. * over `collection` using the provided `eachFunc`.
  34813. *
  34814. * @private
  34815. * @param {Array|Object|string} collection The collection to search.
  34816. * @param {Function} predicate The function invoked per iteration.
  34817. * @param {Function} eachFunc The function to iterate over `collection`.
  34818. * @param {boolean} [retKey] Specify returning the key of the found element
  34819. * instead of the element itself.
  34820. * @returns {*} Returns the found element or its key, else `undefined`.
  34821. */
  34822. function baseFind(collection, predicate, eachFunc, retKey) {
  34823. var result;
  34824. eachFunc(collection, function(value, key, collection) {
  34825. if (predicate(value, key, collection)) {
  34826. result = retKey ? key : value;
  34827. return false;
  34828. }
  34829. });
  34830. return result;
  34831. }
  34832. module.exports = baseFind;
  34833. },{}],254:[function(_dereq_,module,exports){
  34834. /**
  34835. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  34836. * support for callback shorthands and `this` binding.
  34837. *
  34838. * @private
  34839. * @param {Array} array The array to search.
  34840. * @param {Function} predicate The function invoked per iteration.
  34841. * @param {boolean} [fromRight] Specify iterating from right to left.
  34842. * @returns {number} Returns the index of the matched value, else `-1`.
  34843. */
  34844. function baseFindIndex(array, predicate, fromRight) {
  34845. var length = array.length,
  34846. index = fromRight ? length : -1;
  34847. while ((fromRight ? index-- : ++index < length)) {
  34848. if (predicate(array[index], index, array)) {
  34849. return index;
  34850. }
  34851. }
  34852. return -1;
  34853. }
  34854. module.exports = baseFindIndex;
  34855. },{}],255:[function(_dereq_,module,exports){
  34856. var arrayPush = _dereq_(239),
  34857. isArguments = _dereq_(329),
  34858. isArray = _dereq_(330),
  34859. isArrayLike = _dereq_(308),
  34860. isObjectLike = _dereq_(314);
  34861. /**
  34862. * The base implementation of `_.flatten` with added support for restricting
  34863. * flattening and specifying the start index.
  34864. *
  34865. * @private
  34866. * @param {Array} array The array to flatten.
  34867. * @param {boolean} [isDeep] Specify a deep flatten.
  34868. * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
  34869. * @param {Array} [result=[]] The initial result value.
  34870. * @returns {Array} Returns the new flattened array.
  34871. */
  34872. function baseFlatten(array, isDeep, isStrict, result) {
  34873. result || (result = []);
  34874. var index = -1,
  34875. length = array.length;
  34876. while (++index < length) {
  34877. var value = array[index];
  34878. if (isObjectLike(value) && isArrayLike(value) &&
  34879. (isStrict || isArray(value) || isArguments(value))) {
  34880. if (isDeep) {
  34881. // Recursively flatten arrays (susceptible to call stack limits).
  34882. baseFlatten(value, isDeep, isStrict, result);
  34883. } else {
  34884. arrayPush(result, value);
  34885. }
  34886. } else if (!isStrict) {
  34887. result[result.length] = value;
  34888. }
  34889. }
  34890. return result;
  34891. }
  34892. module.exports = baseFlatten;
  34893. },{"239":239,"308":308,"314":314,"329":329,"330":330}],256:[function(_dereq_,module,exports){
  34894. var createBaseFor = _dereq_(289);
  34895. /**
  34896. * The base implementation of `baseForIn` and `baseForOwn` which iterates
  34897. * over `object` properties returned by `keysFunc` invoking `iteratee` for
  34898. * each property. Iteratee functions may exit iteration early by explicitly
  34899. * returning `false`.
  34900. *
  34901. * @private
  34902. * @param {Object} object The object to iterate over.
  34903. * @param {Function} iteratee The function invoked per iteration.
  34904. * @param {Function} keysFunc The function to get the keys of `object`.
  34905. * @returns {Object} Returns `object`.
  34906. */
  34907. var baseFor = createBaseFor();
  34908. module.exports = baseFor;
  34909. },{"289":289}],257:[function(_dereq_,module,exports){
  34910. var baseFor = _dereq_(256),
  34911. keysIn = _dereq_(341);
  34912. /**
  34913. * The base implementation of `_.forIn` without support for callback
  34914. * shorthands and `this` binding.
  34915. *
  34916. * @private
  34917. * @param {Object} object The object to iterate over.
  34918. * @param {Function} iteratee The function invoked per iteration.
  34919. * @returns {Object} Returns `object`.
  34920. */
  34921. function baseForIn(object, iteratee) {
  34922. return baseFor(object, iteratee, keysIn);
  34923. }
  34924. module.exports = baseForIn;
  34925. },{"256":256,"341":341}],258:[function(_dereq_,module,exports){
  34926. var baseFor = _dereq_(256),
  34927. keys = _dereq_(340);
  34928. /**
  34929. * The base implementation of `_.forOwn` without support for callback
  34930. * shorthands and `this` binding.
  34931. *
  34932. * @private
  34933. * @param {Object} object The object to iterate over.
  34934. * @param {Function} iteratee The function invoked per iteration.
  34935. * @returns {Object} Returns `object`.
  34936. */
  34937. function baseForOwn(object, iteratee) {
  34938. return baseFor(object, iteratee, keys);
  34939. }
  34940. module.exports = baseForOwn;
  34941. },{"256":256,"340":340}],259:[function(_dereq_,module,exports){
  34942. var toObject = _dereq_(326);
  34943. /**
  34944. * The base implementation of `get` without support for string paths
  34945. * and default values.
  34946. *
  34947. * @private
  34948. * @param {Object} object The object to query.
  34949. * @param {Array} path The path of the property to get.
  34950. * @param {string} [pathKey] The key representation of path.
  34951. * @returns {*} Returns the resolved value.
  34952. */
  34953. function baseGet(object, path, pathKey) {
  34954. if (object == null) {
  34955. return;
  34956. }
  34957. if (pathKey !== undefined && pathKey in toObject(object)) {
  34958. path = [pathKey];
  34959. }
  34960. var index = 0,
  34961. length = path.length;
  34962. while (object != null && index < length) {
  34963. object = object[path[index++]];
  34964. }
  34965. return (index && index == length) ? object : undefined;
  34966. }
  34967. module.exports = baseGet;
  34968. },{"326":326}],260:[function(_dereq_,module,exports){
  34969. var indexOfNaN = _dereq_(307);
  34970. /**
  34971. * The base implementation of `_.indexOf` without support for binary searches.
  34972. *
  34973. * @private
  34974. * @param {Array} array The array to search.
  34975. * @param {*} value The value to search for.
  34976. * @param {number} fromIndex The index to search from.
  34977. * @returns {number} Returns the index of the matched value, else `-1`.
  34978. */
  34979. function baseIndexOf(array, value, fromIndex) {
  34980. if (value !== value) {
  34981. return indexOfNaN(array, fromIndex);
  34982. }
  34983. var index = fromIndex - 1,
  34984. length = array.length;
  34985. while (++index < length) {
  34986. if (array[index] === value) {
  34987. return index;
  34988. }
  34989. }
  34990. return -1;
  34991. }
  34992. module.exports = baseIndexOf;
  34993. },{"307":307}],261:[function(_dereq_,module,exports){
  34994. var baseIsEqualDeep = _dereq_(262),
  34995. isObject = _dereq_(334),
  34996. isObjectLike = _dereq_(314);
  34997. /**
  34998. * The base implementation of `_.isEqual` without support for `this` binding
  34999. * `customizer` functions.
  35000. *
  35001. * @private
  35002. * @param {*} value The value to compare.
  35003. * @param {*} other The other value to compare.
  35004. * @param {Function} [customizer] The function to customize comparing values.
  35005. * @param {boolean} [isLoose] Specify performing partial comparisons.
  35006. * @param {Array} [stackA] Tracks traversed `value` objects.
  35007. * @param {Array} [stackB] Tracks traversed `other` objects.
  35008. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  35009. */
  35010. function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
  35011. if (value === other) {
  35012. return true;
  35013. }
  35014. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  35015. return value !== value && other !== other;
  35016. }
  35017. return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
  35018. }
  35019. module.exports = baseIsEqual;
  35020. },{"262":262,"314":314,"334":334}],262:[function(_dereq_,module,exports){
  35021. var equalArrays = _dereq_(299),
  35022. equalByTag = _dereq_(300),
  35023. equalObjects = _dereq_(301),
  35024. isArray = _dereq_(330),
  35025. isTypedArray = _dereq_(337);
  35026. /** `Object#toString` result references. */
  35027. var argsTag = '[object Arguments]',
  35028. arrayTag = '[object Array]',
  35029. objectTag = '[object Object]';
  35030. /** Used for native method references. */
  35031. var objectProto = Object.prototype;
  35032. /** Used to check objects for own properties. */
  35033. var hasOwnProperty = objectProto.hasOwnProperty;
  35034. /**
  35035. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  35036. * of values.
  35037. */
  35038. var objToString = objectProto.toString;
  35039. /**
  35040. * A specialized version of `baseIsEqual` for arrays and objects which performs
  35041. * deep comparisons and tracks traversed objects enabling objects with circular
  35042. * references to be compared.
  35043. *
  35044. * @private
  35045. * @param {Object} object The object to compare.
  35046. * @param {Object} other The other object to compare.
  35047. * @param {Function} equalFunc The function to determine equivalents of values.
  35048. * @param {Function} [customizer] The function to customize comparing objects.
  35049. * @param {boolean} [isLoose] Specify performing partial comparisons.
  35050. * @param {Array} [stackA=[]] Tracks traversed `value` objects.
  35051. * @param {Array} [stackB=[]] Tracks traversed `other` objects.
  35052. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  35053. */
  35054. function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  35055. var objIsArr = isArray(object),
  35056. othIsArr = isArray(other),
  35057. objTag = arrayTag,
  35058. othTag = arrayTag;
  35059. if (!objIsArr) {
  35060. objTag = objToString.call(object);
  35061. if (objTag == argsTag) {
  35062. objTag = objectTag;
  35063. } else if (objTag != objectTag) {
  35064. objIsArr = isTypedArray(object);
  35065. }
  35066. }
  35067. if (!othIsArr) {
  35068. othTag = objToString.call(other);
  35069. if (othTag == argsTag) {
  35070. othTag = objectTag;
  35071. } else if (othTag != objectTag) {
  35072. othIsArr = isTypedArray(other);
  35073. }
  35074. }
  35075. var objIsObj = objTag == objectTag,
  35076. othIsObj = othTag == objectTag,
  35077. isSameTag = objTag == othTag;
  35078. if (isSameTag && !(objIsArr || objIsObj)) {
  35079. return equalByTag(object, other, objTag);
  35080. }
  35081. if (!isLoose) {
  35082. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  35083. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  35084. if (objIsWrapped || othIsWrapped) {
  35085. return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
  35086. }
  35087. }
  35088. if (!isSameTag) {
  35089. return false;
  35090. }
  35091. // Assume cyclic values are equal.
  35092. // For more information on detecting circular references see https://es5.github.io/#JO.
  35093. stackA || (stackA = []);
  35094. stackB || (stackB = []);
  35095. var length = stackA.length;
  35096. while (length--) {
  35097. if (stackA[length] == object) {
  35098. return stackB[length] == other;
  35099. }
  35100. }
  35101. // Add `object` and `other` to the stack of traversed objects.
  35102. stackA.push(object);
  35103. stackB.push(other);
  35104. var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
  35105. stackA.pop();
  35106. stackB.pop();
  35107. return result;
  35108. }
  35109. module.exports = baseIsEqualDeep;
  35110. },{"299":299,"300":300,"301":301,"330":330,"337":337}],263:[function(_dereq_,module,exports){
  35111. var baseIsEqual = _dereq_(261),
  35112. toObject = _dereq_(326);
  35113. /**
  35114. * The base implementation of `_.isMatch` without support for callback
  35115. * shorthands and `this` binding.
  35116. *
  35117. * @private
  35118. * @param {Object} object The object to inspect.
  35119. * @param {Array} matchData The propery names, values, and compare flags to match.
  35120. * @param {Function} [customizer] The function to customize comparing objects.
  35121. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  35122. */
  35123. function baseIsMatch(object, matchData, customizer) {
  35124. var index = matchData.length,
  35125. length = index,
  35126. noCustomizer = !customizer;
  35127. if (object == null) {
  35128. return !length;
  35129. }
  35130. object = toObject(object);
  35131. while (index--) {
  35132. var data = matchData[index];
  35133. if ((noCustomizer && data[2])
  35134. ? data[1] !== object[data[0]]
  35135. : !(data[0] in object)
  35136. ) {
  35137. return false;
  35138. }
  35139. }
  35140. while (++index < length) {
  35141. data = matchData[index];
  35142. var key = data[0],
  35143. objValue = object[key],
  35144. srcValue = data[1];
  35145. if (noCustomizer && data[2]) {
  35146. if (objValue === undefined && !(key in object)) {
  35147. return false;
  35148. }
  35149. } else {
  35150. var result = customizer ? customizer(objValue, srcValue, key) : undefined;
  35151. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
  35152. return false;
  35153. }
  35154. }
  35155. }
  35156. return true;
  35157. }
  35158. module.exports = baseIsMatch;
  35159. },{"261":261,"326":326}],264:[function(_dereq_,module,exports){
  35160. /**
  35161. * The function whose prototype all chaining wrappers inherit from.
  35162. *
  35163. * @private
  35164. */
  35165. function baseLodash() {
  35166. // No operation performed.
  35167. }
  35168. module.exports = baseLodash;
  35169. },{}],265:[function(_dereq_,module,exports){
  35170. var baseEach = _dereq_(250),
  35171. isArrayLike = _dereq_(308);
  35172. /**
  35173. * The base implementation of `_.map` without support for callback shorthands
  35174. * and `this` binding.
  35175. *
  35176. * @private
  35177. * @param {Array|Object|string} collection The collection to iterate over.
  35178. * @param {Function} iteratee The function invoked per iteration.
  35179. * @returns {Array} Returns the new mapped array.
  35180. */
  35181. function baseMap(collection, iteratee) {
  35182. var index = -1,
  35183. result = isArrayLike(collection) ? Array(collection.length) : [];
  35184. baseEach(collection, function(value, key, collection) {
  35185. result[++index] = iteratee(value, key, collection);
  35186. });
  35187. return result;
  35188. }
  35189. module.exports = baseMap;
  35190. },{"250":250,"308":308}],266:[function(_dereq_,module,exports){
  35191. var baseIsMatch = _dereq_(263),
  35192. getMatchData = _dereq_(305),
  35193. toObject = _dereq_(326);
  35194. /**
  35195. * The base implementation of `_.matches` which does not clone `source`.
  35196. *
  35197. * @private
  35198. * @param {Object} source The object of property values to match.
  35199. * @returns {Function} Returns the new function.
  35200. */
  35201. function baseMatches(source) {
  35202. var matchData = getMatchData(source);
  35203. if (matchData.length == 1 && matchData[0][2]) {
  35204. var key = matchData[0][0],
  35205. value = matchData[0][1];
  35206. return function(object) {
  35207. if (object == null) {
  35208. return false;
  35209. }
  35210. return object[key] === value && (value !== undefined || (key in toObject(object)));
  35211. };
  35212. }
  35213. return function(object) {
  35214. return baseIsMatch(object, matchData);
  35215. };
  35216. }
  35217. module.exports = baseMatches;
  35218. },{"263":263,"305":305,"326":326}],267:[function(_dereq_,module,exports){
  35219. var baseGet = _dereq_(259),
  35220. baseIsEqual = _dereq_(261),
  35221. baseSlice = _dereq_(274),
  35222. isArray = _dereq_(330),
  35223. isKey = _dereq_(311),
  35224. isStrictComparable = _dereq_(315),
  35225. last = _dereq_(209),
  35226. toObject = _dereq_(326),
  35227. toPath = _dereq_(327);
  35228. /**
  35229. * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
  35230. *
  35231. * @private
  35232. * @param {string} path The path of the property to get.
  35233. * @param {*} srcValue The value to compare.
  35234. * @returns {Function} Returns the new function.
  35235. */
  35236. function baseMatchesProperty(path, srcValue) {
  35237. var isArr = isArray(path),
  35238. isCommon = isKey(path) && isStrictComparable(srcValue),
  35239. pathKey = (path + '');
  35240. path = toPath(path);
  35241. return function(object) {
  35242. if (object == null) {
  35243. return false;
  35244. }
  35245. var key = pathKey;
  35246. object = toObject(object);
  35247. if ((isArr || !isCommon) && !(key in object)) {
  35248. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  35249. if (object == null) {
  35250. return false;
  35251. }
  35252. key = last(path);
  35253. object = toObject(object);
  35254. }
  35255. return object[key] === srcValue
  35256. ? (srcValue !== undefined || (key in object))
  35257. : baseIsEqual(srcValue, object[key], undefined, true);
  35258. };
  35259. }
  35260. module.exports = baseMatchesProperty;
  35261. },{"209":209,"259":259,"261":261,"274":274,"311":311,"315":315,"326":326,"327":327,"330":330}],268:[function(_dereq_,module,exports){
  35262. var arrayEach = _dereq_(235),
  35263. baseMergeDeep = _dereq_(269),
  35264. isArray = _dereq_(330),
  35265. isArrayLike = _dereq_(308),
  35266. isObject = _dereq_(334),
  35267. isObjectLike = _dereq_(314),
  35268. isTypedArray = _dereq_(337),
  35269. keys = _dereq_(340);
  35270. /**
  35271. * The base implementation of `_.merge` without support for argument juggling,
  35272. * multiple sources, and `this` binding `customizer` functions.
  35273. *
  35274. * @private
  35275. * @param {Object} object The destination object.
  35276. * @param {Object} source The source object.
  35277. * @param {Function} [customizer] The function to customize merged values.
  35278. * @param {Array} [stackA=[]] Tracks traversed source objects.
  35279. * @param {Array} [stackB=[]] Associates values with source counterparts.
  35280. * @returns {Object} Returns `object`.
  35281. */
  35282. function baseMerge(object, source, customizer, stackA, stackB) {
  35283. if (!isObject(object)) {
  35284. return object;
  35285. }
  35286. var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
  35287. props = isSrcArr ? undefined : keys(source);
  35288. arrayEach(props || source, function(srcValue, key) {
  35289. if (props) {
  35290. key = srcValue;
  35291. srcValue = source[key];
  35292. }
  35293. if (isObjectLike(srcValue)) {
  35294. stackA || (stackA = []);
  35295. stackB || (stackB = []);
  35296. baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
  35297. }
  35298. else {
  35299. var value = object[key],
  35300. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  35301. isCommon = result === undefined;
  35302. if (isCommon) {
  35303. result = srcValue;
  35304. }
  35305. if ((result !== undefined || (isSrcArr && !(key in object))) &&
  35306. (isCommon || (result === result ? (result !== value) : (value === value)))) {
  35307. object[key] = result;
  35308. }
  35309. }
  35310. });
  35311. return object;
  35312. }
  35313. module.exports = baseMerge;
  35314. },{"235":235,"269":269,"308":308,"314":314,"330":330,"334":334,"337":337,"340":340}],269:[function(_dereq_,module,exports){
  35315. var arrayCopy = _dereq_(234),
  35316. isArguments = _dereq_(329),
  35317. isArray = _dereq_(330),
  35318. isArrayLike = _dereq_(308),
  35319. isPlainObject = _dereq_(335),
  35320. isTypedArray = _dereq_(337),
  35321. toPlainObject = _dereq_(338);
  35322. /**
  35323. * A specialized version of `baseMerge` for arrays and objects which performs
  35324. * deep merges and tracks traversed objects enabling objects with circular
  35325. * references to be merged.
  35326. *
  35327. * @private
  35328. * @param {Object} object The destination object.
  35329. * @param {Object} source The source object.
  35330. * @param {string} key The key of the value to merge.
  35331. * @param {Function} mergeFunc The function to merge values.
  35332. * @param {Function} [customizer] The function to customize merged values.
  35333. * @param {Array} [stackA=[]] Tracks traversed source objects.
  35334. * @param {Array} [stackB=[]] Associates values with source counterparts.
  35335. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  35336. */
  35337. function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
  35338. var length = stackA.length,
  35339. srcValue = source[key];
  35340. while (length--) {
  35341. if (stackA[length] == srcValue) {
  35342. object[key] = stackB[length];
  35343. return;
  35344. }
  35345. }
  35346. var value = object[key],
  35347. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  35348. isCommon = result === undefined;
  35349. if (isCommon) {
  35350. result = srcValue;
  35351. if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
  35352. result = isArray(value)
  35353. ? value
  35354. : (isArrayLike(value) ? arrayCopy(value) : []);
  35355. }
  35356. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  35357. result = isArguments(value)
  35358. ? toPlainObject(value)
  35359. : (isPlainObject(value) ? value : {});
  35360. }
  35361. else {
  35362. isCommon = false;
  35363. }
  35364. }
  35365. // Add the source value to the stack of traversed objects and associate
  35366. // it with its merged value.
  35367. stackA.push(srcValue);
  35368. stackB.push(result);
  35369. if (isCommon) {
  35370. // Recursively merge objects and arrays (susceptible to call stack limits).
  35371. object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
  35372. } else if (result === result ? (result !== value) : (value === value)) {
  35373. object[key] = result;
  35374. }
  35375. }
  35376. module.exports = baseMergeDeep;
  35377. },{"234":234,"308":308,"329":329,"330":330,"335":335,"337":337,"338":338}],270:[function(_dereq_,module,exports){
  35378. /**
  35379. * The base implementation of `_.property` without support for deep paths.
  35380. *
  35381. * @private
  35382. * @param {string} key The key of the property to get.
  35383. * @returns {Function} Returns the new function.
  35384. */
  35385. function baseProperty(key) {
  35386. return function(object) {
  35387. return object == null ? undefined : object[key];
  35388. };
  35389. }
  35390. module.exports = baseProperty;
  35391. },{}],271:[function(_dereq_,module,exports){
  35392. var baseGet = _dereq_(259),
  35393. toPath = _dereq_(327);
  35394. /**
  35395. * A specialized version of `baseProperty` which supports deep paths.
  35396. *
  35397. * @private
  35398. * @param {Array|string} path The path of the property to get.
  35399. * @returns {Function} Returns the new function.
  35400. */
  35401. function basePropertyDeep(path) {
  35402. var pathKey = (path + '');
  35403. path = toPath(path);
  35404. return function(object) {
  35405. return baseGet(object, path, pathKey);
  35406. };
  35407. }
  35408. module.exports = basePropertyDeep;
  35409. },{"259":259,"327":327}],272:[function(_dereq_,module,exports){
  35410. /**
  35411. * The base implementation of `_.reduce` and `_.reduceRight` without support
  35412. * for callback shorthands and `this` binding, which iterates over `collection`
  35413. * using the provided `eachFunc`.
  35414. *
  35415. * @private
  35416. * @param {Array|Object|string} collection The collection to iterate over.
  35417. * @param {Function} iteratee The function invoked per iteration.
  35418. * @param {*} accumulator The initial value.
  35419. * @param {boolean} initFromCollection Specify using the first or last element
  35420. * of `collection` as the initial value.
  35421. * @param {Function} eachFunc The function to iterate over `collection`.
  35422. * @returns {*} Returns the accumulated value.
  35423. */
  35424. function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
  35425. eachFunc(collection, function(value, index, collection) {
  35426. accumulator = initFromCollection
  35427. ? (initFromCollection = false, value)
  35428. : iteratee(accumulator, value, index, collection);
  35429. });
  35430. return accumulator;
  35431. }
  35432. module.exports = baseReduce;
  35433. },{}],273:[function(_dereq_,module,exports){
  35434. var identity = _dereq_(348),
  35435. metaMap = _dereq_(317);
  35436. /**
  35437. * The base implementation of `setData` without support for hot loop detection.
  35438. *
  35439. * @private
  35440. * @param {Function} func The function to associate metadata with.
  35441. * @param {*} data The metadata.
  35442. * @returns {Function} Returns `func`.
  35443. */
  35444. var baseSetData = !metaMap ? identity : function(func, data) {
  35445. metaMap.set(func, data);
  35446. return func;
  35447. };
  35448. module.exports = baseSetData;
  35449. },{"317":317,"348":348}],274:[function(_dereq_,module,exports){
  35450. /**
  35451. * The base implementation of `_.slice` without an iteratee call guard.
  35452. *
  35453. * @private
  35454. * @param {Array} array The array to slice.
  35455. * @param {number} [start=0] The start position.
  35456. * @param {number} [end=array.length] The end position.
  35457. * @returns {Array} Returns the slice of `array`.
  35458. */
  35459. function baseSlice(array, start, end) {
  35460. var index = -1,
  35461. length = array.length;
  35462. start = start == null ? 0 : (+start || 0);
  35463. if (start < 0) {
  35464. start = -start > length ? 0 : (length + start);
  35465. }
  35466. end = (end === undefined || end > length) ? length : (+end || 0);
  35467. if (end < 0) {
  35468. end += length;
  35469. }
  35470. length = start > end ? 0 : ((end - start) >>> 0);
  35471. start >>>= 0;
  35472. var result = Array(length);
  35473. while (++index < length) {
  35474. result[index] = array[index + start];
  35475. }
  35476. return result;
  35477. }
  35478. module.exports = baseSlice;
  35479. },{}],275:[function(_dereq_,module,exports){
  35480. var baseEach = _dereq_(250);
  35481. /**
  35482. * The base implementation of `_.some` without support for callback shorthands
  35483. * and `this` binding.
  35484. *
  35485. * @private
  35486. * @param {Array|Object|string} collection The collection to iterate over.
  35487. * @param {Function} predicate The function invoked per iteration.
  35488. * @returns {boolean} Returns `true` if any element passes the predicate check,
  35489. * else `false`.
  35490. */
  35491. function baseSome(collection, predicate) {
  35492. var result;
  35493. baseEach(collection, function(value, index, collection) {
  35494. result = predicate(value, index, collection);
  35495. return !result;
  35496. });
  35497. return !!result;
  35498. }
  35499. module.exports = baseSome;
  35500. },{"250":250}],276:[function(_dereq_,module,exports){
  35501. /**
  35502. * The base implementation of `_.sortBy` which uses `comparer` to define
  35503. * the sort order of `array` and replaces criteria objects with their
  35504. * corresponding values.
  35505. *
  35506. * @private
  35507. * @param {Array} array The array to sort.
  35508. * @param {Function} comparer The function to define sort order.
  35509. * @returns {Array} Returns `array`.
  35510. */
  35511. function baseSortBy(array, comparer) {
  35512. var length = array.length;
  35513. array.sort(comparer);
  35514. while (length--) {
  35515. array[length] = array[length].value;
  35516. }
  35517. return array;
  35518. }
  35519. module.exports = baseSortBy;
  35520. },{}],277:[function(_dereq_,module,exports){
  35521. /**
  35522. * Converts `value` to a string if it's not one. An empty string is returned
  35523. * for `null` or `undefined` values.
  35524. *
  35525. * @private
  35526. * @param {*} value The value to process.
  35527. * @returns {string} Returns the string.
  35528. */
  35529. function baseToString(value) {
  35530. return value == null ? '' : (value + '');
  35531. }
  35532. module.exports = baseToString;
  35533. },{}],278:[function(_dereq_,module,exports){
  35534. var baseIndexOf = _dereq_(260),
  35535. cacheIndexOf = _dereq_(281),
  35536. createCache = _dereq_(291);
  35537. /** Used as the size to enable large array optimizations. */
  35538. var LARGE_ARRAY_SIZE = 200;
  35539. /**
  35540. * The base implementation of `_.uniq` without support for callback shorthands
  35541. * and `this` binding.
  35542. *
  35543. * @private
  35544. * @param {Array} array The array to inspect.
  35545. * @param {Function} [iteratee] The function invoked per iteration.
  35546. * @returns {Array} Returns the new duplicate free array.
  35547. */
  35548. function baseUniq(array, iteratee) {
  35549. var index = -1,
  35550. indexOf = baseIndexOf,
  35551. length = array.length,
  35552. isCommon = true,
  35553. isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
  35554. seen = isLarge ? createCache() : null,
  35555. result = [];
  35556. if (seen) {
  35557. indexOf = cacheIndexOf;
  35558. isCommon = false;
  35559. } else {
  35560. isLarge = false;
  35561. seen = iteratee ? [] : result;
  35562. }
  35563. outer:
  35564. while (++index < length) {
  35565. var value = array[index],
  35566. computed = iteratee ? iteratee(value, index, array) : value;
  35567. if (isCommon && value === value) {
  35568. var seenIndex = seen.length;
  35569. while (seenIndex--) {
  35570. if (seen[seenIndex] === computed) {
  35571. continue outer;
  35572. }
  35573. }
  35574. if (iteratee) {
  35575. seen.push(computed);
  35576. }
  35577. result.push(value);
  35578. }
  35579. else if (indexOf(seen, computed, 0) < 0) {
  35580. if (iteratee || isLarge) {
  35581. seen.push(computed);
  35582. }
  35583. result.push(value);
  35584. }
  35585. }
  35586. return result;
  35587. }
  35588. module.exports = baseUniq;
  35589. },{"260":260,"281":281,"291":291}],279:[function(_dereq_,module,exports){
  35590. /**
  35591. * The base implementation of `_.values` and `_.valuesIn` which creates an
  35592. * array of `object` property values corresponding to the property names
  35593. * of `props`.
  35594. *
  35595. * @private
  35596. * @param {Object} object The object to query.
  35597. * @param {Array} props The property names to get values for.
  35598. * @returns {Object} Returns the array of property values.
  35599. */
  35600. function baseValues(object, props) {
  35601. var index = -1,
  35602. length = props.length,
  35603. result = Array(length);
  35604. while (++index < length) {
  35605. result[index] = object[props[index]];
  35606. }
  35607. return result;
  35608. }
  35609. module.exports = baseValues;
  35610. },{}],280:[function(_dereq_,module,exports){
  35611. var identity = _dereq_(348);
  35612. /**
  35613. * A specialized version of `baseCallback` which only supports `this` binding
  35614. * and specifying the number of arguments to provide to `func`.
  35615. *
  35616. * @private
  35617. * @param {Function} func The function to bind.
  35618. * @param {*} thisArg The `this` binding of `func`.
  35619. * @param {number} [argCount] The number of arguments to provide to `func`.
  35620. * @returns {Function} Returns the callback.
  35621. */
  35622. function bindCallback(func, thisArg, argCount) {
  35623. if (typeof func != 'function') {
  35624. return identity;
  35625. }
  35626. if (thisArg === undefined) {
  35627. return func;
  35628. }
  35629. switch (argCount) {
  35630. case 1: return function(value) {
  35631. return func.call(thisArg, value);
  35632. };
  35633. case 3: return function(value, index, collection) {
  35634. return func.call(thisArg, value, index, collection);
  35635. };
  35636. case 4: return function(accumulator, value, index, collection) {
  35637. return func.call(thisArg, accumulator, value, index, collection);
  35638. };
  35639. case 5: return function(value, other, key, object, source) {
  35640. return func.call(thisArg, value, other, key, object, source);
  35641. };
  35642. }
  35643. return function() {
  35644. return func.apply(thisArg, arguments);
  35645. };
  35646. }
  35647. module.exports = bindCallback;
  35648. },{"348":348}],281:[function(_dereq_,module,exports){
  35649. var isObject = _dereq_(334);
  35650. /**
  35651. * Checks if `value` is in `cache` mimicking the return signature of
  35652. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  35653. *
  35654. * @private
  35655. * @param {Object} cache The cache to search.
  35656. * @param {*} value The value to search for.
  35657. * @returns {number} Returns `0` if `value` is found, else `-1`.
  35658. */
  35659. function cacheIndexOf(cache, value) {
  35660. var data = cache.data,
  35661. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  35662. return result ? 0 : -1;
  35663. }
  35664. module.exports = cacheIndexOf;
  35665. },{"334":334}],282:[function(_dereq_,module,exports){
  35666. var isObject = _dereq_(334);
  35667. /**
  35668. * Adds `value` to the cache.
  35669. *
  35670. * @private
  35671. * @name push
  35672. * @memberOf SetCache
  35673. * @param {*} value The value to cache.
  35674. */
  35675. function cachePush(value) {
  35676. var data = this.data;
  35677. if (typeof value == 'string' || isObject(value)) {
  35678. data.set.add(value);
  35679. } else {
  35680. data.hash[value] = true;
  35681. }
  35682. }
  35683. module.exports = cachePush;
  35684. },{"334":334}],283:[function(_dereq_,module,exports){
  35685. var baseCompareAscending = _dereq_(245);
  35686. /**
  35687. * Used by `_.sortBy` to compare transformed elements of a collection and stable
  35688. * sort them in ascending order.
  35689. *
  35690. * @private
  35691. * @param {Object} object The object to compare.
  35692. * @param {Object} other The other object to compare.
  35693. * @returns {number} Returns the sort order indicator for `object`.
  35694. */
  35695. function compareAscending(object, other) {
  35696. return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
  35697. }
  35698. module.exports = compareAscending;
  35699. },{"245":245}],284:[function(_dereq_,module,exports){
  35700. /* Native method references for those with the same name as other `lodash` methods. */
  35701. var nativeMax = Math.max;
  35702. /**
  35703. * Creates an array that is the composition of partially applied arguments,
  35704. * placeholders, and provided arguments into a single array of arguments.
  35705. *
  35706. * @private
  35707. * @param {Array|Object} args The provided arguments.
  35708. * @param {Array} partials The arguments to prepend to those provided.
  35709. * @param {Array} holders The `partials` placeholder indexes.
  35710. * @returns {Array} Returns the new array of composed arguments.
  35711. */
  35712. function composeArgs(args, partials, holders) {
  35713. var holdersLength = holders.length,
  35714. argsIndex = -1,
  35715. argsLength = nativeMax(args.length - holdersLength, 0),
  35716. leftIndex = -1,
  35717. leftLength = partials.length,
  35718. result = Array(leftLength + argsLength);
  35719. while (++leftIndex < leftLength) {
  35720. result[leftIndex] = partials[leftIndex];
  35721. }
  35722. while (++argsIndex < holdersLength) {
  35723. result[holders[argsIndex]] = args[argsIndex];
  35724. }
  35725. while (argsLength--) {
  35726. result[leftIndex++] = args[argsIndex++];
  35727. }
  35728. return result;
  35729. }
  35730. module.exports = composeArgs;
  35731. },{}],285:[function(_dereq_,module,exports){
  35732. /* Native method references for those with the same name as other `lodash` methods. */
  35733. var nativeMax = Math.max;
  35734. /**
  35735. * This function is like `composeArgs` except that the arguments composition
  35736. * is tailored for `_.partialRight`.
  35737. *
  35738. * @private
  35739. * @param {Array|Object} args The provided arguments.
  35740. * @param {Array} partials The arguments to append to those provided.
  35741. * @param {Array} holders The `partials` placeholder indexes.
  35742. * @returns {Array} Returns the new array of composed arguments.
  35743. */
  35744. function composeArgsRight(args, partials, holders) {
  35745. var holdersIndex = -1,
  35746. holdersLength = holders.length,
  35747. argsIndex = -1,
  35748. argsLength = nativeMax(args.length - holdersLength, 0),
  35749. rightIndex = -1,
  35750. rightLength = partials.length,
  35751. result = Array(argsLength + rightLength);
  35752. while (++argsIndex < argsLength) {
  35753. result[argsIndex] = args[argsIndex];
  35754. }
  35755. var offset = argsIndex;
  35756. while (++rightIndex < rightLength) {
  35757. result[offset + rightIndex] = partials[rightIndex];
  35758. }
  35759. while (++holdersIndex < holdersLength) {
  35760. result[offset + holders[holdersIndex]] = args[argsIndex++];
  35761. }
  35762. return result;
  35763. }
  35764. module.exports = composeArgsRight;
  35765. },{}],286:[function(_dereq_,module,exports){
  35766. var baseCallback = _dereq_(244),
  35767. baseEach = _dereq_(250),
  35768. isArray = _dereq_(330);
  35769. /**
  35770. * Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
  35771. *
  35772. * @private
  35773. * @param {Function} setter The function to set keys and values of the accumulator object.
  35774. * @param {Function} [initializer] The function to initialize the accumulator object.
  35775. * @returns {Function} Returns the new aggregator function.
  35776. */
  35777. function createAggregator(setter, initializer) {
  35778. return function(collection, iteratee, thisArg) {
  35779. var result = initializer ? initializer() : {};
  35780. iteratee = baseCallback(iteratee, thisArg, 3);
  35781. if (isArray(collection)) {
  35782. var index = -1,
  35783. length = collection.length;
  35784. while (++index < length) {
  35785. var value = collection[index];
  35786. setter(result, value, iteratee(value, index, collection), collection);
  35787. }
  35788. } else {
  35789. baseEach(collection, function(value, key, collection) {
  35790. setter(result, value, iteratee(value, key, collection), collection);
  35791. });
  35792. }
  35793. return result;
  35794. };
  35795. }
  35796. module.exports = createAggregator;
  35797. },{"244":244,"250":250,"330":330}],287:[function(_dereq_,module,exports){
  35798. var bindCallback = _dereq_(280),
  35799. isIterateeCall = _dereq_(310),
  35800. restParam = _dereq_(230);
  35801. /**
  35802. * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
  35803. *
  35804. * @private
  35805. * @param {Function} assigner The function to assign values.
  35806. * @returns {Function} Returns the new assigner function.
  35807. */
  35808. function createAssigner(assigner) {
  35809. return restParam(function(object, sources) {
  35810. var index = -1,
  35811. length = object == null ? 0 : sources.length,
  35812. customizer = length > 2 ? sources[length - 2] : undefined,
  35813. guard = length > 2 ? sources[2] : undefined,
  35814. thisArg = length > 1 ? sources[length - 1] : undefined;
  35815. if (typeof customizer == 'function') {
  35816. customizer = bindCallback(customizer, thisArg, 5);
  35817. length -= 2;
  35818. } else {
  35819. customizer = typeof thisArg == 'function' ? thisArg : undefined;
  35820. length -= (customizer ? 1 : 0);
  35821. }
  35822. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  35823. customizer = length < 3 ? undefined : customizer;
  35824. length = 1;
  35825. }
  35826. while (++index < length) {
  35827. var source = sources[index];
  35828. if (source) {
  35829. assigner(object, source, customizer);
  35830. }
  35831. }
  35832. return object;
  35833. });
  35834. }
  35835. module.exports = createAssigner;
  35836. },{"230":230,"280":280,"310":310}],288:[function(_dereq_,module,exports){
  35837. var getLength = _dereq_(304),
  35838. isLength = _dereq_(313),
  35839. toObject = _dereq_(326);
  35840. /**
  35841. * Creates a `baseEach` or `baseEachRight` function.
  35842. *
  35843. * @private
  35844. * @param {Function} eachFunc The function to iterate over a collection.
  35845. * @param {boolean} [fromRight] Specify iterating from right to left.
  35846. * @returns {Function} Returns the new base function.
  35847. */
  35848. function createBaseEach(eachFunc, fromRight) {
  35849. return function(collection, iteratee) {
  35850. var length = collection ? getLength(collection) : 0;
  35851. if (!isLength(length)) {
  35852. return eachFunc(collection, iteratee);
  35853. }
  35854. var index = fromRight ? length : -1,
  35855. iterable = toObject(collection);
  35856. while ((fromRight ? index-- : ++index < length)) {
  35857. if (iteratee(iterable[index], index, iterable) === false) {
  35858. break;
  35859. }
  35860. }
  35861. return collection;
  35862. };
  35863. }
  35864. module.exports = createBaseEach;
  35865. },{"304":304,"313":313,"326":326}],289:[function(_dereq_,module,exports){
  35866. var toObject = _dereq_(326);
  35867. /**
  35868. * Creates a base function for `_.forIn` or `_.forInRight`.
  35869. *
  35870. * @private
  35871. * @param {boolean} [fromRight] Specify iterating from right to left.
  35872. * @returns {Function} Returns the new base function.
  35873. */
  35874. function createBaseFor(fromRight) {
  35875. return function(object, iteratee, keysFunc) {
  35876. var iterable = toObject(object),
  35877. props = keysFunc(object),
  35878. length = props.length,
  35879. index = fromRight ? length : -1;
  35880. while ((fromRight ? index-- : ++index < length)) {
  35881. var key = props[index];
  35882. if (iteratee(iterable[key], key, iterable) === false) {
  35883. break;
  35884. }
  35885. }
  35886. return object;
  35887. };
  35888. }
  35889. module.exports = createBaseFor;
  35890. },{"326":326}],290:[function(_dereq_,module,exports){
  35891. (function (global){
  35892. var createCtorWrapper = _dereq_(292);
  35893. /**
  35894. * Creates a function that wraps `func` and invokes it with the `this`
  35895. * binding of `thisArg`.
  35896. *
  35897. * @private
  35898. * @param {Function} func The function to bind.
  35899. * @param {*} [thisArg] The `this` binding of `func`.
  35900. * @returns {Function} Returns the new bound function.
  35901. */
  35902. function createBindWrapper(func, thisArg) {
  35903. var Ctor = createCtorWrapper(func);
  35904. function wrapper() {
  35905. var fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
  35906. return fn.apply(thisArg, arguments);
  35907. }
  35908. return wrapper;
  35909. }
  35910. module.exports = createBindWrapper;
  35911. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  35912. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9sb2Rhc2gvaW50ZXJuYWwvY3JlYXRlQmluZFdyYXBwZXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXNDb250ZW50IjpbInZhciBjcmVhdGVDdG9yV3JhcHBlciA9IHJlcXVpcmUoJy4vY3JlYXRlQ3RvcldyYXBwZXInKTtcblxuLyoqXG4gKiBDcmVhdGVzIGEgZnVuY3Rpb24gdGhhdCB3cmFwcyBgZnVuY2AgYW5kIGludm9rZXMgaXQgd2l0aCB0aGUgYHRoaXNgXG4gKiBiaW5kaW5nIG9mIGB0aGlzQXJnYC5cbiAqXG4gKiBAcHJpdmF0ZVxuICogQHBhcmFtIHtGdW5jdGlvbn0gZnVuYyBUaGUgZnVuY3Rpb24gdG8gYmluZC5cbiAqIEBwYXJhbSB7Kn0gW3RoaXNBcmddIFRoZSBgdGhpc2AgYmluZGluZyBvZiBgZnVuY2AuXG4gKiBAcmV0dXJucyB7RnVuY3Rpb259IFJldHVybnMgdGhlIG5ldyBib3VuZCBmdW5jdGlvbi5cbiAqL1xuZnVuY3Rpb24gY3JlYXRlQmluZFdyYXBwZXIoZnVuYywgdGhpc0FyZykge1xuICB2YXIgQ3RvciA9IGNyZWF0ZUN0b3JXcmFwcGVyKGZ1bmMpO1xuXG4gIGZ1bmN0aW9uIHdyYXBwZXIoKSB7XG4gICAgdmFyIGZuID0gKHRoaXMgJiYgdGhpcyAhPT0gZ2xvYmFsICYmIHRoaXMgaW5zdGFuY2VvZiB3cmFwcGVyKSA/IEN0b3IgOiBmdW5jO1xuICAgIHJldHVybiBmbi5hcHBseSh0aGlzQXJnLCBhcmd1bWVudHMpO1xuICB9XG4gIHJldHVybiB3cmFwcGVyO1xufVxuXG5tb2R1bGUuZXhwb3J0cyA9IGNyZWF0ZUJpbmRXcmFwcGVyO1xuIl19
  35913. },{"292":292}],291:[function(_dereq_,module,exports){
  35914. (function (global){
  35915. var SetCache = _dereq_(233),
  35916. getNative = _dereq_(306);
  35917. /** Native method references. */
  35918. var Set = getNative(global, 'Set');
  35919. /* Native method references for those with the same name as other `lodash` methods. */
  35920. var nativeCreate = getNative(Object, 'create');
  35921. /**
  35922. * Creates a `Set` cache object to optimize linear searches of large arrays.
  35923. *
  35924. * @private
  35925. * @param {Array} [values] The values to cache.
  35926. * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
  35927. */
  35928. function createCache(values) {
  35929. return (nativeCreate && Set) ? new SetCache(values) : null;
  35930. }
  35931. module.exports = createCache;
  35932. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  35933. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9sb2Rhc2gvaW50ZXJuYWwvY3JlYXRlQ2FjaGUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6ImdlbmVyYXRlZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgU2V0Q2FjaGUgPSByZXF1aXJlKCcuL1NldENhY2hlJyksXG4gICAgZ2V0TmF0aXZlID0gcmVxdWlyZSgnLi9nZXROYXRpdmUnKTtcblxuLyoqIE5hdGl2ZSBtZXRob2QgcmVmZXJlbmNlcy4gKi9cbnZhciBTZXQgPSBnZXROYXRpdmUoZ2xvYmFsLCAnU2V0Jyk7XG5cbi8qIE5hdGl2ZSBtZXRob2QgcmVmZXJlbmNlcyBmb3IgdGhvc2Ugd2l0aCB0aGUgc2FtZSBuYW1lIGFzIG90aGVyIGBsb2Rhc2hgIG1ldGhvZHMuICovXG52YXIgbmF0aXZlQ3JlYXRlID0gZ2V0TmF0aXZlKE9iamVjdCwgJ2NyZWF0ZScpO1xuXG4vKipcbiAqIENyZWF0ZXMgYSBgU2V0YCBjYWNoZSBvYmplY3QgdG8gb3B0aW1pemUgbGluZWFyIHNlYXJjaGVzIG9mIGxhcmdlIGFycmF5cy5cbiAqXG4gKiBAcHJpdmF0ZVxuICogQHBhcmFtIHtBcnJheX0gW3ZhbHVlc10gVGhlIHZhbHVlcyB0byBjYWNoZS5cbiAqIEByZXR1cm5zIHtudWxsfE9iamVjdH0gUmV0dXJucyB0aGUgbmV3IGNhY2hlIG9iamVjdCBpZiBgU2V0YCBpcyBzdXBwb3J0ZWQsIGVsc2UgYG51bGxgLlxuICovXG5mdW5jdGlvbiBjcmVhdGVDYWNoZSh2YWx1ZXMpIHtcbiAgcmV0dXJuIChuYXRpdmVDcmVhdGUgJiYgU2V0KSA/IG5ldyBTZXRDYWNoZSh2YWx1ZXMpIDogbnVsbDtcbn1cblxubW9kdWxlLmV4cG9ydHMgPSBjcmVhdGVDYWNoZTtcbiJdfQ==
  35934. },{"233":233,"306":306}],292:[function(_dereq_,module,exports){
  35935. var baseCreate = _dereq_(247),
  35936. isObject = _dereq_(334);
  35937. /**
  35938. * Creates a function that produces an instance of `Ctor` regardless of
  35939. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  35940. *
  35941. * @private
  35942. * @param {Function} Ctor The constructor to wrap.
  35943. * @returns {Function} Returns the new wrapped function.
  35944. */
  35945. function createCtorWrapper(Ctor) {
  35946. return function() {
  35947. // Use a `switch` statement to work with class constructors.
  35948. // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  35949. // for more details.
  35950. var args = arguments;
  35951. switch (args.length) {
  35952. case 0: return new Ctor;
  35953. case 1: return new Ctor(args[0]);
  35954. case 2: return new Ctor(args[0], args[1]);
  35955. case 3: return new Ctor(args[0], args[1], args[2]);
  35956. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  35957. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  35958. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  35959. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  35960. }
  35961. var thisBinding = baseCreate(Ctor.prototype),
  35962. result = Ctor.apply(thisBinding, args);
  35963. // Mimic the constructor's `return` behavior.
  35964. // See https://es5.github.io/#x13.2.2 for more details.
  35965. return isObject(result) ? result : thisBinding;
  35966. };
  35967. }
  35968. module.exports = createCtorWrapper;
  35969. },{"247":247,"334":334}],293:[function(_dereq_,module,exports){
  35970. var baseCallback = _dereq_(244),
  35971. baseFind = _dereq_(253),
  35972. baseFindIndex = _dereq_(254),
  35973. isArray = _dereq_(330);
  35974. /**
  35975. * Creates a `_.find` or `_.findLast` function.
  35976. *
  35977. * @private
  35978. * @param {Function} eachFunc The function to iterate over a collection.
  35979. * @param {boolean} [fromRight] Specify iterating from right to left.
  35980. * @returns {Function} Returns the new find function.
  35981. */
  35982. function createFind(eachFunc, fromRight) {
  35983. return function(collection, predicate, thisArg) {
  35984. predicate = baseCallback(predicate, thisArg, 3);
  35985. if (isArray(collection)) {
  35986. var index = baseFindIndex(collection, predicate, fromRight);
  35987. return index > -1 ? collection[index] : undefined;
  35988. }
  35989. return baseFind(collection, predicate, eachFunc);
  35990. };
  35991. }
  35992. module.exports = createFind;
  35993. },{"244":244,"253":253,"254":254,"330":330}],294:[function(_dereq_,module,exports){
  35994. var bindCallback = _dereq_(280),
  35995. isArray = _dereq_(330);
  35996. /**
  35997. * Creates a function for `_.forEach` or `_.forEachRight`.
  35998. *
  35999. * @private
  36000. * @param {Function} arrayFunc The function to iterate over an array.
  36001. * @param {Function} eachFunc The function to iterate over a collection.
  36002. * @returns {Function} Returns the new each function.
  36003. */
  36004. function createForEach(arrayFunc, eachFunc) {
  36005. return function(collection, iteratee, thisArg) {
  36006. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  36007. ? arrayFunc(collection, iteratee)
  36008. : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
  36009. };
  36010. }
  36011. module.exports = createForEach;
  36012. },{"280":280,"330":330}],295:[function(_dereq_,module,exports){
  36013. (function (global){
  36014. var arrayCopy = _dereq_(234),
  36015. composeArgs = _dereq_(284),
  36016. composeArgsRight = _dereq_(285),
  36017. createCtorWrapper = _dereq_(292),
  36018. isLaziable = _dereq_(312),
  36019. reorder = _dereq_(321),
  36020. replaceHolders = _dereq_(322),
  36021. setData = _dereq_(323);
  36022. /** Used to compose bitmasks for wrapper metadata. */
  36023. var BIND_FLAG = 1,
  36024. BIND_KEY_FLAG = 2,
  36025. CURRY_BOUND_FLAG = 4,
  36026. CURRY_FLAG = 8,
  36027. CURRY_RIGHT_FLAG = 16,
  36028. PARTIAL_FLAG = 32,
  36029. PARTIAL_RIGHT_FLAG = 64,
  36030. ARY_FLAG = 128;
  36031. /* Native method references for those with the same name as other `lodash` methods. */
  36032. var nativeMax = Math.max;
  36033. /**
  36034. * Creates a function that wraps `func` and invokes it with optional `this`
  36035. * binding of, partial application, and currying.
  36036. *
  36037. * @private
  36038. * @param {Function|string} func The function or method name to reference.
  36039. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  36040. * @param {*} [thisArg] The `this` binding of `func`.
  36041. * @param {Array} [partials] The arguments to prepend to those provided to the new function.
  36042. * @param {Array} [holders] The `partials` placeholder indexes.
  36043. * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
  36044. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  36045. * @param {Array} [argPos] The argument positions of the new function.
  36046. * @param {number} [ary] The arity cap of `func`.
  36047. * @param {number} [arity] The arity of `func`.
  36048. * @returns {Function} Returns the new wrapped function.
  36049. */
  36050. function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  36051. var isAry = bitmask & ARY_FLAG,
  36052. isBind = bitmask & BIND_FLAG,
  36053. isBindKey = bitmask & BIND_KEY_FLAG,
  36054. isCurry = bitmask & CURRY_FLAG,
  36055. isCurryBound = bitmask & CURRY_BOUND_FLAG,
  36056. isCurryRight = bitmask & CURRY_RIGHT_FLAG,
  36057. Ctor = isBindKey ? undefined : createCtorWrapper(func);
  36058. function wrapper() {
  36059. // Avoid `arguments` object use disqualifying optimizations by
  36060. // converting it to an array before providing it to other functions.
  36061. var length = arguments.length,
  36062. index = length,
  36063. args = Array(length);
  36064. while (index--) {
  36065. args[index] = arguments[index];
  36066. }
  36067. if (partials) {
  36068. args = composeArgs(args, partials, holders);
  36069. }
  36070. if (partialsRight) {
  36071. args = composeArgsRight(args, partialsRight, holdersRight);
  36072. }
  36073. if (isCurry || isCurryRight) {
  36074. var placeholder = wrapper.placeholder,
  36075. argsHolders = replaceHolders(args, placeholder);
  36076. length -= argsHolders.length;
  36077. if (length < arity) {
  36078. var newArgPos = argPos ? arrayCopy(argPos) : undefined,
  36079. newArity = nativeMax(arity - length, 0),
  36080. newsHolders = isCurry ? argsHolders : undefined,
  36081. newHoldersRight = isCurry ? undefined : argsHolders,
  36082. newPartials = isCurry ? args : undefined,
  36083. newPartialsRight = isCurry ? undefined : args;
  36084. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  36085. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  36086. if (!isCurryBound) {
  36087. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  36088. }
  36089. var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
  36090. result = createHybridWrapper.apply(undefined, newData);
  36091. if (isLaziable(func)) {
  36092. setData(result, newData);
  36093. }
  36094. result.placeholder = placeholder;
  36095. return result;
  36096. }
  36097. }
  36098. var thisBinding = isBind ? thisArg : this,
  36099. fn = isBindKey ? thisBinding[func] : func;
  36100. if (argPos) {
  36101. args = reorder(args, argPos);
  36102. }
  36103. if (isAry && ary < args.length) {
  36104. args.length = ary;
  36105. }
  36106. if (this && this !== global && this instanceof wrapper) {
  36107. fn = Ctor || createCtorWrapper(func);
  36108. }
  36109. return fn.apply(thisBinding, args);
  36110. }
  36111. return wrapper;
  36112. }
  36113. module.exports = createHybridWrapper;
  36114. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  36115. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9sb2Rhc2gvaW50ZXJuYWwvY3JlYXRlSHlicmlkV3JhcHBlci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXNDb250ZW50IjpbInZhciBhcnJheUNvcHkgPSByZXF1aXJlKCcuL2FycmF5Q29weScpLFxuICAgIGNvbXBvc2VBcmdzID0gcmVxdWlyZSgnLi9jb21wb3NlQXJncycpLFxuICAgIGNvbXBvc2VBcmdzUmlnaHQgPSByZXF1aXJlKCcuL2NvbXBvc2VBcmdzUmlnaHQnKSxcbiAgICBjcmVhdGVDdG9yV3JhcHBlciA9IHJlcXVpcmUoJy4vY3JlYXRlQ3RvcldyYXBwZXInKSxcbiAgICBpc0xhemlhYmxlID0gcmVxdWlyZSgnLi9pc0xhemlhYmxlJyksXG4gICAgcmVvcmRlciA9IHJlcXVpcmUoJy4vcmVvcmRlcicpLFxuICAgIHJlcGxhY2VIb2xkZXJzID0gcmVxdWlyZSgnLi9yZXBsYWNlSG9sZGVycycpLFxuICAgIHNldERhdGEgPSByZXF1aXJlKCcuL3NldERhdGEnKTtcblxuLyoqIFVzZWQgdG8gY29tcG9zZSBiaXRtYXNrcyBmb3Igd3JhcHBlciBtZXRhZGF0YS4gKi9cbnZhciBCSU5EX0ZMQUcgPSAxLFxuICAgIEJJTkRfS0VZX0ZMQUcgPSAyLFxuICAgIENVUlJZX0JPVU5EX0ZMQUcgPSA0LFxuICAgIENVUlJZX0ZMQUcgPSA4LFxuICAgIENVUlJZX1JJR0hUX0ZMQUcgPSAxNixcbiAgICBQQVJUSUFMX0ZMQUcgPSAzMixcbiAgICBQQVJUSUFMX1JJR0hUX0ZMQUcgPSA2NCxcbiAgICBBUllfRkxBRyA9IDEyODtcblxuLyogTmF0aXZlIG1ldGhvZCByZWZlcmVuY2VzIGZvciB0aG9zZSB3aXRoIHRoZSBzYW1lIG5hbWUgYXMgb3RoZXIgYGxvZGFzaGAgbWV0aG9kcy4gKi9cbnZhciBuYXRpdmVNYXggPSBNYXRoLm1heDtcblxuLyoqXG4gKiBDcmVhdGVzIGEgZnVuY3Rpb24gdGhhdCB3cmFwcyBgZnVuY2AgYW5kIGludm9rZXMgaXQgd2l0aCBvcHRpb25hbCBgdGhpc2BcbiAqIGJpbmRpbmcgb2YsIHBhcnRpYWwgYXBwbGljYXRpb24sIGFuZCBjdXJyeWluZy5cbiAqXG4gKiBAcHJpdmF0ZVxuICogQHBhcmFtIHtGdW5jdGlvbnxzdHJpbmd9IGZ1bmMgVGhlIGZ1bmN0aW9uIG9yIG1ldGhvZCBuYW1lIHRvIHJlZmVyZW5jZS5cbiAqIEBwYXJhbSB7bnVtYmVyfSBiaXRtYXNrIFRoZSBiaXRtYXNrIG9mIGZsYWdzLiBTZWUgYGNyZWF0ZVdyYXBwZXJgIGZvciBtb3JlIGRldGFpbHMuXG4gKiBAcGFyYW0geyp9IFt0aGlzQXJnXSBUaGUgYHRoaXNgIGJpbmRpbmcgb2YgYGZ1bmNgLlxuICogQHBhcmFtIHtBcnJheX0gW3BhcnRpYWxzXSBUaGUgYXJndW1lbnRzIHRvIHByZXBlbmQgdG8gdGhvc2UgcHJvdmlkZWQgdG8gdGhlIG5ldyBmdW5jdGlvbi5cbiAqIEBwYXJhbSB7QXJyYXl9IFtob2xkZXJzXSBUaGUgYHBhcnRpYWxzYCBwbGFjZWhvbGRlciBpbmRleGVzLlxuICogQHBhcmFtIHtBcnJheX0gW3BhcnRpYWxzUmlnaHRdIFRoZSBhcmd1bWVudHMgdG8gYXBwZW5kIHRvIHRob3NlIHByb3ZpZGVkIHRvIHRoZSBuZXcgZnVuY3Rpb24uXG4gKiBAcGFyYW0ge0FycmF5fSBbaG9sZGVyc1JpZ2h0XSBUaGUgYHBhcnRpYWxzUmlnaHRgIHBsYWNlaG9sZGVyIGluZGV4ZXMuXG4gKiBAcGFyYW0ge0FycmF5fSBbYXJnUG9zXSBUaGUgYXJndW1lbnQgcG9zaXRpb25zIG9mIHRoZSBuZXcgZnVuY3Rpb24uXG4gKiBAcGFyYW0ge251bWJlcn0gW2FyeV0gVGhlIGFyaXR5IGNhcCBvZiBgZnVuY2AuXG4gKiBAcGFyYW0ge251bWJlcn0gW2FyaXR5XSBUaGUgYXJpdHkgb2YgYGZ1bmNgLlxuICogQHJldHVybnMge0Z1bmN0aW9ufSBSZXR1cm5zIHRoZSBuZXcgd3JhcHBlZCBmdW5jdGlvbi5cbiAqL1xuZnVuY3Rpb24gY3JlYXRlSHlicmlkV3JhcHBlcihmdW5jLCBiaXRtYXNrLCB0aGlzQXJnLCBwYXJ0aWFscywgaG9sZGVycywgcGFydGlhbHNSaWdodCwgaG9sZGVyc1JpZ2h0LCBhcmdQb3MsIGFyeSwgYXJpdHkpIHtcbiAgdmFyIGlzQXJ5ID0gYml0bWFzayAmIEFSWV9GTEFHLFxuICAgICAgaXNCaW5kID0gYml0bWFzayAmIEJJTkRfRkxBRyxcbiAgICAgIGlzQmluZEtleSA9IGJpdG1hc2sgJiBCSU5EX0tFWV9GTEFHLFxuICAgICAgaXNDdXJyeSA9IGJpdG1hc2sgJiBDVVJSWV9GTEFHLFxuICAgICAgaXNDdXJyeUJvdW5kID0gYml0bWFzayAmIENVUlJZX0JPVU5EX0ZMQUcsXG4gICAgICBpc0N1cnJ5UmlnaHQgPSBiaXRtYXNrICYgQ1VSUllfUklHSFRfRkxBRyxcbiAgICAgIEN0b3IgPSBpc0JpbmRLZXkgPyB1bmRlZmluZWQgOiBjcmVhdGVDdG9yV3JhcHBlcihmdW5jKTtcblxuICBmdW5jdGlvbiB3cmFwcGVyKCkge1xuICAgIC8vIEF2b2lkIGBhcmd1bWVudHNgIG9iamVjdCB1c2UgZGlzcXVhbGlmeWluZyBvcHRpbWl6YXRpb25zIGJ5XG4gICAgLy8gY29udmVydGluZyBpdCB0byBhbiBhcnJheSBiZWZvcmUgcHJvdmlkaW5nIGl0IHRvIG90aGVyIGZ1bmN0aW9ucy5cbiAgICB2YXIgbGVuZ3RoID0gYXJndW1lbnRzLmxlbmd0aCxcbiAgICAgICAgaW5kZXggPSBsZW5ndGgsXG4gICAgICAgIGFyZ3MgPSBBcnJheShsZW5ndGgpO1xuXG4gICAgd2hpbGUgKGluZGV4LS0pIHtcbiAgICAgIGFyZ3NbaW5kZXhdID0gYXJndW1lbnRzW2luZGV4XTtcbiAgICB9XG4gICAgaWYgKHBhcnRpYWxzKSB7XG4gICAgICBhcmdzID0gY29tcG9zZUFyZ3MoYXJncywgcGFydGlhbHMsIGhvbGRlcnMpO1xuICAgIH1cbiAgICBpZiAocGFydGlhbHNSaWdodCkge1xuICAgICAgYXJncyA9IGNvbXBvc2VBcmdzUmlnaHQoYXJncywgcGFydGlhbHNSaWdodCwgaG9sZGVyc1JpZ2h0KTtcbiAgICB9XG4gICAgaWYgKGlzQ3VycnkgfHwgaXNDdXJyeVJpZ2h0KSB7XG4gICAgICB2YXIgcGxhY2Vob2xkZXIgPSB3cmFwcGVyLnBsYWNlaG9sZGVyLFxuICAgICAgICAgIGFyZ3NIb2xkZXJzID0gcmVwbGFjZUhvbGRlcnMoYXJncywgcGxhY2Vob2xkZXIpO1xuXG4gICAgICBsZW5ndGggLT0gYXJnc0hvbGRlcnMubGVuZ3RoO1xuICAgICAgaWYgKGxlbmd0aCA8IGFyaXR5KSB7XG4gICAgICAgIHZhciBuZXdBcmdQb3MgPSBhcmdQb3MgPyBhcnJheUNvcHkoYXJnUG9zKSA6IHVuZGVmaW5lZCxcbiAgICAgICAgICAgIG5ld0FyaXR5ID0gbmF0aXZlTWF4KGFyaXR5IC0gbGVuZ3RoLCAwKSxcbiAgICAgICAgICAgIG5ld3NIb2xkZXJzID0gaXNDdXJyeSA/IGFyZ3NIb2xkZXJzIDogdW5kZWZpbmVkLFxuICAgICAgICAgICAgbmV3SG9sZGVyc1JpZ2h0ID0gaXNDdXJyeSA/IHVuZGVmaW5lZCA6IGFyZ3NIb2xkZXJzLFxuICAgICAgICAgICAgbmV3UGFydGlhbHMgPSBpc0N1cnJ5ID8gYXJncyA6IHVuZGVmaW5lZCxcbiAgICAgICAgICAgIG5ld1BhcnRpYWxzUmlnaHQgPSBpc0N1cnJ5ID8gdW5kZWZpbmVkIDogYXJncztcblxuICAgICAgICBiaXRtYXNrIHw9IChpc0N1cnJ5ID8gUEFSVElBTF9GTEFHIDogUEFSVElBTF9SSUdIVF9GTEFHKTtcbiAgICAgICAgYml0bWFzayAmPSB+KGlzQ3VycnkgPyBQQVJUSUFMX1JJR0hUX0ZMQUcgOiBQQVJUSUFMX0ZMQUcpO1xuXG4gICAgICAgIGlmICghaXNDdXJyeUJvdW5kKSB7XG4gICAgICAgICAgYml0bWFzayAmPSB+KEJJTkRfRkxBRyB8IEJJTkRfS0VZX0ZMQUcpO1xuICAgICAgICB9XG4gICAgICAgIHZhciBuZXdEYXRhID0gW2Z1bmMsIGJpdG1hc2ssIHRoaXNBcmcsIG5ld1BhcnRpYWxzLCBuZXdzSG9sZGVycywgbmV3UGFydGlhbHNSaWdodCwgbmV3SG9sZGVyc1JpZ2h0LCBuZXdBcmdQb3MsIGFyeSwgbmV3QXJpdHldLFxuICAgICAgICAgICAgcmVzdWx0ID0gY3JlYXRlSHlicmlkV3JhcHBlci5hcHBseSh1bmRlZmluZWQsIG5ld0RhdGEpO1xuXG4gICAgICAgIGlmIChpc0xhemlhYmxlKGZ1bmMpKSB7XG4gICAgICAgICAgc2V0RGF0YShyZXN1bHQsIG5ld0RhdGEpO1xuICAgICAgICB9XG4gICAgICAgIHJlc3VsdC5wbGFjZWhvbGRlciA9IHBsYWNlaG9sZGVyO1xuICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgICAgfVxuICAgIH1cbiAgICB2YXIgdGhpc0JpbmRpbmcgPSBpc0JpbmQgPyB0aGlzQXJnIDogdGhpcyxcbiAgICAgICAgZm4gPSBpc0JpbmRLZXkgPyB0aGlzQmluZGluZ1tmdW5jXSA6IGZ1bmM7XG5cbiAgICBpZiAoYXJnUG9zKSB7XG4gICAgICBhcmdzID0gcmVvcmRlcihhcmdzLCBhcmdQb3MpO1xuICAgIH1cbiAgICBpZiAoaXNBcnkgJiYgYXJ5IDwgYXJncy5sZW5ndGgpIHtcbiAgICAgIGFyZ3MubGVuZ3RoID0gYXJ5O1xuICAgIH1cbiAgICBpZiAodGhpcyAmJiB0aGlzICE9PSBnbG9iYWwgJiYgdGhpcyBpbnN0YW5jZW9mIHdyYXBwZXIpIHtcbiAgICAgIGZuID0gQ3RvciB8fCBjcmVhdGVDdG9yV3JhcHBlcihmdW5jKTtcbiAgICB9XG4gICAgcmV0dXJuIGZuLmFwcGx5KHRoaXNCaW5kaW5nLCBhcmdzKTtcbiAgfVxuICByZXR1cm4gd3JhcHBlcjtcbn1cblxubW9kdWxlLmV4cG9ydHMgPSBjcmVhdGVIeWJyaWRXcmFwcGVyO1xuIl19
  36116. },{"234":234,"284":284,"285":285,"292":292,"312":312,"321":321,"322":322,"323":323}],296:[function(_dereq_,module,exports){
  36117. (function (global){
  36118. var createCtorWrapper = _dereq_(292);
  36119. /** Used to compose bitmasks for wrapper metadata. */
  36120. var BIND_FLAG = 1;
  36121. /**
  36122. * Creates a function that wraps `func` and invokes it with the optional `this`
  36123. * binding of `thisArg` and the `partials` prepended to those provided to
  36124. * the wrapper.
  36125. *
  36126. * @private
  36127. * @param {Function} func The function to partially apply arguments to.
  36128. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  36129. * @param {*} thisArg The `this` binding of `func`.
  36130. * @param {Array} partials The arguments to prepend to those provided to the new function.
  36131. * @returns {Function} Returns the new bound function.
  36132. */
  36133. function createPartialWrapper(func, bitmask, thisArg, partials) {
  36134. var isBind = bitmask & BIND_FLAG,
  36135. Ctor = createCtorWrapper(func);
  36136. function wrapper() {
  36137. // Avoid `arguments` object use disqualifying optimizations by
  36138. // converting it to an array before providing it `func`.
  36139. var argsIndex = -1,
  36140. argsLength = arguments.length,
  36141. leftIndex = -1,
  36142. leftLength = partials.length,
  36143. args = Array(leftLength + argsLength);
  36144. while (++leftIndex < leftLength) {
  36145. args[leftIndex] = partials[leftIndex];
  36146. }
  36147. while (argsLength--) {
  36148. args[leftIndex++] = arguments[++argsIndex];
  36149. }
  36150. var fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
  36151. return fn.apply(isBind ? thisArg : this, args);
  36152. }
  36153. return wrapper;
  36154. }
  36155. module.exports = createPartialWrapper;
  36156. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  36157. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9sb2Rhc2gvaW50ZXJuYWwvY3JlYXRlUGFydGlhbFdyYXBwZXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXNDb250ZW50IjpbInZhciBjcmVhdGVDdG9yV3JhcHBlciA9IHJlcXVpcmUoJy4vY3JlYXRlQ3RvcldyYXBwZXInKTtcblxuLyoqIFVzZWQgdG8gY29tcG9zZSBiaXRtYXNrcyBmb3Igd3JhcHBlciBtZXRhZGF0YS4gKi9cbnZhciBCSU5EX0ZMQUcgPSAxO1xuXG4vKipcbiAqIENyZWF0ZXMgYSBmdW5jdGlvbiB0aGF0IHdyYXBzIGBmdW5jYCBhbmQgaW52b2tlcyBpdCB3aXRoIHRoZSBvcHRpb25hbCBgdGhpc2BcbiAqIGJpbmRpbmcgb2YgYHRoaXNBcmdgIGFuZCB0aGUgYHBhcnRpYWxzYCBwcmVwZW5kZWQgdG8gdGhvc2UgcHJvdmlkZWQgdG9cbiAqIHRoZSB3cmFwcGVyLlxuICpcbiAqIEBwcml2YXRlXG4gKiBAcGFyYW0ge0Z1bmN0aW9ufSBmdW5jIFRoZSBmdW5jdGlvbiB0byBwYXJ0aWFsbHkgYXBwbHkgYXJndW1lbnRzIHRvLlxuICogQHBhcmFtIHtudW1iZXJ9IGJpdG1hc2sgVGhlIGJpdG1hc2sgb2YgZmxhZ3MuIFNlZSBgY3JlYXRlV3JhcHBlcmAgZm9yIG1vcmUgZGV0YWlscy5cbiAqIEBwYXJhbSB7Kn0gdGhpc0FyZyBUaGUgYHRoaXNgIGJpbmRpbmcgb2YgYGZ1bmNgLlxuICogQHBhcmFtIHtBcnJheX0gcGFydGlhbHMgVGhlIGFyZ3VtZW50cyB0byBwcmVwZW5kIHRvIHRob3NlIHByb3ZpZGVkIHRvIHRoZSBuZXcgZnVuY3Rpb24uXG4gKiBAcmV0dXJucyB7RnVuY3Rpb259IFJldHVybnMgdGhlIG5ldyBib3VuZCBmdW5jdGlvbi5cbiAqL1xuZnVuY3Rpb24gY3JlYXRlUGFydGlhbFdyYXBwZXIoZnVuYywgYml0bWFzaywgdGhpc0FyZywgcGFydGlhbHMpIHtcbiAgdmFyIGlzQmluZCA9IGJpdG1hc2sgJiBCSU5EX0ZMQUcsXG4gICAgICBDdG9yID0gY3JlYXRlQ3RvcldyYXBwZXIoZnVuYyk7XG5cbiAgZnVuY3Rpb24gd3JhcHBlcigpIHtcbiAgICAvLyBBdm9pZCBgYXJndW1lbnRzYCBvYmplY3QgdXNlIGRpc3F1YWxpZnlpbmcgb3B0aW1pemF0aW9ucyBieVxuICAgIC8vIGNvbnZlcnRpbmcgaXQgdG8gYW4gYXJyYXkgYmVmb3JlIHByb3ZpZGluZyBpdCBgZnVuY2AuXG4gICAgdmFyIGFyZ3NJbmRleCA9IC0xLFxuICAgICAgICBhcmdzTGVuZ3RoID0gYXJndW1lbnRzLmxlbmd0aCxcbiAgICAgICAgbGVmdEluZGV4ID0gLTEsXG4gICAgICAgIGxlZnRMZW5ndGggPSBwYXJ0aWFscy5sZW5ndGgsXG4gICAgICAgIGFyZ3MgPSBBcnJheShsZWZ0TGVuZ3RoICsgYXJnc0xlbmd0aCk7XG5cbiAgICB3aGlsZSAoKytsZWZ0SW5kZXggPCBsZWZ0TGVuZ3RoKSB7XG4gICAgICBhcmdzW2xlZnRJbmRleF0gPSBwYXJ0aWFsc1tsZWZ0SW5kZXhdO1xuICAgIH1cbiAgICB3aGlsZSAoYXJnc0xlbmd0aC0tKSB7XG4gICAgICBhcmdzW2xlZnRJbmRleCsrXSA9IGFyZ3VtZW50c1srK2FyZ3NJbmRleF07XG4gICAgfVxuICAgIHZhciBmbiA9ICh0aGlzICYmIHRoaXMgIT09IGdsb2JhbCAmJiB0aGlzIGluc3RhbmNlb2Ygd3JhcHBlcikgPyBDdG9yIDogZnVuYztcbiAgICByZXR1cm4gZm4uYXBwbHkoaXNCaW5kID8gdGhpc0FyZyA6IHRoaXMsIGFyZ3MpO1xuICB9XG4gIHJldHVybiB3cmFwcGVyO1xufVxuXG5tb2R1bGUuZXhwb3J0cyA9IGNyZWF0ZVBhcnRpYWxXcmFwcGVyO1xuIl19
  36158. },{"292":292}],297:[function(_dereq_,module,exports){
  36159. var baseCallback = _dereq_(244),
  36160. baseReduce = _dereq_(272),
  36161. isArray = _dereq_(330);
  36162. /**
  36163. * Creates a function for `_.reduce` or `_.reduceRight`.
  36164. *
  36165. * @private
  36166. * @param {Function} arrayFunc The function to iterate over an array.
  36167. * @param {Function} eachFunc The function to iterate over a collection.
  36168. * @returns {Function} Returns the new each function.
  36169. */
  36170. function createReduce(arrayFunc, eachFunc) {
  36171. return function(collection, iteratee, accumulator, thisArg) {
  36172. var initFromArray = arguments.length < 3;
  36173. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  36174. ? arrayFunc(collection, iteratee, accumulator, initFromArray)
  36175. : baseReduce(collection, baseCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
  36176. };
  36177. }
  36178. module.exports = createReduce;
  36179. },{"244":244,"272":272,"330":330}],298:[function(_dereq_,module,exports){
  36180. var baseSetData = _dereq_(273),
  36181. createBindWrapper = _dereq_(290),
  36182. createHybridWrapper = _dereq_(295),
  36183. createPartialWrapper = _dereq_(296),
  36184. getData = _dereq_(302),
  36185. mergeData = _dereq_(316),
  36186. setData = _dereq_(323);
  36187. /** Used to compose bitmasks for wrapper metadata. */
  36188. var BIND_FLAG = 1,
  36189. BIND_KEY_FLAG = 2,
  36190. PARTIAL_FLAG = 32,
  36191. PARTIAL_RIGHT_FLAG = 64;
  36192. /** Used as the `TypeError` message for "Functions" methods. */
  36193. var FUNC_ERROR_TEXT = 'Expected a function';
  36194. /* Native method references for those with the same name as other `lodash` methods. */
  36195. var nativeMax = Math.max;
  36196. /**
  36197. * Creates a function that either curries or invokes `func` with optional
  36198. * `this` binding and partially applied arguments.
  36199. *
  36200. * @private
  36201. * @param {Function|string} func The function or method name to reference.
  36202. * @param {number} bitmask The bitmask of flags.
  36203. * The bitmask may be composed of the following flags:
  36204. * 1 - `_.bind`
  36205. * 2 - `_.bindKey`
  36206. * 4 - `_.curry` or `_.curryRight` of a bound function
  36207. * 8 - `_.curry`
  36208. * 16 - `_.curryRight`
  36209. * 32 - `_.partial`
  36210. * 64 - `_.partialRight`
  36211. * 128 - `_.rearg`
  36212. * 256 - `_.ary`
  36213. * @param {*} [thisArg] The `this` binding of `func`.
  36214. * @param {Array} [partials] The arguments to be partially applied.
  36215. * @param {Array} [holders] The `partials` placeholder indexes.
  36216. * @param {Array} [argPos] The argument positions of the new function.
  36217. * @param {number} [ary] The arity cap of `func`.
  36218. * @param {number} [arity] The arity of `func`.
  36219. * @returns {Function} Returns the new wrapped function.
  36220. */
  36221. function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  36222. var isBindKey = bitmask & BIND_KEY_FLAG;
  36223. if (!isBindKey && typeof func != 'function') {
  36224. throw new TypeError(FUNC_ERROR_TEXT);
  36225. }
  36226. var length = partials ? partials.length : 0;
  36227. if (!length) {
  36228. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  36229. partials = holders = undefined;
  36230. }
  36231. length -= (holders ? holders.length : 0);
  36232. if (bitmask & PARTIAL_RIGHT_FLAG) {
  36233. var partialsRight = partials,
  36234. holdersRight = holders;
  36235. partials = holders = undefined;
  36236. }
  36237. var data = isBindKey ? undefined : getData(func),
  36238. newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
  36239. if (data) {
  36240. mergeData(newData, data);
  36241. bitmask = newData[1];
  36242. arity = newData[9];
  36243. }
  36244. newData[9] = arity == null
  36245. ? (isBindKey ? 0 : func.length)
  36246. : (nativeMax(arity - length, 0) || 0);
  36247. if (bitmask == BIND_FLAG) {
  36248. var result = createBindWrapper(newData[0], newData[2]);
  36249. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
  36250. result = createPartialWrapper.apply(undefined, newData);
  36251. } else {
  36252. result = createHybridWrapper.apply(undefined, newData);
  36253. }
  36254. var setter = data ? baseSetData : setData;
  36255. return setter(result, newData);
  36256. }
  36257. module.exports = createWrapper;
  36258. },{"273":273,"290":290,"295":295,"296":296,"302":302,"316":316,"323":323}],299:[function(_dereq_,module,exports){
  36259. var arraySome = _dereq_(241);
  36260. /**
  36261. * A specialized version of `baseIsEqualDeep` for arrays with support for
  36262. * partial deep comparisons.
  36263. *
  36264. * @private
  36265. * @param {Array} array The array to compare.
  36266. * @param {Array} other The other array to compare.
  36267. * @param {Function} equalFunc The function to determine equivalents of values.
  36268. * @param {Function} [customizer] The function to customize comparing arrays.
  36269. * @param {boolean} [isLoose] Specify performing partial comparisons.
  36270. * @param {Array} [stackA] Tracks traversed `value` objects.
  36271. * @param {Array} [stackB] Tracks traversed `other` objects.
  36272. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  36273. */
  36274. function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
  36275. var index = -1,
  36276. arrLength = array.length,
  36277. othLength = other.length;
  36278. if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
  36279. return false;
  36280. }
  36281. // Ignore non-index properties.
  36282. while (++index < arrLength) {
  36283. var arrValue = array[index],
  36284. othValue = other[index],
  36285. result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
  36286. if (result !== undefined) {
  36287. if (result) {
  36288. continue;
  36289. }
  36290. return false;
  36291. }
  36292. // Recursively compare arrays (susceptible to call stack limits).
  36293. if (isLoose) {
  36294. if (!arraySome(other, function(othValue) {
  36295. return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
  36296. })) {
  36297. return false;
  36298. }
  36299. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
  36300. return false;
  36301. }
  36302. }
  36303. return true;
  36304. }
  36305. module.exports = equalArrays;
  36306. },{"241":241}],300:[function(_dereq_,module,exports){
  36307. /** `Object#toString` result references. */
  36308. var boolTag = '[object Boolean]',
  36309. dateTag = '[object Date]',
  36310. errorTag = '[object Error]',
  36311. numberTag = '[object Number]',
  36312. regexpTag = '[object RegExp]',
  36313. stringTag = '[object String]';
  36314. /**
  36315. * A specialized version of `baseIsEqualDeep` for comparing objects of
  36316. * the same `toStringTag`.
  36317. *
  36318. * **Note:** This function only supports comparing values with tags of
  36319. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  36320. *
  36321. * @private
  36322. * @param {Object} object The object to compare.
  36323. * @param {Object} other The other object to compare.
  36324. * @param {string} tag The `toStringTag` of the objects to compare.
  36325. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  36326. */
  36327. function equalByTag(object, other, tag) {
  36328. switch (tag) {
  36329. case boolTag:
  36330. case dateTag:
  36331. // Coerce dates and booleans to numbers, dates to milliseconds and booleans
  36332. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
  36333. return +object == +other;
  36334. case errorTag:
  36335. return object.name == other.name && object.message == other.message;
  36336. case numberTag:
  36337. // Treat `NaN` vs. `NaN` as equal.
  36338. return (object != +object)
  36339. ? other != +other
  36340. : object == +other;
  36341. case regexpTag:
  36342. case stringTag:
  36343. // Coerce regexes to strings and treat strings primitives and string
  36344. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
  36345. return object == (other + '');
  36346. }
  36347. return false;
  36348. }
  36349. module.exports = equalByTag;
  36350. },{}],301:[function(_dereq_,module,exports){
  36351. var keys = _dereq_(340);
  36352. /** Used for native method references. */
  36353. var objectProto = Object.prototype;
  36354. /** Used to check objects for own properties. */
  36355. var hasOwnProperty = objectProto.hasOwnProperty;
  36356. /**
  36357. * A specialized version of `baseIsEqualDeep` for objects with support for
  36358. * partial deep comparisons.
  36359. *
  36360. * @private
  36361. * @param {Object} object The object to compare.
  36362. * @param {Object} other The other object to compare.
  36363. * @param {Function} equalFunc The function to determine equivalents of values.
  36364. * @param {Function} [customizer] The function to customize comparing values.
  36365. * @param {boolean} [isLoose] Specify performing partial comparisons.
  36366. * @param {Array} [stackA] Tracks traversed `value` objects.
  36367. * @param {Array} [stackB] Tracks traversed `other` objects.
  36368. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  36369. */
  36370. function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  36371. var objProps = keys(object),
  36372. objLength = objProps.length,
  36373. othProps = keys(other),
  36374. othLength = othProps.length;
  36375. if (objLength != othLength && !isLoose) {
  36376. return false;
  36377. }
  36378. var index = objLength;
  36379. while (index--) {
  36380. var key = objProps[index];
  36381. if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
  36382. return false;
  36383. }
  36384. }
  36385. var skipCtor = isLoose;
  36386. while (++index < objLength) {
  36387. key = objProps[index];
  36388. var objValue = object[key],
  36389. othValue = other[key],
  36390. result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
  36391. // Recursively compare objects (susceptible to call stack limits).
  36392. if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
  36393. return false;
  36394. }
  36395. skipCtor || (skipCtor = key == 'constructor');
  36396. }
  36397. if (!skipCtor) {
  36398. var objCtor = object.constructor,
  36399. othCtor = other.constructor;
  36400. // Non `Object` object instances with different constructors are not equal.
  36401. if (objCtor != othCtor &&
  36402. ('constructor' in object && 'constructor' in other) &&
  36403. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  36404. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  36405. return false;
  36406. }
  36407. }
  36408. return true;
  36409. }
  36410. module.exports = equalObjects;
  36411. },{"340":340}],302:[function(_dereq_,module,exports){
  36412. var metaMap = _dereq_(317),
  36413. noop = _dereq_(349);
  36414. /**
  36415. * Gets metadata for `func`.
  36416. *
  36417. * @private
  36418. * @param {Function} func The function to query.
  36419. * @returns {*} Returns the metadata for `func`.
  36420. */
  36421. var getData = !metaMap ? noop : function(func) {
  36422. return metaMap.get(func);
  36423. };
  36424. module.exports = getData;
  36425. },{"317":317,"349":349}],303:[function(_dereq_,module,exports){
  36426. var realNames = _dereq_(320);
  36427. /**
  36428. * Gets the name of `func`.
  36429. *
  36430. * @private
  36431. * @param {Function} func The function to query.
  36432. * @returns {string} Returns the function name.
  36433. */
  36434. function getFuncName(func) {
  36435. var result = (func.name + ''),
  36436. array = realNames[result],
  36437. length = array ? array.length : 0;
  36438. while (length--) {
  36439. var data = array[length],
  36440. otherFunc = data.func;
  36441. if (otherFunc == null || otherFunc == func) {
  36442. return data.name;
  36443. }
  36444. }
  36445. return result;
  36446. }
  36447. module.exports = getFuncName;
  36448. },{"320":320}],304:[function(_dereq_,module,exports){
  36449. var baseProperty = _dereq_(270);
  36450. /**
  36451. * Gets the "length" property value of `object`.
  36452. *
  36453. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  36454. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  36455. *
  36456. * @private
  36457. * @param {Object} object The object to query.
  36458. * @returns {*} Returns the "length" value.
  36459. */
  36460. var getLength = baseProperty('length');
  36461. module.exports = getLength;
  36462. },{"270":270}],305:[function(_dereq_,module,exports){
  36463. var isStrictComparable = _dereq_(315),
  36464. pairs = _dereq_(344);
  36465. /**
  36466. * Gets the propery names, values, and compare flags of `object`.
  36467. *
  36468. * @private
  36469. * @param {Object} object The object to query.
  36470. * @returns {Array} Returns the match data of `object`.
  36471. */
  36472. function getMatchData(object) {
  36473. var result = pairs(object),
  36474. length = result.length;
  36475. while (length--) {
  36476. result[length][2] = isStrictComparable(result[length][1]);
  36477. }
  36478. return result;
  36479. }
  36480. module.exports = getMatchData;
  36481. },{"315":315,"344":344}],306:[function(_dereq_,module,exports){
  36482. var isNative = _dereq_(332);
  36483. /**
  36484. * Gets the native function at `key` of `object`.
  36485. *
  36486. * @private
  36487. * @param {Object} object The object to query.
  36488. * @param {string} key The key of the method to get.
  36489. * @returns {*} Returns the function if it's native, else `undefined`.
  36490. */
  36491. function getNative(object, key) {
  36492. var value = object == null ? undefined : object[key];
  36493. return isNative(value) ? value : undefined;
  36494. }
  36495. module.exports = getNative;
  36496. },{"332":332}],307:[function(_dereq_,module,exports){
  36497. /**
  36498. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  36499. *
  36500. * @private
  36501. * @param {Array} array The array to search.
  36502. * @param {number} fromIndex The index to search from.
  36503. * @param {boolean} [fromRight] Specify iterating from right to left.
  36504. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  36505. */
  36506. function indexOfNaN(array, fromIndex, fromRight) {
  36507. var length = array.length,
  36508. index = fromIndex + (fromRight ? 0 : -1);
  36509. while ((fromRight ? index-- : ++index < length)) {
  36510. var other = array[index];
  36511. if (other !== other) {
  36512. return index;
  36513. }
  36514. }
  36515. return -1;
  36516. }
  36517. module.exports = indexOfNaN;
  36518. },{}],308:[function(_dereq_,module,exports){
  36519. var getLength = _dereq_(304),
  36520. isLength = _dereq_(313);
  36521. /**
  36522. * Checks if `value` is array-like.
  36523. *
  36524. * @private
  36525. * @param {*} value The value to check.
  36526. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  36527. */
  36528. function isArrayLike(value) {
  36529. return value != null && isLength(getLength(value));
  36530. }
  36531. module.exports = isArrayLike;
  36532. },{"304":304,"313":313}],309:[function(_dereq_,module,exports){
  36533. /** Used to detect unsigned integer values. */
  36534. var reIsUint = /^\d+$/;
  36535. /**
  36536. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  36537. * of an array-like value.
  36538. */
  36539. var MAX_SAFE_INTEGER = 9007199254740991;
  36540. /**
  36541. * Checks if `value` is a valid array-like index.
  36542. *
  36543. * @private
  36544. * @param {*} value The value to check.
  36545. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  36546. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  36547. */
  36548. function isIndex(value, length) {
  36549. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  36550. length = length == null ? MAX_SAFE_INTEGER : length;
  36551. return value > -1 && value % 1 == 0 && value < length;
  36552. }
  36553. module.exports = isIndex;
  36554. },{}],310:[function(_dereq_,module,exports){
  36555. var isArrayLike = _dereq_(308),
  36556. isIndex = _dereq_(309),
  36557. isObject = _dereq_(334);
  36558. /**
  36559. * Checks if the provided arguments are from an iteratee call.
  36560. *
  36561. * @private
  36562. * @param {*} value The potential iteratee value argument.
  36563. * @param {*} index The potential iteratee index or key argument.
  36564. * @param {*} object The potential iteratee object argument.
  36565. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  36566. */
  36567. function isIterateeCall(value, index, object) {
  36568. if (!isObject(object)) {
  36569. return false;
  36570. }
  36571. var type = typeof index;
  36572. if (type == 'number'
  36573. ? (isArrayLike(object) && isIndex(index, object.length))
  36574. : (type == 'string' && index in object)) {
  36575. var other = object[index];
  36576. return value === value ? (value === other) : (other !== other);
  36577. }
  36578. return false;
  36579. }
  36580. module.exports = isIterateeCall;
  36581. },{"308":308,"309":309,"334":334}],311:[function(_dereq_,module,exports){
  36582. var isArray = _dereq_(330),
  36583. toObject = _dereq_(326);
  36584. /** Used to match property names within property paths. */
  36585. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
  36586. reIsPlainProp = /^\w*$/;
  36587. /**
  36588. * Checks if `value` is a property name and not a property path.
  36589. *
  36590. * @private
  36591. * @param {*} value The value to check.
  36592. * @param {Object} [object] The object to query keys on.
  36593. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  36594. */
  36595. function isKey(value, object) {
  36596. var type = typeof value;
  36597. if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
  36598. return true;
  36599. }
  36600. if (isArray(value)) {
  36601. return false;
  36602. }
  36603. var result = !reIsDeepProp.test(value);
  36604. return result || (object != null && value in toObject(object));
  36605. }
  36606. module.exports = isKey;
  36607. },{"326":326,"330":330}],312:[function(_dereq_,module,exports){
  36608. var LazyWrapper = _dereq_(231),
  36609. getData = _dereq_(302),
  36610. getFuncName = _dereq_(303),
  36611. lodash = _dereq_(213);
  36612. /**
  36613. * Checks if `func` has a lazy counterpart.
  36614. *
  36615. * @private
  36616. * @param {Function} func The function to check.
  36617. * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
  36618. */
  36619. function isLaziable(func) {
  36620. var funcName = getFuncName(func),
  36621. other = lodash[funcName];
  36622. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  36623. return false;
  36624. }
  36625. if (func === other) {
  36626. return true;
  36627. }
  36628. var data = getData(other);
  36629. return !!data && func === data[0];
  36630. }
  36631. module.exports = isLaziable;
  36632. },{"213":213,"231":231,"302":302,"303":303}],313:[function(_dereq_,module,exports){
  36633. /**
  36634. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  36635. * of an array-like value.
  36636. */
  36637. var MAX_SAFE_INTEGER = 9007199254740991;
  36638. /**
  36639. * Checks if `value` is a valid array-like length.
  36640. *
  36641. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  36642. *
  36643. * @private
  36644. * @param {*} value The value to check.
  36645. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  36646. */
  36647. function isLength(value) {
  36648. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  36649. }
  36650. module.exports = isLength;
  36651. },{}],314:[function(_dereq_,module,exports){
  36652. /**
  36653. * Checks if `value` is object-like.
  36654. *
  36655. * @private
  36656. * @param {*} value The value to check.
  36657. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  36658. */
  36659. function isObjectLike(value) {
  36660. return !!value && typeof value == 'object';
  36661. }
  36662. module.exports = isObjectLike;
  36663. },{}],315:[function(_dereq_,module,exports){
  36664. var isObject = _dereq_(334);
  36665. /**
  36666. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  36667. *
  36668. * @private
  36669. * @param {*} value The value to check.
  36670. * @returns {boolean} Returns `true` if `value` if suitable for strict
  36671. * equality comparisons, else `false`.
  36672. */
  36673. function isStrictComparable(value) {
  36674. return value === value && !isObject(value);
  36675. }
  36676. module.exports = isStrictComparable;
  36677. },{"334":334}],316:[function(_dereq_,module,exports){
  36678. var arrayCopy = _dereq_(234),
  36679. composeArgs = _dereq_(284),
  36680. composeArgsRight = _dereq_(285),
  36681. replaceHolders = _dereq_(322);
  36682. /** Used to compose bitmasks for wrapper metadata. */
  36683. var BIND_FLAG = 1,
  36684. CURRY_BOUND_FLAG = 4,
  36685. CURRY_FLAG = 8,
  36686. ARY_FLAG = 128,
  36687. REARG_FLAG = 256;
  36688. /** Used as the internal argument placeholder. */
  36689. var PLACEHOLDER = '__lodash_placeholder__';
  36690. /* Native method references for those with the same name as other `lodash` methods. */
  36691. var nativeMin = Math.min;
  36692. /**
  36693. * Merges the function metadata of `source` into `data`.
  36694. *
  36695. * Merging metadata reduces the number of wrappers required to invoke a function.
  36696. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  36697. * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
  36698. * augment function arguments, making the order in which they are executed important,
  36699. * preventing the merging of metadata. However, we make an exception for a safe
  36700. * common case where curried functions have `_.ary` and or `_.rearg` applied.
  36701. *
  36702. * @private
  36703. * @param {Array} data The destination metadata.
  36704. * @param {Array} source The source metadata.
  36705. * @returns {Array} Returns `data`.
  36706. */
  36707. function mergeData(data, source) {
  36708. var bitmask = data[1],
  36709. srcBitmask = source[1],
  36710. newBitmask = bitmask | srcBitmask,
  36711. isCommon = newBitmask < ARY_FLAG;
  36712. var isCombo =
  36713. (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
  36714. (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
  36715. (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
  36716. // Exit early if metadata can't be merged.
  36717. if (!(isCommon || isCombo)) {
  36718. return data;
  36719. }
  36720. // Use source `thisArg` if available.
  36721. if (srcBitmask & BIND_FLAG) {
  36722. data[2] = source[2];
  36723. // Set when currying a bound function.
  36724. newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
  36725. }
  36726. // Compose partial arguments.
  36727. var value = source[3];
  36728. if (value) {
  36729. var partials = data[3];
  36730. data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
  36731. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
  36732. }
  36733. // Compose partial right arguments.
  36734. value = source[5];
  36735. if (value) {
  36736. partials = data[5];
  36737. data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
  36738. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
  36739. }
  36740. // Use source `argPos` if available.
  36741. value = source[7];
  36742. if (value) {
  36743. data[7] = arrayCopy(value);
  36744. }
  36745. // Use source `ary` if it's smaller.
  36746. if (srcBitmask & ARY_FLAG) {
  36747. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  36748. }
  36749. // Use source `arity` if one is not provided.
  36750. if (data[9] == null) {
  36751. data[9] = source[9];
  36752. }
  36753. // Use source `func` and merge bitmasks.
  36754. data[0] = source[0];
  36755. data[1] = newBitmask;
  36756. return data;
  36757. }
  36758. module.exports = mergeData;
  36759. },{"234":234,"284":284,"285":285,"322":322}],317:[function(_dereq_,module,exports){
  36760. (function (global){
  36761. var getNative = _dereq_(306);
  36762. /** Native method references. */
  36763. var WeakMap = getNative(global, 'WeakMap');
  36764. /** Used to store function metadata. */
  36765. var metaMap = WeakMap && new WeakMap;
  36766. module.exports = metaMap;
  36767. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  36768. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9sb2Rhc2gvaW50ZXJuYWwvbWV0YU1hcC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXNDb250ZW50IjpbInZhciBnZXROYXRpdmUgPSByZXF1aXJlKCcuL2dldE5hdGl2ZScpO1xuXG4vKiogTmF0aXZlIG1ldGhvZCByZWZlcmVuY2VzLiAqL1xudmFyIFdlYWtNYXAgPSBnZXROYXRpdmUoZ2xvYmFsLCAnV2Vha01hcCcpO1xuXG4vKiogVXNlZCB0byBzdG9yZSBmdW5jdGlvbiBtZXRhZGF0YS4gKi9cbnZhciBtZXRhTWFwID0gV2Vha01hcCAmJiBuZXcgV2Vha01hcDtcblxubW9kdWxlLmV4cG9ydHMgPSBtZXRhTWFwO1xuIl19
  36769. },{"306":306}],318:[function(_dereq_,module,exports){
  36770. var toObject = _dereq_(326);
  36771. /**
  36772. * A specialized version of `_.pick` which picks `object` properties specified
  36773. * by `props`.
  36774. *
  36775. * @private
  36776. * @param {Object} object The source object.
  36777. * @param {string[]} props The property names to pick.
  36778. * @returns {Object} Returns the new object.
  36779. */
  36780. function pickByArray(object, props) {
  36781. object = toObject(object);
  36782. var index = -1,
  36783. length = props.length,
  36784. result = {};
  36785. while (++index < length) {
  36786. var key = props[index];
  36787. if (key in object) {
  36788. result[key] = object[key];
  36789. }
  36790. }
  36791. return result;
  36792. }
  36793. module.exports = pickByArray;
  36794. },{"326":326}],319:[function(_dereq_,module,exports){
  36795. var baseForIn = _dereq_(257);
  36796. /**
  36797. * A specialized version of `_.pick` which picks `object` properties `predicate`
  36798. * returns truthy for.
  36799. *
  36800. * @private
  36801. * @param {Object} object The source object.
  36802. * @param {Function} predicate The function invoked per iteration.
  36803. * @returns {Object} Returns the new object.
  36804. */
  36805. function pickByCallback(object, predicate) {
  36806. var result = {};
  36807. baseForIn(object, function(value, key, object) {
  36808. if (predicate(value, key, object)) {
  36809. result[key] = value;
  36810. }
  36811. });
  36812. return result;
  36813. }
  36814. module.exports = pickByCallback;
  36815. },{"257":257}],320:[function(_dereq_,module,exports){
  36816. /** Used to lookup unminified function names. */
  36817. var realNames = {};
  36818. module.exports = realNames;
  36819. },{}],321:[function(_dereq_,module,exports){
  36820. var arrayCopy = _dereq_(234),
  36821. isIndex = _dereq_(309);
  36822. /* Native method references for those with the same name as other `lodash` methods. */
  36823. var nativeMin = Math.min;
  36824. /**
  36825. * Reorder `array` according to the specified indexes where the element at
  36826. * the first index is assigned as the first element, the element at
  36827. * the second index is assigned as the second element, and so on.
  36828. *
  36829. * @private
  36830. * @param {Array} array The array to reorder.
  36831. * @param {Array} indexes The arranged array indexes.
  36832. * @returns {Array} Returns `array`.
  36833. */
  36834. function reorder(array, indexes) {
  36835. var arrLength = array.length,
  36836. length = nativeMin(indexes.length, arrLength),
  36837. oldArray = arrayCopy(array);
  36838. while (length--) {
  36839. var index = indexes[length];
  36840. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  36841. }
  36842. return array;
  36843. }
  36844. module.exports = reorder;
  36845. },{"234":234,"309":309}],322:[function(_dereq_,module,exports){
  36846. /** Used as the internal argument placeholder. */
  36847. var PLACEHOLDER = '__lodash_placeholder__';
  36848. /**
  36849. * Replaces all `placeholder` elements in `array` with an internal placeholder
  36850. * and returns an array of their indexes.
  36851. *
  36852. * @private
  36853. * @param {Array} array The array to modify.
  36854. * @param {*} placeholder The placeholder to replace.
  36855. * @returns {Array} Returns the new array of placeholder indexes.
  36856. */
  36857. function replaceHolders(array, placeholder) {
  36858. var index = -1,
  36859. length = array.length,
  36860. resIndex = -1,
  36861. result = [];
  36862. while (++index < length) {
  36863. if (array[index] === placeholder) {
  36864. array[index] = PLACEHOLDER;
  36865. result[++resIndex] = index;
  36866. }
  36867. }
  36868. return result;
  36869. }
  36870. module.exports = replaceHolders;
  36871. },{}],323:[function(_dereq_,module,exports){
  36872. var baseSetData = _dereq_(273),
  36873. now = _dereq_(226);
  36874. /** Used to detect when a function becomes hot. */
  36875. var HOT_COUNT = 150,
  36876. HOT_SPAN = 16;
  36877. /**
  36878. * Sets metadata for `func`.
  36879. *
  36880. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  36881. * period of time, it will trip its breaker and transition to an identity function
  36882. * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
  36883. * for more details.
  36884. *
  36885. * @private
  36886. * @param {Function} func The function to associate metadata with.
  36887. * @param {*} data The metadata.
  36888. * @returns {Function} Returns `func`.
  36889. */
  36890. var setData = (function() {
  36891. var count = 0,
  36892. lastCalled = 0;
  36893. return function(key, value) {
  36894. var stamp = now(),
  36895. remaining = HOT_SPAN - (stamp - lastCalled);
  36896. lastCalled = stamp;
  36897. if (remaining > 0) {
  36898. if (++count >= HOT_COUNT) {
  36899. return key;
  36900. }
  36901. } else {
  36902. count = 0;
  36903. }
  36904. return baseSetData(key, value);
  36905. };
  36906. }());
  36907. module.exports = setData;
  36908. },{"226":226,"273":273}],324:[function(_dereq_,module,exports){
  36909. var isArguments = _dereq_(329),
  36910. isArray = _dereq_(330),
  36911. isIndex = _dereq_(309),
  36912. isLength = _dereq_(313),
  36913. keysIn = _dereq_(341);
  36914. /** Used for native method references. */
  36915. var objectProto = Object.prototype;
  36916. /** Used to check objects for own properties. */
  36917. var hasOwnProperty = objectProto.hasOwnProperty;
  36918. /**
  36919. * A fallback implementation of `Object.keys` which creates an array of the
  36920. * own enumerable property names of `object`.
  36921. *
  36922. * @private
  36923. * @param {Object} object The object to query.
  36924. * @returns {Array} Returns the array of property names.
  36925. */
  36926. function shimKeys(object) {
  36927. var props = keysIn(object),
  36928. propsLength = props.length,
  36929. length = propsLength && object.length;
  36930. var allowIndexes = !!length && isLength(length) &&
  36931. (isArray(object) || isArguments(object));
  36932. var index = -1,
  36933. result = [];
  36934. while (++index < propsLength) {
  36935. var key = props[index];
  36936. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  36937. result.push(key);
  36938. }
  36939. }
  36940. return result;
  36941. }
  36942. module.exports = shimKeys;
  36943. },{"309":309,"313":313,"329":329,"330":330,"341":341}],325:[function(_dereq_,module,exports){
  36944. /**
  36945. * An implementation of `_.uniq` optimized for sorted arrays without support
  36946. * for callback shorthands and `this` binding.
  36947. *
  36948. * @private
  36949. * @param {Array} array The array to inspect.
  36950. * @param {Function} [iteratee] The function invoked per iteration.
  36951. * @returns {Array} Returns the new duplicate free array.
  36952. */
  36953. function sortedUniq(array, iteratee) {
  36954. var seen,
  36955. index = -1,
  36956. length = array.length,
  36957. resIndex = -1,
  36958. result = [];
  36959. while (++index < length) {
  36960. var value = array[index],
  36961. computed = iteratee ? iteratee(value, index, array) : value;
  36962. if (!index || seen !== computed) {
  36963. seen = computed;
  36964. result[++resIndex] = value;
  36965. }
  36966. }
  36967. return result;
  36968. }
  36969. module.exports = sortedUniq;
  36970. },{}],326:[function(_dereq_,module,exports){
  36971. var isObject = _dereq_(334);
  36972. /**
  36973. * Converts `value` to an object if it's not one.
  36974. *
  36975. * @private
  36976. * @param {*} value The value to process.
  36977. * @returns {Object} Returns the object.
  36978. */
  36979. function toObject(value) {
  36980. return isObject(value) ? value : Object(value);
  36981. }
  36982. module.exports = toObject;
  36983. },{"334":334}],327:[function(_dereq_,module,exports){
  36984. var baseToString = _dereq_(277),
  36985. isArray = _dereq_(330);
  36986. /** Used to match property names within property paths. */
  36987. var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
  36988. /** Used to match backslashes in property paths. */
  36989. var reEscapeChar = /\\(\\)?/g;
  36990. /**
  36991. * Converts `value` to property path array if it's not one.
  36992. *
  36993. * @private
  36994. * @param {*} value The value to process.
  36995. * @returns {Array} Returns the property path array.
  36996. */
  36997. function toPath(value) {
  36998. if (isArray(value)) {
  36999. return value;
  37000. }
  37001. var result = [];
  37002. baseToString(value).replace(rePropName, function(match, number, quote, string) {
  37003. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  37004. });
  37005. return result;
  37006. }
  37007. module.exports = toPath;
  37008. },{"277":277,"330":330}],328:[function(_dereq_,module,exports){
  37009. var LazyWrapper = _dereq_(231),
  37010. LodashWrapper = _dereq_(232),
  37011. arrayCopy = _dereq_(234);
  37012. /**
  37013. * Creates a clone of `wrapper`.
  37014. *
  37015. * @private
  37016. * @param {Object} wrapper The wrapper to clone.
  37017. * @returns {Object} Returns the cloned wrapper.
  37018. */
  37019. function wrapperClone(wrapper) {
  37020. return wrapper instanceof LazyWrapper
  37021. ? wrapper.clone()
  37022. : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
  37023. }
  37024. module.exports = wrapperClone;
  37025. },{"231":231,"232":232,"234":234}],329:[function(_dereq_,module,exports){
  37026. var isArrayLike = _dereq_(308),
  37027. isObjectLike = _dereq_(314);
  37028. /** Used for native method references. */
  37029. var objectProto = Object.prototype;
  37030. /** Used to check objects for own properties. */
  37031. var hasOwnProperty = objectProto.hasOwnProperty;
  37032. /** Native method references. */
  37033. var propertyIsEnumerable = objectProto.propertyIsEnumerable;
  37034. /**
  37035. * Checks if `value` is classified as an `arguments` object.
  37036. *
  37037. * @static
  37038. * @memberOf _
  37039. * @category Lang
  37040. * @param {*} value The value to check.
  37041. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  37042. * @example
  37043. *
  37044. * _.isArguments(function() { return arguments; }());
  37045. * // => true
  37046. *
  37047. * _.isArguments([1, 2, 3]);
  37048. * // => false
  37049. */
  37050. function isArguments(value) {
  37051. return isObjectLike(value) && isArrayLike(value) &&
  37052. hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  37053. }
  37054. module.exports = isArguments;
  37055. },{"308":308,"314":314}],330:[function(_dereq_,module,exports){
  37056. var getNative = _dereq_(306),
  37057. isLength = _dereq_(313),
  37058. isObjectLike = _dereq_(314);
  37059. /** `Object#toString` result references. */
  37060. var arrayTag = '[object Array]';
  37061. /** Used for native method references. */
  37062. var objectProto = Object.prototype;
  37063. /**
  37064. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  37065. * of values.
  37066. */
  37067. var objToString = objectProto.toString;
  37068. /* Native method references for those with the same name as other `lodash` methods. */
  37069. var nativeIsArray = getNative(Array, 'isArray');
  37070. /**
  37071. * Checks if `value` is classified as an `Array` object.
  37072. *
  37073. * @static
  37074. * @memberOf _
  37075. * @category Lang
  37076. * @param {*} value The value to check.
  37077. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  37078. * @example
  37079. *
  37080. * _.isArray([1, 2, 3]);
  37081. * // => true
  37082. *
  37083. * _.isArray(function() { return arguments; }());
  37084. * // => false
  37085. */
  37086. var isArray = nativeIsArray || function(value) {
  37087. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  37088. };
  37089. module.exports = isArray;
  37090. },{"306":306,"313":313,"314":314}],331:[function(_dereq_,module,exports){
  37091. var isObject = _dereq_(334);
  37092. /** `Object#toString` result references. */
  37093. var funcTag = '[object Function]';
  37094. /** Used for native method references. */
  37095. var objectProto = Object.prototype;
  37096. /**
  37097. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  37098. * of values.
  37099. */
  37100. var objToString = objectProto.toString;
  37101. /**
  37102. * Checks if `value` is classified as a `Function` object.
  37103. *
  37104. * @static
  37105. * @memberOf _
  37106. * @category Lang
  37107. * @param {*} value The value to check.
  37108. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  37109. * @example
  37110. *
  37111. * _.isFunction(_);
  37112. * // => true
  37113. *
  37114. * _.isFunction(/abc/);
  37115. * // => false
  37116. */
  37117. function isFunction(value) {
  37118. // The use of `Object#toString` avoids issues with the `typeof` operator
  37119. // in older versions of Chrome and Safari which return 'function' for regexes
  37120. // and Safari 8 which returns 'object' for typed array constructors.
  37121. return isObject(value) && objToString.call(value) == funcTag;
  37122. }
  37123. module.exports = isFunction;
  37124. },{"334":334}],332:[function(_dereq_,module,exports){
  37125. var isFunction = _dereq_(331),
  37126. isObjectLike = _dereq_(314);
  37127. /** Used to detect host constructors (Safari > 5). */
  37128. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  37129. /** Used for native method references. */
  37130. var objectProto = Object.prototype;
  37131. /** Used to resolve the decompiled source of functions. */
  37132. var fnToString = Function.prototype.toString;
  37133. /** Used to check objects for own properties. */
  37134. var hasOwnProperty = objectProto.hasOwnProperty;
  37135. /** Used to detect if a method is native. */
  37136. var reIsNative = RegExp('^' +
  37137. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  37138. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  37139. );
  37140. /**
  37141. * Checks if `value` is a native function.
  37142. *
  37143. * @static
  37144. * @memberOf _
  37145. * @category Lang
  37146. * @param {*} value The value to check.
  37147. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  37148. * @example
  37149. *
  37150. * _.isNative(Array.prototype.push);
  37151. * // => true
  37152. *
  37153. * _.isNative(_);
  37154. * // => false
  37155. */
  37156. function isNative(value) {
  37157. if (value == null) {
  37158. return false;
  37159. }
  37160. if (isFunction(value)) {
  37161. return reIsNative.test(fnToString.call(value));
  37162. }
  37163. return isObjectLike(value) && reIsHostCtor.test(value);
  37164. }
  37165. module.exports = isNative;
  37166. },{"314":314,"331":331}],333:[function(_dereq_,module,exports){
  37167. var isObjectLike = _dereq_(314);
  37168. /** `Object#toString` result references. */
  37169. var numberTag = '[object Number]';
  37170. /** Used for native method references. */
  37171. var objectProto = Object.prototype;
  37172. /**
  37173. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  37174. * of values.
  37175. */
  37176. var objToString = objectProto.toString;
  37177. /**
  37178. * Checks if `value` is classified as a `Number` primitive or object.
  37179. *
  37180. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
  37181. * as numbers, use the `_.isFinite` method.
  37182. *
  37183. * @static
  37184. * @memberOf _
  37185. * @category Lang
  37186. * @param {*} value The value to check.
  37187. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  37188. * @example
  37189. *
  37190. * _.isNumber(8.4);
  37191. * // => true
  37192. *
  37193. * _.isNumber(NaN);
  37194. * // => true
  37195. *
  37196. * _.isNumber('8.4');
  37197. * // => false
  37198. */
  37199. function isNumber(value) {
  37200. return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
  37201. }
  37202. module.exports = isNumber;
  37203. },{"314":314}],334:[function(_dereq_,module,exports){
  37204. /**
  37205. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  37206. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  37207. *
  37208. * @static
  37209. * @memberOf _
  37210. * @category Lang
  37211. * @param {*} value The value to check.
  37212. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  37213. * @example
  37214. *
  37215. * _.isObject({});
  37216. * // => true
  37217. *
  37218. * _.isObject([1, 2, 3]);
  37219. * // => true
  37220. *
  37221. * _.isObject(1);
  37222. * // => false
  37223. */
  37224. function isObject(value) {
  37225. // Avoid a V8 JIT bug in Chrome 19-20.
  37226. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  37227. var type = typeof value;
  37228. return !!value && (type == 'object' || type == 'function');
  37229. }
  37230. module.exports = isObject;
  37231. },{}],335:[function(_dereq_,module,exports){
  37232. var baseForIn = _dereq_(257),
  37233. isArguments = _dereq_(329),
  37234. isObjectLike = _dereq_(314);
  37235. /** `Object#toString` result references. */
  37236. var objectTag = '[object Object]';
  37237. /** Used for native method references. */
  37238. var objectProto = Object.prototype;
  37239. /** Used to check objects for own properties. */
  37240. var hasOwnProperty = objectProto.hasOwnProperty;
  37241. /**
  37242. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  37243. * of values.
  37244. */
  37245. var objToString = objectProto.toString;
  37246. /**
  37247. * Checks if `value` is a plain object, that is, an object created by the
  37248. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  37249. *
  37250. * **Note:** This method assumes objects created by the `Object` constructor
  37251. * have no inherited enumerable properties.
  37252. *
  37253. * @static
  37254. * @memberOf _
  37255. * @category Lang
  37256. * @param {*} value The value to check.
  37257. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  37258. * @example
  37259. *
  37260. * function Foo() {
  37261. * this.a = 1;
  37262. * }
  37263. *
  37264. * _.isPlainObject(new Foo);
  37265. * // => false
  37266. *
  37267. * _.isPlainObject([1, 2, 3]);
  37268. * // => false
  37269. *
  37270. * _.isPlainObject({ 'x': 0, 'y': 0 });
  37271. * // => true
  37272. *
  37273. * _.isPlainObject(Object.create(null));
  37274. * // => true
  37275. */
  37276. function isPlainObject(value) {
  37277. var Ctor;
  37278. // Exit early for non `Object` objects.
  37279. if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
  37280. (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
  37281. return false;
  37282. }
  37283. // IE < 9 iterates inherited properties before own properties. If the first
  37284. // iterated property is an object's own property then there are no inherited
  37285. // enumerable properties.
  37286. var result;
  37287. // In most environments an object's own properties are iterated before
  37288. // its inherited properties. If the last iterated property is an object's
  37289. // own property then there are no inherited enumerable properties.
  37290. baseForIn(value, function(subValue, key) {
  37291. result = key;
  37292. });
  37293. return result === undefined || hasOwnProperty.call(value, result);
  37294. }
  37295. module.exports = isPlainObject;
  37296. },{"257":257,"314":314,"329":329}],336:[function(_dereq_,module,exports){
  37297. var isObjectLike = _dereq_(314);
  37298. /** `Object#toString` result references. */
  37299. var stringTag = '[object String]';
  37300. /** Used for native method references. */
  37301. var objectProto = Object.prototype;
  37302. /**
  37303. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  37304. * of values.
  37305. */
  37306. var objToString = objectProto.toString;
  37307. /**
  37308. * Checks if `value` is classified as a `String` primitive or object.
  37309. *
  37310. * @static
  37311. * @memberOf _
  37312. * @category Lang
  37313. * @param {*} value The value to check.
  37314. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  37315. * @example
  37316. *
  37317. * _.isString('abc');
  37318. * // => true
  37319. *
  37320. * _.isString(1);
  37321. * // => false
  37322. */
  37323. function isString(value) {
  37324. return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
  37325. }
  37326. module.exports = isString;
  37327. },{"314":314}],337:[function(_dereq_,module,exports){
  37328. var isLength = _dereq_(313),
  37329. isObjectLike = _dereq_(314);
  37330. /** `Object#toString` result references. */
  37331. var argsTag = '[object Arguments]',
  37332. arrayTag = '[object Array]',
  37333. boolTag = '[object Boolean]',
  37334. dateTag = '[object Date]',
  37335. errorTag = '[object Error]',
  37336. funcTag = '[object Function]',
  37337. mapTag = '[object Map]',
  37338. numberTag = '[object Number]',
  37339. objectTag = '[object Object]',
  37340. regexpTag = '[object RegExp]',
  37341. setTag = '[object Set]',
  37342. stringTag = '[object String]',
  37343. weakMapTag = '[object WeakMap]';
  37344. var arrayBufferTag = '[object ArrayBuffer]',
  37345. float32Tag = '[object Float32Array]',
  37346. float64Tag = '[object Float64Array]',
  37347. int8Tag = '[object Int8Array]',
  37348. int16Tag = '[object Int16Array]',
  37349. int32Tag = '[object Int32Array]',
  37350. uint8Tag = '[object Uint8Array]',
  37351. uint8ClampedTag = '[object Uint8ClampedArray]',
  37352. uint16Tag = '[object Uint16Array]',
  37353. uint32Tag = '[object Uint32Array]';
  37354. /** Used to identify `toStringTag` values of typed arrays. */
  37355. var typedArrayTags = {};
  37356. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  37357. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  37358. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  37359. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  37360. typedArrayTags[uint32Tag] = true;
  37361. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  37362. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  37363. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  37364. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  37365. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  37366. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  37367. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  37368. /** Used for native method references. */
  37369. var objectProto = Object.prototype;
  37370. /**
  37371. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  37372. * of values.
  37373. */
  37374. var objToString = objectProto.toString;
  37375. /**
  37376. * Checks if `value` is classified as a typed array.
  37377. *
  37378. * @static
  37379. * @memberOf _
  37380. * @category Lang
  37381. * @param {*} value The value to check.
  37382. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  37383. * @example
  37384. *
  37385. * _.isTypedArray(new Uint8Array);
  37386. * // => true
  37387. *
  37388. * _.isTypedArray([]);
  37389. * // => false
  37390. */
  37391. function isTypedArray(value) {
  37392. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
  37393. }
  37394. module.exports = isTypedArray;
  37395. },{"313":313,"314":314}],338:[function(_dereq_,module,exports){
  37396. var baseCopy = _dereq_(246),
  37397. keysIn = _dereq_(341);
  37398. /**
  37399. * Converts `value` to a plain object flattening inherited enumerable
  37400. * properties of `value` to own properties of the plain object.
  37401. *
  37402. * @static
  37403. * @memberOf _
  37404. * @category Lang
  37405. * @param {*} value The value to convert.
  37406. * @returns {Object} Returns the converted plain object.
  37407. * @example
  37408. *
  37409. * function Foo() {
  37410. * this.b = 2;
  37411. * }
  37412. *
  37413. * Foo.prototype.c = 3;
  37414. *
  37415. * _.assign({ 'a': 1 }, new Foo);
  37416. * // => { 'a': 1, 'b': 2 }
  37417. *
  37418. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  37419. * // => { 'a': 1, 'b': 2, 'c': 3 }
  37420. */
  37421. function toPlainObject(value) {
  37422. return baseCopy(value, keysIn(value));
  37423. }
  37424. module.exports = toPlainObject;
  37425. },{"246":246,"341":341}],339:[function(_dereq_,module,exports){
  37426. var assignWith = _dereq_(242),
  37427. baseAssign = _dereq_(243),
  37428. createAssigner = _dereq_(287);
  37429. /**
  37430. * Assigns own enumerable properties of source object(s) to the destination
  37431. * object. Subsequent sources overwrite property assignments of previous sources.
  37432. * If `customizer` is provided it's invoked to produce the assigned values.
  37433. * The `customizer` is bound to `thisArg` and invoked with five arguments:
  37434. * (objectValue, sourceValue, key, object, source).
  37435. *
  37436. * **Note:** This method mutates `object` and is based on
  37437. * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
  37438. *
  37439. * @static
  37440. * @memberOf _
  37441. * @alias extend
  37442. * @category Object
  37443. * @param {Object} object The destination object.
  37444. * @param {...Object} [sources] The source objects.
  37445. * @param {Function} [customizer] The function to customize assigned values.
  37446. * @param {*} [thisArg] The `this` binding of `customizer`.
  37447. * @returns {Object} Returns `object`.
  37448. * @example
  37449. *
  37450. * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
  37451. * // => { 'user': 'fred', 'age': 40 }
  37452. *
  37453. * // using a customizer callback
  37454. * var defaults = _.partialRight(_.assign, function(value, other) {
  37455. * return _.isUndefined(value) ? other : value;
  37456. * });
  37457. *
  37458. * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  37459. * // => { 'user': 'barney', 'age': 36 }
  37460. */
  37461. var assign = createAssigner(function(object, source, customizer) {
  37462. return customizer
  37463. ? assignWith(object, source, customizer)
  37464. : baseAssign(object, source);
  37465. });
  37466. module.exports = assign;
  37467. },{"242":242,"243":243,"287":287}],340:[function(_dereq_,module,exports){
  37468. var getNative = _dereq_(306),
  37469. isArrayLike = _dereq_(308),
  37470. isObject = _dereq_(334),
  37471. shimKeys = _dereq_(324);
  37472. /* Native method references for those with the same name as other `lodash` methods. */
  37473. var nativeKeys = getNative(Object, 'keys');
  37474. /**
  37475. * Creates an array of the own enumerable property names of `object`.
  37476. *
  37477. * **Note:** Non-object values are coerced to objects. See the
  37478. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  37479. * for more details.
  37480. *
  37481. * @static
  37482. * @memberOf _
  37483. * @category Object
  37484. * @param {Object} object The object to query.
  37485. * @returns {Array} Returns the array of property names.
  37486. * @example
  37487. *
  37488. * function Foo() {
  37489. * this.a = 1;
  37490. * this.b = 2;
  37491. * }
  37492. *
  37493. * Foo.prototype.c = 3;
  37494. *
  37495. * _.keys(new Foo);
  37496. * // => ['a', 'b'] (iteration order is not guaranteed)
  37497. *
  37498. * _.keys('hi');
  37499. * // => ['0', '1']
  37500. */
  37501. var keys = !nativeKeys ? shimKeys : function(object) {
  37502. var Ctor = object == null ? undefined : object.constructor;
  37503. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  37504. (typeof object != 'function' && isArrayLike(object))) {
  37505. return shimKeys(object);
  37506. }
  37507. return isObject(object) ? nativeKeys(object) : [];
  37508. };
  37509. module.exports = keys;
  37510. },{"306":306,"308":308,"324":324,"334":334}],341:[function(_dereq_,module,exports){
  37511. var isArguments = _dereq_(329),
  37512. isArray = _dereq_(330),
  37513. isIndex = _dereq_(309),
  37514. isLength = _dereq_(313),
  37515. isObject = _dereq_(334);
  37516. /** Used for native method references. */
  37517. var objectProto = Object.prototype;
  37518. /** Used to check objects for own properties. */
  37519. var hasOwnProperty = objectProto.hasOwnProperty;
  37520. /**
  37521. * Creates an array of the own and inherited enumerable property names of `object`.
  37522. *
  37523. * **Note:** Non-object values are coerced to objects.
  37524. *
  37525. * @static
  37526. * @memberOf _
  37527. * @category Object
  37528. * @param {Object} object The object to query.
  37529. * @returns {Array} Returns the array of property names.
  37530. * @example
  37531. *
  37532. * function Foo() {
  37533. * this.a = 1;
  37534. * this.b = 2;
  37535. * }
  37536. *
  37537. * Foo.prototype.c = 3;
  37538. *
  37539. * _.keysIn(new Foo);
  37540. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  37541. */
  37542. function keysIn(object) {
  37543. if (object == null) {
  37544. return [];
  37545. }
  37546. if (!isObject(object)) {
  37547. object = Object(object);
  37548. }
  37549. var length = object.length;
  37550. length = (length && isLength(length) &&
  37551. (isArray(object) || isArguments(object)) && length) || 0;
  37552. var Ctor = object.constructor,
  37553. index = -1,
  37554. isProto = typeof Ctor == 'function' && Ctor.prototype === object,
  37555. result = Array(length),
  37556. skipIndexes = length > 0;
  37557. while (++index < length) {
  37558. result[index] = (index + '');
  37559. }
  37560. for (var key in object) {
  37561. if (!(skipIndexes && isIndex(key, length)) &&
  37562. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  37563. result.push(key);
  37564. }
  37565. }
  37566. return result;
  37567. }
  37568. module.exports = keysIn;
  37569. },{"309":309,"313":313,"329":329,"330":330,"334":334}],342:[function(_dereq_,module,exports){
  37570. var baseMerge = _dereq_(268),
  37571. createAssigner = _dereq_(287);
  37572. /**
  37573. * Recursively merges own enumerable properties of the source object(s), that
  37574. * don't resolve to `undefined` into the destination object. Subsequent sources
  37575. * overwrite property assignments of previous sources. If `customizer` is
  37576. * provided it's invoked to produce the merged values of the destination and
  37577. * source properties. If `customizer` returns `undefined` merging is handled
  37578. * by the method instead. The `customizer` is bound to `thisArg` and invoked
  37579. * with five arguments: (objectValue, sourceValue, key, object, source).
  37580. *
  37581. * @static
  37582. * @memberOf _
  37583. * @category Object
  37584. * @param {Object} object The destination object.
  37585. * @param {...Object} [sources] The source objects.
  37586. * @param {Function} [customizer] The function to customize assigned values.
  37587. * @param {*} [thisArg] The `this` binding of `customizer`.
  37588. * @returns {Object} Returns `object`.
  37589. * @example
  37590. *
  37591. * var users = {
  37592. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  37593. * };
  37594. *
  37595. * var ages = {
  37596. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  37597. * };
  37598. *
  37599. * _.merge(users, ages);
  37600. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  37601. *
  37602. * // using a customizer callback
  37603. * var object = {
  37604. * 'fruits': ['apple'],
  37605. * 'vegetables': ['beet']
  37606. * };
  37607. *
  37608. * var other = {
  37609. * 'fruits': ['banana'],
  37610. * 'vegetables': ['carrot']
  37611. * };
  37612. *
  37613. * _.merge(object, other, function(a, b) {
  37614. * if (_.isArray(a)) {
  37615. * return a.concat(b);
  37616. * }
  37617. * });
  37618. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  37619. */
  37620. var merge = createAssigner(baseMerge);
  37621. module.exports = merge;
  37622. },{"268":268,"287":287}],343:[function(_dereq_,module,exports){
  37623. var arrayMap = _dereq_(238),
  37624. baseDifference = _dereq_(249),
  37625. baseFlatten = _dereq_(255),
  37626. bindCallback = _dereq_(280),
  37627. keysIn = _dereq_(341),
  37628. pickByArray = _dereq_(318),
  37629. pickByCallback = _dereq_(319),
  37630. restParam = _dereq_(230);
  37631. /**
  37632. * The opposite of `_.pick`; this method creates an object composed of the
  37633. * own and inherited enumerable properties of `object` that are not omitted.
  37634. *
  37635. * @static
  37636. * @memberOf _
  37637. * @category Object
  37638. * @param {Object} object The source object.
  37639. * @param {Function|...(string|string[])} [predicate] The function invoked per
  37640. * iteration or property names to omit, specified as individual property
  37641. * names or arrays of property names.
  37642. * @param {*} [thisArg] The `this` binding of `predicate`.
  37643. * @returns {Object} Returns the new object.
  37644. * @example
  37645. *
  37646. * var object = { 'user': 'fred', 'age': 40 };
  37647. *
  37648. * _.omit(object, 'age');
  37649. * // => { 'user': 'fred' }
  37650. *
  37651. * _.omit(object, _.isNumber);
  37652. * // => { 'user': 'fred' }
  37653. */
  37654. var omit = restParam(function(object, props) {
  37655. if (object == null) {
  37656. return {};
  37657. }
  37658. if (typeof props[0] != 'function') {
  37659. var props = arrayMap(baseFlatten(props), String);
  37660. return pickByArray(object, baseDifference(keysIn(object), props));
  37661. }
  37662. var predicate = bindCallback(props[0], props[1], 3);
  37663. return pickByCallback(object, function(value, key, object) {
  37664. return !predicate(value, key, object);
  37665. });
  37666. });
  37667. module.exports = omit;
  37668. },{"230":230,"238":238,"249":249,"255":255,"280":280,"318":318,"319":319,"341":341}],344:[function(_dereq_,module,exports){
  37669. var keys = _dereq_(340),
  37670. toObject = _dereq_(326);
  37671. /**
  37672. * Creates a two dimensional array of the key-value pairs for `object`,
  37673. * e.g. `[[key1, value1], [key2, value2]]`.
  37674. *
  37675. * @static
  37676. * @memberOf _
  37677. * @category Object
  37678. * @param {Object} object The object to query.
  37679. * @returns {Array} Returns the new array of key-value pairs.
  37680. * @example
  37681. *
  37682. * _.pairs({ 'barney': 36, 'fred': 40 });
  37683. * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
  37684. */
  37685. function pairs(object) {
  37686. object = toObject(object);
  37687. var index = -1,
  37688. props = keys(object),
  37689. length = props.length,
  37690. result = Array(length);
  37691. while (++index < length) {
  37692. var key = props[index];
  37693. result[index] = [key, object[key]];
  37694. }
  37695. return result;
  37696. }
  37697. module.exports = pairs;
  37698. },{"326":326,"340":340}],345:[function(_dereq_,module,exports){
  37699. var baseFlatten = _dereq_(255),
  37700. bindCallback = _dereq_(280),
  37701. pickByArray = _dereq_(318),
  37702. pickByCallback = _dereq_(319),
  37703. restParam = _dereq_(230);
  37704. /**
  37705. * Creates an object composed of the picked `object` properties. Property
  37706. * names may be specified as individual arguments or as arrays of property
  37707. * names. If `predicate` is provided it's invoked for each property of `object`
  37708. * picking the properties `predicate` returns truthy for. The predicate is
  37709. * bound to `thisArg` and invoked with three arguments: (value, key, object).
  37710. *
  37711. * @static
  37712. * @memberOf _
  37713. * @category Object
  37714. * @param {Object} object The source object.
  37715. * @param {Function|...(string|string[])} [predicate] The function invoked per
  37716. * iteration or property names to pick, specified as individual property
  37717. * names or arrays of property names.
  37718. * @param {*} [thisArg] The `this` binding of `predicate`.
  37719. * @returns {Object} Returns the new object.
  37720. * @example
  37721. *
  37722. * var object = { 'user': 'fred', 'age': 40 };
  37723. *
  37724. * _.pick(object, 'user');
  37725. * // => { 'user': 'fred' }
  37726. *
  37727. * _.pick(object, _.isString);
  37728. * // => { 'user': 'fred' }
  37729. */
  37730. var pick = restParam(function(object, props) {
  37731. if (object == null) {
  37732. return {};
  37733. }
  37734. return typeof props[0] == 'function'
  37735. ? pickByCallback(object, bindCallback(props[0], props[1], 3))
  37736. : pickByArray(object, baseFlatten(props));
  37737. });
  37738. module.exports = pick;
  37739. },{"230":230,"255":255,"280":280,"318":318,"319":319}],346:[function(_dereq_,module,exports){
  37740. var arrayEach = _dereq_(235),
  37741. baseCallback = _dereq_(244),
  37742. baseCreate = _dereq_(247),
  37743. baseForOwn = _dereq_(258),
  37744. isArray = _dereq_(330),
  37745. isFunction = _dereq_(331),
  37746. isObject = _dereq_(334),
  37747. isTypedArray = _dereq_(337);
  37748. /**
  37749. * An alternative to `_.reduce`; this method transforms `object` to a new
  37750. * `accumulator` object which is the result of running each of its own enumerable
  37751. * properties through `iteratee`, with each invocation potentially mutating
  37752. * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
  37753. * with four arguments: (accumulator, value, key, object). Iteratee functions
  37754. * may exit iteration early by explicitly returning `false`.
  37755. *
  37756. * @static
  37757. * @memberOf _
  37758. * @category Object
  37759. * @param {Array|Object} object The object to iterate over.
  37760. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  37761. * @param {*} [accumulator] The custom accumulator value.
  37762. * @param {*} [thisArg] The `this` binding of `iteratee`.
  37763. * @returns {*} Returns the accumulated value.
  37764. * @example
  37765. *
  37766. * _.transform([2, 3, 4], function(result, n) {
  37767. * result.push(n *= n);
  37768. * return n % 2 == 0;
  37769. * });
  37770. * // => [4, 9]
  37771. *
  37772. * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
  37773. * result[key] = n * 3;
  37774. * });
  37775. * // => { 'a': 3, 'b': 6 }
  37776. */
  37777. function transform(object, iteratee, accumulator, thisArg) {
  37778. var isArr = isArray(object) || isTypedArray(object);
  37779. iteratee = baseCallback(iteratee, thisArg, 4);
  37780. if (accumulator == null) {
  37781. if (isArr || isObject(object)) {
  37782. var Ctor = object.constructor;
  37783. if (isArr) {
  37784. accumulator = isArray(object) ? new Ctor : [];
  37785. } else {
  37786. accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
  37787. }
  37788. } else {
  37789. accumulator = {};
  37790. }
  37791. }
  37792. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  37793. return iteratee(accumulator, value, index, object);
  37794. });
  37795. return accumulator;
  37796. }
  37797. module.exports = transform;
  37798. },{"235":235,"244":244,"247":247,"258":258,"330":330,"331":331,"334":334,"337":337}],347:[function(_dereq_,module,exports){
  37799. var baseValues = _dereq_(279),
  37800. keys = _dereq_(340);
  37801. /**
  37802. * Creates an array of the own enumerable property values of `object`.
  37803. *
  37804. * **Note:** Non-object values are coerced to objects.
  37805. *
  37806. * @static
  37807. * @memberOf _
  37808. * @category Object
  37809. * @param {Object} object The object to query.
  37810. * @returns {Array} Returns the array of property values.
  37811. * @example
  37812. *
  37813. * function Foo() {
  37814. * this.a = 1;
  37815. * this.b = 2;
  37816. * }
  37817. *
  37818. * Foo.prototype.c = 3;
  37819. *
  37820. * _.values(new Foo);
  37821. * // => [1, 2] (iteration order is not guaranteed)
  37822. *
  37823. * _.values('hi');
  37824. * // => ['h', 'i']
  37825. */
  37826. function values(object) {
  37827. return baseValues(object, keys(object));
  37828. }
  37829. module.exports = values;
  37830. },{"279":279,"340":340}],348:[function(_dereq_,module,exports){
  37831. /**
  37832. * This method returns the first argument provided to it.
  37833. *
  37834. * @static
  37835. * @memberOf _
  37836. * @category Utility
  37837. * @param {*} value Any value.
  37838. * @returns {*} Returns `value`.
  37839. * @example
  37840. *
  37841. * var object = { 'user': 'fred' };
  37842. *
  37843. * _.identity(object) === object;
  37844. * // => true
  37845. */
  37846. function identity(value) {
  37847. return value;
  37848. }
  37849. module.exports = identity;
  37850. },{}],349:[function(_dereq_,module,exports){
  37851. /**
  37852. * A no-operation function that returns `undefined` regardless of the
  37853. * arguments it receives.
  37854. *
  37855. * @static
  37856. * @memberOf _
  37857. * @category Utility
  37858. * @example
  37859. *
  37860. * var object = { 'user': 'fred' };
  37861. *
  37862. * _.noop(object) === undefined;
  37863. * // => true
  37864. */
  37865. function noop() {
  37866. // No operation performed.
  37867. }
  37868. module.exports = noop;
  37869. },{}],350:[function(_dereq_,module,exports){
  37870. var baseProperty = _dereq_(270),
  37871. basePropertyDeep = _dereq_(271),
  37872. isKey = _dereq_(311);
  37873. /**
  37874. * Creates a function that returns the property value at `path` on a
  37875. * given object.
  37876. *
  37877. * @static
  37878. * @memberOf _
  37879. * @category Utility
  37880. * @param {Array|string} path The path of the property to get.
  37881. * @returns {Function} Returns the new function.
  37882. * @example
  37883. *
  37884. * var objects = [
  37885. * { 'a': { 'b': { 'c': 2 } } },
  37886. * { 'a': { 'b': { 'c': 1 } } }
  37887. * ];
  37888. *
  37889. * _.map(objects, _.property('a.b.c'));
  37890. * // => [2, 1]
  37891. *
  37892. * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
  37893. * // => [1, 2]
  37894. */
  37895. function property(path) {
  37896. return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
  37897. }
  37898. module.exports = property;
  37899. },{"270":270,"271":271,"311":311}],351:[function(_dereq_,module,exports){
  37900. /**
  37901. * Set attribute `name` to `val`, or get attr `name`.
  37902. *
  37903. * @param {Element} el
  37904. * @param {String} name
  37905. * @param {String} [val]
  37906. * @api public
  37907. */
  37908. module.exports = function(el, name, val) {
  37909. // get
  37910. if (arguments.length == 2) {
  37911. return el.getAttribute(name);
  37912. }
  37913. // remove
  37914. if (val === null) {
  37915. return el.removeAttribute(name);
  37916. }
  37917. // set
  37918. el.setAttribute(name, val);
  37919. return el;
  37920. };
  37921. },{}],352:[function(_dereq_,module,exports){
  37922. module.exports = _dereq_(361);
  37923. },{"361":361}],353:[function(_dereq_,module,exports){
  37924. module.exports = function(el) {
  37925. var c;
  37926. while (el.childNodes.length) {
  37927. c = el.childNodes[0];
  37928. el.removeChild(c);
  37929. }
  37930. return el;
  37931. };
  37932. },{}],354:[function(_dereq_,module,exports){
  37933. module.exports = _dereq_(363);
  37934. },{"363":363}],355:[function(_dereq_,module,exports){
  37935. module.exports = _dereq_(364);
  37936. },{"364":364}],356:[function(_dereq_,module,exports){
  37937. module.exports = _dereq_(368);
  37938. },{"368":368}],357:[function(_dereq_,module,exports){
  37939. module.exports = _dereq_(365);
  37940. },{"365":365}],358:[function(_dereq_,module,exports){
  37941. module.exports = _dereq_(366);
  37942. },{"366":366}],359:[function(_dereq_,module,exports){
  37943. module.exports = _dereq_(367);
  37944. },{"367":367}],360:[function(_dereq_,module,exports){
  37945. module.exports = function(el) {
  37946. el.parentNode && el.parentNode.removeChild(el);
  37947. };
  37948. },{}],361:[function(_dereq_,module,exports){
  37949. /**
  37950. * Module dependencies.
  37951. */
  37952. var index = _dereq_(362);
  37953. /**
  37954. * Whitespace regexp.
  37955. */
  37956. var re = /\s+/;
  37957. /**
  37958. * toString reference.
  37959. */
  37960. var toString = Object.prototype.toString;
  37961. /**
  37962. * Wrap `el` in a `ClassList`.
  37963. *
  37964. * @param {Element} el
  37965. * @return {ClassList}
  37966. * @api public
  37967. */
  37968. module.exports = function(el){
  37969. return new ClassList(el);
  37970. };
  37971. /**
  37972. * Initialize a new ClassList for `el`.
  37973. *
  37974. * @param {Element} el
  37975. * @api private
  37976. */
  37977. function ClassList(el) {
  37978. if (!el || !el.nodeType) {
  37979. throw new Error('A DOM element reference is required');
  37980. }
  37981. this.el = el;
  37982. this.list = el.classList;
  37983. }
  37984. /**
  37985. * Add class `name` if not already present.
  37986. *
  37987. * @param {String} name
  37988. * @return {ClassList}
  37989. * @api public
  37990. */
  37991. ClassList.prototype.add = function(name){
  37992. // classList
  37993. if (this.list) {
  37994. this.list.add(name);
  37995. return this;
  37996. }
  37997. // fallback
  37998. var arr = this.array();
  37999. var i = index(arr, name);
  38000. if (!~i) arr.push(name);
  38001. this.el.className = arr.join(' ');
  38002. return this;
  38003. };
  38004. /**
  38005. * Remove class `name` when present, or
  38006. * pass a regular expression to remove
  38007. * any which match.
  38008. *
  38009. * @param {String|RegExp} name
  38010. * @return {ClassList}
  38011. * @api public
  38012. */
  38013. ClassList.prototype.remove = function(name){
  38014. if ('[object RegExp]' == toString.call(name)) {
  38015. return this.removeMatching(name);
  38016. }
  38017. // classList
  38018. if (this.list) {
  38019. this.list.remove(name);
  38020. return this;
  38021. }
  38022. // fallback
  38023. var arr = this.array();
  38024. var i = index(arr, name);
  38025. if (~i) arr.splice(i, 1);
  38026. this.el.className = arr.join(' ');
  38027. return this;
  38028. };
  38029. /**
  38030. * Remove all classes matching `re`.
  38031. *
  38032. * @param {RegExp} re
  38033. * @return {ClassList}
  38034. * @api private
  38035. */
  38036. ClassList.prototype.removeMatching = function(re){
  38037. var arr = this.array();
  38038. for (var i = 0; i < arr.length; i++) {
  38039. if (re.test(arr[i])) {
  38040. this.remove(arr[i]);
  38041. }
  38042. }
  38043. return this;
  38044. };
  38045. /**
  38046. * Toggle class `name`, can force state via `force`.
  38047. *
  38048. * For browsers that support classList, but do not support `force` yet,
  38049. * the mistake will be detected and corrected.
  38050. *
  38051. * @param {String} name
  38052. * @param {Boolean} force
  38053. * @return {ClassList}
  38054. * @api public
  38055. */
  38056. ClassList.prototype.toggle = function(name, force){
  38057. // classList
  38058. if (this.list) {
  38059. if ("undefined" !== typeof force) {
  38060. if (force !== this.list.toggle(name, force)) {
  38061. this.list.toggle(name); // toggle again to correct
  38062. }
  38063. } else {
  38064. this.list.toggle(name);
  38065. }
  38066. return this;
  38067. }
  38068. // fallback
  38069. if ("undefined" !== typeof force) {
  38070. if (!force) {
  38071. this.remove(name);
  38072. } else {
  38073. this.add(name);
  38074. }
  38075. } else {
  38076. if (this.has(name)) {
  38077. this.remove(name);
  38078. } else {
  38079. this.add(name);
  38080. }
  38081. }
  38082. return this;
  38083. };
  38084. /**
  38085. * Return an array of classes.
  38086. *
  38087. * @return {Array}
  38088. * @api public
  38089. */
  38090. ClassList.prototype.array = function(){
  38091. var className = this.el.getAttribute('class') || '';
  38092. var str = className.replace(/^\s+|\s+$/g, '');
  38093. var arr = str.split(re);
  38094. if ('' === arr[0]) arr.shift();
  38095. return arr;
  38096. };
  38097. /**
  38098. * Check if class `name` is present.
  38099. *
  38100. * @param {String} name
  38101. * @return {ClassList}
  38102. * @api public
  38103. */
  38104. ClassList.prototype.has =
  38105. ClassList.prototype.contains = function(name){
  38106. return this.list
  38107. ? this.list.contains(name)
  38108. : !! ~index(this.array(), name);
  38109. };
  38110. },{"362":362}],362:[function(_dereq_,module,exports){
  38111. module.exports = function(arr, obj){
  38112. if (arr.indexOf) return arr.indexOf(obj);
  38113. for (var i = 0; i < arr.length; ++i) {
  38114. if (arr[i] === obj) return i;
  38115. }
  38116. return -1;
  38117. };
  38118. },{}],363:[function(_dereq_,module,exports){
  38119. var matches = _dereq_(366)
  38120. module.exports = function (element, selector, checkYoSelf, root) {
  38121. element = checkYoSelf ? {parentNode: element} : element
  38122. root = root || document
  38123. // Make sure `element !== document` and `element != null`
  38124. // otherwise we get an illegal invocation
  38125. while ((element = element.parentNode) && element !== document) {
  38126. if (matches(element, selector))
  38127. return element
  38128. // After `matches` on the edge case that
  38129. // the selector matches the root
  38130. // (when the root is not the document)
  38131. if (element === root)
  38132. return
  38133. }
  38134. }
  38135. },{"366":366}],364:[function(_dereq_,module,exports){
  38136. /**
  38137. * Module dependencies.
  38138. */
  38139. var closest = _dereq_(363)
  38140. , event = _dereq_(365);
  38141. /**
  38142. * Delegate event `type` to `selector`
  38143. * and invoke `fn(e)`. A callback function
  38144. * is returned which may be passed to `.unbind()`.
  38145. *
  38146. * @param {Element} el
  38147. * @param {String} selector
  38148. * @param {String} type
  38149. * @param {Function} fn
  38150. * @param {Boolean} capture
  38151. * @return {Function}
  38152. * @api public
  38153. */
  38154. exports.bind = function(el, selector, type, fn, capture){
  38155. return event.bind(el, type, function(e){
  38156. var target = e.target || e.srcElement;
  38157. e.delegateTarget = closest(target, selector, true, el);
  38158. if (e.delegateTarget) fn.call(el, e);
  38159. }, capture);
  38160. };
  38161. /**
  38162. * Unbind event `type`'s callback `fn`.
  38163. *
  38164. * @param {Element} el
  38165. * @param {String} type
  38166. * @param {Function} fn
  38167. * @param {Boolean} capture
  38168. * @api public
  38169. */
  38170. exports.unbind = function(el, type, fn, capture){
  38171. event.unbind(el, type, fn, capture);
  38172. };
  38173. },{"363":363,"365":365}],365:[function(_dereq_,module,exports){
  38174. var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
  38175. unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
  38176. prefix = bind !== 'addEventListener' ? 'on' : '';
  38177. /**
  38178. * Bind `el` event `type` to `fn`.
  38179. *
  38180. * @param {Element} el
  38181. * @param {String} type
  38182. * @param {Function} fn
  38183. * @param {Boolean} capture
  38184. * @return {Function}
  38185. * @api public
  38186. */
  38187. exports.bind = function(el, type, fn, capture){
  38188. el[bind](prefix + type, fn, capture || false);
  38189. return fn;
  38190. };
  38191. /**
  38192. * Unbind `el` event `type`'s callback `fn`.
  38193. *
  38194. * @param {Element} el
  38195. * @param {String} type
  38196. * @param {Function} fn
  38197. * @param {Boolean} capture
  38198. * @return {Function}
  38199. * @api public
  38200. */
  38201. exports.unbind = function(el, type, fn, capture){
  38202. el[unbind](prefix + type, fn, capture || false);
  38203. return fn;
  38204. };
  38205. },{}],366:[function(_dereq_,module,exports){
  38206. /**
  38207. * Module dependencies.
  38208. */
  38209. var query = _dereq_(367);
  38210. /**
  38211. * Element prototype.
  38212. */
  38213. var proto = Element.prototype;
  38214. /**
  38215. * Vendor function.
  38216. */
  38217. var vendor = proto.matches
  38218. || proto.webkitMatchesSelector
  38219. || proto.mozMatchesSelector
  38220. || proto.msMatchesSelector
  38221. || proto.oMatchesSelector;
  38222. /**
  38223. * Expose `match()`.
  38224. */
  38225. module.exports = match;
  38226. /**
  38227. * Match `el` to `selector`.
  38228. *
  38229. * @param {Element} el
  38230. * @param {String} selector
  38231. * @return {Boolean}
  38232. * @api public
  38233. */
  38234. function match(el, selector) {
  38235. if (!el || el.nodeType !== 1) return false;
  38236. if (vendor) return vendor.call(el, selector);
  38237. var nodes = query.all(selector, el.parentNode);
  38238. for (var i = 0; i < nodes.length; ++i) {
  38239. if (nodes[i] == el) return true;
  38240. }
  38241. return false;
  38242. }
  38243. },{"367":367}],367:[function(_dereq_,module,exports){
  38244. function one(selector, el) {
  38245. return el.querySelector(selector);
  38246. }
  38247. exports = module.exports = function(selector, el){
  38248. el = el || document;
  38249. return one(selector, el);
  38250. };
  38251. exports.all = function(selector, el){
  38252. el = el || document;
  38253. return el.querySelectorAll(selector);
  38254. };
  38255. exports.engine = function(obj){
  38256. if (!obj.one) throw new Error('.one callback required');
  38257. if (!obj.all) throw new Error('.all callback required');
  38258. one = obj.one;
  38259. exports.all = obj.all;
  38260. return exports;
  38261. };
  38262. },{}],368:[function(_dereq_,module,exports){
  38263. /**
  38264. * Expose `parse`.
  38265. */
  38266. module.exports = parse;
  38267. /**
  38268. * Tests for browser support.
  38269. */
  38270. var div = document.createElement('div');
  38271. // Setup
  38272. div.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';
  38273. // Make sure that link elements get serialized correctly by innerHTML
  38274. // This requires a wrapper element in IE
  38275. var innerHTMLBug = !div.getElementsByTagName('link').length;
  38276. div = undefined;
  38277. /**
  38278. * Wrap map from jquery.
  38279. */
  38280. var map = {
  38281. legend: [1, '<fieldset>', '</fieldset>'],
  38282. tr: [2, '<table><tbody>', '</tbody></table>'],
  38283. col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
  38284. // for script/link/style tags to work in IE6-8, you have to wrap
  38285. // in a div with a non-whitespace character in front, ha!
  38286. _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', '']
  38287. };
  38288. map.td =
  38289. map.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
  38290. map.option =
  38291. map.optgroup = [1, '<select multiple="multiple">', '</select>'];
  38292. map.thead =
  38293. map.tbody =
  38294. map.colgroup =
  38295. map.caption =
  38296. map.tfoot = [1, '<table>', '</table>'];
  38297. map.polyline =
  38298. map.ellipse =
  38299. map.polygon =
  38300. map.circle =
  38301. map.text =
  38302. map.line =
  38303. map.path =
  38304. map.rect =
  38305. map.g = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'];
  38306. /**
  38307. * Parse `html` and return a DOM Node instance, which could be a TextNode,
  38308. * HTML DOM Node of some kind (<div> for example), or a DocumentFragment
  38309. * instance, depending on the contents of the `html` string.
  38310. *
  38311. * @param {String} html - HTML string to "domify"
  38312. * @param {Document} doc - The `document` instance to create the Node for
  38313. * @return {DOMNode} the TextNode, DOM Node, or DocumentFragment instance
  38314. * @api private
  38315. */
  38316. function parse(html, doc) {
  38317. if ('string' != typeof html) throw new TypeError('String expected');
  38318. // default to the global `document` object
  38319. if (!doc) doc = document;
  38320. // tag name
  38321. var m = /<([\w:]+)/.exec(html);
  38322. if (!m) return doc.createTextNode(html);
  38323. html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace
  38324. var tag = m[1];
  38325. // body support
  38326. if (tag == 'body') {
  38327. var el = doc.createElement('html');
  38328. el.innerHTML = html;
  38329. return el.removeChild(el.lastChild);
  38330. }
  38331. // wrap map
  38332. var wrap = map[tag] || map._default;
  38333. var depth = wrap[0];
  38334. var prefix = wrap[1];
  38335. var suffix = wrap[2];
  38336. var el = doc.createElement('div');
  38337. el.innerHTML = prefix + html + suffix;
  38338. while (depth--) el = el.lastChild;
  38339. // one element
  38340. if (el.firstChild == el.lastChild) {
  38341. return el.removeChild(el.firstChild);
  38342. }
  38343. // several elements
  38344. var fragment = doc.createDocumentFragment();
  38345. while (el.firstChild) {
  38346. fragment.appendChild(el.removeChild(el.firstChild));
  38347. }
  38348. return fragment;
  38349. }
  38350. },{}],369:[function(_dereq_,module,exports){
  38351. module.exports = _dereq_(371);
  38352. module.exports.Collection = _dereq_(370);
  38353. },{"370":370,"371":371}],370:[function(_dereq_,module,exports){
  38354. 'use strict';
  38355. /**
  38356. * An empty collection stub. Use {@link RefsCollection.extend} to extend a
  38357. * collection with ref semantics.
  38358. *
  38359. * @classdesc A change and inverse-reference aware collection with set semantics.
  38360. *
  38361. * @class RefsCollection
  38362. */
  38363. function RefsCollection() { }
  38364. /**
  38365. * Extends a collection with {@link Refs} aware methods
  38366. *
  38367. * @memberof RefsCollection
  38368. * @static
  38369. *
  38370. * @param {Array<Object>} collection
  38371. * @param {Refs} refs instance
  38372. * @param {Object} property represented by the collection
  38373. * @param {Object} target object the collection is attached to
  38374. *
  38375. * @return {RefsCollection<Object>} the extended array
  38376. */
  38377. function extend(collection, refs, property, target) {
  38378. var inverseProperty = property.inverse;
  38379. /**
  38380. * Removes the given element from the array and returns it.
  38381. *
  38382. * @method RefsCollection#remove
  38383. *
  38384. * @param {Object} element the element to remove
  38385. */
  38386. collection.remove = function(element) {
  38387. var idx = this.indexOf(element);
  38388. if (idx !== -1) {
  38389. this.splice(idx, 1);
  38390. // unset inverse
  38391. refs.unset(element, inverseProperty, target);
  38392. }
  38393. return element;
  38394. };
  38395. /**
  38396. * Returns true if the collection contains the given element
  38397. *
  38398. * @method RefsCollection#contains
  38399. *
  38400. * @param {Object} element the element to check for
  38401. */
  38402. collection.contains = function(element) {
  38403. return this.indexOf(element) !== -1;
  38404. };
  38405. /**
  38406. * Adds an element to the array, unless it exists already (set semantics).
  38407. *
  38408. * @method RefsCollection#add
  38409. *
  38410. * @param {Object} element the element to add
  38411. */
  38412. collection.add = function(element) {
  38413. if (!this.contains(element)) {
  38414. this.push(element);
  38415. // set inverse
  38416. refs.set(element, inverseProperty, target);
  38417. }
  38418. };
  38419. return collection;
  38420. }
  38421. module.exports.extend = extend;
  38422. },{}],371:[function(_dereq_,module,exports){
  38423. 'use strict';
  38424. var Collection = _dereq_(370);
  38425. function hasOwnProperty(e, property) {
  38426. return Object.prototype.hasOwnProperty.call(e, property.name || property);
  38427. }
  38428. function defineCollectionProperty(ref, property, target) {
  38429. Object.defineProperty(target, property.name, {
  38430. enumerable: property.enumerable,
  38431. value: Collection.extend(target[property.name] || [], ref, property, target)
  38432. });
  38433. }
  38434. function defineProperty(ref, property, target) {
  38435. var inverseProperty = property.inverse;
  38436. var _value = target[property.name];
  38437. Object.defineProperty(target, property.name, {
  38438. enumerable: property.enumerable,
  38439. get: function() {
  38440. return _value;
  38441. },
  38442. set: function(value) {
  38443. // return if we already performed all changes
  38444. if (value === _value) {
  38445. return;
  38446. }
  38447. var old = _value;
  38448. // temporary set null
  38449. _value = null;
  38450. if (old) {
  38451. ref.unset(old, inverseProperty, target);
  38452. }
  38453. // set new value
  38454. _value = value;
  38455. // set inverse value
  38456. ref.set(_value, inverseProperty, target);
  38457. }
  38458. });
  38459. }
  38460. /**
  38461. * Creates a new references object defining two inversly related
  38462. * attribute descriptors a and b.
  38463. *
  38464. * <p>
  38465. * When bound to an object using {@link Refs#bind} the references
  38466. * get activated and ensure that add and remove operations are applied
  38467. * reversely, too.
  38468. * </p>
  38469. *
  38470. * <p>
  38471. * For attributes represented as collections {@link Refs} provides the
  38472. * {@link RefsCollection#add}, {@link RefsCollection#remove} and {@link RefsCollection#contains} extensions
  38473. * that must be used to properly hook into the inverse change mechanism.
  38474. * </p>
  38475. *
  38476. * @class Refs
  38477. *
  38478. * @classdesc A bi-directional reference between two attributes.
  38479. *
  38480. * @param {Refs.AttributeDescriptor} a property descriptor
  38481. * @param {Refs.AttributeDescriptor} b property descriptor
  38482. *
  38483. * @example
  38484. *
  38485. * var refs = Refs({ name: 'wheels', collection: true, enumerable: true }, { name: 'car' });
  38486. *
  38487. * var car = { name: 'toyota' };
  38488. * var wheels = [{ pos: 'front-left' }, { pos: 'front-right' }];
  38489. *
  38490. * refs.bind(car, 'wheels');
  38491. *
  38492. * car.wheels // []
  38493. * car.wheels.add(wheels[0]);
  38494. * car.wheels.add(wheels[1]);
  38495. *
  38496. * car.wheels // [{ pos: 'front-left' }, { pos: 'front-right' }]
  38497. *
  38498. * wheels[0].car // { name: 'toyota' };
  38499. * car.wheels.remove(wheels[0]);
  38500. *
  38501. * wheels[0].car // undefined
  38502. */
  38503. function Refs(a, b) {
  38504. if (!(this instanceof Refs)) {
  38505. return new Refs(a, b);
  38506. }
  38507. // link
  38508. a.inverse = b;
  38509. b.inverse = a;
  38510. this.props = {};
  38511. this.props[a.name] = a;
  38512. this.props[b.name] = b;
  38513. }
  38514. /**
  38515. * Binds one side of a bi-directional reference to a
  38516. * target object.
  38517. *
  38518. * @memberOf Refs
  38519. *
  38520. * @param {Object} target
  38521. * @param {String} property
  38522. */
  38523. Refs.prototype.bind = function(target, property) {
  38524. if (typeof property === 'string') {
  38525. if (!this.props[property]) {
  38526. throw new Error('no property <' + property + '> in ref');
  38527. }
  38528. property = this.props[property];
  38529. }
  38530. if (property.collection) {
  38531. defineCollectionProperty(this, property, target);
  38532. } else {
  38533. defineProperty(this, property, target);
  38534. }
  38535. };
  38536. Refs.prototype.ensureBound = function(target, property) {
  38537. if (!hasOwnProperty(target, property)) {
  38538. this.bind(target, property);
  38539. }
  38540. };
  38541. Refs.prototype.unset = function(target, property, value) {
  38542. if (target) {
  38543. this.ensureBound(target, property);
  38544. if (property.collection) {
  38545. target[property.name].remove(value);
  38546. } else {
  38547. target[property.name] = undefined;
  38548. }
  38549. }
  38550. };
  38551. Refs.prototype.set = function(target, property, value) {
  38552. if (target) {
  38553. this.ensureBound(target, property);
  38554. if (property.collection) {
  38555. target[property.name].add(value);
  38556. } else {
  38557. target[property.name] = value;
  38558. }
  38559. }
  38560. };
  38561. module.exports = Refs;
  38562. /**
  38563. * An attribute descriptor to be used specify an attribute in a {@link Refs} instance
  38564. *
  38565. * @typedef {Object} Refs.AttributeDescriptor
  38566. * @property {String} name
  38567. * @property {boolean} [collection=false]
  38568. * @property {boolean} [enumerable=false]
  38569. */
  38570. },{"370":370}]},{},[1])(1)
  38571. });
  38572. //# sourceMappingURL=bpmn-modeler.js.map