animations-browser.umd.js 217KB

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