animations-browser.umd.js 222 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/animations'), require('@angular/core')) :
  8. typeof define === 'function' && define.amd ? define('@angular/animations/browser', ['exports', '@angular/animations', '@angular/core'], factory) :
  9. (global = global || self, factory((global.ng = global.ng || {}, global.ng.animations = global.ng.animations || {}, global.ng.animations.browser = {}), global.ng.animations, global.ng.core));
  10. }(this, function (exports, animations, core) { '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 = function(d, b) {
  25. extendStatics = Object.setPrototypeOf ||
  26. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  27. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  28. return extendStatics(d, b);
  29. };
  30. function __extends(d, b) {
  31. extendStatics(d, b);
  32. function __() { this.constructor = d; }
  33. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  34. }
  35. var __assign = function() {
  36. __assign = Object.assign || function __assign(t) {
  37. for (var s, i = 1, n = arguments.length; i < n; i++) {
  38. s = arguments[i];
  39. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  40. }
  41. return t;
  42. };
  43. return __assign.apply(this, arguments);
  44. };
  45. function __decorate(decorators, target, key, desc) {
  46. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  47. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  48. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  49. return c > 3 && r && Object.defineProperty(target, key, r), r;
  50. }
  51. function __values(o) {
  52. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  53. if (m) return m.call(o);
  54. return {
  55. next: function () {
  56. if (o && i >= o.length) o = void 0;
  57. return { value: o && o[i++], done: !o };
  58. }
  59. };
  60. }
  61. function __read(o, n) {
  62. var m = typeof Symbol === "function" && o[Symbol.iterator];
  63. if (!m) return o;
  64. var i = m.call(o), r, ar = [], e;
  65. try {
  66. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  67. }
  68. catch (error) { e = { error: error }; }
  69. finally {
  70. try {
  71. if (r && !r.done && (m = i["return"])) m.call(i);
  72. }
  73. finally { if (e) throw e.error; }
  74. }
  75. return ar;
  76. }
  77. function __spread() {
  78. for (var ar = [], i = 0; i < arguments.length; i++)
  79. ar = ar.concat(__read(arguments[i]));
  80. return ar;
  81. }
  82. function isBrowser() {
  83. return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
  84. }
  85. function isNode() {
  86. return (typeof process !== 'undefined');
  87. }
  88. function optimizeGroupPlayer(players) {
  89. switch (players.length) {
  90. case 0:
  91. return new animations.NoopAnimationPlayer();
  92. case 1:
  93. return players[0];
  94. default:
  95. return new animations.ɵAnimationGroupPlayer(players);
  96. }
  97. }
  98. function normalizeKeyframes(driver, normalizer, element, keyframes, preStyles, postStyles) {
  99. if (preStyles === void 0) { preStyles = {}; }
  100. if (postStyles === void 0) { postStyles = {}; }
  101. var errors = [];
  102. var normalizedKeyframes = [];
  103. var previousOffset = -1;
  104. var previousKeyframe = null;
  105. keyframes.forEach(function (kf) {
  106. var offset = kf['offset'];
  107. var isSameOffset = offset == previousOffset;
  108. var normalizedKeyframe = (isSameOffset && previousKeyframe) || {};
  109. Object.keys(kf).forEach(function (prop) {
  110. var normalizedProp = prop;
  111. var normalizedValue = kf[prop];
  112. if (prop !== 'offset') {
  113. normalizedProp = normalizer.normalizePropertyName(normalizedProp, errors);
  114. switch (normalizedValue) {
  115. case animations.ɵPRE_STYLE:
  116. normalizedValue = preStyles[prop];
  117. break;
  118. case animations.AUTO_STYLE:
  119. normalizedValue = postStyles[prop];
  120. break;
  121. default:
  122. normalizedValue =
  123. normalizer.normalizeStyleValue(prop, normalizedProp, normalizedValue, errors);
  124. break;
  125. }
  126. }
  127. normalizedKeyframe[normalizedProp] = normalizedValue;
  128. });
  129. if (!isSameOffset) {
  130. normalizedKeyframes.push(normalizedKeyframe);
  131. }
  132. previousKeyframe = normalizedKeyframe;
  133. previousOffset = offset;
  134. });
  135. if (errors.length) {
  136. var LINE_START = '\n - ';
  137. throw new Error("Unable to animate due to the following errors:" + LINE_START + errors.join(LINE_START));
  138. }
  139. return normalizedKeyframes;
  140. }
  141. function listenOnPlayer(player, eventName, event, callback) {
  142. switch (eventName) {
  143. case 'start':
  144. player.onStart(function () { return callback(event && copyAnimationEvent(event, 'start', player)); });
  145. break;
  146. case 'done':
  147. player.onDone(function () { return callback(event && copyAnimationEvent(event, 'done', player)); });
  148. break;
  149. case 'destroy':
  150. player.onDestroy(function () { return callback(event && copyAnimationEvent(event, 'destroy', player)); });
  151. break;
  152. }
  153. }
  154. function copyAnimationEvent(e, phaseName, player) {
  155. var totalTime = player.totalTime;
  156. var disabled = player.disabled ? true : false;
  157. var event = makeAnimationEvent(e.element, e.triggerName, e.fromState, e.toState, phaseName || e.phaseName, totalTime == undefined ? e.totalTime : totalTime, disabled);
  158. var data = e['_data'];
  159. if (data != null) {
  160. event['_data'] = data;
  161. }
  162. return event;
  163. }
  164. function makeAnimationEvent(element, triggerName, fromState, toState, phaseName, totalTime, disabled) {
  165. if (phaseName === void 0) { phaseName = ''; }
  166. if (totalTime === void 0) { totalTime = 0; }
  167. return { element: element, triggerName: triggerName, fromState: fromState, toState: toState, phaseName: phaseName, totalTime: totalTime, disabled: !!disabled };
  168. }
  169. function getOrSetAsInMap(map, key, defaultValue) {
  170. var value;
  171. if (map instanceof Map) {
  172. value = map.get(key);
  173. if (!value) {
  174. map.set(key, value = defaultValue);
  175. }
  176. }
  177. else {
  178. value = map[key];
  179. if (!value) {
  180. value = map[key] = defaultValue;
  181. }
  182. }
  183. return value;
  184. }
  185. function parseTimelineCommand(command) {
  186. var separatorPos = command.indexOf(':');
  187. var id = command.substring(1, separatorPos);
  188. var action = command.substr(separatorPos + 1);
  189. return [id, action];
  190. }
  191. var _contains = function (elm1, elm2) { return false; };
  192. var _matches = function (element, selector) {
  193. return false;
  194. };
  195. var _query = function (element, selector, multi) {
  196. return [];
  197. };
  198. // Define utility methods for browsers and platform-server(domino) where Element
  199. // and utility methods exist.
  200. var _isNode = isNode();
  201. if (_isNode || typeof Element !== 'undefined') {
  202. // this is well supported in all browsers
  203. _contains = function (elm1, elm2) { return elm1.contains(elm2); };
  204. _matches = (function () {
  205. if (_isNode || Element.prototype.matches) {
  206. return function (element, selector) { return element.matches(selector); };
  207. }
  208. else {
  209. var proto = Element.prototype;
  210. var fn_1 = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector ||
  211. proto.oMatchesSelector || proto.webkitMatchesSelector;
  212. if (fn_1) {
  213. return function (element, selector) { return fn_1.apply(element, [selector]); };
  214. }
  215. else {
  216. return _matches;
  217. }
  218. }
  219. })();
  220. _query = function (element, selector, multi) {
  221. var results = [];
  222. if (multi) {
  223. results.push.apply(results, __spread(element.querySelectorAll(selector)));
  224. }
  225. else {
  226. var elm = element.querySelector(selector);
  227. if (elm) {
  228. results.push(elm);
  229. }
  230. }
  231. return results;
  232. };
  233. }
  234. function containsVendorPrefix(prop) {
  235. // Webkit is the only real popular vendor prefix nowadays
  236. // cc: http://shouldiprefix.com/
  237. return prop.substring(1, 6) == 'ebkit'; // webkit or Webkit
  238. }
  239. var _CACHED_BODY = null;
  240. var _IS_WEBKIT = false;
  241. function validateStyleProperty(prop) {
  242. if (!_CACHED_BODY) {
  243. _CACHED_BODY = getBodyNode() || {};
  244. _IS_WEBKIT = _CACHED_BODY.style ? ('WebkitAppearance' in _CACHED_BODY.style) : false;
  245. }
  246. var result = true;
  247. if (_CACHED_BODY.style && !containsVendorPrefix(prop)) {
  248. result = prop in _CACHED_BODY.style;
  249. if (!result && _IS_WEBKIT) {
  250. var camelProp = 'Webkit' + prop.charAt(0).toUpperCase() + prop.substr(1);
  251. result = camelProp in _CACHED_BODY.style;
  252. }
  253. }
  254. return result;
  255. }
  256. function getBodyNode() {
  257. if (typeof document != 'undefined') {
  258. return document.body;
  259. }
  260. return null;
  261. }
  262. var matchesElement = _matches;
  263. var containsElement = _contains;
  264. var invokeQuery = _query;
  265. function hypenatePropsObject(object) {
  266. var newObj = {};
  267. Object.keys(object).forEach(function (prop) {
  268. var newProp = prop.replace(/([a-z])([A-Z])/g, '$1-$2');
  269. newObj[newProp] = object[prop];
  270. });
  271. return newObj;
  272. }
  273. /**
  274. * @publicApi
  275. */
  276. var NoopAnimationDriver = /** @class */ (function () {
  277. function NoopAnimationDriver() {
  278. }
  279. NoopAnimationDriver.prototype.validateStyleProperty = function (prop) { return validateStyleProperty(prop); };
  280. NoopAnimationDriver.prototype.matchesElement = function (element, selector) {
  281. return matchesElement(element, selector);
  282. };
  283. NoopAnimationDriver.prototype.containsElement = function (elm1, elm2) { return containsElement(elm1, elm2); };
  284. NoopAnimationDriver.prototype.query = function (element, selector, multi) {
  285. return invokeQuery(element, selector, multi);
  286. };
  287. NoopAnimationDriver.prototype.computeStyle = function (element, prop, defaultValue) {
  288. return defaultValue || '';
  289. };
  290. NoopAnimationDriver.prototype.animate = function (element, keyframes, duration, delay, easing, previousPlayers, scrubberAccessRequested) {
  291. if (previousPlayers === void 0) { previousPlayers = []; }
  292. return new animations.NoopAnimationPlayer(duration, delay);
  293. };
  294. NoopAnimationDriver = __decorate([
  295. core.Injectable()
  296. ], NoopAnimationDriver);
  297. return NoopAnimationDriver;
  298. }());
  299. /**
  300. * @publicApi
  301. */
  302. var AnimationDriver = /** @class */ (function () {
  303. function AnimationDriver() {
  304. }
  305. AnimationDriver.NOOP = new NoopAnimationDriver();
  306. return AnimationDriver;
  307. }());
  308. /**
  309. * @license
  310. * Copyright Google Inc. All Rights Reserved.
  311. *
  312. * Use of this source code is governed by an MIT-style license that can be
  313. * found in the LICENSE file at https://angular.io/license
  314. */
  315. var ONE_SECOND = 1000;
  316. var SUBSTITUTION_EXPR_START = '{{';
  317. var SUBSTITUTION_EXPR_END = '}}';
  318. var ENTER_CLASSNAME = 'ng-enter';
  319. var LEAVE_CLASSNAME = 'ng-leave';
  320. var NG_TRIGGER_CLASSNAME = 'ng-trigger';
  321. var NG_TRIGGER_SELECTOR = '.ng-trigger';
  322. var NG_ANIMATING_CLASSNAME = 'ng-animating';
  323. var NG_ANIMATING_SELECTOR = '.ng-animating';
  324. function resolveTimingValue(value) {
  325. if (typeof value == 'number')
  326. return value;
  327. var matches = value.match(/^(-?[\.\d]+)(m?s)/);
  328. if (!matches || matches.length < 2)
  329. return 0;
  330. return _convertTimeValueToMS(parseFloat(matches[1]), matches[2]);
  331. }
  332. function _convertTimeValueToMS(value, unit) {
  333. switch (unit) {
  334. case 's':
  335. return value * ONE_SECOND;
  336. default: // ms or something else
  337. return value;
  338. }
  339. }
  340. function resolveTiming(timings, errors, allowNegativeValues) {
  341. return timings.hasOwnProperty('duration') ?
  342. timings :
  343. parseTimeExpression(timings, errors, allowNegativeValues);
  344. }
  345. function parseTimeExpression(exp, errors, allowNegativeValues) {
  346. var regex = /^(-?[\.\d]+)(m?s)(?:\s+(-?[\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?$/i;
  347. var duration;
  348. var delay = 0;
  349. var easing = '';
  350. if (typeof exp === 'string') {
  351. var matches = exp.match(regex);
  352. if (matches === null) {
  353. errors.push("The provided timing value \"" + exp + "\" is invalid.");
  354. return { duration: 0, delay: 0, easing: '' };
  355. }
  356. duration = _convertTimeValueToMS(parseFloat(matches[1]), matches[2]);
  357. var delayMatch = matches[3];
  358. if (delayMatch != null) {
  359. delay = _convertTimeValueToMS(parseFloat(delayMatch), matches[4]);
  360. }
  361. var easingVal = matches[5];
  362. if (easingVal) {
  363. easing = easingVal;
  364. }
  365. }
  366. else {
  367. duration = exp;
  368. }
  369. if (!allowNegativeValues) {
  370. var containsErrors = false;
  371. var startIndex = errors.length;
  372. if (duration < 0) {
  373. errors.push("Duration values below 0 are not allowed for this animation step.");
  374. containsErrors = true;
  375. }
  376. if (delay < 0) {
  377. errors.push("Delay values below 0 are not allowed for this animation step.");
  378. containsErrors = true;
  379. }
  380. if (containsErrors) {
  381. errors.splice(startIndex, 0, "The provided timing value \"" + exp + "\" is invalid.");
  382. }
  383. }
  384. return { duration: duration, delay: delay, easing: easing };
  385. }
  386. function copyObj(obj, destination) {
  387. if (destination === void 0) { destination = {}; }
  388. Object.keys(obj).forEach(function (prop) { destination[prop] = obj[prop]; });
  389. return destination;
  390. }
  391. function normalizeStyles(styles) {
  392. var normalizedStyles = {};
  393. if (Array.isArray(styles)) {
  394. styles.forEach(function (data) { return copyStyles(data, false, normalizedStyles); });
  395. }
  396. else {
  397. copyStyles(styles, false, normalizedStyles);
  398. }
  399. return normalizedStyles;
  400. }
  401. function copyStyles(styles, readPrototype, destination) {
  402. if (destination === void 0) { destination = {}; }
  403. if (readPrototype) {
  404. // we make use of a for-in loop so that the
  405. // prototypically inherited properties are
  406. // revealed from the backFill map
  407. for (var prop in styles) {
  408. destination[prop] = styles[prop];
  409. }
  410. }
  411. else {
  412. copyObj(styles, destination);
  413. }
  414. return destination;
  415. }
  416. function getStyleAttributeString(element, key, value) {
  417. // Return the key-value pair string to be added to the style attribute for the
  418. // given CSS style key.
  419. if (value) {
  420. return key + ':' + value + ';';
  421. }
  422. else {
  423. return '';
  424. }
  425. }
  426. function writeStyleAttribute(element) {
  427. // Read the style property of the element and manually reflect it to the
  428. // style attribute. This is needed because Domino on platform-server doesn't
  429. // understand the full set of allowed CSS properties and doesn't reflect some
  430. // of them automatically.
  431. var styleAttrValue = '';
  432. for (var i = 0; i < element.style.length; i++) {
  433. var key = element.style.item(i);
  434. styleAttrValue += getStyleAttributeString(element, key, element.style.getPropertyValue(key));
  435. }
  436. for (var key in element.style) {
  437. // Skip internal Domino properties that don't need to be reflected.
  438. if (!element.style.hasOwnProperty(key) || key.startsWith('_')) {
  439. continue;
  440. }
  441. var dashKey = camelCaseToDashCase(key);
  442. styleAttrValue += getStyleAttributeString(element, dashKey, element.style[key]);
  443. }
  444. element.setAttribute('style', styleAttrValue);
  445. }
  446. function setStyles(element, styles, formerStyles) {
  447. if (element['style']) {
  448. Object.keys(styles).forEach(function (prop) {
  449. var camelProp = dashCaseToCamelCase(prop);
  450. if (formerStyles && !formerStyles.hasOwnProperty(prop)) {
  451. formerStyles[prop] = element.style[camelProp];
  452. }
  453. element.style[camelProp] = styles[prop];
  454. });
  455. // On the server set the 'style' attribute since it's not automatically reflected.
  456. if (isNode()) {
  457. writeStyleAttribute(element);
  458. }
  459. }
  460. }
  461. function eraseStyles(element, styles) {
  462. if (element['style']) {
  463. Object.keys(styles).forEach(function (prop) {
  464. var camelProp = dashCaseToCamelCase(prop);
  465. element.style[camelProp] = '';
  466. });
  467. // On the server set the 'style' attribute since it's not automatically reflected.
  468. if (isNode()) {
  469. writeStyleAttribute(element);
  470. }
  471. }
  472. }
  473. function normalizeAnimationEntry(steps) {
  474. if (Array.isArray(steps)) {
  475. if (steps.length == 1)
  476. return steps[0];
  477. return animations.sequence(steps);
  478. }
  479. return steps;
  480. }
  481. function validateStyleParams(value, options, errors) {
  482. var params = options.params || {};
  483. var matches = extractStyleParams(value);
  484. if (matches.length) {
  485. matches.forEach(function (varName) {
  486. if (!params.hasOwnProperty(varName)) {
  487. errors.push("Unable to resolve the local animation param " + varName + " in the given list of values");
  488. }
  489. });
  490. }
  491. }
  492. var PARAM_REGEX = new RegExp(SUBSTITUTION_EXPR_START + "\\s*(.+?)\\s*" + SUBSTITUTION_EXPR_END, 'g');
  493. function extractStyleParams(value) {
  494. var params = [];
  495. if (typeof value === 'string') {
  496. var val = value.toString();
  497. var match = void 0;
  498. while (match = PARAM_REGEX.exec(val)) {
  499. params.push(match[1]);
  500. }
  501. PARAM_REGEX.lastIndex = 0;
  502. }
  503. return params;
  504. }
  505. function interpolateParams(value, params, errors) {
  506. var original = value.toString();
  507. var str = original.replace(PARAM_REGEX, function (_, varName) {
  508. var localVal = params[varName];
  509. // this means that the value was never overridden by the data passed in by the user
  510. if (!params.hasOwnProperty(varName)) {
  511. errors.push("Please provide a value for the animation param " + varName);
  512. localVal = '';
  513. }
  514. return localVal.toString();
  515. });
  516. // we do this to assert that numeric values stay as they are
  517. return str == original ? value : str;
  518. }
  519. function iteratorToArray(iterator) {
  520. var arr = [];
  521. var item = iterator.next();
  522. while (!item.done) {
  523. arr.push(item.value);
  524. item = iterator.next();
  525. }
  526. return arr;
  527. }
  528. var DASH_CASE_REGEXP = /-+([a-z0-9])/g;
  529. function dashCaseToCamelCase(input) {
  530. return input.replace(DASH_CASE_REGEXP, function () {
  531. var m = [];
  532. for (var _i = 0; _i < arguments.length; _i++) {
  533. m[_i] = arguments[_i];
  534. }
  535. return m[1].toUpperCase();
  536. });
  537. }
  538. function camelCaseToDashCase(input) {
  539. return input.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  540. }
  541. function allowPreviousPlayerStylesMerge(duration, delay) {
  542. return duration === 0 || delay === 0;
  543. }
  544. function balancePreviousStylesIntoKeyframes(element, keyframes, previousStyles) {
  545. var previousStyleProps = Object.keys(previousStyles);
  546. if (previousStyleProps.length && keyframes.length) {
  547. var startingKeyframe_1 = keyframes[0];
  548. var missingStyleProps_1 = [];
  549. previousStyleProps.forEach(function (prop) {
  550. if (!startingKeyframe_1.hasOwnProperty(prop)) {
  551. missingStyleProps_1.push(prop);
  552. }
  553. startingKeyframe_1[prop] = previousStyles[prop];
  554. });
  555. if (missingStyleProps_1.length) {
  556. var _loop_1 = function () {
  557. var kf = keyframes[i];
  558. missingStyleProps_1.forEach(function (prop) { kf[prop] = computeStyle(element, prop); });
  559. };
  560. // tslint:disable-next-line
  561. for (var i = 1; i < keyframes.length; i++) {
  562. _loop_1();
  563. }
  564. }
  565. }
  566. return keyframes;
  567. }
  568. function visitDslNode(visitor, node, context) {
  569. switch (node.type) {
  570. case 7 /* Trigger */:
  571. return visitor.visitTrigger(node, context);
  572. case 0 /* State */:
  573. return visitor.visitState(node, context);
  574. case 1 /* Transition */:
  575. return visitor.visitTransition(node, context);
  576. case 2 /* Sequence */:
  577. return visitor.visitSequence(node, context);
  578. case 3 /* Group */:
  579. return visitor.visitGroup(node, context);
  580. case 4 /* Animate */:
  581. return visitor.visitAnimate(node, context);
  582. case 5 /* Keyframes */:
  583. return visitor.visitKeyframes(node, context);
  584. case 6 /* Style */:
  585. return visitor.visitStyle(node, context);
  586. case 8 /* Reference */:
  587. return visitor.visitReference(node, context);
  588. case 9 /* AnimateChild */:
  589. return visitor.visitAnimateChild(node, context);
  590. case 10 /* AnimateRef */:
  591. return visitor.visitAnimateRef(node, context);
  592. case 11 /* Query */:
  593. return visitor.visitQuery(node, context);
  594. case 12 /* Stagger */:
  595. return visitor.visitStagger(node, context);
  596. default:
  597. throw new Error("Unable to resolve animation metadata node #" + node.type);
  598. }
  599. }
  600. function computeStyle(element, prop) {
  601. return window.getComputedStyle(element)[prop];
  602. }
  603. /**
  604. * @license
  605. * Copyright Google Inc. All Rights Reserved.
  606. *
  607. * Use of this source code is governed by an MIT-style license that can be
  608. * found in the LICENSE file at https://angular.io/license
  609. */
  610. var ANY_STATE = '*';
  611. function parseTransitionExpr(transitionValue, errors) {
  612. var expressions = [];
  613. if (typeof transitionValue == 'string') {
  614. transitionValue
  615. .split(/\s*,\s*/)
  616. .forEach(function (str) { return parseInnerTransitionStr(str, expressions, errors); });
  617. }
  618. else {
  619. expressions.push(transitionValue);
  620. }
  621. return expressions;
  622. }
  623. function parseInnerTransitionStr(eventStr, expressions, errors) {
  624. if (eventStr[0] == ':') {
  625. var result = parseAnimationAlias(eventStr, errors);
  626. if (typeof result == 'function') {
  627. expressions.push(result);
  628. return;
  629. }
  630. eventStr = result;
  631. }
  632. var match = eventStr.match(/^(\*|[-\w]+)\s*(<?[=-]>)\s*(\*|[-\w]+)$/);
  633. if (match == null || match.length < 4) {
  634. errors.push("The provided transition expression \"" + eventStr + "\" is not supported");
  635. return expressions;
  636. }
  637. var fromState = match[1];
  638. var separator = match[2];
  639. var toState = match[3];
  640. expressions.push(makeLambdaFromStates(fromState, toState));
  641. var isFullAnyStateExpr = fromState == ANY_STATE && toState == ANY_STATE;
  642. if (separator[0] == '<' && !isFullAnyStateExpr) {
  643. expressions.push(makeLambdaFromStates(toState, fromState));
  644. }
  645. }
  646. function parseAnimationAlias(alias, errors) {
  647. switch (alias) {
  648. case ':enter':
  649. return 'void => *';
  650. case ':leave':
  651. return '* => void';
  652. case ':increment':
  653. return function (fromState, toState) { return parseFloat(toState) > parseFloat(fromState); };
  654. case ':decrement':
  655. return function (fromState, toState) { return parseFloat(toState) < parseFloat(fromState); };
  656. default:
  657. errors.push("The transition alias value \"" + alias + "\" is not supported");
  658. return '* => *';
  659. }
  660. }
  661. // DO NOT REFACTOR ... keep the follow set instantiations
  662. // with the values intact (closure compiler for some reason
  663. // removes follow-up lines that add the values outside of
  664. // the constructor...
  665. var TRUE_BOOLEAN_VALUES = new Set(['true', '1']);
  666. var FALSE_BOOLEAN_VALUES = new Set(['false', '0']);
  667. function makeLambdaFromStates(lhs, rhs) {
  668. var LHS_MATCH_BOOLEAN = TRUE_BOOLEAN_VALUES.has(lhs) || FALSE_BOOLEAN_VALUES.has(lhs);
  669. var RHS_MATCH_BOOLEAN = TRUE_BOOLEAN_VALUES.has(rhs) || FALSE_BOOLEAN_VALUES.has(rhs);
  670. return function (fromState, toState) {
  671. var lhsMatch = lhs == ANY_STATE || lhs == fromState;
  672. var rhsMatch = rhs == ANY_STATE || rhs == toState;
  673. if (!lhsMatch && LHS_MATCH_BOOLEAN && typeof fromState === 'boolean') {
  674. lhsMatch = fromState ? TRUE_BOOLEAN_VALUES.has(lhs) : FALSE_BOOLEAN_VALUES.has(lhs);
  675. }
  676. if (!rhsMatch && RHS_MATCH_BOOLEAN && typeof toState === 'boolean') {
  677. rhsMatch = toState ? TRUE_BOOLEAN_VALUES.has(rhs) : FALSE_BOOLEAN_VALUES.has(rhs);
  678. }
  679. return lhsMatch && rhsMatch;
  680. };
  681. }
  682. var SELF_TOKEN = ':self';
  683. var SELF_TOKEN_REGEX = new RegExp("s*" + SELF_TOKEN + "s*,?", 'g');
  684. /*
  685. * [Validation]
  686. * The visitor code below will traverse the animation AST generated by the animation verb functions
  687. * (the output is a tree of objects) and attempt to perform a series of validations on the data. The
  688. * following corner-cases will be validated:
  689. *
  690. * 1. Overlap of animations
  691. * Given that a CSS property cannot be animated in more than one place at the same time, it's
  692. * important that this behavior is detected and validated. The way in which this occurs is that
  693. * each time a style property is examined, a string-map containing the property will be updated with
  694. * the start and end times for when the property is used within an animation step.
  695. *
  696. * If there are two or more parallel animations that are currently running (these are invoked by the
  697. * group()) on the same element then the validator will throw an error. Since the start/end timing
  698. * values are collected for each property then if the current animation step is animating the same
  699. * property and its timing values fall anywhere into the window of time that the property is
  700. * currently being animated within then this is what causes an error.
  701. *
  702. * 2. Timing values
  703. * The validator will validate to see if a timing value of `duration delay easing` or
  704. * `durationNumber` is valid or not.
  705. *
  706. * (note that upon validation the code below will replace the timing data with an object containing
  707. * {duration,delay,easing}.
  708. *
  709. * 3. Offset Validation
  710. * Each of the style() calls are allowed to have an offset value when placed inside of keyframes().
  711. * Offsets within keyframes() are considered valid when:
  712. *
  713. * - No offsets are used at all
  714. * - Each style() entry contains an offset value
  715. * - Each offset is between 0 and 1
  716. * - Each offset is greater to or equal than the previous one
  717. *
  718. * Otherwise an error will be thrown.
  719. */
  720. function buildAnimationAst(driver, metadata, errors) {
  721. return new AnimationAstBuilderVisitor(driver).build(metadata, errors);
  722. }
  723. var ROOT_SELECTOR = '';
  724. var AnimationAstBuilderVisitor = /** @class */ (function () {
  725. function AnimationAstBuilderVisitor(_driver) {
  726. this._driver = _driver;
  727. }
  728. AnimationAstBuilderVisitor.prototype.build = function (metadata, errors) {
  729. var context = new AnimationAstBuilderContext(errors);
  730. this._resetContextStyleTimingState(context);
  731. return visitDslNode(this, normalizeAnimationEntry(metadata), context);
  732. };
  733. AnimationAstBuilderVisitor.prototype._resetContextStyleTimingState = function (context) {
  734. context.currentQuerySelector = ROOT_SELECTOR;
  735. context.collectedStyles = {};
  736. context.collectedStyles[ROOT_SELECTOR] = {};
  737. context.currentTime = 0;
  738. };
  739. AnimationAstBuilderVisitor.prototype.visitTrigger = function (metadata, context) {
  740. var _this = this;
  741. var queryCount = context.queryCount = 0;
  742. var depCount = context.depCount = 0;
  743. var states = [];
  744. var transitions = [];
  745. if (metadata.name.charAt(0) == '@') {
  746. context.errors.push('animation triggers cannot be prefixed with an `@` sign (e.g. trigger(\'@foo\', [...]))');
  747. }
  748. metadata.definitions.forEach(function (def) {
  749. _this._resetContextStyleTimingState(context);
  750. if (def.type == 0 /* State */) {
  751. var stateDef_1 = def;
  752. var name_1 = stateDef_1.name;
  753. name_1.toString().split(/\s*,\s*/).forEach(function (n) {
  754. stateDef_1.name = n;
  755. states.push(_this.visitState(stateDef_1, context));
  756. });
  757. stateDef_1.name = name_1;
  758. }
  759. else if (def.type == 1 /* Transition */) {
  760. var transition = _this.visitTransition(def, context);
  761. queryCount += transition.queryCount;
  762. depCount += transition.depCount;
  763. transitions.push(transition);
  764. }
  765. else {
  766. context.errors.push('only state() and transition() definitions can sit inside of a trigger()');
  767. }
  768. });
  769. return {
  770. type: 7 /* Trigger */,
  771. name: metadata.name, states: states, transitions: transitions, queryCount: queryCount, depCount: depCount,
  772. options: null
  773. };
  774. };
  775. AnimationAstBuilderVisitor.prototype.visitState = function (metadata, context) {
  776. var styleAst = this.visitStyle(metadata.styles, context);
  777. var astParams = (metadata.options && metadata.options.params) || null;
  778. if (styleAst.containsDynamicStyles) {
  779. var missingSubs_1 = new Set();
  780. var params_1 = astParams || {};
  781. styleAst.styles.forEach(function (value) {
  782. if (isObject(value)) {
  783. var stylesObj_1 = value;
  784. Object.keys(stylesObj_1).forEach(function (prop) {
  785. extractStyleParams(stylesObj_1[prop]).forEach(function (sub) {
  786. if (!params_1.hasOwnProperty(sub)) {
  787. missingSubs_1.add(sub);
  788. }
  789. });
  790. });
  791. }
  792. });
  793. if (missingSubs_1.size) {
  794. var missingSubsArr = iteratorToArray(missingSubs_1.values());
  795. context.errors.push("state(\"" + metadata.name + "\", ...) must define default values for all the following style substitutions: " + missingSubsArr.join(', '));
  796. }
  797. }
  798. return {
  799. type: 0 /* State */,
  800. name: metadata.name,
  801. style: styleAst,
  802. options: astParams ? { params: astParams } : null
  803. };
  804. };
  805. AnimationAstBuilderVisitor.prototype.visitTransition = function (metadata, context) {
  806. context.queryCount = 0;
  807. context.depCount = 0;
  808. var animation = visitDslNode(this, normalizeAnimationEntry(metadata.animation), context);
  809. var matchers = parseTransitionExpr(metadata.expr, context.errors);
  810. return {
  811. type: 1 /* Transition */,
  812. matchers: matchers,
  813. animation: animation,
  814. queryCount: context.queryCount,
  815. depCount: context.depCount,
  816. options: normalizeAnimationOptions(metadata.options)
  817. };
  818. };
  819. AnimationAstBuilderVisitor.prototype.visitSequence = function (metadata, context) {
  820. var _this = this;
  821. return {
  822. type: 2 /* Sequence */,
  823. steps: metadata.steps.map(function (s) { return visitDslNode(_this, s, context); }),
  824. options: normalizeAnimationOptions(metadata.options)
  825. };
  826. };
  827. AnimationAstBuilderVisitor.prototype.visitGroup = function (metadata, context) {
  828. var _this = this;
  829. var currentTime = context.currentTime;
  830. var furthestTime = 0;
  831. var steps = metadata.steps.map(function (step) {
  832. context.currentTime = currentTime;
  833. var innerAst = visitDslNode(_this, step, context);
  834. furthestTime = Math.max(furthestTime, context.currentTime);
  835. return innerAst;
  836. });
  837. context.currentTime = furthestTime;
  838. return {
  839. type: 3 /* Group */,
  840. steps: steps,
  841. options: normalizeAnimationOptions(metadata.options)
  842. };
  843. };
  844. AnimationAstBuilderVisitor.prototype.visitAnimate = function (metadata, context) {
  845. var timingAst = constructTimingAst(metadata.timings, context.errors);
  846. context.currentAnimateTimings = timingAst;
  847. var styleAst;
  848. var styleMetadata = metadata.styles ? metadata.styles : animations.style({});
  849. if (styleMetadata.type == 5 /* Keyframes */) {
  850. styleAst = this.visitKeyframes(styleMetadata, context);
  851. }
  852. else {
  853. var styleMetadata_1 = metadata.styles;
  854. var isEmpty = false;
  855. if (!styleMetadata_1) {
  856. isEmpty = true;
  857. var newStyleData = {};
  858. if (timingAst.easing) {
  859. newStyleData['easing'] = timingAst.easing;
  860. }
  861. styleMetadata_1 = animations.style(newStyleData);
  862. }
  863. context.currentTime += timingAst.duration + timingAst.delay;
  864. var _styleAst = this.visitStyle(styleMetadata_1, context);
  865. _styleAst.isEmptyStep = isEmpty;
  866. styleAst = _styleAst;
  867. }
  868. context.currentAnimateTimings = null;
  869. return {
  870. type: 4 /* Animate */,
  871. timings: timingAst,
  872. style: styleAst,
  873. options: null
  874. };
  875. };
  876. AnimationAstBuilderVisitor.prototype.visitStyle = function (metadata, context) {
  877. var ast = this._makeStyleAst(metadata, context);
  878. this._validateStyleAst(ast, context);
  879. return ast;
  880. };
  881. AnimationAstBuilderVisitor.prototype._makeStyleAst = function (metadata, context) {
  882. var styles = [];
  883. if (Array.isArray(metadata.styles)) {
  884. metadata.styles.forEach(function (styleTuple) {
  885. if (typeof styleTuple == 'string') {
  886. if (styleTuple == animations.AUTO_STYLE) {
  887. styles.push(styleTuple);
  888. }
  889. else {
  890. context.errors.push("The provided style string value " + styleTuple + " is not allowed.");
  891. }
  892. }
  893. else {
  894. styles.push(styleTuple);
  895. }
  896. });
  897. }
  898. else {
  899. styles.push(metadata.styles);
  900. }
  901. var containsDynamicStyles = false;
  902. var collectedEasing = null;
  903. styles.forEach(function (styleData) {
  904. if (isObject(styleData)) {
  905. var styleMap = styleData;
  906. var easing = styleMap['easing'];
  907. if (easing) {
  908. collectedEasing = easing;
  909. delete styleMap['easing'];
  910. }
  911. if (!containsDynamicStyles) {
  912. for (var prop in styleMap) {
  913. var value = styleMap[prop];
  914. if (value.toString().indexOf(SUBSTITUTION_EXPR_START) >= 0) {
  915. containsDynamicStyles = true;
  916. break;
  917. }
  918. }
  919. }
  920. }
  921. });
  922. return {
  923. type: 6 /* Style */,
  924. styles: styles,
  925. easing: collectedEasing,
  926. offset: metadata.offset, containsDynamicStyles: containsDynamicStyles,
  927. options: null
  928. };
  929. };
  930. AnimationAstBuilderVisitor.prototype._validateStyleAst = function (ast, context) {
  931. var _this = this;
  932. var timings = context.currentAnimateTimings;
  933. var endTime = context.currentTime;
  934. var startTime = context.currentTime;
  935. if (timings && startTime > 0) {
  936. startTime -= timings.duration + timings.delay;
  937. }
  938. ast.styles.forEach(function (tuple) {
  939. if (typeof tuple == 'string')
  940. return;
  941. Object.keys(tuple).forEach(function (prop) {
  942. if (!_this._driver.validateStyleProperty(prop)) {
  943. context.errors.push("The provided animation property \"" + prop + "\" is not a supported CSS property for animations");
  944. return;
  945. }
  946. var collectedStyles = context.collectedStyles[context.currentQuerySelector];
  947. var collectedEntry = collectedStyles[prop];
  948. var updateCollectedStyle = true;
  949. if (collectedEntry) {
  950. if (startTime != endTime && startTime >= collectedEntry.startTime &&
  951. endTime <= collectedEntry.endTime) {
  952. 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\"");
  953. updateCollectedStyle = false;
  954. }
  955. // we always choose the smaller start time value since we
  956. // want to have a record of the entire animation window where
  957. // the style property is being animated in between
  958. startTime = collectedEntry.startTime;
  959. }
  960. if (updateCollectedStyle) {
  961. collectedStyles[prop] = { startTime: startTime, endTime: endTime };
  962. }
  963. if (context.options) {
  964. validateStyleParams(tuple[prop], context.options, context.errors);
  965. }
  966. });
  967. });
  968. };
  969. AnimationAstBuilderVisitor.prototype.visitKeyframes = function (metadata, context) {
  970. var _this = this;
  971. var ast = { type: 5 /* Keyframes */, styles: [], options: null };
  972. if (!context.currentAnimateTimings) {
  973. context.errors.push("keyframes() must be placed inside of a call to animate()");
  974. return ast;
  975. }
  976. var MAX_KEYFRAME_OFFSET = 1;
  977. var totalKeyframesWithOffsets = 0;
  978. var offsets = [];
  979. var offsetsOutOfOrder = false;
  980. var keyframesOutOfRange = false;
  981. var previousOffset = 0;
  982. var keyframes = metadata.steps.map(function (styles) {
  983. var style = _this._makeStyleAst(styles, context);
  984. var offsetVal = style.offset != null ? style.offset : consumeOffset(style.styles);
  985. var offset = 0;
  986. if (offsetVal != null) {
  987. totalKeyframesWithOffsets++;
  988. offset = style.offset = offsetVal;
  989. }
  990. keyframesOutOfRange = keyframesOutOfRange || offset < 0 || offset > 1;
  991. offsetsOutOfOrder = offsetsOutOfOrder || offset < previousOffset;
  992. previousOffset = offset;
  993. offsets.push(offset);
  994. return style;
  995. });
  996. if (keyframesOutOfRange) {
  997. context.errors.push("Please ensure that all keyframe offsets are between 0 and 1");
  998. }
  999. if (offsetsOutOfOrder) {
  1000. context.errors.push("Please ensure that all keyframe offsets are in order");
  1001. }
  1002. var length = metadata.steps.length;
  1003. var generatedOffset = 0;
  1004. if (totalKeyframesWithOffsets > 0 && totalKeyframesWithOffsets < length) {
  1005. context.errors.push("Not all style() steps within the declared keyframes() contain offsets");
  1006. }
  1007. else if (totalKeyframesWithOffsets == 0) {
  1008. generatedOffset = MAX_KEYFRAME_OFFSET / (length - 1);
  1009. }
  1010. var limit = length - 1;
  1011. var currentTime = context.currentTime;
  1012. var currentAnimateTimings = context.currentAnimateTimings;
  1013. var animateDuration = currentAnimateTimings.duration;
  1014. keyframes.forEach(function (kf, i) {
  1015. var offset = generatedOffset > 0 ? (i == limit ? 1 : (generatedOffset * i)) : offsets[i];
  1016. var durationUpToThisFrame = offset * animateDuration;
  1017. context.currentTime = currentTime + currentAnimateTimings.delay + durationUpToThisFrame;
  1018. currentAnimateTimings.duration = durationUpToThisFrame;
  1019. _this._validateStyleAst(kf, context);
  1020. kf.offset = offset;
  1021. ast.styles.push(kf);
  1022. });
  1023. return ast;
  1024. };
  1025. AnimationAstBuilderVisitor.prototype.visitReference = function (metadata, context) {
  1026. return {
  1027. type: 8 /* Reference */,
  1028. animation: visitDslNode(this, normalizeAnimationEntry(metadata.animation), context),
  1029. options: normalizeAnimationOptions(metadata.options)
  1030. };
  1031. };
  1032. AnimationAstBuilderVisitor.prototype.visitAnimateChild = function (metadata, context) {
  1033. context.depCount++;
  1034. return {
  1035. type: 9 /* AnimateChild */,
  1036. options: normalizeAnimationOptions(metadata.options)
  1037. };
  1038. };
  1039. AnimationAstBuilderVisitor.prototype.visitAnimateRef = function (metadata, context) {
  1040. return {
  1041. type: 10 /* AnimateRef */,
  1042. animation: this.visitReference(metadata.animation, context),
  1043. options: normalizeAnimationOptions(metadata.options)
  1044. };
  1045. };
  1046. AnimationAstBuilderVisitor.prototype.visitQuery = function (metadata, context) {
  1047. var parentSelector = context.currentQuerySelector;
  1048. var options = (metadata.options || {});
  1049. context.queryCount++;
  1050. context.currentQuery = metadata;
  1051. var _a = __read(normalizeSelector(metadata.selector), 2), selector = _a[0], includeSelf = _a[1];
  1052. context.currentQuerySelector =
  1053. parentSelector.length ? (parentSelector + ' ' + selector) : selector;
  1054. getOrSetAsInMap(context.collectedStyles, context.currentQuerySelector, {});
  1055. var animation = visitDslNode(this, normalizeAnimationEntry(metadata.animation), context);
  1056. context.currentQuery = null;
  1057. context.currentQuerySelector = parentSelector;
  1058. return {
  1059. type: 11 /* Query */,
  1060. selector: selector,
  1061. limit: options.limit || 0,
  1062. optional: !!options.optional, includeSelf: includeSelf, animation: animation,
  1063. originalSelector: metadata.selector,
  1064. options: normalizeAnimationOptions(metadata.options)
  1065. };
  1066. };
  1067. AnimationAstBuilderVisitor.prototype.visitStagger = function (metadata, context) {
  1068. if (!context.currentQuery) {
  1069. context.errors.push("stagger() can only be used inside of query()");
  1070. }
  1071. var timings = metadata.timings === 'full' ?
  1072. { duration: 0, delay: 0, easing: 'full' } :
  1073. resolveTiming(metadata.timings, context.errors, true);
  1074. return {
  1075. type: 12 /* Stagger */,
  1076. animation: visitDslNode(this, normalizeAnimationEntry(metadata.animation), context), timings: timings,
  1077. options: null
  1078. };
  1079. };
  1080. return AnimationAstBuilderVisitor;
  1081. }());
  1082. function normalizeSelector(selector) {
  1083. var hasAmpersand = selector.split(/\s*,\s*/).find(function (token) { return token == SELF_TOKEN; }) ? true : false;
  1084. if (hasAmpersand) {
  1085. selector = selector.replace(SELF_TOKEN_REGEX, '');
  1086. }
  1087. // the :enter and :leave selectors are filled in at runtime during timeline building
  1088. selector = selector.replace(/@\*/g, NG_TRIGGER_SELECTOR)
  1089. .replace(/@\w+/g, function (match) { return NG_TRIGGER_SELECTOR + '-' + match.substr(1); })
  1090. .replace(/:animating/g, NG_ANIMATING_SELECTOR);
  1091. return [selector, hasAmpersand];
  1092. }
  1093. function normalizeParams(obj) {
  1094. return obj ? copyObj(obj) : null;
  1095. }
  1096. var AnimationAstBuilderContext = /** @class */ (function () {
  1097. function AnimationAstBuilderContext(errors) {
  1098. this.errors = errors;
  1099. this.queryCount = 0;
  1100. this.depCount = 0;
  1101. this.currentTransition = null;
  1102. this.currentQuery = null;
  1103. this.currentQuerySelector = null;
  1104. this.currentAnimateTimings = null;
  1105. this.currentTime = 0;
  1106. this.collectedStyles = {};
  1107. this.options = null;
  1108. }
  1109. return AnimationAstBuilderContext;
  1110. }());
  1111. function consumeOffset(styles) {
  1112. if (typeof styles == 'string')
  1113. return null;
  1114. var offset = null;
  1115. if (Array.isArray(styles)) {
  1116. styles.forEach(function (styleTuple) {
  1117. if (isObject(styleTuple) && styleTuple.hasOwnProperty('offset')) {
  1118. var obj = styleTuple;
  1119. offset = parseFloat(obj['offset']);
  1120. delete obj['offset'];
  1121. }
  1122. });
  1123. }
  1124. else if (isObject(styles) && styles.hasOwnProperty('offset')) {
  1125. var obj = styles;
  1126. offset = parseFloat(obj['offset']);
  1127. delete obj['offset'];
  1128. }
  1129. return offset;
  1130. }
  1131. function isObject(value) {
  1132. return !Array.isArray(value) && typeof value == 'object';
  1133. }
  1134. function constructTimingAst(value, errors) {
  1135. var timings = null;
  1136. if (value.hasOwnProperty('duration')) {
  1137. timings = value;
  1138. }
  1139. else if (typeof value == 'number') {
  1140. var duration = resolveTiming(value, errors).duration;
  1141. return makeTimingAst(duration, 0, '');
  1142. }
  1143. var strValue = value;
  1144. var isDynamic = strValue.split(/\s+/).some(function (v) { return v.charAt(0) == '{' && v.charAt(1) == '{'; });
  1145. if (isDynamic) {
  1146. var ast = makeTimingAst(0, 0, '');
  1147. ast.dynamic = true;
  1148. ast.strValue = strValue;
  1149. return ast;
  1150. }
  1151. timings = timings || resolveTiming(strValue, errors);
  1152. return makeTimingAst(timings.duration, timings.delay, timings.easing);
  1153. }
  1154. function normalizeAnimationOptions(options) {
  1155. if (options) {
  1156. options = copyObj(options);
  1157. if (options['params']) {
  1158. options['params'] = normalizeParams(options['params']);
  1159. }
  1160. }
  1161. else {
  1162. options = {};
  1163. }
  1164. return options;
  1165. }
  1166. function makeTimingAst(duration, delay, easing) {
  1167. return { duration: duration, delay: delay, easing: easing };
  1168. }
  1169. function createTimelineInstruction(element, keyframes, preStyleProps, postStyleProps, duration, delay, easing, subTimeline) {
  1170. if (easing === void 0) { easing = null; }
  1171. if (subTimeline === void 0) { subTimeline = false; }
  1172. return {
  1173. type: 1 /* TimelineAnimation */,
  1174. element: element,
  1175. keyframes: keyframes,
  1176. preStyleProps: preStyleProps,
  1177. postStyleProps: postStyleProps,
  1178. duration: duration,
  1179. delay: delay,
  1180. totalTime: duration + delay, easing: easing, subTimeline: subTimeline
  1181. };
  1182. }
  1183. var ElementInstructionMap = /** @class */ (function () {
  1184. function ElementInstructionMap() {
  1185. this._map = new Map();
  1186. }
  1187. ElementInstructionMap.prototype.consume = function (element) {
  1188. var instructions = this._map.get(element);
  1189. if (instructions) {
  1190. this._map.delete(element);
  1191. }
  1192. else {
  1193. instructions = [];
  1194. }
  1195. return instructions;
  1196. };
  1197. ElementInstructionMap.prototype.append = function (element, instructions) {
  1198. var existingInstructions = this._map.get(element);
  1199. if (!existingInstructions) {
  1200. this._map.set(element, existingInstructions = []);
  1201. }
  1202. existingInstructions.push.apply(existingInstructions, __spread(instructions));
  1203. };
  1204. ElementInstructionMap.prototype.has = function (element) { return this._map.has(element); };
  1205. ElementInstructionMap.prototype.clear = function () { this._map.clear(); };
  1206. return ElementInstructionMap;
  1207. }());
  1208. var ONE_FRAME_IN_MILLISECONDS = 1;
  1209. var ENTER_TOKEN = ':enter';
  1210. var ENTER_TOKEN_REGEX = new RegExp(ENTER_TOKEN, 'g');
  1211. var LEAVE_TOKEN = ':leave';
  1212. var LEAVE_TOKEN_REGEX = new RegExp(LEAVE_TOKEN, 'g');
  1213. /*
  1214. * The code within this file aims to generate web-animations-compatible keyframes from Angular's
  1215. * animation DSL code.
  1216. *
  1217. * The code below will be converted from:
  1218. *
  1219. * ```
  1220. * sequence([
  1221. * style({ opacity: 0 }),
  1222. * animate(1000, style({ opacity: 0 }))
  1223. * ])
  1224. * ```
  1225. *
  1226. * To:
  1227. * ```
  1228. * keyframes = [{ opacity: 0, offset: 0 }, { opacity: 1, offset: 1 }]
  1229. * duration = 1000
  1230. * delay = 0
  1231. * easing = ''
  1232. * ```
  1233. *
  1234. * For this operation to cover the combination of animation verbs (style, animate, group, etc...) a
  1235. * combination of prototypical inheritance, AST traversal and merge-sort-like algorithms are used.
  1236. *
  1237. * [AST Traversal]
  1238. * Each of the animation verbs, when executed, will return an string-map object representing what
  1239. * type of action it is (style, animate, group, etc...) and the data associated with it. This means
  1240. * that when functional composition mix of these functions is evaluated (like in the example above)
  1241. * then it will end up producing a tree of objects representing the animation itself.
  1242. *
  1243. * When this animation object tree is processed by the visitor code below it will visit each of the
  1244. * verb statements within the visitor. And during each visit it will build the context of the
  1245. * animation keyframes by interacting with the `TimelineBuilder`.
  1246. *
  1247. * [TimelineBuilder]
  1248. * This class is responsible for tracking the styles and building a series of keyframe objects for a
  1249. * timeline between a start and end time. The builder starts off with an initial timeline and each
  1250. * time the AST comes across a `group()`, `keyframes()` or a combination of the two wihtin a
  1251. * `sequence()` then it will generate a sub timeline for each step as well as a new one after
  1252. * they are complete.
  1253. *
  1254. * As the AST is traversed, the timing state on each of the timelines will be incremented. If a sub
  1255. * timeline was created (based on one of the cases above) then the parent timeline will attempt to
  1256. * merge the styles used within the sub timelines into itself (only with group() this will happen).
  1257. * This happens with a merge operation (much like how the merge works in mergesort) and it will only
  1258. * copy the most recently used styles from the sub timelines into the parent timeline. This ensures
  1259. * that if the styles are used later on in another phase of the animation then they will be the most
  1260. * up-to-date values.
  1261. *
  1262. * [How Missing Styles Are Updated]
  1263. * Each timeline has a `backFill` property which is responsible for filling in new styles into
  1264. * already processed keyframes if a new style shows up later within the animation sequence.
  1265. *
  1266. * ```
  1267. * sequence([
  1268. * style({ width: 0 }),
  1269. * animate(1000, style({ width: 100 })),
  1270. * animate(1000, style({ width: 200 })),
  1271. * animate(1000, style({ width: 300 }))
  1272. * animate(1000, style({ width: 400, height: 400 })) // notice how `height` doesn't exist anywhere
  1273. * else
  1274. * ])
  1275. * ```
  1276. *
  1277. * What is happening here is that the `height` value is added later in the sequence, but is missing
  1278. * from all previous animation steps. Therefore when a keyframe is created it would also be missing
  1279. * from all previous keyframes up until where it is first used. For the timeline keyframe generation
  1280. * to properly fill in the style it will place the previous value (the value from the parent
  1281. * timeline) or a default value of `*` into the backFill object. Given that each of the keyframe
  1282. * styles are objects that prototypically inhert from the backFill object, this means that if a
  1283. * value is added into the backFill then it will automatically propagate any missing values to all
  1284. * keyframes. Therefore the missing `height` value will be properly filled into the already
  1285. * processed keyframes.
  1286. *
  1287. * When a sub-timeline is created it will have its own backFill property. This is done so that
  1288. * styles present within the sub-timeline do not accidentally seep into the previous/future timeline
  1289. * keyframes
  1290. *
  1291. * (For prototypically-inherited contents to be detected a `for(i in obj)` loop must be used.)
  1292. *
  1293. * [Validation]
  1294. * The code in this file is not responsible for validation. That functionality happens with within
  1295. * the `AnimationValidatorVisitor` code.
  1296. */
  1297. function buildAnimationTimelines(driver, rootElement, ast, enterClassName, leaveClassName, startingStyles, finalStyles, options, subInstructions, errors) {
  1298. if (startingStyles === void 0) { startingStyles = {}; }
  1299. if (finalStyles === void 0) { finalStyles = {}; }
  1300. if (errors === void 0) { errors = []; }
  1301. return new AnimationTimelineBuilderVisitor().buildKeyframes(driver, rootElement, ast, enterClassName, leaveClassName, startingStyles, finalStyles, options, subInstructions, errors);
  1302. }
  1303. var AnimationTimelineBuilderVisitor = /** @class */ (function () {
  1304. function AnimationTimelineBuilderVisitor() {
  1305. }
  1306. AnimationTimelineBuilderVisitor.prototype.buildKeyframes = function (driver, rootElement, ast, enterClassName, leaveClassName, startingStyles, finalStyles, options, subInstructions, errors) {
  1307. if (errors === void 0) { errors = []; }
  1308. subInstructions = subInstructions || new ElementInstructionMap();
  1309. var context = new AnimationTimelineContext(driver, rootElement, subInstructions, enterClassName, leaveClassName, errors, []);
  1310. context.options = options;
  1311. context.currentTimeline.setStyles([startingStyles], null, context.errors, options);
  1312. visitDslNode(this, ast, context);
  1313. // this checks to see if an actual animation happened
  1314. var timelines = context.timelines.filter(function (timeline) { return timeline.containsAnimation(); });
  1315. if (timelines.length && Object.keys(finalStyles).length) {
  1316. var tl = timelines[timelines.length - 1];
  1317. if (!tl.allowOnlyTimelineStyles()) {
  1318. tl.setStyles([finalStyles], null, context.errors, options);
  1319. }
  1320. }
  1321. return timelines.length ? timelines.map(function (timeline) { return timeline.buildKeyframes(); }) :
  1322. [createTimelineInstruction(rootElement, [], [], [], 0, 0, '', false)];
  1323. };
  1324. AnimationTimelineBuilderVisitor.prototype.visitTrigger = function (ast, context) {
  1325. // these values are not visited in this AST
  1326. };
  1327. AnimationTimelineBuilderVisitor.prototype.visitState = function (ast, context) {
  1328. // these values are not visited in this AST
  1329. };
  1330. AnimationTimelineBuilderVisitor.prototype.visitTransition = function (ast, context) {
  1331. // these values are not visited in this AST
  1332. };
  1333. AnimationTimelineBuilderVisitor.prototype.visitAnimateChild = function (ast, context) {
  1334. var elementInstructions = context.subInstructions.consume(context.element);
  1335. if (elementInstructions) {
  1336. var innerContext = context.createSubContext(ast.options);
  1337. var startTime = context.currentTimeline.currentTime;
  1338. var endTime = this._visitSubInstructions(elementInstructions, innerContext, innerContext.options);
  1339. if (startTime != endTime) {
  1340. // we do this on the upper context because we created a sub context for
  1341. // the sub child animations
  1342. context.transformIntoNewTimeline(endTime);
  1343. }
  1344. }
  1345. context.previousNode = ast;
  1346. };
  1347. AnimationTimelineBuilderVisitor.prototype.visitAnimateRef = function (ast, context) {
  1348. var innerContext = context.createSubContext(ast.options);
  1349. innerContext.transformIntoNewTimeline();
  1350. this.visitReference(ast.animation, innerContext);
  1351. context.transformIntoNewTimeline(innerContext.currentTimeline.currentTime);
  1352. context.previousNode = ast;
  1353. };
  1354. AnimationTimelineBuilderVisitor.prototype._visitSubInstructions = function (instructions, context, options) {
  1355. var startTime = context.currentTimeline.currentTime;
  1356. var furthestTime = startTime;
  1357. // this is a special-case for when a user wants to skip a sub
  1358. // animation from being fired entirely.
  1359. var duration = options.duration != null ? resolveTimingValue(options.duration) : null;
  1360. var delay = options.delay != null ? resolveTimingValue(options.delay) : null;
  1361. if (duration !== 0) {
  1362. instructions.forEach(function (instruction) {
  1363. var instructionTimings = context.appendInstructionToTimeline(instruction, duration, delay);
  1364. furthestTime =
  1365. Math.max(furthestTime, instructionTimings.duration + instructionTimings.delay);
  1366. });
  1367. }
  1368. return furthestTime;
  1369. };
  1370. AnimationTimelineBuilderVisitor.prototype.visitReference = function (ast, context) {
  1371. context.updateOptions(ast.options, true);
  1372. visitDslNode(this, ast.animation, context);
  1373. context.previousNode = ast;
  1374. };
  1375. AnimationTimelineBuilderVisitor.prototype.visitSequence = function (ast, context) {
  1376. var _this = this;
  1377. var subContextCount = context.subContextCount;
  1378. var ctx = context;
  1379. var options = ast.options;
  1380. if (options && (options.params || options.delay)) {
  1381. ctx = context.createSubContext(options);
  1382. ctx.transformIntoNewTimeline();
  1383. if (options.delay != null) {
  1384. if (ctx.previousNode.type == 6 /* Style */) {
  1385. ctx.currentTimeline.snapshotCurrentStyles();
  1386. ctx.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
  1387. }
  1388. var delay = resolveTimingValue(options.delay);
  1389. ctx.delayNextStep(delay);
  1390. }
  1391. }
  1392. if (ast.steps.length) {
  1393. ast.steps.forEach(function (s) { return visitDslNode(_this, s, ctx); });
  1394. // this is here just incase the inner steps only contain or end with a style() call
  1395. ctx.currentTimeline.applyStylesToKeyframe();
  1396. // this means that some animation function within the sequence
  1397. // ended up creating a sub timeline (which means the current
  1398. // timeline cannot overlap with the contents of the sequence)
  1399. if (ctx.subContextCount > subContextCount) {
  1400. ctx.transformIntoNewTimeline();
  1401. }
  1402. }
  1403. context.previousNode = ast;
  1404. };
  1405. AnimationTimelineBuilderVisitor.prototype.visitGroup = function (ast, context) {
  1406. var _this = this;
  1407. var innerTimelines = [];
  1408. var furthestTime = context.currentTimeline.currentTime;
  1409. var delay = ast.options && ast.options.delay ? resolveTimingValue(ast.options.delay) : 0;
  1410. ast.steps.forEach(function (s) {
  1411. var innerContext = context.createSubContext(ast.options);
  1412. if (delay) {
  1413. innerContext.delayNextStep(delay);
  1414. }
  1415. visitDslNode(_this, s, innerContext);
  1416. furthestTime = Math.max(furthestTime, innerContext.currentTimeline.currentTime);
  1417. innerTimelines.push(innerContext.currentTimeline);
  1418. });
  1419. // this operation is run after the AST loop because otherwise
  1420. // if the parent timeline's collected styles were updated then
  1421. // it would pass in invalid data into the new-to-be forked items
  1422. innerTimelines.forEach(function (timeline) { return context.currentTimeline.mergeTimelineCollectedStyles(timeline); });
  1423. context.transformIntoNewTimeline(furthestTime);
  1424. context.previousNode = ast;
  1425. };
  1426. AnimationTimelineBuilderVisitor.prototype._visitTiming = function (ast, context) {
  1427. if (ast.dynamic) {
  1428. var strValue = ast.strValue;
  1429. var timingValue = context.params ? interpolateParams(strValue, context.params, context.errors) : strValue;
  1430. return resolveTiming(timingValue, context.errors);
  1431. }
  1432. else {
  1433. return { duration: ast.duration, delay: ast.delay, easing: ast.easing };
  1434. }
  1435. };
  1436. AnimationTimelineBuilderVisitor.prototype.visitAnimate = function (ast, context) {
  1437. var timings = context.currentAnimateTimings = this._visitTiming(ast.timings, context);
  1438. var timeline = context.currentTimeline;
  1439. if (timings.delay) {
  1440. context.incrementTime(timings.delay);
  1441. timeline.snapshotCurrentStyles();
  1442. }
  1443. var style = ast.style;
  1444. if (style.type == 5 /* Keyframes */) {
  1445. this.visitKeyframes(style, context);
  1446. }
  1447. else {
  1448. context.incrementTime(timings.duration);
  1449. this.visitStyle(style, context);
  1450. timeline.applyStylesToKeyframe();
  1451. }
  1452. context.currentAnimateTimings = null;
  1453. context.previousNode = ast;
  1454. };
  1455. AnimationTimelineBuilderVisitor.prototype.visitStyle = function (ast, context) {
  1456. var timeline = context.currentTimeline;
  1457. var timings = context.currentAnimateTimings;
  1458. // this is a special case for when a style() call
  1459. // directly follows an animate() call (but not inside of an animate() call)
  1460. if (!timings && timeline.getCurrentStyleProperties().length) {
  1461. timeline.forwardFrame();
  1462. }
  1463. var easing = (timings && timings.easing) || ast.easing;
  1464. if (ast.isEmptyStep) {
  1465. timeline.applyEmptyStep(easing);
  1466. }
  1467. else {
  1468. timeline.setStyles(ast.styles, easing, context.errors, context.options);
  1469. }
  1470. context.previousNode = ast;
  1471. };
  1472. AnimationTimelineBuilderVisitor.prototype.visitKeyframes = function (ast, context) {
  1473. var currentAnimateTimings = context.currentAnimateTimings;
  1474. var startTime = (context.currentTimeline).duration;
  1475. var duration = currentAnimateTimings.duration;
  1476. var innerContext = context.createSubContext();
  1477. var innerTimeline = innerContext.currentTimeline;
  1478. innerTimeline.easing = currentAnimateTimings.easing;
  1479. ast.styles.forEach(function (step) {
  1480. var offset = step.offset || 0;
  1481. innerTimeline.forwardTime(offset * duration);
  1482. innerTimeline.setStyles(step.styles, step.easing, context.errors, context.options);
  1483. innerTimeline.applyStylesToKeyframe();
  1484. });
  1485. // this will ensure that the parent timeline gets all the styles from
  1486. // the child even if the new timeline below is not used
  1487. context.currentTimeline.mergeTimelineCollectedStyles(innerTimeline);
  1488. // we do this because the window between this timeline and the sub timeline
  1489. // should ensure that the styles within are exactly the same as they were before
  1490. context.transformIntoNewTimeline(startTime + duration);
  1491. context.previousNode = ast;
  1492. };
  1493. AnimationTimelineBuilderVisitor.prototype.visitQuery = function (ast, context) {
  1494. var _this = this;
  1495. // in the event that the first step before this is a style step we need
  1496. // to ensure the styles are applied before the children are animated
  1497. var startTime = context.currentTimeline.currentTime;
  1498. var options = (ast.options || {});
  1499. var delay = options.delay ? resolveTimingValue(options.delay) : 0;
  1500. if (delay && (context.previousNode.type === 6 /* Style */ ||
  1501. (startTime == 0 && context.currentTimeline.getCurrentStyleProperties().length))) {
  1502. context.currentTimeline.snapshotCurrentStyles();
  1503. context.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
  1504. }
  1505. var furthestTime = startTime;
  1506. var elms = context.invokeQuery(ast.selector, ast.originalSelector, ast.limit, ast.includeSelf, options.optional ? true : false, context.errors);
  1507. context.currentQueryTotal = elms.length;
  1508. var sameElementTimeline = null;
  1509. elms.forEach(function (element, i) {
  1510. context.currentQueryIndex = i;
  1511. var innerContext = context.createSubContext(ast.options, element);
  1512. if (delay) {
  1513. innerContext.delayNextStep(delay);
  1514. }
  1515. if (element === context.element) {
  1516. sameElementTimeline = innerContext.currentTimeline;
  1517. }
  1518. visitDslNode(_this, ast.animation, innerContext);
  1519. // this is here just incase the inner steps only contain or end
  1520. // with a style() call (which is here to signal that this is a preparatory
  1521. // call to style an element before it is animated again)
  1522. innerContext.currentTimeline.applyStylesToKeyframe();
  1523. var endTime = innerContext.currentTimeline.currentTime;
  1524. furthestTime = Math.max(furthestTime, endTime);
  1525. });
  1526. context.currentQueryIndex = 0;
  1527. context.currentQueryTotal = 0;
  1528. context.transformIntoNewTimeline(furthestTime);
  1529. if (sameElementTimeline) {
  1530. context.currentTimeline.mergeTimelineCollectedStyles(sameElementTimeline);
  1531. context.currentTimeline.snapshotCurrentStyles();
  1532. }
  1533. context.previousNode = ast;
  1534. };
  1535. AnimationTimelineBuilderVisitor.prototype.visitStagger = function (ast, context) {
  1536. var parentContext = context.parentContext;
  1537. var tl = context.currentTimeline;
  1538. var timings = ast.timings;
  1539. var duration = Math.abs(timings.duration);
  1540. var maxTime = duration * (context.currentQueryTotal - 1);
  1541. var delay = duration * context.currentQueryIndex;
  1542. var staggerTransformer = timings.duration < 0 ? 'reverse' : timings.easing;
  1543. switch (staggerTransformer) {
  1544. case 'reverse':
  1545. delay = maxTime - delay;
  1546. break;
  1547. case 'full':
  1548. delay = parentContext.currentStaggerTime;
  1549. break;
  1550. }
  1551. var timeline = context.currentTimeline;
  1552. if (delay) {
  1553. timeline.delayNextStep(delay);
  1554. }
  1555. var startingTime = timeline.currentTime;
  1556. visitDslNode(this, ast.animation, context);
  1557. context.previousNode = ast;
  1558. // time = duration + delay
  1559. // the reason why this computation is so complex is because
  1560. // the inner timeline may either have a delay value or a stretched
  1561. // keyframe depending on if a subtimeline is not used or is used.
  1562. parentContext.currentStaggerTime =
  1563. (tl.currentTime - startingTime) + (tl.startTime - parentContext.currentTimeline.startTime);
  1564. };
  1565. return AnimationTimelineBuilderVisitor;
  1566. }());
  1567. var DEFAULT_NOOP_PREVIOUS_NODE = {};
  1568. var AnimationTimelineContext = /** @class */ (function () {
  1569. function AnimationTimelineContext(_driver, element, subInstructions, _enterClassName, _leaveClassName, errors, timelines, initialTimeline) {
  1570. this._driver = _driver;
  1571. this.element = element;
  1572. this.subInstructions = subInstructions;
  1573. this._enterClassName = _enterClassName;
  1574. this._leaveClassName = _leaveClassName;
  1575. this.errors = errors;
  1576. this.timelines = timelines;
  1577. this.parentContext = null;
  1578. this.currentAnimateTimings = null;
  1579. this.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
  1580. this.subContextCount = 0;
  1581. this.options = {};
  1582. this.currentQueryIndex = 0;
  1583. this.currentQueryTotal = 0;
  1584. this.currentStaggerTime = 0;
  1585. this.currentTimeline = initialTimeline || new TimelineBuilder(this._driver, element, 0);
  1586. timelines.push(this.currentTimeline);
  1587. }
  1588. Object.defineProperty(AnimationTimelineContext.prototype, "params", {
  1589. get: function () { return this.options.params; },
  1590. enumerable: true,
  1591. configurable: true
  1592. });
  1593. AnimationTimelineContext.prototype.updateOptions = function (options, skipIfExists) {
  1594. var _this = this;
  1595. if (!options)
  1596. return;
  1597. var newOptions = options;
  1598. var optionsToUpdate = this.options;
  1599. // NOTE: this will get patched up when other animation methods support duration overrides
  1600. if (newOptions.duration != null) {
  1601. optionsToUpdate.duration = resolveTimingValue(newOptions.duration);
  1602. }
  1603. if (newOptions.delay != null) {
  1604. optionsToUpdate.delay = resolveTimingValue(newOptions.delay);
  1605. }
  1606. var newParams = newOptions.params;
  1607. if (newParams) {
  1608. var paramsToUpdate_1 = optionsToUpdate.params;
  1609. if (!paramsToUpdate_1) {
  1610. paramsToUpdate_1 = this.options.params = {};
  1611. }
  1612. Object.keys(newParams).forEach(function (name) {
  1613. if (!skipIfExists || !paramsToUpdate_1.hasOwnProperty(name)) {
  1614. paramsToUpdate_1[name] = interpolateParams(newParams[name], paramsToUpdate_1, _this.errors);
  1615. }
  1616. });
  1617. }
  1618. };
  1619. AnimationTimelineContext.prototype._copyOptions = function () {
  1620. var options = {};
  1621. if (this.options) {
  1622. var oldParams_1 = this.options.params;
  1623. if (oldParams_1) {
  1624. var params_1 = options['params'] = {};
  1625. Object.keys(oldParams_1).forEach(function (name) { params_1[name] = oldParams_1[name]; });
  1626. }
  1627. }
  1628. return options;
  1629. };
  1630. AnimationTimelineContext.prototype.createSubContext = function (options, element, newTime) {
  1631. if (options === void 0) { options = null; }
  1632. var target = element || this.element;
  1633. var context = new AnimationTimelineContext(this._driver, target, this.subInstructions, this._enterClassName, this._leaveClassName, this.errors, this.timelines, this.currentTimeline.fork(target, newTime || 0));
  1634. context.previousNode = this.previousNode;
  1635. context.currentAnimateTimings = this.currentAnimateTimings;
  1636. context.options = this._copyOptions();
  1637. context.updateOptions(options);
  1638. context.currentQueryIndex = this.currentQueryIndex;
  1639. context.currentQueryTotal = this.currentQueryTotal;
  1640. context.parentContext = this;
  1641. this.subContextCount++;
  1642. return context;
  1643. };
  1644. AnimationTimelineContext.prototype.transformIntoNewTimeline = function (newTime) {
  1645. this.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
  1646. this.currentTimeline = this.currentTimeline.fork(this.element, newTime);
  1647. this.timelines.push(this.currentTimeline);
  1648. return this.currentTimeline;
  1649. };
  1650. AnimationTimelineContext.prototype.appendInstructionToTimeline = function (instruction, duration, delay) {
  1651. var updatedTimings = {
  1652. duration: duration != null ? duration : instruction.duration,
  1653. delay: this.currentTimeline.currentTime + (delay != null ? delay : 0) + instruction.delay,
  1654. easing: ''
  1655. };
  1656. var builder = new SubTimelineBuilder(this._driver, instruction.element, instruction.keyframes, instruction.preStyleProps, instruction.postStyleProps, updatedTimings, instruction.stretchStartingKeyframe);
  1657. this.timelines.push(builder);
  1658. return updatedTimings;
  1659. };
  1660. AnimationTimelineContext.prototype.incrementTime = function (time) {
  1661. this.currentTimeline.forwardTime(this.currentTimeline.duration + time);
  1662. };
  1663. AnimationTimelineContext.prototype.delayNextStep = function (delay) {
  1664. // negative delays are not yet supported
  1665. if (delay > 0) {
  1666. this.currentTimeline.delayNextStep(delay);
  1667. }
  1668. };
  1669. AnimationTimelineContext.prototype.invokeQuery = function (selector, originalSelector, limit, includeSelf, optional, errors) {
  1670. var results = [];
  1671. if (includeSelf) {
  1672. results.push(this.element);
  1673. }
  1674. if (selector.length > 0) { // if :self is only used then the selector is empty
  1675. selector = selector.replace(ENTER_TOKEN_REGEX, '.' + this._enterClassName);
  1676. selector = selector.replace(LEAVE_TOKEN_REGEX, '.' + this._leaveClassName);
  1677. var multi = limit != 1;
  1678. var elements = this._driver.query(this.element, selector, multi);
  1679. if (limit !== 0) {
  1680. elements = limit < 0 ? elements.slice(elements.length + limit, elements.length) :
  1681. elements.slice(0, limit);
  1682. }
  1683. results.push.apply(results, __spread(elements));
  1684. }
  1685. if (!optional && results.length == 0) {
  1686. errors.push("`query(\"" + originalSelector + "\")` returned zero elements. (Use `query(\"" + originalSelector + "\", { optional: true })` if you wish to allow this.)");
  1687. }
  1688. return results;
  1689. };
  1690. return AnimationTimelineContext;
  1691. }());
  1692. var TimelineBuilder = /** @class */ (function () {
  1693. function TimelineBuilder(_driver, element, startTime, _elementTimelineStylesLookup) {
  1694. this._driver = _driver;
  1695. this.element = element;
  1696. this.startTime = startTime;
  1697. this._elementTimelineStylesLookup = _elementTimelineStylesLookup;
  1698. this.duration = 0;
  1699. this._previousKeyframe = {};
  1700. this._currentKeyframe = {};
  1701. this._keyframes = new Map();
  1702. this._styleSummary = {};
  1703. this._pendingStyles = {};
  1704. this._backFill = {};
  1705. this._currentEmptyStepKeyframe = null;
  1706. if (!this._elementTimelineStylesLookup) {
  1707. this._elementTimelineStylesLookup = new Map();
  1708. }
  1709. this._localTimelineStyles = Object.create(this._backFill, {});
  1710. this._globalTimelineStyles = this._elementTimelineStylesLookup.get(element);
  1711. if (!this._globalTimelineStyles) {
  1712. this._globalTimelineStyles = this._localTimelineStyles;
  1713. this._elementTimelineStylesLookup.set(element, this._localTimelineStyles);
  1714. }
  1715. this._loadKeyframe();
  1716. }
  1717. TimelineBuilder.prototype.containsAnimation = function () {
  1718. switch (this._keyframes.size) {
  1719. case 0:
  1720. return false;
  1721. case 1:
  1722. return this.getCurrentStyleProperties().length > 0;
  1723. default:
  1724. return true;
  1725. }
  1726. };
  1727. TimelineBuilder.prototype.getCurrentStyleProperties = function () { return Object.keys(this._currentKeyframe); };
  1728. Object.defineProperty(TimelineBuilder.prototype, "currentTime", {
  1729. get: function () { return this.startTime + this.duration; },
  1730. enumerable: true,
  1731. configurable: true
  1732. });
  1733. TimelineBuilder.prototype.delayNextStep = function (delay) {
  1734. // in the event that a style() step is placed right before a stagger()
  1735. // and that style() step is the very first style() value in the animation
  1736. // then we need to make a copy of the keyframe [0, copy, 1] so that the delay
  1737. // properly applies the style() values to work with the stagger...
  1738. var hasPreStyleStep = this._keyframes.size == 1 && Object.keys(this._pendingStyles).length;
  1739. if (this.duration || hasPreStyleStep) {
  1740. this.forwardTime(this.currentTime + delay);
  1741. if (hasPreStyleStep) {
  1742. this.snapshotCurrentStyles();
  1743. }
  1744. }
  1745. else {
  1746. this.startTime += delay;
  1747. }
  1748. };
  1749. TimelineBuilder.prototype.fork = function (element, currentTime) {
  1750. this.applyStylesToKeyframe();
  1751. return new TimelineBuilder(this._driver, element, currentTime || this.currentTime, this._elementTimelineStylesLookup);
  1752. };
  1753. TimelineBuilder.prototype._loadKeyframe = function () {
  1754. if (this._currentKeyframe) {
  1755. this._previousKeyframe = this._currentKeyframe;
  1756. }
  1757. this._currentKeyframe = this._keyframes.get(this.duration);
  1758. if (!this._currentKeyframe) {
  1759. this._currentKeyframe = Object.create(this._backFill, {});
  1760. this._keyframes.set(this.duration, this._currentKeyframe);
  1761. }
  1762. };
  1763. TimelineBuilder.prototype.forwardFrame = function () {
  1764. this.duration += ONE_FRAME_IN_MILLISECONDS;
  1765. this._loadKeyframe();
  1766. };
  1767. TimelineBuilder.prototype.forwardTime = function (time) {
  1768. this.applyStylesToKeyframe();
  1769. this.duration = time;
  1770. this._loadKeyframe();
  1771. };
  1772. TimelineBuilder.prototype._updateStyle = function (prop, value) {
  1773. this._localTimelineStyles[prop] = value;
  1774. this._globalTimelineStyles[prop] = value;
  1775. this._styleSummary[prop] = { time: this.currentTime, value: value };
  1776. };
  1777. TimelineBuilder.prototype.allowOnlyTimelineStyles = function () { return this._currentEmptyStepKeyframe !== this._currentKeyframe; };
  1778. TimelineBuilder.prototype.applyEmptyStep = function (easing) {
  1779. var _this = this;
  1780. if (easing) {
  1781. this._previousKeyframe['easing'] = easing;
  1782. }
  1783. // special case for animate(duration):
  1784. // all missing styles are filled with a `*` value then
  1785. // if any destination styles are filled in later on the same
  1786. // keyframe then they will override the overridden styles
  1787. // We use `_globalTimelineStyles` here because there may be
  1788. // styles in previous keyframes that are not present in this timeline
  1789. Object.keys(this._globalTimelineStyles).forEach(function (prop) {
  1790. _this._backFill[prop] = _this._globalTimelineStyles[prop] || animations.AUTO_STYLE;
  1791. _this._currentKeyframe[prop] = animations.AUTO_STYLE;
  1792. });
  1793. this._currentEmptyStepKeyframe = this._currentKeyframe;
  1794. };
  1795. TimelineBuilder.prototype.setStyles = function (input, easing, errors, options) {
  1796. var _this = this;
  1797. if (easing) {
  1798. this._previousKeyframe['easing'] = easing;
  1799. }
  1800. var params = (options && options.params) || {};
  1801. var styles = flattenStyles(input, this._globalTimelineStyles);
  1802. Object.keys(styles).forEach(function (prop) {
  1803. var val = interpolateParams(styles[prop], params, errors);
  1804. _this._pendingStyles[prop] = val;
  1805. if (!_this._localTimelineStyles.hasOwnProperty(prop)) {
  1806. _this._backFill[prop] = _this._globalTimelineStyles.hasOwnProperty(prop) ?
  1807. _this._globalTimelineStyles[prop] :
  1808. animations.AUTO_STYLE;
  1809. }
  1810. _this._updateStyle(prop, val);
  1811. });
  1812. };
  1813. TimelineBuilder.prototype.applyStylesToKeyframe = function () {
  1814. var _this = this;
  1815. var styles = this._pendingStyles;
  1816. var props = Object.keys(styles);
  1817. if (props.length == 0)
  1818. return;
  1819. this._pendingStyles = {};
  1820. props.forEach(function (prop) {
  1821. var val = styles[prop];
  1822. _this._currentKeyframe[prop] = val;
  1823. });
  1824. Object.keys(this._localTimelineStyles).forEach(function (prop) {
  1825. if (!_this._currentKeyframe.hasOwnProperty(prop)) {
  1826. _this._currentKeyframe[prop] = _this._localTimelineStyles[prop];
  1827. }
  1828. });
  1829. };
  1830. TimelineBuilder.prototype.snapshotCurrentStyles = function () {
  1831. var _this = this;
  1832. Object.keys(this._localTimelineStyles).forEach(function (prop) {
  1833. var val = _this._localTimelineStyles[prop];
  1834. _this._pendingStyles[prop] = val;
  1835. _this._updateStyle(prop, val);
  1836. });
  1837. };
  1838. TimelineBuilder.prototype.getFinalKeyframe = function () { return this._keyframes.get(this.duration); };
  1839. Object.defineProperty(TimelineBuilder.prototype, "properties", {
  1840. get: function () {
  1841. var properties = [];
  1842. for (var prop in this._currentKeyframe) {
  1843. properties.push(prop);
  1844. }
  1845. return properties;
  1846. },
  1847. enumerable: true,
  1848. configurable: true
  1849. });
  1850. TimelineBuilder.prototype.mergeTimelineCollectedStyles = function (timeline) {
  1851. var _this = this;
  1852. Object.keys(timeline._styleSummary).forEach(function (prop) {
  1853. var details0 = _this._styleSummary[prop];
  1854. var details1 = timeline._styleSummary[prop];
  1855. if (!details0 || details1.time > details0.time) {
  1856. _this._updateStyle(prop, details1.value);
  1857. }
  1858. });
  1859. };
  1860. TimelineBuilder.prototype.buildKeyframes = function () {
  1861. var _this = this;
  1862. this.applyStylesToKeyframe();
  1863. var preStyleProps = new Set();
  1864. var postStyleProps = new Set();
  1865. var isEmpty = this._keyframes.size === 1 && this.duration === 0;
  1866. var finalKeyframes = [];
  1867. this._keyframes.forEach(function (keyframe, time) {
  1868. var finalKeyframe = copyStyles(keyframe, true);
  1869. Object.keys(finalKeyframe).forEach(function (prop) {
  1870. var value = finalKeyframe[prop];
  1871. if (value == animations.ɵPRE_STYLE) {
  1872. preStyleProps.add(prop);
  1873. }
  1874. else if (value == animations.AUTO_STYLE) {
  1875. postStyleProps.add(prop);
  1876. }
  1877. });
  1878. if (!isEmpty) {
  1879. finalKeyframe['offset'] = time / _this.duration;
  1880. }
  1881. finalKeyframes.push(finalKeyframe);
  1882. });
  1883. var preProps = preStyleProps.size ? iteratorToArray(preStyleProps.values()) : [];
  1884. var postProps = postStyleProps.size ? iteratorToArray(postStyleProps.values()) : [];
  1885. // special case for a 0-second animation (which is designed just to place styles onscreen)
  1886. if (isEmpty) {
  1887. var kf0 = finalKeyframes[0];
  1888. var kf1 = copyObj(kf0);
  1889. kf0['offset'] = 0;
  1890. kf1['offset'] = 1;
  1891. finalKeyframes = [kf0, kf1];
  1892. }
  1893. return createTimelineInstruction(this.element, finalKeyframes, preProps, postProps, this.duration, this.startTime, this.easing, false);
  1894. };
  1895. return TimelineBuilder;
  1896. }());
  1897. var SubTimelineBuilder = /** @class */ (function (_super) {
  1898. __extends(SubTimelineBuilder, _super);
  1899. function SubTimelineBuilder(driver, element, keyframes, preStyleProps, postStyleProps, timings, _stretchStartingKeyframe) {
  1900. if (_stretchStartingKeyframe === void 0) { _stretchStartingKeyframe = false; }
  1901. var _this = _super.call(this, driver, element, timings.delay) || this;
  1902. _this.element = element;
  1903. _this.keyframes = keyframes;
  1904. _this.preStyleProps = preStyleProps;
  1905. _this.postStyleProps = postStyleProps;
  1906. _this._stretchStartingKeyframe = _stretchStartingKeyframe;
  1907. _this.timings = { duration: timings.duration, delay: timings.delay, easing: timings.easing };
  1908. return _this;
  1909. }
  1910. SubTimelineBuilder.prototype.containsAnimation = function () { return this.keyframes.length > 1; };
  1911. SubTimelineBuilder.prototype.buildKeyframes = function () {
  1912. var keyframes = this.keyframes;
  1913. var _a = this.timings, delay = _a.delay, duration = _a.duration, easing = _a.easing;
  1914. if (this._stretchStartingKeyframe && delay) {
  1915. var newKeyframes = [];
  1916. var totalTime = duration + delay;
  1917. var startingGap = delay / totalTime;
  1918. // the original starting keyframe now starts once the delay is done
  1919. var newFirstKeyframe = copyStyles(keyframes[0], false);
  1920. newFirstKeyframe['offset'] = 0;
  1921. newKeyframes.push(newFirstKeyframe);
  1922. var oldFirstKeyframe = copyStyles(keyframes[0], false);
  1923. oldFirstKeyframe['offset'] = roundOffset(startingGap);
  1924. newKeyframes.push(oldFirstKeyframe);
  1925. /*
  1926. When the keyframe is stretched then it means that the delay before the animation
  1927. starts is gone. Instead the first keyframe is placed at the start of the animation
  1928. and it is then copied to where it starts when the original delay is over. This basically
  1929. means nothing animates during that delay, but the styles are still renderered. For this
  1930. to work the original offset values that exist in the original keyframes must be "warped"
  1931. so that they can take the new keyframe + delay into account.
  1932. delay=1000, duration=1000, keyframes = 0 .5 1
  1933. turns into
  1934. delay=0, duration=2000, keyframes = 0 .33 .66 1
  1935. */
  1936. // offsets between 1 ... n -1 are all warped by the keyframe stretch
  1937. var limit = keyframes.length - 1;
  1938. for (var i = 1; i <= limit; i++) {
  1939. var kf = copyStyles(keyframes[i], false);
  1940. var oldOffset = kf['offset'];
  1941. var timeAtKeyframe = delay + oldOffset * duration;
  1942. kf['offset'] = roundOffset(timeAtKeyframe / totalTime);
  1943. newKeyframes.push(kf);
  1944. }
  1945. // the new starting keyframe should be added at the start
  1946. duration = totalTime;
  1947. delay = 0;
  1948. easing = '';
  1949. keyframes = newKeyframes;
  1950. }
  1951. return createTimelineInstruction(this.element, keyframes, this.preStyleProps, this.postStyleProps, duration, delay, easing, true);
  1952. };
  1953. return SubTimelineBuilder;
  1954. }(TimelineBuilder));
  1955. function roundOffset(offset, decimalPoints) {
  1956. if (decimalPoints === void 0) { decimalPoints = 3; }
  1957. var mult = Math.pow(10, decimalPoints - 1);
  1958. return Math.round(offset * mult) / mult;
  1959. }
  1960. function flattenStyles(input, allStyles) {
  1961. var styles = {};
  1962. var allProperties;
  1963. input.forEach(function (token) {
  1964. if (token === '*') {
  1965. allProperties = allProperties || Object.keys(allStyles);
  1966. allProperties.forEach(function (prop) { styles[prop] = animations.AUTO_STYLE; });
  1967. }
  1968. else {
  1969. copyStyles(token, false, styles);
  1970. }
  1971. });
  1972. return styles;
  1973. }
  1974. var Animation = /** @class */ (function () {
  1975. function Animation(_driver, input) {
  1976. this._driver = _driver;
  1977. var errors = [];
  1978. var ast = buildAnimationAst(_driver, input, errors);
  1979. if (errors.length) {
  1980. var errorMessage = "animation validation failed:\n" + errors.join("\n");
  1981. throw new Error(errorMessage);
  1982. }
  1983. this._animationAst = ast;
  1984. }
  1985. Animation.prototype.buildTimelines = function (element, startingStyles, destinationStyles, options, subInstructions) {
  1986. var start = Array.isArray(startingStyles) ? normalizeStyles(startingStyles) :
  1987. startingStyles;
  1988. var dest = Array.isArray(destinationStyles) ? normalizeStyles(destinationStyles) :
  1989. destinationStyles;
  1990. var errors = [];
  1991. subInstructions = subInstructions || new ElementInstructionMap();
  1992. var result = buildAnimationTimelines(this._driver, element, this._animationAst, ENTER_CLASSNAME, LEAVE_CLASSNAME, start, dest, options, subInstructions, errors);
  1993. if (errors.length) {
  1994. var errorMessage = "animation building failed:\n" + errors.join("\n");
  1995. throw new Error(errorMessage);
  1996. }
  1997. return result;
  1998. };
  1999. return Animation;
  2000. }());
  2001. /**
  2002. * @license
  2003. * Copyright Google Inc. All Rights Reserved.
  2004. *
  2005. * Use of this source code is governed by an MIT-style license that can be
  2006. * found in the LICENSE file at https://angular.io/license
  2007. */
  2008. /**
  2009. * @publicApi
  2010. */
  2011. var AnimationStyleNormalizer = /** @class */ (function () {
  2012. function AnimationStyleNormalizer() {
  2013. }
  2014. return AnimationStyleNormalizer;
  2015. }());
  2016. /**
  2017. * @publicApi
  2018. */
  2019. var NoopAnimationStyleNormalizer = /** @class */ (function () {
  2020. function NoopAnimationStyleNormalizer() {
  2021. }
  2022. NoopAnimationStyleNormalizer.prototype.normalizePropertyName = function (propertyName, errors) { return propertyName; };
  2023. NoopAnimationStyleNormalizer.prototype.normalizeStyleValue = function (userProvidedProperty, normalizedProperty, value, errors) {
  2024. return value;
  2025. };
  2026. return NoopAnimationStyleNormalizer;
  2027. }());
  2028. var WebAnimationsStyleNormalizer = /** @class */ (function (_super) {
  2029. __extends(WebAnimationsStyleNormalizer, _super);
  2030. function WebAnimationsStyleNormalizer() {
  2031. return _super !== null && _super.apply(this, arguments) || this;
  2032. }
  2033. WebAnimationsStyleNormalizer.prototype.normalizePropertyName = function (propertyName, errors) {
  2034. return dashCaseToCamelCase(propertyName);
  2035. };
  2036. WebAnimationsStyleNormalizer.prototype.normalizeStyleValue = function (userProvidedProperty, normalizedProperty, value, errors) {
  2037. var unit = '';
  2038. var strVal = value.toString().trim();
  2039. if (DIMENSIONAL_PROP_MAP[normalizedProperty] && value !== 0 && value !== '0') {
  2040. if (typeof value === 'number') {
  2041. unit = 'px';
  2042. }
  2043. else {
  2044. var valAndSuffixMatch = value.match(/^[+-]?[\d\.]+([a-z]*)$/);
  2045. if (valAndSuffixMatch && valAndSuffixMatch[1].length == 0) {
  2046. errors.push("Please provide a CSS unit value for " + userProvidedProperty + ":" + value);
  2047. }
  2048. }
  2049. }
  2050. return strVal + unit;
  2051. };
  2052. return WebAnimationsStyleNormalizer;
  2053. }(AnimationStyleNormalizer));
  2054. var ɵ0 = function () { return 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'
  2055. .split(',')); };
  2056. var DIMENSIONAL_PROP_MAP = (ɵ0)();
  2057. function makeBooleanMap(keys) {
  2058. var map = {};
  2059. keys.forEach(function (key) { return map[key] = true; });
  2060. return map;
  2061. }
  2062. function createTransitionInstruction(element, triggerName, fromState, toState, isRemovalTransition, fromStyles, toStyles, timelines, queriedElements, preStyleProps, postStyleProps, totalTime, errors) {
  2063. return {
  2064. type: 0 /* TransitionAnimation */,
  2065. element: element,
  2066. triggerName: triggerName,
  2067. isRemovalTransition: isRemovalTransition,
  2068. fromState: fromState,
  2069. fromStyles: fromStyles,
  2070. toState: toState,
  2071. toStyles: toStyles,
  2072. timelines: timelines,
  2073. queriedElements: queriedElements,
  2074. preStyleProps: preStyleProps,
  2075. postStyleProps: postStyleProps,
  2076. totalTime: totalTime,
  2077. errors: errors
  2078. };
  2079. }
  2080. var EMPTY_OBJECT = {};
  2081. var AnimationTransitionFactory = /** @class */ (function () {
  2082. function AnimationTransitionFactory(_triggerName, ast, _stateStyles) {
  2083. this._triggerName = _triggerName;
  2084. this.ast = ast;
  2085. this._stateStyles = _stateStyles;
  2086. }
  2087. AnimationTransitionFactory.prototype.match = function (currentState, nextState, element, params) {
  2088. return oneOrMoreTransitionsMatch(this.ast.matchers, currentState, nextState, element, params);
  2089. };
  2090. AnimationTransitionFactory.prototype.buildStyles = function (stateName, params, errors) {
  2091. var backupStateStyler = this._stateStyles['*'];
  2092. var stateStyler = this._stateStyles[stateName];
  2093. var backupStyles = backupStateStyler ? backupStateStyler.buildStyles(params, errors) : {};
  2094. return stateStyler ? stateStyler.buildStyles(params, errors) : backupStyles;
  2095. };
  2096. AnimationTransitionFactory.prototype.build = function (driver, element, currentState, nextState, enterClassName, leaveClassName, currentOptions, nextOptions, subInstructions, skipAstBuild) {
  2097. var errors = [];
  2098. var transitionAnimationParams = this.ast.options && this.ast.options.params || EMPTY_OBJECT;
  2099. var currentAnimationParams = currentOptions && currentOptions.params || EMPTY_OBJECT;
  2100. var currentStateStyles = this.buildStyles(currentState, currentAnimationParams, errors);
  2101. var nextAnimationParams = nextOptions && nextOptions.params || EMPTY_OBJECT;
  2102. var nextStateStyles = this.buildStyles(nextState, nextAnimationParams, errors);
  2103. var queriedElements = new Set();
  2104. var preStyleMap = new Map();
  2105. var postStyleMap = new Map();
  2106. var isRemoval = nextState === 'void';
  2107. var animationOptions = { params: __assign({}, transitionAnimationParams, nextAnimationParams) };
  2108. var timelines = skipAstBuild ? [] : buildAnimationTimelines(driver, element, this.ast.animation, enterClassName, leaveClassName, currentStateStyles, nextStateStyles, animationOptions, subInstructions, errors);
  2109. var totalTime = 0;
  2110. timelines.forEach(function (tl) { totalTime = Math.max(tl.duration + tl.delay, totalTime); });
  2111. if (errors.length) {
  2112. return createTransitionInstruction(element, this._triggerName, currentState, nextState, isRemoval, currentStateStyles, nextStateStyles, [], [], preStyleMap, postStyleMap, totalTime, errors);
  2113. }
  2114. timelines.forEach(function (tl) {
  2115. var elm = tl.element;
  2116. var preProps = getOrSetAsInMap(preStyleMap, elm, {});
  2117. tl.preStyleProps.forEach(function (prop) { return preProps[prop] = true; });
  2118. var postProps = getOrSetAsInMap(postStyleMap, elm, {});
  2119. tl.postStyleProps.forEach(function (prop) { return postProps[prop] = true; });
  2120. if (elm !== element) {
  2121. queriedElements.add(elm);
  2122. }
  2123. });
  2124. var queriedElementsList = iteratorToArray(queriedElements.values());
  2125. return createTransitionInstruction(element, this._triggerName, currentState, nextState, isRemoval, currentStateStyles, nextStateStyles, timelines, queriedElementsList, preStyleMap, postStyleMap, totalTime);
  2126. };
  2127. return AnimationTransitionFactory;
  2128. }());
  2129. function oneOrMoreTransitionsMatch(matchFns, currentState, nextState, element, params) {
  2130. return matchFns.some(function (fn) { return fn(currentState, nextState, element, params); });
  2131. }
  2132. var AnimationStateStyles = /** @class */ (function () {
  2133. function AnimationStateStyles(styles, defaultParams) {
  2134. this.styles = styles;
  2135. this.defaultParams = defaultParams;
  2136. }
  2137. AnimationStateStyles.prototype.buildStyles = function (params, errors) {
  2138. var finalStyles = {};
  2139. var combinedParams = copyObj(this.defaultParams);
  2140. Object.keys(params).forEach(function (key) {
  2141. var value = params[key];
  2142. if (value != null) {
  2143. combinedParams[key] = value;
  2144. }
  2145. });
  2146. this.styles.styles.forEach(function (value) {
  2147. if (typeof value !== 'string') {
  2148. var styleObj_1 = value;
  2149. Object.keys(styleObj_1).forEach(function (prop) {
  2150. var val = styleObj_1[prop];
  2151. if (val.length > 1) {
  2152. val = interpolateParams(val, combinedParams, errors);
  2153. }
  2154. finalStyles[prop] = val;
  2155. });
  2156. }
  2157. });
  2158. return finalStyles;
  2159. };
  2160. return AnimationStateStyles;
  2161. }());
  2162. /**
  2163. * @publicApi
  2164. */
  2165. function buildTrigger(name, ast) {
  2166. return new AnimationTrigger(name, ast);
  2167. }
  2168. /**
  2169. * @publicApi
  2170. */
  2171. var AnimationTrigger = /** @class */ (function () {
  2172. function AnimationTrigger(name, ast) {
  2173. var _this = this;
  2174. this.name = name;
  2175. this.ast = ast;
  2176. this.transitionFactories = [];
  2177. this.states = {};
  2178. ast.states.forEach(function (ast) {
  2179. var defaultParams = (ast.options && ast.options.params) || {};
  2180. _this.states[ast.name] = new AnimationStateStyles(ast.style, defaultParams);
  2181. });
  2182. balanceProperties(this.states, 'true', '1');
  2183. balanceProperties(this.states, 'false', '0');
  2184. ast.transitions.forEach(function (ast) {
  2185. _this.transitionFactories.push(new AnimationTransitionFactory(name, ast, _this.states));
  2186. });
  2187. this.fallbackTransition = createFallbackTransition(name, this.states);
  2188. }
  2189. Object.defineProperty(AnimationTrigger.prototype, "containsQueries", {
  2190. get: function () { return this.ast.queryCount > 0; },
  2191. enumerable: true,
  2192. configurable: true
  2193. });
  2194. AnimationTrigger.prototype.matchTransition = function (currentState, nextState, element, params) {
  2195. var entry = this.transitionFactories.find(function (f) { return f.match(currentState, nextState, element, params); });
  2196. return entry || null;
  2197. };
  2198. AnimationTrigger.prototype.matchStyles = function (currentState, params, errors) {
  2199. return this.fallbackTransition.buildStyles(currentState, params, errors);
  2200. };
  2201. return AnimationTrigger;
  2202. }());
  2203. function createFallbackTransition(triggerName, states) {
  2204. var matchers = [function (fromState, toState) { return true; }];
  2205. var animation = { type: 2 /* Sequence */, steps: [], options: null };
  2206. var transition = {
  2207. type: 1 /* Transition */,
  2208. animation: animation,
  2209. matchers: matchers,
  2210. options: null,
  2211. queryCount: 0,
  2212. depCount: 0
  2213. };
  2214. return new AnimationTransitionFactory(triggerName, transition, states);
  2215. }
  2216. function balanceProperties(obj, key1, key2) {
  2217. if (obj.hasOwnProperty(key1)) {
  2218. if (!obj.hasOwnProperty(key2)) {
  2219. obj[key2] = obj[key1];
  2220. }
  2221. }
  2222. else if (obj.hasOwnProperty(key2)) {
  2223. obj[key1] = obj[key2];
  2224. }
  2225. }
  2226. /**
  2227. * @license
  2228. * Copyright Google Inc. All Rights Reserved.
  2229. *
  2230. * Use of this source code is governed by an MIT-style license that can be
  2231. * found in the LICENSE file at https://angular.io/license
  2232. */
  2233. var EMPTY_INSTRUCTION_MAP = new ElementInstructionMap();
  2234. var TimelineAnimationEngine = /** @class */ (function () {
  2235. function TimelineAnimationEngine(bodyNode, _driver, _normalizer) {
  2236. this.bodyNode = bodyNode;
  2237. this._driver = _driver;
  2238. this._normalizer = _normalizer;
  2239. this._animations = {};
  2240. this._playersById = {};
  2241. this.players = [];
  2242. }
  2243. TimelineAnimationEngine.prototype.register = function (id, metadata) {
  2244. var errors = [];
  2245. var ast = buildAnimationAst(this._driver, metadata, errors);
  2246. if (errors.length) {
  2247. throw new Error("Unable to build the animation due to the following errors: " + errors.join("\n"));
  2248. }
  2249. else {
  2250. this._animations[id] = ast;
  2251. }
  2252. };
  2253. TimelineAnimationEngine.prototype._buildPlayer = function (i, preStyles, postStyles) {
  2254. var element = i.element;
  2255. var keyframes = normalizeKeyframes(this._driver, this._normalizer, element, i.keyframes, preStyles, postStyles);
  2256. return this._driver.animate(element, keyframes, i.duration, i.delay, i.easing, [], true);
  2257. };
  2258. TimelineAnimationEngine.prototype.create = function (id, element, options) {
  2259. var _this = this;
  2260. if (options === void 0) { options = {}; }
  2261. var errors = [];
  2262. var ast = this._animations[id];
  2263. var instructions;
  2264. var autoStylesMap = new Map();
  2265. if (ast) {
  2266. instructions = buildAnimationTimelines(this._driver, element, ast, ENTER_CLASSNAME, LEAVE_CLASSNAME, {}, {}, options, EMPTY_INSTRUCTION_MAP, errors);
  2267. instructions.forEach(function (inst) {
  2268. var styles = getOrSetAsInMap(autoStylesMap, inst.element, {});
  2269. inst.postStyleProps.forEach(function (prop) { return styles[prop] = null; });
  2270. });
  2271. }
  2272. else {
  2273. errors.push('The requested animation doesn\'t exist or has already been destroyed');
  2274. instructions = [];
  2275. }
  2276. if (errors.length) {
  2277. throw new Error("Unable to create the animation due to the following errors: " + errors.join("\n"));
  2278. }
  2279. autoStylesMap.forEach(function (styles, element) {
  2280. Object.keys(styles).forEach(function (prop) { styles[prop] = _this._driver.computeStyle(element, prop, animations.AUTO_STYLE); });
  2281. });
  2282. var players = instructions.map(function (i) {
  2283. var styles = autoStylesMap.get(i.element);
  2284. return _this._buildPlayer(i, {}, styles);
  2285. });
  2286. var player = optimizeGroupPlayer(players);
  2287. this._playersById[id] = player;
  2288. player.onDestroy(function () { return _this.destroy(id); });
  2289. this.players.push(player);
  2290. return player;
  2291. };
  2292. TimelineAnimationEngine.prototype.destroy = function (id) {
  2293. var player = this._getPlayer(id);
  2294. player.destroy();
  2295. delete this._playersById[id];
  2296. var index = this.players.indexOf(player);
  2297. if (index >= 0) {
  2298. this.players.splice(index, 1);
  2299. }
  2300. };
  2301. TimelineAnimationEngine.prototype._getPlayer = function (id) {
  2302. var player = this._playersById[id];
  2303. if (!player) {
  2304. throw new Error("Unable to find the timeline player referenced by " + id);
  2305. }
  2306. return player;
  2307. };
  2308. TimelineAnimationEngine.prototype.listen = function (id, element, eventName, callback) {
  2309. // triggerName, fromState, toState are all ignored for timeline animations
  2310. var baseEvent = makeAnimationEvent(element, '', '', '');
  2311. listenOnPlayer(this._getPlayer(id), eventName, baseEvent, callback);
  2312. return function () { };
  2313. };
  2314. TimelineAnimationEngine.prototype.command = function (id, element, command, args) {
  2315. if (command == 'register') {
  2316. this.register(id, args[0]);
  2317. return;
  2318. }
  2319. if (command == 'create') {
  2320. var options = (args[0] || {});
  2321. this.create(id, element, options);
  2322. return;
  2323. }
  2324. var player = this._getPlayer(id);
  2325. switch (command) {
  2326. case 'play':
  2327. player.play();
  2328. break;
  2329. case 'pause':
  2330. player.pause();
  2331. break;
  2332. case 'reset':
  2333. player.reset();
  2334. break;
  2335. case 'restart':
  2336. player.restart();
  2337. break;
  2338. case 'finish':
  2339. player.finish();
  2340. break;
  2341. case 'init':
  2342. player.init();
  2343. break;
  2344. case 'setPosition':
  2345. player.setPosition(parseFloat(args[0]));
  2346. break;
  2347. case 'destroy':
  2348. this.destroy(id);
  2349. break;
  2350. }
  2351. };
  2352. return TimelineAnimationEngine;
  2353. }());
  2354. var QUEUED_CLASSNAME = 'ng-animate-queued';
  2355. var QUEUED_SELECTOR = '.ng-animate-queued';
  2356. var DISABLED_CLASSNAME = 'ng-animate-disabled';
  2357. var DISABLED_SELECTOR = '.ng-animate-disabled';
  2358. var STAR_CLASSNAME = 'ng-star-inserted';
  2359. var STAR_SELECTOR = '.ng-star-inserted';
  2360. var EMPTY_PLAYER_ARRAY = [];
  2361. var NULL_REMOVAL_STATE = {
  2362. namespaceId: '',
  2363. setForRemoval: false,
  2364. setForMove: false,
  2365. hasAnimation: false,
  2366. removedBeforeQueried: false
  2367. };
  2368. var NULL_REMOVED_QUERIED_STATE = {
  2369. namespaceId: '',
  2370. setForMove: false,
  2371. setForRemoval: false,
  2372. hasAnimation: false,
  2373. removedBeforeQueried: true
  2374. };
  2375. var REMOVAL_FLAG = '__ng_removed';
  2376. var StateValue = /** @class */ (function () {
  2377. function StateValue(input, namespaceId) {
  2378. if (namespaceId === void 0) { namespaceId = ''; }
  2379. this.namespaceId = namespaceId;
  2380. var isObj = input && input.hasOwnProperty('value');
  2381. var value = isObj ? input['value'] : input;
  2382. this.value = normalizeTriggerValue(value);
  2383. if (isObj) {
  2384. var options = copyObj(input);
  2385. delete options['value'];
  2386. this.options = options;
  2387. }
  2388. else {
  2389. this.options = {};
  2390. }
  2391. if (!this.options.params) {
  2392. this.options.params = {};
  2393. }
  2394. }
  2395. Object.defineProperty(StateValue.prototype, "params", {
  2396. get: function () { return this.options.params; },
  2397. enumerable: true,
  2398. configurable: true
  2399. });
  2400. StateValue.prototype.absorbOptions = function (options) {
  2401. var newParams = options.params;
  2402. if (newParams) {
  2403. var oldParams_1 = this.options.params;
  2404. Object.keys(newParams).forEach(function (prop) {
  2405. if (oldParams_1[prop] == null) {
  2406. oldParams_1[prop] = newParams[prop];
  2407. }
  2408. });
  2409. }
  2410. };
  2411. return StateValue;
  2412. }());
  2413. var VOID_VALUE = 'void';
  2414. var DEFAULT_STATE_VALUE = new StateValue(VOID_VALUE);
  2415. var AnimationTransitionNamespace = /** @class */ (function () {
  2416. function AnimationTransitionNamespace(id, hostElement, _engine) {
  2417. this.id = id;
  2418. this.hostElement = hostElement;
  2419. this._engine = _engine;
  2420. this.players = [];
  2421. this._triggers = {};
  2422. this._queue = [];
  2423. this._elementListeners = new Map();
  2424. this._hostClassName = 'ng-tns-' + id;
  2425. addClass(hostElement, this._hostClassName);
  2426. }
  2427. AnimationTransitionNamespace.prototype.listen = function (element, name, phase, callback) {
  2428. var _this = this;
  2429. if (!this._triggers.hasOwnProperty(name)) {
  2430. throw new Error("Unable to listen on the animation trigger event \"" + phase + "\" because the animation trigger \"" + name + "\" doesn't exist!");
  2431. }
  2432. if (phase == null || phase.length == 0) {
  2433. throw new Error("Unable to listen on the animation trigger \"" + name + "\" because the provided event is undefined!");
  2434. }
  2435. if (!isTriggerEventValid(phase)) {
  2436. throw new Error("The provided animation trigger event \"" + phase + "\" for the animation trigger \"" + name + "\" is not supported!");
  2437. }
  2438. var listeners = getOrSetAsInMap(this._elementListeners, element, []);
  2439. var data = { name: name, phase: phase, callback: callback };
  2440. listeners.push(data);
  2441. var triggersWithStates = getOrSetAsInMap(this._engine.statesByElement, element, {});
  2442. if (!triggersWithStates.hasOwnProperty(name)) {
  2443. addClass(element, NG_TRIGGER_CLASSNAME);
  2444. addClass(element, NG_TRIGGER_CLASSNAME + '-' + name);
  2445. triggersWithStates[name] = DEFAULT_STATE_VALUE;
  2446. }
  2447. return function () {
  2448. // the event listener is removed AFTER the flush has occurred such
  2449. // that leave animations callbacks can fire (otherwise if the node
  2450. // is removed in between then the listeners would be deregistered)
  2451. _this._engine.afterFlush(function () {
  2452. var index = listeners.indexOf(data);
  2453. if (index >= 0) {
  2454. listeners.splice(index, 1);
  2455. }
  2456. if (!_this._triggers[name]) {
  2457. delete triggersWithStates[name];
  2458. }
  2459. });
  2460. };
  2461. };
  2462. AnimationTransitionNamespace.prototype.register = function (name, ast) {
  2463. if (this._triggers[name]) {
  2464. // throw
  2465. return false;
  2466. }
  2467. else {
  2468. this._triggers[name] = ast;
  2469. return true;
  2470. }
  2471. };
  2472. AnimationTransitionNamespace.prototype._getTrigger = function (name) {
  2473. var trigger = this._triggers[name];
  2474. if (!trigger) {
  2475. throw new Error("The provided animation trigger \"" + name + "\" has not been registered!");
  2476. }
  2477. return trigger;
  2478. };
  2479. AnimationTransitionNamespace.prototype.trigger = function (element, triggerName, value, defaultToFallback) {
  2480. var _this = this;
  2481. if (defaultToFallback === void 0) { defaultToFallback = true; }
  2482. var trigger = this._getTrigger(triggerName);
  2483. var player = new TransitionAnimationPlayer(this.id, triggerName, element);
  2484. var triggersWithStates = this._engine.statesByElement.get(element);
  2485. if (!triggersWithStates) {
  2486. addClass(element, NG_TRIGGER_CLASSNAME);
  2487. addClass(element, NG_TRIGGER_CLASSNAME + '-' + triggerName);
  2488. this._engine.statesByElement.set(element, triggersWithStates = {});
  2489. }
  2490. var fromState = triggersWithStates[triggerName];
  2491. var toState = new StateValue(value, this.id);
  2492. var isObj = value && value.hasOwnProperty('value');
  2493. if (!isObj && fromState) {
  2494. toState.absorbOptions(fromState.options);
  2495. }
  2496. triggersWithStates[triggerName] = toState;
  2497. if (!fromState) {
  2498. fromState = DEFAULT_STATE_VALUE;
  2499. }
  2500. var isRemoval = toState.value === VOID_VALUE;
  2501. // normally this isn't reached by here, however, if an object expression
  2502. // is passed in then it may be a new object each time. Comparing the value
  2503. // is important since that will stay the same despite there being a new object.
  2504. // The removal arc here is special cased because the same element is triggered
  2505. // twice in the event that it contains animations on the outer/inner portions
  2506. // of the host container
  2507. if (!isRemoval && fromState.value === toState.value) {
  2508. // this means that despite the value not changing, some inner params
  2509. // have changed which means that the animation final styles need to be applied
  2510. if (!objEquals(fromState.params, toState.params)) {
  2511. var errors = [];
  2512. var fromStyles_1 = trigger.matchStyles(fromState.value, fromState.params, errors);
  2513. var toStyles_1 = trigger.matchStyles(toState.value, toState.params, errors);
  2514. if (errors.length) {
  2515. this._engine.reportError(errors);
  2516. }
  2517. else {
  2518. this._engine.afterFlush(function () {
  2519. eraseStyles(element, fromStyles_1);
  2520. setStyles(element, toStyles_1);
  2521. });
  2522. }
  2523. }
  2524. return;
  2525. }
  2526. var playersOnElement = getOrSetAsInMap(this._engine.playersByElement, element, []);
  2527. playersOnElement.forEach(function (player) {
  2528. // only remove the player if it is queued on the EXACT same trigger/namespace
  2529. // we only also deal with queued players here because if the animation has
  2530. // started then we want to keep the player alive until the flush happens
  2531. // (which is where the previousPlayers are passed into the new palyer)
  2532. if (player.namespaceId == _this.id && player.triggerName == triggerName && player.queued) {
  2533. player.destroy();
  2534. }
  2535. });
  2536. var transition = trigger.matchTransition(fromState.value, toState.value, element, toState.params);
  2537. var isFallbackTransition = false;
  2538. if (!transition) {
  2539. if (!defaultToFallback)
  2540. return;
  2541. transition = trigger.fallbackTransition;
  2542. isFallbackTransition = true;
  2543. }
  2544. this._engine.totalQueuedPlayers++;
  2545. this._queue.push({ element: element, triggerName: triggerName, transition: transition, fromState: fromState, toState: toState, player: player, isFallbackTransition: isFallbackTransition });
  2546. if (!isFallbackTransition) {
  2547. addClass(element, QUEUED_CLASSNAME);
  2548. player.onStart(function () { removeClass(element, QUEUED_CLASSNAME); });
  2549. }
  2550. player.onDone(function () {
  2551. var index = _this.players.indexOf(player);
  2552. if (index >= 0) {
  2553. _this.players.splice(index, 1);
  2554. }
  2555. var players = _this._engine.playersByElement.get(element);
  2556. if (players) {
  2557. var index_1 = players.indexOf(player);
  2558. if (index_1 >= 0) {
  2559. players.splice(index_1, 1);
  2560. }
  2561. }
  2562. });
  2563. this.players.push(player);
  2564. playersOnElement.push(player);
  2565. return player;
  2566. };
  2567. AnimationTransitionNamespace.prototype.deregister = function (name) {
  2568. var _this = this;
  2569. delete this._triggers[name];
  2570. this._engine.statesByElement.forEach(function (stateMap, element) { delete stateMap[name]; });
  2571. this._elementListeners.forEach(function (listeners, element) {
  2572. _this._elementListeners.set(element, listeners.filter(function (entry) { return entry.name != name; }));
  2573. });
  2574. };
  2575. AnimationTransitionNamespace.prototype.clearElementCache = function (element) {
  2576. this._engine.statesByElement.delete(element);
  2577. this._elementListeners.delete(element);
  2578. var elementPlayers = this._engine.playersByElement.get(element);
  2579. if (elementPlayers) {
  2580. elementPlayers.forEach(function (player) { return player.destroy(); });
  2581. this._engine.playersByElement.delete(element);
  2582. }
  2583. };
  2584. AnimationTransitionNamespace.prototype._signalRemovalForInnerTriggers = function (rootElement, context, animate) {
  2585. var _this = this;
  2586. if (animate === void 0) { animate = false; }
  2587. // emulate a leave animation for all inner nodes within this node.
  2588. // If there are no animations found for any of the nodes then clear the cache
  2589. // for the element.
  2590. this._engine.driver.query(rootElement, NG_TRIGGER_SELECTOR, true).forEach(function (elm) {
  2591. // this means that an inner remove() operation has already kicked off
  2592. // the animation on this element...
  2593. if (elm[REMOVAL_FLAG])
  2594. return;
  2595. var namespaces = _this._engine.fetchNamespacesByElement(elm);
  2596. if (namespaces.size) {
  2597. namespaces.forEach(function (ns) { return ns.triggerLeaveAnimation(elm, context, false, true); });
  2598. }
  2599. else {
  2600. _this.clearElementCache(elm);
  2601. }
  2602. });
  2603. };
  2604. AnimationTransitionNamespace.prototype.triggerLeaveAnimation = function (element, context, destroyAfterComplete, defaultToFallback) {
  2605. var _this = this;
  2606. var triggerStates = this._engine.statesByElement.get(element);
  2607. if (triggerStates) {
  2608. var players_1 = [];
  2609. Object.keys(triggerStates).forEach(function (triggerName) {
  2610. // this check is here in the event that an element is removed
  2611. // twice (both on the host level and the component level)
  2612. if (_this._triggers[triggerName]) {
  2613. var player = _this.trigger(element, triggerName, VOID_VALUE, defaultToFallback);
  2614. if (player) {
  2615. players_1.push(player);
  2616. }
  2617. }
  2618. });
  2619. if (players_1.length) {
  2620. this._engine.markElementAsRemoved(this.id, element, true, context);
  2621. if (destroyAfterComplete) {
  2622. optimizeGroupPlayer(players_1).onDone(function () { return _this._engine.processLeaveNode(element); });
  2623. }
  2624. return true;
  2625. }
  2626. }
  2627. return false;
  2628. };
  2629. AnimationTransitionNamespace.prototype.prepareLeaveAnimationListeners = function (element) {
  2630. var _this = this;
  2631. var listeners = this._elementListeners.get(element);
  2632. if (listeners) {
  2633. var visitedTriggers_1 = new Set();
  2634. listeners.forEach(function (listener) {
  2635. var triggerName = listener.name;
  2636. if (visitedTriggers_1.has(triggerName))
  2637. return;
  2638. visitedTriggers_1.add(triggerName);
  2639. var trigger = _this._triggers[triggerName];
  2640. var transition = trigger.fallbackTransition;
  2641. var elementStates = _this._engine.statesByElement.get(element);
  2642. var fromState = elementStates[triggerName] || DEFAULT_STATE_VALUE;
  2643. var toState = new StateValue(VOID_VALUE);
  2644. var player = new TransitionAnimationPlayer(_this.id, triggerName, element);
  2645. _this._engine.totalQueuedPlayers++;
  2646. _this._queue.push({
  2647. element: element,
  2648. triggerName: triggerName,
  2649. transition: transition,
  2650. fromState: fromState,
  2651. toState: toState,
  2652. player: player,
  2653. isFallbackTransition: true
  2654. });
  2655. });
  2656. }
  2657. };
  2658. AnimationTransitionNamespace.prototype.removeNode = function (element, context) {
  2659. var _this = this;
  2660. var engine = this._engine;
  2661. if (element.childElementCount) {
  2662. this._signalRemovalForInnerTriggers(element, context, true);
  2663. }
  2664. // this means that a * => VOID animation was detected and kicked off
  2665. if (this.triggerLeaveAnimation(element, context, true))
  2666. return;
  2667. // find the player that is animating and make sure that the
  2668. // removal is delayed until that player has completed
  2669. var containsPotentialParentTransition = false;
  2670. if (engine.totalAnimations) {
  2671. var currentPlayers = engine.players.length ? engine.playersByQueriedElement.get(element) : [];
  2672. // when this `if statement` does not continue forward it means that
  2673. // a previous animation query has selected the current element and
  2674. // is animating it. In this situation want to continue forwards and
  2675. // allow the element to be queued up for animation later.
  2676. if (currentPlayers && currentPlayers.length) {
  2677. containsPotentialParentTransition = true;
  2678. }
  2679. else {
  2680. var parent_1 = element;
  2681. while (parent_1 = parent_1.parentNode) {
  2682. var triggers = engine.statesByElement.get(parent_1);
  2683. if (triggers) {
  2684. containsPotentialParentTransition = true;
  2685. break;
  2686. }
  2687. }
  2688. }
  2689. }
  2690. // at this stage we know that the element will either get removed
  2691. // during flush or will be picked up by a parent query. Either way
  2692. // we need to fire the listeners for this element when it DOES get
  2693. // removed (once the query parent animation is done or after flush)
  2694. this.prepareLeaveAnimationListeners(element);
  2695. // whether or not a parent has an animation we need to delay the deferral of the leave
  2696. // operation until we have more information (which we do after flush() has been called)
  2697. if (containsPotentialParentTransition) {
  2698. engine.markElementAsRemoved(this.id, element, false, context);
  2699. }
  2700. else {
  2701. // we do this after the flush has occurred such
  2702. // that the callbacks can be fired
  2703. engine.afterFlush(function () { return _this.clearElementCache(element); });
  2704. engine.destroyInnerAnimations(element);
  2705. engine._onRemovalComplete(element, context);
  2706. }
  2707. };
  2708. AnimationTransitionNamespace.prototype.insertNode = function (element, parent) { addClass(element, this._hostClassName); };
  2709. AnimationTransitionNamespace.prototype.drainQueuedTransitions = function (microtaskId) {
  2710. var _this = this;
  2711. var instructions = [];
  2712. this._queue.forEach(function (entry) {
  2713. var player = entry.player;
  2714. if (player.destroyed)
  2715. return;
  2716. var element = entry.element;
  2717. var listeners = _this._elementListeners.get(element);
  2718. if (listeners) {
  2719. listeners.forEach(function (listener) {
  2720. if (listener.name == entry.triggerName) {
  2721. var baseEvent = makeAnimationEvent(element, entry.triggerName, entry.fromState.value, entry.toState.value);
  2722. baseEvent['_data'] = microtaskId;
  2723. listenOnPlayer(entry.player, listener.phase, baseEvent, listener.callback);
  2724. }
  2725. });
  2726. }
  2727. if (player.markedForDestroy) {
  2728. _this._engine.afterFlush(function () {
  2729. // now we can destroy the element properly since the event listeners have
  2730. // been bound to the player
  2731. player.destroy();
  2732. });
  2733. }
  2734. else {
  2735. instructions.push(entry);
  2736. }
  2737. });
  2738. this._queue = [];
  2739. return instructions.sort(function (a, b) {
  2740. // if depCount == 0 them move to front
  2741. // otherwise if a contains b then move back
  2742. var d0 = a.transition.ast.depCount;
  2743. var d1 = b.transition.ast.depCount;
  2744. if (d0 == 0 || d1 == 0) {
  2745. return d0 - d1;
  2746. }
  2747. return _this._engine.driver.containsElement(a.element, b.element) ? 1 : -1;
  2748. });
  2749. };
  2750. AnimationTransitionNamespace.prototype.destroy = function (context) {
  2751. this.players.forEach(function (p) { return p.destroy(); });
  2752. this._signalRemovalForInnerTriggers(this.hostElement, context);
  2753. };
  2754. AnimationTransitionNamespace.prototype.elementContainsData = function (element) {
  2755. var containsData = false;
  2756. if (this._elementListeners.has(element))
  2757. containsData = true;
  2758. containsData =
  2759. (this._queue.find(function (entry) { return entry.element === element; }) ? true : false) || containsData;
  2760. return containsData;
  2761. };
  2762. return AnimationTransitionNamespace;
  2763. }());
  2764. var TransitionAnimationEngine = /** @class */ (function () {
  2765. function TransitionAnimationEngine(bodyNode, driver, _normalizer) {
  2766. this.bodyNode = bodyNode;
  2767. this.driver = driver;
  2768. this._normalizer = _normalizer;
  2769. this.players = [];
  2770. this.newHostElements = new Map();
  2771. this.playersByElement = new Map();
  2772. this.playersByQueriedElement = new Map();
  2773. this.statesByElement = new Map();
  2774. this.disabledNodes = new Set();
  2775. this.totalAnimations = 0;
  2776. this.totalQueuedPlayers = 0;
  2777. this._namespaceLookup = {};
  2778. this._namespaceList = [];
  2779. this._flushFns = [];
  2780. this._whenQuietFns = [];
  2781. this.namespacesByHostElement = new Map();
  2782. this.collectedEnterElements = [];
  2783. this.collectedLeaveElements = [];
  2784. // this method is designed to be overridden by the code that uses this engine
  2785. this.onRemovalComplete = function (element, context) { };
  2786. }
  2787. /** @internal */
  2788. TransitionAnimationEngine.prototype._onRemovalComplete = function (element, context) { this.onRemovalComplete(element, context); };
  2789. Object.defineProperty(TransitionAnimationEngine.prototype, "queuedPlayers", {
  2790. get: function () {
  2791. var players = [];
  2792. this._namespaceList.forEach(function (ns) {
  2793. ns.players.forEach(function (player) {
  2794. if (player.queued) {
  2795. players.push(player);
  2796. }
  2797. });
  2798. });
  2799. return players;
  2800. },
  2801. enumerable: true,
  2802. configurable: true
  2803. });
  2804. TransitionAnimationEngine.prototype.createNamespace = function (namespaceId, hostElement) {
  2805. var ns = new AnimationTransitionNamespace(namespaceId, hostElement, this);
  2806. if (hostElement.parentNode) {
  2807. this._balanceNamespaceList(ns, hostElement);
  2808. }
  2809. else {
  2810. // defer this later until flush during when the host element has
  2811. // been inserted so that we know exactly where to place it in
  2812. // the namespace list
  2813. this.newHostElements.set(hostElement, ns);
  2814. // given that this host element is apart of the animation code, it
  2815. // may or may not be inserted by a parent node that is an of an
  2816. // animation renderer type. If this happens then we can still have
  2817. // access to this item when we query for :enter nodes. If the parent
  2818. // is a renderer then the set data-structure will normalize the entry
  2819. this.collectEnterElement(hostElement);
  2820. }
  2821. return this._namespaceLookup[namespaceId] = ns;
  2822. };
  2823. TransitionAnimationEngine.prototype._balanceNamespaceList = function (ns, hostElement) {
  2824. var limit = this._namespaceList.length - 1;
  2825. if (limit >= 0) {
  2826. var found = false;
  2827. for (var i = limit; i >= 0; i--) {
  2828. var nextNamespace = this._namespaceList[i];
  2829. if (this.driver.containsElement(nextNamespace.hostElement, hostElement)) {
  2830. this._namespaceList.splice(i + 1, 0, ns);
  2831. found = true;
  2832. break;
  2833. }
  2834. }
  2835. if (!found) {
  2836. this._namespaceList.splice(0, 0, ns);
  2837. }
  2838. }
  2839. else {
  2840. this._namespaceList.push(ns);
  2841. }
  2842. this.namespacesByHostElement.set(hostElement, ns);
  2843. return ns;
  2844. };
  2845. TransitionAnimationEngine.prototype.register = function (namespaceId, hostElement) {
  2846. var ns = this._namespaceLookup[namespaceId];
  2847. if (!ns) {
  2848. ns = this.createNamespace(namespaceId, hostElement);
  2849. }
  2850. return ns;
  2851. };
  2852. TransitionAnimationEngine.prototype.registerTrigger = function (namespaceId, name, trigger) {
  2853. var ns = this._namespaceLookup[namespaceId];
  2854. if (ns && ns.register(name, trigger)) {
  2855. this.totalAnimations++;
  2856. }
  2857. };
  2858. TransitionAnimationEngine.prototype.destroy = function (namespaceId, context) {
  2859. var _this = this;
  2860. if (!namespaceId)
  2861. return;
  2862. var ns = this._fetchNamespace(namespaceId);
  2863. this.afterFlush(function () {
  2864. _this.namespacesByHostElement.delete(ns.hostElement);
  2865. delete _this._namespaceLookup[namespaceId];
  2866. var index = _this._namespaceList.indexOf(ns);
  2867. if (index >= 0) {
  2868. _this._namespaceList.splice(index, 1);
  2869. }
  2870. });
  2871. this.afterFlushAnimationsDone(function () { return ns.destroy(context); });
  2872. };
  2873. TransitionAnimationEngine.prototype._fetchNamespace = function (id) { return this._namespaceLookup[id]; };
  2874. TransitionAnimationEngine.prototype.fetchNamespacesByElement = function (element) {
  2875. // normally there should only be one namespace per element, however
  2876. // if @triggers are placed on both the component element and then
  2877. // its host element (within the component code) then there will be
  2878. // two namespaces returned. We use a set here to simply the dedupe
  2879. // of namespaces incase there are multiple triggers both the elm and host
  2880. var namespaces = new Set();
  2881. var elementStates = this.statesByElement.get(element);
  2882. if (elementStates) {
  2883. var keys = Object.keys(elementStates);
  2884. for (var i = 0; i < keys.length; i++) {
  2885. var nsId = elementStates[keys[i]].namespaceId;
  2886. if (nsId) {
  2887. var ns = this._fetchNamespace(nsId);
  2888. if (ns) {
  2889. namespaces.add(ns);
  2890. }
  2891. }
  2892. }
  2893. }
  2894. return namespaces;
  2895. };
  2896. TransitionAnimationEngine.prototype.trigger = function (namespaceId, element, name, value) {
  2897. if (isElementNode(element)) {
  2898. var ns = this._fetchNamespace(namespaceId);
  2899. if (ns) {
  2900. ns.trigger(element, name, value);
  2901. return true;
  2902. }
  2903. }
  2904. return false;
  2905. };
  2906. TransitionAnimationEngine.prototype.insertNode = function (namespaceId, element, parent, insertBefore) {
  2907. if (!isElementNode(element))
  2908. return;
  2909. // special case for when an element is removed and reinserted (move operation)
  2910. // when this occurs we do not want to use the element for deletion later
  2911. var details = element[REMOVAL_FLAG];
  2912. if (details && details.setForRemoval) {
  2913. details.setForRemoval = false;
  2914. details.setForMove = true;
  2915. var index = this.collectedLeaveElements.indexOf(element);
  2916. if (index >= 0) {
  2917. this.collectedLeaveElements.splice(index, 1);
  2918. }
  2919. }
  2920. // in the event that the namespaceId is blank then the caller
  2921. // code does not contain any animation code in it, but it is
  2922. // just being called so that the node is marked as being inserted
  2923. if (namespaceId) {
  2924. var ns = this._fetchNamespace(namespaceId);
  2925. // This if-statement is a workaround for router issue #21947.
  2926. // The router sometimes hits a race condition where while a route
  2927. // is being instantiated a new navigation arrives, triggering leave
  2928. // animation of DOM that has not been fully initialized, until this
  2929. // is resolved, we need to handle the scenario when DOM is not in a
  2930. // consistent state during the animation.
  2931. if (ns) {
  2932. ns.insertNode(element, parent);
  2933. }
  2934. }
  2935. // only *directives and host elements are inserted before
  2936. if (insertBefore) {
  2937. this.collectEnterElement(element);
  2938. }
  2939. };
  2940. TransitionAnimationEngine.prototype.collectEnterElement = function (element) { this.collectedEnterElements.push(element); };
  2941. TransitionAnimationEngine.prototype.markElementAsDisabled = function (element, value) {
  2942. if (value) {
  2943. if (!this.disabledNodes.has(element)) {
  2944. this.disabledNodes.add(element);
  2945. addClass(element, DISABLED_CLASSNAME);
  2946. }
  2947. }
  2948. else if (this.disabledNodes.has(element)) {
  2949. this.disabledNodes.delete(element);
  2950. removeClass(element, DISABLED_CLASSNAME);
  2951. }
  2952. };
  2953. TransitionAnimationEngine.prototype.removeNode = function (namespaceId, element, isHostElement, context) {
  2954. if (isElementNode(element)) {
  2955. var ns = namespaceId ? this._fetchNamespace(namespaceId) : null;
  2956. if (ns) {
  2957. ns.removeNode(element, context);
  2958. }
  2959. else {
  2960. this.markElementAsRemoved(namespaceId, element, false, context);
  2961. }
  2962. if (isHostElement) {
  2963. var hostNS = this.namespacesByHostElement.get(element);
  2964. if (hostNS && hostNS.id !== namespaceId) {
  2965. hostNS.removeNode(element, context);
  2966. }
  2967. }
  2968. }
  2969. else {
  2970. this._onRemovalComplete(element, context);
  2971. }
  2972. };
  2973. TransitionAnimationEngine.prototype.markElementAsRemoved = function (namespaceId, element, hasAnimation, context) {
  2974. this.collectedLeaveElements.push(element);
  2975. element[REMOVAL_FLAG] = {
  2976. namespaceId: namespaceId,
  2977. setForRemoval: context, hasAnimation: hasAnimation,
  2978. removedBeforeQueried: false
  2979. };
  2980. };
  2981. TransitionAnimationEngine.prototype.listen = function (namespaceId, element, name, phase, callback) {
  2982. if (isElementNode(element)) {
  2983. return this._fetchNamespace(namespaceId).listen(element, name, phase, callback);
  2984. }
  2985. return function () { };
  2986. };
  2987. TransitionAnimationEngine.prototype._buildInstruction = function (entry, subTimelines, enterClassName, leaveClassName, skipBuildAst) {
  2988. return entry.transition.build(this.driver, entry.element, entry.fromState.value, entry.toState.value, enterClassName, leaveClassName, entry.fromState.options, entry.toState.options, subTimelines, skipBuildAst);
  2989. };
  2990. TransitionAnimationEngine.prototype.destroyInnerAnimations = function (containerElement) {
  2991. var _this = this;
  2992. var elements = this.driver.query(containerElement, NG_TRIGGER_SELECTOR, true);
  2993. elements.forEach(function (element) { return _this.destroyActiveAnimationsForElement(element); });
  2994. if (this.playersByQueriedElement.size == 0)
  2995. return;
  2996. elements = this.driver.query(containerElement, NG_ANIMATING_SELECTOR, true);
  2997. elements.forEach(function (element) { return _this.finishActiveQueriedAnimationOnElement(element); });
  2998. };
  2999. TransitionAnimationEngine.prototype.destroyActiveAnimationsForElement = function (element) {
  3000. var players = this.playersByElement.get(element);
  3001. if (players) {
  3002. players.forEach(function (player) {
  3003. // special case for when an element is set for destruction, but hasn't started.
  3004. // in this situation we want to delay the destruction until the flush occurs
  3005. // so that any event listeners attached to the player are triggered.
  3006. if (player.queued) {
  3007. player.markedForDestroy = true;
  3008. }
  3009. else {
  3010. player.destroy();
  3011. }
  3012. });
  3013. }
  3014. };
  3015. TransitionAnimationEngine.prototype.finishActiveQueriedAnimationOnElement = function (element) {
  3016. var players = this.playersByQueriedElement.get(element);
  3017. if (players) {
  3018. players.forEach(function (player) { return player.finish(); });
  3019. }
  3020. };
  3021. TransitionAnimationEngine.prototype.whenRenderingDone = function () {
  3022. var _this = this;
  3023. return new Promise(function (resolve) {
  3024. if (_this.players.length) {
  3025. return optimizeGroupPlayer(_this.players).onDone(function () { return resolve(); });
  3026. }
  3027. else {
  3028. resolve();
  3029. }
  3030. });
  3031. };
  3032. TransitionAnimationEngine.prototype.processLeaveNode = function (element) {
  3033. var _this = this;
  3034. var details = element[REMOVAL_FLAG];
  3035. if (details && details.setForRemoval) {
  3036. // this will prevent it from removing it twice
  3037. element[REMOVAL_FLAG] = NULL_REMOVAL_STATE;
  3038. if (details.namespaceId) {
  3039. this.destroyInnerAnimations(element);
  3040. var ns = this._fetchNamespace(details.namespaceId);
  3041. if (ns) {
  3042. ns.clearElementCache(element);
  3043. }
  3044. }
  3045. this._onRemovalComplete(element, details.setForRemoval);
  3046. }
  3047. if (this.driver.matchesElement(element, DISABLED_SELECTOR)) {
  3048. this.markElementAsDisabled(element, false);
  3049. }
  3050. this.driver.query(element, DISABLED_SELECTOR, true).forEach(function (node) {
  3051. _this.markElementAsDisabled(node, false);
  3052. });
  3053. };
  3054. TransitionAnimationEngine.prototype.flush = function (microtaskId) {
  3055. var _this = this;
  3056. if (microtaskId === void 0) { microtaskId = -1; }
  3057. var players = [];
  3058. if (this.newHostElements.size) {
  3059. this.newHostElements.forEach(function (ns, element) { return _this._balanceNamespaceList(ns, element); });
  3060. this.newHostElements.clear();
  3061. }
  3062. if (this.totalAnimations && this.collectedEnterElements.length) {
  3063. for (var i = 0; i < this.collectedEnterElements.length; i++) {
  3064. var elm = this.collectedEnterElements[i];
  3065. addClass(elm, STAR_CLASSNAME);
  3066. }
  3067. }
  3068. if (this._namespaceList.length &&
  3069. (this.totalQueuedPlayers || this.collectedLeaveElements.length)) {
  3070. var cleanupFns = [];
  3071. try {
  3072. players = this._flushAnimations(cleanupFns, microtaskId);
  3073. }
  3074. finally {
  3075. for (var i = 0; i < cleanupFns.length; i++) {
  3076. cleanupFns[i]();
  3077. }
  3078. }
  3079. }
  3080. else {
  3081. for (var i = 0; i < this.collectedLeaveElements.length; i++) {
  3082. var element = this.collectedLeaveElements[i];
  3083. this.processLeaveNode(element);
  3084. }
  3085. }
  3086. this.totalQueuedPlayers = 0;
  3087. this.collectedEnterElements.length = 0;
  3088. this.collectedLeaveElements.length = 0;
  3089. this._flushFns.forEach(function (fn) { return fn(); });
  3090. this._flushFns = [];
  3091. if (this._whenQuietFns.length) {
  3092. // we move these over to a variable so that
  3093. // if any new callbacks are registered in another
  3094. // flush they do not populate the existing set
  3095. var quietFns_1 = this._whenQuietFns;
  3096. this._whenQuietFns = [];
  3097. if (players.length) {
  3098. optimizeGroupPlayer(players).onDone(function () { quietFns_1.forEach(function (fn) { return fn(); }); });
  3099. }
  3100. else {
  3101. quietFns_1.forEach(function (fn) { return fn(); });
  3102. }
  3103. }
  3104. };
  3105. TransitionAnimationEngine.prototype.reportError = function (errors) {
  3106. throw new Error("Unable to process animations due to the following failed trigger transitions\n " + errors.join('\n'));
  3107. };
  3108. TransitionAnimationEngine.prototype._flushAnimations = function (cleanupFns, microtaskId) {
  3109. var _this = this;
  3110. var subTimelines = new ElementInstructionMap();
  3111. var skippedPlayers = [];
  3112. var skippedPlayersMap = new Map();
  3113. var queuedInstructions = [];
  3114. var queriedElements = new Map();
  3115. var allPreStyleElements = new Map();
  3116. var allPostStyleElements = new Map();
  3117. var disabledElementsSet = new Set();
  3118. this.disabledNodes.forEach(function (node) {
  3119. disabledElementsSet.add(node);
  3120. var nodesThatAreDisabled = _this.driver.query(node, QUEUED_SELECTOR, true);
  3121. for (var i_1 = 0; i_1 < nodesThatAreDisabled.length; i_1++) {
  3122. disabledElementsSet.add(nodesThatAreDisabled[i_1]);
  3123. }
  3124. });
  3125. var bodyNode = this.bodyNode;
  3126. var allTriggerElements = Array.from(this.statesByElement.keys());
  3127. var enterNodeMap = buildRootMap(allTriggerElements, this.collectedEnterElements);
  3128. // this must occur before the instructions are built below such that
  3129. // the :enter queries match the elements (since the timeline queries
  3130. // are fired during instruction building).
  3131. var enterNodeMapIds = new Map();
  3132. var i = 0;
  3133. enterNodeMap.forEach(function (nodes, root) {
  3134. var className = ENTER_CLASSNAME + i++;
  3135. enterNodeMapIds.set(root, className);
  3136. nodes.forEach(function (node) { return addClass(node, className); });
  3137. });
  3138. var allLeaveNodes = [];
  3139. var mergedLeaveNodes = new Set();
  3140. var leaveNodesWithoutAnimations = new Set();
  3141. for (var i_2 = 0; i_2 < this.collectedLeaveElements.length; i_2++) {
  3142. var element = this.collectedLeaveElements[i_2];
  3143. var details = element[REMOVAL_FLAG];
  3144. if (details && details.setForRemoval) {
  3145. allLeaveNodes.push(element);
  3146. mergedLeaveNodes.add(element);
  3147. if (details.hasAnimation) {
  3148. this.driver.query(element, STAR_SELECTOR, true).forEach(function (elm) { return mergedLeaveNodes.add(elm); });
  3149. }
  3150. else {
  3151. leaveNodesWithoutAnimations.add(element);
  3152. }
  3153. }
  3154. }
  3155. var leaveNodeMapIds = new Map();
  3156. var leaveNodeMap = buildRootMap(allTriggerElements, Array.from(mergedLeaveNodes));
  3157. leaveNodeMap.forEach(function (nodes, root) {
  3158. var className = LEAVE_CLASSNAME + i++;
  3159. leaveNodeMapIds.set(root, className);
  3160. nodes.forEach(function (node) { return addClass(node, className); });
  3161. });
  3162. cleanupFns.push(function () {
  3163. enterNodeMap.forEach(function (nodes, root) {
  3164. var className = enterNodeMapIds.get(root);
  3165. nodes.forEach(function (node) { return removeClass(node, className); });
  3166. });
  3167. leaveNodeMap.forEach(function (nodes, root) {
  3168. var className = leaveNodeMapIds.get(root);
  3169. nodes.forEach(function (node) { return removeClass(node, className); });
  3170. });
  3171. allLeaveNodes.forEach(function (element) { _this.processLeaveNode(element); });
  3172. });
  3173. var allPlayers = [];
  3174. var erroneousTransitions = [];
  3175. for (var i_3 = this._namespaceList.length - 1; i_3 >= 0; i_3--) {
  3176. var ns = this._namespaceList[i_3];
  3177. ns.drainQueuedTransitions(microtaskId).forEach(function (entry) {
  3178. var player = entry.player;
  3179. var element = entry.element;
  3180. allPlayers.push(player);
  3181. if (_this.collectedEnterElements.length) {
  3182. var details = element[REMOVAL_FLAG];
  3183. // move animations are currently not supported...
  3184. if (details && details.setForMove) {
  3185. player.destroy();
  3186. return;
  3187. }
  3188. }
  3189. var nodeIsOrphaned = !bodyNode || !_this.driver.containsElement(bodyNode, element);
  3190. var leaveClassName = leaveNodeMapIds.get(element);
  3191. var enterClassName = enterNodeMapIds.get(element);
  3192. var instruction = _this._buildInstruction(entry, subTimelines, enterClassName, leaveClassName, nodeIsOrphaned);
  3193. if (instruction.errors && instruction.errors.length) {
  3194. erroneousTransitions.push(instruction);
  3195. return;
  3196. }
  3197. // even though the element may not be apart of the DOM, it may
  3198. // still be added at a later point (due to the mechanics of content
  3199. // projection and/or dynamic component insertion) therefore it's
  3200. // important we still style the element.
  3201. if (nodeIsOrphaned) {
  3202. player.onStart(function () { return eraseStyles(element, instruction.fromStyles); });
  3203. player.onDestroy(function () { return setStyles(element, instruction.toStyles); });
  3204. skippedPlayers.push(player);
  3205. return;
  3206. }
  3207. // if a unmatched transition is queued to go then it SHOULD NOT render
  3208. // an animation and cancel the previously running animations.
  3209. if (entry.isFallbackTransition) {
  3210. player.onStart(function () { return eraseStyles(element, instruction.fromStyles); });
  3211. player.onDestroy(function () { return setStyles(element, instruction.toStyles); });
  3212. skippedPlayers.push(player);
  3213. return;
  3214. }
  3215. // this means that if a parent animation uses this animation as a sub trigger
  3216. // then it will instruct the timeline builder to not add a player delay, but
  3217. // instead stretch the first keyframe gap up until the animation starts. The
  3218. // reason this is important is to prevent extra initialization styles from being
  3219. // required by the user in the animation.
  3220. instruction.timelines.forEach(function (tl) { return tl.stretchStartingKeyframe = true; });
  3221. subTimelines.append(element, instruction.timelines);
  3222. var tuple = { instruction: instruction, player: player, element: element };
  3223. queuedInstructions.push(tuple);
  3224. instruction.queriedElements.forEach(function (element) { return getOrSetAsInMap(queriedElements, element, []).push(player); });
  3225. instruction.preStyleProps.forEach(function (stringMap, element) {
  3226. var props = Object.keys(stringMap);
  3227. if (props.length) {
  3228. var setVal_1 = allPreStyleElements.get(element);
  3229. if (!setVal_1) {
  3230. allPreStyleElements.set(element, setVal_1 = new Set());
  3231. }
  3232. props.forEach(function (prop) { return setVal_1.add(prop); });
  3233. }
  3234. });
  3235. instruction.postStyleProps.forEach(function (stringMap, element) {
  3236. var props = Object.keys(stringMap);
  3237. var setVal = allPostStyleElements.get(element);
  3238. if (!setVal) {
  3239. allPostStyleElements.set(element, setVal = new Set());
  3240. }
  3241. props.forEach(function (prop) { return setVal.add(prop); });
  3242. });
  3243. });
  3244. }
  3245. if (erroneousTransitions.length) {
  3246. var errors_1 = [];
  3247. erroneousTransitions.forEach(function (instruction) {
  3248. errors_1.push("@" + instruction.triggerName + " has failed due to:\n");
  3249. instruction.errors.forEach(function (error) { return errors_1.push("- " + error + "\n"); });
  3250. });
  3251. allPlayers.forEach(function (player) { return player.destroy(); });
  3252. this.reportError(errors_1);
  3253. }
  3254. var allPreviousPlayersMap = new Map();
  3255. // this map works to tell which element in the DOM tree is contained by
  3256. // which animation. Further down below this map will get populated once
  3257. // the players are built and in doing so it can efficiently figure out
  3258. // if a sub player is skipped due to a parent player having priority.
  3259. var animationElementMap = new Map();
  3260. queuedInstructions.forEach(function (entry) {
  3261. var element = entry.element;
  3262. if (subTimelines.has(element)) {
  3263. animationElementMap.set(element, element);
  3264. _this._beforeAnimationBuild(entry.player.namespaceId, entry.instruction, allPreviousPlayersMap);
  3265. }
  3266. });
  3267. skippedPlayers.forEach(function (player) {
  3268. var element = player.element;
  3269. var previousPlayers = _this._getPreviousPlayers(element, false, player.namespaceId, player.triggerName, null);
  3270. previousPlayers.forEach(function (prevPlayer) {
  3271. getOrSetAsInMap(allPreviousPlayersMap, element, []).push(prevPlayer);
  3272. prevPlayer.destroy();
  3273. });
  3274. });
  3275. // this is a special case for nodes that will be removed (either by)
  3276. // having their own leave animations or by being queried in a container
  3277. // that will be removed once a parent animation is complete. The idea
  3278. // here is that * styles must be identical to ! styles because of
  3279. // backwards compatibility (* is also filled in by default in many places).
  3280. // Otherwise * styles will return an empty value or auto since the element
  3281. // that is being getComputedStyle'd will not be visible (since * = destination)
  3282. var replaceNodes = allLeaveNodes.filter(function (node) {
  3283. return replacePostStylesAsPre(node, allPreStyleElements, allPostStyleElements);
  3284. });
  3285. // POST STAGE: fill the * styles
  3286. var postStylesMap = new Map();
  3287. var allLeaveQueriedNodes = cloakAndComputeStyles(postStylesMap, this.driver, leaveNodesWithoutAnimations, allPostStyleElements, animations.AUTO_STYLE);
  3288. allLeaveQueriedNodes.forEach(function (node) {
  3289. if (replacePostStylesAsPre(node, allPreStyleElements, allPostStyleElements)) {
  3290. replaceNodes.push(node);
  3291. }
  3292. });
  3293. // PRE STAGE: fill the ! styles
  3294. var preStylesMap = new Map();
  3295. enterNodeMap.forEach(function (nodes, root) {
  3296. cloakAndComputeStyles(preStylesMap, _this.driver, new Set(nodes), allPreStyleElements, animations.ɵPRE_STYLE);
  3297. });
  3298. replaceNodes.forEach(function (node) {
  3299. var post = postStylesMap.get(node);
  3300. var pre = preStylesMap.get(node);
  3301. postStylesMap.set(node, __assign({}, post, pre));
  3302. });
  3303. var rootPlayers = [];
  3304. var subPlayers = [];
  3305. var NO_PARENT_ANIMATION_ELEMENT_DETECTED = {};
  3306. queuedInstructions.forEach(function (entry) {
  3307. var element = entry.element, player = entry.player, instruction = entry.instruction;
  3308. // this means that it was never consumed by a parent animation which
  3309. // means that it is independent and therefore should be set for animation
  3310. if (subTimelines.has(element)) {
  3311. if (disabledElementsSet.has(element)) {
  3312. player.onDestroy(function () { return setStyles(element, instruction.toStyles); });
  3313. player.disabled = true;
  3314. player.overrideTotalTime(instruction.totalTime);
  3315. skippedPlayers.push(player);
  3316. return;
  3317. }
  3318. // this will flow up the DOM and query the map to figure out
  3319. // if a parent animation has priority over it. In the situation
  3320. // that a parent is detected then it will cancel the loop. If
  3321. // nothing is detected, or it takes a few hops to find a parent,
  3322. // then it will fill in the missing nodes and signal them as having
  3323. // a detected parent (or a NO_PARENT value via a special constant).
  3324. var parentWithAnimation_1 = NO_PARENT_ANIMATION_ELEMENT_DETECTED;
  3325. if (animationElementMap.size > 1) {
  3326. var elm = element;
  3327. var parentsToAdd = [];
  3328. while (elm = elm.parentNode) {
  3329. var detectedParent = animationElementMap.get(elm);
  3330. if (detectedParent) {
  3331. parentWithAnimation_1 = detectedParent;
  3332. break;
  3333. }
  3334. parentsToAdd.push(elm);
  3335. }
  3336. parentsToAdd.forEach(function (parent) { return animationElementMap.set(parent, parentWithAnimation_1); });
  3337. }
  3338. var innerPlayer = _this._buildAnimation(player.namespaceId, instruction, allPreviousPlayersMap, skippedPlayersMap, preStylesMap, postStylesMap);
  3339. player.setRealPlayer(innerPlayer);
  3340. if (parentWithAnimation_1 === NO_PARENT_ANIMATION_ELEMENT_DETECTED) {
  3341. rootPlayers.push(player);
  3342. }
  3343. else {
  3344. var parentPlayers = _this.playersByElement.get(parentWithAnimation_1);
  3345. if (parentPlayers && parentPlayers.length) {
  3346. player.parentPlayer = optimizeGroupPlayer(parentPlayers);
  3347. }
  3348. skippedPlayers.push(player);
  3349. }
  3350. }
  3351. else {
  3352. eraseStyles(element, instruction.fromStyles);
  3353. player.onDestroy(function () { return setStyles(element, instruction.toStyles); });
  3354. // there still might be a ancestor player animating this
  3355. // element therefore we will still add it as a sub player
  3356. // even if its animation may be disabled
  3357. subPlayers.push(player);
  3358. if (disabledElementsSet.has(element)) {
  3359. skippedPlayers.push(player);
  3360. }
  3361. }
  3362. });
  3363. // find all of the sub players' corresponding inner animation player
  3364. subPlayers.forEach(function (player) {
  3365. // even if any players are not found for a sub animation then it
  3366. // will still complete itself after the next tick since it's Noop
  3367. var playersForElement = skippedPlayersMap.get(player.element);
  3368. if (playersForElement && playersForElement.length) {
  3369. var innerPlayer = optimizeGroupPlayer(playersForElement);
  3370. player.setRealPlayer(innerPlayer);
  3371. }
  3372. });
  3373. // the reason why we don't actually play the animation is
  3374. // because all that a skipped player is designed to do is to
  3375. // fire the start/done transition callback events
  3376. skippedPlayers.forEach(function (player) {
  3377. if (player.parentPlayer) {
  3378. player.syncPlayerEvents(player.parentPlayer);
  3379. }
  3380. else {
  3381. player.destroy();
  3382. }
  3383. });
  3384. // run through all of the queued removals and see if they
  3385. // were picked up by a query. If not then perform the removal
  3386. // operation right away unless a parent animation is ongoing.
  3387. for (var i_4 = 0; i_4 < allLeaveNodes.length; i_4++) {
  3388. var element = allLeaveNodes[i_4];
  3389. var details = element[REMOVAL_FLAG];
  3390. removeClass(element, LEAVE_CLASSNAME);
  3391. // this means the element has a removal animation that is being
  3392. // taken care of and therefore the inner elements will hang around
  3393. // until that animation is over (or the parent queried animation)
  3394. if (details && details.hasAnimation)
  3395. continue;
  3396. var players = [];
  3397. // if this element is queried or if it contains queried children
  3398. // then we want for the element not to be removed from the page
  3399. // until the queried animations have finished
  3400. if (queriedElements.size) {
  3401. var queriedPlayerResults = queriedElements.get(element);
  3402. if (queriedPlayerResults && queriedPlayerResults.length) {
  3403. players.push.apply(players, __spread(queriedPlayerResults));
  3404. }
  3405. var queriedInnerElements = this.driver.query(element, NG_ANIMATING_SELECTOR, true);
  3406. for (var j = 0; j < queriedInnerElements.length; j++) {
  3407. var queriedPlayers = queriedElements.get(queriedInnerElements[j]);
  3408. if (queriedPlayers && queriedPlayers.length) {
  3409. players.push.apply(players, __spread(queriedPlayers));
  3410. }
  3411. }
  3412. }
  3413. var activePlayers = players.filter(function (p) { return !p.destroyed; });
  3414. if (activePlayers.length) {
  3415. removeNodesAfterAnimationDone(this, element, activePlayers);
  3416. }
  3417. else {
  3418. this.processLeaveNode(element);
  3419. }
  3420. }
  3421. // this is required so the cleanup method doesn't remove them
  3422. allLeaveNodes.length = 0;
  3423. rootPlayers.forEach(function (player) {
  3424. _this.players.push(player);
  3425. player.onDone(function () {
  3426. player.destroy();
  3427. var index = _this.players.indexOf(player);
  3428. _this.players.splice(index, 1);
  3429. });
  3430. player.play();
  3431. });
  3432. return rootPlayers;
  3433. };
  3434. TransitionAnimationEngine.prototype.elementContainsData = function (namespaceId, element) {
  3435. var containsData = false;
  3436. var details = element[REMOVAL_FLAG];
  3437. if (details && details.setForRemoval)
  3438. containsData = true;
  3439. if (this.playersByElement.has(element))
  3440. containsData = true;
  3441. if (this.playersByQueriedElement.has(element))
  3442. containsData = true;
  3443. if (this.statesByElement.has(element))
  3444. containsData = true;
  3445. return this._fetchNamespace(namespaceId).elementContainsData(element) || containsData;
  3446. };
  3447. TransitionAnimationEngine.prototype.afterFlush = function (callback) { this._flushFns.push(callback); };
  3448. TransitionAnimationEngine.prototype.afterFlushAnimationsDone = function (callback) { this._whenQuietFns.push(callback); };
  3449. TransitionAnimationEngine.prototype._getPreviousPlayers = function (element, isQueriedElement, namespaceId, triggerName, toStateValue) {
  3450. var players = [];
  3451. if (isQueriedElement) {
  3452. var queriedElementPlayers = this.playersByQueriedElement.get(element);
  3453. if (queriedElementPlayers) {
  3454. players = queriedElementPlayers;
  3455. }
  3456. }
  3457. else {
  3458. var elementPlayers = this.playersByElement.get(element);
  3459. if (elementPlayers) {
  3460. var isRemovalAnimation_1 = !toStateValue || toStateValue == VOID_VALUE;
  3461. elementPlayers.forEach(function (player) {
  3462. if (player.queued)
  3463. return;
  3464. if (!isRemovalAnimation_1 && player.triggerName != triggerName)
  3465. return;
  3466. players.push(player);
  3467. });
  3468. }
  3469. }
  3470. if (namespaceId || triggerName) {
  3471. players = players.filter(function (player) {
  3472. if (namespaceId && namespaceId != player.namespaceId)
  3473. return false;
  3474. if (triggerName && triggerName != player.triggerName)
  3475. return false;
  3476. return true;
  3477. });
  3478. }
  3479. return players;
  3480. };
  3481. TransitionAnimationEngine.prototype._beforeAnimationBuild = function (namespaceId, instruction, allPreviousPlayersMap) {
  3482. var e_1, _a;
  3483. var triggerName = instruction.triggerName;
  3484. var rootElement = instruction.element;
  3485. // when a removal animation occurs, ALL previous players are collected
  3486. // and destroyed (even if they are outside of the current namespace)
  3487. var targetNameSpaceId = instruction.isRemovalTransition ? undefined : namespaceId;
  3488. var targetTriggerName = instruction.isRemovalTransition ? undefined : triggerName;
  3489. var _loop_1 = function (timelineInstruction) {
  3490. var element = timelineInstruction.element;
  3491. var isQueriedElement = element !== rootElement;
  3492. var players = getOrSetAsInMap(allPreviousPlayersMap, element, []);
  3493. var previousPlayers = this_1._getPreviousPlayers(element, isQueriedElement, targetNameSpaceId, targetTriggerName, instruction.toState);
  3494. previousPlayers.forEach(function (player) {
  3495. var realPlayer = player.getRealPlayer();
  3496. if (realPlayer.beforeDestroy) {
  3497. realPlayer.beforeDestroy();
  3498. }
  3499. player.destroy();
  3500. players.push(player);
  3501. });
  3502. };
  3503. var this_1 = this;
  3504. try {
  3505. for (var _b = __values(instruction.timelines), _c = _b.next(); !_c.done; _c = _b.next()) {
  3506. var timelineInstruction = _c.value;
  3507. _loop_1(timelineInstruction);
  3508. }
  3509. }
  3510. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  3511. finally {
  3512. try {
  3513. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  3514. }
  3515. finally { if (e_1) throw e_1.error; }
  3516. }
  3517. // this needs to be done so that the PRE/POST styles can be
  3518. // computed properly without interfering with the previous animation
  3519. eraseStyles(rootElement, instruction.fromStyles);
  3520. };
  3521. TransitionAnimationEngine.prototype._buildAnimation = function (namespaceId, instruction, allPreviousPlayersMap, skippedPlayersMap, preStylesMap, postStylesMap) {
  3522. var _this = this;
  3523. var triggerName = instruction.triggerName;
  3524. var rootElement = instruction.element;
  3525. // we first run this so that the previous animation player
  3526. // data can be passed into the successive animation players
  3527. var allQueriedPlayers = [];
  3528. var allConsumedElements = new Set();
  3529. var allSubElements = new Set();
  3530. var allNewPlayers = instruction.timelines.map(function (timelineInstruction) {
  3531. var element = timelineInstruction.element;
  3532. allConsumedElements.add(element);
  3533. // FIXME (matsko): make sure to-be-removed animations are removed properly
  3534. var details = element[REMOVAL_FLAG];
  3535. if (details && details.removedBeforeQueried)
  3536. return new animations.NoopAnimationPlayer(timelineInstruction.duration, timelineInstruction.delay);
  3537. var isQueriedElement = element !== rootElement;
  3538. var previousPlayers = flattenGroupPlayers((allPreviousPlayersMap.get(element) || EMPTY_PLAYER_ARRAY)
  3539. .map(function (p) { return p.getRealPlayer(); }))
  3540. .filter(function (p) {
  3541. // the `element` is not apart of the AnimationPlayer definition, but
  3542. // Mock/WebAnimations
  3543. // use the element within their implementation. This will be added in Angular5 to
  3544. // AnimationPlayer
  3545. var pp = p;
  3546. return pp.element ? pp.element === element : false;
  3547. });
  3548. var preStyles = preStylesMap.get(element);
  3549. var postStyles = postStylesMap.get(element);
  3550. var keyframes = normalizeKeyframes(_this.driver, _this._normalizer, element, timelineInstruction.keyframes, preStyles, postStyles);
  3551. var player = _this._buildPlayer(timelineInstruction, keyframes, previousPlayers);
  3552. // this means that this particular player belongs to a sub trigger. It is
  3553. // important that we match this player up with the corresponding (@trigger.listener)
  3554. if (timelineInstruction.subTimeline && skippedPlayersMap) {
  3555. allSubElements.add(element);
  3556. }
  3557. if (isQueriedElement) {
  3558. var wrappedPlayer = new TransitionAnimationPlayer(namespaceId, triggerName, element);
  3559. wrappedPlayer.setRealPlayer(player);
  3560. allQueriedPlayers.push(wrappedPlayer);
  3561. }
  3562. return player;
  3563. });
  3564. allQueriedPlayers.forEach(function (player) {
  3565. getOrSetAsInMap(_this.playersByQueriedElement, player.element, []).push(player);
  3566. player.onDone(function () { return deleteOrUnsetInMap(_this.playersByQueriedElement, player.element, player); });
  3567. });
  3568. allConsumedElements.forEach(function (element) { return addClass(element, NG_ANIMATING_CLASSNAME); });
  3569. var player = optimizeGroupPlayer(allNewPlayers);
  3570. player.onDestroy(function () {
  3571. allConsumedElements.forEach(function (element) { return removeClass(element, NG_ANIMATING_CLASSNAME); });
  3572. setStyles(rootElement, instruction.toStyles);
  3573. });
  3574. // this basically makes all of the callbacks for sub element animations
  3575. // be dependent on the upper players for when they finish
  3576. allSubElements.forEach(function (element) { getOrSetAsInMap(skippedPlayersMap, element, []).push(player); });
  3577. return player;
  3578. };
  3579. TransitionAnimationEngine.prototype._buildPlayer = function (instruction, keyframes, previousPlayers) {
  3580. if (keyframes.length > 0) {
  3581. return this.driver.animate(instruction.element, keyframes, instruction.duration, instruction.delay, instruction.easing, previousPlayers);
  3582. }
  3583. // special case for when an empty transition|definition is provided
  3584. // ... there is no point in rendering an empty animation
  3585. return new animations.NoopAnimationPlayer(instruction.duration, instruction.delay);
  3586. };
  3587. return TransitionAnimationEngine;
  3588. }());
  3589. var TransitionAnimationPlayer = /** @class */ (function () {
  3590. function TransitionAnimationPlayer(namespaceId, triggerName, element) {
  3591. this.namespaceId = namespaceId;
  3592. this.triggerName = triggerName;
  3593. this.element = element;
  3594. this._player = new animations.NoopAnimationPlayer();
  3595. this._containsRealPlayer = false;
  3596. this._queuedCallbacks = {};
  3597. this.destroyed = false;
  3598. this.markedForDestroy = false;
  3599. this.disabled = false;
  3600. this.queued = true;
  3601. this.totalTime = 0;
  3602. }
  3603. TransitionAnimationPlayer.prototype.setRealPlayer = function (player) {
  3604. var _this = this;
  3605. if (this._containsRealPlayer)
  3606. return;
  3607. this._player = player;
  3608. Object.keys(this._queuedCallbacks).forEach(function (phase) {
  3609. _this._queuedCallbacks[phase].forEach(function (callback) { return listenOnPlayer(player, phase, undefined, callback); });
  3610. });
  3611. this._queuedCallbacks = {};
  3612. this._containsRealPlayer = true;
  3613. this.overrideTotalTime(player.totalTime);
  3614. this.queued = false;
  3615. };
  3616. TransitionAnimationPlayer.prototype.getRealPlayer = function () { return this._player; };
  3617. TransitionAnimationPlayer.prototype.overrideTotalTime = function (totalTime) { this.totalTime = totalTime; };
  3618. TransitionAnimationPlayer.prototype.syncPlayerEvents = function (player) {
  3619. var _this = this;
  3620. var p = this._player;
  3621. if (p.triggerCallback) {
  3622. player.onStart(function () { return p.triggerCallback('start'); });
  3623. }
  3624. player.onDone(function () { return _this.finish(); });
  3625. player.onDestroy(function () { return _this.destroy(); });
  3626. };
  3627. TransitionAnimationPlayer.prototype._queueEvent = function (name, callback) {
  3628. getOrSetAsInMap(this._queuedCallbacks, name, []).push(callback);
  3629. };
  3630. TransitionAnimationPlayer.prototype.onDone = function (fn) {
  3631. if (this.queued) {
  3632. this._queueEvent('done', fn);
  3633. }
  3634. this._player.onDone(fn);
  3635. };
  3636. TransitionAnimationPlayer.prototype.onStart = function (fn) {
  3637. if (this.queued) {
  3638. this._queueEvent('start', fn);
  3639. }
  3640. this._player.onStart(fn);
  3641. };
  3642. TransitionAnimationPlayer.prototype.onDestroy = function (fn) {
  3643. if (this.queued) {
  3644. this._queueEvent('destroy', fn);
  3645. }
  3646. this._player.onDestroy(fn);
  3647. };
  3648. TransitionAnimationPlayer.prototype.init = function () { this._player.init(); };
  3649. TransitionAnimationPlayer.prototype.hasStarted = function () { return this.queued ? false : this._player.hasStarted(); };
  3650. TransitionAnimationPlayer.prototype.play = function () { !this.queued && this._player.play(); };
  3651. TransitionAnimationPlayer.prototype.pause = function () { !this.queued && this._player.pause(); };
  3652. TransitionAnimationPlayer.prototype.restart = function () { !this.queued && this._player.restart(); };
  3653. TransitionAnimationPlayer.prototype.finish = function () { this._player.finish(); };
  3654. TransitionAnimationPlayer.prototype.destroy = function () {
  3655. this.destroyed = true;
  3656. this._player.destroy();
  3657. };
  3658. TransitionAnimationPlayer.prototype.reset = function () { !this.queued && this._player.reset(); };
  3659. TransitionAnimationPlayer.prototype.setPosition = function (p) {
  3660. if (!this.queued) {
  3661. this._player.setPosition(p);
  3662. }
  3663. };
  3664. TransitionAnimationPlayer.prototype.getPosition = function () { return this.queued ? 0 : this._player.getPosition(); };
  3665. /** @internal */
  3666. TransitionAnimationPlayer.prototype.triggerCallback = function (phaseName) {
  3667. var p = this._player;
  3668. if (p.triggerCallback) {
  3669. p.triggerCallback(phaseName);
  3670. }
  3671. };
  3672. return TransitionAnimationPlayer;
  3673. }());
  3674. function deleteOrUnsetInMap(map, key, value) {
  3675. var currentValues;
  3676. if (map instanceof Map) {
  3677. currentValues = map.get(key);
  3678. if (currentValues) {
  3679. if (currentValues.length) {
  3680. var index = currentValues.indexOf(value);
  3681. currentValues.splice(index, 1);
  3682. }
  3683. if (currentValues.length == 0) {
  3684. map.delete(key);
  3685. }
  3686. }
  3687. }
  3688. else {
  3689. currentValues = map[key];
  3690. if (currentValues) {
  3691. if (currentValues.length) {
  3692. var index = currentValues.indexOf(value);
  3693. currentValues.splice(index, 1);
  3694. }
  3695. if (currentValues.length == 0) {
  3696. delete map[key];
  3697. }
  3698. }
  3699. }
  3700. return currentValues;
  3701. }
  3702. function normalizeTriggerValue(value) {
  3703. // we use `!= null` here because it's the most simple
  3704. // way to test against a "falsy" value without mixing
  3705. // in empty strings or a zero value. DO NOT OPTIMIZE.
  3706. return value != null ? value : null;
  3707. }
  3708. function isElementNode(node) {
  3709. return node && node['nodeType'] === 1;
  3710. }
  3711. function isTriggerEventValid(eventName) {
  3712. return eventName == 'start' || eventName == 'done';
  3713. }
  3714. function cloakElement(element, value) {
  3715. var oldValue = element.style.display;
  3716. element.style.display = value != null ? value : 'none';
  3717. return oldValue;
  3718. }
  3719. function cloakAndComputeStyles(valuesMap, driver, elements, elementPropsMap, defaultStyle) {
  3720. var cloakVals = [];
  3721. elements.forEach(function (element) { return cloakVals.push(cloakElement(element)); });
  3722. var failedElements = [];
  3723. elementPropsMap.forEach(function (props, element) {
  3724. var styles = {};
  3725. props.forEach(function (prop) {
  3726. var value = styles[prop] = driver.computeStyle(element, prop, defaultStyle);
  3727. // there is no easy way to detect this because a sub element could be removed
  3728. // by a parent animation element being detached.
  3729. if (!value || value.length == 0) {
  3730. element[REMOVAL_FLAG] = NULL_REMOVED_QUERIED_STATE;
  3731. failedElements.push(element);
  3732. }
  3733. });
  3734. valuesMap.set(element, styles);
  3735. });
  3736. // we use a index variable here since Set.forEach(a, i) does not return
  3737. // an index value for the closure (but instead just the value)
  3738. var i = 0;
  3739. elements.forEach(function (element) { return cloakElement(element, cloakVals[i++]); });
  3740. return failedElements;
  3741. }
  3742. /*
  3743. Since the Angular renderer code will return a collection of inserted
  3744. nodes in all areas of a DOM tree, it's up to this algorithm to figure
  3745. out which nodes are roots for each animation @trigger.
  3746. By placing each inserted node into a Set and traversing upwards, it
  3747. is possible to find the @trigger elements and well any direct *star
  3748. insertion nodes, if a @trigger root is found then the enter element
  3749. is placed into the Map[@trigger] spot.
  3750. */
  3751. function buildRootMap(roots, nodes) {
  3752. var rootMap = new Map();
  3753. roots.forEach(function (root) { return rootMap.set(root, []); });
  3754. if (nodes.length == 0)
  3755. return rootMap;
  3756. var NULL_NODE = 1;
  3757. var nodeSet = new Set(nodes);
  3758. var localRootMap = new Map();
  3759. function getRoot(node) {
  3760. if (!node)
  3761. return NULL_NODE;
  3762. var root = localRootMap.get(node);
  3763. if (root)
  3764. return root;
  3765. var parent = node.parentNode;
  3766. if (rootMap.has(parent)) { // ngIf inside @trigger
  3767. root = parent;
  3768. }
  3769. else if (nodeSet.has(parent)) { // ngIf inside ngIf
  3770. root = NULL_NODE;
  3771. }
  3772. else { // recurse upwards
  3773. root = getRoot(parent);
  3774. }
  3775. localRootMap.set(node, root);
  3776. return root;
  3777. }
  3778. nodes.forEach(function (node) {
  3779. var root = getRoot(node);
  3780. if (root !== NULL_NODE) {
  3781. rootMap.get(root).push(node);
  3782. }
  3783. });
  3784. return rootMap;
  3785. }
  3786. var CLASSES_CACHE_KEY = '$$classes';
  3787. function addClass(element, className) {
  3788. if (element.classList) {
  3789. element.classList.add(className);
  3790. }
  3791. else {
  3792. var classes = element[CLASSES_CACHE_KEY];
  3793. if (!classes) {
  3794. classes = element[CLASSES_CACHE_KEY] = {};
  3795. }
  3796. classes[className] = true;
  3797. }
  3798. }
  3799. function removeClass(element, className) {
  3800. if (element.classList) {
  3801. element.classList.remove(className);
  3802. }
  3803. else {
  3804. var classes = element[CLASSES_CACHE_KEY];
  3805. if (classes) {
  3806. delete classes[className];
  3807. }
  3808. }
  3809. }
  3810. function removeNodesAfterAnimationDone(engine, element, players) {
  3811. optimizeGroupPlayer(players).onDone(function () { return engine.processLeaveNode(element); });
  3812. }
  3813. function flattenGroupPlayers(players) {
  3814. var finalPlayers = [];
  3815. _flattenGroupPlayersRecur(players, finalPlayers);
  3816. return finalPlayers;
  3817. }
  3818. function _flattenGroupPlayersRecur(players, finalPlayers) {
  3819. for (var i = 0; i < players.length; i++) {
  3820. var player = players[i];
  3821. if (player instanceof animations.ɵAnimationGroupPlayer) {
  3822. _flattenGroupPlayersRecur(player.players, finalPlayers);
  3823. }
  3824. else {
  3825. finalPlayers.push(player);
  3826. }
  3827. }
  3828. }
  3829. function objEquals(a, b) {
  3830. var k1 = Object.keys(a);
  3831. var k2 = Object.keys(b);
  3832. if (k1.length != k2.length)
  3833. return false;
  3834. for (var i = 0; i < k1.length; i++) {
  3835. var prop = k1[i];
  3836. if (!b.hasOwnProperty(prop) || a[prop] !== b[prop])
  3837. return false;
  3838. }
  3839. return true;
  3840. }
  3841. function replacePostStylesAsPre(element, allPreStyleElements, allPostStyleElements) {
  3842. var postEntry = allPostStyleElements.get(element);
  3843. if (!postEntry)
  3844. return false;
  3845. var preEntry = allPreStyleElements.get(element);
  3846. if (preEntry) {
  3847. postEntry.forEach(function (data) { return preEntry.add(data); });
  3848. }
  3849. else {
  3850. allPreStyleElements.set(element, postEntry);
  3851. }
  3852. allPostStyleElements.delete(element);
  3853. return true;
  3854. }
  3855. var AnimationEngine = /** @class */ (function () {
  3856. function AnimationEngine(bodyNode, _driver, normalizer) {
  3857. var _this = this;
  3858. this.bodyNode = bodyNode;
  3859. this._driver = _driver;
  3860. this._triggerCache = {};
  3861. // this method is designed to be overridden by the code that uses this engine
  3862. this.onRemovalComplete = function (element, context) { };
  3863. this._transitionEngine = new TransitionAnimationEngine(bodyNode, _driver, normalizer);
  3864. this._timelineEngine = new TimelineAnimationEngine(bodyNode, _driver, normalizer);
  3865. this._transitionEngine.onRemovalComplete = function (element, context) {
  3866. return _this.onRemovalComplete(element, context);
  3867. };
  3868. }
  3869. AnimationEngine.prototype.registerTrigger = function (componentId, namespaceId, hostElement, name, metadata) {
  3870. var cacheKey = componentId + '-' + name;
  3871. var trigger = this._triggerCache[cacheKey];
  3872. if (!trigger) {
  3873. var errors = [];
  3874. var ast = buildAnimationAst(this._driver, metadata, errors);
  3875. if (errors.length) {
  3876. throw new Error("The animation trigger \"" + name + "\" has failed to build due to the following errors:\n - " + errors.join("\n - "));
  3877. }
  3878. trigger = buildTrigger(name, ast);
  3879. this._triggerCache[cacheKey] = trigger;
  3880. }
  3881. this._transitionEngine.registerTrigger(namespaceId, name, trigger);
  3882. };
  3883. AnimationEngine.prototype.register = function (namespaceId, hostElement) {
  3884. this._transitionEngine.register(namespaceId, hostElement);
  3885. };
  3886. AnimationEngine.prototype.destroy = function (namespaceId, context) {
  3887. this._transitionEngine.destroy(namespaceId, context);
  3888. };
  3889. AnimationEngine.prototype.onInsert = function (namespaceId, element, parent, insertBefore) {
  3890. this._transitionEngine.insertNode(namespaceId, element, parent, insertBefore);
  3891. };
  3892. AnimationEngine.prototype.onRemove = function (namespaceId, element, context, isHostElement) {
  3893. this._transitionEngine.removeNode(namespaceId, element, isHostElement || false, context);
  3894. };
  3895. AnimationEngine.prototype.disableAnimations = function (element, disable) {
  3896. this._transitionEngine.markElementAsDisabled(element, disable);
  3897. };
  3898. AnimationEngine.prototype.process = function (namespaceId, element, property, value) {
  3899. if (property.charAt(0) == '@') {
  3900. var _a = __read(parseTimelineCommand(property), 2), id = _a[0], action = _a[1];
  3901. var args = value;
  3902. this._timelineEngine.command(id, element, action, args);
  3903. }
  3904. else {
  3905. this._transitionEngine.trigger(namespaceId, element, property, value);
  3906. }
  3907. };
  3908. AnimationEngine.prototype.listen = function (namespaceId, element, eventName, eventPhase, callback) {
  3909. // @@listen
  3910. if (eventName.charAt(0) == '@') {
  3911. var _a = __read(parseTimelineCommand(eventName), 2), id = _a[0], action = _a[1];
  3912. return this._timelineEngine.listen(id, element, action, callback);
  3913. }
  3914. return this._transitionEngine.listen(namespaceId, element, eventName, eventPhase, callback);
  3915. };
  3916. AnimationEngine.prototype.flush = function (microtaskId) {
  3917. if (microtaskId === void 0) { microtaskId = -1; }
  3918. this._transitionEngine.flush(microtaskId);
  3919. };
  3920. Object.defineProperty(AnimationEngine.prototype, "players", {
  3921. get: function () {
  3922. return this._transitionEngine.players
  3923. .concat(this._timelineEngine.players);
  3924. },
  3925. enumerable: true,
  3926. configurable: true
  3927. });
  3928. AnimationEngine.prototype.whenRenderingDone = function () { return this._transitionEngine.whenRenderingDone(); };
  3929. return AnimationEngine;
  3930. }());
  3931. /**
  3932. * @license
  3933. * Copyright Google Inc. All Rights Reserved.
  3934. *
  3935. * Use of this source code is governed by an MIT-style license that can be
  3936. * found in the LICENSE file at https://angular.io/license
  3937. */
  3938. /**
  3939. * Returns an instance of `SpecialCasedStyles` if and when any special (non animateable) styles are
  3940. * detected.
  3941. *
  3942. * In CSS there exist properties that cannot be animated within a keyframe animation
  3943. * (whether it be via CSS keyframes or web-animations) and the animation implementation
  3944. * will ignore them. This function is designed to detect those special cased styles and
  3945. * return a container that will be executed at the start and end of the animation.
  3946. *
  3947. * @returns an instance of `SpecialCasedStyles` if any special styles are detected otherwise `null`
  3948. */
  3949. function packageNonAnimatableStyles(element, styles) {
  3950. var startStyles = null;
  3951. var endStyles = null;
  3952. if (Array.isArray(styles) && styles.length) {
  3953. startStyles = filterNonAnimatableStyles(styles[0]);
  3954. if (styles.length > 1) {
  3955. endStyles = filterNonAnimatableStyles(styles[styles.length - 1]);
  3956. }
  3957. }
  3958. else if (styles) {
  3959. startStyles = filterNonAnimatableStyles(styles);
  3960. }
  3961. return (startStyles || endStyles) ? new SpecialCasedStyles(element, startStyles, endStyles) :
  3962. null;
  3963. }
  3964. /**
  3965. * Designed to be executed during a keyframe-based animation to apply any special-cased styles.
  3966. *
  3967. * When started (when the `start()` method is run) then the provided `startStyles`
  3968. * will be applied. When finished (when the `finish()` method is called) the
  3969. * `endStyles` will be applied as well any any starting styles. Finally when
  3970. * `destroy()` is called then all styles will be removed.
  3971. */
  3972. var SpecialCasedStyles = /** @class */ (function () {
  3973. function SpecialCasedStyles(_element, _startStyles, _endStyles) {
  3974. this._element = _element;
  3975. this._startStyles = _startStyles;
  3976. this._endStyles = _endStyles;
  3977. this._state = 0 /* Pending */;
  3978. var initialStyles = SpecialCasedStyles.initialStylesByElement.get(_element);
  3979. if (!initialStyles) {
  3980. SpecialCasedStyles.initialStylesByElement.set(_element, initialStyles = {});
  3981. }
  3982. this._initialStyles = initialStyles;
  3983. }
  3984. SpecialCasedStyles.prototype.start = function () {
  3985. if (this._state < 1 /* Started */) {
  3986. if (this._startStyles) {
  3987. setStyles(this._element, this._startStyles, this._initialStyles);
  3988. }
  3989. this._state = 1 /* Started */;
  3990. }
  3991. };
  3992. SpecialCasedStyles.prototype.finish = function () {
  3993. this.start();
  3994. if (this._state < 2 /* Finished */) {
  3995. setStyles(this._element, this._initialStyles);
  3996. if (this._endStyles) {
  3997. setStyles(this._element, this._endStyles);
  3998. this._endStyles = null;
  3999. }
  4000. this._state = 1 /* Started */;
  4001. }
  4002. };
  4003. SpecialCasedStyles.prototype.destroy = function () {
  4004. this.finish();
  4005. if (this._state < 3 /* Destroyed */) {
  4006. SpecialCasedStyles.initialStylesByElement.delete(this._element);
  4007. if (this._startStyles) {
  4008. eraseStyles(this._element, this._startStyles);
  4009. this._endStyles = null;
  4010. }
  4011. if (this._endStyles) {
  4012. eraseStyles(this._element, this._endStyles);
  4013. this._endStyles = null;
  4014. }
  4015. setStyles(this._element, this._initialStyles);
  4016. this._state = 3 /* Destroyed */;
  4017. }
  4018. };
  4019. SpecialCasedStyles.initialStylesByElement = new WeakMap();
  4020. return SpecialCasedStyles;
  4021. }());
  4022. function filterNonAnimatableStyles(styles) {
  4023. var result = null;
  4024. var props = Object.keys(styles);
  4025. for (var i = 0; i < props.length; i++) {
  4026. var prop = props[i];
  4027. if (isNonAnimatableStyle(prop)) {
  4028. result = result || {};
  4029. result[prop] = styles[prop];
  4030. }
  4031. }
  4032. return result;
  4033. }
  4034. function isNonAnimatableStyle(prop) {
  4035. return prop === 'display' || prop === 'position';
  4036. }
  4037. /**
  4038. * @license
  4039. * Copyright Google Inc. All Rights Reserved.
  4040. *
  4041. * Use of this source code is governed by an MIT-style license that can be
  4042. * found in the LICENSE file at https://angular.io/license
  4043. */
  4044. var ELAPSED_TIME_MAX_DECIMAL_PLACES = 3;
  4045. var ANIMATION_PROP = 'animation';
  4046. var ANIMATIONEND_EVENT = 'animationend';
  4047. var ONE_SECOND$1 = 1000;
  4048. var ElementAnimationStyleHandler = /** @class */ (function () {
  4049. function ElementAnimationStyleHandler(_element, _name, _duration, _delay, _easing, _fillMode, _onDoneFn) {
  4050. var _this = this;
  4051. this._element = _element;
  4052. this._name = _name;
  4053. this._duration = _duration;
  4054. this._delay = _delay;
  4055. this._easing = _easing;
  4056. this._fillMode = _fillMode;
  4057. this._onDoneFn = _onDoneFn;
  4058. this._finished = false;
  4059. this._destroyed = false;
  4060. this._startTime = 0;
  4061. this._position = 0;
  4062. this._eventFn = function (e) { return _this._handleCallback(e); };
  4063. }
  4064. ElementAnimationStyleHandler.prototype.apply = function () {
  4065. applyKeyframeAnimation(this._element, this._duration + "ms " + this._easing + " " + this._delay + "ms 1 normal " + this._fillMode + " " + this._name);
  4066. addRemoveAnimationEvent(this._element, this._eventFn, false);
  4067. this._startTime = Date.now();
  4068. };
  4069. ElementAnimationStyleHandler.prototype.pause = function () { playPauseAnimation(this._element, this._name, 'paused'); };
  4070. ElementAnimationStyleHandler.prototype.resume = function () { playPauseAnimation(this._element, this._name, 'running'); };
  4071. ElementAnimationStyleHandler.prototype.setPosition = function (position) {
  4072. var index = findIndexForAnimation(this._element, this._name);
  4073. this._position = position * this._duration;
  4074. setAnimationStyle(this._element, 'Delay', "-" + this._position + "ms", index);
  4075. };
  4076. ElementAnimationStyleHandler.prototype.getPosition = function () { return this._position; };
  4077. ElementAnimationStyleHandler.prototype._handleCallback = function (event) {
  4078. var timestamp = event._ngTestManualTimestamp || Date.now();
  4079. var elapsedTime = parseFloat(event.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES)) * ONE_SECOND$1;
  4080. if (event.animationName == this._name &&
  4081. Math.max(timestamp - this._startTime, 0) >= this._delay && elapsedTime >= this._duration) {
  4082. this.finish();
  4083. }
  4084. };
  4085. ElementAnimationStyleHandler.prototype.finish = function () {
  4086. if (this._finished)
  4087. return;
  4088. this._finished = true;
  4089. this._onDoneFn();
  4090. addRemoveAnimationEvent(this._element, this._eventFn, true);
  4091. };
  4092. ElementAnimationStyleHandler.prototype.destroy = function () {
  4093. if (this._destroyed)
  4094. return;
  4095. this._destroyed = true;
  4096. this.finish();
  4097. removeKeyframeAnimation(this._element, this._name);
  4098. };
  4099. return ElementAnimationStyleHandler;
  4100. }());
  4101. function playPauseAnimation(element, name, status) {
  4102. var index = findIndexForAnimation(element, name);
  4103. setAnimationStyle(element, 'PlayState', status, index);
  4104. }
  4105. function applyKeyframeAnimation(element, value) {
  4106. var anim = getAnimationStyle(element, '').trim();
  4107. var index = 0;
  4108. if (anim.length) {
  4109. index = countChars(anim, ',') + 1;
  4110. value = anim + ", " + value;
  4111. }
  4112. setAnimationStyle(element, '', value);
  4113. return index;
  4114. }
  4115. function removeKeyframeAnimation(element, name) {
  4116. var anim = getAnimationStyle(element, '');
  4117. var tokens = anim.split(',');
  4118. var index = findMatchingTokenIndex(tokens, name);
  4119. if (index >= 0) {
  4120. tokens.splice(index, 1);
  4121. var newValue = tokens.join(',');
  4122. setAnimationStyle(element, '', newValue);
  4123. }
  4124. }
  4125. function findIndexForAnimation(element, value) {
  4126. var anim = getAnimationStyle(element, '');
  4127. if (anim.indexOf(',') > 0) {
  4128. var tokens = anim.split(',');
  4129. return findMatchingTokenIndex(tokens, value);
  4130. }
  4131. return findMatchingTokenIndex([anim], value);
  4132. }
  4133. function findMatchingTokenIndex(tokens, searchToken) {
  4134. for (var i = 0; i < tokens.length; i++) {
  4135. if (tokens[i].indexOf(searchToken) >= 0) {
  4136. return i;
  4137. }
  4138. }
  4139. return -1;
  4140. }
  4141. function addRemoveAnimationEvent(element, fn, doRemove) {
  4142. doRemove ? element.removeEventListener(ANIMATIONEND_EVENT, fn) :
  4143. element.addEventListener(ANIMATIONEND_EVENT, fn);
  4144. }
  4145. function setAnimationStyle(element, name, value, index) {
  4146. var prop = ANIMATION_PROP + name;
  4147. if (index != null) {
  4148. var oldValue = element.style[prop];
  4149. if (oldValue.length) {
  4150. var tokens = oldValue.split(',');
  4151. tokens[index] = value;
  4152. value = tokens.join(',');
  4153. }
  4154. }
  4155. element.style[prop] = value;
  4156. }
  4157. function getAnimationStyle(element, name) {
  4158. return element.style[ANIMATION_PROP + name];
  4159. }
  4160. function countChars(value, char) {
  4161. var count = 0;
  4162. for (var i = 0; i < value.length; i++) {
  4163. var c = value.charAt(i);
  4164. if (c === char)
  4165. count++;
  4166. }
  4167. return count;
  4168. }
  4169. var DEFAULT_FILL_MODE = 'forwards';
  4170. var DEFAULT_EASING = 'linear';
  4171. var CssKeyframesPlayer = /** @class */ (function () {
  4172. function CssKeyframesPlayer(element, keyframes, animationName, _duration, _delay, easing, _finalStyles, _specialStyles) {
  4173. this.element = element;
  4174. this.keyframes = keyframes;
  4175. this.animationName = animationName;
  4176. this._duration = _duration;
  4177. this._delay = _delay;
  4178. this._finalStyles = _finalStyles;
  4179. this._specialStyles = _specialStyles;
  4180. this._onDoneFns = [];
  4181. this._onStartFns = [];
  4182. this._onDestroyFns = [];
  4183. this._started = false;
  4184. this.currentSnapshot = {};
  4185. this._state = 0;
  4186. this.easing = easing || DEFAULT_EASING;
  4187. this.totalTime = _duration + _delay;
  4188. this._buildStyler();
  4189. }
  4190. CssKeyframesPlayer.prototype.onStart = function (fn) { this._onStartFns.push(fn); };
  4191. CssKeyframesPlayer.prototype.onDone = function (fn) { this._onDoneFns.push(fn); };
  4192. CssKeyframesPlayer.prototype.onDestroy = function (fn) { this._onDestroyFns.push(fn); };
  4193. CssKeyframesPlayer.prototype.destroy = function () {
  4194. this.init();
  4195. if (this._state >= 4 /* DESTROYED */)
  4196. return;
  4197. this._state = 4 /* DESTROYED */;
  4198. this._styler.destroy();
  4199. this._flushStartFns();
  4200. this._flushDoneFns();
  4201. if (this._specialStyles) {
  4202. this._specialStyles.destroy();
  4203. }
  4204. this._onDestroyFns.forEach(function (fn) { return fn(); });
  4205. this._onDestroyFns = [];
  4206. };
  4207. CssKeyframesPlayer.prototype._flushDoneFns = function () {
  4208. this._onDoneFns.forEach(function (fn) { return fn(); });
  4209. this._onDoneFns = [];
  4210. };
  4211. CssKeyframesPlayer.prototype._flushStartFns = function () {
  4212. this._onStartFns.forEach(function (fn) { return fn(); });
  4213. this._onStartFns = [];
  4214. };
  4215. CssKeyframesPlayer.prototype.finish = function () {
  4216. this.init();
  4217. if (this._state >= 3 /* FINISHED */)
  4218. return;
  4219. this._state = 3 /* FINISHED */;
  4220. this._styler.finish();
  4221. this._flushStartFns();
  4222. if (this._specialStyles) {
  4223. this._specialStyles.finish();
  4224. }
  4225. this._flushDoneFns();
  4226. };
  4227. CssKeyframesPlayer.prototype.setPosition = function (value) { this._styler.setPosition(value); };
  4228. CssKeyframesPlayer.prototype.getPosition = function () { return this._styler.getPosition(); };
  4229. CssKeyframesPlayer.prototype.hasStarted = function () { return this._state >= 2 /* STARTED */; };
  4230. CssKeyframesPlayer.prototype.init = function () {
  4231. if (this._state >= 1 /* INITIALIZED */)
  4232. return;
  4233. this._state = 1 /* INITIALIZED */;
  4234. var elm = this.element;
  4235. this._styler.apply();
  4236. if (this._delay) {
  4237. this._styler.pause();
  4238. }
  4239. };
  4240. CssKeyframesPlayer.prototype.play = function () {
  4241. this.init();
  4242. if (!this.hasStarted()) {
  4243. this._flushStartFns();
  4244. this._state = 2 /* STARTED */;
  4245. if (this._specialStyles) {
  4246. this._specialStyles.start();
  4247. }
  4248. }
  4249. this._styler.resume();
  4250. };
  4251. CssKeyframesPlayer.prototype.pause = function () {
  4252. this.init();
  4253. this._styler.pause();
  4254. };
  4255. CssKeyframesPlayer.prototype.restart = function () {
  4256. this.reset();
  4257. this.play();
  4258. };
  4259. CssKeyframesPlayer.prototype.reset = function () {
  4260. this._styler.destroy();
  4261. this._buildStyler();
  4262. this._styler.apply();
  4263. };
  4264. CssKeyframesPlayer.prototype._buildStyler = function () {
  4265. var _this = this;
  4266. this._styler = new ElementAnimationStyleHandler(this.element, this.animationName, this._duration, this._delay, this.easing, DEFAULT_FILL_MODE, function () { return _this.finish(); });
  4267. };
  4268. /** @internal */
  4269. CssKeyframesPlayer.prototype.triggerCallback = function (phaseName) {
  4270. var methods = phaseName == 'start' ? this._onStartFns : this._onDoneFns;
  4271. methods.forEach(function (fn) { return fn(); });
  4272. methods.length = 0;
  4273. };
  4274. CssKeyframesPlayer.prototype.beforeDestroy = function () {
  4275. var _this = this;
  4276. this.init();
  4277. var styles = {};
  4278. if (this.hasStarted()) {
  4279. var finished_1 = this._state >= 3 /* FINISHED */;
  4280. Object.keys(this._finalStyles).forEach(function (prop) {
  4281. if (prop != 'offset') {
  4282. styles[prop] = finished_1 ? _this._finalStyles[prop] : computeStyle(_this.element, prop);
  4283. }
  4284. });
  4285. }
  4286. this.currentSnapshot = styles;
  4287. };
  4288. return CssKeyframesPlayer;
  4289. }());
  4290. var DirectStylePlayer = /** @class */ (function (_super) {
  4291. __extends(DirectStylePlayer, _super);
  4292. function DirectStylePlayer(element, styles) {
  4293. var _this = _super.call(this) || this;
  4294. _this.element = element;
  4295. _this._startingStyles = {};
  4296. _this.__initialized = false;
  4297. _this._styles = hypenatePropsObject(styles);
  4298. return _this;
  4299. }
  4300. DirectStylePlayer.prototype.init = function () {
  4301. var _this = this;
  4302. if (this.__initialized || !this._startingStyles)
  4303. return;
  4304. this.__initialized = true;
  4305. Object.keys(this._styles).forEach(function (prop) {
  4306. _this._startingStyles[prop] = _this.element.style[prop];
  4307. });
  4308. _super.prototype.init.call(this);
  4309. };
  4310. DirectStylePlayer.prototype.play = function () {
  4311. var _this = this;
  4312. if (!this._startingStyles)
  4313. return;
  4314. this.init();
  4315. Object.keys(this._styles)
  4316. .forEach(function (prop) { return _this.element.style.setProperty(prop, _this._styles[prop]); });
  4317. _super.prototype.play.call(this);
  4318. };
  4319. DirectStylePlayer.prototype.destroy = function () {
  4320. var _this = this;
  4321. if (!this._startingStyles)
  4322. return;
  4323. Object.keys(this._startingStyles).forEach(function (prop) {
  4324. var value = _this._startingStyles[prop];
  4325. if (value) {
  4326. _this.element.style.setProperty(prop, value);
  4327. }
  4328. else {
  4329. _this.element.style.removeProperty(prop);
  4330. }
  4331. });
  4332. this._startingStyles = null;
  4333. _super.prototype.destroy.call(this);
  4334. };
  4335. return DirectStylePlayer;
  4336. }(animations.NoopAnimationPlayer));
  4337. var KEYFRAMES_NAME_PREFIX = 'gen_css_kf_';
  4338. var TAB_SPACE = ' ';
  4339. var CssKeyframesDriver = /** @class */ (function () {
  4340. function CssKeyframesDriver() {
  4341. this._count = 0;
  4342. this._head = document.querySelector('head');
  4343. this._warningIssued = false;
  4344. }
  4345. CssKeyframesDriver.prototype.validateStyleProperty = function (prop) { return validateStyleProperty(prop); };
  4346. CssKeyframesDriver.prototype.matchesElement = function (element, selector) {
  4347. return matchesElement(element, selector);
  4348. };
  4349. CssKeyframesDriver.prototype.containsElement = function (elm1, elm2) { return containsElement(elm1, elm2); };
  4350. CssKeyframesDriver.prototype.query = function (element, selector, multi) {
  4351. return invokeQuery(element, selector, multi);
  4352. };
  4353. CssKeyframesDriver.prototype.computeStyle = function (element, prop, defaultValue) {
  4354. return window.getComputedStyle(element)[prop];
  4355. };
  4356. CssKeyframesDriver.prototype.buildKeyframeElement = function (element, name, keyframes) {
  4357. keyframes = keyframes.map(function (kf) { return hypenatePropsObject(kf); });
  4358. var keyframeStr = "@keyframes " + name + " {\n";
  4359. var tab = '';
  4360. keyframes.forEach(function (kf) {
  4361. tab = TAB_SPACE;
  4362. var offset = parseFloat(kf['offset']);
  4363. keyframeStr += "" + tab + offset * 100 + "% {\n";
  4364. tab += TAB_SPACE;
  4365. Object.keys(kf).forEach(function (prop) {
  4366. var value = kf[prop];
  4367. switch (prop) {
  4368. case 'offset':
  4369. return;
  4370. case 'easing':
  4371. if (value) {
  4372. keyframeStr += tab + "animation-timing-function: " + value + ";\n";
  4373. }
  4374. return;
  4375. default:
  4376. keyframeStr += "" + tab + prop + ": " + value + ";\n";
  4377. return;
  4378. }
  4379. });
  4380. keyframeStr += tab + "}\n";
  4381. });
  4382. keyframeStr += "}\n";
  4383. var kfElm = document.createElement('style');
  4384. kfElm.innerHTML = keyframeStr;
  4385. return kfElm;
  4386. };
  4387. CssKeyframesDriver.prototype.animate = function (element, keyframes, duration, delay, easing, previousPlayers, scrubberAccessRequested) {
  4388. if (previousPlayers === void 0) { previousPlayers = []; }
  4389. if (scrubberAccessRequested) {
  4390. this._notifyFaultyScrubber();
  4391. }
  4392. var previousCssKeyframePlayers = previousPlayers.filter(function (player) { return player instanceof CssKeyframesPlayer; });
  4393. var previousStyles = {};
  4394. if (allowPreviousPlayerStylesMerge(duration, delay)) {
  4395. previousCssKeyframePlayers.forEach(function (player) {
  4396. var styles = player.currentSnapshot;
  4397. Object.keys(styles).forEach(function (prop) { return previousStyles[prop] = styles[prop]; });
  4398. });
  4399. }
  4400. keyframes = balancePreviousStylesIntoKeyframes(element, keyframes, previousStyles);
  4401. var finalStyles = flattenKeyframesIntoStyles(keyframes);
  4402. // if there is no animation then there is no point in applying
  4403. // styles and waiting for an event to get fired. This causes lag.
  4404. // It's better to just directly apply the styles to the element
  4405. // via the direct styling animation player.
  4406. if (duration == 0) {
  4407. return new DirectStylePlayer(element, finalStyles);
  4408. }
  4409. var animationName = "" + KEYFRAMES_NAME_PREFIX + this._count++;
  4410. var kfElm = this.buildKeyframeElement(element, animationName, keyframes);
  4411. document.querySelector('head').appendChild(kfElm);
  4412. var specialStyles = packageNonAnimatableStyles(element, keyframes);
  4413. var player = new CssKeyframesPlayer(element, keyframes, animationName, duration, delay, easing, finalStyles, specialStyles);
  4414. player.onDestroy(function () { return removeElement(kfElm); });
  4415. return player;
  4416. };
  4417. CssKeyframesDriver.prototype._notifyFaultyScrubber = function () {
  4418. if (!this._warningIssued) {
  4419. console.warn('@angular/animations: please load the web-animations.js polyfill to allow programmatic access...\n', ' visit http://bit.ly/IWukam to learn more about using the web-animation-js polyfill.');
  4420. this._warningIssued = true;
  4421. }
  4422. };
  4423. return CssKeyframesDriver;
  4424. }());
  4425. function flattenKeyframesIntoStyles(keyframes) {
  4426. var flatKeyframes = {};
  4427. if (keyframes) {
  4428. var kfs = Array.isArray(keyframes) ? keyframes : [keyframes];
  4429. kfs.forEach(function (kf) {
  4430. Object.keys(kf).forEach(function (prop) {
  4431. if (prop == 'offset' || prop == 'easing')
  4432. return;
  4433. flatKeyframes[prop] = kf[prop];
  4434. });
  4435. });
  4436. }
  4437. return flatKeyframes;
  4438. }
  4439. function removeElement(node) {
  4440. node.parentNode.removeChild(node);
  4441. }
  4442. var WebAnimationsPlayer = /** @class */ (function () {
  4443. function WebAnimationsPlayer(element, keyframes, options, _specialStyles) {
  4444. this.element = element;
  4445. this.keyframes = keyframes;
  4446. this.options = options;
  4447. this._specialStyles = _specialStyles;
  4448. this._onDoneFns = [];
  4449. this._onStartFns = [];
  4450. this._onDestroyFns = [];
  4451. this._initialized = false;
  4452. this._finished = false;
  4453. this._started = false;
  4454. this._destroyed = false;
  4455. this.time = 0;
  4456. this.parentPlayer = null;
  4457. this.currentSnapshot = {};
  4458. this._duration = options['duration'];
  4459. this._delay = options['delay'] || 0;
  4460. this.time = this._duration + this._delay;
  4461. }
  4462. WebAnimationsPlayer.prototype._onFinish = function () {
  4463. if (!this._finished) {
  4464. this._finished = true;
  4465. this._onDoneFns.forEach(function (fn) { return fn(); });
  4466. this._onDoneFns = [];
  4467. }
  4468. };
  4469. WebAnimationsPlayer.prototype.init = function () {
  4470. this._buildPlayer();
  4471. this._preparePlayerBeforeStart();
  4472. };
  4473. WebAnimationsPlayer.prototype._buildPlayer = function () {
  4474. var _this = this;
  4475. if (this._initialized)
  4476. return;
  4477. this._initialized = true;
  4478. var keyframes = this.keyframes;
  4479. this.domPlayer =
  4480. this._triggerWebAnimation(this.element, keyframes, this.options);
  4481. this._finalKeyframe = keyframes.length ? keyframes[keyframes.length - 1] : {};
  4482. this.domPlayer.addEventListener('finish', function () { return _this._onFinish(); });
  4483. };
  4484. WebAnimationsPlayer.prototype._preparePlayerBeforeStart = function () {
  4485. // this is required so that the player doesn't start to animate right away
  4486. if (this._delay) {
  4487. this._resetDomPlayerState();
  4488. }
  4489. else {
  4490. this.domPlayer.pause();
  4491. }
  4492. };
  4493. /** @internal */
  4494. WebAnimationsPlayer.prototype._triggerWebAnimation = function (element, keyframes, options) {
  4495. // jscompiler doesn't seem to know animate is a native property because it's not fully
  4496. // supported yet across common browsers (we polyfill it for Edge/Safari) [CL #143630929]
  4497. return element['animate'](keyframes, options);
  4498. };
  4499. WebAnimationsPlayer.prototype.onStart = function (fn) { this._onStartFns.push(fn); };
  4500. WebAnimationsPlayer.prototype.onDone = function (fn) { this._onDoneFns.push(fn); };
  4501. WebAnimationsPlayer.prototype.onDestroy = function (fn) { this._onDestroyFns.push(fn); };
  4502. WebAnimationsPlayer.prototype.play = function () {
  4503. this._buildPlayer();
  4504. if (!this.hasStarted()) {
  4505. this._onStartFns.forEach(function (fn) { return fn(); });
  4506. this._onStartFns = [];
  4507. this._started = true;
  4508. if (this._specialStyles) {
  4509. this._specialStyles.start();
  4510. }
  4511. }
  4512. this.domPlayer.play();
  4513. };
  4514. WebAnimationsPlayer.prototype.pause = function () {
  4515. this.init();
  4516. this.domPlayer.pause();
  4517. };
  4518. WebAnimationsPlayer.prototype.finish = function () {
  4519. this.init();
  4520. if (this._specialStyles) {
  4521. this._specialStyles.finish();
  4522. }
  4523. this._onFinish();
  4524. this.domPlayer.finish();
  4525. };
  4526. WebAnimationsPlayer.prototype.reset = function () {
  4527. this._resetDomPlayerState();
  4528. this._destroyed = false;
  4529. this._finished = false;
  4530. this._started = false;
  4531. };
  4532. WebAnimationsPlayer.prototype._resetDomPlayerState = function () {
  4533. if (this.domPlayer) {
  4534. this.domPlayer.cancel();
  4535. }
  4536. };
  4537. WebAnimationsPlayer.prototype.restart = function () {
  4538. this.reset();
  4539. this.play();
  4540. };
  4541. WebAnimationsPlayer.prototype.hasStarted = function () { return this._started; };
  4542. WebAnimationsPlayer.prototype.destroy = function () {
  4543. if (!this._destroyed) {
  4544. this._destroyed = true;
  4545. this._resetDomPlayerState();
  4546. this._onFinish();
  4547. if (this._specialStyles) {
  4548. this._specialStyles.destroy();
  4549. }
  4550. this._onDestroyFns.forEach(function (fn) { return fn(); });
  4551. this._onDestroyFns = [];
  4552. }
  4553. };
  4554. WebAnimationsPlayer.prototype.setPosition = function (p) { this.domPlayer.currentTime = p * this.time; };
  4555. WebAnimationsPlayer.prototype.getPosition = function () { return this.domPlayer.currentTime / this.time; };
  4556. Object.defineProperty(WebAnimationsPlayer.prototype, "totalTime", {
  4557. get: function () { return this._delay + this._duration; },
  4558. enumerable: true,
  4559. configurable: true
  4560. });
  4561. WebAnimationsPlayer.prototype.beforeDestroy = function () {
  4562. var _this = this;
  4563. var styles = {};
  4564. if (this.hasStarted()) {
  4565. Object.keys(this._finalKeyframe).forEach(function (prop) {
  4566. if (prop != 'offset') {
  4567. styles[prop] =
  4568. _this._finished ? _this._finalKeyframe[prop] : computeStyle(_this.element, prop);
  4569. }
  4570. });
  4571. }
  4572. this.currentSnapshot = styles;
  4573. };
  4574. /** @internal */
  4575. WebAnimationsPlayer.prototype.triggerCallback = function (phaseName) {
  4576. var methods = phaseName == 'start' ? this._onStartFns : this._onDoneFns;
  4577. methods.forEach(function (fn) { return fn(); });
  4578. methods.length = 0;
  4579. };
  4580. return WebAnimationsPlayer;
  4581. }());
  4582. var WebAnimationsDriver = /** @class */ (function () {
  4583. function WebAnimationsDriver() {
  4584. this._isNativeImpl = /\{\s*\[native\s+code\]\s*\}/.test(getElementAnimateFn().toString());
  4585. this._cssKeyframesDriver = new CssKeyframesDriver();
  4586. }
  4587. WebAnimationsDriver.prototype.validateStyleProperty = function (prop) { return validateStyleProperty(prop); };
  4588. WebAnimationsDriver.prototype.matchesElement = function (element, selector) {
  4589. return matchesElement(element, selector);
  4590. };
  4591. WebAnimationsDriver.prototype.containsElement = function (elm1, elm2) { return containsElement(elm1, elm2); };
  4592. WebAnimationsDriver.prototype.query = function (element, selector, multi) {
  4593. return invokeQuery(element, selector, multi);
  4594. };
  4595. WebAnimationsDriver.prototype.computeStyle = function (element, prop, defaultValue) {
  4596. return window.getComputedStyle(element)[prop];
  4597. };
  4598. WebAnimationsDriver.prototype.overrideWebAnimationsSupport = function (supported) { this._isNativeImpl = supported; };
  4599. WebAnimationsDriver.prototype.animate = function (element, keyframes, duration, delay, easing, previousPlayers, scrubberAccessRequested) {
  4600. if (previousPlayers === void 0) { previousPlayers = []; }
  4601. var useKeyframes = !scrubberAccessRequested && !this._isNativeImpl;
  4602. if (useKeyframes) {
  4603. return this._cssKeyframesDriver.animate(element, keyframes, duration, delay, easing, previousPlayers);
  4604. }
  4605. var fill = delay == 0 ? 'both' : 'forwards';
  4606. var playerOptions = { duration: duration, delay: delay, fill: fill };
  4607. // we check for this to avoid having a null|undefined value be present
  4608. // for the easing (which results in an error for certain browsers #9752)
  4609. if (easing) {
  4610. playerOptions['easing'] = easing;
  4611. }
  4612. var previousStyles = {};
  4613. var previousWebAnimationPlayers = previousPlayers.filter(function (player) { return player instanceof WebAnimationsPlayer; });
  4614. if (allowPreviousPlayerStylesMerge(duration, delay)) {
  4615. previousWebAnimationPlayers.forEach(function (player) {
  4616. var styles = player.currentSnapshot;
  4617. Object.keys(styles).forEach(function (prop) { return previousStyles[prop] = styles[prop]; });
  4618. });
  4619. }
  4620. keyframes = keyframes.map(function (styles) { return copyStyles(styles, false); });
  4621. keyframes = balancePreviousStylesIntoKeyframes(element, keyframes, previousStyles);
  4622. var specialStyles = packageNonAnimatableStyles(element, keyframes);
  4623. return new WebAnimationsPlayer(element, keyframes, playerOptions, specialStyles);
  4624. };
  4625. return WebAnimationsDriver;
  4626. }());
  4627. function supportsWebAnimations() {
  4628. return typeof getElementAnimateFn() === 'function';
  4629. }
  4630. function getElementAnimateFn() {
  4631. return (isBrowser() && Element.prototype['animate']) || {};
  4632. }
  4633. /**
  4634. * @license
  4635. * Copyright Google Inc. All Rights Reserved.
  4636. *
  4637. * Use of this source code is governed by an MIT-style license that can be
  4638. * found in the LICENSE file at https://angular.io/license
  4639. */
  4640. /**
  4641. * @license
  4642. * Copyright Google Inc. All Rights Reserved.
  4643. *
  4644. * Use of this source code is governed by an MIT-style license that can be
  4645. * found in the LICENSE file at https://angular.io/license
  4646. */
  4647. /**
  4648. * @license
  4649. * Copyright Google Inc. All Rights Reserved.
  4650. *
  4651. * Use of this source code is governed by an MIT-style license that can be
  4652. * found in the LICENSE file at https://angular.io/license
  4653. */
  4654. /**
  4655. * @license
  4656. * Copyright Google Inc. All Rights Reserved.
  4657. *
  4658. * Use of this source code is governed by an MIT-style license that can be
  4659. * found in the LICENSE file at https://angular.io/license
  4660. */
  4661. /**
  4662. * Generated bundle index. Do not edit.
  4663. */
  4664. exports.ɵangular_packages_animations_browser_browser_a = SpecialCasedStyles;
  4665. exports.AnimationDriver = AnimationDriver;
  4666. exports.ɵAnimationDriver = AnimationDriver;
  4667. exports.ɵAnimation = Animation;
  4668. exports.ɵAnimationStyleNormalizer = AnimationStyleNormalizer;
  4669. exports.ɵNoopAnimationStyleNormalizer = NoopAnimationStyleNormalizer;
  4670. exports.ɵWebAnimationsStyleNormalizer = WebAnimationsStyleNormalizer;
  4671. exports.ɵNoopAnimationDriver = NoopAnimationDriver;
  4672. exports.ɵAnimationEngine = AnimationEngine;
  4673. exports.ɵCssKeyframesDriver = CssKeyframesDriver;
  4674. exports.ɵCssKeyframesPlayer = CssKeyframesPlayer;
  4675. exports.ɵcontainsElement = containsElement;
  4676. exports.ɵinvokeQuery = invokeQuery;
  4677. exports.ɵmatchesElement = matchesElement;
  4678. exports.ɵvalidateStyleProperty = validateStyleProperty;
  4679. exports.ɵWebAnimationsDriver = WebAnimationsDriver;
  4680. exports.ɵsupportsWebAnimations = supportsWebAnimations;
  4681. exports.ɵWebAnimationsPlayer = WebAnimationsPlayer;
  4682. exports.ɵallowPreviousPlayerStylesMerge = allowPreviousPlayerStylesMerge;
  4683. Object.defineProperty(exports, '__esModule', { value: true });
  4684. }));
  4685. //# sourceMappingURL=animations-browser.umd.js.map