browser.mjs 191 KB

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