123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { AUTO_STYLE, NoopAnimationPlayer, sequence, style, ɵAnimationGroupPlayer, ɵPRE_STYLE } from '@angular/animations';
  7. import { __assign, __extends } from 'tslib';
  8. /**
  9. * @fileoverview added by tsickle
  10. * @suppress {checkTypes} checked by tsc
  11. */
  12. /**
  13. * @param {?} players
  14. * @return {?}
  15. */
  16. function optimizeGroupPlayer(players) {
  17. switch (players.length) {
  18. case 0:
  19. return new NoopAnimationPlayer();
  20. case 1:
  21. return players[0];
  22. default:
  23. return new ɵAnimationGroupPlayer(players);
  24. }
  25. }
  26. /**
  27. * @param {?} driver
  28. * @param {?} normalizer
  29. * @param {?} element
  30. * @param {?} keyframes
  31. * @param {?=} preStyles
  32. * @param {?=} postStyles
  33. * @return {?}
  34. */
  35. function normalizeKeyframes(driver, normalizer, element, keyframes, preStyles, postStyles) {
  36. if (preStyles === void 0) { preStyles = {}; }
  37. if (postStyles === void 0) { postStyles = {}; }
  38. var /** @type {?} */ errors = [];
  39. var /** @type {?} */ normalizedKeyframes = [];
  40. var /** @type {?} */ previousOffset = -1;
  41. var /** @type {?} */ previousKeyframe = null;
  42. keyframes.forEach(function (kf) {
  43. var /** @type {?} */ offset = /** @type {?} */ (kf['offset']);
  44. var /** @type {?} */ isSameOffset = offset == previousOffset;
  45. var /** @type {?} */ normalizedKeyframe = (isSameOffset && previousKeyframe) || {};
  46. Object.keys(kf).forEach(function (prop) {
  47. var /** @type {?} */ normalizedProp = prop;
  48. var /** @type {?} */ normalizedValue = kf[prop];
  49. if (prop !== 'offset') {
  50. normalizedProp = normalizer.normalizePropertyName(normalizedProp, errors);
  51. switch (normalizedValue) {
  52. case ɵPRE_STYLE:
  53. normalizedValue = preStyles[prop];
  54. break;
  55. case AUTO_STYLE:
  56. normalizedValue = postStyles[prop];
  57. break;
  58. default:
  59. normalizedValue =
  60. normalizer.normalizeStyleValue(prop, normalizedProp, normalizedValue, errors);
  61. break;
  62. }
  63. }
  64. normalizedKeyframe[normalizedProp] = normalizedValue;
  65. });
  66. if (!isSameOffset) {
  67. normalizedKeyframes.push(normalizedKeyframe);
  68. }
  69. previousKeyframe = normalizedKeyframe;
  70. previousOffset = offset;
  71. });
  72. if (errors.length) {
  73. var /** @type {?} */ LINE_START = '\n - ';
  74. throw new Error("Unable to animate due to the following errors:" + LINE_START + errors.join(LINE_START));
  75. }
  76. return normalizedKeyframes;
  77. }
  78. /**
  79. * @param {?} player
  80. * @param {?} eventName
  81. * @param {?} event
  82. * @param {?} callback
  83. * @return {?}
  84. */
  85. function listenOnPlayer(player, eventName, event, callback) {
  86. switch (eventName) {
  87. case 'start':
  88. player.onStart(function () { return callback(event && copyAnimationEvent(event, 'start', player.totalTime)); });
  89. break;
  90. case 'done':
  91. player.onDone(function () { return callback(event && copyAnimationEvent(event, 'done', player.totalTime)); });
  92. break;
  93. case 'destroy':
  94. player.onDestroy(function () { return callback(event && copyAnimationEvent(event, 'destroy', player.totalTime)); });
  95. break;
  96. }
  97. }
  98. /**
  99. * @param {?} e
  100. * @param {?=} phaseName
  101. * @param {?=} totalTime
  102. * @return {?}
  103. */
  104. function copyAnimationEvent(e, phaseName, totalTime) {
  105. var /** @type {?} */ event = makeAnimationEvent(e.element, e.triggerName, e.fromState, e.toState, phaseName || e.phaseName, totalTime == undefined ? e.totalTime : totalTime);
  106. var /** @type {?} */ data = (/** @type {?} */ (e))['_data'];
  107. if (data != null) {
  108. (/** @type {?} */ (event))['_data'] = data;
  109. }
  110. return event;
  111. }
  112. /**
  113. * @param {?} element
  114. * @param {?} triggerName
  115. * @param {?} fromState
  116. * @param {?} toState
  117. * @param {?=} phaseName
  118. * @param {?=} totalTime
  119. * @return {?}
  120. */
  121. function makeAnimationEvent(element, triggerName, fromState, toState, phaseName, totalTime) {
  122. if (phaseName === void 0) { phaseName = ''; }
  123. if (totalTime === void 0) { totalTime = 0; }
  124. return { element: element, triggerName: triggerName, fromState: fromState, toState: toState, phaseName: phaseName, totalTime: totalTime };
  125. }
  126. /**
  127. * @param {?} map
  128. * @param {?} key
  129. * @param {?} defaultValue
  130. * @return {?}
  131. */
  132. function getOrSetAsInMap(map, key, defaultValue) {
  133. var /** @type {?} */ value;
  134. if (map instanceof Map) {
  135. value = map.get(key);
  136. if (!value) {
  137. map.set(key, value = defaultValue);
  138. }
  139. }
  140. else {
  141. value = map[key];
  142. if (!value) {
  143. value = map[key] = defaultValue;
  144. }
  145. }
  146. return value;
  147. }
  148. /**
  149. * @param {?} command
  150. * @return {?}
  151. */
  152. function parseTimelineCommand(command) {
  153. var /** @type {?} */ separatorPos = command.indexOf(':');
  154. var /** @type {?} */ id = command.substring(1, separatorPos);
  155. var /** @type {?} */ action = command.substr(separatorPos + 1);
  156. return [id, action];
  157. }
  158. var _contains = function (elm1, elm2) { return false; };
  159. var _matches = function (element, selector) {
  160. return false;
  161. };
  162. var _query = function (element, selector, multi) {
  163. return [];
  164. };
  165. if (typeof Element != 'undefined') {
  166. // this is well supported in all browsers
  167. _contains = function (elm1, elm2) { return /** @type {?} */ (elm1.contains(elm2)); };
  168. if (Element.prototype.matches) {
  169. _matches = function (element, selector) { return element.matches(selector); };
  170. }
  171. else {
  172. var /** @type {?} */ proto = /** @type {?} */ (Element.prototype);
  173. var /** @type {?} */ fn_1 = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector ||
  174. proto.oMatchesSelector || proto.webkitMatchesSelector;
  175. if (fn_1) {
  176. _matches = function (element, selector) { return fn_1.apply(element, [selector]); };
  177. }
  178. }
  179. _query = function (element, selector, multi) {
  180. var /** @type {?} */ results = [];
  181. if (multi) {
  182. results.push.apply(results, element.querySelectorAll(selector));
  183. }
  184. else {
  185. var /** @type {?} */ elm = element.querySelector(selector);
  186. if (elm) {
  187. results.push(elm);
  188. }
  189. }
  190. return results;
  191. };
  192. }
  193. /**
  194. * @param {?} prop
  195. * @return {?}
  196. */
  197. function containsVendorPrefix(prop) {
  198. // Webkit is the only real popular vendor prefix nowadays
  199. // cc: http://shouldiprefix.com/
  200. return prop.substring(1, 6) == 'ebkit'; // webkit or Webkit
  201. }
  202. var _CACHED_BODY = null;
  203. var _IS_WEBKIT = false;
  204. /**
  205. * @param {?} prop
  206. * @return {?}
  207. */
  208. function validateStyleProperty(prop) {
  209. if (!_CACHED_BODY) {
  210. _CACHED_BODY = getBodyNode() || {};
  211. _IS_WEBKIT = /** @type {?} */ ((_CACHED_BODY)).style ? ('WebkitAppearance' in /** @type {?} */ ((_CACHED_BODY)).style) : false;
  212. }
  213. var /** @type {?} */ result = true;
  214. if (/** @type {?} */ ((_CACHED_BODY)).style && !containsVendorPrefix(prop)) {
  215. result = prop in /** @type {?} */ ((_CACHED_BODY)).style;
  216. if (!result && _IS_WEBKIT) {
  217. var /** @type {?} */ camelProp = 'Webkit' + prop.charAt(0).toUpperCase() + prop.substr(1);
  218. result = camelProp in /** @type {?} */ ((_CACHED_BODY)).style;
  219. }
  220. }
  221. return result;
  222. }
  223. /**
  224. * @return {?}
  225. */
  226. function getBodyNode() {
  227. if (typeof document != 'undefined') {
  228. return document.body;
  229. }
  230. return null;
  231. }
  232. var matchesElement = _matches;
  233. var containsElement = _contains;
  234. var invokeQuery = _query;
  235. /**
  236. * @fileoverview added by tsickle
  237. * @suppress {checkTypes} checked by tsc
  238. */
  239. /**
  240. * \@experimental
  241. */
  242. var NoopAnimationDriver = /** @class */ (function () {
  243. function NoopAnimationDriver() {
  244. }
  245. /**
  246. * @param {?} prop
  247. * @return {?}
  248. */
  249. NoopAnimationDriver.prototype.validateStyleProperty = /**
  250. * @param {?} prop
  251. * @return {?}
  252. */
  253. function (prop) { return validateStyleProperty(prop); };
  254. /**
  255. * @param {?} element
  256. * @param {?} selector
  257. * @return {?}
  258. */
  259. NoopAnimationDriver.prototype.matchesElement = /**
  260. * @param {?} element
  261. * @param {?} selector
  262. * @return {?}
  263. */
  264. function (element, selector) {
  265. return matchesElement(element, selector);
  266. };
  267. /**
  268. * @param {?} elm1
  269. * @param {?} elm2
  270. * @return {?}
  271. */
  272. NoopAnimationDriver.prototype.containsElement = /**
  273. * @param {?} elm1
  274. * @param {?} elm2
  275. * @return {?}
  276. */
  277. function (elm1, elm2) { return containsElement(elm1, elm2); };
  278. /**
  279. * @param {?} element
  280. * @param {?} selector
  281. * @param {?} multi
  282. * @return {?}
  283. */
  284. NoopAnimationDriver.prototype.query = /**
  285. * @param {?} element
  286. * @param {?} selector
  287. * @param {?} multi
  288. * @return {?}
  289. */
  290. function (element, selector, multi) {
  291. return invokeQuery(element, selector, multi);
  292. };
  293. /**
  294. * @param {?} element
  295. * @param {?} prop
  296. * @param {?=} defaultValue
  297. * @return {?}
  298. */
  299. NoopAnimationDriver.prototype.computeStyle = /**
  300. * @param {?} element
  301. * @param {?} prop
  302. * @param {?=} defaultValue
  303. * @return {?}
  304. */
  305. function (element, prop, defaultValue) {
  306. return defaultValue || '';
  307. };
  308. /**
  309. * @param {?} element
  310. * @param {?} keyframes
  311. * @param {?} duration
  312. * @param {?} delay
  313. * @param {?} easing
  314. * @param {?=} previousPlayers
  315. * @return {?}
  316. */
  317. NoopAnimationDriver.prototype.animate = /**
  318. * @param {?} element
  319. * @param {?} keyframes
  320. * @param {?} duration
  321. * @param {?} delay
  322. * @param {?} easing
  323. * @param {?=} previousPlayers
  324. * @return {?}
  325. */
  326. function (element, keyframes, duration, delay, easing, previousPlayers) {
  327. if (previousPlayers === void 0) { previousPlayers = []; }
  328. return new NoopAnimationPlayer();
  329. };
  330. return NoopAnimationDriver;
  331. }());
  332. /**
  333. * \@experimental
  334. * @abstract
  335. */
  336. var AnimationDriver = /** @class */ (function () {
  337. function AnimationDriver() {
  338. }
  339. AnimationDriver.NOOP = new NoopAnimationDriver();
  340. return AnimationDriver;
  341. }());
  342. /**
  343. * @fileoverview added by tsickle
  344. * @suppress {checkTypes} checked by tsc
  345. */
  346. var ONE_SECOND = 1000;
  347. var SUBSTITUTION_EXPR_START = '{{';
  348. var SUBSTITUTION_EXPR_END = '}}';
  349. var ENTER_CLASSNAME = 'ng-enter';
  350. var LEAVE_CLASSNAME = 'ng-leave';
  351. var NG_TRIGGER_CLASSNAME = 'ng-trigger';
  352. var NG_TRIGGER_SELECTOR = '.ng-trigger';
  353. var NG_ANIMATING_CLASSNAME = 'ng-animating';
  354. var NG_ANIMATING_SELECTOR = '.ng-animating';
  355. /**
  356. * @param {?} value
  357. * @return {?}
  358. */
  359. function resolveTimingValue(value) {
  360. if (typeof value == 'number')
  361. return value;
  362. var /** @type {?} */ matches = (/** @type {?} */ (value)).match(/^(-?[\.\d]+)(m?s)/);
  363. if (!matches || matches.length < 2)
  364. return 0;
  365. return _convertTimeValueToMS(parseFloat(matches[1]), matches[2]);
  366. }
  367. /**
  368. * @param {?} value
  369. * @param {?} unit
  370. * @return {?}
  371. */
  372. function _convertTimeValueToMS(value, unit) {
  373. switch (unit) {
  374. case 's':
  375. return value * ONE_SECOND;
  376. default:
  377. // ms or something else
  378. return value;
  379. }
  380. }
  381. /**
  382. * @param {?} timings
  383. * @param {?} errors
  384. * @param {?=} allowNegativeValues
  385. * @return {?}
  386. */
  387. function resolveTiming(timings, errors, allowNegativeValues) {
  388. return timings.hasOwnProperty('duration') ? /** @type {?} */ (timings) :
  389. parseTimeExpression(/** @type {?} */ (timings), errors, allowNegativeValues);
  390. }
  391. /**
  392. * @param {?} exp
  393. * @param {?} errors
  394. * @param {?=} allowNegativeValues
  395. * @return {?}
  396. */
  397. function parseTimeExpression(exp, errors, allowNegativeValues) {
  398. var /** @type {?} */ regex = /^(-?[\.\d]+)(m?s)(?:\s+(-?[\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?$/i;
  399. var /** @type {?} */ duration;
  400. var /** @type {?} */ delay = 0;
  401. var /** @type {?} */ easing = '';
  402. if (typeof exp === 'string') {
  403. var /** @type {?} */ matches = exp.match(regex);
  404. if (matches === null) {
  405. errors.push("The provided timing value \"" + exp + "\" is invalid.");
  406. return { duration: 0, delay: 0, easing: '' };
  407. }
  408. duration = _convertTimeValueToMS(parseFloat(matches[1]), matches[2]);
  409. var /** @type {?} */ delayMatch = matches[3];
  410. if (delayMatch != null) {
  411. delay = _convertTimeValueToMS(Math.floor(parseFloat(delayMatch)), matches[4]);
  412. }
  413. var /** @type {?} */ easingVal = matches[5];
  414. if (easingVal) {
  415. easing = easingVal;
  416. }
  417. }
  418. else {
  419. duration = /** @type {?} */ (exp);
  420. }
  421. if (!allowNegativeValues) {
  422. var /** @type {?} */ containsErrors = false;
  423. var /** @type {?} */ startIndex = errors.length;
  424. if (duration < 0) {
  425. errors.push("Duration values below 0 are not allowed for this animation step.");
  426. containsErrors = true;
  427. }
  428. if (delay < 0) {
  429. errors.push("Delay values below 0 are not allowed for this animation step.");
  430. containsErrors = true;
  431. }
  432. if (containsErrors) {
  433. errors.splice(startIndex, 0, "The provided timing value \"" + exp + "\" is invalid.");
  434. }
  435. }
  436. return { duration: duration, delay: delay, easing: easing };
  437. }
  438. /**
  439. * @param {?} obj
  440. * @param {?=} destination
  441. * @return {?}
  442. */
  443. function copyObj(obj, destination) {
  444. if (destination === void 0) { destination = {}; }
  445. Object.keys(obj).forEach(function (prop) { destination[prop] = obj[prop]; });
  446. return destination;
  447. }
  448. /**
  449. * @param {?} styles
  450. * @return {?}
  451. */
  452. function normalizeStyles(styles) {
  453. var /** @type {?} */ normalizedStyles = {};
  454. if (Array.isArray(styles)) {
  455. styles.forEach(function (data) { return copyStyles(data, false, normalizedStyles); });
  456. }
  457. else {
  458. copyStyles(styles, false, normalizedStyles);
  459. }
  460. return normalizedStyles;
  461. }
  462. /**
  463. * @param {?} styles
  464. * @param {?} readPrototype
  465. * @param {?=} destination
  466. * @return {?}
  467. */
  468. function copyStyles(styles, readPrototype, destination) {
  469. if (destination === void 0) { destination = {}; }
  470. if (readPrototype) {
  471. // we make use of a for-in loop so that the
  472. // prototypically inherited properties are
  473. // revealed from the backFill map
  474. for (var /** @type {?} */ prop in styles) {
  475. destination[prop] = styles[prop];
  476. }
  477. }
  478. else {
  479. copyObj(styles, destination);
  480. }
  481. return destination;
  482. }
  483. /**
  484. * @param {?} element
  485. * @param {?} styles
  486. * @return {?}
  487. */
  488. function setStyles(element, styles) {
  489. if (element['style']) {
  490. Object.keys(styles).forEach(function (prop) {
  491. var /** @type {?} */ camelProp = dashCaseToCamelCase(prop);
  492. element.style[camelProp] = styles[prop];
  493. });
  494. }
  495. }
  496. /**
  497. * @param {?} element
  498. * @param {?} styles
  499. * @return {?}
  500. */
  501. function eraseStyles(element, styles) {
  502. if (element['style']) {
  503. Object.keys(styles).forEach(function (prop) {
  504. var /** @type {?} */ camelProp = dashCaseToCamelCase(prop);
  505. element.style[camelProp] = '';
  506. });
  507. }
  508. }
  509. /**
  510. * @param {?} steps
  511. * @return {?}
  512. */
  513. function normalizeAnimationEntry(steps) {
  514. if (Array.isArray(steps)) {
  515. if (steps.length == 1)
  516. return steps[0];
  517. return sequence(steps);
  518. }
  519. return /** @type {?} */ (steps);
  520. }
  521. /**
  522. * @param {?} value
  523. * @param {?} options
  524. * @param {?} errors
  525. * @return {?}
  526. */
  527. function validateStyleParams(value, options, errors) {
  528. var /** @type {?} */ params = options.params || {};
  529. var /** @type {?} */ matches = extractStyleParams(value);
  530. if (matches.length) {
  531. matches.forEach(function (varName) {
  532. if (!params.hasOwnProperty(varName)) {
  533. errors.push("Unable to resolve the local animation param " + varName + " in the given list of values");
  534. }
  535. });
  536. }
  537. }
  538. var PARAM_REGEX = new RegExp(SUBSTITUTION_EXPR_START + "\\s*(.+?)\\s*" + SUBSTITUTION_EXPR_END, 'g');
  539. /**
  540. * @param {?} value
  541. * @return {?}
  542. */
  543. function extractStyleParams(value) {
  544. var /** @type {?} */ params = [];
  545. if (typeof value === 'string') {
  546. var /** @type {?} */ val = value.toString();
  547. var /** @type {?} */ match = void 0;
  548. while (match = PARAM_REGEX.exec(val)) {
  549. params.push(/** @type {?} */ (match[1]));
  550. }
  551. PARAM_REGEX.lastIndex = 0;
  552. }
  553. return params;
  554. }
  555. /**
  556. * @param {?} value
  557. * @param {?} params
  558. * @param {?} errors
  559. * @return {?}
  560. */
  561. function interpolateParams(value, params, errors) {
  562. var /** @type {?} */ original = value.toString();
  563. var /** @type {?} */ str = original.replace(PARAM_REGEX, function (_, varName) {
  564. var /** @type {?} */ localVal = params[varName];
  565. // this means that the value was never overidden by the data passed in by the user
  566. if (!params.hasOwnProperty(varName)) {
  567. errors.push("Please provide a value for the animation param " + varName);
  568. localVal = '';
  569. }
  570. return localVal.toString();
  571. });
  572. // we do this to assert that numeric values stay as they are
  573. return str == original ? value : str;
  574. }
  575. /**
  576. * @param {?} iterator
  577. * @return {?}
  578. */
  579. function iteratorToArray(iterator) {
  580. var /** @type {?} */ arr = [];
  581. var /** @type {?} */ item = iterator.next();
  582. while (!item.done) {
  583. arr.push(item.value);
  584. item = iterator.next();
  585. }
  586. return arr;
  587. }
  588. /**
  589. * @param {?} source
  590. * @param {?} destination
  591. * @return {?}
  592. */
  593. var DASH_CASE_REGEXP = /-+([a-z0-9])/g;
  594. /**
  595. * @param {?} input
  596. * @return {?}
  597. */
  598. function dashCaseToCamelCase(input) {
  599. return input.replace(DASH_CASE_REGEXP, function () {
  600. var m = [];
  601. for (var _i = 0; _i < arguments.length; _i++) {
  602. m[_i] = arguments[_i];
  603. }
  604. return m[1].toUpperCase();
  605. });
  606. }
  607. /**
  608. * @param {?} duration
  609. * @param {?} delay
  610. * @return {?}
  611. */
  612. function allowPreviousPlayerStylesMerge(duration, delay) {
  613. return duration === 0 || delay === 0;
  614. }
  615. /**
  616. * @param {?} visitor
  617. * @param {?} node
  618. * @param {?} context
  619. * @return {?}
  620. */
  621. function visitDslNode(visitor, node, context) {
  622. switch (node.type) {
  623. case 7 /* Trigger */:
  624. return visitor.visitTrigger(node, context);
  625. case 0 /* State */:
  626. return visitor.visitState(node, context);
  627. case 1 /* Transition */:
  628. return visitor.visitTransition(node, context);
  629. case 2 /* Sequence */:
  630. return visitor.visitSequence(node, context);
  631. case 3 /* Group */:
  632. return visitor.visitGroup(node, context);
  633. case 4 /* Animate */:
  634. return visitor.visitAnimate(node, context);
  635. case 5 /* Keyframes */:
  636. return visitor.visitKeyframes(node, context);
  637. case 6 /* Style */:
  638. return visitor.visitStyle(node, context);
  639. case 8 /* Reference */:
  640. return visitor.visitReference(node, context);
  641. case 9 /* AnimateChild */:
  642. return visitor.visitAnimateChild(node, context);
  643. case 10 /* AnimateRef */:
  644. return visitor.visitAnimateRef(node, context);
  645. case 11 /* Query */:
  646. return visitor.visitQuery(node, context);
  647. case 12 /* Stagger */:
  648. return visitor.visitStagger(node, context);
  649. default:
  650. throw new Error("Unable to resolve animation metadata node #" + node.type);
  651. }
  652. }
  653. /**
  654. * @fileoverview added by tsickle
  655. * @suppress {checkTypes} checked by tsc
  656. */
  657. /**
  658. * @license
  659. * Copyright Google Inc. All Rights Reserved.
  660. *
  661. * Use of this source code is governed by an MIT-style license that can be
  662. * found in the LICENSE file at https://angular.io/license
  663. */
  664. var ANY_STATE = '*';
  665. /**
  666. * @param {?} transitionValue
  667. * @param {?} errors
  668. * @return {?}
  669. */
  670. function parseTransitionExpr(transitionValue, errors) {
  671. var /** @type {?} */ expressions = [];
  672. if (typeof transitionValue == 'string') {
  673. (/** @type {?} */ (transitionValue))
  674. .split(/\s*,\s*/)
  675. .forEach(function (str) { return parseInnerTransitionStr(str, expressions, errors); });
  676. }
  677. else {
  678. expressions.push(/** @type {?} */ (transitionValue));
  679. }
  680. return expressions;
  681. }
  682. /**
  683. * @param {?} eventStr
  684. * @param {?} expressions
  685. * @param {?} errors
  686. * @return {?}
  687. */
  688. function parseInnerTransitionStr(eventStr, expressions, errors) {
  689. if (eventStr[0] == ':') {
  690. var /** @type {?} */ result = parseAnimationAlias(eventStr, errors);
  691. if (typeof result == 'function') {
  692. expressions.push(result);
  693. return;
  694. }
  695. eventStr = /** @type {?} */ (result);
  696. }
  697. var /** @type {?} */ match = eventStr.match(/^(\*|[-\w]+)\s*(<?[=-]>)\s*(\*|[-\w]+)$/);
  698. if (match == null || match.length < 4) {
  699. errors.push("The provided transition expression \"" + eventStr + "\" is not supported");
  700. return expressions;
  701. }
  702. var /** @type {?} */ fromState = match[1];
  703. var /** @type {?} */ separator = match[2];
  704. var /** @type {?} */ toState = match[3];
  705. expressions.push(makeLambdaFromStates(fromState, toState));
  706. var /** @type {?} */ isFullAnyStateExpr = fromState == ANY_STATE && toState == ANY_STATE;
  707. if (separator[0] == '<' && !isFullAnyStateExpr) {
  708. expressions.push(makeLambdaFromStates(toState, fromState));
  709. }
  710. }
  711. /**
  712. * @param {?} alias
  713. * @param {?} errors
  714. * @return {?}
  715. */
  716. function parseAnimationAlias(alias, errors) {
  717. switch (alias) {
  718. case ':enter':
  719. return 'void => *';
  720. case ':leave':
  721. return '* => void';
  722. case ':increment':
  723. return function (fromState, toState) { return parseFloat(toState) > parseFloat(fromState); };
  724. case ':decrement':
  725. return function (fromState, toState) { return parseFloat(toState) < parseFloat(fromState); };
  726. default:
  727. errors.push("The transition alias value \"" + alias + "\" is not supported");
  728. return '* => *';
  729. }
  730. }
  731. // DO NOT REFACTOR ... keep the follow set instantiations
  732. // with the values intact (closure compiler for some reason
  733. // removes follow-up lines that add the values outside of
  734. // the constructor...
  735. var TRUE_BOOLEAN_VALUES = new Set(['true', '1']);
  736. var FALSE_BOOLEAN_VALUES = new Set(['false', '0']);
  737. /**
  738. * @param {?} lhs
  739. * @param {?} rhs
  740. * @return {?}
  741. */
  742. function makeLambdaFromStates(lhs, rhs) {
  743. var /** @type {?} */ LHS_MATCH_BOOLEAN = TRUE_BOOLEAN_VALUES.has(lhs) || FALSE_BOOLEAN_VALUES.has(lhs);
  744. var /** @type {?} */ RHS_MATCH_BOOLEAN = TRUE_BOOLEAN_VALUES.has(rhs) || FALSE_BOOLEAN_VALUES.has(rhs);
  745. return function (fromState, toState) {
  746. var /** @type {?} */ lhsMatch = lhs == ANY_STATE || lhs == fromState;
  747. var /** @type {?} */ rhsMatch = rhs == ANY_STATE || rhs == toState;
  748. if (!lhsMatch && LHS_MATCH_BOOLEAN && typeof fromState === 'boolean') {
  749. lhsMatch = fromState ? TRUE_BOOLEAN_VALUES.has(lhs) : FALSE_BOOLEAN_VALUES.has(lhs);
  750. }
  751. if (!rhsMatch && RHS_MATCH_BOOLEAN && typeof toState === 'boolean') {
  752. rhsMatch = toState ? TRUE_BOOLEAN_VALUES.has(rhs) : FALSE_BOOLEAN_VALUES.has(rhs);
  753. }
  754. return lhsMatch && rhsMatch;
  755. };
  756. }
  757. /**
  758. * @fileoverview added by tsickle
  759. * @suppress {checkTypes} checked by tsc
  760. */
  761. var SELF_TOKEN = ':self';
  762. var SELF_TOKEN_REGEX = new RegExp("s*" + SELF_TOKEN + "s*,?", 'g');
  763. /**
  764. * @param {?} driver
  765. * @param {?} metadata
  766. * @param {?} errors
  767. * @return {?}
  768. */
  769. function buildAnimationAst(driver, metadata, errors) {
  770. return new AnimationAstBuilderVisitor(driver).build(metadata, errors);
  771. }
  772. var ROOT_SELECTOR = '';
  773. var AnimationAstBuilderVisitor = /** @class */ (function () {
  774. function AnimationAstBuilderVisitor(_driver) {
  775. this._driver = _driver;
  776. }
  777. /**
  778. * @param {?} metadata
  779. * @param {?} errors
  780. * @return {?}
  781. */
  782. AnimationAstBuilderVisitor.prototype.build = /**
  783. * @param {?} metadata
  784. * @param {?} errors
  785. * @return {?}
  786. */
  787. function (metadata, errors) {
  788. var /** @type {?} */ context = new AnimationAstBuilderContext(errors);
  789. this._resetContextStyleTimingState(context);
  790. return /** @type {?} */ (visitDslNode(this, normalizeAnimationEntry(metadata), context));
  791. };
  792. /**
  793. * @param {?} context
  794. * @return {?}
  795. */
  796. AnimationAstBuilderVisitor.prototype._resetContextStyleTimingState = /**
  797. * @param {?} context
  798. * @return {?}
  799. */
  800. function (context) {
  801. context.currentQuerySelector = ROOT_SELECTOR;
  802. context.collectedStyles = {};
  803. context.collectedStyles[ROOT_SELECTOR] = {};
  804. context.currentTime = 0;
  805. };
  806. /**
  807. * @param {?} metadata
  808. * @param {?} context
  809. * @return {?}
  810. */
  811. AnimationAstBuilderVisitor.prototype.visitTrigger = /**
  812. * @param {?} metadata
  813. * @param {?} context
  814. * @return {?}
  815. */
  816. function (metadata, context) {
  817. var _this = this;
  818. var /** @type {?} */ queryCount = context.queryCount = 0;
  819. var /** @type {?} */ depCount = context.depCount = 0;
  820. var /** @type {?} */ states = [];
  821. var /** @type {?} */ transitions = [];
  822. if (metadata.name.charAt(0) == '@') {
  823. context.errors.push('animation triggers cannot be prefixed with an `@` sign (e.g. trigger(\'@foo\', [...]))');
  824. }
  825. metadata.definitions.forEach(function (def) {
  826. _this._resetContextStyleTimingState(context);
  827. if (def.type == 0 /* State */) {
  828. var /** @type {?} */ stateDef_1 = /** @type {?} */ (def);
  829. var /** @type {?} */ name_1 = stateDef_1.name;
  830. name_1.split(/\s*,\s*/).forEach(function (n) {
  831. stateDef_1.name = n;
  832. states.push(_this.visitState(stateDef_1, context));
  833. });
  834. stateDef_1.name = name_1;
  835. }
  836. else if (def.type == 1 /* Transition */) {
  837. var /** @type {?} */ transition = _this.visitTransition(/** @type {?} */ (def), context);
  838. queryCount += transition.queryCount;
  839. depCount += transition.depCount;
  840. transitions.push(transition);
  841. }
  842. else {
  843. context.errors.push('only state() and transition() definitions can sit inside of a trigger()');
  844. }
  845. });
  846. return {
  847. type: 7 /* Trigger */,
  848. name: metadata.name, states: states, transitions: transitions, queryCount: queryCount, depCount: depCount,
  849. options: null
  850. };
  851. };
  852. /**
  853. * @param {?} metadata
  854. * @param {?} context
  855. * @return {?}
  856. */
  857. AnimationAstBuilderVisitor.prototype.visitState = /**
  858. * @param {?} metadata
  859. * @param {?} context
  860. * @return {?}
  861. */
  862. function (metadata, context) {
  863. var /** @type {?} */ styleAst = this.visitStyle(metadata.styles, context);
  864. var /** @type {?} */ astParams = (metadata.options && metadata.options.params) || null;
  865. if (styleAst.containsDynamicStyles) {
  866. var /** @type {?} */ missingSubs_1 = new Set();
  867. var /** @type {?} */ params_1 = astParams || {};
  868. styleAst.styles.forEach(function (value) {
  869. if (isObject(value)) {
  870. var /** @type {?} */ stylesObj_1 = /** @type {?} */ (value);
  871. Object.keys(stylesObj_1).forEach(function (prop) {
  872. extractStyleParams(stylesObj_1[prop]).forEach(function (sub) {
  873. if (!params_1.hasOwnProperty(sub)) {
  874. missingSubs_1.add(sub);
  875. }
  876. });
  877. });
  878. }
  879. });
  880. if (missingSubs_1.size) {
  881. var /** @type {?} */ missingSubsArr = iteratorToArray(missingSubs_1.values());
  882. context.errors.push("state(\"" + metadata.name + "\", ...) must define default values for all the following style substitutions: " + missingSubsArr.join(', '));
  883. }
  884. }
  885. return {
  886. type: 0 /* State */,
  887. name: metadata.name,
  888. style: styleAst,
  889. options: astParams ? { params: astParams } : null
  890. };
  891. };
  892. /**
  893. * @param {?} metadata
  894. * @param {?} context
  895. * @return {?}
  896. */
  897. AnimationAstBuilderVisitor.prototype.visitTransition = /**
  898. * @param {?} metadata
  899. * @param {?} context
  900. * @return {?}
  901. */
  902. function (metadata, context) {
  903. context.queryCount = 0;
  904. context.depCount = 0;
  905. var /** @type {?} */ animation = visitDslNode(this, normalizeAnimationEntry(metadata.animation), context);
  906. var /** @type {?} */ matchers = parseTransitionExpr(metadata.expr, context.errors);
  907. return {
  908. type: 1 /* Transition */,
  909. matchers: matchers,
  910. animation: animation,
  911. queryCount: context.queryCount,
  912. depCount: context.depCount,
  913. options: normalizeAnimationOptions(metadata.options)
  914. };
  915. };
  916. /**
  917. * @param {?} metadata
  918. * @param {?} context
  919. * @return {?}
  920. */
  921. AnimationAstBuilderVisitor.prototype.visitSequence = /**
  922. * @param {?} metadata
  923. * @param {?} context
  924. * @return {?}
  925. */
  926. function (metadata, context) {
  927. var _this = this;
  928. return {
  929. type: 2 /* Sequence */,
  930. steps: metadata.steps.map(function (s) { return visitDslNode(_this, s, context); }),
  931. options: normalizeAnimationOptions(metadata.options)
  932. };
  933. };
  934. /**
  935. * @param {?} metadata
  936. * @param {?} context
  937. * @return {?}
  938. */
  939. AnimationAstBuilderVisitor.prototype.visitGroup = /**
  940. * @param {?} metadata
  941. * @param {?} context
  942. * @return {?}
  943. */
  944. function (metadata, context) {
  945. var _this = this;
  946. var /** @type {?} */ currentTime = context.currentTime;
  947. var /** @type {?} */ furthestTime = 0;
  948. var /** @type {?} */ steps = metadata.steps.map(function (step) {
  949. context.currentTime = currentTime;
  950. var /** @type {?} */ innerAst = visitDslNode(_this, step, context);
  951. furthestTime = Math.max(furthestTime, context.currentTime);
  952. return innerAst;
  953. });
  954. context.currentTime = furthestTime;
  955. return {
  956. type: 3 /* Group */,
  957. steps: steps,
  958. options: normalizeAnimationOptions(metadata.options)
  959. };
  960. };
  961. /**
  962. * @param {?} metadata
  963. * @param {?} context
  964. * @return {?}
  965. */
  966. AnimationAstBuilderVisitor.prototype.visitAnimate = /**
  967. * @param {?} metadata
  968. * @param {?} context
  969. * @return {?}
  970. */
  971. function (metadata, context) {
  972. var /** @type {?} */ timingAst = constructTimingAst(metadata.timings, context.errors);
  973. context.currentAnimateTimings = timingAst;
  974. var /** @type {?} */ styleAst;
  975. var /** @type {?} */ styleMetadata = metadata.styles ? metadata.styles : style({});
  976. if (styleMetadata.type == 5 /* Keyframes */) {
  977. styleAst = this.visitKeyframes(/** @type {?} */ (styleMetadata), context);
  978. }
  979. else {
  980. var /** @type {?} */ styleMetadata_1 = /** @type {?} */ (metadata.styles);
  981. var /** @type {?} */ isEmpty = false;
  982. if (!styleMetadata_1) {
  983. isEmpty = true;
  984. var /** @type {?} */ newStyleData = {};
  985. if (timingAst.easing) {
  986. newStyleData['easing'] = timingAst.easing;
  987. }
  988. styleMetadata_1 = style(newStyleData);
  989. }
  990. context.currentTime += timingAst.duration + timingAst.delay;
  991. var /** @type {?} */ _styleAst = this.visitStyle(styleMetadata_1, context);
  992. _styleAst.isEmptyStep = isEmpty;
  993. styleAst = _styleAst;
  994. }
  995. context.currentAnimateTimings = null;
  996. return {
  997. type: 4 /* Animate */,
  998. timings: timingAst,
  999. style: styleAst,
  1000. options: null
  1001. };
  1002. };
  1003. /**
  1004. * @param {?} metadata
  1005. * @param {?} context
  1006. * @return {?}
  1007. */
  1008. AnimationAstBuilderVisitor.prototype.visitStyle = /**
  1009. * @param {?} metadata
  1010. * @param {?} context
  1011. * @return {?}
  1012. */
  1013. function (metadata, context) {
  1014. var /** @type {?} */ ast = this._makeStyleAst(metadata, context);
  1015. this._validateStyleAst(ast, context);
  1016. return ast;
  1017. };
  1018. /**
  1019. * @param {?} metadata
  1020. * @param {?} context
  1021. * @return {?}
  1022. */
  1023. AnimationAstBuilderVisitor.prototype._makeStyleAst = /**
  1024. * @param {?} metadata
  1025. * @param {?} context
  1026. * @return {?}
  1027. */
  1028. function (metadata, context) {
  1029. var /** @type {?} */ styles = [];
  1030. if (Array.isArray(metadata.styles)) {
  1031. (/** @type {?} */ (metadata.styles)).forEach(function (styleTuple) {
  1032. if (typeof styleTuple == 'string') {
  1033. if (styleTuple == AUTO_STYLE) {
  1034. styles.push(/** @type {?} */ (styleTuple));
  1035. }
  1036. else {
  1037. context.errors.push("The provided style string value " + styleTuple + " is not allowed.");
  1038. }
  1039. }
  1040. else {
  1041. styles.push(/** @type {?} */ (styleTuple));
  1042. }
  1043. });
  1044. }
  1045. else {
  1046. styles.push(metadata.styles);
  1047. }
  1048. var /** @type {?} */ containsDynamicStyles = false;
  1049. var /** @type {?} */ collectedEasing = null;
  1050. styles.forEach(function (styleData) {
  1051. if (isObject(styleData)) {
  1052. var /** @type {?} */ styleMap = /** @type {?} */ (styleData);
  1053. var /** @type {?} */ easing = styleMap['easing'];
  1054. if (easing) {
  1055. collectedEasing = /** @type {?} */ (easing);
  1056. delete styleMap['easing'];
  1057. }
  1058. if (!containsDynamicStyles) {
  1059. for (var /** @type {?} */ prop in styleMap) {
  1060. var /** @type {?} */ value = styleMap[prop];
  1061. if (value.toString().indexOf(SUBSTITUTION_EXPR_START) >= 0) {
  1062. containsDynamicStyles = true;
  1063. break;
  1064. }
  1065. }
  1066. }
  1067. }
  1068. });
  1069. return {
  1070. type: 6 /* Style */,
  1071. styles: styles,
  1072. easing: collectedEasing,
  1073. offset: metadata.offset, containsDynamicStyles: containsDynamicStyles,
  1074. options: null
  1075. };
  1076. };
  1077. /**
  1078. * @param {?} ast
  1079. * @param {?} context
  1080. * @return {?}
  1081. */
  1082. AnimationAstBuilderVisitor.prototype._validateStyleAst = /**
  1083. * @param {?} ast
  1084. * @param {?} context
  1085. * @return {?}
  1086. */
  1087. function (ast, context) {
  1088. var _this = this;
  1089. var /** @type {?} */ timings = context.currentAnimateTimings;
  1090. var /** @type {?} */ endTime = context.currentTime;
  1091. var /** @type {?} */ startTime = context.currentTime;
  1092. if (timings && startTime > 0) {
  1093. startTime -= timings.duration + timings.delay;
  1094. }
  1095. ast.styles.forEach(function (tuple) {
  1096. if (typeof tuple == 'string')
  1097. return;
  1098. Object.keys(tuple).forEach(function (prop) {
  1099. if (!_this._driver.validateStyleProperty(prop)) {
  1100. context.errors.push("The provided animation property \"" + prop + "\" is not a supported CSS property for animations");
  1101. return;
  1102. }
  1103. var /** @type {?} */ collectedStyles = context.collectedStyles[/** @type {?} */ ((context.currentQuerySelector))];
  1104. var /** @type {?} */ collectedEntry = collectedStyles[prop];
  1105. var /** @type {?} */ updateCollectedStyle = true;
  1106. if (collectedEntry) {
  1107. if (startTime != endTime && startTime >= collectedEntry.startTime &&
  1108. endTime <= collectedEntry.endTime) {
  1109. context.errors.push("The CSS property \"" + prop + "\" that exists between the times of \"" + collectedEntry.startTime + "ms\" and \"" + collectedEntry.endTime + "ms\" is also being animated in a parallel animation between the times of \"" + startTime + "ms\" and \"" + endTime + "ms\"");
  1110. updateCollectedStyle = false;
  1111. }
  1112. // we always choose the smaller start time value since we
  1113. // want to have a record of the entire animation window where
  1114. // the style property is being animated in between
  1115. startTime = collectedEntry.startTime;
  1116. }
  1117. if (updateCollectedStyle) {
  1118. collectedStyles[prop] = { startTime: startTime, endTime: endTime };
  1119. }
  1120. if (context.options) {
  1121. validateStyleParams(tuple[prop], context.options, context.errors);
  1122. }
  1123. });
  1124. });
  1125. };
  1126. /**
  1127. * @param {?} metadata
  1128. * @param {?} context
  1129. * @return {?}
  1130. */
  1131. AnimationAstBuilderVisitor.prototype.visitKeyframes = /**
  1132. * @param {?} metadata
  1133. * @param {?} context
  1134. * @return {?}
  1135. */
  1136. function (metadata, context) {
  1137. var _this = this;
  1138. var /** @type {?} */ ast = { type: 5 /* Keyframes */, styles: [], options: null };
  1139. if (!context.currentAnimateTimings) {
  1140. context.errors.push("keyframes() must be placed inside of a call to animate()");
  1141. return ast;
  1142. }
  1143. var /** @type {?} */ MAX_KEYFRAME_OFFSET = 1;
  1144. var /** @type {?} */ totalKeyframesWithOffsets = 0;
  1145. var /** @type {?} */ offsets = [];
  1146. var /** @type {?} */ offsetsOutOfOrder = false;
  1147. var /** @type {?} */ keyframesOutOfRange = false;
  1148. var /** @type {?} */ previousOffset = 0;
  1149. var /** @type {?} */ keyframes = metadata.steps.map(function (styles) {
  1150. var /** @type {?} */ style$$1 = _this._makeStyleAst(styles, context);
  1151. var /** @type {?} */ offsetVal = style$$1.offset != null ? style$$1.offset : consumeOffset(style$$1.styles);
  1152. var /** @type {?} */ offset = 0;
  1153. if (offsetVal != null) {
  1154. totalKeyframesWithOffsets++;
  1155. offset = style$$1.offset = offsetVal;
  1156. }
  1157. keyframesOutOfRange = keyframesOutOfRange || offset < 0 || offset > 1;
  1158. offsetsOutOfOrder = offsetsOutOfOrder || offset < previousOffset;
  1159. previousOffset = offset;
  1160. offsets.push(offset);
  1161. return style$$1;
  1162. });
  1163. if (keyframesOutOfRange) {
  1164. context.errors.push("Please ensure that all keyframe offsets are between 0 and 1");
  1165. }
  1166. if (offsetsOutOfOrder) {
  1167. context.errors.push("Please ensure that all keyframe offsets are in order");
  1168. }
  1169. var /** @type {?} */ length = metadata.steps.length;
  1170. var /** @type {?} */ generatedOffset = 0;
  1171. if (totalKeyframesWithOffsets > 0 && totalKeyframesWithOffsets < length) {
  1172. context.errors.push("Not all style() steps within the declared keyframes() contain offsets");
  1173. }
  1174. else if (totalKeyframesWithOffsets == 0) {
  1175. generatedOffset = MAX_KEYFRAME_OFFSET / (length - 1);
  1176. }
  1177. var /** @type {?} */ limit = length - 1;
  1178. var /** @type {?} */ currentTime = context.currentTime;
  1179. var /** @type {?} */ currentAnimateTimings = /** @type {?} */ ((context.currentAnimateTimings));
  1180. var /** @type {?} */ animateDuration = currentAnimateTimings.duration;
  1181. keyframes.forEach(function (kf, i) {
  1182. var /** @type {?} */ offset = generatedOffset > 0 ? (i == limit ? 1 : (generatedOffset * i)) : offsets[i];
  1183. var /** @type {?} */ durationUpToThisFrame = offset * animateDuration;
  1184. context.currentTime = currentTime + currentAnimateTimings.delay + durationUpToThisFrame;
  1185. currentAnimateTimings.duration = durationUpToThisFrame;
  1186. _this._validateStyleAst(kf, context);
  1187. kf.offset = offset;
  1188. ast.styles.push(kf);
  1189. });
  1190. return ast;
  1191. };
  1192. /**
  1193. * @param {?} metadata
  1194. * @param {?} context
  1195. * @return {?}
  1196. */
  1197. AnimationAstBuilderVisitor.prototype.visitReference = /**
  1198. * @param {?} metadata
  1199. * @param {?} context
  1200. * @return {?}
  1201. */
  1202. function (metadata, context) {
  1203. return {
  1204. type: 8 /* Reference */,
  1205. animation: visitDslNode(this, normalizeAnimationEntry(metadata.animation), context),
  1206. options: normalizeAnimationOptions(metadata.options)
  1207. };
  1208. };
  1209. /**
  1210. * @param {?} metadata
  1211. * @param {?} context
  1212. * @return {?}
  1213. */
  1214. AnimationAstBuilderVisitor.prototype.visitAnimateChild = /**
  1215. * @param {?} metadata
  1216. * @param {?} context
  1217. * @return {?}
  1218. */
  1219. function (metadata, context) {
  1220. context.depCount++;
  1221. return {
  1222. type: 9 /* AnimateChild */,
  1223. options: normalizeAnimationOptions(metadata.options)
  1224. };
  1225. };
  1226. /**
  1227. * @param {?} metadata
  1228. * @param {?} context
  1229. * @return {?}
  1230. */
  1231. AnimationAstBuilderVisitor.prototype.visitAnimateRef = /**
  1232. * @param {?} metadata
  1233. * @param {?} context
  1234. * @return {?}
  1235. */
  1236. function (metadata, context) {
  1237. return {
  1238. type: 10 /* AnimateRef */,
  1239. animation: this.visitReference(metadata.animation, context),
  1240. options: normalizeAnimationOptions(metadata.options)
  1241. };
  1242. };
  1243. /**
  1244. * @param {?} metadata
  1245. * @param {?} context
  1246. * @return {?}
  1247. */
  1248. AnimationAstBuilderVisitor.prototype.visitQuery = /**
  1249. * @param {?} metadata
  1250. * @param {?} context
  1251. * @return {?}
  1252. */
  1253. function (metadata, context) {
  1254. var /** @type {?} */ parentSelector = /** @type {?} */ ((context.currentQuerySelector));
  1255. var /** @type {?} */ options = /** @type {?} */ ((metadata.options || {}));
  1256. context.queryCount++;
  1257. context.currentQuery = metadata;
  1258. var _a = normalizeSelector(metadata.selector), selector = _a[0], includeSelf = _a[1];
  1259. context.currentQuerySelector =
  1260. parentSelector.length ? (parentSelector + ' ' + selector) : selector;
  1261. getOrSetAsInMap(context.collectedStyles, context.currentQuerySelector, {});
  1262. var /** @type {?} */ animation = visitDslNode(this, normalizeAnimationEntry(metadata.animation), context);
  1263. context.currentQuery = null;
  1264. context.currentQuerySelector = parentSelector;
  1265. return {
  1266. type: 11 /* Query */,
  1267. selector: selector,
  1268. limit: options.limit || 0,
  1269. optional: !!options.optional, includeSelf: includeSelf, animation: animation,
  1270. originalSelector: metadata.selector,
  1271. options: normalizeAnimationOptions(metadata.options)
  1272. };
  1273. };
  1274. /**
  1275. * @param {?} metadata
  1276. * @param {?} context
  1277. * @return {?}
  1278. */
  1279. AnimationAstBuilderVisitor.prototype.visitStagger = /**
  1280. * @param {?} metadata
  1281. * @param {?} context
  1282. * @return {?}
  1283. */
  1284. function (metadata, context) {
  1285. if (!context.currentQuery) {
  1286. context.errors.push("stagger() can only be used inside of query()");
  1287. }
  1288. var /** @type {?} */ timings = metadata.timings === 'full' ?
  1289. { duration: 0, delay: 0, easing: 'full' } :
  1290. resolveTiming(metadata.timings, context.errors, true);
  1291. return {
  1292. type: 12 /* Stagger */,
  1293. animation: visitDslNode(this, normalizeAnimationEntry(metadata.animation), context), timings: timings,
  1294. options: null
  1295. };
  1296. };
  1297. return AnimationAstBuilderVisitor;
  1298. }());
  1299. /**
  1300. * @param {?} selector
  1301. * @return {?}
  1302. */
  1303. function normalizeSelector(selector) {
  1304. var /** @type {?} */ hasAmpersand = selector.split(/\s*,\s*/).find(function (token) { return token == SELF_TOKEN; }) ? true : false;
  1305. if (hasAmpersand) {
  1306. selector = selector.replace(SELF_TOKEN_REGEX, '');
  1307. }
  1308. // the :enter and :leave selectors are filled in at runtime during timeline building
  1309. selector = selector.replace(/@\*/g, NG_TRIGGER_SELECTOR)
  1310. .replace(/@\w+/g, function (match) { return NG_TRIGGER_SELECTOR + '-' + match.substr(1); })
  1311. .replace(/:animating/g, NG_ANIMATING_SELECTOR);
  1312. return [selector, hasAmpersand];
  1313. }
  1314. /**
  1315. * @param {?} obj
  1316. * @return {?}
  1317. */
  1318. function normalizeParams(obj) {
  1319. return obj ? copyObj(obj) : null;
  1320. }
  1321. var AnimationAstBuilderContext = /** @class */ (function () {
  1322. function AnimationAstBuilderContext(errors) {
  1323. this.errors = errors;
  1324. this.queryCount = 0;
  1325. this.depCount = 0;
  1326. this.currentTransition = null;
  1327. this.currentQuery = null;
  1328. this.currentQuerySelector = null;
  1329. this.currentAnimateTimings = null;
  1330. this.currentTime = 0;
  1331. this.collectedStyles = {};
  1332. this.options = null;
  1333. }
  1334. return AnimationAstBuilderContext;
  1335. }());
  1336. /**
  1337. * @param {?} styles
  1338. * @return {?}
  1339. */
  1340. function consumeOffset(styles) {
  1341. if (typeof styles == 'string')
  1342. return null;
  1343. var /** @type {?} */ offset = null;
  1344. if (Array.isArray(styles)) {
  1345. styles.forEach(function (styleTuple) {
  1346. if (isObject(styleTuple) && styleTuple.hasOwnProperty('offset')) {
  1347. var /** @type {?} */ obj = /** @type {?} */ (styleTuple);
  1348. offset = parseFloat(/** @type {?} */ (obj['offset']));
  1349. delete obj['offset'];
  1350. }
  1351. });
  1352. }
  1353. else if (isObject(styles) && styles.hasOwnProperty('offset')) {
  1354. var /** @type {?} */ obj = /** @type {?} */ (styles);
  1355. offset = parseFloat(/** @type {?} */ (obj['offset']));
  1356. delete obj['offset'];
  1357. }
  1358. return offset;
  1359. }
  1360. /**
  1361. * @param {?} value
  1362. * @return {?}
  1363. */
  1364. function isObject(value) {
  1365. return !Array.isArray(value) && typeof value == 'object';
  1366. }
  1367. /**
  1368. * @param {?} value
  1369. * @param {?} errors
  1370. * @return {?}
  1371. */
  1372. function constructTimingAst(value, errors) {
  1373. var /** @type {?} */ timings = null;
  1374. if (value.hasOwnProperty('duration')) {
  1375. timings = /** @type {?} */ (value);
  1376. }
  1377. else if (typeof value == 'number') {
  1378. var /** @type {?} */ duration = resolveTiming(/** @type {?} */ (value), errors).duration;
  1379. return makeTimingAst(/** @type {?} */ (duration), 0, '');
  1380. }
  1381. var /** @type {?} */ strValue = /** @type {?} */ (value);
  1382. var /** @type {?} */ isDynamic = strValue.split(/\s+/).some(function (v) { return v.charAt(0) == '{' && v.charAt(1) == '{'; });
  1383. if (isDynamic) {
  1384. var /** @type {?} */ ast = /** @type {?} */ (makeTimingAst(0, 0, ''));
  1385. ast.dynamic = true;
  1386. ast.strValue = strValue;
  1387. return /** @type {?} */ (ast);
  1388. }
  1389. timings = timings || resolveTiming(strValue, errors);
  1390. return makeTimingAst(timings.duration, timings.delay, timings.easing);
  1391. }
  1392. /**
  1393. * @param {?} options
  1394. * @return {?}
  1395. */
  1396. function normalizeAnimationOptions(options) {
  1397. if (options) {
  1398. options = copyObj(options);
  1399. if (options['params']) {
  1400. options['params'] = /** @type {?} */ ((normalizeParams(options['params'])));
  1401. }
  1402. }
  1403. else {
  1404. options = {};
  1405. }
  1406. return options;
  1407. }
  1408. /**
  1409. * @param {?} duration
  1410. * @param {?} delay
  1411. * @param {?} easing
  1412. * @return {?}
  1413. */
  1414. function makeTimingAst(duration, delay, easing) {
  1415. return { duration: duration, delay: delay, easing: easing };
  1416. }
  1417. /**
  1418. * @fileoverview added by tsickle
  1419. * @suppress {checkTypes} checked by tsc
  1420. */
  1421. /**
  1422. * @record
  1423. */
  1424. /**
  1425. * @param {?} element
  1426. * @param {?} keyframes
  1427. * @param {?} preStyleProps
  1428. * @param {?} postStyleProps
  1429. * @param {?} duration
  1430. * @param {?} delay
  1431. * @param {?=} easing
  1432. * @param {?=} subTimeline
  1433. * @return {?}
  1434. */
  1435. function createTimelineInstruction(element, keyframes, preStyleProps, postStyleProps, duration, delay, easing, subTimeline) {
  1436. if (easing === void 0) { easing = null; }
  1437. if (subTimeline === void 0) { subTimeline = false; }
  1438. return {
  1439. type: 1 /* TimelineAnimation */,
  1440. element: element,
  1441. keyframes: keyframes,
  1442. preStyleProps: preStyleProps,
  1443. postStyleProps: postStyleProps,
  1444. duration: duration,
  1445. delay: delay,
  1446. totalTime: duration + delay, easing: easing, subTimeline: subTimeline
  1447. };
  1448. }
  1449. /**
  1450. * @fileoverview added by tsickle
  1451. * @suppress {checkTypes} checked by tsc
  1452. */
  1453. var ElementInstructionMap = /** @class */ (function () {
  1454. function ElementInstructionMap() {
  1455. this._map = new Map();
  1456. }
  1457. /**
  1458. * @param {?} element
  1459. * @return {?}
  1460. */
  1461. ElementInstructionMap.prototype.consume = /**
  1462. * @param {?} element
  1463. * @return {?}
  1464. */
  1465. function (element) {
  1466. var /** @type {?} */ instructions = this._map.get(element);
  1467. if (instructions) {
  1468. this._map.delete(element);
  1469. }
  1470. else {
  1471. instructions = [];
  1472. }
  1473. return instructions;
  1474. };
  1475. /**
  1476. * @param {?} element
  1477. * @param {?} instructions
  1478. * @return {?}
  1479. */
  1480. ElementInstructionMap.prototype.append = /**
  1481. * @param {?} element
  1482. * @param {?} instructions
  1483. * @return {?}
  1484. */
  1485. function (element, instructions) {
  1486. var /** @type {?} */ existingInstructions = this._map.get(element);
  1487. if (!existingInstructions) {
  1488. this._map.set(element, existingInstructions = []);
  1489. }
  1490. existingInstructions.push.apply(existingInstructions, instructions);
  1491. };
  1492. /**
  1493. * @param {?} element
  1494. * @return {?}
  1495. */
  1496. ElementInstructionMap.prototype.has = /**
  1497. * @param {?} element
  1498. * @return {?}
  1499. */
  1500. function (element) { return this._map.has(element); };
  1501. /**
  1502. * @return {?}
  1503. */
  1504. ElementInstructionMap.prototype.clear = /**
  1505. * @return {?}
  1506. */
  1507. function () { this._map.clear(); };
  1508. return ElementInstructionMap;
  1509. }());
  1510. /**
  1511. * @fileoverview added by tsickle
  1512. * @suppress {checkTypes} checked by tsc
  1513. */
  1514. var ONE_FRAME_IN_MILLISECONDS = 1;
  1515. var ENTER_TOKEN = ':enter';
  1516. var ENTER_TOKEN_REGEX = new RegExp(ENTER_TOKEN, 'g');
  1517. var LEAVE_TOKEN = ':leave';
  1518. var LEAVE_TOKEN_REGEX = new RegExp(LEAVE_TOKEN, 'g');
  1519. /**
  1520. * @param {?} driver
  1521. * @param {?} rootElement
  1522. * @param {?} ast
  1523. * @param {?} enterClassName
  1524. * @param {?} leaveClassName
  1525. * @param {?=} startingStyles
  1526. * @param {?=} finalStyles
  1527. * @param {?=} options
  1528. * @param {?=} subInstructions
  1529. * @param {?=} errors
  1530. * @return {?}
  1531. */
  1532. function buildAnimationTimelines(driver, rootElement, ast, enterClassName, leaveClassName, startingStyles, finalStyles, options, subInstructions, errors) {
  1533. if (startingStyles === void 0) { startingStyles = {}; }
  1534. if (finalStyles === void 0) { finalStyles = {}; }
  1535. if (errors === void 0) { errors = []; }
  1536. return new AnimationTimelineBuilderVisitor().buildKeyframes(driver, rootElement, ast, enterClassName, leaveClassName, startingStyles, finalStyles, options, subInstructions, errors);
  1537. }
  1538. var AnimationTimelineBuilderVisitor = /** @class */ (function () {
  1539. function AnimationTimelineBuilderVisitor() {
  1540. }
  1541. /**
  1542. * @param {?} driver
  1543. * @param {?} rootElement
  1544. * @param {?} ast
  1545. * @param {?} enterClassName
  1546. * @param {?} leaveClassName
  1547. * @param {?} startingStyles
  1548. * @param {?} finalStyles
  1549. * @param {?} options
  1550. * @param {?=} subInstructions
  1551. * @param {?=} errors
  1552. * @return {?}
  1553. */
  1554. AnimationTimelineBuilderVisitor.prototype.buildKeyframes = /**
  1555. * @param {?} driver
  1556. * @param {?} rootElement
  1557. * @param {?} ast
  1558. * @param {?} enterClassName
  1559. * @param {?} leaveClassName
  1560. * @param {?} startingStyles
  1561. * @param {?} finalStyles
  1562. * @param {?} options
  1563. * @param {?=} subInstructions
  1564. * @param {?=} errors
  1565. * @return {?}
  1566. */
  1567. function (driver, rootElement, ast, enterClassName, leaveClassName, startingStyles, finalStyles, options, subInstructions, errors) {
  1568. if (errors === void 0) { errors = []; }
  1569. subInstructions = subInstructions || new ElementInstructionMap();
  1570. var /** @type {?} */ context = new AnimationTimelineContext(driver, rootElement, subInstructions, enterClassName, leaveClassName, errors, []);
  1571. context.options = options;
  1572. context.currentTimeline.setStyles([startingStyles], null, context.errors, options);
  1573. visitDslNode(this, ast, context);
  1574. // this checks to see if an actual animation happened
  1575. var /** @type {?} */ timelines = context.timelines.filter(function (timeline) { return timeline.containsAnimation(); });
  1576. if (timelines.length && Object.keys(finalStyles).length) {
  1577. var /** @type {?} */ tl = timelines[timelines.length - 1];
  1578. if (!tl.allowOnlyTimelineStyles()) {
  1579. tl.setStyles([finalStyles], null, context.errors, options);
  1580. }
  1581. }
  1582. return timelines.length ? timelines.map(function (timeline) { return timeline.buildKeyframes(); }) :
  1583. [createTimelineInstruction(rootElement, [], [], [], 0, 0, '', false)];
  1584. };
  1585. /**
  1586. * @param {?} ast
  1587. * @param {?} context
  1588. * @return {?}
  1589. */
  1590. AnimationTimelineBuilderVisitor.prototype.visitTrigger = /**
  1591. * @param {?} ast
  1592. * @param {?} context
  1593. * @return {?}
  1594. */
  1595. function (ast, context) {
  1596. // these values are not visited in this AST
  1597. };
  1598. /**
  1599. * @param {?} ast
  1600. * @param {?} context
  1601. * @return {?}
  1602. */
  1603. AnimationTimelineBuilderVisitor.prototype.visitState = /**
  1604. * @param {?} ast
  1605. * @param {?} context
  1606. * @return {?}
  1607. */
  1608. function (ast, context) {
  1609. // these values are not visited in this AST
  1610. };
  1611. /**
  1612. * @param {?} ast
  1613. * @param {?} context
  1614. * @return {?}
  1615. */
  1616. AnimationTimelineBuilderVisitor.prototype.visitTransition = /**
  1617. * @param {?} ast
  1618. * @param {?} context
  1619. * @return {?}
  1620. */
  1621. function (ast, context) {
  1622. // these values are not visited in this AST
  1623. };
  1624. /**
  1625. * @param {?} ast
  1626. * @param {?} context
  1627. * @return {?}
  1628. */
  1629. AnimationTimelineBuilderVisitor.prototype.visitAnimateChild = /**
  1630. * @param {?} ast
  1631. * @param {?} context
  1632. * @return {?}
  1633. */
  1634. function (ast, context) {
  1635. var /** @type {?} */ elementInstructions = context.subInstructions.consume(context.element);
  1636. if (elementInstructions) {
  1637. var /** @type {?} */ innerContext = context.createSubContext(ast.options);
  1638. var /** @type {?} */ startTime = context.currentTimeline.currentTime;
  1639. var /** @type {?} */ endTime = this._visitSubInstructions(elementInstructions, innerContext, /** @type {?} */ (innerContext.options));
  1640. if (startTime != endTime) {
  1641. // we do this on the upper context because we created a sub context for
  1642. // the sub child animations
  1643. context.transformIntoNewTimeline(endTime);
  1644. }
  1645. }
  1646. context.previousNode = ast;
  1647. };
  1648. /**
  1649. * @param {?} ast
  1650. * @param {?} context
  1651. * @return {?}
  1652. */
  1653. AnimationTimelineBuilderVisitor.prototype.visitAnimateRef = /**
  1654. * @param {?} ast
  1655. * @param {?} context
  1656. * @return {?}
  1657. */
  1658. function (ast, context) {
  1659. var /** @type {?} */ innerContext = context.createSubContext(ast.options);
  1660. innerContext.transformIntoNewTimeline();
  1661. this.visitReference(ast.animation, innerContext);
  1662. context.transformIntoNewTimeline(innerContext.currentTimeline.currentTime);
  1663. context.previousNode = ast;
  1664. };
  1665. /**
  1666. * @param {?} instructions
  1667. * @param {?} context
  1668. * @param {?} options
  1669. * @return {?}
  1670. */
  1671. AnimationTimelineBuilderVisitor.prototype._visitSubInstructions = /**
  1672. * @param {?} instructions
  1673. * @param {?} context
  1674. * @param {?} options
  1675. * @return {?}
  1676. */
  1677. function (instructions, context, options) {
  1678. var /** @type {?} */ startTime = context.currentTimeline.currentTime;
  1679. var /** @type {?} */ furthestTime = startTime;
  1680. // this is a special-case for when a user wants to skip a sub
  1681. // animation from being fired entirely.
  1682. var /** @type {?} */ duration = options.duration != null ? resolveTimingValue(options.duration) : null;
  1683. var /** @type {?} */ delay = options.delay != null ? resolveTimingValue(options.delay) : null;
  1684. if (duration !== 0) {
  1685. instructions.forEach(function (instruction) {
  1686. var /** @type {?} */ instructionTimings = context.appendInstructionToTimeline(instruction, duration, delay);
  1687. furthestTime =
  1688. Math.max(furthestTime, instructionTimings.duration + instructionTimings.delay);
  1689. });
  1690. }
  1691. return furthestTime;
  1692. };
  1693. /**
  1694. * @param {?} ast
  1695. * @param {?} context
  1696. * @return {?}
  1697. */
  1698. AnimationTimelineBuilderVisitor.prototype.visitReference = /**
  1699. * @param {?} ast
  1700. * @param {?} context
  1701. * @return {?}
  1702. */
  1703. function (ast, context) {
  1704. context.updateOptions(ast.options, true);
  1705. visitDslNode(this, ast.animation, context);
  1706. context.previousNode = ast;
  1707. };
  1708. /**
  1709. * @param {?} ast
  1710. * @param {?} context
  1711. * @return {?}
  1712. */
  1713. AnimationTimelineBuilderVisitor.prototype.visitSequence = /**
  1714. * @param {?} ast
  1715. * @param {?} context
  1716. * @return {?}
  1717. */
  1718. function (ast, context) {
  1719. var _this = this;
  1720. var /** @type {?} */ subContextCount = context.subContextCount;
  1721. var /** @type {?} */ ctx = context;
  1722. var /** @type {?} */ options = ast.options;
  1723. if (options && (options.params || options.delay)) {
  1724. ctx = context.createSubContext(options);
  1725. ctx.transformIntoNewTimeline();
  1726. if (options.delay != null) {
  1727. if (ctx.previousNode.type == 6 /* Style */) {
  1728. ctx.currentTimeline.snapshotCurrentStyles();
  1729. ctx.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
  1730. }
  1731. var /** @type {?} */ delay = resolveTimingValue(options.delay);
  1732. ctx.delayNextStep(delay);
  1733. }
  1734. }
  1735. if (ast.steps.length) {
  1736. ast.steps.forEach(function (s) { return visitDslNode(_this, s, ctx); });
  1737. // this is here just incase the inner steps only contain or end with a style() call
  1738. ctx.currentTimeline.applyStylesToKeyframe();
  1739. // this means that some animation function within the sequence
  1740. // ended up creating a sub timeline (which means the current
  1741. // timeline cannot overlap with the contents of the sequence)
  1742. if (ctx.subContextCount > subContextCount) {
  1743. ctx.transformIntoNewTimeline();
  1744. }
  1745. }
  1746. context.previousNode = ast;
  1747. };
  1748. /**
  1749. * @param {?} ast
  1750. * @param {?} context
  1751. * @return {?}
  1752. */
  1753. AnimationTimelineBuilderVisitor.prototype.visitGroup = /**
  1754. * @param {?} ast
  1755. * @param {?} context
  1756. * @return {?}
  1757. */
  1758. function (ast, context) {
  1759. var _this = this;
  1760. var /** @type {?} */ innerTimelines = [];
  1761. var /** @type {?} */ furthestTime = context.currentTimeline.currentTime;
  1762. var /** @type {?} */ delay = ast.options && ast.options.delay ? resolveTimingValue(ast.options.delay) : 0;
  1763. ast.steps.forEach(function (s) {
  1764. var /** @type {?} */ innerContext = context.createSubContext(ast.options);
  1765. if (delay) {
  1766. innerContext.delayNextStep(delay);
  1767. }
  1768. visitDslNode(_this, s, innerContext);
  1769. furthestTime = Math.max(furthestTime, innerContext.currentTimeline.currentTime);
  1770. innerTimelines.push(innerContext.currentTimeline);
  1771. });
  1772. // this operation is run after the AST loop because otherwise
  1773. // if the parent timeline's collected styles were updated then
  1774. // it would pass in invalid data into the new-to-be forked items
  1775. innerTimelines.forEach(function (timeline) { return context.currentTimeline.mergeTimelineCollectedStyles(timeline); });
  1776. context.transformIntoNewTimeline(furthestTime);
  1777. context.previousNode = ast;
  1778. };
  1779. /**
  1780. * @param {?} ast
  1781. * @param {?} context
  1782. * @return {?}
  1783. */
  1784. AnimationTimelineBuilderVisitor.prototype._visitTiming = /**
  1785. * @param {?} ast
  1786. * @param {?} context
  1787. * @return {?}
  1788. */
  1789. function (ast, context) {
  1790. if ((/** @type {?} */ (ast)).dynamic) {
  1791. var /** @type {?} */ strValue = (/** @type {?} */ (ast)).strValue;
  1792. var /** @type {?} */ timingValue = context.params ? interpolateParams(strValue, context.params, context.errors) : strValue;
  1793. return resolveTiming(timingValue, context.errors);
  1794. }
  1795. else {
  1796. return { duration: ast.duration, delay: ast.delay, easing: ast.easing };
  1797. }
  1798. };
  1799. /**
  1800. * @param {?} ast
  1801. * @param {?} context
  1802. * @return {?}
  1803. */
  1804. AnimationTimelineBuilderVisitor.prototype.visitAnimate = /**
  1805. * @param {?} ast
  1806. * @param {?} context
  1807. * @return {?}
  1808. */
  1809. function (ast, context) {
  1810. var /** @type {?} */ timings = context.currentAnimateTimings = this._visitTiming(ast.timings, context);
  1811. var /** @type {?} */ timeline = context.currentTimeline;
  1812. if (timings.delay) {
  1813. context.incrementTime(timings.delay);
  1814. timeline.snapshotCurrentStyles();
  1815. }
  1816. var /** @type {?} */ style$$1 = ast.style;
  1817. if (style$$1.type == 5 /* Keyframes */) {
  1818. this.visitKeyframes(style$$1, context);
  1819. }
  1820. else {
  1821. context.incrementTime(timings.duration);
  1822. this.visitStyle(/** @type {?} */ (style$$1), context);
  1823. timeline.applyStylesToKeyframe();
  1824. }
  1825. context.currentAnimateTimings = null;
  1826. context.previousNode = ast;
  1827. };
  1828. /**
  1829. * @param {?} ast
  1830. * @param {?} context
  1831. * @return {?}
  1832. */
  1833. AnimationTimelineBuilderVisitor.prototype.visitStyle = /**
  1834. * @param {?} ast
  1835. * @param {?} context
  1836. * @return {?}
  1837. */
  1838. function (ast, context) {
  1839. var /** @type {?} */ timeline = context.currentTimeline;
  1840. var /** @type {?} */ timings = /** @type {?} */ ((context.currentAnimateTimings));
  1841. // this is a special case for when a style() call
  1842. // directly follows an animate() call (but not inside of an animate() call)
  1843. if (!timings && timeline.getCurrentStyleProperties().length) {
  1844. timeline.forwardFrame();
  1845. }
  1846. var /** @type {?} */ easing = (timings && timings.easing) || ast.easing;
  1847. if (ast.isEmptyStep) {
  1848. timeline.applyEmptyStep(easing);
  1849. }
  1850. else {
  1851. timeline.setStyles(ast.styles, easing, context.errors, context.options);
  1852. }
  1853. context.previousNode = ast;
  1854. };
  1855. /**
  1856. * @param {?} ast
  1857. * @param {?} context
  1858. * @return {?}
  1859. */
  1860. AnimationTimelineBuilderVisitor.prototype.visitKeyframes = /**
  1861. * @param {?} ast
  1862. * @param {?} context
  1863. * @return {?}
  1864. */
  1865. function (ast, context) {
  1866. var /** @type {?} */ currentAnimateTimings = /** @type {?} */ ((context.currentAnimateTimings));
  1867. var /** @type {?} */ startTime = (/** @type {?} */ ((context.currentTimeline))).duration;
  1868. var /** @type {?} */ duration = currentAnimateTimings.duration;
  1869. var /** @type {?} */ innerContext = context.createSubContext();
  1870. var /** @type {?} */ innerTimeline = innerContext.currentTimeline;
  1871. innerTimeline.easing = currentAnimateTimings.easing;
  1872. ast.styles.forEach(function (step) {
  1873. var /** @type {?} */ offset = step.offset || 0;
  1874. innerTimeline.forwardTime(offset * duration);
  1875. innerTimeline.setStyles(step.styles, step.easing, context.errors, context.options);
  1876. innerTimeline.applyStylesToKeyframe();
  1877. });
  1878. // this will ensure that the parent timeline gets all the styles from
  1879. // the child even if the new timeline below is not used
  1880. context.currentTimeline.mergeTimelineCollectedStyles(innerTimeline);
  1881. // we do this because the window between this timeline and the sub timeline
  1882. // should ensure that the styles within are exactly the same as they were before
  1883. context.transformIntoNewTimeline(startTime + duration);
  1884. context.previousNode = ast;
  1885. };
  1886. /**
  1887. * @param {?} ast
  1888. * @param {?} context
  1889. * @return {?}
  1890. */
  1891. AnimationTimelineBuilderVisitor.prototype.visitQuery = /**
  1892. * @param {?} ast
  1893. * @param {?} context
  1894. * @return {?}
  1895. */
  1896. function (ast, context) {
  1897. var _this = this;
  1898. // in the event that the first step before this is a style step we need
  1899. // to ensure the styles are applied before the children are animated
  1900. var /** @type {?} */ startTime = context.currentTimeline.currentTime;
  1901. var /** @type {?} */ options = /** @type {?} */ ((ast.options || {}));
  1902. var /** @type {?} */ delay = options.delay ? resolveTimingValue(options.delay) : 0;
  1903. if (delay && (context.previousNode.type === 6 /* Style */ ||
  1904. (startTime == 0 && context.currentTimeline.getCurrentStyleProperties().length))) {
  1905. context.currentTimeline.snapshotCurrentStyles();
  1906. context.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
  1907. }
  1908. var /** @type {?} */ furthestTime = startTime;
  1909. var /** @type {?} */ elms = context.invokeQuery(ast.selector, ast.originalSelector, ast.limit, ast.includeSelf, options.optional ? true : false, context.errors);
  1910. context.currentQueryTotal = elms.length;
  1911. var /** @type {?} */ sameElementTimeline = null;
  1912. elms.forEach(function (element, i) {
  1913. context.currentQueryIndex = i;
  1914. var /** @type {?} */ innerContext = context.createSubContext(ast.options, element);
  1915. if (delay) {
  1916. innerContext.delayNextStep(delay);
  1917. }
  1918. if (element === context.element) {
  1919. sameElementTimeline = innerContext.currentTimeline;
  1920. }
  1921. visitDslNode(_this, ast.animation, innerContext);
  1922. // this is here just incase the inner steps only contain or end
  1923. // with a style() call (which is here to signal that this is a preparatory
  1924. // call to style an element before it is animated again)
  1925. innerContext.currentTimeline.applyStylesToKeyframe();
  1926. var /** @type {?} */ endTime = innerContext.currentTimeline.currentTime;
  1927. furthestTime = Math.max(furthestTime, endTime);
  1928. });
  1929. context.currentQueryIndex = 0;
  1930. context.currentQueryTotal = 0;
  1931. context.transformIntoNewTimeline(furthestTime);
  1932. if (sameElementTimeline) {
  1933. context.currentTimeline.mergeTimelineCollectedStyles(sameElementTimeline);
  1934. context.currentTimeline.snapshotCurrentStyles();
  1935. }
  1936. context.previousNode = ast;
  1937. };
  1938. /**
  1939. * @param {?} ast
  1940. * @param {?} context
  1941. * @return {?}
  1942. */
  1943. AnimationTimelineBuilderVisitor.prototype.visitStagger = /**
  1944. * @param {?} ast
  1945. * @param {?} context
  1946. * @return {?}
  1947. */
  1948. function (ast, context) {
  1949. var /** @type {?} */ parentContext = /** @type {?} */ ((context.parentContext));
  1950. var /** @type {?} */ tl = context.currentTimeline;
  1951. var /** @type {?} */ timings = ast.timings;
  1952. var /** @type {?} */ duration = Math.abs(timings.duration);
  1953. var /** @type {?} */ maxTime = duration * (context.currentQueryTotal - 1);
  1954. var /** @type {?} */ delay = duration * context.currentQueryIndex;
  1955. var /** @type {?} */ staggerTransformer = timings.duration < 0 ? 'reverse' : timings.easing;
  1956. switch (staggerTransformer) {
  1957. case 'reverse':
  1958. delay = maxTime - delay;
  1959. break;
  1960. case 'full':
  1961. delay = parentContext.currentStaggerTime;
  1962. break;
  1963. }
  1964. var /** @type {?} */ timeline = context.currentTimeline;
  1965. if (delay) {
  1966. timeline.delayNextStep(delay);
  1967. }
  1968. var /** @type {?} */ startingTime = timeline.currentTime;
  1969. visitDslNode(this, ast.animation, context);
  1970. context.previousNode = ast;
  1971. // time = duration + delay
  1972. // the reason why this computation is so complex is because
  1973. // the inner timeline may either have a delay value or a stretched
  1974. // keyframe depending on if a subtimeline is not used or is used.
  1975. parentContext.currentStaggerTime =
  1976. (tl.currentTime - startingTime) + (tl.startTime - parentContext.currentTimeline.startTime);
  1977. };
  1978. return AnimationTimelineBuilderVisitor;
  1979. }());
  1980. var DEFAULT_NOOP_PREVIOUS_NODE = /** @type {?} */ ({});
  1981. var AnimationTimelineContext = /** @class */ (function () {
  1982. function AnimationTimelineContext(_driver, element, subInstructions, _enterClassName, _leaveClassName, errors, timelines, initialTimeline) {
  1983. this._driver = _driver;
  1984. this.element = element;
  1985. this.subInstructions = subInstructions;
  1986. this._enterClassName = _enterClassName;
  1987. this._leaveClassName = _leaveClassName;
  1988. this.errors = errors;
  1989. this.timelines = timelines;
  1990. this.parentContext = null;
  1991. this.currentAnimateTimings = null;
  1992. this.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
  1993. this.subContextCount = 0;
  1994. this.options = {};
  1995. this.currentQueryIndex = 0;
  1996. this.currentQueryTotal = 0;
  1997. this.currentStaggerTime = 0;
  1998. this.currentTimeline = initialTimeline || new TimelineBuilder(this._driver, element, 0);
  1999. timelines.push(this.currentTimeline);
  2000. }
  2001. Object.defineProperty(AnimationTimelineContext.prototype, "params", {
  2002. get: /**
  2003. * @return {?}
  2004. */
  2005. function () { return this.options.params; },
  2006. enumerable: true,
  2007. configurable: true
  2008. });
  2009. /**
  2010. * @param {?} options
  2011. * @param {?=} skipIfExists
  2012. * @return {?}
  2013. */
  2014. AnimationTimelineContext.prototype.updateOptions = /**
  2015. * @param {?} options
  2016. * @param {?=} skipIfExists
  2017. * @return {?}
  2018. */
  2019. function (options, skipIfExists) {
  2020. var _this = this;
  2021. if (!options)
  2022. return;
  2023. var /** @type {?} */ newOptions = /** @type {?} */ (options);
  2024. var /** @type {?} */ optionsToUpdate = this.options;
  2025. // NOTE: this will get patched up when other animation methods support duration overrides
  2026. if (newOptions.duration != null) {
  2027. (/** @type {?} */ (optionsToUpdate)).duration = resolveTimingValue(newOptions.duration);
  2028. }
  2029. if (newOptions.delay != null) {
  2030. optionsToUpdate.delay = resolveTimingValue(newOptions.delay);
  2031. }
  2032. var /** @type {?} */ newParams = newOptions.params;
  2033. if (newParams) {
  2034. var /** @type {?} */ paramsToUpdate_1 = /** @type {?} */ ((optionsToUpdate.params));
  2035. if (!paramsToUpdate_1) {
  2036. paramsToUpdate_1 = this.options.params = {};
  2037. }
  2038. Object.keys(newParams).forEach(function (name) {
  2039. if (!skipIfExists || !paramsToUpdate_1.hasOwnProperty(name)) {
  2040. paramsToUpdate_1[name] = interpolateParams(newParams[name], paramsToUpdate_1, _this.errors);
  2041. }
  2042. });
  2043. }
  2044. };
  2045. /**
  2046. * @return {?}
  2047. */
  2048. AnimationTimelineContext.prototype._copyOptions = /**
  2049. * @return {?}
  2050. */
  2051. function () {
  2052. var /** @type {?} */ options = {};
  2053. if (this.options) {
  2054. var /** @type {?} */ oldParams_1 = this.options.params;
  2055. if (oldParams_1) {
  2056. var /** @type {?} */ params_1 = options['params'] = {};
  2057. Object.keys(oldParams_1).forEach(function (name) { params_1[name] = oldParams_1[name]; });
  2058. }
  2059. }
  2060. return options;
  2061. };
  2062. /**
  2063. * @param {?=} options
  2064. * @param {?=} element
  2065. * @param {?=} newTime
  2066. * @return {?}
  2067. */
  2068. AnimationTimelineContext.prototype.createSubContext = /**
  2069. * @param {?=} options
  2070. * @param {?=} element
  2071. * @param {?=} newTime
  2072. * @return {?}
  2073. */
  2074. function (options, element, newTime) {
  2075. if (options === void 0) { options = null; }
  2076. var /** @type {?} */ target = element || this.element;
  2077. var /** @type {?} */ context = new AnimationTimelineContext(this._driver, target, this.subInstructions, this._enterClassName, this._leaveClassName, this.errors, this.timelines, this.currentTimeline.fork(target, newTime || 0));
  2078. context.previousNode = this.previousNode;
  2079. context.currentAnimateTimings = this.currentAnimateTimings;
  2080. context.options = this._copyOptions();
  2081. context.updateOptions(options);
  2082. context.currentQueryIndex = this.currentQueryIndex;
  2083. context.currentQueryTotal = this.currentQueryTotal;
  2084. context.parentContext = this;
  2085. this.subContextCount++;
  2086. return context;
  2087. };
  2088. /**
  2089. * @param {?=} newTime
  2090. * @return {?}
  2091. */
  2092. AnimationTimelineContext.prototype.transformIntoNewTimeline = /**
  2093. * @param {?=} newTime
  2094. * @return {?}
  2095. */
  2096. function (newTime) {
  2097. this.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
  2098. this.currentTimeline = this.currentTimeline.fork(this.element, newTime);
  2099. this.timelines.push(this.currentTimeline);
  2100. return this.currentTimeline;
  2101. };
  2102. /**
  2103. * @param {?} instruction
  2104. * @param {?} duration
  2105. * @param {?} delay
  2106. * @return {?}
  2107. */
  2108. AnimationTimelineContext.prototype.appendInstructionToTimeline = /**
  2109. * @param {?} instruction
  2110. * @param {?} duration
  2111. * @param {?} delay
  2112. * @return {?}
  2113. */
  2114. function (instruction, duration, delay) {
  2115. var /** @type {?} */ updatedTimings = {
  2116. duration: duration != null ? duration : instruction.duration,
  2117. delay: this.currentTimeline.currentTime + (delay != null ? delay : 0) + instruction.delay,
  2118. easing: ''
  2119. };
  2120. var /** @type {?} */ builder = new SubTimelineBuilder(this._driver, instruction.element, instruction.keyframes, instruction.preStyleProps, instruction.postStyleProps, updatedTimings, instruction.stretchStartingKeyframe);
  2121. this.timelines.push(builder);
  2122. return updatedTimings;
  2123. };
  2124. /**
  2125. * @param {?} time
  2126. * @return {?}
  2127. */
  2128. AnimationTimelineContext.prototype.incrementTime = /**
  2129. * @param {?} time
  2130. * @return {?}
  2131. */
  2132. function (time) {
  2133. this.currentTimeline.forwardTime(this.currentTimeline.duration + time);
  2134. };
  2135. /**
  2136. * @param {?} delay
  2137. * @return {?}
  2138. */
  2139. AnimationTimelineContext.prototype.delayNextStep = /**
  2140. * @param {?} delay
  2141. * @return {?}
  2142. */
  2143. function (delay) {
  2144. // negative delays are not yet supported
  2145. if (delay > 0) {
  2146. this.currentTimeline.delayNextStep(delay);
  2147. }
  2148. };
  2149. /**
  2150. * @param {?} selector
  2151. * @param {?} originalSelector
  2152. * @param {?} limit
  2153. * @param {?} includeSelf
  2154. * @param {?} optional
  2155. * @param {?} errors
  2156. * @return {?}
  2157. */
  2158. AnimationTimelineContext.prototype.invokeQuery = /**
  2159. * @param {?} selector
  2160. * @param {?} originalSelector
  2161. * @param {?} limit
  2162. * @param {?} includeSelf
  2163. * @param {?} optional
  2164. * @param {?} errors
  2165. * @return {?}
  2166. */
  2167. function (selector, originalSelector, limit, includeSelf, optional, errors) {
  2168. var /** @type {?} */ results = [];
  2169. if (includeSelf) {
  2170. results.push(this.element);
  2171. }
  2172. if (selector.length > 0) {
  2173. // if :self is only used then the selector is empty
  2174. selector = selector.replace(ENTER_TOKEN_REGEX, '.' + this._enterClassName);
  2175. selector = selector.replace(LEAVE_TOKEN_REGEX, '.' + this._leaveClassName);
  2176. var /** @type {?} */ multi = limit != 1;
  2177. var /** @type {?} */ elements = this._driver.query(this.element, selector, multi);
  2178. if (limit !== 0) {
  2179. elements = limit < 0 ? elements.slice(elements.length + limit, elements.length) :
  2180. elements.slice(0, limit);
  2181. }
  2182. results.push.apply(results, elements);
  2183. }
  2184. if (!optional && results.length == 0) {
  2185. errors.push("`query(\"" + originalSelector + "\")` returned zero elements. (Use `query(\"" + originalSelector + "\", { optional: true })` if you wish to allow this.)");
  2186. }
  2187. return results;
  2188. };
  2189. return AnimationTimelineContext;
  2190. }());
  2191. var TimelineBuilder = /** @class */ (function () {
  2192. function TimelineBuilder(_driver, element, startTime, _elementTimelineStylesLookup) {
  2193. this._driver = _driver;
  2194. this.element = element;
  2195. this.startTime = startTime;
  2196. this._elementTimelineStylesLookup = _elementTimelineStylesLookup;
  2197. this.duration = 0;
  2198. this._previousKeyframe = {};
  2199. this._currentKeyframe = {};
  2200. this._keyframes = new Map();
  2201. this._styleSummary = {};
  2202. this._pendingStyles = {};
  2203. this._backFill = {};
  2204. this._currentEmptyStepKeyframe = null;
  2205. if (!this._elementTimelineStylesLookup) {
  2206. this._elementTimelineStylesLookup = new Map();
  2207. }
  2208. this._localTimelineStyles = Object.create(this._backFill, {});
  2209. this._globalTimelineStyles = /** @type {?} */ ((this._elementTimelineStylesLookup.get(element)));
  2210. if (!this._globalTimelineStyles) {
  2211. this._globalTimelineStyles = this._localTimelineStyles;
  2212. this._elementTimelineStylesLookup.set(element, this._localTimelineStyles);
  2213. }
  2214. this._loadKeyframe();
  2215. }
  2216. /**
  2217. * @return {?}
  2218. */
  2219. TimelineBuilder.prototype.containsAnimation = /**
  2220. * @return {?}
  2221. */
  2222. function () {
  2223. switch (this._keyframes.size) {
  2224. case 0:
  2225. return false;
  2226. case 1:
  2227. return this.getCurrentStyleProperties().length > 0;
  2228. default:
  2229. return true;
  2230. }
  2231. };
  2232. /**
  2233. * @return {?}
  2234. */
  2235. TimelineBuilder.prototype.getCurrentStyleProperties = /**
  2236. * @return {?}
  2237. */
  2238. function () { return Object.keys(this._currentKeyframe); };
  2239. Object.defineProperty(TimelineBuilder.prototype, "currentTime", {
  2240. get: /**
  2241. * @return {?}
  2242. */
  2243. function () { return this.startTime + this.duration; },
  2244. enumerable: true,
  2245. configurable: true
  2246. });
  2247. /**
  2248. * @param {?} delay
  2249. * @return {?}
  2250. */
  2251. TimelineBuilder.prototype.delayNextStep = /**
  2252. * @param {?} delay
  2253. * @return {?}
  2254. */
  2255. function (delay) {
  2256. // in the event that a style() step is placed right before a stagger()
  2257. // and that style() step is the very first style() value in the animation
  2258. // then we need to make a copy of the keyframe [0, copy, 1] so that the delay
  2259. // properly applies the style() values to work with the stagger...
  2260. var /** @type {?} */ hasPreStyleStep = this._keyframes.size == 1 && Object.keys(this._pendingStyles).length;
  2261. if (this.duration || hasPreStyleStep) {
  2262. this.forwardTime(this.currentTime + delay);
  2263. if (hasPreStyleStep) {
  2264. this.snapshotCurrentStyles();
  2265. }
  2266. }
  2267. else {
  2268. this.startTime += delay;
  2269. }
  2270. };
  2271. /**
  2272. * @param {?} element
  2273. * @param {?=} currentTime
  2274. * @return {?}
  2275. */
  2276. TimelineBuilder.prototype.fork = /**
  2277. * @param {?} element
  2278. * @param {?=} currentTime
  2279. * @return {?}
  2280. */
  2281. function (element, currentTime) {
  2282. this.applyStylesToKeyframe();
  2283. return new TimelineBuilder(this._driver, element, currentTime || this.currentTime, this._elementTimelineStylesLookup);
  2284. };
  2285. /**
  2286. * @return {?}
  2287. */
  2288. TimelineBuilder.prototype._loadKeyframe = /**
  2289. * @return {?}
  2290. */
  2291. function () {
  2292. if (this._currentKeyframe) {
  2293. this._previousKeyframe = this._currentKeyframe;
  2294. }
  2295. this._currentKeyframe = /** @type {?} */ ((this._keyframes.get(this.duration)));
  2296. if (!this._currentKeyframe) {
  2297. this._currentKeyframe = Object.create(this._backFill, {});
  2298. this._keyframes.set(this.duration, this._currentKeyframe);
  2299. }
  2300. };
  2301. /**
  2302. * @return {?}
  2303. */
  2304. TimelineBuilder.prototype.forwardFrame = /**
  2305. * @return {?}
  2306. */
  2307. function () {
  2308. this.duration += ONE_FRAME_IN_MILLISECONDS;
  2309. this._loadKeyframe();
  2310. };
  2311. /**
  2312. * @param {?} time
  2313. * @return {?}
  2314. */
  2315. TimelineBuilder.prototype.forwardTime = /**
  2316. * @param {?} time
  2317. * @return {?}
  2318. */
  2319. function (time) {
  2320. this.applyStylesToKeyframe();
  2321. this.duration = time;
  2322. this._loadKeyframe();
  2323. };
  2324. /**
  2325. * @param {?} prop
  2326. * @param {?} value
  2327. * @return {?}
  2328. */
  2329. TimelineBuilder.prototype._updateStyle = /**
  2330. * @param {?} prop
  2331. * @param {?} value
  2332. * @return {?}
  2333. */
  2334. function (prop, value) {
  2335. this._localTimelineStyles[prop] = value;
  2336. this._globalTimelineStyles[prop] = value;
  2337. this._styleSummary[prop] = { time: this.currentTime, value: value };
  2338. };
  2339. /**
  2340. * @return {?}
  2341. */
  2342. TimelineBuilder.prototype.allowOnlyTimelineStyles = /**
  2343. * @return {?}
  2344. */
  2345. function () { return this._currentEmptyStepKeyframe !== this._currentKeyframe; };
  2346. /**
  2347. * @param {?} easing
  2348. * @return {?}
  2349. */
  2350. TimelineBuilder.prototype.applyEmptyStep = /**
  2351. * @param {?} easing
  2352. * @return {?}
  2353. */
  2354. function (easing) {
  2355. var _this = this;
  2356. if (easing) {
  2357. this._previousKeyframe['easing'] = easing;
  2358. }
  2359. // special case for animate(duration):
  2360. // all missing styles are filled with a `*` value then
  2361. // if any destination styles are filled in later on the same
  2362. // keyframe then they will override the overridden styles
  2363. // We use `_globalTimelineStyles` here because there may be
  2364. // styles in previous keyframes that are not present in this timeline
  2365. Object.keys(this._globalTimelineStyles).forEach(function (prop) {
  2366. _this._backFill[prop] = _this._globalTimelineStyles[prop] || AUTO_STYLE;
  2367. _this._currentKeyframe[prop] = AUTO_STYLE;
  2368. });
  2369. this._currentEmptyStepKeyframe = this._currentKeyframe;
  2370. };
  2371. /**
  2372. * @param {?} input
  2373. * @param {?} easing
  2374. * @param {?} errors
  2375. * @param {?=} options
  2376. * @return {?}
  2377. */
  2378. TimelineBuilder.prototype.setStyles = /**
  2379. * @param {?} input
  2380. * @param {?} easing
  2381. * @param {?} errors
  2382. * @param {?=} options
  2383. * @return {?}
  2384. */
  2385. function (input, easing, errors, options) {
  2386. var _this = this;
  2387. if (easing) {
  2388. this._previousKeyframe['easing'] = easing;
  2389. }
  2390. var /** @type {?} */ params = (options && options.params) || {};
  2391. var /** @type {?} */ styles = flattenStyles(input, this._globalTimelineStyles);
  2392. Object.keys(styles).forEach(function (prop) {
  2393. var /** @type {?} */ val = interpolateParams(styles[prop], params, errors);
  2394. _this._pendingStyles[prop] = val;
  2395. if (!_this._localTimelineStyles.hasOwnProperty(prop)) {
  2396. _this._backFill[prop] = _this._globalTimelineStyles.hasOwnProperty(prop) ?
  2397. _this._globalTimelineStyles[prop] :
  2398. AUTO_STYLE;
  2399. }
  2400. _this._updateStyle(prop, val);
  2401. });
  2402. };
  2403. /**
  2404. * @return {?}
  2405. */
  2406. TimelineBuilder.prototype.applyStylesToKeyframe = /**
  2407. * @return {?}
  2408. */
  2409. function () {
  2410. var _this = this;
  2411. var /** @type {?} */ styles = this._pendingStyles;
  2412. var /** @type {?} */ props = Object.keys(styles);
  2413. if (props.length == 0)
  2414. return;
  2415. this._pendingStyles = {};
  2416. props.forEach(function (prop) {
  2417. var /** @type {?} */ val = styles[prop];
  2418. _this._currentKeyframe[prop] = val;
  2419. });
  2420. Object.keys(this._localTimelineStyles).forEach(function (prop) {
  2421. if (!_this._currentKeyframe.hasOwnProperty(prop)) {
  2422. _this._currentKeyframe[prop] = _this._localTimelineStyles[prop];
  2423. }
  2424. });
  2425. };
  2426. /**
  2427. * @return {?}
  2428. */
  2429. TimelineBuilder.prototype.snapshotCurrentStyles = /**
  2430. * @return {?}
  2431. */
  2432. function () {
  2433. var _this = this;
  2434. Object.keys(this._localTimelineStyles).forEach(function (prop) {
  2435. var /** @type {?} */ val = _this._localTimelineStyles[prop];
  2436. _this._pendingStyles[prop] = val;
  2437. _this._updateStyle(prop, val);
  2438. });
  2439. };
  2440. /**
  2441. * @return {?}
  2442. */
  2443. TimelineBuilder.prototype.getFinalKeyframe = /**
  2444. * @return {?}
  2445. */
  2446. function () { return this._keyframes.get(this.duration); };
  2447. Object.defineProperty(TimelineBuilder.prototype, "properties", {
  2448. get: /**
  2449. * @return {?}
  2450. */
  2451. function () {
  2452. var /** @type {?} */ properties = [];
  2453. for (var /** @type {?} */ prop in this._currentKeyframe) {
  2454. properties.push(prop);
  2455. }
  2456. return properties;
  2457. },
  2458. enumerable: true,
  2459. configurable: true
  2460. });
  2461. /**
  2462. * @param {?} timeline
  2463. * @return {?}
  2464. */
  2465. TimelineBuilder.prototype.mergeTimelineCollectedStyles = /**
  2466. * @param {?} timeline
  2467. * @return {?}
  2468. */
  2469. function (timeline) {
  2470. var _this = this;
  2471. Object.keys(timeline._styleSummary).forEach(function (prop) {
  2472. var /** @type {?} */ details0 = _this._styleSummary[prop];
  2473. var /** @type {?} */ details1 = timeline._styleSummary[prop];
  2474. if (!details0 || details1.time > details0.time) {
  2475. _this._updateStyle(prop, details1.value);
  2476. }
  2477. });
  2478. };
  2479. /**
  2480. * @return {?}
  2481. */
  2482. TimelineBuilder.prototype.buildKeyframes = /**
  2483. * @return {?}
  2484. */
  2485. function () {
  2486. var _this = this;
  2487. this.applyStylesToKeyframe();
  2488. var /** @type {?} */ preStyleProps = new Set();
  2489. var /** @type {?} */ postStyleProps = new Set();
  2490. var /** @type {?} */ isEmpty = this._keyframes.size === 1 && this.duration === 0;
  2491. var /** @type {?} */ finalKeyframes = [];
  2492. this._keyframes.forEach(function (keyframe, time) {
  2493. var /** @type {?} */ finalKeyframe = copyStyles(keyframe, true);
  2494. Object.keys(finalKeyframe).forEach(function (prop) {
  2495. var /** @type {?} */ value = finalKeyframe[prop];
  2496. if (value == ɵPRE_STYLE) {
  2497. preStyleProps.add(prop);
  2498. }
  2499. else if (value == AUTO_STYLE) {
  2500. postStyleProps.add(prop);
  2501. }
  2502. });
  2503. if (!isEmpty) {
  2504. finalKeyframe['offset'] = time / _this.duration;
  2505. }
  2506. finalKeyframes.push(finalKeyframe);
  2507. });
  2508. var /** @type {?} */ preProps = preStyleProps.size ? iteratorToArray(preStyleProps.values()) : [];
  2509. var /** @type {?} */ postProps = postStyleProps.size ? iteratorToArray(postStyleProps.values()) : [];
  2510. // special case for a 0-second animation (which is designed just to place styles onscreen)
  2511. if (isEmpty) {
  2512. var /** @type {?} */ kf0 = finalKeyframes[0];
  2513. var /** @type {?} */ kf1 = copyObj(kf0);
  2514. kf0['offset'] = 0;
  2515. kf1['offset'] = 1;
  2516. finalKeyframes = [kf0, kf1];
  2517. }
  2518. return createTimelineInstruction(this.element, finalKeyframes, preProps, postProps, this.duration, this.startTime, this.easing, false);
  2519. };
  2520. return TimelineBuilder;
  2521. }());
  2522. var SubTimelineBuilder = /** @class */ (function (_super) {
  2523. __extends(SubTimelineBuilder, _super);
  2524. function SubTimelineBuilder(driver, element, keyframes, preStyleProps, postStyleProps, timings, _stretchStartingKeyframe) {
  2525. if (_stretchStartingKeyframe === void 0) { _stretchStartingKeyframe = false; }
  2526. var _this = _super.call(this, driver, element, timings.delay) || this;
  2527. _this.element = element;
  2528. _this.keyframes = keyframes;
  2529. _this.preStyleProps = preStyleProps;
  2530. _this.postStyleProps = postStyleProps;
  2531. _this._stretchStartingKeyframe = _stretchStartingKeyframe;
  2532. _this.timings = { duration: timings.duration, delay: timings.delay, easing: timings.easing };
  2533. return _this;
  2534. }
  2535. /**
  2536. * @return {?}
  2537. */
  2538. SubTimelineBuilder.prototype.containsAnimation = /**
  2539. * @return {?}
  2540. */
  2541. function () { return this.keyframes.length > 1; };
  2542. /**
  2543. * @return {?}
  2544. */
  2545. SubTimelineBuilder.prototype.buildKeyframes = /**
  2546. * @return {?}
  2547. */
  2548. function () {
  2549. var /** @type {?} */ keyframes = this.keyframes;
  2550. var _a = this.timings, delay = _a.delay, duration = _a.duration, easing = _a.easing;
  2551. if (this._stretchStartingKeyframe && delay) {
  2552. var /** @type {?} */ newKeyframes = [];
  2553. var /** @type {?} */ totalTime = duration + delay;
  2554. var /** @type {?} */ startingGap = delay / totalTime;
  2555. // the original starting keyframe now starts once the delay is done
  2556. var /** @type {?} */ newFirstKeyframe = copyStyles(keyframes[0], false);
  2557. newFirstKeyframe['offset'] = 0;
  2558. newKeyframes.push(newFirstKeyframe);
  2559. var /** @type {?} */ oldFirstKeyframe = copyStyles(keyframes[0], false);
  2560. oldFirstKeyframe['offset'] = roundOffset(startingGap);
  2561. newKeyframes.push(oldFirstKeyframe);
  2562. /*
  2563. When the keyframe is stretched then it means that the delay before the animation
  2564. starts is gone. Instead the first keyframe is placed at the start of the animation
  2565. and it is then copied to where it starts when the original delay is over. This basically
  2566. means nothing animates during that delay, but the styles are still renderered. For this
  2567. to work the original offset values that exist in the original keyframes must be "warped"
  2568. so that they can take the new keyframe + delay into account.
  2569. delay=1000, duration=1000, keyframes = 0 .5 1
  2570. turns into
  2571. delay=0, duration=2000, keyframes = 0 .33 .66 1
  2572. */
  2573. // offsets between 1 ... n -1 are all warped by the keyframe stretch
  2574. var /** @type {?} */ limit = keyframes.length - 1;
  2575. for (var /** @type {?} */ i = 1; i <= limit; i++) {
  2576. var /** @type {?} */ kf = copyStyles(keyframes[i], false);
  2577. var /** @type {?} */ oldOffset = /** @type {?} */ (kf['offset']);
  2578. var /** @type {?} */ timeAtKeyframe = delay + oldOffset * duration;
  2579. kf['offset'] = roundOffset(timeAtKeyframe / totalTime);
  2580. newKeyframes.push(kf);
  2581. }
  2582. // the new starting keyframe should be added at the start
  2583. duration = totalTime;
  2584. delay = 0;
  2585. easing = '';
  2586. keyframes = newKeyframes;
  2587. }
  2588. return createTimelineInstruction(this.element, keyframes, this.preStyleProps, this.postStyleProps, duration, delay, easing, true);
  2589. };
  2590. return SubTimelineBuilder;
  2591. }(TimelineBuilder));
  2592. /**
  2593. * @param {?} offset
  2594. * @param {?=} decimalPoints
  2595. * @return {?}
  2596. */
  2597. function roundOffset(offset, decimalPoints) {
  2598. if (decimalPoints === void 0) { decimalPoints = 3; }
  2599. var /** @type {?} */ mult = Math.pow(10, decimalPoints - 1);
  2600. return Math.round(offset * mult) / mult;
  2601. }
  2602. /**
  2603. * @param {?} input
  2604. * @param {?} allStyles
  2605. * @return {?}
  2606. */
  2607. function flattenStyles(input, allStyles) {
  2608. var /** @type {?} */ styles = {};
  2609. var /** @type {?} */ allProperties;
  2610. input.forEach(function (token) {
  2611. if (token === '*') {
  2612. allProperties = allProperties || Object.keys(allStyles);
  2613. allProperties.forEach(function (prop) { styles[prop] = AUTO_STYLE; });
  2614. }
  2615. else {
  2616. copyStyles(/** @type {?} */ (token), false, styles);
  2617. }
  2618. });
  2619. return styles;
  2620. }
  2621. /**
  2622. * @fileoverview added by tsickle
  2623. * @suppress {checkTypes} checked by tsc
  2624. */
  2625. var Animation = /** @class */ (function () {
  2626. function Animation(_driver, input) {
  2627. this._driver = _driver;
  2628. var /** @type {?} */ errors = [];
  2629. var /** @type {?} */ ast = buildAnimationAst(_driver, input, errors);
  2630. if (errors.length) {
  2631. var /** @type {?} */ errorMessage = "animation validation failed:\n" + errors.join("\n");
  2632. throw new Error(errorMessage);
  2633. }
  2634. this._animationAst = ast;
  2635. }
  2636. /**
  2637. * @param {?} element
  2638. * @param {?} startingStyles
  2639. * @param {?} destinationStyles
  2640. * @param {?} options
  2641. * @param {?=} subInstructions
  2642. * @return {?}
  2643. */
  2644. Animation.prototype.buildTimelines = /**
  2645. * @param {?} element
  2646. * @param {?} startingStyles
  2647. * @param {?} destinationStyles
  2648. * @param {?} options
  2649. * @param {?=} subInstructions
  2650. * @return {?}
  2651. */
  2652. function (element, startingStyles, destinationStyles, options, subInstructions) {
  2653. var /** @type {?} */ start = Array.isArray(startingStyles) ? normalizeStyles(startingStyles) : /** @type {?} */ (startingStyles);
  2654. var /** @type {?} */ dest = Array.isArray(destinationStyles) ? normalizeStyles(destinationStyles) : /** @type {?} */ (destinationStyles);
  2655. var /** @type {?} */ errors = [];
  2656. subInstructions = subInstructions || new ElementInstructionMap();
  2657. var /** @type {?} */ result = buildAnimationTimelines(this._driver, element, this._animationAst, ENTER_CLASSNAME, LEAVE_CLASSNAME, start, dest, options, subInstructions, errors);
  2658. if (errors.length) {
  2659. var /** @type {?} */ errorMessage = "animation building failed:\n" + errors.join("\n");
  2660. throw new Error(errorMessage);
  2661. }
  2662. return result;
  2663. };
  2664. return Animation;
  2665. }());
  2666. /**
  2667. * @fileoverview added by tsickle
  2668. * @suppress {checkTypes} checked by tsc
  2669. */
  2670. /**
  2671. * @license
  2672. * Copyright Google Inc. All Rights Reserved.
  2673. *
  2674. * Use of this source code is governed by an MIT-style license that can be
  2675. * found in the LICENSE file at https://angular.io/license
  2676. */
  2677. /**
  2678. * \@experimental Animation support is experimental.
  2679. * @abstract
  2680. */
  2681. var AnimationStyleNormalizer = /** @class */ (function () {
  2682. function AnimationStyleNormalizer() {
  2683. }
  2684. return AnimationStyleNormalizer;
  2685. }());
  2686. /**
  2687. * \@experimental Animation support is experimental.
  2688. */
  2689. var NoopAnimationStyleNormalizer = /** @class */ (function () {
  2690. function NoopAnimationStyleNormalizer() {
  2691. }
  2692. /**
  2693. * @param {?} propertyName
  2694. * @param {?} errors
  2695. * @return {?}
  2696. */
  2697. NoopAnimationStyleNormalizer.prototype.normalizePropertyName = /**
  2698. * @param {?} propertyName
  2699. * @param {?} errors
  2700. * @return {?}
  2701. */
  2702. function (propertyName, errors) { return propertyName; };
  2703. /**
  2704. * @param {?} userProvidedProperty
  2705. * @param {?} normalizedProperty
  2706. * @param {?} value
  2707. * @param {?} errors
  2708. * @return {?}
  2709. */
  2710. NoopAnimationStyleNormalizer.prototype.normalizeStyleValue = /**
  2711. * @param {?} userProvidedProperty
  2712. * @param {?} normalizedProperty
  2713. * @param {?} value
  2714. * @param {?} errors
  2715. * @return {?}
  2716. */
  2717. function (userProvidedProperty, normalizedProperty, value, errors) {
  2718. return /** @type {?} */ (value);
  2719. };
  2720. return NoopAnimationStyleNormalizer;
  2721. }());
  2722. /**
  2723. * @fileoverview added by tsickle
  2724. * @suppress {checkTypes} checked by tsc
  2725. */
  2726. var WebAnimationsStyleNormalizer = /** @class */ (function (_super) {
  2727. __extends(WebAnimationsStyleNormalizer, _super);
  2728. function WebAnimationsStyleNormalizer() {
  2729. return _super !== null && _super.apply(this, arguments) || this;
  2730. }
  2731. /**
  2732. * @param {?} propertyName
  2733. * @param {?} errors
  2734. * @return {?}
  2735. */
  2736. WebAnimationsStyleNormalizer.prototype.normalizePropertyName = /**
  2737. * @param {?} propertyName
  2738. * @param {?} errors
  2739. * @return {?}
  2740. */
  2741. function (propertyName, errors) {
  2742. return dashCaseToCamelCase(propertyName);
  2743. };
  2744. /**
  2745. * @param {?} userProvidedProperty
  2746. * @param {?} normalizedProperty
  2747. * @param {?} value
  2748. * @param {?} errors
  2749. * @return {?}
  2750. */
  2751. WebAnimationsStyleNormalizer.prototype.normalizeStyleValue = /**
  2752. * @param {?} userProvidedProperty
  2753. * @param {?} normalizedProperty
  2754. * @param {?} value
  2755. * @param {?} errors
  2756. * @return {?}
  2757. */
  2758. function (userProvidedProperty, normalizedProperty, value, errors) {
  2759. var /** @type {?} */ unit = '';
  2760. var /** @type {?} */ strVal = value.toString().trim();
  2761. if (DIMENSIONAL_PROP_MAP[normalizedProperty] && value !== 0 && value !== '0') {
  2762. if (typeof value === 'number') {
  2763. unit = 'px';
  2764. }
  2765. else {
  2766. var /** @type {?} */ valAndSuffixMatch = value.match(/^[+-]?[\d\.]+([a-z]*)$/);
  2767. if (valAndSuffixMatch && valAndSuffixMatch[1].length == 0) {
  2768. errors.push("Please provide a CSS unit value for " + userProvidedProperty + ":" + value);
  2769. }
  2770. }
  2771. }
  2772. return strVal + unit;
  2773. };
  2774. return WebAnimationsStyleNormalizer;
  2775. }(AnimationStyleNormalizer));
  2776. var DIMENSIONAL_PROP_MAP = makeBooleanMap('width,height,minWidth,minHeight,maxWidth,maxHeight,left,top,bottom,right,fontSize,outlineWidth,outlineOffset,paddingTop,paddingLeft,paddingBottom,paddingRight,marginTop,marginLeft,marginBottom,marginRight,borderRadius,borderWidth,borderTopWidth,borderLeftWidth,borderRightWidth,borderBottomWidth,textIndent,perspective'
  2777. .split(','));
  2778. /**
  2779. * @param {?} keys
  2780. * @return {?}
  2781. */
  2782. function makeBooleanMap(keys) {
  2783. var /** @type {?} */ map = {};
  2784. keys.forEach(function (key) { return map[key] = true; });
  2785. return map;
  2786. }
  2787. /**
  2788. * @fileoverview added by tsickle
  2789. * @suppress {checkTypes} checked by tsc
  2790. */
  2791. /**
  2792. * @record
  2793. */
  2794. /**
  2795. * @param {?} element
  2796. * @param {?} triggerName
  2797. * @param {?} fromState
  2798. * @param {?} toState
  2799. * @param {?} isRemovalTransition
  2800. * @param {?} fromStyles
  2801. * @param {?} toStyles
  2802. * @param {?} timelines
  2803. * @param {?} queriedElements
  2804. * @param {?} preStyleProps
  2805. * @param {?} postStyleProps
  2806. * @param {?=} errors
  2807. * @return {?}
  2808. */
  2809. function createTransitionInstruction(element, triggerName, fromState, toState, isRemovalTransition, fromStyles, toStyles, timelines, queriedElements, preStyleProps, postStyleProps, errors) {
  2810. return {
  2811. type: 0 /* TransitionAnimation */,
  2812. element: element,
  2813. triggerName: triggerName,
  2814. isRemovalTransition: isRemovalTransition,
  2815. fromState: fromState,
  2816. fromStyles: fromStyles,
  2817. toState: toState,
  2818. toStyles: toStyles,
  2819. timelines: timelines,
  2820. queriedElements: queriedElements,
  2821. preStyleProps: preStyleProps,
  2822. postStyleProps: postStyleProps,
  2823. errors: errors
  2824. };
  2825. }
  2826. /**
  2827. * @fileoverview added by tsickle
  2828. * @suppress {checkTypes} checked by tsc
  2829. */
  2830. var EMPTY_OBJECT = {};
  2831. var AnimationTransitionFactory = /** @class */ (function () {
  2832. function AnimationTransitionFactory(_triggerName, ast, _stateStyles) {
  2833. this._triggerName = _triggerName;
  2834. this.ast = ast;
  2835. this._stateStyles = _stateStyles;
  2836. }
  2837. /**
  2838. * @param {?} currentState
  2839. * @param {?} nextState
  2840. * @return {?}
  2841. */
  2842. AnimationTransitionFactory.prototype.match = /**
  2843. * @param {?} currentState
  2844. * @param {?} nextState
  2845. * @return {?}
  2846. */
  2847. function (currentState, nextState) {
  2848. return oneOrMoreTransitionsMatch(this.ast.matchers, currentState, nextState);
  2849. };
  2850. /**
  2851. * @param {?} stateName
  2852. * @param {?} params
  2853. * @param {?} errors
  2854. * @return {?}
  2855. */
  2856. AnimationTransitionFactory.prototype.buildStyles = /**
  2857. * @param {?} stateName
  2858. * @param {?} params
  2859. * @param {?} errors
  2860. * @return {?}
  2861. */
  2862. function (stateName, params, errors) {
  2863. var /** @type {?} */ backupStateStyler = this._stateStyles['*'];
  2864. var /** @type {?} */ stateStyler = this._stateStyles[stateName];
  2865. var /** @type {?} */ backupStyles = backupStateStyler ? backupStateStyler.buildStyles(params, errors) : {};
  2866. return stateStyler ? stateStyler.buildStyles(params, errors) : backupStyles;
  2867. };
  2868. /**
  2869. * @param {?} driver
  2870. * @param {?} element
  2871. * @param {?} currentState
  2872. * @param {?} nextState
  2873. * @param {?} enterClassName
  2874. * @param {?} leaveClassName
  2875. * @param {?=} currentOptions
  2876. * @param {?=} nextOptions
  2877. * @param {?=} subInstructions
  2878. * @return {?}
  2879. */
  2880. AnimationTransitionFactory.prototype.build = /**
  2881. * @param {?} driver
  2882. * @param {?} element
  2883. * @param {?} currentState
  2884. * @param {?} nextState
  2885. * @param {?} enterClassName
  2886. * @param {?} leaveClassName
  2887. * @param {?=} currentOptions
  2888. * @param {?=} nextOptions
  2889. * @param {?=} subInstructions
  2890. * @return {?}
  2891. */
  2892. function (driver, element, currentState, nextState, enterClassName, leaveClassName, currentOptions, nextOptions, subInstructions) {
  2893. var /** @type {?} */ errors = [];
  2894. var /** @type {?} */ transitionAnimationParams = this.ast.options && this.ast.options.params || EMPTY_OBJECT;
  2895. var /** @type {?} */ currentAnimationParams = currentOptions && currentOptions.params || EMPTY_OBJECT;
  2896. var /** @type {?} */ currentStateStyles = this.buildStyles(currentState, currentAnimationParams, errors);
  2897. var /** @type {?} */ nextAnimationParams = nextOptions && nextOptions.params || EMPTY_OBJECT;
  2898. var /** @type {?} */ nextStateStyles = this.buildStyles(nextState, nextAnimationParams, errors);
  2899. var /** @type {?} */ queriedElements = new Set();
  2900. var /** @type {?} */ preStyleMap = new Map();
  2901. var /** @type {?} */ postStyleMap = new Map();
  2902. var /** @type {?} */ isRemoval = nextState === 'void';
  2903. var /** @type {?} */ animationOptions = { params: __assign({}, transitionAnimationParams, nextAnimationParams) };
  2904. var /** @type {?} */ timelines = buildAnimationTimelines(driver, element, this.ast.animation, enterClassName, leaveClassName, currentStateStyles, nextStateStyles, animationOptions, subInstructions, errors);
  2905. if (errors.length) {
  2906. return createTransitionInstruction(element, this._triggerName, currentState, nextState, isRemoval, currentStateStyles, nextStateStyles, [], [], preStyleMap, postStyleMap, errors);
  2907. }
  2908. timelines.forEach(function (tl) {
  2909. var /** @type {?} */ elm = tl.element;
  2910. var /** @type {?} */ preProps = getOrSetAsInMap(preStyleMap, elm, {});
  2911. tl.preStyleProps.forEach(function (prop) { return preProps[prop] = true; });
  2912. var /** @type {?} */ postProps = getOrSetAsInMap(postStyleMap, elm, {});
  2913. tl.postStyleProps.forEach(function (prop) { return postProps[prop] = true; });
  2914. if (elm !== element) {
  2915. queriedElements.add(elm);
  2916. }
  2917. });
  2918. var /** @type {?} */ queriedElementsList = iteratorToArray(queriedElements.values());
  2919. return createTransitionInstruction(element, this._triggerName, currentState, nextState, isRemoval, currentStateStyles, nextStateStyles, timelines, queriedElementsList, preStyleMap, postStyleMap);
  2920. };
  2921. return AnimationTransitionFactory;
  2922. }());
  2923. /**
  2924. * @param {?} matchFns
  2925. * @param {?} currentState
  2926. * @param {?} nextState
  2927. * @return {?}
  2928. */
  2929. function oneOrMoreTransitionsMatch(matchFns, currentState, nextState) {
  2930. return matchFns.some(function (fn) { return fn(currentState, nextState); });
  2931. }
  2932. var AnimationStateStyles = /** @class */ (function () {
  2933. function AnimationStateStyles(styles, defaultParams) {
  2934. this.styles = styles;
  2935. this.defaultParams = defaultParams;
  2936. }
  2937. /**
  2938. * @param {?} params
  2939. * @param {?} errors
  2940. * @return {?}
  2941. */
  2942. AnimationStateStyles.prototype.buildStyles = /**
  2943. * @param {?} params
  2944. * @param {?} errors
  2945. * @return {?}
  2946. */
  2947. function (params, errors) {
  2948. var /** @type {?} */ finalStyles = {};
  2949. var /** @type {?} */ combinedParams = copyObj(this.defaultParams);
  2950. Object.keys(params).forEach(function (key) {
  2951. var /** @type {?} */ value = params[key];
  2952. if (value != null) {
  2953. combinedParams[key] = value;
  2954. }
  2955. });
  2956. this.styles.styles.forEach(function (value) {
  2957. if (typeof value !== 'string') {
  2958. var /** @type {?} */ styleObj_1 = /** @type {?} */ (value);
  2959. Object.keys(styleObj_1).forEach(function (prop) {
  2960. var /** @type {?} */ val = styleObj_1[prop];
  2961. if (val.length > 1) {
  2962. val = interpolateParams(val, combinedParams, errors);
  2963. }
  2964. finalStyles[prop] = val;
  2965. });
  2966. }
  2967. });
  2968. return finalStyles;
  2969. };
  2970. return AnimationStateStyles;
  2971. }());
  2972. /**
  2973. * @fileoverview added by tsickle
  2974. * @suppress {checkTypes} checked by tsc
  2975. */
  2976. /**
  2977. * \@experimental Animation support is experimental.
  2978. * @param {?} name
  2979. * @param {?} ast
  2980. * @return {?}
  2981. */
  2982. function buildTrigger(name, ast) {
  2983. return new AnimationTrigger(name, ast);
  2984. }
  2985. /**
  2986. * \@experimental Animation support is experimental.
  2987. */
  2988. var AnimationTrigger = /** @class */ (function () {
  2989. function AnimationTrigger(name, ast) {
  2990. var _this = this;
  2991. this.name = name;
  2992. this.ast = ast;
  2993. this.transitionFactories = [];
  2994. this.states = {};
  2995. ast.states.forEach(function (ast) {
  2996. var /** @type {?} */ defaultParams = (ast.options && ast.options.params) || {};
  2997. _this.states[ast.name] = new AnimationStateStyles(ast.style, defaultParams);
  2998. });
  2999. balanceProperties(this.states, 'true', '1');
  3000. balanceProperties(this.states, 'false', '0');
  3001. ast.transitions.forEach(function (ast) {
  3002. _this.transitionFactories.push(new AnimationTransitionFactory(name, ast, _this.states));
  3003. });
  3004. this.fallbackTransition = createFallbackTransition(name, this.states);
  3005. }
  3006. Object.defineProperty(AnimationTrigger.prototype, "containsQueries", {
  3007. get: /**
  3008. * @return {?}
  3009. */
  3010. function () { return this.ast.queryCount > 0; },
  3011. enumerable: true,
  3012. configurable: true
  3013. });
  3014. /**
  3015. * @param {?} currentState
  3016. * @param {?} nextState
  3017. * @return {?}
  3018. */
  3019. AnimationTrigger.prototype.matchTransition = /**
  3020. * @param {?} currentState
  3021. * @param {?} nextState
  3022. * @return {?}
  3023. */
  3024. function (currentState, nextState) {
  3025. var /** @type {?} */ entry = this.transitionFactories.find(function (f) { return f.match(currentState, nextState); });
  3026. return entry || null;
  3027. };
  3028. /**
  3029. * @param {?} currentState
  3030. * @param {?} params
  3031. * @param {?} errors
  3032. * @return {?}
  3033. */
  3034. AnimationTrigger.prototype.matchStyles = /**
  3035. * @param {?} currentState
  3036. * @param {?} params
  3037. * @param {?} errors
  3038. * @return {?}
  3039. */
  3040. function (currentState, params, errors) {
  3041. return this.fallbackTransition.buildStyles(currentState, params, errors);
  3042. };
  3043. return AnimationTrigger;
  3044. }());
  3045. /**
  3046. * @param {?} triggerName
  3047. * @param {?} states
  3048. * @return {?}
  3049. */
  3050. function createFallbackTransition(triggerName, states) {
  3051. var /** @type {?} */ matchers = [function (fromState, toState) { return true; }];
  3052. var /** @type {?} */ animation = { type: 2 /* Sequence */, steps: [], options: null };
  3053. var /** @type {?} */ transition = {
  3054. type: 1 /* Transition */,
  3055. animation: animation,
  3056. matchers: matchers,
  3057. options: null,
  3058. queryCount: 0,
  3059. depCount: 0
  3060. };
  3061. return new AnimationTransitionFactory(triggerName, transition, states);
  3062. }
  3063. /**
  3064. * @param {?} obj
  3065. * @param {?} key1
  3066. * @param {?} key2
  3067. * @return {?}
  3068. */
  3069. function balanceProperties(obj, key1, key2) {
  3070. if (obj.hasOwnProperty(key1)) {
  3071. if (!obj.hasOwnProperty(key2)) {
  3072. obj[key2] = obj[key1];
  3073. }
  3074. }
  3075. else if (obj.hasOwnProperty(key2)) {
  3076. obj[key1] = obj[key2];
  3077. }
  3078. }
  3079. /**
  3080. * @fileoverview added by tsickle
  3081. * @suppress {checkTypes} checked by tsc
  3082. */
  3083. var EMPTY_INSTRUCTION_MAP = new ElementInstructionMap();
  3084. var TimelineAnimationEngine = /** @class */ (function () {
  3085. function TimelineAnimationEngine(_driver, _normalizer) {
  3086. this._driver = _driver;
  3087. this._normalizer = _normalizer;
  3088. this._animations = {};
  3089. this._playersById = {};
  3090. this.players = [];
  3091. }
  3092. /**
  3093. * @param {?} id
  3094. * @param {?} metadata
  3095. * @return {?}
  3096. */
  3097. TimelineAnimationEngine.prototype.register = /**
  3098. * @param {?} id
  3099. * @param {?} metadata
  3100. * @return {?}
  3101. */
  3102. function (id, metadata) {
  3103. var /** @type {?} */ errors = [];
  3104. var /** @type {?} */ ast = buildAnimationAst(this._driver, metadata, errors);
  3105. if (errors.length) {
  3106. throw new Error("Unable to build the animation due to the following errors: " + errors.join("\n"));
  3107. }
  3108. else {
  3109. this._animations[id] = ast;
  3110. }
  3111. };
  3112. /**
  3113. * @param {?} i
  3114. * @param {?} preStyles
  3115. * @param {?=} postStyles
  3116. * @return {?}
  3117. */
  3118. TimelineAnimationEngine.prototype._buildPlayer = /**
  3119. * @param {?} i
  3120. * @param {?} preStyles
  3121. * @param {?=} postStyles
  3122. * @return {?}
  3123. */
  3124. function (i, preStyles, postStyles) {
  3125. var /** @type {?} */ element = i.element;
  3126. var /** @type {?} */ keyframes = normalizeKeyframes(this._driver, this._normalizer, element, i.keyframes, preStyles, postStyles);
  3127. return this._driver.animate(element, keyframes, i.duration, i.delay, i.easing, []);
  3128. };
  3129. /**
  3130. * @param {?} id
  3131. * @param {?} element
  3132. * @param {?=} options
  3133. * @return {?}
  3134. */
  3135. TimelineAnimationEngine.prototype.create = /**
  3136. * @param {?} id
  3137. * @param {?} element
  3138. * @param {?=} options
  3139. * @return {?}
  3140. */
  3141. function (id, element, options) {
  3142. var _this = this;
  3143. if (options === void 0) { options = {}; }
  3144. var /** @type {?} */ errors = [];
  3145. var /** @type {?} */ ast = this._animations[id];
  3146. var /** @type {?} */ instructions;
  3147. var /** @type {?} */ autoStylesMap = new Map();
  3148. if (ast) {
  3149. instructions = buildAnimationTimelines(this._driver, element, ast, ENTER_CLASSNAME, LEAVE_CLASSNAME, {}, {}, options, EMPTY_INSTRUCTION_MAP, errors);
  3150. instructions.forEach(function (inst) {
  3151. var /** @type {?} */ styles = getOrSetAsInMap(autoStylesMap, inst.element, {});
  3152. inst.postStyleProps.forEach(function (prop) { return styles[prop] = null; });
  3153. });
  3154. }
  3155. else {
  3156. errors.push('The requested animation doesn\'t exist or has already been destroyed');
  3157. instructions = [];
  3158. }
  3159. if (errors.length) {
  3160. throw new Error("Unable to create the animation due to the following errors: " + errors.join("\n"));
  3161. }
  3162. autoStylesMap.forEach(function (styles, element) {
  3163. Object.keys(styles).forEach(function (prop) { styles[prop] = _this._driver.computeStyle(element, prop, AUTO_STYLE); });
  3164. });
  3165. var /** @type {?} */ players = instructions.map(function (i) {
  3166. var /** @type {?} */ styles = autoStylesMap.get(i.element);
  3167. return _this._buildPlayer(i, {}, styles);
  3168. });
  3169. var /** @type {?} */ player = optimizeGroupPlayer(players);
  3170. this._playersById[id] = player;
  3171. player.onDestroy(function () { return _this.destroy(id); });
  3172. this.players.push(player);
  3173. return player;
  3174. };
  3175. /**
  3176. * @param {?} id
  3177. * @return {?}
  3178. */
  3179. TimelineAnimationEngine.prototype.destroy = /**
  3180. * @param {?} id
  3181. * @return {?}
  3182. */
  3183. function (id) {
  3184. var /** @type {?} */ player = this._getPlayer(id);
  3185. player.destroy();
  3186. delete this._playersById[id];
  3187. var /** @type {?} */ index = this.players.indexOf(player);
  3188. if (index >= 0) {
  3189. this.players.splice(index, 1);
  3190. }
  3191. };
  3192. /**
  3193. * @param {?} id
  3194. * @return {?}
  3195. */
  3196. TimelineAnimationEngine.prototype._getPlayer = /**
  3197. * @param {?} id
  3198. * @return {?}
  3199. */
  3200. function (id) {
  3201. var /** @type {?} */ player = this._playersById[id];
  3202. if (!player) {
  3203. throw new Error("Unable to find the timeline player referenced by " + id);
  3204. }
  3205. return player;
  3206. };
  3207. /**
  3208. * @param {?} id
  3209. * @param {?} element
  3210. * @param {?} eventName
  3211. * @param {?} callback
  3212. * @return {?}
  3213. */
  3214. TimelineAnimationEngine.prototype.listen = /**
  3215. * @param {?} id
  3216. * @param {?} element
  3217. * @param {?} eventName
  3218. * @param {?} callback
  3219. * @return {?}
  3220. */
  3221. function (id, element, eventName, callback) {
  3222. // triggerName, fromState, toState are all ignored for timeline animations
  3223. var /** @type {?} */ baseEvent = makeAnimationEvent(element, '', '', '');
  3224. listenOnPlayer(this._getPlayer(id), eventName, baseEvent, callback);
  3225. return function () { };
  3226. };
  3227. /**
  3228. * @param {?} id
  3229. * @param {?} element
  3230. * @param {?} command
  3231. * @param {?} args
  3232. * @return {?}
  3233. */
  3234. TimelineAnimationEngine.prototype.command = /**
  3235. * @param {?} id
  3236. * @param {?} element
  3237. * @param {?} command
  3238. * @param {?} args
  3239. * @return {?}
  3240. */
  3241. function (id, element, command, args) {
  3242. if (command == 'register') {
  3243. this.register(id, /** @type {?} */ (args[0]));
  3244. return;
  3245. }
  3246. if (command == 'create') {
  3247. var /** @type {?} */ options = /** @type {?} */ ((args[0] || {}));
  3248. this.create(id, element, options);
  3249. return;
  3250. }
  3251. var /** @type {?} */ player = this._getPlayer(id);
  3252. switch (command) {
  3253. case 'play':
  3254. player.play();
  3255. break;
  3256. case 'pause':
  3257. player.pause();
  3258. break;
  3259. case 'reset':
  3260. player.reset();
  3261. break;
  3262. case 'restart':
  3263. player.restart();
  3264. break;
  3265. case 'finish':
  3266. player.finish();
  3267. break;
  3268. case 'init':
  3269. player.init();
  3270. break;
  3271. case 'setPosition':
  3272. player.setPosition(parseFloat(/** @type {?} */ (args[0])));
  3273. break;
  3274. case 'destroy':
  3275. this.destroy(id);
  3276. break;
  3277. }
  3278. };
  3279. return TimelineAnimationEngine;
  3280. }());
  3281. /**
  3282. * @fileoverview added by tsickle
  3283. * @suppress {checkTypes} checked by tsc
  3284. */
  3285. var QUEUED_CLASSNAME = 'ng-animate-queued';
  3286. var QUEUED_SELECTOR = '.ng-animate-queued';
  3287. var DISABLED_CLASSNAME = 'ng-animate-disabled';
  3288. var DISABLED_SELECTOR = '.ng-animate-disabled';
  3289. var STAR_CLASSNAME = 'ng-star-inserted';
  3290. var STAR_SELECTOR = '.ng-star-inserted';
  3291. var EMPTY_PLAYER_ARRAY = [];
  3292. var NULL_REMOVAL_STATE = {
  3293. namespaceId: '',
  3294. setForRemoval: null,
  3295. hasAnimation: false,
  3296. removedBeforeQueried: false
  3297. };
  3298. var NULL_REMOVED_QUERIED_STATE = {
  3299. namespaceId: '',
  3300. setForRemoval: null,
  3301. hasAnimation: false,
  3302. removedBeforeQueried: true
  3303. };
  3304. /**
  3305. * @record
  3306. */
  3307. var REMOVAL_FLAG = '__ng_removed';
  3308. /**
  3309. * @record
  3310. */
  3311. var StateValue = /** @class */ (function () {
  3312. function StateValue(input, namespaceId) {
  3313. if (namespaceId === void 0) { namespaceId = ''; }
  3314. this.namespaceId = namespaceId;
  3315. var /** @type {?} */ isObj = input && input.hasOwnProperty('value');
  3316. var /** @type {?} */ value = isObj ? input['value'] : input;
  3317. this.value = normalizeTriggerValue(value);
  3318. if (isObj) {
  3319. var /** @type {?} */ options = copyObj(/** @type {?} */ (input));
  3320. delete options['value'];
  3321. this.options = /** @type {?} */ (options);
  3322. }
  3323. else {
  3324. this.options = {};
  3325. }
  3326. if (!this.options.params) {
  3327. this.options.params = {};
  3328. }
  3329. }
  3330. Object.defineProperty(StateValue.prototype, "params", {
  3331. get: /**
  3332. * @return {?}
  3333. */
  3334. function () { return /** @type {?} */ (this.options.params); },
  3335. enumerable: true,
  3336. configurable: true
  3337. });
  3338. /**
  3339. * @param {?} options
  3340. * @return {?}
  3341. */
  3342. StateValue.prototype.absorbOptions = /**
  3343. * @param {?} options
  3344. * @return {?}
  3345. */
  3346. function (options) {
  3347. var /** @type {?} */ newParams = options.params;
  3348. if (newParams) {
  3349. var /** @type {?} */ oldParams_1 = /** @type {?} */ ((this.options.params));
  3350. Object.keys(newParams).forEach(function (prop) {
  3351. if (oldParams_1[prop] == null) {
  3352. oldParams_1[prop] = newParams[prop];
  3353. }
  3354. });
  3355. }
  3356. };
  3357. return StateValue;
  3358. }());
  3359. var VOID_VALUE = 'void';
  3360. var DEFAULT_STATE_VALUE = new StateValue(VOID_VALUE);
  3361. var DELETED_STATE_VALUE = new StateValue('DELETED');
  3362. var AnimationTransitionNamespace = /** @class */ (function () {
  3363. function AnimationTransitionNamespace(id, hostElement, _engine) {
  3364. this.id = id;
  3365. this.hostElement = hostElement;
  3366. this._engine = _engine;
  3367. this.players = [];
  3368. this._triggers = {};
  3369. this._queue = [];
  3370. this._elementListeners = new Map();
  3371. this._hostClassName = 'ng-tns-' + id;
  3372. addClass(hostElement, this._hostClassName);
  3373. }
  3374. /**
  3375. * @param {?} element
  3376. * @param {?} name
  3377. * @param {?} phase
  3378. * @param {?} callback
  3379. * @return {?}
  3380. */
  3381. AnimationTransitionNamespace.prototype.listen = /**
  3382. * @param {?} element
  3383. * @param {?} name
  3384. * @param {?} phase
  3385. * @param {?} callback
  3386. * @return {?}
  3387. */
  3388. function (element, name, phase, callback) {
  3389. var _this = this;
  3390. if (!this._triggers.hasOwnProperty(name)) {
  3391. throw new Error("Unable to listen on the animation trigger event \"" + phase + "\" because the animation trigger \"" + name + "\" doesn't exist!");
  3392. }
  3393. if (phase == null || phase.length == 0) {
  3394. throw new Error("Unable to listen on the animation trigger \"" + name + "\" because the provided event is undefined!");
  3395. }
  3396. if (!isTriggerEventValid(phase)) {
  3397. throw new Error("The provided animation trigger event \"" + phase + "\" for the animation trigger \"" + name + "\" is not supported!");
  3398. }
  3399. var /** @type {?} */ listeners = getOrSetAsInMap(this._elementListeners, element, []);
  3400. var /** @type {?} */ data = { name: name, phase: phase, callback: callback };
  3401. listeners.push(data);
  3402. var /** @type {?} */ triggersWithStates = getOrSetAsInMap(this._engine.statesByElement, element, {});
  3403. if (!triggersWithStates.hasOwnProperty(name)) {
  3404. addClass(element, NG_TRIGGER_CLASSNAME);
  3405. addClass(element, NG_TRIGGER_CLASSNAME + '-' + name);
  3406. triggersWithStates[name] = DEFAULT_STATE_VALUE;
  3407. }
  3408. return function () {
  3409. // the event listener is removed AFTER the flush has occurred such
  3410. // that leave animations callbacks can fire (otherwise if the node
  3411. // is removed in between then the listeners would be deregistered)
  3412. // the event listener is removed AFTER the flush has occurred such
  3413. // that leave animations callbacks can fire (otherwise if the node
  3414. // is removed in between then the listeners would be deregistered)
  3415. _this._engine.afterFlush(function () {
  3416. var /** @type {?} */ index = listeners.indexOf(data);
  3417. if (index >= 0) {
  3418. listeners.splice(index, 1);
  3419. }
  3420. if (!_this._triggers[name]) {
  3421. delete triggersWithStates[name];
  3422. }
  3423. });
  3424. };
  3425. };
  3426. /**
  3427. * @param {?} name
  3428. * @param {?} ast
  3429. * @return {?}
  3430. */
  3431. AnimationTransitionNamespace.prototype.register = /**
  3432. * @param {?} name
  3433. * @param {?} ast
  3434. * @return {?}
  3435. */
  3436. function (name, ast) {
  3437. if (this._triggers[name]) {
  3438. // throw
  3439. return false;
  3440. }
  3441. else {
  3442. this._triggers[name] = ast;
  3443. return true;
  3444. }
  3445. };
  3446. /**
  3447. * @param {?} name
  3448. * @return {?}
  3449. */
  3450. AnimationTransitionNamespace.prototype._getTrigger = /**
  3451. * @param {?} name
  3452. * @return {?}
  3453. */
  3454. function (name) {
  3455. var /** @type {?} */ trigger = this._triggers[name];
  3456. if (!trigger) {
  3457. throw new Error("The provided animation trigger \"" + name + "\" has not been registered!");
  3458. }
  3459. return trigger;
  3460. };
  3461. /**
  3462. * @param {?} element
  3463. * @param {?} triggerName
  3464. * @param {?} value
  3465. * @param {?=} defaultToFallback
  3466. * @return {?}
  3467. */
  3468. AnimationTransitionNamespace.prototype.trigger = /**
  3469. * @param {?} element
  3470. * @param {?} triggerName
  3471. * @param {?} value
  3472. * @param {?=} defaultToFallback
  3473. * @return {?}
  3474. */
  3475. function (element, triggerName, value, defaultToFallback) {
  3476. var _this = this;
  3477. if (defaultToFallback === void 0) { defaultToFallback = true; }
  3478. var /** @type {?} */ trigger = this._getTrigger(triggerName);
  3479. var /** @type {?} */ player = new TransitionAnimationPlayer(this.id, triggerName, element);
  3480. var /** @type {?} */ triggersWithStates = this._engine.statesByElement.get(element);
  3481. if (!triggersWithStates) {
  3482. addClass(element, NG_TRIGGER_CLASSNAME);
  3483. addClass(element, NG_TRIGGER_CLASSNAME + '-' + triggerName);
  3484. this._engine.statesByElement.set(element, triggersWithStates = {});
  3485. }
  3486. var /** @type {?} */ fromState = triggersWithStates[triggerName];
  3487. var /** @type {?} */ toState = new StateValue(value, this.id);
  3488. var /** @type {?} */ isObj = value && value.hasOwnProperty('value');
  3489. if (!isObj && fromState) {
  3490. toState.absorbOptions(fromState.options);
  3491. }
  3492. triggersWithStates[triggerName] = toState;
  3493. if (!fromState) {
  3494. fromState = DEFAULT_STATE_VALUE;
  3495. }
  3496. else if (fromState === DELETED_STATE_VALUE) {
  3497. return player;
  3498. }
  3499. var /** @type {?} */ isRemoval = toState.value === VOID_VALUE;
  3500. // normally this isn't reached by here, however, if an object expression
  3501. // is passed in then it may be a new object each time. Comparing the value
  3502. // is important since that will stay the same despite there being a new object.
  3503. // The removal arc here is special cased because the same element is triggered
  3504. // twice in the event that it contains animations on the outer/inner portions
  3505. // of the host container
  3506. if (!isRemoval && fromState.value === toState.value) {
  3507. // this means that despite the value not changing, some inner params
  3508. // have changed which means that the animation final styles need to be applied
  3509. if (!objEquals(fromState.params, toState.params)) {
  3510. var /** @type {?} */ errors = [];
  3511. var /** @type {?} */ fromStyles_1 = trigger.matchStyles(fromState.value, fromState.params, errors);
  3512. var /** @type {?} */ toStyles_1 = trigger.matchStyles(toState.value, toState.params, errors);
  3513. if (errors.length) {
  3514. this._engine.reportError(errors);
  3515. }
  3516. else {
  3517. this._engine.afterFlush(function () {
  3518. eraseStyles(element, fromStyles_1);
  3519. setStyles(element, toStyles_1);
  3520. });
  3521. }
  3522. }
  3523. return;
  3524. }
  3525. var /** @type {?} */ playersOnElement = getOrSetAsInMap(this._engine.playersByElement, element, []);
  3526. playersOnElement.forEach(function (player) {
  3527. // only remove the player if it is queued on the EXACT same trigger/namespace
  3528. // we only also deal with queued players here because if the animation has
  3529. // started then we want to keep the player alive until the flush happens
  3530. // (which is where the previousPlayers are passed into the new palyer)
  3531. if (player.namespaceId == _this.id && player.triggerName == triggerName && player.queued) {
  3532. player.destroy();
  3533. }
  3534. });
  3535. var /** @type {?} */ transition = trigger.matchTransition(fromState.value, toState.value);
  3536. var /** @type {?} */ isFallbackTransition = false;
  3537. if (!transition) {
  3538. if (!defaultToFallback)
  3539. return;
  3540. transition = trigger.fallbackTransition;
  3541. isFallbackTransition = true;
  3542. }
  3543. this._engine.totalQueuedPlayers++;
  3544. this._queue.push({ element: element, triggerName: triggerName, transition: transition, fromState: fromState, toState: toState, player: player, isFallbackTransition: isFallbackTransition });
  3545. if (!isFallbackTransition) {
  3546. addClass(element, QUEUED_CLASSNAME);
  3547. player.onStart(function () { removeClass(element, QUEUED_CLASSNAME); });
  3548. }
  3549. player.onDone(function () {
  3550. var /** @type {?} */ index = _this.players.indexOf(player);
  3551. if (index >= 0) {
  3552. _this.players.splice(index, 1);
  3553. }
  3554. var /** @type {?} */ players = _this._engine.playersByElement.get(element);
  3555. if (players) {
  3556. var /** @type {?} */ index_1 = players.indexOf(player);
  3557. if (index_1 >= 0) {
  3558. players.splice(index_1, 1);
  3559. }
  3560. }
  3561. });
  3562. this.players.push(player);
  3563. playersOnElement.push(player);
  3564. return player;
  3565. };
  3566. /**
  3567. * @param {?} name
  3568. * @return {?}
  3569. */
  3570. AnimationTransitionNamespace.prototype.deregister = /**
  3571. * @param {?} name
  3572. * @return {?}
  3573. */
  3574. function (name) {
  3575. var _this = this;
  3576. delete this._triggers[name];
  3577. this._engine.statesByElement.forEach(function (stateMap, element) { delete stateMap[name]; });
  3578. this._elementListeners.forEach(function (listeners, element) {
  3579. _this._elementListeners.set(element, listeners.filter(function (entry) { return entry.name != name; }));
  3580. });
  3581. };
  3582. /**
  3583. * @param {?} element
  3584. * @return {?}
  3585. */
  3586. AnimationTransitionNamespace.prototype.clearElementCache = /**
  3587. * @param {?} element
  3588. * @return {?}
  3589. */
  3590. function (element) {
  3591. this._engine.statesByElement.delete(element);
  3592. this._elementListeners.delete(element);
  3593. var /** @type {?} */ elementPlayers = this._engine.playersByElement.get(element);
  3594. if (elementPlayers) {
  3595. elementPlayers.forEach(function (player) { return player.destroy(); });
  3596. this._engine.playersByElement.delete(element);
  3597. }
  3598. };
  3599. /**
  3600. * @param {?} rootElement
  3601. * @param {?} context
  3602. * @param {?=} animate
  3603. * @return {?}
  3604. */
  3605. AnimationTransitionNamespace.prototype._signalRemovalForInnerTriggers = /**
  3606. * @param {?} rootElement
  3607. * @param {?} context
  3608. * @param {?=} animate
  3609. * @return {?}
  3610. */
  3611. function (rootElement, context, animate) {
  3612. var _this = this;
  3613. if (animate === void 0) { animate = false; }
  3614. // emulate a leave animation for all inner nodes within this node.
  3615. // If there are no animations found for any of the nodes then clear the cache
  3616. // for the element.
  3617. this._engine.driver.query(rootElement, NG_TRIGGER_SELECTOR, true).forEach(function (elm) {
  3618. // this means that an inner remove() operation has already kicked off
  3619. // the animation on this element...
  3620. if (elm[REMOVAL_FLAG])
  3621. return;
  3622. var /** @type {?} */ namespaces = _this._engine.fetchNamespacesByElement(elm);
  3623. if (namespaces.size) {
  3624. namespaces.forEach(function (ns) { return ns.triggerLeaveAnimation(elm, context, false, true); });
  3625. }
  3626. else {
  3627. _this.clearElementCache(elm);
  3628. }
  3629. });
  3630. };
  3631. /**
  3632. * @param {?} element
  3633. * @param {?} context
  3634. * @param {?=} destroyAfterComplete
  3635. * @param {?=} defaultToFallback
  3636. * @return {?}
  3637. */
  3638. AnimationTransitionNamespace.prototype.triggerLeaveAnimation = /**
  3639. * @param {?} element
  3640. * @param {?} context
  3641. * @param {?=} destroyAfterComplete
  3642. * @param {?=} defaultToFallback
  3643. * @return {?}
  3644. */
  3645. function (element, context, destroyAfterComplete, defaultToFallback) {
  3646. var _this = this;
  3647. var /** @type {?} */ triggerStates = this._engine.statesByElement.get(element);
  3648. if (triggerStates) {
  3649. var /** @type {?} */ players_1 = [];
  3650. Object.keys(triggerStates).forEach(function (triggerName) {
  3651. // this check is here in the event that an element is removed
  3652. // twice (both on the host level and the component level)
  3653. if (_this._triggers[triggerName]) {
  3654. var /** @type {?} */ player = _this.trigger(element, triggerName, VOID_VALUE, defaultToFallback);
  3655. if (player) {
  3656. players_1.push(player);
  3657. }
  3658. }
  3659. });
  3660. if (players_1.length) {
  3661. this._engine.markElementAsRemoved(this.id, element, true, context);
  3662. if (destroyAfterComplete) {
  3663. optimizeGroupPlayer(players_1).onDone(function () { return _this._engine.processLeaveNode(element); });
  3664. }
  3665. return true;
  3666. }
  3667. }
  3668. return false;
  3669. };
  3670. /**
  3671. * @param {?} element
  3672. * @return {?}
  3673. */
  3674. AnimationTransitionNamespace.prototype.prepareLeaveAnimationListeners = /**
  3675. * @param {?} element
  3676. * @return {?}
  3677. */
  3678. function (element) {
  3679. var _this = this;
  3680. var /** @type {?} */ listeners = this._elementListeners.get(element);
  3681. if (listeners) {
  3682. var /** @type {?} */ visitedTriggers_1 = new Set();
  3683. listeners.forEach(function (listener) {
  3684. var /** @type {?} */ triggerName = listener.name;
  3685. if (visitedTriggers_1.has(triggerName))
  3686. return;
  3687. visitedTriggers_1.add(triggerName);
  3688. var /** @type {?} */ trigger = _this._triggers[triggerName];
  3689. var /** @type {?} */ transition = trigger.fallbackTransition;
  3690. var /** @type {?} */ elementStates = /** @type {?} */ ((_this._engine.statesByElement.get(element)));
  3691. var /** @type {?} */ fromState = elementStates[triggerName] || DEFAULT_STATE_VALUE;
  3692. var /** @type {?} */ toState = new StateValue(VOID_VALUE);
  3693. var /** @type {?} */ player = new TransitionAnimationPlayer(_this.id, triggerName, element);
  3694. _this._engine.totalQueuedPlayers++;
  3695. _this._queue.push({
  3696. element: element,
  3697. triggerName: triggerName,
  3698. transition: transition,
  3699. fromState: fromState,
  3700. toState: toState,
  3701. player: player,
  3702. isFallbackTransition: true
  3703. });
  3704. });
  3705. }
  3706. };
  3707. /**
  3708. * @param {?} element
  3709. * @param {?} context
  3710. * @return {?}
  3711. */
  3712. AnimationTransitionNamespace.prototype.removeNode = /**
  3713. * @param {?} element
  3714. * @param {?} context
  3715. * @return {?}
  3716. */
  3717. function (element, context) {
  3718. var _this = this;
  3719. var /** @type {?} */ engine = this._engine;
  3720. if (element.childElementCount) {
  3721. this._signalRemovalForInnerTriggers(element, context, true);
  3722. }
  3723. // this means that a * => VOID animation was detected and kicked off
  3724. if (this.triggerLeaveAnimation(element, context, true))
  3725. return;
  3726. // find the player that is animating and make sure that the
  3727. // removal is delayed until that player has completed
  3728. var /** @type {?} */ containsPotentialParentTransition = false;
  3729. if (engine.totalAnimations) {
  3730. var /** @type {?} */ currentPlayers = engine.players.length ? engine.playersByQueriedElement.get(element) : [];
  3731. // when this `if statement` does not continue forward it means that
  3732. // a previous animation query has selected the current element and
  3733. // is animating it. In this situation want to continue fowards and
  3734. // allow the element to be queued up for animation later.
  3735. if (currentPlayers && currentPlayers.length) {
  3736. containsPotentialParentTransition = true;
  3737. }
  3738. else {
  3739. var /** @type {?} */ parent_1 = element;
  3740. while (parent_1 = parent_1.parentNode) {
  3741. var /** @type {?} */ triggers = engine.statesByElement.get(parent_1);
  3742. if (triggers) {
  3743. containsPotentialParentTransition = true;
  3744. break;
  3745. }
  3746. }
  3747. }
  3748. }
  3749. // at this stage we know that the element will either get removed
  3750. // during flush or will be picked up by a parent query. Either way
  3751. // we need to fire the listeners for this element when it DOES get
  3752. // removed (once the query parent animation is done or after flush)
  3753. this.prepareLeaveAnimationListeners(element);
  3754. // whether or not a parent has an animation we need to delay the deferral of the leave
  3755. // operation until we have more information (which we do after flush() has been called)
  3756. if (containsPotentialParentTransition) {
  3757. engine.markElementAsRemoved(this.id, element, false, context);
  3758. }
  3759. else {
  3760. // we do this after the flush has occurred such
  3761. // that the callbacks can be fired
  3762. engine.afterFlush(function () { return _this.clearElementCache(element); });
  3763. engine.destroyInnerAnimations(element);
  3764. engine._onRemovalComplete(element, context);
  3765. }
  3766. };
  3767. /**
  3768. * @param {?} element
  3769. * @param {?} parent
  3770. * @return {?}
  3771. */
  3772. AnimationTransitionNamespace.prototype.insertNode = /**
  3773. * @param {?} element
  3774. * @param {?} parent
  3775. * @return {?}
  3776. */
  3777. function (element, parent) { addClass(element, this._hostClassName); };
  3778. /**
  3779. * @param {?} microtaskId
  3780. * @return {?}
  3781. */
  3782. AnimationTransitionNamespace.prototype.drainQueuedTransitions = /**
  3783. * @param {?} microtaskId
  3784. * @return {?}
  3785. */
  3786. function (microtaskId) {
  3787. var _this = this;
  3788. var /** @type {?} */ instructions = [];
  3789. this._queue.forEach(function (entry) {
  3790. var /** @type {?} */ player = entry.player;
  3791. if (player.destroyed)
  3792. return;
  3793. var /** @type {?} */ element = entry.element;
  3794. var /** @type {?} */ listeners = _this._elementListeners.get(element);
  3795. if (listeners) {
  3796. listeners.forEach(function (listener) {
  3797. if (listener.name == entry.triggerName) {
  3798. var /** @type {?} */ baseEvent = makeAnimationEvent(element, entry.triggerName, entry.fromState.value, entry.toState.value);
  3799. (/** @type {?} */ (baseEvent))['_data'] = microtaskId;
  3800. listenOnPlayer(entry.player, listener.phase, baseEvent, listener.callback);
  3801. }
  3802. });
  3803. }
  3804. if (player.markedForDestroy) {
  3805. _this._engine.afterFlush(function () {
  3806. // now we can destroy the element properly since the event listeners have
  3807. // been bound to the player
  3808. player.destroy();
  3809. });
  3810. }
  3811. else {
  3812. instructions.push(entry);
  3813. }
  3814. });
  3815. this._queue = [];
  3816. return instructions.sort(function (a, b) {
  3817. // if depCount == 0 them move to front
  3818. // otherwise if a contains b then move back
  3819. var /** @type {?} */ d0 = a.transition.ast.depCount;
  3820. var /** @type {?} */ d1 = b.transition.ast.depCount;
  3821. if (d0 == 0 || d1 == 0) {
  3822. return d0 - d1;
  3823. }
  3824. return _this._engine.driver.containsElement(a.element, b.element) ? 1 : -1;
  3825. });
  3826. };
  3827. /**
  3828. * @param {?} context
  3829. * @return {?}
  3830. */
  3831. AnimationTransitionNamespace.prototype.destroy = /**
  3832. * @param {?} context
  3833. * @return {?}
  3834. */
  3835. function (context) {
  3836. this.players.forEach(function (p) { return p.destroy(); });
  3837. this._signalRemovalForInnerTriggers(this.hostElement, context);
  3838. };
  3839. /**
  3840. * @param {?} element
  3841. * @return {?}
  3842. */
  3843. AnimationTransitionNamespace.prototype.elementContainsData = /**
  3844. * @param {?} element
  3845. * @return {?}
  3846. */
  3847. function (element) {
  3848. var /** @type {?} */ containsData = false;
  3849. if (this._elementListeners.has(element))
  3850. containsData = true;
  3851. containsData =
  3852. (this._queue.find(function (entry) { return entry.element === element; }) ? true : false) || containsData;
  3853. return containsData;
  3854. };
  3855. return AnimationTransitionNamespace;
  3856. }());
  3857. /**
  3858. * @record
  3859. */
  3860. var TransitionAnimationEngine = /** @class */ (function () {
  3861. function TransitionAnimationEngine(driver, _normalizer) {
  3862. this.driver = driver;
  3863. this._normalizer = _normalizer;
  3864. this.players = [];
  3865. this.newHostElements = new Map();
  3866. this.playersByElement = new Map();
  3867. this.playersByQueriedElement = new Map();
  3868. this.statesByElement = new Map();
  3869. this.disabledNodes = new Set();
  3870. this.totalAnimations = 0;
  3871. this.totalQueuedPlayers = 0;
  3872. this._namespaceLookup = {};
  3873. this._namespaceList = [];
  3874. this._flushFns = [];
  3875. this._whenQuietFns = [];
  3876. this.namespacesByHostElement = new Map();
  3877. this.collectedEnterElements = [];
  3878. this.collectedLeaveElements = [];
  3879. this.onRemovalComplete = function (element, context) { };
  3880. }
  3881. /** @internal */
  3882. /**
  3883. * \@internal
  3884. * @param {?} element
  3885. * @param {?} context
  3886. * @return {?}
  3887. */
  3888. TransitionAnimationEngine.prototype._onRemovalComplete = /**
  3889. * \@internal
  3890. * @param {?} element
  3891. * @param {?} context
  3892. * @return {?}
  3893. */
  3894. function (element, context) { this.onRemovalComplete(element, context); };
  3895. Object.defineProperty(TransitionAnimationEngine.prototype, "queuedPlayers", {
  3896. get: /**
  3897. * @return {?}
  3898. */
  3899. function () {
  3900. var /** @type {?} */ players = [];
  3901. this._namespaceList.forEach(function (ns) {
  3902. ns.players.forEach(function (player) {
  3903. if (player.queued) {
  3904. players.push(player);
  3905. }
  3906. });
  3907. });
  3908. return players;
  3909. },
  3910. enumerable: true,
  3911. configurable: true
  3912. });
  3913. /**
  3914. * @param {?} namespaceId
  3915. * @param {?} hostElement
  3916. * @return {?}
  3917. */
  3918. TransitionAnimationEngine.prototype.createNamespace = /**
  3919. * @param {?} namespaceId
  3920. * @param {?} hostElement
  3921. * @return {?}
  3922. */
  3923. function (namespaceId, hostElement) {
  3924. var /** @type {?} */ ns = new AnimationTransitionNamespace(namespaceId, hostElement, this);
  3925. if (hostElement.parentNode) {
  3926. this._balanceNamespaceList(ns, hostElement);
  3927. }
  3928. else {
  3929. // defer this later until flush during when the host element has
  3930. // been inserted so that we know exactly where to place it in
  3931. // the namespace list
  3932. this.newHostElements.set(hostElement, ns);
  3933. // given that this host element is apart of the animation code, it
  3934. // may or may not be inserted by a parent node that is an of an
  3935. // animation renderer type. If this happens then we can still have
  3936. // access to this item when we query for :enter nodes. If the parent
  3937. // is a renderer then the set data-structure will normalize the entry
  3938. this.collectEnterElement(hostElement);
  3939. }
  3940. return this._namespaceLookup[namespaceId] = ns;
  3941. };
  3942. /**
  3943. * @param {?} ns
  3944. * @param {?} hostElement
  3945. * @return {?}
  3946. */
  3947. TransitionAnimationEngine.prototype._balanceNamespaceList = /**
  3948. * @param {?} ns
  3949. * @param {?} hostElement
  3950. * @return {?}
  3951. */
  3952. function (ns, hostElement) {
  3953. var /** @type {?} */ limit = this._namespaceList.length - 1;
  3954. if (limit >= 0) {
  3955. var /** @type {?} */ found = false;
  3956. for (var /** @type {?} */ i = limit; i >= 0; i--) {
  3957. var /** @type {?} */ nextNamespace = this._namespaceList[i];
  3958. if (this.driver.containsElement(nextNamespace.hostElement, hostElement)) {
  3959. this._namespaceList.splice(i + 1, 0, ns);
  3960. found = true;
  3961. break;
  3962. }
  3963. }
  3964. if (!found) {
  3965. this._namespaceList.splice(0, 0, ns);
  3966. }
  3967. }
  3968. else {
  3969. this._namespaceList.push(ns);
  3970. }
  3971. this.namespacesByHostElement.set(hostElement, ns);
  3972. return ns;
  3973. };
  3974. /**
  3975. * @param {?} namespaceId
  3976. * @param {?} hostElement
  3977. * @return {?}
  3978. */
  3979. TransitionAnimationEngine.prototype.register = /**
  3980. * @param {?} namespaceId
  3981. * @param {?} hostElement
  3982. * @return {?}
  3983. */
  3984. function (namespaceId, hostElement) {
  3985. var /** @type {?} */ ns = this._namespaceLookup[namespaceId];
  3986. if (!ns) {
  3987. ns = this.createNamespace(namespaceId, hostElement);
  3988. }
  3989. return ns;
  3990. };
  3991. /**
  3992. * @param {?} namespaceId
  3993. * @param {?} name
  3994. * @param {?} trigger
  3995. * @return {?}
  3996. */
  3997. TransitionAnimationEngine.prototype.registerTrigger = /**
  3998. * @param {?} namespaceId
  3999. * @param {?} name
  4000. * @param {?} trigger
  4001. * @return {?}
  4002. */
  4003. function (namespaceId, name, trigger) {
  4004. var /** @type {?} */ ns = this._namespaceLookup[namespaceId];
  4005. if (ns && ns.register(name, trigger)) {
  4006. this.totalAnimations++;
  4007. }
  4008. };
  4009. /**
  4010. * @param {?} namespaceId
  4011. * @param {?} context
  4012. * @return {?}
  4013. */
  4014. TransitionAnimationEngine.prototype.destroy = /**
  4015. * @param {?} namespaceId
  4016. * @param {?} context
  4017. * @return {?}
  4018. */
  4019. function (namespaceId, context) {
  4020. var _this = this;
  4021. if (!namespaceId)
  4022. return;
  4023. var /** @type {?} */ ns = this._fetchNamespace(namespaceId);
  4024. this.afterFlush(function () {
  4025. _this.namespacesByHostElement.delete(ns.hostElement);
  4026. delete _this._namespaceLookup[namespaceId];
  4027. var /** @type {?} */ index = _this._namespaceList.indexOf(ns);
  4028. if (index >= 0) {
  4029. _this._namespaceList.splice(index, 1);
  4030. }
  4031. });
  4032. this.afterFlushAnimationsDone(function () { return ns.destroy(context); });
  4033. };
  4034. /**
  4035. * @param {?} id
  4036. * @return {?}
  4037. */
  4038. TransitionAnimationEngine.prototype._fetchNamespace = /**
  4039. * @param {?} id
  4040. * @return {?}
  4041. */
  4042. function (id) { return this._namespaceLookup[id]; };
  4043. /**
  4044. * @param {?} element
  4045. * @return {?}
  4046. */
  4047. TransitionAnimationEngine.prototype.fetchNamespacesByElement = /**
  4048. * @param {?} element
  4049. * @return {?}
  4050. */
  4051. function (element) {
  4052. // normally there should only be one namespace per element, however
  4053. // if @triggers are placed on both the component element and then
  4054. // its host element (within the component code) then there will be
  4055. // two namespaces returned. We use a set here to simply the dedupe
  4056. // of namespaces incase there are multiple triggers both the elm and host
  4057. var /** @type {?} */ namespaces = new Set();
  4058. var /** @type {?} */ elementStates = this.statesByElement.get(element);
  4059. if (elementStates) {
  4060. var /** @type {?} */ keys = Object.keys(elementStates);
  4061. for (var /** @type {?} */ i = 0; i < keys.length; i++) {
  4062. var /** @type {?} */ nsId = elementStates[keys[i]].namespaceId;
  4063. if (nsId) {
  4064. var /** @type {?} */ ns = this._fetchNamespace(nsId);
  4065. if (ns) {
  4066. namespaces.add(ns);
  4067. }
  4068. }
  4069. }
  4070. }
  4071. return namespaces;
  4072. };
  4073. /**
  4074. * @param {?} namespaceId
  4075. * @param {?} element
  4076. * @param {?} name
  4077. * @param {?} value
  4078. * @return {?}
  4079. */
  4080. TransitionAnimationEngine.prototype.trigger = /**
  4081. * @param {?} namespaceId
  4082. * @param {?} element
  4083. * @param {?} name
  4084. * @param {?} value
  4085. * @return {?}
  4086. */
  4087. function (namespaceId, element, name, value) {
  4088. if (isElementNode(element)) {
  4089. this._fetchNamespace(namespaceId).trigger(element, name, value);
  4090. return true;
  4091. }
  4092. return false;
  4093. };
  4094. /**
  4095. * @param {?} namespaceId
  4096. * @param {?} element
  4097. * @param {?} parent
  4098. * @param {?} insertBefore
  4099. * @return {?}
  4100. */
  4101. TransitionAnimationEngine.prototype.insertNode = /**
  4102. * @param {?} namespaceId
  4103. * @param {?} element
  4104. * @param {?} parent
  4105. * @param {?} insertBefore
  4106. * @return {?}
  4107. */
  4108. function (namespaceId, element, parent, insertBefore) {
  4109. if (!isElementNode(element))
  4110. return;
  4111. // special case for when an element is removed and reinserted (move operation)
  4112. // when this occurs we do not want to use the element for deletion later
  4113. var /** @type {?} */ details = /** @type {?} */ (element[REMOVAL_FLAG]);
  4114. if (details && details.setForRemoval) {
  4115. details.setForRemoval = false;
  4116. }
  4117. // in the event that the namespaceId is blank then the caller
  4118. // code does not contain any animation code in it, but it is
  4119. // just being called so that the node is marked as being inserted
  4120. if (namespaceId) {
  4121. var /** @type {?} */ ns = this._fetchNamespace(namespaceId);
  4122. // This if-statement is a workaround for router issue #21947.
  4123. // The router sometimes hits a race condition where while a route
  4124. // is being instantiated a new navigation arrives, triggering leave
  4125. // animation of DOM that has not been fully initialized, until this
  4126. // is resolved, we need to handle the scenario when DOM is not in a
  4127. // consistent state during the animation.
  4128. if (ns) {
  4129. ns.insertNode(element, parent);
  4130. }
  4131. }
  4132. // only *directives and host elements are inserted before
  4133. if (insertBefore) {
  4134. this.collectEnterElement(element);
  4135. }
  4136. };
  4137. /**
  4138. * @param {?} element
  4139. * @return {?}
  4140. */
  4141. TransitionAnimationEngine.prototype.collectEnterElement = /**
  4142. * @param {?} element
  4143. * @return {?}
  4144. */
  4145. function (element) { this.collectedEnterElements.push(element); };
  4146. /**
  4147. * @param {?} element
  4148. * @param {?} value
  4149. * @return {?}
  4150. */
  4151. TransitionAnimationEngine.prototype.markElementAsDisabled = /**
  4152. * @param {?} element
  4153. * @param {?} value
  4154. * @return {?}
  4155. */
  4156. function (element, value) {
  4157. if (value) {
  4158. if (!this.disabledNodes.has(element)) {
  4159. this.disabledNodes.add(element);
  4160. addClass(element, DISABLED_CLASSNAME);
  4161. }
  4162. }
  4163. else if (this.disabledNodes.has(element)) {
  4164. this.disabledNodes.delete(element);
  4165. removeClass(element, DISABLED_CLASSNAME);
  4166. }
  4167. };
  4168. /**
  4169. * @param {?} namespaceId
  4170. * @param {?} element
  4171. * @param {?} context
  4172. * @return {?}
  4173. */
  4174. TransitionAnimationEngine.prototype.removeNode = /**
  4175. * @param {?} namespaceId
  4176. * @param {?} element
  4177. * @param {?} context
  4178. * @return {?}
  4179. */
  4180. function (namespaceId, element, context) {
  4181. if (!isElementNode(element)) {
  4182. this._onRemovalComplete(element, context);
  4183. return;
  4184. }
  4185. var /** @type {?} */ ns = namespaceId ? this._fetchNamespace(namespaceId) : null;
  4186. if (ns) {
  4187. ns.removeNode(element, context);
  4188. }
  4189. else {
  4190. this.markElementAsRemoved(namespaceId, element, false, context);
  4191. }
  4192. };
  4193. /**
  4194. * @param {?} namespaceId
  4195. * @param {?} element
  4196. * @param {?=} hasAnimation
  4197. * @param {?=} context
  4198. * @return {?}
  4199. */
  4200. TransitionAnimationEngine.prototype.markElementAsRemoved = /**
  4201. * @param {?} namespaceId
  4202. * @param {?} element
  4203. * @param {?=} hasAnimation
  4204. * @param {?=} context
  4205. * @return {?}
  4206. */
  4207. function (namespaceId, element, hasAnimation, context) {
  4208. this.collectedLeaveElements.push(element);
  4209. element[REMOVAL_FLAG] = {
  4210. namespaceId: namespaceId,
  4211. setForRemoval: context, hasAnimation: hasAnimation,
  4212. removedBeforeQueried: false
  4213. };
  4214. };
  4215. /**
  4216. * @param {?} namespaceId
  4217. * @param {?} element
  4218. * @param {?} name
  4219. * @param {?} phase
  4220. * @param {?} callback
  4221. * @return {?}
  4222. */
  4223. TransitionAnimationEngine.prototype.listen = /**
  4224. * @param {?} namespaceId
  4225. * @param {?} element
  4226. * @param {?} name
  4227. * @param {?} phase
  4228. * @param {?} callback
  4229. * @return {?}
  4230. */
  4231. function (namespaceId, element, name, phase, callback) {
  4232. if (isElementNode(element)) {
  4233. return this._fetchNamespace(namespaceId).listen(element, name, phase, callback);
  4234. }
  4235. return function () { };
  4236. };
  4237. /**
  4238. * @param {?} entry
  4239. * @param {?} subTimelines
  4240. * @param {?} enterClassName
  4241. * @param {?} leaveClassName
  4242. * @return {?}
  4243. */
  4244. TransitionAnimationEngine.prototype._buildInstruction = /**
  4245. * @param {?} entry
  4246. * @param {?} subTimelines
  4247. * @param {?} enterClassName
  4248. * @param {?} leaveClassName
  4249. * @return {?}
  4250. */
  4251. function (entry, subTimelines, enterClassName, leaveClassName) {
  4252. return entry.transition.build(this.driver, entry.element, entry.fromState.value, entry.toState.value, enterClassName, leaveClassName, entry.fromState.options, entry.toState.options, subTimelines);
  4253. };
  4254. /**
  4255. * @param {?} containerElement
  4256. * @return {?}
  4257. */
  4258. TransitionAnimationEngine.prototype.destroyInnerAnimations = /**
  4259. * @param {?} containerElement
  4260. * @return {?}
  4261. */
  4262. function (containerElement) {
  4263. var _this = this;
  4264. var /** @type {?} */ elements = this.driver.query(containerElement, NG_TRIGGER_SELECTOR, true);
  4265. elements.forEach(function (element) { return _this.destroyActiveAnimationsForElement(element); });
  4266. if (this.playersByQueriedElement.size == 0)
  4267. return;
  4268. elements = this.driver.query(containerElement, NG_ANIMATING_SELECTOR, true);
  4269. elements.forEach(function (element) { return _this.finishActiveQueriedAnimationOnElement(element); });
  4270. };
  4271. /**
  4272. * @param {?} element
  4273. * @return {?}
  4274. */
  4275. TransitionAnimationEngine.prototype.destroyActiveAnimationsForElement = /**
  4276. * @param {?} element
  4277. * @return {?}
  4278. */
  4279. function (element) {
  4280. var /** @type {?} */ players = this.playersByElement.get(element);
  4281. if (players) {
  4282. players.forEach(function (player) {
  4283. // special case for when an element is set for destruction, but hasn't started.
  4284. // in this situation we want to delay the destruction until the flush occurs
  4285. // so that any event listeners attached to the player are triggered.
  4286. if (player.queued) {
  4287. player.markedForDestroy = true;
  4288. }
  4289. else {
  4290. player.destroy();
  4291. }
  4292. });
  4293. }
  4294. var /** @type {?} */ stateMap = this.statesByElement.get(element);
  4295. if (stateMap) {
  4296. Object.keys(stateMap).forEach(function (triggerName) { return stateMap[triggerName] = DELETED_STATE_VALUE; });
  4297. }
  4298. };
  4299. /**
  4300. * @param {?} element
  4301. * @return {?}
  4302. */
  4303. TransitionAnimationEngine.prototype.finishActiveQueriedAnimationOnElement = /**
  4304. * @param {?} element
  4305. * @return {?}
  4306. */
  4307. function (element) {
  4308. var /** @type {?} */ players = this.playersByQueriedElement.get(element);
  4309. if (players) {
  4310. players.forEach(function (player) { return player.finish(); });
  4311. }
  4312. };
  4313. /**
  4314. * @return {?}
  4315. */
  4316. TransitionAnimationEngine.prototype.whenRenderingDone = /**
  4317. * @return {?}
  4318. */
  4319. function () {
  4320. var _this = this;
  4321. return new Promise(function (resolve) {
  4322. if (_this.players.length) {
  4323. return optimizeGroupPlayer(_this.players).onDone(function () { return resolve(); });
  4324. }
  4325. else {
  4326. resolve();
  4327. }
  4328. });
  4329. };
  4330. /**
  4331. * @param {?} element
  4332. * @return {?}
  4333. */
  4334. TransitionAnimationEngine.prototype.processLeaveNode = /**
  4335. * @param {?} element
  4336. * @return {?}
  4337. */
  4338. function (element) {
  4339. var _this = this;
  4340. var /** @type {?} */ details = /** @type {?} */ (element[REMOVAL_FLAG]);
  4341. if (details && details.setForRemoval) {
  4342. // this will prevent it from removing it twice
  4343. element[REMOVAL_FLAG] = NULL_REMOVAL_STATE;
  4344. if (details.namespaceId) {
  4345. this.destroyInnerAnimations(element);
  4346. var /** @type {?} */ ns = this._fetchNamespace(details.namespaceId);
  4347. if (ns) {
  4348. ns.clearElementCache(element);
  4349. }
  4350. }
  4351. this._onRemovalComplete(element, details.setForRemoval);
  4352. }
  4353. if (this.driver.matchesElement(element, DISABLED_SELECTOR)) {
  4354. this.markElementAsDisabled(element, false);
  4355. }
  4356. this.driver.query(element, DISABLED_SELECTOR, true).forEach(function (node) {
  4357. _this.markElementAsDisabled(element, false);
  4358. });
  4359. };
  4360. /**
  4361. * @param {?=} microtaskId
  4362. * @return {?}
  4363. */
  4364. TransitionAnimationEngine.prototype.flush = /**
  4365. * @param {?=} microtaskId
  4366. * @return {?}
  4367. */
  4368. function (microtaskId) {
  4369. var _this = this;
  4370. if (microtaskId === void 0) { microtaskId = -1; }
  4371. var /** @type {?} */ players = [];
  4372. if (this.newHostElements.size) {
  4373. this.newHostElements.forEach(function (ns, element) { return _this._balanceNamespaceList(ns, element); });
  4374. this.newHostElements.clear();
  4375. }
  4376. if (this.totalAnimations && this.collectedEnterElements.length) {
  4377. for (var /** @type {?} */ i = 0; i < this.collectedEnterElements.length; i++) {
  4378. var /** @type {?} */ elm = this.collectedEnterElements[i];
  4379. addClass(elm, STAR_CLASSNAME);
  4380. }
  4381. }
  4382. if (this._namespaceList.length &&
  4383. (this.totalQueuedPlayers || this.collectedLeaveElements.length)) {
  4384. var /** @type {?} */ cleanupFns = [];
  4385. try {
  4386. players = this._flushAnimations(cleanupFns, microtaskId);
  4387. }
  4388. finally {
  4389. for (var /** @type {?} */ i = 0; i < cleanupFns.length; i++) {
  4390. cleanupFns[i]();
  4391. }
  4392. }
  4393. }
  4394. else {
  4395. for (var /** @type {?} */ i = 0; i < this.collectedLeaveElements.length; i++) {
  4396. var /** @type {?} */ element = this.collectedLeaveElements[i];
  4397. this.processLeaveNode(element);
  4398. }
  4399. }
  4400. this.totalQueuedPlayers = 0;
  4401. this.collectedEnterElements.length = 0;
  4402. this.collectedLeaveElements.length = 0;
  4403. this._flushFns.forEach(function (fn) { return fn(); });
  4404. this._flushFns = [];
  4405. if (this._whenQuietFns.length) {
  4406. // we move these over to a variable so that
  4407. // if any new callbacks are registered in another
  4408. // flush they do not populate the existing set
  4409. var /** @type {?} */ quietFns_1 = this._whenQuietFns;
  4410. this._whenQuietFns = [];
  4411. if (players.length) {
  4412. optimizeGroupPlayer(players).onDone(function () { quietFns_1.forEach(function (fn) { return fn(); }); });
  4413. }
  4414. else {
  4415. quietFns_1.forEach(function (fn) { return fn(); });
  4416. }
  4417. }
  4418. };
  4419. /**
  4420. * @param {?} errors
  4421. * @return {?}
  4422. */
  4423. TransitionAnimationEngine.prototype.reportError = /**
  4424. * @param {?} errors
  4425. * @return {?}
  4426. */
  4427. function (errors) {
  4428. throw new Error("Unable to process animations due to the following failed trigger transitions\n " + errors.join('\n'));
  4429. };
  4430. /**
  4431. * @param {?} cleanupFns
  4432. * @param {?} microtaskId
  4433. * @return {?}
  4434. */
  4435. TransitionAnimationEngine.prototype._flushAnimations = /**
  4436. * @param {?} cleanupFns
  4437. * @param {?} microtaskId
  4438. * @return {?}
  4439. */
  4440. function (cleanupFns, microtaskId) {
  4441. var _this = this;
  4442. var /** @type {?} */ subTimelines = new ElementInstructionMap();
  4443. var /** @type {?} */ skippedPlayers = [];
  4444. var /** @type {?} */ skippedPlayersMap = new Map();
  4445. var /** @type {?} */ queuedInstructions = [];
  4446. var /** @type {?} */ queriedElements = new Map();
  4447. var /** @type {?} */ allPreStyleElements = new Map();
  4448. var /** @type {?} */ allPostStyleElements = new Map();
  4449. var /** @type {?} */ disabledElementsSet = new Set();
  4450. this.disabledNodes.forEach(function (node) {
  4451. disabledElementsSet.add(node);
  4452. var /** @type {?} */ nodesThatAreDisabled = _this.driver.query(node, QUEUED_SELECTOR, true);
  4453. for (var /** @type {?} */ i_1 = 0; i_1 < nodesThatAreDisabled.length; i_1++) {
  4454. disabledElementsSet.add(nodesThatAreDisabled[i_1]);
  4455. }
  4456. });
  4457. var /** @type {?} */ bodyNode = getBodyNode();
  4458. var /** @type {?} */ allTriggerElements = Array.from(this.statesByElement.keys());
  4459. var /** @type {?} */ enterNodeMap = buildRootMap(allTriggerElements, this.collectedEnterElements);
  4460. // this must occur before the instructions are built below such that
  4461. // the :enter queries match the elements (since the timeline queries
  4462. // are fired during instruction building).
  4463. var /** @type {?} */ enterNodeMapIds = new Map();
  4464. var /** @type {?} */ i = 0;
  4465. enterNodeMap.forEach(function (nodes, root) {
  4466. var /** @type {?} */ className = ENTER_CLASSNAME + i++;
  4467. enterNodeMapIds.set(root, className);
  4468. nodes.forEach(function (node) { return addClass(node, className); });
  4469. });
  4470. var /** @type {?} */ allLeaveNodes = [];
  4471. var /** @type {?} */ mergedLeaveNodes = new Set();
  4472. var /** @type {?} */ leaveNodesWithoutAnimations = new Set();
  4473. for (var /** @type {?} */ i_2 = 0; i_2 < this.collectedLeaveElements.length; i_2++) {
  4474. var /** @type {?} */ element = this.collectedLeaveElements[i_2];
  4475. var /** @type {?} */ details = /** @type {?} */ (element[REMOVAL_FLAG]);
  4476. if (details && details.setForRemoval) {
  4477. allLeaveNodes.push(element);
  4478. mergedLeaveNodes.add(element);
  4479. if (details.hasAnimation) {
  4480. this.driver.query(element, STAR_SELECTOR, true).forEach(function (elm) { return mergedLeaveNodes.add(elm); });
  4481. }
  4482. else {
  4483. leaveNodesWithoutAnimations.add(element);
  4484. }
  4485. }
  4486. }
  4487. var /** @type {?} */ leaveNodeMapIds = new Map();
  4488. var /** @type {?} */ leaveNodeMap = buildRootMap(allTriggerElements, Array.from(mergedLeaveNodes));
  4489. leaveNodeMap.forEach(function (nodes, root) {
  4490. var /** @type {?} */ className = LEAVE_CLASSNAME + i++;
  4491. leaveNodeMapIds.set(root, className);
  4492. nodes.forEach(function (node) { return addClass(node, className); });
  4493. });
  4494. cleanupFns.push(function () {
  4495. enterNodeMap.forEach(function (nodes, root) {
  4496. var /** @type {?} */ className = /** @type {?} */ ((enterNodeMapIds.get(root)));
  4497. nodes.forEach(function (node) { return removeClass(node, className); });
  4498. });
  4499. leaveNodeMap.forEach(function (nodes, root) {
  4500. var /** @type {?} */ className = /** @type {?} */ ((leaveNodeMapIds.get(root)));
  4501. nodes.forEach(function (node) { return removeClass(node, className); });
  4502. });
  4503. allLeaveNodes.forEach(function (element) { _this.processLeaveNode(element); });
  4504. });
  4505. var /** @type {?} */ allPlayers = [];
  4506. var /** @type {?} */ erroneousTransitions = [];
  4507. for (var /** @type {?} */ i_3 = this._namespaceList.length - 1; i_3 >= 0; i_3--) {
  4508. var /** @type {?} */ ns = this._namespaceList[i_3];
  4509. ns.drainQueuedTransitions(microtaskId).forEach(function (entry) {
  4510. var /** @type {?} */ player = entry.player;
  4511. allPlayers.push(player);
  4512. var /** @type {?} */ element = entry.element;
  4513. if (!bodyNode || !_this.driver.containsElement(bodyNode, element)) {
  4514. player.destroy();
  4515. return;
  4516. }
  4517. var /** @type {?} */ leaveClassName = /** @type {?} */ ((leaveNodeMapIds.get(element)));
  4518. var /** @type {?} */ enterClassName = /** @type {?} */ ((enterNodeMapIds.get(element)));
  4519. var /** @type {?} */ instruction = /** @type {?} */ ((_this._buildInstruction(entry, subTimelines, enterClassName, leaveClassName)));
  4520. if (instruction.errors && instruction.errors.length) {
  4521. erroneousTransitions.push(instruction);
  4522. return;
  4523. }
  4524. // if a unmatched transition is queued to go then it SHOULD NOT render
  4525. // an animation and cancel the previously running animations.
  4526. if (entry.isFallbackTransition) {
  4527. player.onStart(function () { return eraseStyles(element, instruction.fromStyles); });
  4528. player.onDestroy(function () { return setStyles(element, instruction.toStyles); });
  4529. skippedPlayers.push(player);
  4530. return;
  4531. }
  4532. // this means that if a parent animation uses this animation as a sub trigger
  4533. // then it will instruct the timeline builder to not add a player delay, but
  4534. // instead stretch the first keyframe gap up until the animation starts. The
  4535. // reason this is important is to prevent extra initialization styles from being
  4536. // required by the user in the animation.
  4537. instruction.timelines.forEach(function (tl) { return tl.stretchStartingKeyframe = true; });
  4538. subTimelines.append(element, instruction.timelines);
  4539. var /** @type {?} */ tuple = { instruction: instruction, player: player, element: element };
  4540. queuedInstructions.push(tuple);
  4541. instruction.queriedElements.forEach(function (element) { return getOrSetAsInMap(queriedElements, element, []).push(player); });
  4542. instruction.preStyleProps.forEach(function (stringMap, element) {
  4543. var /** @type {?} */ props = Object.keys(stringMap);
  4544. if (props.length) {
  4545. var /** @type {?} */ setVal_1 = /** @type {?} */ ((allPreStyleElements.get(element)));
  4546. if (!setVal_1) {
  4547. allPreStyleElements.set(element, setVal_1 = new Set());
  4548. }
  4549. props.forEach(function (prop) { return setVal_1.add(prop); });
  4550. }
  4551. });
  4552. instruction.postStyleProps.forEach(function (stringMap, element) {
  4553. var /** @type {?} */ props = Object.keys(stringMap);
  4554. var /** @type {?} */ setVal = /** @type {?} */ ((allPostStyleElements.get(element)));
  4555. if (!setVal) {
  4556. allPostStyleElements.set(element, setVal = new Set());
  4557. }
  4558. props.forEach(function (prop) { return setVal.add(prop); });
  4559. });
  4560. });
  4561. }
  4562. if (erroneousTransitions.length) {
  4563. var /** @type {?} */ errors_1 = [];
  4564. erroneousTransitions.forEach(function (instruction) {
  4565. errors_1.push("@" + instruction.triggerName + " has failed due to:\n"); /** @type {?} */
  4566. ((instruction.errors)).forEach(function (error) { return errors_1.push("- " + error + "\n"); });
  4567. });
  4568. allPlayers.forEach(function (player) { return player.destroy(); });
  4569. this.reportError(errors_1);
  4570. }
  4571. var /** @type {?} */ allPreviousPlayersMap = new Map();
  4572. // this map works to tell which element in the DOM tree is contained by
  4573. // which animation. Further down below this map will get populated once
  4574. // the players are built and in doing so it can efficiently figure out
  4575. // if a sub player is skipped due to a parent player having priority.
  4576. var /** @type {?} */ animationElementMap = new Map();
  4577. queuedInstructions.forEach(function (entry) {
  4578. var /** @type {?} */ element = entry.element;
  4579. if (subTimelines.has(element)) {
  4580. animationElementMap.set(element, element);
  4581. _this._beforeAnimationBuild(entry.player.namespaceId, entry.instruction, allPreviousPlayersMap);
  4582. }
  4583. });
  4584. skippedPlayers.forEach(function (player) {
  4585. var /** @type {?} */ element = player.element;
  4586. var /** @type {?} */ previousPlayers = _this._getPreviousPlayers(element, false, player.namespaceId, player.triggerName, null);
  4587. previousPlayers.forEach(function (prevPlayer) {
  4588. getOrSetAsInMap(allPreviousPlayersMap, element, []).push(prevPlayer);
  4589. prevPlayer.destroy();
  4590. });
  4591. });
  4592. // this is a special case for nodes that will be removed (either by)
  4593. // having their own leave animations or by being queried in a container
  4594. // that will be removed once a parent animation is complete. The idea
  4595. // here is that * styles must be identical to ! styles because of
  4596. // backwards compatibility (* is also filled in by default in many places).
  4597. // Otherwise * styles will return an empty value or auto since the element
  4598. // that is being getComputedStyle'd will not be visible (since * = destination)
  4599. var /** @type {?} */ replaceNodes = allLeaveNodes.filter(function (node) {
  4600. return replacePostStylesAsPre(node, allPreStyleElements, allPostStyleElements);
  4601. });
  4602. // POST STAGE: fill the * styles
  4603. var /** @type {?} */ postStylesMap = new Map();
  4604. var /** @type {?} */ allLeaveQueriedNodes = cloakAndComputeStyles(postStylesMap, this.driver, leaveNodesWithoutAnimations, allPostStyleElements, AUTO_STYLE);
  4605. allLeaveQueriedNodes.forEach(function (node) {
  4606. if (replacePostStylesAsPre(node, allPreStyleElements, allPostStyleElements)) {
  4607. replaceNodes.push(node);
  4608. }
  4609. });
  4610. // PRE STAGE: fill the ! styles
  4611. var /** @type {?} */ preStylesMap = new Map();
  4612. enterNodeMap.forEach(function (nodes, root) {
  4613. cloakAndComputeStyles(preStylesMap, _this.driver, new Set(nodes), allPreStyleElements, ɵPRE_STYLE);
  4614. });
  4615. replaceNodes.forEach(function (node) {
  4616. var /** @type {?} */ post = postStylesMap.get(node);
  4617. var /** @type {?} */ pre = preStylesMap.get(node);
  4618. postStylesMap.set(node, /** @type {?} */ (__assign({}, post, pre)));
  4619. });
  4620. var /** @type {?} */ rootPlayers = [];
  4621. var /** @type {?} */ subPlayers = [];
  4622. var /** @type {?} */ NO_PARENT_ANIMATION_ELEMENT_DETECTED = {};
  4623. queuedInstructions.forEach(function (entry) {
  4624. var element = entry.element, player = entry.player, instruction = entry.instruction;
  4625. // this means that it was never consumed by a parent animation which
  4626. // means that it is independent and therefore should be set for animation
  4627. if (subTimelines.has(element)) {
  4628. if (disabledElementsSet.has(element)) {
  4629. player.onDestroy(function () { return setStyles(element, instruction.toStyles); });
  4630. skippedPlayers.push(player);
  4631. return;
  4632. }
  4633. // this will flow up the DOM and query the map to figure out
  4634. // if a parent animation has priority over it. In the situation
  4635. // that a parent is detected then it will cancel the loop. If
  4636. // nothing is detected, or it takes a few hops to find a parent,
  4637. // then it will fill in the missing nodes and signal them as having
  4638. // a detected parent (or a NO_PARENT value via a special constant).
  4639. var /** @type {?} */ parentWithAnimation_1 = NO_PARENT_ANIMATION_ELEMENT_DETECTED;
  4640. if (animationElementMap.size > 1) {
  4641. var /** @type {?} */ elm = element;
  4642. var /** @type {?} */ parentsToAdd = [];
  4643. while (elm = elm.parentNode) {
  4644. var /** @type {?} */ detectedParent = animationElementMap.get(elm);
  4645. if (detectedParent) {
  4646. parentWithAnimation_1 = detectedParent;
  4647. break;
  4648. }
  4649. parentsToAdd.push(elm);
  4650. }
  4651. parentsToAdd.forEach(function (parent) { return animationElementMap.set(parent, parentWithAnimation_1); });
  4652. }
  4653. var /** @type {?} */ innerPlayer = _this._buildAnimation(player.namespaceId, instruction, allPreviousPlayersMap, skippedPlayersMap, preStylesMap, postStylesMap);
  4654. player.setRealPlayer(innerPlayer);
  4655. if (parentWithAnimation_1 === NO_PARENT_ANIMATION_ELEMENT_DETECTED) {
  4656. rootPlayers.push(player);
  4657. }
  4658. else {
  4659. var /** @type {?} */ parentPlayers = _this.playersByElement.get(parentWithAnimation_1);
  4660. if (parentPlayers && parentPlayers.length) {
  4661. player.parentPlayer = optimizeGroupPlayer(parentPlayers);
  4662. }
  4663. skippedPlayers.push(player);
  4664. }
  4665. }
  4666. else {
  4667. eraseStyles(element, instruction.fromStyles);
  4668. player.onDestroy(function () { return setStyles(element, instruction.toStyles); });
  4669. // there still might be a ancestor player animating this
  4670. // element therefore we will still add it as a sub player
  4671. // even if its animation may be disabled
  4672. subPlayers.push(player);
  4673. if (disabledElementsSet.has(element)) {
  4674. skippedPlayers.push(player);
  4675. }
  4676. }
  4677. });
  4678. // find all of the sub players' corresponding inner animation player
  4679. subPlayers.forEach(function (player) {
  4680. // even if any players are not found for a sub animation then it
  4681. // will still complete itself after the next tick since it's Noop
  4682. var /** @type {?} */ playersForElement = skippedPlayersMap.get(player.element);
  4683. if (playersForElement && playersForElement.length) {
  4684. var /** @type {?} */ innerPlayer = optimizeGroupPlayer(playersForElement);
  4685. player.setRealPlayer(innerPlayer);
  4686. }
  4687. });
  4688. // the reason why we don't actually play the animation is
  4689. // because all that a skipped player is designed to do is to
  4690. // fire the start/done transition callback events
  4691. skippedPlayers.forEach(function (player) {
  4692. if (player.parentPlayer) {
  4693. player.syncPlayerEvents(player.parentPlayer);
  4694. }
  4695. else {
  4696. player.destroy();
  4697. }
  4698. });
  4699. // run through all of the queued removals and see if they
  4700. // were picked up by a query. If not then perform the removal
  4701. // operation right away unless a parent animation is ongoing.
  4702. for (var /** @type {?} */ i_4 = 0; i_4 < allLeaveNodes.length; i_4++) {
  4703. var /** @type {?} */ element = allLeaveNodes[i_4];
  4704. var /** @type {?} */ details = /** @type {?} */ (element[REMOVAL_FLAG]);
  4705. removeClass(element, LEAVE_CLASSNAME);
  4706. // this means the element has a removal animation that is being
  4707. // taken care of and therefore the inner elements will hang around
  4708. // until that animation is over (or the parent queried animation)
  4709. if (details && details.hasAnimation)
  4710. continue;
  4711. var /** @type {?} */ players = [];
  4712. // if this element is queried or if it contains queried children
  4713. // then we want for the element not to be removed from the page
  4714. // until the queried animations have finished
  4715. if (queriedElements.size) {
  4716. var /** @type {?} */ queriedPlayerResults = queriedElements.get(element);
  4717. if (queriedPlayerResults && queriedPlayerResults.length) {
  4718. players.push.apply(players, queriedPlayerResults);
  4719. }
  4720. var /** @type {?} */ queriedInnerElements = this.driver.query(element, NG_ANIMATING_SELECTOR, true);
  4721. for (var /** @type {?} */ j = 0; j < queriedInnerElements.length; j++) {
  4722. var /** @type {?} */ queriedPlayers = queriedElements.get(queriedInnerElements[j]);
  4723. if (queriedPlayers && queriedPlayers.length) {
  4724. players.push.apply(players, queriedPlayers);
  4725. }
  4726. }
  4727. }
  4728. var /** @type {?} */ activePlayers = players.filter(function (p) { return !p.destroyed; });
  4729. if (activePlayers.length) {
  4730. removeNodesAfterAnimationDone(this, element, activePlayers);
  4731. }
  4732. else {
  4733. this.processLeaveNode(element);
  4734. }
  4735. }
  4736. // this is required so the cleanup method doesn't remove them
  4737. allLeaveNodes.length = 0;
  4738. rootPlayers.forEach(function (player) {
  4739. _this.players.push(player);
  4740. player.onDone(function () {
  4741. player.destroy();
  4742. var /** @type {?} */ index = _this.players.indexOf(player);
  4743. _this.players.splice(index, 1);
  4744. });
  4745. player.play();
  4746. });
  4747. return rootPlayers;
  4748. };
  4749. /**
  4750. * @param {?} namespaceId
  4751. * @param {?} element
  4752. * @return {?}
  4753. */
  4754. TransitionAnimationEngine.prototype.elementContainsData = /**
  4755. * @param {?} namespaceId
  4756. * @param {?} element
  4757. * @return {?}
  4758. */
  4759. function (namespaceId, element) {
  4760. var /** @type {?} */ containsData = false;
  4761. var /** @type {?} */ details = /** @type {?} */ (element[REMOVAL_FLAG]);
  4762. if (details && details.setForRemoval)
  4763. containsData = true;
  4764. if (this.playersByElement.has(element))
  4765. containsData = true;
  4766. if (this.playersByQueriedElement.has(element))
  4767. containsData = true;
  4768. if (this.statesByElement.has(element))
  4769. containsData = true;
  4770. return this._fetchNamespace(namespaceId).elementContainsData(element) || containsData;
  4771. };
  4772. /**
  4773. * @param {?} callback
  4774. * @return {?}
  4775. */
  4776. TransitionAnimationEngine.prototype.afterFlush = /**
  4777. * @param {?} callback
  4778. * @return {?}
  4779. */
  4780. function (callback) { this._flushFns.push(callback); };
  4781. /**
  4782. * @param {?} callback
  4783. * @return {?}
  4784. */
  4785. TransitionAnimationEngine.prototype.afterFlushAnimationsDone = /**
  4786. * @param {?} callback
  4787. * @return {?}
  4788. */
  4789. function (callback) { this._whenQuietFns.push(callback); };
  4790. /**
  4791. * @param {?} element
  4792. * @param {?} isQueriedElement
  4793. * @param {?=} namespaceId
  4794. * @param {?=} triggerName
  4795. * @param {?=} toStateValue
  4796. * @return {?}
  4797. */
  4798. TransitionAnimationEngine.prototype._getPreviousPlayers = /**
  4799. * @param {?} element
  4800. * @param {?} isQueriedElement
  4801. * @param {?=} namespaceId
  4802. * @param {?=} triggerName
  4803. * @param {?=} toStateValue
  4804. * @return {?}
  4805. */
  4806. function (element, isQueriedElement, namespaceId, triggerName, toStateValue) {
  4807. var /** @type {?} */ players = [];
  4808. if (isQueriedElement) {
  4809. var /** @type {?} */ queriedElementPlayers = this.playersByQueriedElement.get(element);
  4810. if (queriedElementPlayers) {
  4811. players = queriedElementPlayers;
  4812. }
  4813. }
  4814. else {
  4815. var /** @type {?} */ elementPlayers = this.playersByElement.get(element);
  4816. if (elementPlayers) {
  4817. var /** @type {?} */ isRemovalAnimation_1 = !toStateValue || toStateValue == VOID_VALUE;
  4818. elementPlayers.forEach(function (player) {
  4819. if (player.queued)
  4820. return;
  4821. if (!isRemovalAnimation_1 && player.triggerName != triggerName)
  4822. return;
  4823. players.push(player);
  4824. });
  4825. }
  4826. }
  4827. if (namespaceId || triggerName) {
  4828. players = players.filter(function (player) {
  4829. if (namespaceId && namespaceId != player.namespaceId)
  4830. return false;
  4831. if (triggerName && triggerName != player.triggerName)
  4832. return false;
  4833. return true;
  4834. });
  4835. }
  4836. return players;
  4837. };
  4838. /**
  4839. * @param {?} namespaceId
  4840. * @param {?} instruction
  4841. * @param {?} allPreviousPlayersMap
  4842. * @return {?}
  4843. */
  4844. TransitionAnimationEngine.prototype._beforeAnimationBuild = /**
  4845. * @param {?} namespaceId
  4846. * @param {?} instruction
  4847. * @param {?} allPreviousPlayersMap
  4848. * @return {?}
  4849. */
  4850. function (namespaceId, instruction, allPreviousPlayersMap) {
  4851. var /** @type {?} */ triggerName = instruction.triggerName;
  4852. var /** @type {?} */ rootElement = instruction.element;
  4853. // when a removal animation occurs, ALL previous players are collected
  4854. // and destroyed (even if they are outside of the current namespace)
  4855. var /** @type {?} */ targetNameSpaceId = instruction.isRemovalTransition ? undefined : namespaceId;
  4856. var /** @type {?} */ targetTriggerName = instruction.isRemovalTransition ? undefined : triggerName;
  4857. var _loop_1 = function (timelineInstruction) {
  4858. var /** @type {?} */ element = timelineInstruction.element;
  4859. var /** @type {?} */ isQueriedElement = element !== rootElement;
  4860. var /** @type {?} */ players = getOrSetAsInMap(allPreviousPlayersMap, element, []);
  4861. var /** @type {?} */ previousPlayers = this_1._getPreviousPlayers(element, isQueriedElement, targetNameSpaceId, targetTriggerName, instruction.toState);
  4862. previousPlayers.forEach(function (player) {
  4863. var /** @type {?} */ realPlayer = /** @type {?} */ (player.getRealPlayer());
  4864. if (realPlayer.beforeDestroy) {
  4865. realPlayer.beforeDestroy();
  4866. }
  4867. player.destroy();
  4868. players.push(player);
  4869. });
  4870. };
  4871. var this_1 = this;
  4872. for (var _i = 0, _a = instruction.timelines; _i < _a.length; _i++) {
  4873. var timelineInstruction = _a[_i];
  4874. _loop_1(timelineInstruction);
  4875. }
  4876. // this needs to be done so that the PRE/POST styles can be
  4877. // computed properly without interfering with the previous animation
  4878. eraseStyles(rootElement, instruction.fromStyles);
  4879. };
  4880. /**
  4881. * @param {?} namespaceId
  4882. * @param {?} instruction
  4883. * @param {?} allPreviousPlayersMap
  4884. * @param {?} skippedPlayersMap
  4885. * @param {?} preStylesMap
  4886. * @param {?} postStylesMap
  4887. * @return {?}
  4888. */
  4889. TransitionAnimationEngine.prototype._buildAnimation = /**
  4890. * @param {?} namespaceId
  4891. * @param {?} instruction
  4892. * @param {?} allPreviousPlayersMap
  4893. * @param {?} skippedPlayersMap
  4894. * @param {?} preStylesMap
  4895. * @param {?} postStylesMap
  4896. * @return {?}
  4897. */
  4898. function (namespaceId, instruction, allPreviousPlayersMap, skippedPlayersMap, preStylesMap, postStylesMap) {
  4899. var _this = this;
  4900. var /** @type {?} */ triggerName = instruction.triggerName;
  4901. var /** @type {?} */ rootElement = instruction.element;
  4902. // we first run this so that the previous animation player
  4903. // data can be passed into the successive animation players
  4904. var /** @type {?} */ allQueriedPlayers = [];
  4905. var /** @type {?} */ allConsumedElements = new Set();
  4906. var /** @type {?} */ allSubElements = new Set();
  4907. var /** @type {?} */ allNewPlayers = instruction.timelines.map(function (timelineInstruction) {
  4908. var /** @type {?} */ element = timelineInstruction.element;
  4909. allConsumedElements.add(element);
  4910. // FIXME (matsko): make sure to-be-removed animations are removed properly
  4911. var /** @type {?} */ details = element[REMOVAL_FLAG];
  4912. if (details && details.removedBeforeQueried)
  4913. return new NoopAnimationPlayer();
  4914. var /** @type {?} */ isQueriedElement = element !== rootElement;
  4915. var /** @type {?} */ previousPlayers = flattenGroupPlayers((allPreviousPlayersMap.get(element) || EMPTY_PLAYER_ARRAY)
  4916. .map(function (p) { return p.getRealPlayer(); }))
  4917. .filter(function (p) {
  4918. // the `element` is not apart of the AnimationPlayer definition, but
  4919. // Mock/WebAnimations
  4920. // use the element within their implementation. This will be added in Angular5 to
  4921. // AnimationPlayer
  4922. var /** @type {?} */ pp = /** @type {?} */ (p);
  4923. return pp.element ? pp.element === element : false;
  4924. });
  4925. var /** @type {?} */ preStyles = preStylesMap.get(element);
  4926. var /** @type {?} */ postStyles = postStylesMap.get(element);
  4927. var /** @type {?} */ keyframes = normalizeKeyframes(_this.driver, _this._normalizer, element, timelineInstruction.keyframes, preStyles, postStyles);
  4928. var /** @type {?} */ player = _this._buildPlayer(timelineInstruction, keyframes, previousPlayers);
  4929. // this means that this particular player belongs to a sub trigger. It is
  4930. // important that we match this player up with the corresponding (@trigger.listener)
  4931. if (timelineInstruction.subTimeline && skippedPlayersMap) {
  4932. allSubElements.add(element);
  4933. }
  4934. if (isQueriedElement) {
  4935. var /** @type {?} */ wrappedPlayer = new TransitionAnimationPlayer(namespaceId, triggerName, element);
  4936. wrappedPlayer.setRealPlayer(player);
  4937. allQueriedPlayers.push(wrappedPlayer);
  4938. }
  4939. return player;
  4940. });
  4941. allQueriedPlayers.forEach(function (player) {
  4942. getOrSetAsInMap(_this.playersByQueriedElement, player.element, []).push(player);
  4943. player.onDone(function () { return deleteOrUnsetInMap(_this.playersByQueriedElement, player.element, player); });
  4944. });
  4945. allConsumedElements.forEach(function (element) { return addClass(element, NG_ANIMATING_CLASSNAME); });
  4946. var /** @type {?} */ player = optimizeGroupPlayer(allNewPlayers);
  4947. player.onDestroy(function () {
  4948. allConsumedElements.forEach(function (element) { return removeClass(element, NG_ANIMATING_CLASSNAME); });
  4949. setStyles(rootElement, instruction.toStyles);
  4950. });
  4951. // this basically makes all of the callbacks for sub element animations
  4952. // be dependent on the upper players for when they finish
  4953. allSubElements.forEach(function (element) { getOrSetAsInMap(skippedPlayersMap, element, []).push(player); });
  4954. return player;
  4955. };
  4956. /**
  4957. * @param {?} instruction
  4958. * @param {?} keyframes
  4959. * @param {?} previousPlayers
  4960. * @return {?}
  4961. */
  4962. TransitionAnimationEngine.prototype._buildPlayer = /**
  4963. * @param {?} instruction
  4964. * @param {?} keyframes
  4965. * @param {?} previousPlayers
  4966. * @return {?}
  4967. */
  4968. function (instruction, keyframes, previousPlayers) {
  4969. if (keyframes.length > 0) {
  4970. return this.driver.animate(instruction.element, keyframes, instruction.duration, instruction.delay, instruction.easing, previousPlayers);
  4971. }
  4972. // special case for when an empty transition|definition is provided
  4973. // ... there is no point in rendering an empty animation
  4974. return new NoopAnimationPlayer();
  4975. };
  4976. return TransitionAnimationEngine;
  4977. }());
  4978. var TransitionAnimationPlayer = /** @class */ (function () {
  4979. function TransitionAnimationPlayer(namespaceId, triggerName, element) {
  4980. this.namespaceId = namespaceId;
  4981. this.triggerName = triggerName;
  4982. this.element = element;
  4983. this._player = new NoopAnimationPlayer();
  4984. this._containsRealPlayer = false;
  4985. this._queuedCallbacks = {};
  4986. this.destroyed = false;
  4987. this.markedForDestroy = false;
  4988. this.queued = true;
  4989. }
  4990. /**
  4991. * @param {?} player
  4992. * @return {?}
  4993. */
  4994. TransitionAnimationPlayer.prototype.setRealPlayer = /**
  4995. * @param {?} player
  4996. * @return {?}
  4997. */
  4998. function (player) {
  4999. var _this = this;
  5000. if (this._containsRealPlayer)
  5001. return;
  5002. this._player = player;
  5003. Object.keys(this._queuedCallbacks).forEach(function (phase) {
  5004. _this._queuedCallbacks[phase].forEach(function (callback) { return listenOnPlayer(player, phase, undefined, callback); });
  5005. });
  5006. this._queuedCallbacks = {};
  5007. this._containsRealPlayer = true;
  5008. (/** @type {?} */ (this)).queued = false;
  5009. };
  5010. /**
  5011. * @return {?}
  5012. */
  5013. TransitionAnimationPlayer.prototype.getRealPlayer = /**
  5014. * @return {?}
  5015. */
  5016. function () { return this._player; };
  5017. /**
  5018. * @param {?} player
  5019. * @return {?}
  5020. */
  5021. TransitionAnimationPlayer.prototype.syncPlayerEvents = /**
  5022. * @param {?} player
  5023. * @return {?}
  5024. */
  5025. function (player) {
  5026. var _this = this;
  5027. var /** @type {?} */ p = /** @type {?} */ (this._player);
  5028. if (p.triggerCallback) {
  5029. player.onStart(function () { return p.triggerCallback('start'); });
  5030. }
  5031. player.onDone(function () { return _this.finish(); });
  5032. player.onDestroy(function () { return _this.destroy(); });
  5033. };
  5034. /**
  5035. * @param {?} name
  5036. * @param {?} callback
  5037. * @return {?}
  5038. */
  5039. TransitionAnimationPlayer.prototype._queueEvent = /**
  5040. * @param {?} name
  5041. * @param {?} callback
  5042. * @return {?}
  5043. */
  5044. function (name, callback) {
  5045. getOrSetAsInMap(this._queuedCallbacks, name, []).push(callback);
  5046. };
  5047. /**
  5048. * @param {?} fn
  5049. * @return {?}
  5050. */
  5051. TransitionAnimationPlayer.prototype.onDone = /**
  5052. * @param {?} fn
  5053. * @return {?}
  5054. */
  5055. function (fn) {
  5056. if (this.queued) {
  5057. this._queueEvent('done', fn);
  5058. }
  5059. this._player.onDone(fn);
  5060. };
  5061. /**
  5062. * @param {?} fn
  5063. * @return {?}
  5064. */
  5065. TransitionAnimationPlayer.prototype.onStart = /**
  5066. * @param {?} fn
  5067. * @return {?}
  5068. */
  5069. function (fn) {
  5070. if (this.queued) {
  5071. this._queueEvent('start', fn);
  5072. }
  5073. this._player.onStart(fn);
  5074. };
  5075. /**
  5076. * @param {?} fn
  5077. * @return {?}
  5078. */
  5079. TransitionAnimationPlayer.prototype.onDestroy = /**
  5080. * @param {?} fn
  5081. * @return {?}
  5082. */
  5083. function (fn) {
  5084. if (this.queued) {
  5085. this._queueEvent('destroy', fn);
  5086. }
  5087. this._player.onDestroy(fn);
  5088. };
  5089. /**
  5090. * @return {?}
  5091. */
  5092. TransitionAnimationPlayer.prototype.init = /**
  5093. * @return {?}
  5094. */
  5095. function () { this._player.init(); };
  5096. /**
  5097. * @return {?}
  5098. */
  5099. TransitionAnimationPlayer.prototype.hasStarted = /**
  5100. * @return {?}
  5101. */
  5102. function () { return this.queued ? false : this._player.hasStarted(); };
  5103. /**
  5104. * @return {?}
  5105. */
  5106. TransitionAnimationPlayer.prototype.play = /**
  5107. * @return {?}
  5108. */
  5109. function () { !this.queued && this._player.play(); };
  5110. /**
  5111. * @return {?}
  5112. */
  5113. TransitionAnimationPlayer.prototype.pause = /**
  5114. * @return {?}
  5115. */
  5116. function () { !this.queued && this._player.pause(); };
  5117. /**
  5118. * @return {?}
  5119. */
  5120. TransitionAnimationPlayer.prototype.restart = /**
  5121. * @return {?}
  5122. */
  5123. function () { !this.queued && this._player.restart(); };
  5124. /**
  5125. * @return {?}
  5126. */
  5127. TransitionAnimationPlayer.prototype.finish = /**
  5128. * @return {?}
  5129. */
  5130. function () { this._player.finish(); };
  5131. /**
  5132. * @return {?}
  5133. */
  5134. TransitionAnimationPlayer.prototype.destroy = /**
  5135. * @return {?}
  5136. */
  5137. function () {
  5138. (/** @type {?} */ (this)).destroyed = true;
  5139. this._player.destroy();
  5140. };
  5141. /**
  5142. * @return {?}
  5143. */
  5144. TransitionAnimationPlayer.prototype.reset = /**
  5145. * @return {?}
  5146. */
  5147. function () { !this.queued && this._player.reset(); };
  5148. /**
  5149. * @param {?} p
  5150. * @return {?}
  5151. */
  5152. TransitionAnimationPlayer.prototype.setPosition = /**
  5153. * @param {?} p
  5154. * @return {?}
  5155. */
  5156. function (p) {
  5157. if (!this.queued) {
  5158. this._player.setPosition(p);
  5159. }
  5160. };
  5161. /**
  5162. * @return {?}
  5163. */
  5164. TransitionAnimationPlayer.prototype.getPosition = /**
  5165. * @return {?}
  5166. */
  5167. function () { return this.queued ? 0 : this._player.getPosition(); };
  5168. Object.defineProperty(TransitionAnimationPlayer.prototype, "totalTime", {
  5169. get: /**
  5170. * @return {?}
  5171. */
  5172. function () { return this._player.totalTime; },
  5173. enumerable: true,
  5174. configurable: true
  5175. });
  5176. /* @internal */
  5177. /**
  5178. * @param {?} phaseName
  5179. * @return {?}
  5180. */
  5181. TransitionAnimationPlayer.prototype.triggerCallback = /**
  5182. * @param {?} phaseName
  5183. * @return {?}
  5184. */
  5185. function (phaseName) {
  5186. var /** @type {?} */ p = /** @type {?} */ (this._player);
  5187. if (p.triggerCallback) {
  5188. p.triggerCallback(phaseName);
  5189. }
  5190. };
  5191. return TransitionAnimationPlayer;
  5192. }());
  5193. /**
  5194. * @param {?} map
  5195. * @param {?} key
  5196. * @param {?} value
  5197. * @return {?}
  5198. */
  5199. function deleteOrUnsetInMap(map, key, value) {
  5200. var /** @type {?} */ currentValues;
  5201. if (map instanceof Map) {
  5202. currentValues = map.get(key);
  5203. if (currentValues) {
  5204. if (currentValues.length) {
  5205. var /** @type {?} */ index = currentValues.indexOf(value);
  5206. currentValues.splice(index, 1);
  5207. }
  5208. if (currentValues.length == 0) {
  5209. map.delete(key);
  5210. }
  5211. }
  5212. }
  5213. else {
  5214. currentValues = map[key];
  5215. if (currentValues) {
  5216. if (currentValues.length) {
  5217. var /** @type {?} */ index = currentValues.indexOf(value);
  5218. currentValues.splice(index, 1);
  5219. }
  5220. if (currentValues.length == 0) {
  5221. delete map[key];
  5222. }
  5223. }
  5224. }
  5225. return currentValues;
  5226. }
  5227. /**
  5228. * @param {?} value
  5229. * @return {?}
  5230. */
  5231. function normalizeTriggerValue(value) {
  5232. // we use `!= null` here because it's the most simple
  5233. // way to test against a "falsy" value without mixing
  5234. // in empty strings or a zero value. DO NOT OPTIMIZE.
  5235. return value != null ? value : null;
  5236. }
  5237. /**
  5238. * @param {?} node
  5239. * @return {?}
  5240. */
  5241. function isElementNode(node) {
  5242. return node && node['nodeType'] === 1;
  5243. }
  5244. /**
  5245. * @param {?} eventName
  5246. * @return {?}
  5247. */
  5248. function isTriggerEventValid(eventName) {
  5249. return eventName == 'start' || eventName == 'done';
  5250. }
  5251. /**
  5252. * @param {?} element
  5253. * @param {?=} value
  5254. * @return {?}
  5255. */
  5256. function cloakElement(element, value) {
  5257. var /** @type {?} */ oldValue = element.style.display;
  5258. element.style.display = value != null ? value : 'none';
  5259. return oldValue;
  5260. }
  5261. /**
  5262. * @param {?} valuesMap
  5263. * @param {?} driver
  5264. * @param {?} elements
  5265. * @param {?} elementPropsMap
  5266. * @param {?} defaultStyle
  5267. * @return {?}
  5268. */
  5269. function cloakAndComputeStyles(valuesMap, driver, elements, elementPropsMap, defaultStyle) {
  5270. var /** @type {?} */ cloakVals = [];
  5271. elements.forEach(function (element) { return cloakVals.push(cloakElement(element)); });
  5272. var /** @type {?} */ failedElements = [];
  5273. elementPropsMap.forEach(function (props, element) {
  5274. var /** @type {?} */ styles = {};
  5275. props.forEach(function (prop) {
  5276. var /** @type {?} */ value = styles[prop] = driver.computeStyle(element, prop, defaultStyle);
  5277. // there is no easy way to detect this because a sub element could be removed
  5278. // by a parent animation element being detached.
  5279. if (!value || value.length == 0) {
  5280. element[REMOVAL_FLAG] = NULL_REMOVED_QUERIED_STATE;
  5281. failedElements.push(element);
  5282. }
  5283. });
  5284. valuesMap.set(element, styles);
  5285. });
  5286. // we use a index variable here since Set.forEach(a, i) does not return
  5287. // an index value for the closure (but instead just the value)
  5288. var /** @type {?} */ i = 0;
  5289. elements.forEach(function (element) { return cloakElement(element, cloakVals[i++]); });
  5290. return failedElements;
  5291. }
  5292. /**
  5293. * @param {?} roots
  5294. * @param {?} nodes
  5295. * @return {?}
  5296. */
  5297. function buildRootMap(roots, nodes) {
  5298. var /** @type {?} */ rootMap = new Map();
  5299. roots.forEach(function (root) { return rootMap.set(root, []); });
  5300. if (nodes.length == 0)
  5301. return rootMap;
  5302. var /** @type {?} */ NULL_NODE = 1;
  5303. var /** @type {?} */ nodeSet = new Set(nodes);
  5304. var /** @type {?} */ localRootMap = new Map();
  5305. /**
  5306. * @param {?} node
  5307. * @return {?}
  5308. */
  5309. function getRoot(node) {
  5310. if (!node)
  5311. return NULL_NODE;
  5312. var /** @type {?} */ root = localRootMap.get(node);
  5313. if (root)
  5314. return root;
  5315. var /** @type {?} */ parent = node.parentNode;
  5316. if (rootMap.has(parent)) {
  5317. // ngIf inside @trigger
  5318. root = parent;
  5319. }
  5320. else if (nodeSet.has(parent)) {
  5321. // ngIf inside ngIf
  5322. root = NULL_NODE;
  5323. }
  5324. else {
  5325. // recurse upwards
  5326. root = getRoot(parent);
  5327. }
  5328. localRootMap.set(node, root);
  5329. return root;
  5330. }
  5331. nodes.forEach(function (node) {
  5332. var /** @type {?} */ root = getRoot(node);
  5333. if (root !== NULL_NODE) {
  5334. /** @type {?} */ ((rootMap.get(root))).push(node);
  5335. }
  5336. });
  5337. return rootMap;
  5338. }
  5339. var CLASSES_CACHE_KEY = '$$classes';
  5340. /**
  5341. * @param {?} element
  5342. * @param {?} className
  5343. * @return {?}
  5344. */
  5345. function addClass(element, className) {
  5346. if (element.classList) {
  5347. element.classList.add(className);
  5348. }
  5349. else {
  5350. var /** @type {?} */ classes = element[CLASSES_CACHE_KEY];
  5351. if (!classes) {
  5352. classes = element[CLASSES_CACHE_KEY] = {};
  5353. }
  5354. classes[className] = true;
  5355. }
  5356. }
  5357. /**
  5358. * @param {?} element
  5359. * @param {?} className
  5360. * @return {?}
  5361. */
  5362. function removeClass(element, className) {
  5363. if (element.classList) {
  5364. element.classList.remove(className);
  5365. }
  5366. else {
  5367. var /** @type {?} */ classes = element[CLASSES_CACHE_KEY];
  5368. if (classes) {
  5369. delete classes[className];
  5370. }
  5371. }
  5372. }
  5373. /**
  5374. * @param {?} engine
  5375. * @param {?} element
  5376. * @param {?} players
  5377. * @return {?}
  5378. */
  5379. function removeNodesAfterAnimationDone(engine, element, players) {
  5380. optimizeGroupPlayer(players).onDone(function () { return engine.processLeaveNode(element); });
  5381. }
  5382. /**
  5383. * @param {?} players
  5384. * @return {?}
  5385. */
  5386. function flattenGroupPlayers(players) {
  5387. var /** @type {?} */ finalPlayers = [];
  5388. _flattenGroupPlayersRecur(players, finalPlayers);
  5389. return finalPlayers;
  5390. }
  5391. /**
  5392. * @param {?} players
  5393. * @param {?} finalPlayers
  5394. * @return {?}
  5395. */
  5396. function _flattenGroupPlayersRecur(players, finalPlayers) {
  5397. for (var /** @type {?} */ i = 0; i < players.length; i++) {
  5398. var /** @type {?} */ player = players[i];
  5399. if (player instanceof ɵAnimationGroupPlayer) {
  5400. _flattenGroupPlayersRecur(player.players, finalPlayers);
  5401. }
  5402. else {
  5403. finalPlayers.push(/** @type {?} */ (player));
  5404. }
  5405. }
  5406. }
  5407. /**
  5408. * @param {?} a
  5409. * @param {?} b
  5410. * @return {?}
  5411. */
  5412. function objEquals(a, b) {
  5413. var /** @type {?} */ k1 = Object.keys(a);
  5414. var /** @type {?} */ k2 = Object.keys(b);
  5415. if (k1.length != k2.length)
  5416. return false;
  5417. for (var /** @type {?} */ i = 0; i < k1.length; i++) {
  5418. var /** @type {?} */ prop = k1[i];
  5419. if (!b.hasOwnProperty(prop) || a[prop] !== b[prop])
  5420. return false;
  5421. }
  5422. return true;
  5423. }
  5424. /**
  5425. * @param {?} element
  5426. * @param {?} allPreStyleElements
  5427. * @param {?} allPostStyleElements
  5428. * @return {?}
  5429. */
  5430. function replacePostStylesAsPre(element, allPreStyleElements, allPostStyleElements) {
  5431. var /** @type {?} */ postEntry = allPostStyleElements.get(element);
  5432. if (!postEntry)
  5433. return false;
  5434. var /** @type {?} */ preEntry = allPreStyleElements.get(element);
  5435. if (preEntry) {
  5436. postEntry.forEach(function (data) { return ((preEntry)).add(data); });
  5437. }
  5438. else {
  5439. allPreStyleElements.set(element, postEntry);
  5440. }
  5441. allPostStyleElements.delete(element);
  5442. return true;
  5443. }
  5444. /**
  5445. * @fileoverview added by tsickle
  5446. * @suppress {checkTypes} checked by tsc
  5447. */
  5448. var AnimationEngine = /** @class */ (function () {
  5449. function AnimationEngine(_driver, normalizer) {
  5450. var _this = this;
  5451. this._driver = _driver;
  5452. this._triggerCache = {};
  5453. this.onRemovalComplete = function (element, context) { };
  5454. this._transitionEngine = new TransitionAnimationEngine(_driver, normalizer);
  5455. this._timelineEngine = new TimelineAnimationEngine(_driver, normalizer);
  5456. this._transitionEngine.onRemovalComplete = function (element, context) {
  5457. return _this.onRemovalComplete(element, context);
  5458. };
  5459. }
  5460. /**
  5461. * @param {?} componentId
  5462. * @param {?} namespaceId
  5463. * @param {?} hostElement
  5464. * @param {?} name
  5465. * @param {?} metadata
  5466. * @return {?}
  5467. */
  5468. AnimationEngine.prototype.registerTrigger = /**
  5469. * @param {?} componentId
  5470. * @param {?} namespaceId
  5471. * @param {?} hostElement
  5472. * @param {?} name
  5473. * @param {?} metadata
  5474. * @return {?}
  5475. */
  5476. function (componentId, namespaceId, hostElement, name, metadata) {
  5477. var /** @type {?} */ cacheKey = componentId + '-' + name;
  5478. var /** @type {?} */ trigger = this._triggerCache[cacheKey];
  5479. if (!trigger) {
  5480. var /** @type {?} */ errors = [];
  5481. var /** @type {?} */ ast = /** @type {?} */ (buildAnimationAst(this._driver, /** @type {?} */ (metadata), errors));
  5482. if (errors.length) {
  5483. throw new Error("The animation trigger \"" + name + "\" has failed to build due to the following errors:\n - " + errors.join("\n - "));
  5484. }
  5485. trigger = buildTrigger(name, ast);
  5486. this._triggerCache[cacheKey] = trigger;
  5487. }
  5488. this._transitionEngine.registerTrigger(namespaceId, name, trigger);
  5489. };
  5490. /**
  5491. * @param {?} namespaceId
  5492. * @param {?} hostElement
  5493. * @return {?}
  5494. */
  5495. AnimationEngine.prototype.register = /**
  5496. * @param {?} namespaceId
  5497. * @param {?} hostElement
  5498. * @return {?}
  5499. */
  5500. function (namespaceId, hostElement) {
  5501. this._transitionEngine.register(namespaceId, hostElement);
  5502. };
  5503. /**
  5504. * @param {?} namespaceId
  5505. * @param {?} context
  5506. * @return {?}
  5507. */
  5508. AnimationEngine.prototype.destroy = /**
  5509. * @param {?} namespaceId
  5510. * @param {?} context
  5511. * @return {?}
  5512. */
  5513. function (namespaceId, context) {
  5514. this._transitionEngine.destroy(namespaceId, context);
  5515. };
  5516. /**
  5517. * @param {?} namespaceId
  5518. * @param {?} element
  5519. * @param {?} parent
  5520. * @param {?} insertBefore
  5521. * @return {?}
  5522. */
  5523. AnimationEngine.prototype.onInsert = /**
  5524. * @param {?} namespaceId
  5525. * @param {?} element
  5526. * @param {?} parent
  5527. * @param {?} insertBefore
  5528. * @return {?}
  5529. */
  5530. function (namespaceId, element, parent, insertBefore) {
  5531. this._transitionEngine.insertNode(namespaceId, element, parent, insertBefore);
  5532. };
  5533. /**
  5534. * @param {?} namespaceId
  5535. * @param {?} element
  5536. * @param {?} context
  5537. * @return {?}
  5538. */
  5539. AnimationEngine.prototype.onRemove = /**
  5540. * @param {?} namespaceId
  5541. * @param {?} element
  5542. * @param {?} context
  5543. * @return {?}
  5544. */
  5545. function (namespaceId, element, context) {
  5546. this._transitionEngine.removeNode(namespaceId, element, context);
  5547. };
  5548. /**
  5549. * @param {?} element
  5550. * @param {?} disable
  5551. * @return {?}
  5552. */
  5553. AnimationEngine.prototype.disableAnimations = /**
  5554. * @param {?} element
  5555. * @param {?} disable
  5556. * @return {?}
  5557. */
  5558. function (element, disable) {
  5559. this._transitionEngine.markElementAsDisabled(element, disable);
  5560. };
  5561. /**
  5562. * @param {?} namespaceId
  5563. * @param {?} element
  5564. * @param {?} property
  5565. * @param {?} value
  5566. * @return {?}
  5567. */
  5568. AnimationEngine.prototype.process = /**
  5569. * @param {?} namespaceId
  5570. * @param {?} element
  5571. * @param {?} property
  5572. * @param {?} value
  5573. * @return {?}
  5574. */
  5575. function (namespaceId, element, property, value) {
  5576. if (property.charAt(0) == '@') {
  5577. var _a = parseTimelineCommand(property), id = _a[0], action = _a[1];
  5578. var /** @type {?} */ args = /** @type {?} */ (value);
  5579. this._timelineEngine.command(id, element, action, args);
  5580. }
  5581. else {
  5582. this._transitionEngine.trigger(namespaceId, element, property, value);
  5583. }
  5584. };
  5585. /**
  5586. * @param {?} namespaceId
  5587. * @param {?} element
  5588. * @param {?} eventName
  5589. * @param {?} eventPhase
  5590. * @param {?} callback
  5591. * @return {?}
  5592. */
  5593. AnimationEngine.prototype.listen = /**
  5594. * @param {?} namespaceId
  5595. * @param {?} element
  5596. * @param {?} eventName
  5597. * @param {?} eventPhase
  5598. * @param {?} callback
  5599. * @return {?}
  5600. */
  5601. function (namespaceId, element, eventName, eventPhase, callback) {
  5602. // @@listen
  5603. if (eventName.charAt(0) == '@') {
  5604. var _a = parseTimelineCommand(eventName), id = _a[0], action = _a[1];
  5605. return this._timelineEngine.listen(id, element, action, callback);
  5606. }
  5607. return this._transitionEngine.listen(namespaceId, element, eventName, eventPhase, callback);
  5608. };
  5609. /**
  5610. * @param {?=} microtaskId
  5611. * @return {?}
  5612. */
  5613. AnimationEngine.prototype.flush = /**
  5614. * @param {?=} microtaskId
  5615. * @return {?}
  5616. */
  5617. function (microtaskId) {
  5618. if (microtaskId === void 0) { microtaskId = -1; }
  5619. this._transitionEngine.flush(microtaskId);
  5620. };
  5621. Object.defineProperty(AnimationEngine.prototype, "players", {
  5622. get: /**
  5623. * @return {?}
  5624. */
  5625. function () {
  5626. return (/** @type {?} */ (this._transitionEngine.players))
  5627. .concat(/** @type {?} */ (this._timelineEngine.players));
  5628. },
  5629. enumerable: true,
  5630. configurable: true
  5631. });
  5632. /**
  5633. * @return {?}
  5634. */
  5635. AnimationEngine.prototype.whenRenderingDone = /**
  5636. * @return {?}
  5637. */
  5638. function () { return this._transitionEngine.whenRenderingDone(); };
  5639. return AnimationEngine;
  5640. }());
  5641. /**
  5642. * @fileoverview added by tsickle
  5643. * @suppress {checkTypes} checked by tsc
  5644. */
  5645. var WebAnimationsPlayer = /** @class */ (function () {
  5646. function WebAnimationsPlayer(element, keyframes, options, previousPlayers) {
  5647. if (previousPlayers === void 0) { previousPlayers = []; }
  5648. var _this = this;
  5649. this.element = element;
  5650. this.keyframes = keyframes;
  5651. this.options = options;
  5652. this.previousPlayers = previousPlayers;
  5653. this._onDoneFns = [];
  5654. this._onStartFns = [];
  5655. this._onDestroyFns = [];
  5656. this._initialized = false;
  5657. this._finished = false;
  5658. this._started = false;
  5659. this._destroyed = false;
  5660. this.time = 0;
  5661. this.parentPlayer = null;
  5662. this.previousStyles = {};
  5663. this.currentSnapshot = {};
  5664. this._duration = /** @type {?} */ (options['duration']);
  5665. this._delay = /** @type {?} */ (options['delay']) || 0;
  5666. this.time = this._duration + this._delay;
  5667. if (allowPreviousPlayerStylesMerge(this._duration, this._delay)) {
  5668. previousPlayers.forEach(function (player) {
  5669. var /** @type {?} */ styles = player.currentSnapshot;
  5670. Object.keys(styles).forEach(function (prop) { return _this.previousStyles[prop] = styles[prop]; });
  5671. });
  5672. }
  5673. }
  5674. /**
  5675. * @return {?}
  5676. */
  5677. WebAnimationsPlayer.prototype._onFinish = /**
  5678. * @return {?}
  5679. */
  5680. function () {
  5681. if (!this._finished) {
  5682. this._finished = true;
  5683. this._onDoneFns.forEach(function (fn) { return fn(); });
  5684. this._onDoneFns = [];
  5685. }
  5686. };
  5687. /**
  5688. * @return {?}
  5689. */
  5690. WebAnimationsPlayer.prototype.init = /**
  5691. * @return {?}
  5692. */
  5693. function () {
  5694. this._buildPlayer();
  5695. this._preparePlayerBeforeStart();
  5696. };
  5697. /**
  5698. * @return {?}
  5699. */
  5700. WebAnimationsPlayer.prototype._buildPlayer = /**
  5701. * @return {?}
  5702. */
  5703. function () {
  5704. var _this = this;
  5705. if (this._initialized)
  5706. return;
  5707. this._initialized = true;
  5708. var /** @type {?} */ keyframes = this.keyframes.map(function (styles) { return copyStyles(styles, false); });
  5709. var /** @type {?} */ previousStyleProps = Object.keys(this.previousStyles);
  5710. if (previousStyleProps.length && keyframes.length) {
  5711. var /** @type {?} */ startingKeyframe_1 = keyframes[0];
  5712. var /** @type {?} */ missingStyleProps_1 = [];
  5713. previousStyleProps.forEach(function (prop) {
  5714. if (!startingKeyframe_1.hasOwnProperty(prop)) {
  5715. missingStyleProps_1.push(prop);
  5716. }
  5717. startingKeyframe_1[prop] = _this.previousStyles[prop];
  5718. });
  5719. if (missingStyleProps_1.length) {
  5720. var /** @type {?} */ self_1 = this;
  5721. var _loop_1 = function () {
  5722. var /** @type {?} */ kf = keyframes[i];
  5723. missingStyleProps_1.forEach(function (prop) {
  5724. kf[prop] = _computeStyle(self_1.element, prop);
  5725. });
  5726. };
  5727. // tslint:disable-next-line
  5728. for (var /** @type {?} */ i = 1; i < keyframes.length; i++) {
  5729. _loop_1();
  5730. }
  5731. }
  5732. }
  5733. (/** @type {?} */ (this)).domPlayer =
  5734. this._triggerWebAnimation(this.element, keyframes, this.options);
  5735. this._finalKeyframe = keyframes.length ? keyframes[keyframes.length - 1] : {};
  5736. this.domPlayer.addEventListener('finish', function () { return _this._onFinish(); });
  5737. };
  5738. /**
  5739. * @return {?}
  5740. */
  5741. WebAnimationsPlayer.prototype._preparePlayerBeforeStart = /**
  5742. * @return {?}
  5743. */
  5744. function () {
  5745. // this is required so that the player doesn't start to animate right away
  5746. if (this._delay) {
  5747. this._resetDomPlayerState();
  5748. }
  5749. else {
  5750. this.domPlayer.pause();
  5751. }
  5752. };
  5753. /** @internal */
  5754. /**
  5755. * \@internal
  5756. * @param {?} element
  5757. * @param {?} keyframes
  5758. * @param {?} options
  5759. * @return {?}
  5760. */
  5761. WebAnimationsPlayer.prototype._triggerWebAnimation = /**
  5762. * \@internal
  5763. * @param {?} element
  5764. * @param {?} keyframes
  5765. * @param {?} options
  5766. * @return {?}
  5767. */
  5768. function (element, keyframes, options) {
  5769. // jscompiler doesn't seem to know animate is a native property because it's not fully
  5770. // supported yet across common browsers (we polyfill it for Edge/Safari) [CL #143630929]
  5771. return /** @type {?} */ (element['animate'](keyframes, options));
  5772. };
  5773. /**
  5774. * @param {?} fn
  5775. * @return {?}
  5776. */
  5777. WebAnimationsPlayer.prototype.onStart = /**
  5778. * @param {?} fn
  5779. * @return {?}
  5780. */
  5781. function (fn) { this._onStartFns.push(fn); };
  5782. /**
  5783. * @param {?} fn
  5784. * @return {?}
  5785. */
  5786. WebAnimationsPlayer.prototype.onDone = /**
  5787. * @param {?} fn
  5788. * @return {?}
  5789. */
  5790. function (fn) { this._onDoneFns.push(fn); };
  5791. /**
  5792. * @param {?} fn
  5793. * @return {?}
  5794. */
  5795. WebAnimationsPlayer.prototype.onDestroy = /**
  5796. * @param {?} fn
  5797. * @return {?}
  5798. */
  5799. function (fn) { this._onDestroyFns.push(fn); };
  5800. /**
  5801. * @return {?}
  5802. */
  5803. WebAnimationsPlayer.prototype.play = /**
  5804. * @return {?}
  5805. */
  5806. function () {
  5807. this._buildPlayer();
  5808. if (!this.hasStarted()) {
  5809. this._onStartFns.forEach(function (fn) { return fn(); });
  5810. this._onStartFns = [];
  5811. this._started = true;
  5812. }
  5813. this.domPlayer.play();
  5814. };
  5815. /**
  5816. * @return {?}
  5817. */
  5818. WebAnimationsPlayer.prototype.pause = /**
  5819. * @return {?}
  5820. */
  5821. function () {
  5822. this.init();
  5823. this.domPlayer.pause();
  5824. };
  5825. /**
  5826. * @return {?}
  5827. */
  5828. WebAnimationsPlayer.prototype.finish = /**
  5829. * @return {?}
  5830. */
  5831. function () {
  5832. this.init();
  5833. this._onFinish();
  5834. this.domPlayer.finish();
  5835. };
  5836. /**
  5837. * @return {?}
  5838. */
  5839. WebAnimationsPlayer.prototype.reset = /**
  5840. * @return {?}
  5841. */
  5842. function () {
  5843. this._resetDomPlayerState();
  5844. this._destroyed = false;
  5845. this._finished = false;
  5846. this._started = false;
  5847. };
  5848. /**
  5849. * @return {?}
  5850. */
  5851. WebAnimationsPlayer.prototype._resetDomPlayerState = /**
  5852. * @return {?}
  5853. */
  5854. function () {
  5855. if (this.domPlayer) {
  5856. this.domPlayer.cancel();
  5857. }
  5858. };
  5859. /**
  5860. * @return {?}
  5861. */
  5862. WebAnimationsPlayer.prototype.restart = /**
  5863. * @return {?}
  5864. */
  5865. function () {
  5866. this.reset();
  5867. this.play();
  5868. };
  5869. /**
  5870. * @return {?}
  5871. */
  5872. WebAnimationsPlayer.prototype.hasStarted = /**
  5873. * @return {?}
  5874. */
  5875. function () { return this._started; };
  5876. /**
  5877. * @return {?}
  5878. */
  5879. WebAnimationsPlayer.prototype.destroy = /**
  5880. * @return {?}
  5881. */
  5882. function () {
  5883. if (!this._destroyed) {
  5884. this._destroyed = true;
  5885. this._resetDomPlayerState();
  5886. this._onFinish();
  5887. this._onDestroyFns.forEach(function (fn) { return fn(); });
  5888. this._onDestroyFns = [];
  5889. }
  5890. };
  5891. /**
  5892. * @param {?} p
  5893. * @return {?}
  5894. */
  5895. WebAnimationsPlayer.prototype.setPosition = /**
  5896. * @param {?} p
  5897. * @return {?}
  5898. */
  5899. function (p) { this.domPlayer.currentTime = p * this.time; };
  5900. /**
  5901. * @return {?}
  5902. */
  5903. WebAnimationsPlayer.prototype.getPosition = /**
  5904. * @return {?}
  5905. */
  5906. function () { return this.domPlayer.currentTime / this.time; };
  5907. Object.defineProperty(WebAnimationsPlayer.prototype, "totalTime", {
  5908. get: /**
  5909. * @return {?}
  5910. */
  5911. function () { return this._delay + this._duration; },
  5912. enumerable: true,
  5913. configurable: true
  5914. });
  5915. /**
  5916. * @return {?}
  5917. */
  5918. WebAnimationsPlayer.prototype.beforeDestroy = /**
  5919. * @return {?}
  5920. */
  5921. function () {
  5922. var _this = this;
  5923. var /** @type {?} */ styles = {};
  5924. if (this.hasStarted()) {
  5925. Object.keys(this._finalKeyframe).forEach(function (prop) {
  5926. if (prop != 'offset') {
  5927. styles[prop] =
  5928. _this._finished ? _this._finalKeyframe[prop] : _computeStyle(_this.element, prop);
  5929. }
  5930. });
  5931. }
  5932. this.currentSnapshot = styles;
  5933. };
  5934. /* @internal */
  5935. /**
  5936. * @param {?} phaseName
  5937. * @return {?}
  5938. */
  5939. WebAnimationsPlayer.prototype.triggerCallback = /**
  5940. * @param {?} phaseName
  5941. * @return {?}
  5942. */
  5943. function (phaseName) {
  5944. var /** @type {?} */ methods = phaseName == 'start' ? this._onStartFns : this._onDoneFns;
  5945. methods.forEach(function (fn) { return fn(); });
  5946. methods.length = 0;
  5947. };
  5948. return WebAnimationsPlayer;
  5949. }());
  5950. /**
  5951. * @param {?} element
  5952. * @param {?} prop
  5953. * @return {?}
  5954. */
  5955. function _computeStyle(element, prop) {
  5956. return (/** @type {?} */ (window.getComputedStyle(element)))[prop];
  5957. }
  5958. /**
  5959. * @fileoverview added by tsickle
  5960. * @suppress {checkTypes} checked by tsc
  5961. */
  5962. var WebAnimationsDriver = /** @class */ (function () {
  5963. function WebAnimationsDriver() {
  5964. }
  5965. /**
  5966. * @param {?} prop
  5967. * @return {?}
  5968. */
  5969. WebAnimationsDriver.prototype.validateStyleProperty = /**
  5970. * @param {?} prop
  5971. * @return {?}
  5972. */
  5973. function (prop) { return validateStyleProperty(prop); };
  5974. /**
  5975. * @param {?} element
  5976. * @param {?} selector
  5977. * @return {?}
  5978. */
  5979. WebAnimationsDriver.prototype.matchesElement = /**
  5980. * @param {?} element
  5981. * @param {?} selector
  5982. * @return {?}
  5983. */
  5984. function (element, selector) {
  5985. return matchesElement(element, selector);
  5986. };
  5987. /**
  5988. * @param {?} elm1
  5989. * @param {?} elm2
  5990. * @return {?}
  5991. */
  5992. WebAnimationsDriver.prototype.containsElement = /**
  5993. * @param {?} elm1
  5994. * @param {?} elm2
  5995. * @return {?}
  5996. */
  5997. function (elm1, elm2) { return containsElement(elm1, elm2); };
  5998. /**
  5999. * @param {?} element
  6000. * @param {?} selector
  6001. * @param {?} multi
  6002. * @return {?}
  6003. */
  6004. WebAnimationsDriver.prototype.query = /**
  6005. * @param {?} element
  6006. * @param {?} selector
  6007. * @param {?} multi
  6008. * @return {?}
  6009. */
  6010. function (element, selector, multi) {
  6011. return invokeQuery(element, selector, multi);
  6012. };
  6013. /**
  6014. * @param {?} element
  6015. * @param {?} prop
  6016. * @param {?=} defaultValue
  6017. * @return {?}
  6018. */
  6019. WebAnimationsDriver.prototype.computeStyle = /**
  6020. * @param {?} element
  6021. * @param {?} prop
  6022. * @param {?=} defaultValue
  6023. * @return {?}
  6024. */
  6025. function (element, prop, defaultValue) {
  6026. return /** @type {?} */ ((/** @type {?} */ (window.getComputedStyle(element)))[prop]);
  6027. };
  6028. /**
  6029. * @param {?} element
  6030. * @param {?} keyframes
  6031. * @param {?} duration
  6032. * @param {?} delay
  6033. * @param {?} easing
  6034. * @param {?=} previousPlayers
  6035. * @return {?}
  6036. */
  6037. WebAnimationsDriver.prototype.animate = /**
  6038. * @param {?} element
  6039. * @param {?} keyframes
  6040. * @param {?} duration
  6041. * @param {?} delay
  6042. * @param {?} easing
  6043. * @param {?=} previousPlayers
  6044. * @return {?}
  6045. */
  6046. function (element, keyframes, duration, delay, easing, previousPlayers) {
  6047. if (previousPlayers === void 0) { previousPlayers = []; }
  6048. var /** @type {?} */ fill = delay == 0 ? 'both' : 'forwards';
  6049. var /** @type {?} */ playerOptions = { duration: duration, delay: delay, fill: fill };
  6050. // we check for this to avoid having a null|undefined value be present
  6051. // for the easing (which results in an error for certain browsers #9752)
  6052. if (easing) {
  6053. playerOptions['easing'] = easing;
  6054. }
  6055. var /** @type {?} */ previousWebAnimationPlayers = /** @type {?} */ (previousPlayers.filter(function (player) { return player instanceof WebAnimationsPlayer; }));
  6056. return new WebAnimationsPlayer(element, keyframes, playerOptions, previousWebAnimationPlayers);
  6057. };
  6058. return WebAnimationsDriver;
  6059. }());
  6060. /**
  6061. * @return {?}
  6062. */
  6063. function supportsWebAnimations() {
  6064. return typeof Element !== 'undefined' && typeof (/** @type {?} */ (Element)).prototype['animate'] === 'function';
  6065. }
  6066. /**
  6067. * @fileoverview added by tsickle
  6068. * @suppress {checkTypes} checked by tsc
  6069. */
  6070. /**
  6071. * @fileoverview added by tsickle
  6072. * @suppress {checkTypes} checked by tsc
  6073. */
  6074. /**
  6075. * @license
  6076. * Copyright Google Inc. All Rights Reserved.
  6077. *
  6078. * Use of this source code is governed by an MIT-style license that can be
  6079. * found in the LICENSE file at https://angular.io/license
  6080. */
  6081. /**
  6082. * @fileoverview added by tsickle
  6083. * @suppress {checkTypes} checked by tsc
  6084. */
  6085. /**
  6086. * @license
  6087. * Copyright Google Inc. All Rights Reserved.
  6088. *
  6089. * Use of this source code is governed by an MIT-style license that can be
  6090. * found in the LICENSE file at https://angular.io/license
  6091. */
  6092. /**
  6093. * @module
  6094. * @description
  6095. * Entry point for all public APIs of this package.
  6096. */
  6097. /**
  6098. * @fileoverview added by tsickle
  6099. * @suppress {checkTypes} checked by tsc
  6100. */
  6101. /**
  6102. * Generated bundle index. Do not edit.
  6103. */
  6104. export { AnimationDriver, Animation as ɵAnimation, AnimationStyleNormalizer as ɵAnimationStyleNormalizer, NoopAnimationStyleNormalizer as ɵNoopAnimationStyleNormalizer, WebAnimationsStyleNormalizer as ɵWebAnimationsStyleNormalizer, NoopAnimationDriver as ɵNoopAnimationDriver, AnimationEngine as ɵAnimationEngine, WebAnimationsDriver as ɵWebAnimationsDriver, supportsWebAnimations as ɵsupportsWebAnimations, WebAnimationsPlayer as ɵWebAnimationsPlayer };
  6105. //# sourceMappingURL=browser.js.map