runtime-core.esm-bundler.js 308 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941
  1. import { pauseTracking, resetTracking, isRef, toRaw, isShallow as isShallow$1, isReactive, ReactiveEffect, ref, shallowReadonly, track, reactive, shallowReactive, trigger, isProxy, EffectScope, markRaw, proxyRefs, computed as computed$1, isReadonly } from '@vue/reactivity';
  2. export { EffectScope, ReactiveEffect, customRef, effect, effectScope, getCurrentScope, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onScopeDispose, proxyRefs, reactive, readonly, ref, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, triggerRef, unref } from '@vue/reactivity';
  3. import { isString, isFunction, isPromise, isArray, NOOP, getGlobalThis, extend, EMPTY_OBJ, toHandlerKey, toNumber, hyphenate, camelize, isObject, isOn, hasOwn, isModelListener, hasChanged, remove, isSet, isMap, isPlainObject, invokeArrayFns, isBuiltInDirective, capitalize, isGloballyWhitelisted, def, isReservedProp, EMPTY_ARR, toRawType, makeMap, NO, normalizeClass, normalizeStyle } from '@vue/shared';
  4. export { camelize, capitalize, normalizeClass, normalizeProps, normalizeStyle, toDisplayString, toHandlerKey } from '@vue/shared';
  5. const stack = [];
  6. function pushWarningContext(vnode) {
  7. stack.push(vnode);
  8. }
  9. function popWarningContext() {
  10. stack.pop();
  11. }
  12. function warn(msg, ...args) {
  13. if (!(process.env.NODE_ENV !== 'production'))
  14. return;
  15. // avoid props formatting or warn handler tracking deps that might be mutated
  16. // during patch, leading to infinite recursion.
  17. pauseTracking();
  18. const instance = stack.length ? stack[stack.length - 1].component : null;
  19. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  20. const trace = getComponentTrace();
  21. if (appWarnHandler) {
  22. callWithErrorHandling(appWarnHandler, instance, 11 /* ErrorCodes.APP_WARN_HANDLER */, [
  23. msg + args.join(''),
  24. instance && instance.proxy,
  25. trace
  26. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  27. .join('\n'),
  28. trace
  29. ]);
  30. }
  31. else {
  32. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  33. /* istanbul ignore if */
  34. if (trace.length &&
  35. // avoid spamming console during tests
  36. !false) {
  37. warnArgs.push(`\n`, ...formatTrace(trace));
  38. }
  39. console.warn(...warnArgs);
  40. }
  41. resetTracking();
  42. }
  43. function getComponentTrace() {
  44. let currentVNode = stack[stack.length - 1];
  45. if (!currentVNode) {
  46. return [];
  47. }
  48. // we can't just use the stack because it will be incomplete during updates
  49. // that did not start from the root. Re-construct the parent chain using
  50. // instance parent pointers.
  51. const normalizedStack = [];
  52. while (currentVNode) {
  53. const last = normalizedStack[0];
  54. if (last && last.vnode === currentVNode) {
  55. last.recurseCount++;
  56. }
  57. else {
  58. normalizedStack.push({
  59. vnode: currentVNode,
  60. recurseCount: 0
  61. });
  62. }
  63. const parentInstance = currentVNode.component && currentVNode.component.parent;
  64. currentVNode = parentInstance && parentInstance.vnode;
  65. }
  66. return normalizedStack;
  67. }
  68. /* istanbul ignore next */
  69. function formatTrace(trace) {
  70. const logs = [];
  71. trace.forEach((entry, i) => {
  72. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  73. });
  74. return logs;
  75. }
  76. function formatTraceEntry({ vnode, recurseCount }) {
  77. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  78. const isRoot = vnode.component ? vnode.component.parent == null : false;
  79. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  80. const close = `>` + postfix;
  81. return vnode.props
  82. ? [open, ...formatProps(vnode.props), close]
  83. : [open + close];
  84. }
  85. /* istanbul ignore next */
  86. function formatProps(props) {
  87. const res = [];
  88. const keys = Object.keys(props);
  89. keys.slice(0, 3).forEach(key => {
  90. res.push(...formatProp(key, props[key]));
  91. });
  92. if (keys.length > 3) {
  93. res.push(` ...`);
  94. }
  95. return res;
  96. }
  97. /* istanbul ignore next */
  98. function formatProp(key, value, raw) {
  99. if (isString(value)) {
  100. value = JSON.stringify(value);
  101. return raw ? value : [`${key}=${value}`];
  102. }
  103. else if (typeof value === 'number' ||
  104. typeof value === 'boolean' ||
  105. value == null) {
  106. return raw ? value : [`${key}=${value}`];
  107. }
  108. else if (isRef(value)) {
  109. value = formatProp(key, toRaw(value.value), true);
  110. return raw ? value : [`${key}=Ref<`, value, `>`];
  111. }
  112. else if (isFunction(value)) {
  113. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  114. }
  115. else {
  116. value = toRaw(value);
  117. return raw ? value : [`${key}=`, value];
  118. }
  119. }
  120. const ErrorTypeStrings = {
  121. ["sp" /* LifecycleHooks.SERVER_PREFETCH */]: 'serverPrefetch hook',
  122. ["bc" /* LifecycleHooks.BEFORE_CREATE */]: 'beforeCreate hook',
  123. ["c" /* LifecycleHooks.CREATED */]: 'created hook',
  124. ["bm" /* LifecycleHooks.BEFORE_MOUNT */]: 'beforeMount hook',
  125. ["m" /* LifecycleHooks.MOUNTED */]: 'mounted hook',
  126. ["bu" /* LifecycleHooks.BEFORE_UPDATE */]: 'beforeUpdate hook',
  127. ["u" /* LifecycleHooks.UPDATED */]: 'updated',
  128. ["bum" /* LifecycleHooks.BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  129. ["um" /* LifecycleHooks.UNMOUNTED */]: 'unmounted hook',
  130. ["a" /* LifecycleHooks.ACTIVATED */]: 'activated hook',
  131. ["da" /* LifecycleHooks.DEACTIVATED */]: 'deactivated hook',
  132. ["ec" /* LifecycleHooks.ERROR_CAPTURED */]: 'errorCaptured hook',
  133. ["rtc" /* LifecycleHooks.RENDER_TRACKED */]: 'renderTracked hook',
  134. ["rtg" /* LifecycleHooks.RENDER_TRIGGERED */]: 'renderTriggered hook',
  135. [0 /* ErrorCodes.SETUP_FUNCTION */]: 'setup function',
  136. [1 /* ErrorCodes.RENDER_FUNCTION */]: 'render function',
  137. [2 /* ErrorCodes.WATCH_GETTER */]: 'watcher getter',
  138. [3 /* ErrorCodes.WATCH_CALLBACK */]: 'watcher callback',
  139. [4 /* ErrorCodes.WATCH_CLEANUP */]: 'watcher cleanup function',
  140. [5 /* ErrorCodes.NATIVE_EVENT_HANDLER */]: 'native event handler',
  141. [6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */]: 'component event handler',
  142. [7 /* ErrorCodes.VNODE_HOOK */]: 'vnode hook',
  143. [8 /* ErrorCodes.DIRECTIVE_HOOK */]: 'directive hook',
  144. [9 /* ErrorCodes.TRANSITION_HOOK */]: 'transition hook',
  145. [10 /* ErrorCodes.APP_ERROR_HANDLER */]: 'app errorHandler',
  146. [11 /* ErrorCodes.APP_WARN_HANDLER */]: 'app warnHandler',
  147. [12 /* ErrorCodes.FUNCTION_REF */]: 'ref function',
  148. [13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */]: 'async component loader',
  149. [14 /* ErrorCodes.SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  150. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  151. };
  152. function callWithErrorHandling(fn, instance, type, args) {
  153. let res;
  154. try {
  155. res = args ? fn(...args) : fn();
  156. }
  157. catch (err) {
  158. handleError(err, instance, type);
  159. }
  160. return res;
  161. }
  162. function callWithAsyncErrorHandling(fn, instance, type, args) {
  163. if (isFunction(fn)) {
  164. const res = callWithErrorHandling(fn, instance, type, args);
  165. if (res && isPromise(res)) {
  166. res.catch(err => {
  167. handleError(err, instance, type);
  168. });
  169. }
  170. return res;
  171. }
  172. const values = [];
  173. for (let i = 0; i < fn.length; i++) {
  174. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  175. }
  176. return values;
  177. }
  178. function handleError(err, instance, type, throwInDev = true) {
  179. const contextVNode = instance ? instance.vnode : null;
  180. if (instance) {
  181. let cur = instance.parent;
  182. // the exposed instance is the render proxy to keep it consistent with 2.x
  183. const exposedInstance = instance.proxy;
  184. // in production the hook receives only the error code
  185. const errorInfo = (process.env.NODE_ENV !== 'production') ? ErrorTypeStrings[type] : type;
  186. while (cur) {
  187. const errorCapturedHooks = cur.ec;
  188. if (errorCapturedHooks) {
  189. for (let i = 0; i < errorCapturedHooks.length; i++) {
  190. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  191. return;
  192. }
  193. }
  194. }
  195. cur = cur.parent;
  196. }
  197. // app-level handling
  198. const appErrorHandler = instance.appContext.config.errorHandler;
  199. if (appErrorHandler) {
  200. callWithErrorHandling(appErrorHandler, null, 10 /* ErrorCodes.APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  201. return;
  202. }
  203. }
  204. logError(err, type, contextVNode, throwInDev);
  205. }
  206. function logError(err, type, contextVNode, throwInDev = true) {
  207. if ((process.env.NODE_ENV !== 'production')) {
  208. const info = ErrorTypeStrings[type];
  209. if (contextVNode) {
  210. pushWarningContext(contextVNode);
  211. }
  212. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  213. if (contextVNode) {
  214. popWarningContext();
  215. }
  216. // crash in dev by default so it's more noticeable
  217. if (throwInDev) {
  218. throw err;
  219. }
  220. else {
  221. console.error(err);
  222. }
  223. }
  224. else {
  225. // recover in prod to reduce the impact on end-user
  226. console.error(err);
  227. }
  228. }
  229. let isFlushing = false;
  230. let isFlushPending = false;
  231. const queue = [];
  232. let flushIndex = 0;
  233. const pendingPostFlushCbs = [];
  234. let activePostFlushCbs = null;
  235. let postFlushIndex = 0;
  236. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  237. let currentFlushPromise = null;
  238. const RECURSION_LIMIT = 100;
  239. function nextTick(fn) {
  240. const p = currentFlushPromise || resolvedPromise;
  241. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  242. }
  243. // #2768
  244. // Use binary-search to find a suitable position in the queue,
  245. // so that the queue maintains the increasing order of job's id,
  246. // which can prevent the job from being skipped and also can avoid repeated patching.
  247. function findInsertionIndex(id) {
  248. // the start index should be `flushIndex + 1`
  249. let start = flushIndex + 1;
  250. let end = queue.length;
  251. while (start < end) {
  252. const middle = (start + end) >>> 1;
  253. const middleJobId = getId(queue[middle]);
  254. middleJobId < id ? (start = middle + 1) : (end = middle);
  255. }
  256. return start;
  257. }
  258. function queueJob(job) {
  259. // the dedupe search uses the startIndex argument of Array.includes()
  260. // by default the search index includes the current job that is being run
  261. // so it cannot recursively trigger itself again.
  262. // if the job is a watch() callback, the search will start with a +1 index to
  263. // allow it recursively trigger itself - it is the user's responsibility to
  264. // ensure it doesn't end up in an infinite loop.
  265. if (!queue.length ||
  266. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
  267. if (job.id == null) {
  268. queue.push(job);
  269. }
  270. else {
  271. queue.splice(findInsertionIndex(job.id), 0, job);
  272. }
  273. queueFlush();
  274. }
  275. }
  276. function queueFlush() {
  277. if (!isFlushing && !isFlushPending) {
  278. isFlushPending = true;
  279. currentFlushPromise = resolvedPromise.then(flushJobs);
  280. }
  281. }
  282. function invalidateJob(job) {
  283. const i = queue.indexOf(job);
  284. if (i > flushIndex) {
  285. queue.splice(i, 1);
  286. }
  287. }
  288. function queuePostFlushCb(cb) {
  289. if (!isArray(cb)) {
  290. if (!activePostFlushCbs ||
  291. !activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
  292. pendingPostFlushCbs.push(cb);
  293. }
  294. }
  295. else {
  296. // if cb is an array, it is a component lifecycle hook which can only be
  297. // triggered by a job, which is already deduped in the main queue, so
  298. // we can skip duplicate check here to improve perf
  299. pendingPostFlushCbs.push(...cb);
  300. }
  301. queueFlush();
  302. }
  303. function flushPreFlushCbs(seen,
  304. // if currently flushing, skip the current job itself
  305. i = isFlushing ? flushIndex + 1 : 0) {
  306. if ((process.env.NODE_ENV !== 'production')) {
  307. seen = seen || new Map();
  308. }
  309. for (; i < queue.length; i++) {
  310. const cb = queue[i];
  311. if (cb && cb.pre) {
  312. if ((process.env.NODE_ENV !== 'production') && checkRecursiveUpdates(seen, cb)) {
  313. continue;
  314. }
  315. queue.splice(i, 1);
  316. i--;
  317. cb();
  318. }
  319. }
  320. }
  321. function flushPostFlushCbs(seen) {
  322. if (pendingPostFlushCbs.length) {
  323. const deduped = [...new Set(pendingPostFlushCbs)];
  324. pendingPostFlushCbs.length = 0;
  325. // #1947 already has active queue, nested flushPostFlushCbs call
  326. if (activePostFlushCbs) {
  327. activePostFlushCbs.push(...deduped);
  328. return;
  329. }
  330. activePostFlushCbs = deduped;
  331. if ((process.env.NODE_ENV !== 'production')) {
  332. seen = seen || new Map();
  333. }
  334. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  335. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  336. if ((process.env.NODE_ENV !== 'production') &&
  337. checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  338. continue;
  339. }
  340. activePostFlushCbs[postFlushIndex]();
  341. }
  342. activePostFlushCbs = null;
  343. postFlushIndex = 0;
  344. }
  345. }
  346. const getId = (job) => job.id == null ? Infinity : job.id;
  347. const comparator = (a, b) => {
  348. const diff = getId(a) - getId(b);
  349. if (diff === 0) {
  350. if (a.pre && !b.pre)
  351. return -1;
  352. if (b.pre && !a.pre)
  353. return 1;
  354. }
  355. return diff;
  356. };
  357. function flushJobs(seen) {
  358. isFlushPending = false;
  359. isFlushing = true;
  360. if ((process.env.NODE_ENV !== 'production')) {
  361. seen = seen || new Map();
  362. }
  363. // Sort queue before flush.
  364. // This ensures that:
  365. // 1. Components are updated from parent to child. (because parent is always
  366. // created before the child so its render effect will have smaller
  367. // priority number)
  368. // 2. If a component is unmounted during a parent component's update,
  369. // its update can be skipped.
  370. queue.sort(comparator);
  371. // conditional usage of checkRecursiveUpdate must be determined out of
  372. // try ... catch block since Rollup by default de-optimizes treeshaking
  373. // inside try-catch. This can leave all warning code unshaked. Although
  374. // they would get eventually shaken by a minifier like terser, some minifiers
  375. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  376. const check = (process.env.NODE_ENV !== 'production')
  377. ? (job) => checkRecursiveUpdates(seen, job)
  378. : NOOP;
  379. try {
  380. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  381. const job = queue[flushIndex];
  382. if (job && job.active !== false) {
  383. if ((process.env.NODE_ENV !== 'production') && check(job)) {
  384. continue;
  385. }
  386. // console.log(`running:`, job.id)
  387. callWithErrorHandling(job, null, 14 /* ErrorCodes.SCHEDULER */);
  388. }
  389. }
  390. }
  391. finally {
  392. flushIndex = 0;
  393. queue.length = 0;
  394. flushPostFlushCbs(seen);
  395. isFlushing = false;
  396. currentFlushPromise = null;
  397. // some postFlushCb queued jobs!
  398. // keep flushing until it drains.
  399. if (queue.length || pendingPostFlushCbs.length) {
  400. flushJobs(seen);
  401. }
  402. }
  403. }
  404. function checkRecursiveUpdates(seen, fn) {
  405. if (!seen.has(fn)) {
  406. seen.set(fn, 1);
  407. }
  408. else {
  409. const count = seen.get(fn);
  410. if (count > RECURSION_LIMIT) {
  411. const instance = fn.ownerInstance;
  412. const componentName = instance && getComponentName(instance.type);
  413. warn(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  414. `This means you have a reactive effect that is mutating its own ` +
  415. `dependencies and thus recursively triggering itself. Possible sources ` +
  416. `include component template, render function, updated hook or ` +
  417. `watcher source function.`);
  418. return true;
  419. }
  420. else {
  421. seen.set(fn, count + 1);
  422. }
  423. }
  424. }
  425. /* eslint-disable no-restricted-globals */
  426. let isHmrUpdating = false;
  427. const hmrDirtyComponents = new Set();
  428. // Expose the HMR runtime on the global object
  429. // This makes it entirely tree-shakable without polluting the exports and makes
  430. // it easier to be used in toolings like vue-loader
  431. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  432. // to be set so that its instances can be registered / removed.
  433. if ((process.env.NODE_ENV !== 'production')) {
  434. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  435. createRecord: tryWrap(createRecord),
  436. rerender: tryWrap(rerender),
  437. reload: tryWrap(reload)
  438. };
  439. }
  440. const map = new Map();
  441. function registerHMR(instance) {
  442. const id = instance.type.__hmrId;
  443. let record = map.get(id);
  444. if (!record) {
  445. createRecord(id, instance.type);
  446. record = map.get(id);
  447. }
  448. record.instances.add(instance);
  449. }
  450. function unregisterHMR(instance) {
  451. map.get(instance.type.__hmrId).instances.delete(instance);
  452. }
  453. function createRecord(id, initialDef) {
  454. if (map.has(id)) {
  455. return false;
  456. }
  457. map.set(id, {
  458. initialDef: normalizeClassComponent(initialDef),
  459. instances: new Set()
  460. });
  461. return true;
  462. }
  463. function normalizeClassComponent(component) {
  464. return isClassComponent(component) ? component.__vccOpts : component;
  465. }
  466. function rerender(id, newRender) {
  467. const record = map.get(id);
  468. if (!record) {
  469. return;
  470. }
  471. // update initial record (for not-yet-rendered component)
  472. record.initialDef.render = newRender;
  473. [...record.instances].forEach(instance => {
  474. if (newRender) {
  475. instance.render = newRender;
  476. normalizeClassComponent(instance.type).render = newRender;
  477. }
  478. instance.renderCache = [];
  479. // this flag forces child components with slot content to update
  480. isHmrUpdating = true;
  481. instance.update();
  482. isHmrUpdating = false;
  483. });
  484. }
  485. function reload(id, newComp) {
  486. const record = map.get(id);
  487. if (!record)
  488. return;
  489. newComp = normalizeClassComponent(newComp);
  490. // update initial def (for not-yet-rendered components)
  491. updateComponentDef(record.initialDef, newComp);
  492. // create a snapshot which avoids the set being mutated during updates
  493. const instances = [...record.instances];
  494. for (const instance of instances) {
  495. const oldComp = normalizeClassComponent(instance.type);
  496. if (!hmrDirtyComponents.has(oldComp)) {
  497. // 1. Update existing comp definition to match new one
  498. if (oldComp !== record.initialDef) {
  499. updateComponentDef(oldComp, newComp);
  500. }
  501. // 2. mark definition dirty. This forces the renderer to replace the
  502. // component on patch.
  503. hmrDirtyComponents.add(oldComp);
  504. }
  505. // 3. invalidate options resolution cache
  506. instance.appContext.optionsCache.delete(instance.type);
  507. // 4. actually update
  508. if (instance.ceReload) {
  509. // custom element
  510. hmrDirtyComponents.add(oldComp);
  511. instance.ceReload(newComp.styles);
  512. hmrDirtyComponents.delete(oldComp);
  513. }
  514. else if (instance.parent) {
  515. // 4. Force the parent instance to re-render. This will cause all updated
  516. // components to be unmounted and re-mounted. Queue the update so that we
  517. // don't end up forcing the same parent to re-render multiple times.
  518. queueJob(instance.parent.update);
  519. }
  520. else if (instance.appContext.reload) {
  521. // root instance mounted via createApp() has a reload method
  522. instance.appContext.reload();
  523. }
  524. else if (typeof window !== 'undefined') {
  525. // root instance inside tree created via raw render(). Force reload.
  526. window.location.reload();
  527. }
  528. else {
  529. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  530. }
  531. }
  532. // 5. make sure to cleanup dirty hmr components after update
  533. queuePostFlushCb(() => {
  534. for (const instance of instances) {
  535. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  536. }
  537. });
  538. }
  539. function updateComponentDef(oldComp, newComp) {
  540. extend(oldComp, newComp);
  541. for (const key in oldComp) {
  542. if (key !== '__file' && !(key in newComp)) {
  543. delete oldComp[key];
  544. }
  545. }
  546. }
  547. function tryWrap(fn) {
  548. return (id, arg) => {
  549. try {
  550. return fn(id, arg);
  551. }
  552. catch (e) {
  553. console.error(e);
  554. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  555. `Full reload required.`);
  556. }
  557. };
  558. }
  559. let devtools;
  560. let buffer = [];
  561. let devtoolsNotInstalled = false;
  562. function emit(event, ...args) {
  563. if (devtools) {
  564. devtools.emit(event, ...args);
  565. }
  566. else if (!devtoolsNotInstalled) {
  567. buffer.push({ event, args });
  568. }
  569. }
  570. function setDevtoolsHook(hook, target) {
  571. var _a, _b;
  572. devtools = hook;
  573. if (devtools) {
  574. devtools.enabled = true;
  575. buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
  576. buffer = [];
  577. }
  578. else if (
  579. // handle late devtools injection - only do this if we are in an actual
  580. // browser environment to avoid the timer handle stalling test runner exit
  581. // (#4815)
  582. typeof window !== 'undefined' &&
  583. // some envs mock window but not fully
  584. window.HTMLElement &&
  585. // also exclude jsdom
  586. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  587. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  588. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  589. replay.push((newHook) => {
  590. setDevtoolsHook(newHook, target);
  591. });
  592. // clear buffer after 3s - the user probably doesn't have devtools installed
  593. // at all, and keeping the buffer will cause memory leaks (#4738)
  594. setTimeout(() => {
  595. if (!devtools) {
  596. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  597. devtoolsNotInstalled = true;
  598. buffer = [];
  599. }
  600. }, 3000);
  601. }
  602. else {
  603. // non-browser env, assume not installed
  604. devtoolsNotInstalled = true;
  605. buffer = [];
  606. }
  607. }
  608. function devtoolsInitApp(app, version) {
  609. emit("app:init" /* DevtoolsHooks.APP_INIT */, app, version, {
  610. Fragment,
  611. Text,
  612. Comment,
  613. Static
  614. });
  615. }
  616. function devtoolsUnmountApp(app) {
  617. emit("app:unmount" /* DevtoolsHooks.APP_UNMOUNT */, app);
  618. }
  619. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* DevtoolsHooks.COMPONENT_ADDED */);
  620. const devtoolsComponentUpdated =
  621. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* DevtoolsHooks.COMPONENT_UPDATED */);
  622. const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* DevtoolsHooks.COMPONENT_REMOVED */);
  623. const devtoolsComponentRemoved = (component) => {
  624. if (devtools &&
  625. typeof devtools.cleanupBuffer === 'function' &&
  626. // remove the component if it wasn't buffered
  627. !devtools.cleanupBuffer(component)) {
  628. _devtoolsComponentRemoved(component);
  629. }
  630. };
  631. function createDevtoolsComponentHook(hook) {
  632. return (component) => {
  633. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  634. };
  635. }
  636. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* DevtoolsHooks.PERFORMANCE_START */);
  637. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* DevtoolsHooks.PERFORMANCE_END */);
  638. function createDevtoolsPerformanceHook(hook) {
  639. return (component, type, time) => {
  640. emit(hook, component.appContext.app, component.uid, component, type, time);
  641. };
  642. }
  643. function devtoolsComponentEmit(component, event, params) {
  644. emit("component:emit" /* DevtoolsHooks.COMPONENT_EMIT */, component.appContext.app, component, event, params);
  645. }
  646. function emit$1(instance, event, ...rawArgs) {
  647. if (instance.isUnmounted)
  648. return;
  649. const props = instance.vnode.props || EMPTY_OBJ;
  650. if ((process.env.NODE_ENV !== 'production')) {
  651. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  652. if (emitsOptions) {
  653. if (!(event in emitsOptions) &&
  654. !(false )) {
  655. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  656. warn(`Component emitted event "${event}" but it is neither declared in ` +
  657. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  658. }
  659. }
  660. else {
  661. const validator = emitsOptions[event];
  662. if (isFunction(validator)) {
  663. const isValid = validator(...rawArgs);
  664. if (!isValid) {
  665. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  666. }
  667. }
  668. }
  669. }
  670. }
  671. let args = rawArgs;
  672. const isModelListener = event.startsWith('update:');
  673. // for v-model update:xxx events, apply modifiers on args
  674. const modelArg = isModelListener && event.slice(7);
  675. if (modelArg && modelArg in props) {
  676. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  677. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  678. if (trim) {
  679. args = rawArgs.map(a => (isString(a) ? a.trim() : a));
  680. }
  681. if (number) {
  682. args = rawArgs.map(toNumber);
  683. }
  684. }
  685. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  686. devtoolsComponentEmit(instance, event, args);
  687. }
  688. if ((process.env.NODE_ENV !== 'production')) {
  689. const lowerCaseEvent = event.toLowerCase();
  690. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  691. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  692. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  693. `Note that HTML attributes are case-insensitive and you cannot use ` +
  694. `v-on to listen to camelCase events when using in-DOM templates. ` +
  695. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  696. }
  697. }
  698. let handlerName;
  699. let handler = props[(handlerName = toHandlerKey(event))] ||
  700. // also try camelCase event handler (#2249)
  701. props[(handlerName = toHandlerKey(camelize(event)))];
  702. // for v-model update:xxx events, also trigger kebab-case equivalent
  703. // for props passed via kebab-case
  704. if (!handler && isModelListener) {
  705. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  706. }
  707. if (handler) {
  708. callWithAsyncErrorHandling(handler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  709. }
  710. const onceHandler = props[handlerName + `Once`];
  711. if (onceHandler) {
  712. if (!instance.emitted) {
  713. instance.emitted = {};
  714. }
  715. else if (instance.emitted[handlerName]) {
  716. return;
  717. }
  718. instance.emitted[handlerName] = true;
  719. callWithAsyncErrorHandling(onceHandler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  720. }
  721. }
  722. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  723. const cache = appContext.emitsCache;
  724. const cached = cache.get(comp);
  725. if (cached !== undefined) {
  726. return cached;
  727. }
  728. const raw = comp.emits;
  729. let normalized = {};
  730. // apply mixin/extends props
  731. let hasExtends = false;
  732. if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
  733. const extendEmits = (raw) => {
  734. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  735. if (normalizedFromExtend) {
  736. hasExtends = true;
  737. extend(normalized, normalizedFromExtend);
  738. }
  739. };
  740. if (!asMixin && appContext.mixins.length) {
  741. appContext.mixins.forEach(extendEmits);
  742. }
  743. if (comp.extends) {
  744. extendEmits(comp.extends);
  745. }
  746. if (comp.mixins) {
  747. comp.mixins.forEach(extendEmits);
  748. }
  749. }
  750. if (!raw && !hasExtends) {
  751. if (isObject(comp)) {
  752. cache.set(comp, null);
  753. }
  754. return null;
  755. }
  756. if (isArray(raw)) {
  757. raw.forEach(key => (normalized[key] = null));
  758. }
  759. else {
  760. extend(normalized, raw);
  761. }
  762. if (isObject(comp)) {
  763. cache.set(comp, normalized);
  764. }
  765. return normalized;
  766. }
  767. // Check if an incoming prop key is a declared emit event listener.
  768. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  769. // both considered matched listeners.
  770. function isEmitListener(options, key) {
  771. if (!options || !isOn(key)) {
  772. return false;
  773. }
  774. key = key.slice(2).replace(/Once$/, '');
  775. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  776. hasOwn(options, hyphenate(key)) ||
  777. hasOwn(options, key));
  778. }
  779. /**
  780. * mark the current rendering instance for asset resolution (e.g.
  781. * resolveComponent, resolveDirective) during render
  782. */
  783. let currentRenderingInstance = null;
  784. let currentScopeId = null;
  785. /**
  786. * Note: rendering calls maybe nested. The function returns the parent rendering
  787. * instance if present, which should be restored after the render is done:
  788. *
  789. * ```js
  790. * const prev = setCurrentRenderingInstance(i)
  791. * // ...render
  792. * setCurrentRenderingInstance(prev)
  793. * ```
  794. */
  795. function setCurrentRenderingInstance(instance) {
  796. const prev = currentRenderingInstance;
  797. currentRenderingInstance = instance;
  798. currentScopeId = (instance && instance.type.__scopeId) || null;
  799. return prev;
  800. }
  801. /**
  802. * Set scope id when creating hoisted vnodes.
  803. * @private compiler helper
  804. */
  805. function pushScopeId(id) {
  806. currentScopeId = id;
  807. }
  808. /**
  809. * Technically we no longer need this after 3.0.8 but we need to keep the same
  810. * API for backwards compat w/ code generated by compilers.
  811. * @private
  812. */
  813. function popScopeId() {
  814. currentScopeId = null;
  815. }
  816. /**
  817. * Only for backwards compat
  818. * @private
  819. */
  820. const withScopeId = (_id) => withCtx;
  821. /**
  822. * Wrap a slot function to memoize current rendering instance
  823. * @private compiler helper
  824. */
  825. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  826. ) {
  827. if (!ctx)
  828. return fn;
  829. // already normalized
  830. if (fn._n) {
  831. return fn;
  832. }
  833. const renderFnWithContext = (...args) => {
  834. // If a user calls a compiled slot inside a template expression (#1745), it
  835. // can mess up block tracking, so by default we disable block tracking and
  836. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  837. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  838. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  839. if (renderFnWithContext._d) {
  840. setBlockTracking(-1);
  841. }
  842. const prevInstance = setCurrentRenderingInstance(ctx);
  843. let res;
  844. try {
  845. res = fn(...args);
  846. }
  847. finally {
  848. setCurrentRenderingInstance(prevInstance);
  849. if (renderFnWithContext._d) {
  850. setBlockTracking(1);
  851. }
  852. }
  853. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  854. devtoolsComponentUpdated(ctx);
  855. }
  856. return res;
  857. };
  858. // mark normalized to avoid duplicated wrapping
  859. renderFnWithContext._n = true;
  860. // mark this as compiled by default
  861. // this is used in vnode.ts -> normalizeChildren() to set the slot
  862. // rendering flag.
  863. renderFnWithContext._c = true;
  864. // disable block tracking by default
  865. renderFnWithContext._d = true;
  866. return renderFnWithContext;
  867. }
  868. /**
  869. * dev only flag to track whether $attrs was used during render.
  870. * If $attrs was used during render then the warning for failed attrs
  871. * fallthrough can be suppressed.
  872. */
  873. let accessedAttrs = false;
  874. function markAttrsAccessed() {
  875. accessedAttrs = true;
  876. }
  877. function renderComponentRoot(instance) {
  878. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  879. let result;
  880. let fallthroughAttrs;
  881. const prev = setCurrentRenderingInstance(instance);
  882. if ((process.env.NODE_ENV !== 'production')) {
  883. accessedAttrs = false;
  884. }
  885. try {
  886. if (vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) {
  887. // withProxy is a proxy with a different `has` trap only for
  888. // runtime-compiled render functions using `with` block.
  889. const proxyToUse = withProxy || proxy;
  890. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  891. fallthroughAttrs = attrs;
  892. }
  893. else {
  894. // functional
  895. const render = Component;
  896. // in dev, mark attrs accessed if optional props (attrs === props)
  897. if ((process.env.NODE_ENV !== 'production') && attrs === props) {
  898. markAttrsAccessed();
  899. }
  900. result = normalizeVNode(render.length > 1
  901. ? render(props, (process.env.NODE_ENV !== 'production')
  902. ? {
  903. get attrs() {
  904. markAttrsAccessed();
  905. return attrs;
  906. },
  907. slots,
  908. emit
  909. }
  910. : { attrs, slots, emit })
  911. : render(props, null /* we know it doesn't need it */));
  912. fallthroughAttrs = Component.props
  913. ? attrs
  914. : getFunctionalFallthrough(attrs);
  915. }
  916. }
  917. catch (err) {
  918. blockStack.length = 0;
  919. handleError(err, instance, 1 /* ErrorCodes.RENDER_FUNCTION */);
  920. result = createVNode(Comment);
  921. }
  922. // attr merging
  923. // in dev mode, comments are preserved, and it's possible for a template
  924. // to have comments along side the root element which makes it a fragment
  925. let root = result;
  926. let setRoot = undefined;
  927. if ((process.env.NODE_ENV !== 'production') &&
  928. result.patchFlag > 0 &&
  929. result.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  930. [root, setRoot] = getChildRoot(result);
  931. }
  932. if (fallthroughAttrs && inheritAttrs !== false) {
  933. const keys = Object.keys(fallthroughAttrs);
  934. const { shapeFlag } = root;
  935. if (keys.length) {
  936. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 6 /* ShapeFlags.COMPONENT */)) {
  937. if (propsOptions && keys.some(isModelListener)) {
  938. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  939. // prop, it indicates this component expects to handle v-model and
  940. // it should not fallthrough.
  941. // related: #1543, #1643, #1989
  942. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  943. }
  944. root = cloneVNode(root, fallthroughAttrs);
  945. }
  946. else if ((process.env.NODE_ENV !== 'production') && !accessedAttrs && root.type !== Comment) {
  947. const allAttrs = Object.keys(attrs);
  948. const eventAttrs = [];
  949. const extraAttrs = [];
  950. for (let i = 0, l = allAttrs.length; i < l; i++) {
  951. const key = allAttrs[i];
  952. if (isOn(key)) {
  953. // ignore v-model handlers when they fail to fallthrough
  954. if (!isModelListener(key)) {
  955. // remove `on`, lowercase first letter to reflect event casing
  956. // accurately
  957. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  958. }
  959. }
  960. else {
  961. extraAttrs.push(key);
  962. }
  963. }
  964. if (extraAttrs.length) {
  965. warn(`Extraneous non-props attributes (` +
  966. `${extraAttrs.join(', ')}) ` +
  967. `were passed to component but could not be automatically inherited ` +
  968. `because component renders fragment or text root nodes.`);
  969. }
  970. if (eventAttrs.length) {
  971. warn(`Extraneous non-emits event listeners (` +
  972. `${eventAttrs.join(', ')}) ` +
  973. `were passed to component but could not be automatically inherited ` +
  974. `because component renders fragment or text root nodes. ` +
  975. `If the listener is intended to be a component custom event listener only, ` +
  976. `declare it using the "emits" option.`);
  977. }
  978. }
  979. }
  980. }
  981. // inherit directives
  982. if (vnode.dirs) {
  983. if ((process.env.NODE_ENV !== 'production') && !isElementRoot(root)) {
  984. warn(`Runtime directive used on component with non-element root node. ` +
  985. `The directives will not function as intended.`);
  986. }
  987. // clone before mutating since the root may be a hoisted vnode
  988. root = cloneVNode(root);
  989. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  990. }
  991. // inherit transition data
  992. if (vnode.transition) {
  993. if ((process.env.NODE_ENV !== 'production') && !isElementRoot(root)) {
  994. warn(`Component inside <Transition> renders non-element root node ` +
  995. `that cannot be animated.`);
  996. }
  997. root.transition = vnode.transition;
  998. }
  999. if ((process.env.NODE_ENV !== 'production') && setRoot) {
  1000. setRoot(root);
  1001. }
  1002. else {
  1003. result = root;
  1004. }
  1005. setCurrentRenderingInstance(prev);
  1006. return result;
  1007. }
  1008. /**
  1009. * dev only
  1010. * In dev mode, template root level comments are rendered, which turns the
  1011. * template into a fragment root, but we need to locate the single element
  1012. * root for attrs and scope id processing.
  1013. */
  1014. const getChildRoot = (vnode) => {
  1015. const rawChildren = vnode.children;
  1016. const dynamicChildren = vnode.dynamicChildren;
  1017. const childRoot = filterSingleRoot(rawChildren);
  1018. if (!childRoot) {
  1019. return [vnode, undefined];
  1020. }
  1021. const index = rawChildren.indexOf(childRoot);
  1022. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  1023. const setRoot = (updatedRoot) => {
  1024. rawChildren[index] = updatedRoot;
  1025. if (dynamicChildren) {
  1026. if (dynamicIndex > -1) {
  1027. dynamicChildren[dynamicIndex] = updatedRoot;
  1028. }
  1029. else if (updatedRoot.patchFlag > 0) {
  1030. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  1031. }
  1032. }
  1033. };
  1034. return [normalizeVNode(childRoot), setRoot];
  1035. };
  1036. function filterSingleRoot(children) {
  1037. let singleRoot;
  1038. for (let i = 0; i < children.length; i++) {
  1039. const child = children[i];
  1040. if (isVNode(child)) {
  1041. // ignore user comment
  1042. if (child.type !== Comment || child.children === 'v-if') {
  1043. if (singleRoot) {
  1044. // has more than 1 non-comment child, return now
  1045. return;
  1046. }
  1047. else {
  1048. singleRoot = child;
  1049. }
  1050. }
  1051. }
  1052. else {
  1053. return;
  1054. }
  1055. }
  1056. return singleRoot;
  1057. }
  1058. const getFunctionalFallthrough = (attrs) => {
  1059. let res;
  1060. for (const key in attrs) {
  1061. if (key === 'class' || key === 'style' || isOn(key)) {
  1062. (res || (res = {}))[key] = attrs[key];
  1063. }
  1064. }
  1065. return res;
  1066. };
  1067. const filterModelListeners = (attrs, props) => {
  1068. const res = {};
  1069. for (const key in attrs) {
  1070. if (!isModelListener(key) || !(key.slice(9) in props)) {
  1071. res[key] = attrs[key];
  1072. }
  1073. }
  1074. return res;
  1075. };
  1076. const isElementRoot = (vnode) => {
  1077. return (vnode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 1 /* ShapeFlags.ELEMENT */) ||
  1078. vnode.type === Comment // potential v-if branch switch
  1079. );
  1080. };
  1081. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  1082. const { props: prevProps, children: prevChildren, component } = prevVNode;
  1083. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  1084. const emits = component.emitsOptions;
  1085. // Parent component's render function was hot-updated. Since this may have
  1086. // caused the child component's slots content to have changed, we need to
  1087. // force the child to update as well.
  1088. if ((process.env.NODE_ENV !== 'production') && (prevChildren || nextChildren) && isHmrUpdating) {
  1089. return true;
  1090. }
  1091. // force child update for runtime directive or transition on component vnode.
  1092. if (nextVNode.dirs || nextVNode.transition) {
  1093. return true;
  1094. }
  1095. if (optimized && patchFlag >= 0) {
  1096. if (patchFlag & 1024 /* PatchFlags.DYNAMIC_SLOTS */) {
  1097. // slot content that references values that might have changed,
  1098. // e.g. in a v-for
  1099. return true;
  1100. }
  1101. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  1102. if (!prevProps) {
  1103. return !!nextProps;
  1104. }
  1105. // presence of this flag indicates props are always non-null
  1106. return hasPropsChanged(prevProps, nextProps, emits);
  1107. }
  1108. else if (patchFlag & 8 /* PatchFlags.PROPS */) {
  1109. const dynamicProps = nextVNode.dynamicProps;
  1110. for (let i = 0; i < dynamicProps.length; i++) {
  1111. const key = dynamicProps[i];
  1112. if (nextProps[key] !== prevProps[key] &&
  1113. !isEmitListener(emits, key)) {
  1114. return true;
  1115. }
  1116. }
  1117. }
  1118. }
  1119. else {
  1120. // this path is only taken by manually written render functions
  1121. // so presence of any children leads to a forced update
  1122. if (prevChildren || nextChildren) {
  1123. if (!nextChildren || !nextChildren.$stable) {
  1124. return true;
  1125. }
  1126. }
  1127. if (prevProps === nextProps) {
  1128. return false;
  1129. }
  1130. if (!prevProps) {
  1131. return !!nextProps;
  1132. }
  1133. if (!nextProps) {
  1134. return true;
  1135. }
  1136. return hasPropsChanged(prevProps, nextProps, emits);
  1137. }
  1138. return false;
  1139. }
  1140. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  1141. const nextKeys = Object.keys(nextProps);
  1142. if (nextKeys.length !== Object.keys(prevProps).length) {
  1143. return true;
  1144. }
  1145. for (let i = 0; i < nextKeys.length; i++) {
  1146. const key = nextKeys[i];
  1147. if (nextProps[key] !== prevProps[key] &&
  1148. !isEmitListener(emitsOptions, key)) {
  1149. return true;
  1150. }
  1151. }
  1152. return false;
  1153. }
  1154. function updateHOCHostEl({ vnode, parent }, el // HostNode
  1155. ) {
  1156. while (parent && parent.subTree === vnode) {
  1157. (vnode = parent.vnode).el = el;
  1158. parent = parent.parent;
  1159. }
  1160. }
  1161. const isSuspense = (type) => type.__isSuspense;
  1162. // Suspense exposes a component-like API, and is treated like a component
  1163. // in the compiler, but internally it's a special built-in type that hooks
  1164. // directly into the renderer.
  1165. const SuspenseImpl = {
  1166. name: 'Suspense',
  1167. // In order to make Suspense tree-shakable, we need to avoid importing it
  1168. // directly in the renderer. The renderer checks for the __isSuspense flag
  1169. // on a vnode's type and calls the `process` method, passing in renderer
  1170. // internals.
  1171. __isSuspense: true,
  1172. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  1173. // platform-specific impl passed from renderer
  1174. rendererInternals) {
  1175. if (n1 == null) {
  1176. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  1177. }
  1178. else {
  1179. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  1180. }
  1181. },
  1182. hydrate: hydrateSuspense,
  1183. create: createSuspenseBoundary,
  1184. normalize: normalizeSuspenseChildren
  1185. };
  1186. // Force-casted public typing for h and TSX props inference
  1187. const Suspense = (SuspenseImpl
  1188. );
  1189. function triggerEvent(vnode, name) {
  1190. const eventListener = vnode.props && vnode.props[name];
  1191. if (isFunction(eventListener)) {
  1192. eventListener();
  1193. }
  1194. }
  1195. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  1196. const { p: patch, o: { createElement } } = rendererInternals;
  1197. const hiddenContainer = createElement('div');
  1198. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  1199. // start mounting the content subtree in an off-dom container
  1200. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  1201. // now check if we have encountered any async deps
  1202. if (suspense.deps > 0) {
  1203. // has async
  1204. // invoke @fallback event
  1205. triggerEvent(vnode, 'onPending');
  1206. triggerEvent(vnode, 'onFallback');
  1207. // mount the fallback tree
  1208. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  1209. isSVG, slotScopeIds);
  1210. setActiveBranch(suspense, vnode.ssFallback);
  1211. }
  1212. else {
  1213. // Suspense has no async deps. Just resolve.
  1214. suspense.resolve();
  1215. }
  1216. }
  1217. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  1218. const suspense = (n2.suspense = n1.suspense);
  1219. suspense.vnode = n2;
  1220. n2.el = n1.el;
  1221. const newBranch = n2.ssContent;
  1222. const newFallback = n2.ssFallback;
  1223. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  1224. if (pendingBranch) {
  1225. suspense.pendingBranch = newBranch;
  1226. if (isSameVNodeType(newBranch, pendingBranch)) {
  1227. // same root type but content may have changed.
  1228. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  1229. if (suspense.deps <= 0) {
  1230. suspense.resolve();
  1231. }
  1232. else if (isInFallback) {
  1233. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  1234. isSVG, slotScopeIds, optimized);
  1235. setActiveBranch(suspense, newFallback);
  1236. }
  1237. }
  1238. else {
  1239. // toggled before pending tree is resolved
  1240. suspense.pendingId++;
  1241. if (isHydrating) {
  1242. // if toggled before hydration is finished, the current DOM tree is
  1243. // no longer valid. set it as the active branch so it will be unmounted
  1244. // when resolved
  1245. suspense.isHydrating = false;
  1246. suspense.activeBranch = pendingBranch;
  1247. }
  1248. else {
  1249. unmount(pendingBranch, parentComponent, suspense);
  1250. }
  1251. // increment pending ID. this is used to invalidate async callbacks
  1252. // reset suspense state
  1253. suspense.deps = 0;
  1254. // discard effects from pending branch
  1255. suspense.effects.length = 0;
  1256. // discard previous container
  1257. suspense.hiddenContainer = createElement('div');
  1258. if (isInFallback) {
  1259. // already in fallback state
  1260. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  1261. if (suspense.deps <= 0) {
  1262. suspense.resolve();
  1263. }
  1264. else {
  1265. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  1266. isSVG, slotScopeIds, optimized);
  1267. setActiveBranch(suspense, newFallback);
  1268. }
  1269. }
  1270. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  1271. // toggled "back" to current active branch
  1272. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  1273. // force resolve
  1274. suspense.resolve(true);
  1275. }
  1276. else {
  1277. // switched to a 3rd branch
  1278. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  1279. if (suspense.deps <= 0) {
  1280. suspense.resolve();
  1281. }
  1282. }
  1283. }
  1284. }
  1285. else {
  1286. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  1287. // root did not change, just normal patch
  1288. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  1289. setActiveBranch(suspense, newBranch);
  1290. }
  1291. else {
  1292. // root node toggled
  1293. // invoke @pending event
  1294. triggerEvent(n2, 'onPending');
  1295. // mount pending branch in off-dom container
  1296. suspense.pendingBranch = newBranch;
  1297. suspense.pendingId++;
  1298. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  1299. if (suspense.deps <= 0) {
  1300. // incoming branch has no async deps, resolve now.
  1301. suspense.resolve();
  1302. }
  1303. else {
  1304. const { timeout, pendingId } = suspense;
  1305. if (timeout > 0) {
  1306. setTimeout(() => {
  1307. if (suspense.pendingId === pendingId) {
  1308. suspense.fallback(newFallback);
  1309. }
  1310. }, timeout);
  1311. }
  1312. else if (timeout === 0) {
  1313. suspense.fallback(newFallback);
  1314. }
  1315. }
  1316. }
  1317. }
  1318. }
  1319. let hasWarned = false;
  1320. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  1321. /* istanbul ignore if */
  1322. if ((process.env.NODE_ENV !== 'production') && !false && !hasWarned) {
  1323. hasWarned = true;
  1324. // @ts-ignore `console.info` cannot be null error
  1325. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  1326. }
  1327. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  1328. const timeout = toNumber(vnode.props && vnode.props.timeout);
  1329. const suspense = {
  1330. vnode,
  1331. parent,
  1332. parentComponent,
  1333. isSVG,
  1334. container,
  1335. hiddenContainer,
  1336. anchor,
  1337. deps: 0,
  1338. pendingId: 0,
  1339. timeout: typeof timeout === 'number' ? timeout : -1,
  1340. activeBranch: null,
  1341. pendingBranch: null,
  1342. isInFallback: true,
  1343. isHydrating,
  1344. isUnmounted: false,
  1345. effects: [],
  1346. resolve(resume = false) {
  1347. if ((process.env.NODE_ENV !== 'production')) {
  1348. if (!resume && !suspense.pendingBranch) {
  1349. throw new Error(`suspense.resolve() is called without a pending branch.`);
  1350. }
  1351. if (suspense.isUnmounted) {
  1352. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  1353. }
  1354. }
  1355. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  1356. if (suspense.isHydrating) {
  1357. suspense.isHydrating = false;
  1358. }
  1359. else if (!resume) {
  1360. const delayEnter = activeBranch &&
  1361. pendingBranch.transition &&
  1362. pendingBranch.transition.mode === 'out-in';
  1363. if (delayEnter) {
  1364. activeBranch.transition.afterLeave = () => {
  1365. if (pendingId === suspense.pendingId) {
  1366. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  1367. }
  1368. };
  1369. }
  1370. // this is initial anchor on mount
  1371. let { anchor } = suspense;
  1372. // unmount current active tree
  1373. if (activeBranch) {
  1374. // if the fallback tree was mounted, it may have been moved
  1375. // as part of a parent suspense. get the latest anchor for insertion
  1376. anchor = next(activeBranch);
  1377. unmount(activeBranch, parentComponent, suspense, true);
  1378. }
  1379. if (!delayEnter) {
  1380. // move content from off-dom container to actual container
  1381. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  1382. }
  1383. }
  1384. setActiveBranch(suspense, pendingBranch);
  1385. suspense.pendingBranch = null;
  1386. suspense.isInFallback = false;
  1387. // flush buffered effects
  1388. // check if there is a pending parent suspense
  1389. let parent = suspense.parent;
  1390. let hasUnresolvedAncestor = false;
  1391. while (parent) {
  1392. if (parent.pendingBranch) {
  1393. // found a pending parent suspense, merge buffered post jobs
  1394. // into that parent
  1395. parent.effects.push(...effects);
  1396. hasUnresolvedAncestor = true;
  1397. break;
  1398. }
  1399. parent = parent.parent;
  1400. }
  1401. // no pending parent suspense, flush all jobs
  1402. if (!hasUnresolvedAncestor) {
  1403. queuePostFlushCb(effects);
  1404. }
  1405. suspense.effects = [];
  1406. // invoke @resolve event
  1407. triggerEvent(vnode, 'onResolve');
  1408. },
  1409. fallback(fallbackVNode) {
  1410. if (!suspense.pendingBranch) {
  1411. return;
  1412. }
  1413. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  1414. // invoke @fallback event
  1415. triggerEvent(vnode, 'onFallback');
  1416. const anchor = next(activeBranch);
  1417. const mountFallback = () => {
  1418. if (!suspense.isInFallback) {
  1419. return;
  1420. }
  1421. // mount the fallback tree
  1422. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  1423. isSVG, slotScopeIds, optimized);
  1424. setActiveBranch(suspense, fallbackVNode);
  1425. };
  1426. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  1427. if (delayEnter) {
  1428. activeBranch.transition.afterLeave = mountFallback;
  1429. }
  1430. suspense.isInFallback = true;
  1431. // unmount current active branch
  1432. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  1433. true // shouldRemove
  1434. );
  1435. if (!delayEnter) {
  1436. mountFallback();
  1437. }
  1438. },
  1439. move(container, anchor, type) {
  1440. suspense.activeBranch &&
  1441. move(suspense.activeBranch, container, anchor, type);
  1442. suspense.container = container;
  1443. },
  1444. next() {
  1445. return suspense.activeBranch && next(suspense.activeBranch);
  1446. },
  1447. registerDep(instance, setupRenderEffect) {
  1448. const isInPendingSuspense = !!suspense.pendingBranch;
  1449. if (isInPendingSuspense) {
  1450. suspense.deps++;
  1451. }
  1452. const hydratedEl = instance.vnode.el;
  1453. instance
  1454. .asyncDep.catch(err => {
  1455. handleError(err, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  1456. })
  1457. .then(asyncSetupResult => {
  1458. // retry when the setup() promise resolves.
  1459. // component may have been unmounted before resolve.
  1460. if (instance.isUnmounted ||
  1461. suspense.isUnmounted ||
  1462. suspense.pendingId !== instance.suspenseId) {
  1463. return;
  1464. }
  1465. // retry from this component
  1466. instance.asyncResolved = true;
  1467. const { vnode } = instance;
  1468. if ((process.env.NODE_ENV !== 'production')) {
  1469. pushWarningContext(vnode);
  1470. }
  1471. handleSetupResult(instance, asyncSetupResult, false);
  1472. if (hydratedEl) {
  1473. // vnode may have been replaced if an update happened before the
  1474. // async dep is resolved.
  1475. vnode.el = hydratedEl;
  1476. }
  1477. const placeholder = !hydratedEl && instance.subTree.el;
  1478. setupRenderEffect(instance, vnode,
  1479. // component may have been moved before resolve.
  1480. // if this is not a hydration, instance.subTree will be the comment
  1481. // placeholder.
  1482. parentNode(hydratedEl || instance.subTree.el),
  1483. // anchor will not be used if this is hydration, so only need to
  1484. // consider the comment placeholder case.
  1485. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  1486. if (placeholder) {
  1487. remove(placeholder);
  1488. }
  1489. updateHOCHostEl(instance, vnode.el);
  1490. if ((process.env.NODE_ENV !== 'production')) {
  1491. popWarningContext();
  1492. }
  1493. // only decrease deps count if suspense is not already resolved
  1494. if (isInPendingSuspense && --suspense.deps === 0) {
  1495. suspense.resolve();
  1496. }
  1497. });
  1498. },
  1499. unmount(parentSuspense, doRemove) {
  1500. suspense.isUnmounted = true;
  1501. if (suspense.activeBranch) {
  1502. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  1503. }
  1504. if (suspense.pendingBranch) {
  1505. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  1506. }
  1507. }
  1508. };
  1509. return suspense;
  1510. }
  1511. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  1512. /* eslint-disable no-restricted-globals */
  1513. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  1514. // there are two possible scenarios for server-rendered suspense:
  1515. // - success: ssr content should be fully resolved
  1516. // - failure: ssr content should be the fallback branch.
  1517. // however, on the client we don't really know if it has failed or not
  1518. // attempt to hydrate the DOM assuming it has succeeded, but we still
  1519. // need to construct a suspense boundary first
  1520. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  1521. if (suspense.deps === 0) {
  1522. suspense.resolve();
  1523. }
  1524. return result;
  1525. /* eslint-enable no-restricted-globals */
  1526. }
  1527. function normalizeSuspenseChildren(vnode) {
  1528. const { shapeFlag, children } = vnode;
  1529. const isSlotChildren = shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */;
  1530. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  1531. vnode.ssFallback = isSlotChildren
  1532. ? normalizeSuspenseSlot(children.fallback)
  1533. : createVNode(Comment);
  1534. }
  1535. function normalizeSuspenseSlot(s) {
  1536. let block;
  1537. if (isFunction(s)) {
  1538. const trackBlock = isBlockTreeEnabled && s._c;
  1539. if (trackBlock) {
  1540. // disableTracking: false
  1541. // allow block tracking for compiled slots
  1542. // (see ./componentRenderContext.ts)
  1543. s._d = false;
  1544. openBlock();
  1545. }
  1546. s = s();
  1547. if (trackBlock) {
  1548. s._d = true;
  1549. block = currentBlock;
  1550. closeBlock();
  1551. }
  1552. }
  1553. if (isArray(s)) {
  1554. const singleChild = filterSingleRoot(s);
  1555. if ((process.env.NODE_ENV !== 'production') && !singleChild) {
  1556. warn(`<Suspense> slots expect a single root node.`);
  1557. }
  1558. s = singleChild;
  1559. }
  1560. s = normalizeVNode(s);
  1561. if (block && !s.dynamicChildren) {
  1562. s.dynamicChildren = block.filter(c => c !== s);
  1563. }
  1564. return s;
  1565. }
  1566. function queueEffectWithSuspense(fn, suspense) {
  1567. if (suspense && suspense.pendingBranch) {
  1568. if (isArray(fn)) {
  1569. suspense.effects.push(...fn);
  1570. }
  1571. else {
  1572. suspense.effects.push(fn);
  1573. }
  1574. }
  1575. else {
  1576. queuePostFlushCb(fn);
  1577. }
  1578. }
  1579. function setActiveBranch(suspense, branch) {
  1580. suspense.activeBranch = branch;
  1581. const { vnode, parentComponent } = suspense;
  1582. const el = (vnode.el = branch.el);
  1583. // in case suspense is the root node of a component,
  1584. // recursively update the HOC el
  1585. if (parentComponent && parentComponent.subTree === vnode) {
  1586. parentComponent.vnode.el = el;
  1587. updateHOCHostEl(parentComponent, el);
  1588. }
  1589. }
  1590. function provide(key, value) {
  1591. if (!currentInstance) {
  1592. if ((process.env.NODE_ENV !== 'production')) {
  1593. warn(`provide() can only be used inside setup().`);
  1594. }
  1595. }
  1596. else {
  1597. let provides = currentInstance.provides;
  1598. // by default an instance inherits its parent's provides object
  1599. // but when it needs to provide values of its own, it creates its
  1600. // own provides object using parent provides object as prototype.
  1601. // this way in `inject` we can simply look up injections from direct
  1602. // parent and let the prototype chain do the work.
  1603. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  1604. if (parentProvides === provides) {
  1605. provides = currentInstance.provides = Object.create(parentProvides);
  1606. }
  1607. // TS doesn't allow symbol as index type
  1608. provides[key] = value;
  1609. }
  1610. }
  1611. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  1612. // fallback to `currentRenderingInstance` so that this can be called in
  1613. // a functional component
  1614. const instance = currentInstance || currentRenderingInstance;
  1615. if (instance) {
  1616. // #2400
  1617. // to support `app.use` plugins,
  1618. // fallback to appContext's `provides` if the instance is at root
  1619. const provides = instance.parent == null
  1620. ? instance.vnode.appContext && instance.vnode.appContext.provides
  1621. : instance.parent.provides;
  1622. if (provides && key in provides) {
  1623. // TS doesn't allow symbol as index type
  1624. return provides[key];
  1625. }
  1626. else if (arguments.length > 1) {
  1627. return treatDefaultAsFactory && isFunction(defaultValue)
  1628. ? defaultValue.call(instance.proxy)
  1629. : defaultValue;
  1630. }
  1631. else if ((process.env.NODE_ENV !== 'production')) {
  1632. warn(`injection "${String(key)}" not found.`);
  1633. }
  1634. }
  1635. else if ((process.env.NODE_ENV !== 'production')) {
  1636. warn(`inject() can only be used inside setup() or functional components.`);
  1637. }
  1638. }
  1639. // Simple effect.
  1640. function watchEffect(effect, options) {
  1641. return doWatch(effect, null, options);
  1642. }
  1643. function watchPostEffect(effect, options) {
  1644. return doWatch(effect, null, ((process.env.NODE_ENV !== 'production')
  1645. ? Object.assign(Object.assign({}, options), { flush: 'post' }) : { flush: 'post' }));
  1646. }
  1647. function watchSyncEffect(effect, options) {
  1648. return doWatch(effect, null, ((process.env.NODE_ENV !== 'production')
  1649. ? Object.assign(Object.assign({}, options), { flush: 'sync' }) : { flush: 'sync' }));
  1650. }
  1651. // initial value for watchers to trigger on undefined initial values
  1652. const INITIAL_WATCHER_VALUE = {};
  1653. // implementation
  1654. function watch(source, cb, options) {
  1655. if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
  1656. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  1657. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  1658. `supports \`watch(source, cb, options?) signature.`);
  1659. }
  1660. return doWatch(source, cb, options);
  1661. }
  1662. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  1663. if ((process.env.NODE_ENV !== 'production') && !cb) {
  1664. if (immediate !== undefined) {
  1665. warn(`watch() "immediate" option is only respected when using the ` +
  1666. `watch(source, callback, options?) signature.`);
  1667. }
  1668. if (deep !== undefined) {
  1669. warn(`watch() "deep" option is only respected when using the ` +
  1670. `watch(source, callback, options?) signature.`);
  1671. }
  1672. }
  1673. const warnInvalidSource = (s) => {
  1674. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  1675. `a reactive object, or an array of these types.`);
  1676. };
  1677. const instance = currentInstance;
  1678. let getter;
  1679. let forceTrigger = false;
  1680. let isMultiSource = false;
  1681. if (isRef(source)) {
  1682. getter = () => source.value;
  1683. forceTrigger = isShallow$1(source);
  1684. }
  1685. else if (isReactive(source)) {
  1686. getter = () => source;
  1687. deep = true;
  1688. }
  1689. else if (isArray(source)) {
  1690. isMultiSource = true;
  1691. forceTrigger = source.some(s => isReactive(s) || isShallow$1(s));
  1692. getter = () => source.map(s => {
  1693. if (isRef(s)) {
  1694. return s.value;
  1695. }
  1696. else if (isReactive(s)) {
  1697. return traverse(s);
  1698. }
  1699. else if (isFunction(s)) {
  1700. return callWithErrorHandling(s, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  1701. }
  1702. else {
  1703. (process.env.NODE_ENV !== 'production') && warnInvalidSource(s);
  1704. }
  1705. });
  1706. }
  1707. else if (isFunction(source)) {
  1708. if (cb) {
  1709. // getter with cb
  1710. getter = () => callWithErrorHandling(source, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  1711. }
  1712. else {
  1713. // no cb -> simple effect
  1714. getter = () => {
  1715. if (instance && instance.isUnmounted) {
  1716. return;
  1717. }
  1718. if (cleanup) {
  1719. cleanup();
  1720. }
  1721. return callWithAsyncErrorHandling(source, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [onCleanup]);
  1722. };
  1723. }
  1724. }
  1725. else {
  1726. getter = NOOP;
  1727. (process.env.NODE_ENV !== 'production') && warnInvalidSource(source);
  1728. }
  1729. if (cb && deep) {
  1730. const baseGetter = getter;
  1731. getter = () => traverse(baseGetter());
  1732. }
  1733. let cleanup;
  1734. let onCleanup = (fn) => {
  1735. cleanup = effect.onStop = () => {
  1736. callWithErrorHandling(fn, instance, 4 /* ErrorCodes.WATCH_CLEANUP */);
  1737. };
  1738. };
  1739. // in SSR there is no need to setup an actual effect, and it should be noop
  1740. // unless it's eager or sync flush
  1741. let ssrCleanup;
  1742. if (isInSSRComponentSetup) {
  1743. // we will also not call the invalidate callback (+ runner is not set up)
  1744. onCleanup = NOOP;
  1745. if (!cb) {
  1746. getter();
  1747. }
  1748. else if (immediate) {
  1749. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  1750. getter(),
  1751. isMultiSource ? [] : undefined,
  1752. onCleanup
  1753. ]);
  1754. }
  1755. if (flush === 'sync') {
  1756. const ctx = useSSRContext();
  1757. ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = []);
  1758. }
  1759. else {
  1760. return NOOP;
  1761. }
  1762. }
  1763. let oldValue = isMultiSource
  1764. ? new Array(source.length).fill(INITIAL_WATCHER_VALUE)
  1765. : INITIAL_WATCHER_VALUE;
  1766. const job = () => {
  1767. if (!effect.active) {
  1768. return;
  1769. }
  1770. if (cb) {
  1771. // watch(source, cb)
  1772. const newValue = effect.run();
  1773. if (deep ||
  1774. forceTrigger ||
  1775. (isMultiSource
  1776. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  1777. : hasChanged(newValue, oldValue)) ||
  1778. (false )) {
  1779. // cleanup before running cb again
  1780. if (cleanup) {
  1781. cleanup();
  1782. }
  1783. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  1784. newValue,
  1785. // pass undefined as the old value when it's changed for the first time
  1786. oldValue === INITIAL_WATCHER_VALUE
  1787. ? undefined
  1788. : (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE)
  1789. ? []
  1790. : oldValue,
  1791. onCleanup
  1792. ]);
  1793. oldValue = newValue;
  1794. }
  1795. }
  1796. else {
  1797. // watchEffect
  1798. effect.run();
  1799. }
  1800. };
  1801. // important: mark the job as a watcher callback so that scheduler knows
  1802. // it is allowed to self-trigger (#1727)
  1803. job.allowRecurse = !!cb;
  1804. let scheduler;
  1805. if (flush === 'sync') {
  1806. scheduler = job; // the scheduler function gets called directly
  1807. }
  1808. else if (flush === 'post') {
  1809. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  1810. }
  1811. else {
  1812. // default: 'pre'
  1813. job.pre = true;
  1814. if (instance)
  1815. job.id = instance.uid;
  1816. scheduler = () => queueJob(job);
  1817. }
  1818. const effect = new ReactiveEffect(getter, scheduler);
  1819. if ((process.env.NODE_ENV !== 'production')) {
  1820. effect.onTrack = onTrack;
  1821. effect.onTrigger = onTrigger;
  1822. }
  1823. // initial run
  1824. if (cb) {
  1825. if (immediate) {
  1826. job();
  1827. }
  1828. else {
  1829. oldValue = effect.run();
  1830. }
  1831. }
  1832. else if (flush === 'post') {
  1833. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  1834. }
  1835. else {
  1836. effect.run();
  1837. }
  1838. const unwatch = () => {
  1839. effect.stop();
  1840. if (instance && instance.scope) {
  1841. remove(instance.scope.effects, effect);
  1842. }
  1843. };
  1844. if (ssrCleanup)
  1845. ssrCleanup.push(unwatch);
  1846. return unwatch;
  1847. }
  1848. // this.$watch
  1849. function instanceWatch(source, value, options) {
  1850. const publicThis = this.proxy;
  1851. const getter = isString(source)
  1852. ? source.includes('.')
  1853. ? createPathGetter(publicThis, source)
  1854. : () => publicThis[source]
  1855. : source.bind(publicThis, publicThis);
  1856. let cb;
  1857. if (isFunction(value)) {
  1858. cb = value;
  1859. }
  1860. else {
  1861. cb = value.handler;
  1862. options = value;
  1863. }
  1864. const cur = currentInstance;
  1865. setCurrentInstance(this);
  1866. const res = doWatch(getter, cb.bind(publicThis), options);
  1867. if (cur) {
  1868. setCurrentInstance(cur);
  1869. }
  1870. else {
  1871. unsetCurrentInstance();
  1872. }
  1873. return res;
  1874. }
  1875. function createPathGetter(ctx, path) {
  1876. const segments = path.split('.');
  1877. return () => {
  1878. let cur = ctx;
  1879. for (let i = 0; i < segments.length && cur; i++) {
  1880. cur = cur[segments[i]];
  1881. }
  1882. return cur;
  1883. };
  1884. }
  1885. function traverse(value, seen) {
  1886. if (!isObject(value) || value["__v_skip" /* ReactiveFlags.SKIP */]) {
  1887. return value;
  1888. }
  1889. seen = seen || new Set();
  1890. if (seen.has(value)) {
  1891. return value;
  1892. }
  1893. seen.add(value);
  1894. if (isRef(value)) {
  1895. traverse(value.value, seen);
  1896. }
  1897. else if (isArray(value)) {
  1898. for (let i = 0; i < value.length; i++) {
  1899. traverse(value[i], seen);
  1900. }
  1901. }
  1902. else if (isSet(value) || isMap(value)) {
  1903. value.forEach((v) => {
  1904. traverse(v, seen);
  1905. });
  1906. }
  1907. else if (isPlainObject(value)) {
  1908. for (const key in value) {
  1909. traverse(value[key], seen);
  1910. }
  1911. }
  1912. return value;
  1913. }
  1914. function useTransitionState() {
  1915. const state = {
  1916. isMounted: false,
  1917. isLeaving: false,
  1918. isUnmounting: false,
  1919. leavingVNodes: new Map()
  1920. };
  1921. onMounted(() => {
  1922. state.isMounted = true;
  1923. });
  1924. onBeforeUnmount(() => {
  1925. state.isUnmounting = true;
  1926. });
  1927. return state;
  1928. }
  1929. const TransitionHookValidator = [Function, Array];
  1930. const BaseTransitionImpl = {
  1931. name: `BaseTransition`,
  1932. props: {
  1933. mode: String,
  1934. appear: Boolean,
  1935. persisted: Boolean,
  1936. // enter
  1937. onBeforeEnter: TransitionHookValidator,
  1938. onEnter: TransitionHookValidator,
  1939. onAfterEnter: TransitionHookValidator,
  1940. onEnterCancelled: TransitionHookValidator,
  1941. // leave
  1942. onBeforeLeave: TransitionHookValidator,
  1943. onLeave: TransitionHookValidator,
  1944. onAfterLeave: TransitionHookValidator,
  1945. onLeaveCancelled: TransitionHookValidator,
  1946. // appear
  1947. onBeforeAppear: TransitionHookValidator,
  1948. onAppear: TransitionHookValidator,
  1949. onAfterAppear: TransitionHookValidator,
  1950. onAppearCancelled: TransitionHookValidator
  1951. },
  1952. setup(props, { slots }) {
  1953. const instance = getCurrentInstance();
  1954. const state = useTransitionState();
  1955. let prevTransitionKey;
  1956. return () => {
  1957. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  1958. if (!children || !children.length) {
  1959. return;
  1960. }
  1961. let child = children[0];
  1962. if (children.length > 1) {
  1963. let hasFound = false;
  1964. // locate first non-comment child
  1965. for (const c of children) {
  1966. if (c.type !== Comment) {
  1967. if ((process.env.NODE_ENV !== 'production') && hasFound) {
  1968. // warn more than one non-comment child
  1969. warn('<transition> can only be used on a single element or component. ' +
  1970. 'Use <transition-group> for lists.');
  1971. break;
  1972. }
  1973. child = c;
  1974. hasFound = true;
  1975. if (!(process.env.NODE_ENV !== 'production'))
  1976. break;
  1977. }
  1978. }
  1979. }
  1980. // there's no need to track reactivity for these props so use the raw
  1981. // props for a bit better perf
  1982. const rawProps = toRaw(props);
  1983. const { mode } = rawProps;
  1984. // check mode
  1985. if ((process.env.NODE_ENV !== 'production') &&
  1986. mode &&
  1987. mode !== 'in-out' &&
  1988. mode !== 'out-in' &&
  1989. mode !== 'default') {
  1990. warn(`invalid <transition> mode: ${mode}`);
  1991. }
  1992. if (state.isLeaving) {
  1993. return emptyPlaceholder(child);
  1994. }
  1995. // in the case of <transition><keep-alive/></transition>, we need to
  1996. // compare the type of the kept-alive children.
  1997. const innerChild = getKeepAliveChild(child);
  1998. if (!innerChild) {
  1999. return emptyPlaceholder(child);
  2000. }
  2001. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  2002. setTransitionHooks(innerChild, enterHooks);
  2003. const oldChild = instance.subTree;
  2004. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  2005. let transitionKeyChanged = false;
  2006. const { getTransitionKey } = innerChild.type;
  2007. if (getTransitionKey) {
  2008. const key = getTransitionKey();
  2009. if (prevTransitionKey === undefined) {
  2010. prevTransitionKey = key;
  2011. }
  2012. else if (key !== prevTransitionKey) {
  2013. prevTransitionKey = key;
  2014. transitionKeyChanged = true;
  2015. }
  2016. }
  2017. // handle mode
  2018. if (oldInnerChild &&
  2019. oldInnerChild.type !== Comment &&
  2020. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  2021. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  2022. // update old tree's hooks in case of dynamic transition
  2023. setTransitionHooks(oldInnerChild, leavingHooks);
  2024. // switching between different views
  2025. if (mode === 'out-in') {
  2026. state.isLeaving = true;
  2027. // return placeholder node and queue update when leave finishes
  2028. leavingHooks.afterLeave = () => {
  2029. state.isLeaving = false;
  2030. // #6835
  2031. // it also needs to be updated when active is undefined
  2032. if (instance.update.active !== false) {
  2033. instance.update();
  2034. }
  2035. };
  2036. return emptyPlaceholder(child);
  2037. }
  2038. else if (mode === 'in-out' && innerChild.type !== Comment) {
  2039. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  2040. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  2041. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  2042. // early removal callback
  2043. el._leaveCb = () => {
  2044. earlyRemove();
  2045. el._leaveCb = undefined;
  2046. delete enterHooks.delayedLeave;
  2047. };
  2048. enterHooks.delayedLeave = delayedLeave;
  2049. };
  2050. }
  2051. }
  2052. return child;
  2053. };
  2054. }
  2055. };
  2056. // export the public type for h/tsx inference
  2057. // also to avoid inline import() in generated d.ts files
  2058. const BaseTransition = BaseTransitionImpl;
  2059. function getLeavingNodesForType(state, vnode) {
  2060. const { leavingVNodes } = state;
  2061. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  2062. if (!leavingVNodesCache) {
  2063. leavingVNodesCache = Object.create(null);
  2064. leavingVNodes.set(vnode.type, leavingVNodesCache);
  2065. }
  2066. return leavingVNodesCache;
  2067. }
  2068. // The transition hooks are attached to the vnode as vnode.transition
  2069. // and will be called at appropriate timing in the renderer.
  2070. function resolveTransitionHooks(vnode, props, state, instance) {
  2071. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  2072. const key = String(vnode.key);
  2073. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  2074. const callHook = (hook, args) => {
  2075. hook &&
  2076. callWithAsyncErrorHandling(hook, instance, 9 /* ErrorCodes.TRANSITION_HOOK */, args);
  2077. };
  2078. const callAsyncHook = (hook, args) => {
  2079. const done = args[1];
  2080. callHook(hook, args);
  2081. if (isArray(hook)) {
  2082. if (hook.every(hook => hook.length <= 1))
  2083. done();
  2084. }
  2085. else if (hook.length <= 1) {
  2086. done();
  2087. }
  2088. };
  2089. const hooks = {
  2090. mode,
  2091. persisted,
  2092. beforeEnter(el) {
  2093. let hook = onBeforeEnter;
  2094. if (!state.isMounted) {
  2095. if (appear) {
  2096. hook = onBeforeAppear || onBeforeEnter;
  2097. }
  2098. else {
  2099. return;
  2100. }
  2101. }
  2102. // for same element (v-show)
  2103. if (el._leaveCb) {
  2104. el._leaveCb(true /* cancelled */);
  2105. }
  2106. // for toggled element with same key (v-if)
  2107. const leavingVNode = leavingVNodesCache[key];
  2108. if (leavingVNode &&
  2109. isSameVNodeType(vnode, leavingVNode) &&
  2110. leavingVNode.el._leaveCb) {
  2111. // force early removal (not cancelled)
  2112. leavingVNode.el._leaveCb();
  2113. }
  2114. callHook(hook, [el]);
  2115. },
  2116. enter(el) {
  2117. let hook = onEnter;
  2118. let afterHook = onAfterEnter;
  2119. let cancelHook = onEnterCancelled;
  2120. if (!state.isMounted) {
  2121. if (appear) {
  2122. hook = onAppear || onEnter;
  2123. afterHook = onAfterAppear || onAfterEnter;
  2124. cancelHook = onAppearCancelled || onEnterCancelled;
  2125. }
  2126. else {
  2127. return;
  2128. }
  2129. }
  2130. let called = false;
  2131. const done = (el._enterCb = (cancelled) => {
  2132. if (called)
  2133. return;
  2134. called = true;
  2135. if (cancelled) {
  2136. callHook(cancelHook, [el]);
  2137. }
  2138. else {
  2139. callHook(afterHook, [el]);
  2140. }
  2141. if (hooks.delayedLeave) {
  2142. hooks.delayedLeave();
  2143. }
  2144. el._enterCb = undefined;
  2145. });
  2146. if (hook) {
  2147. callAsyncHook(hook, [el, done]);
  2148. }
  2149. else {
  2150. done();
  2151. }
  2152. },
  2153. leave(el, remove) {
  2154. const key = String(vnode.key);
  2155. if (el._enterCb) {
  2156. el._enterCb(true /* cancelled */);
  2157. }
  2158. if (state.isUnmounting) {
  2159. return remove();
  2160. }
  2161. callHook(onBeforeLeave, [el]);
  2162. let called = false;
  2163. const done = (el._leaveCb = (cancelled) => {
  2164. if (called)
  2165. return;
  2166. called = true;
  2167. remove();
  2168. if (cancelled) {
  2169. callHook(onLeaveCancelled, [el]);
  2170. }
  2171. else {
  2172. callHook(onAfterLeave, [el]);
  2173. }
  2174. el._leaveCb = undefined;
  2175. if (leavingVNodesCache[key] === vnode) {
  2176. delete leavingVNodesCache[key];
  2177. }
  2178. });
  2179. leavingVNodesCache[key] = vnode;
  2180. if (onLeave) {
  2181. callAsyncHook(onLeave, [el, done]);
  2182. }
  2183. else {
  2184. done();
  2185. }
  2186. },
  2187. clone(vnode) {
  2188. return resolveTransitionHooks(vnode, props, state, instance);
  2189. }
  2190. };
  2191. return hooks;
  2192. }
  2193. // the placeholder really only handles one special case: KeepAlive
  2194. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  2195. // placeholder with empty content to avoid the KeepAlive instance from being
  2196. // unmounted.
  2197. function emptyPlaceholder(vnode) {
  2198. if (isKeepAlive(vnode)) {
  2199. vnode = cloneVNode(vnode);
  2200. vnode.children = null;
  2201. return vnode;
  2202. }
  2203. }
  2204. function getKeepAliveChild(vnode) {
  2205. return isKeepAlive(vnode)
  2206. ? vnode.children
  2207. ? vnode.children[0]
  2208. : undefined
  2209. : vnode;
  2210. }
  2211. function setTransitionHooks(vnode, hooks) {
  2212. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */ && vnode.component) {
  2213. setTransitionHooks(vnode.component.subTree, hooks);
  2214. }
  2215. else if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  2216. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  2217. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  2218. }
  2219. else {
  2220. vnode.transition = hooks;
  2221. }
  2222. }
  2223. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  2224. let ret = [];
  2225. let keyedFragmentCount = 0;
  2226. for (let i = 0; i < children.length; i++) {
  2227. let child = children[i];
  2228. // #5360 inherit parent key in case of <template v-for>
  2229. const key = parentKey == null
  2230. ? child.key
  2231. : String(parentKey) + String(child.key != null ? child.key : i);
  2232. // handle fragment children case, e.g. v-for
  2233. if (child.type === Fragment) {
  2234. if (child.patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */)
  2235. keyedFragmentCount++;
  2236. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  2237. }
  2238. // comment placeholders should be skipped, e.g. v-if
  2239. else if (keepComment || child.type !== Comment) {
  2240. ret.push(key != null ? cloneVNode(child, { key }) : child);
  2241. }
  2242. }
  2243. // #1126 if a transition children list contains multiple sub fragments, these
  2244. // fragments will be merged into a flat children array. Since each v-for
  2245. // fragment may contain different static bindings inside, we need to de-op
  2246. // these children to force full diffs to ensure correct behavior.
  2247. if (keyedFragmentCount > 1) {
  2248. for (let i = 0; i < ret.length; i++) {
  2249. ret[i].patchFlag = -2 /* PatchFlags.BAIL */;
  2250. }
  2251. }
  2252. return ret;
  2253. }
  2254. // implementation, close to no-op
  2255. function defineComponent(options) {
  2256. return isFunction(options) ? { setup: options, name: options.name } : options;
  2257. }
  2258. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  2259. function defineAsyncComponent(source) {
  2260. if (isFunction(source)) {
  2261. source = { loader: source };
  2262. }
  2263. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  2264. suspensible = true, onError: userOnError } = source;
  2265. let pendingRequest = null;
  2266. let resolvedComp;
  2267. let retries = 0;
  2268. const retry = () => {
  2269. retries++;
  2270. pendingRequest = null;
  2271. return load();
  2272. };
  2273. const load = () => {
  2274. let thisRequest;
  2275. return (pendingRequest ||
  2276. (thisRequest = pendingRequest =
  2277. loader()
  2278. .catch(err => {
  2279. err = err instanceof Error ? err : new Error(String(err));
  2280. if (userOnError) {
  2281. return new Promise((resolve, reject) => {
  2282. const userRetry = () => resolve(retry());
  2283. const userFail = () => reject(err);
  2284. userOnError(err, userRetry, userFail, retries + 1);
  2285. });
  2286. }
  2287. else {
  2288. throw err;
  2289. }
  2290. })
  2291. .then((comp) => {
  2292. if (thisRequest !== pendingRequest && pendingRequest) {
  2293. return pendingRequest;
  2294. }
  2295. if ((process.env.NODE_ENV !== 'production') && !comp) {
  2296. warn(`Async component loader resolved to undefined. ` +
  2297. `If you are using retry(), make sure to return its return value.`);
  2298. }
  2299. // interop module default
  2300. if (comp &&
  2301. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  2302. comp = comp.default;
  2303. }
  2304. if ((process.env.NODE_ENV !== 'production') && comp && !isObject(comp) && !isFunction(comp)) {
  2305. throw new Error(`Invalid async component load result: ${comp}`);
  2306. }
  2307. resolvedComp = comp;
  2308. return comp;
  2309. })));
  2310. };
  2311. return defineComponent({
  2312. name: 'AsyncComponentWrapper',
  2313. __asyncLoader: load,
  2314. get __asyncResolved() {
  2315. return resolvedComp;
  2316. },
  2317. setup() {
  2318. const instance = currentInstance;
  2319. // already resolved
  2320. if (resolvedComp) {
  2321. return () => createInnerComp(resolvedComp, instance);
  2322. }
  2323. const onError = (err) => {
  2324. pendingRequest = null;
  2325. handleError(err, instance, 13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  2326. };
  2327. // suspense-controlled or SSR.
  2328. if ((suspensible && instance.suspense) ||
  2329. (isInSSRComponentSetup)) {
  2330. return load()
  2331. .then(comp => {
  2332. return () => createInnerComp(comp, instance);
  2333. })
  2334. .catch(err => {
  2335. onError(err);
  2336. return () => errorComponent
  2337. ? createVNode(errorComponent, {
  2338. error: err
  2339. })
  2340. : null;
  2341. });
  2342. }
  2343. const loaded = ref(false);
  2344. const error = ref();
  2345. const delayed = ref(!!delay);
  2346. if (delay) {
  2347. setTimeout(() => {
  2348. delayed.value = false;
  2349. }, delay);
  2350. }
  2351. if (timeout != null) {
  2352. setTimeout(() => {
  2353. if (!loaded.value && !error.value) {
  2354. const err = new Error(`Async component timed out after ${timeout}ms.`);
  2355. onError(err);
  2356. error.value = err;
  2357. }
  2358. }, timeout);
  2359. }
  2360. load()
  2361. .then(() => {
  2362. loaded.value = true;
  2363. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  2364. // parent is keep-alive, force update so the loaded component's
  2365. // name is taken into account
  2366. queueJob(instance.parent.update);
  2367. }
  2368. })
  2369. .catch(err => {
  2370. onError(err);
  2371. error.value = err;
  2372. });
  2373. return () => {
  2374. if (loaded.value && resolvedComp) {
  2375. return createInnerComp(resolvedComp, instance);
  2376. }
  2377. else if (error.value && errorComponent) {
  2378. return createVNode(errorComponent, {
  2379. error: error.value
  2380. });
  2381. }
  2382. else if (loadingComponent && !delayed.value) {
  2383. return createVNode(loadingComponent);
  2384. }
  2385. };
  2386. }
  2387. });
  2388. }
  2389. function createInnerComp(comp, parent) {
  2390. const { ref, props, children, ce } = parent.vnode;
  2391. const vnode = createVNode(comp, props, children);
  2392. // ensure inner component inherits the async wrapper's ref owner
  2393. vnode.ref = ref;
  2394. // pass the custom element callback on to the inner comp
  2395. // and remove it from the async wrapper
  2396. vnode.ce = ce;
  2397. delete parent.vnode.ce;
  2398. return vnode;
  2399. }
  2400. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  2401. const KeepAliveImpl = {
  2402. name: `KeepAlive`,
  2403. // Marker for special handling inside the renderer. We are not using a ===
  2404. // check directly on KeepAlive in the renderer, because importing it directly
  2405. // would prevent it from being tree-shaken.
  2406. __isKeepAlive: true,
  2407. props: {
  2408. include: [String, RegExp, Array],
  2409. exclude: [String, RegExp, Array],
  2410. max: [String, Number]
  2411. },
  2412. setup(props, { slots }) {
  2413. const instance = getCurrentInstance();
  2414. // KeepAlive communicates with the instantiated renderer via the
  2415. // ctx where the renderer passes in its internals,
  2416. // and the KeepAlive instance exposes activate/deactivate implementations.
  2417. // The whole point of this is to avoid importing KeepAlive directly in the
  2418. // renderer to facilitate tree-shaking.
  2419. const sharedContext = instance.ctx;
  2420. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  2421. // for KeepAlive, we just need to render its children
  2422. if (!sharedContext.renderer) {
  2423. return () => {
  2424. const children = slots.default && slots.default();
  2425. return children && children.length === 1 ? children[0] : children;
  2426. };
  2427. }
  2428. const cache = new Map();
  2429. const keys = new Set();
  2430. let current = null;
  2431. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  2432. instance.__v_cache = cache;
  2433. }
  2434. const parentSuspense = instance.suspense;
  2435. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  2436. const storageContainer = createElement('div');
  2437. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  2438. const instance = vnode.component;
  2439. move(vnode, container, anchor, 0 /* MoveType.ENTER */, parentSuspense);
  2440. // in case props have changed
  2441. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  2442. queuePostRenderEffect(() => {
  2443. instance.isDeactivated = false;
  2444. if (instance.a) {
  2445. invokeArrayFns(instance.a);
  2446. }
  2447. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  2448. if (vnodeHook) {
  2449. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  2450. }
  2451. }, parentSuspense);
  2452. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  2453. // Update components tree
  2454. devtoolsComponentAdded(instance);
  2455. }
  2456. };
  2457. sharedContext.deactivate = (vnode) => {
  2458. const instance = vnode.component;
  2459. move(vnode, storageContainer, null, 1 /* MoveType.LEAVE */, parentSuspense);
  2460. queuePostRenderEffect(() => {
  2461. if (instance.da) {
  2462. invokeArrayFns(instance.da);
  2463. }
  2464. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  2465. if (vnodeHook) {
  2466. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  2467. }
  2468. instance.isDeactivated = true;
  2469. }, parentSuspense);
  2470. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  2471. // Update components tree
  2472. devtoolsComponentAdded(instance);
  2473. }
  2474. };
  2475. function unmount(vnode) {
  2476. // reset the shapeFlag so it can be properly unmounted
  2477. resetShapeFlag(vnode);
  2478. _unmount(vnode, instance, parentSuspense, true);
  2479. }
  2480. function pruneCache(filter) {
  2481. cache.forEach((vnode, key) => {
  2482. const name = getComponentName(vnode.type);
  2483. if (name && (!filter || !filter(name))) {
  2484. pruneCacheEntry(key);
  2485. }
  2486. });
  2487. }
  2488. function pruneCacheEntry(key) {
  2489. const cached = cache.get(key);
  2490. if (!current || cached.type !== current.type) {
  2491. unmount(cached);
  2492. }
  2493. else if (current) {
  2494. // current active instance should no longer be kept-alive.
  2495. // we can't unmount it now but it might be later, so reset its flag now.
  2496. resetShapeFlag(current);
  2497. }
  2498. cache.delete(key);
  2499. keys.delete(key);
  2500. }
  2501. // prune cache on include/exclude prop change
  2502. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  2503. include && pruneCache(name => matches(include, name));
  2504. exclude && pruneCache(name => !matches(exclude, name));
  2505. },
  2506. // prune post-render after `current` has been updated
  2507. { flush: 'post', deep: true });
  2508. // cache sub tree after render
  2509. let pendingCacheKey = null;
  2510. const cacheSubtree = () => {
  2511. // fix #1621, the pendingCacheKey could be 0
  2512. if (pendingCacheKey != null) {
  2513. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  2514. }
  2515. };
  2516. onMounted(cacheSubtree);
  2517. onUpdated(cacheSubtree);
  2518. onBeforeUnmount(() => {
  2519. cache.forEach(cached => {
  2520. const { subTree, suspense } = instance;
  2521. const vnode = getInnerChild(subTree);
  2522. if (cached.type === vnode.type) {
  2523. // current instance will be unmounted as part of keep-alive's unmount
  2524. resetShapeFlag(vnode);
  2525. // but invoke its deactivated hook here
  2526. const da = vnode.component.da;
  2527. da && queuePostRenderEffect(da, suspense);
  2528. return;
  2529. }
  2530. unmount(cached);
  2531. });
  2532. });
  2533. return () => {
  2534. pendingCacheKey = null;
  2535. if (!slots.default) {
  2536. return null;
  2537. }
  2538. const children = slots.default();
  2539. const rawVNode = children[0];
  2540. if (children.length > 1) {
  2541. if ((process.env.NODE_ENV !== 'production')) {
  2542. warn(`KeepAlive should contain exactly one component child.`);
  2543. }
  2544. current = null;
  2545. return children;
  2546. }
  2547. else if (!isVNode(rawVNode) ||
  2548. (!(rawVNode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) &&
  2549. !(rawVNode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */))) {
  2550. current = null;
  2551. return rawVNode;
  2552. }
  2553. let vnode = getInnerChild(rawVNode);
  2554. const comp = vnode.type;
  2555. // for async components, name check should be based in its loaded
  2556. // inner component if available
  2557. const name = getComponentName(isAsyncWrapper(vnode)
  2558. ? vnode.type.__asyncResolved || {}
  2559. : comp);
  2560. const { include, exclude, max } = props;
  2561. if ((include && (!name || !matches(include, name))) ||
  2562. (exclude && name && matches(exclude, name))) {
  2563. current = vnode;
  2564. return rawVNode;
  2565. }
  2566. const key = vnode.key == null ? comp : vnode.key;
  2567. const cachedVNode = cache.get(key);
  2568. // clone vnode if it's reused because we are going to mutate it
  2569. if (vnode.el) {
  2570. vnode = cloneVNode(vnode);
  2571. if (rawVNode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  2572. rawVNode.ssContent = vnode;
  2573. }
  2574. }
  2575. // #1513 it's possible for the returned vnode to be cloned due to attr
  2576. // fallthrough or scopeId, so the vnode here may not be the final vnode
  2577. // that is mounted. Instead of caching it directly, we store the pending
  2578. // key and cache `instance.subTree` (the normalized vnode) in
  2579. // beforeMount/beforeUpdate hooks.
  2580. pendingCacheKey = key;
  2581. if (cachedVNode) {
  2582. // copy over mounted state
  2583. vnode.el = cachedVNode.el;
  2584. vnode.component = cachedVNode.component;
  2585. if (vnode.transition) {
  2586. // recursively update transition hooks on subTree
  2587. setTransitionHooks(vnode, vnode.transition);
  2588. }
  2589. // avoid vnode being mounted as fresh
  2590. vnode.shapeFlag |= 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  2591. // make this key the freshest
  2592. keys.delete(key);
  2593. keys.add(key);
  2594. }
  2595. else {
  2596. keys.add(key);
  2597. // prune oldest entry
  2598. if (max && keys.size > parseInt(max, 10)) {
  2599. pruneCacheEntry(keys.values().next().value);
  2600. }
  2601. }
  2602. // avoid vnode being unmounted
  2603. vnode.shapeFlag |= 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  2604. current = vnode;
  2605. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  2606. };
  2607. }
  2608. };
  2609. // export the public type for h/tsx inference
  2610. // also to avoid inline import() in generated d.ts files
  2611. const KeepAlive = KeepAliveImpl;
  2612. function matches(pattern, name) {
  2613. if (isArray(pattern)) {
  2614. return pattern.some((p) => matches(p, name));
  2615. }
  2616. else if (isString(pattern)) {
  2617. return pattern.split(',').includes(name);
  2618. }
  2619. else if (pattern.test) {
  2620. return pattern.test(name);
  2621. }
  2622. /* istanbul ignore next */
  2623. return false;
  2624. }
  2625. function onActivated(hook, target) {
  2626. registerKeepAliveHook(hook, "a" /* LifecycleHooks.ACTIVATED */, target);
  2627. }
  2628. function onDeactivated(hook, target) {
  2629. registerKeepAliveHook(hook, "da" /* LifecycleHooks.DEACTIVATED */, target);
  2630. }
  2631. function registerKeepAliveHook(hook, type, target = currentInstance) {
  2632. // cache the deactivate branch check wrapper for injected hooks so the same
  2633. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  2634. // deactivation check".
  2635. const wrappedHook = hook.__wdc ||
  2636. (hook.__wdc = () => {
  2637. // only fire the hook if the target instance is NOT in a deactivated branch.
  2638. let current = target;
  2639. while (current) {
  2640. if (current.isDeactivated) {
  2641. return;
  2642. }
  2643. current = current.parent;
  2644. }
  2645. return hook();
  2646. });
  2647. injectHook(type, wrappedHook, target);
  2648. // In addition to registering it on the target instance, we walk up the parent
  2649. // chain and register it on all ancestor instances that are keep-alive roots.
  2650. // This avoids the need to walk the entire component tree when invoking these
  2651. // hooks, and more importantly, avoids the need to track child components in
  2652. // arrays.
  2653. if (target) {
  2654. let current = target.parent;
  2655. while (current && current.parent) {
  2656. if (isKeepAlive(current.parent.vnode)) {
  2657. injectToKeepAliveRoot(wrappedHook, type, target, current);
  2658. }
  2659. current = current.parent;
  2660. }
  2661. }
  2662. }
  2663. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  2664. // injectHook wraps the original for error handling, so make sure to remove
  2665. // the wrapped version.
  2666. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  2667. onUnmounted(() => {
  2668. remove(keepAliveRoot[type], injected);
  2669. }, target);
  2670. }
  2671. function resetShapeFlag(vnode) {
  2672. // bitwise operations to remove keep alive flags
  2673. vnode.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  2674. vnode.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  2675. }
  2676. function getInnerChild(vnode) {
  2677. return vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */ ? vnode.ssContent : vnode;
  2678. }
  2679. function injectHook(type, hook, target = currentInstance, prepend = false) {
  2680. if (target) {
  2681. const hooks = target[type] || (target[type] = []);
  2682. // cache the error handling wrapper for injected hooks so the same hook
  2683. // can be properly deduped by the scheduler. "__weh" stands for "with error
  2684. // handling".
  2685. const wrappedHook = hook.__weh ||
  2686. (hook.__weh = (...args) => {
  2687. if (target.isUnmounted) {
  2688. return;
  2689. }
  2690. // disable tracking inside all lifecycle hooks
  2691. // since they can potentially be called inside effects.
  2692. pauseTracking();
  2693. // Set currentInstance during hook invocation.
  2694. // This assumes the hook does not synchronously trigger other hooks, which
  2695. // can only be false when the user does something really funky.
  2696. setCurrentInstance(target);
  2697. const res = callWithAsyncErrorHandling(hook, target, type, args);
  2698. unsetCurrentInstance();
  2699. resetTracking();
  2700. return res;
  2701. });
  2702. if (prepend) {
  2703. hooks.unshift(wrappedHook);
  2704. }
  2705. else {
  2706. hooks.push(wrappedHook);
  2707. }
  2708. return wrappedHook;
  2709. }
  2710. else if ((process.env.NODE_ENV !== 'production')) {
  2711. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  2712. warn(`${apiName} is called when there is no active component instance to be ` +
  2713. `associated with. ` +
  2714. `Lifecycle injection APIs can only be used during execution of setup().` +
  2715. (` If you are using async setup(), make sure to register lifecycle ` +
  2716. `hooks before the first await statement.`
  2717. ));
  2718. }
  2719. }
  2720. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  2721. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  2722. (!isInSSRComponentSetup || lifecycle === "sp" /* LifecycleHooks.SERVER_PREFETCH */) &&
  2723. injectHook(lifecycle, (...args) => hook(...args), target);
  2724. const onBeforeMount = createHook("bm" /* LifecycleHooks.BEFORE_MOUNT */);
  2725. const onMounted = createHook("m" /* LifecycleHooks.MOUNTED */);
  2726. const onBeforeUpdate = createHook("bu" /* LifecycleHooks.BEFORE_UPDATE */);
  2727. const onUpdated = createHook("u" /* LifecycleHooks.UPDATED */);
  2728. const onBeforeUnmount = createHook("bum" /* LifecycleHooks.BEFORE_UNMOUNT */);
  2729. const onUnmounted = createHook("um" /* LifecycleHooks.UNMOUNTED */);
  2730. const onServerPrefetch = createHook("sp" /* LifecycleHooks.SERVER_PREFETCH */);
  2731. const onRenderTriggered = createHook("rtg" /* LifecycleHooks.RENDER_TRIGGERED */);
  2732. const onRenderTracked = createHook("rtc" /* LifecycleHooks.RENDER_TRACKED */);
  2733. function onErrorCaptured(hook, target = currentInstance) {
  2734. injectHook("ec" /* LifecycleHooks.ERROR_CAPTURED */, hook, target);
  2735. }
  2736. /**
  2737. Runtime helper for applying directives to a vnode. Example usage:
  2738. const comp = resolveComponent('comp')
  2739. const foo = resolveDirective('foo')
  2740. const bar = resolveDirective('bar')
  2741. return withDirectives(h(comp), [
  2742. [foo, this.x],
  2743. [bar, this.y]
  2744. ])
  2745. */
  2746. function validateDirectiveName(name) {
  2747. if (isBuiltInDirective(name)) {
  2748. warn('Do not use built-in directive ids as custom directive id: ' + name);
  2749. }
  2750. }
  2751. /**
  2752. * Adds directives to a VNode.
  2753. */
  2754. function withDirectives(vnode, directives) {
  2755. const internalInstance = currentRenderingInstance;
  2756. if (internalInstance === null) {
  2757. (process.env.NODE_ENV !== 'production') && warn(`withDirectives can only be used inside render functions.`);
  2758. return vnode;
  2759. }
  2760. const instance = getExposeProxy(internalInstance) ||
  2761. internalInstance.proxy;
  2762. const bindings = vnode.dirs || (vnode.dirs = []);
  2763. for (let i = 0; i < directives.length; i++) {
  2764. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  2765. if (dir) {
  2766. if (isFunction(dir)) {
  2767. dir = {
  2768. mounted: dir,
  2769. updated: dir
  2770. };
  2771. }
  2772. if (dir.deep) {
  2773. traverse(value);
  2774. }
  2775. bindings.push({
  2776. dir,
  2777. instance,
  2778. value,
  2779. oldValue: void 0,
  2780. arg,
  2781. modifiers
  2782. });
  2783. }
  2784. }
  2785. return vnode;
  2786. }
  2787. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  2788. const bindings = vnode.dirs;
  2789. const oldBindings = prevVNode && prevVNode.dirs;
  2790. for (let i = 0; i < bindings.length; i++) {
  2791. const binding = bindings[i];
  2792. if (oldBindings) {
  2793. binding.oldValue = oldBindings[i].value;
  2794. }
  2795. let hook = binding.dir[name];
  2796. if (hook) {
  2797. // disable tracking inside all lifecycle hooks
  2798. // since they can potentially be called inside effects.
  2799. pauseTracking();
  2800. callWithAsyncErrorHandling(hook, instance, 8 /* ErrorCodes.DIRECTIVE_HOOK */, [
  2801. vnode.el,
  2802. binding,
  2803. vnode,
  2804. prevVNode
  2805. ]);
  2806. resetTracking();
  2807. }
  2808. }
  2809. }
  2810. const COMPONENTS = 'components';
  2811. const DIRECTIVES = 'directives';
  2812. /**
  2813. * @private
  2814. */
  2815. function resolveComponent(name, maybeSelfReference) {
  2816. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  2817. }
  2818. const NULL_DYNAMIC_COMPONENT = Symbol();
  2819. /**
  2820. * @private
  2821. */
  2822. function resolveDynamicComponent(component) {
  2823. if (isString(component)) {
  2824. return resolveAsset(COMPONENTS, component, false) || component;
  2825. }
  2826. else {
  2827. // invalid types will fallthrough to createVNode and raise warning
  2828. return (component || NULL_DYNAMIC_COMPONENT);
  2829. }
  2830. }
  2831. /**
  2832. * @private
  2833. */
  2834. function resolveDirective(name) {
  2835. return resolveAsset(DIRECTIVES, name);
  2836. }
  2837. // implementation
  2838. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  2839. const instance = currentRenderingInstance || currentInstance;
  2840. if (instance) {
  2841. const Component = instance.type;
  2842. // explicit self name has highest priority
  2843. if (type === COMPONENTS) {
  2844. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  2845. if (selfName &&
  2846. (selfName === name ||
  2847. selfName === camelize(name) ||
  2848. selfName === capitalize(camelize(name)))) {
  2849. return Component;
  2850. }
  2851. }
  2852. const res =
  2853. // local registration
  2854. // check instance[type] first which is resolved for options API
  2855. resolve(instance[type] || Component[type], name) ||
  2856. // global registration
  2857. resolve(instance.appContext[type], name);
  2858. if (!res && maybeSelfReference) {
  2859. // fallback to implicit self-reference
  2860. return Component;
  2861. }
  2862. if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) {
  2863. const extra = type === COMPONENTS
  2864. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  2865. `component resolution via compilerOptions.isCustomElement.`
  2866. : ``;
  2867. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  2868. }
  2869. return res;
  2870. }
  2871. else if ((process.env.NODE_ENV !== 'production')) {
  2872. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  2873. `can only be used in render() or setup().`);
  2874. }
  2875. }
  2876. function resolve(registry, name) {
  2877. return (registry &&
  2878. (registry[name] ||
  2879. registry[camelize(name)] ||
  2880. registry[capitalize(camelize(name))]));
  2881. }
  2882. /**
  2883. * Actual implementation
  2884. */
  2885. function renderList(source, renderItem, cache, index) {
  2886. let ret;
  2887. const cached = (cache && cache[index]);
  2888. if (isArray(source) || isString(source)) {
  2889. ret = new Array(source.length);
  2890. for (let i = 0, l = source.length; i < l; i++) {
  2891. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  2892. }
  2893. }
  2894. else if (typeof source === 'number') {
  2895. if ((process.env.NODE_ENV !== 'production') && !Number.isInteger(source)) {
  2896. warn(`The v-for range expect an integer value but got ${source}.`);
  2897. }
  2898. ret = new Array(source);
  2899. for (let i = 0; i < source; i++) {
  2900. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  2901. }
  2902. }
  2903. else if (isObject(source)) {
  2904. if (source[Symbol.iterator]) {
  2905. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  2906. }
  2907. else {
  2908. const keys = Object.keys(source);
  2909. ret = new Array(keys.length);
  2910. for (let i = 0, l = keys.length; i < l; i++) {
  2911. const key = keys[i];
  2912. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  2913. }
  2914. }
  2915. }
  2916. else {
  2917. ret = [];
  2918. }
  2919. if (cache) {
  2920. cache[index] = ret;
  2921. }
  2922. return ret;
  2923. }
  2924. /**
  2925. * Compiler runtime helper for creating dynamic slots object
  2926. * @private
  2927. */
  2928. function createSlots(slots, dynamicSlots) {
  2929. for (let i = 0; i < dynamicSlots.length; i++) {
  2930. const slot = dynamicSlots[i];
  2931. // array of dynamic slot generated by <template v-for="..." #[...]>
  2932. if (isArray(slot)) {
  2933. for (let j = 0; j < slot.length; j++) {
  2934. slots[slot[j].name] = slot[j].fn;
  2935. }
  2936. }
  2937. else if (slot) {
  2938. // conditional single slot generated by <template v-if="..." #foo>
  2939. slots[slot.name] = slot.key
  2940. ? (...args) => {
  2941. const res = slot.fn(...args);
  2942. // attach branch key so each conditional branch is considered a
  2943. // different fragment
  2944. if (res)
  2945. res.key = slot.key;
  2946. return res;
  2947. }
  2948. : slot.fn;
  2949. }
  2950. }
  2951. return slots;
  2952. }
  2953. /**
  2954. * Compiler runtime helper for rendering `<slot/>`
  2955. * @private
  2956. */
  2957. function renderSlot(slots, name, props = {},
  2958. // this is not a user-facing function, so the fallback is always generated by
  2959. // the compiler and guaranteed to be a function returning an array
  2960. fallback, noSlotted) {
  2961. if (currentRenderingInstance.isCE ||
  2962. (currentRenderingInstance.parent &&
  2963. isAsyncWrapper(currentRenderingInstance.parent) &&
  2964. currentRenderingInstance.parent.isCE)) {
  2965. if (name !== 'default')
  2966. props.name = name;
  2967. return createVNode('slot', props, fallback && fallback());
  2968. }
  2969. let slot = slots[name];
  2970. if ((process.env.NODE_ENV !== 'production') && slot && slot.length > 1) {
  2971. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  2972. `function. You need to mark this component with $dynamic-slots in the ` +
  2973. `parent template.`);
  2974. slot = () => [];
  2975. }
  2976. // a compiled slot disables block tracking by default to avoid manual
  2977. // invocation interfering with template-based block tracking, but in
  2978. // `renderSlot` we can be sure that it's template-based so we can force
  2979. // enable it.
  2980. if (slot && slot._c) {
  2981. slot._d = false;
  2982. }
  2983. openBlock();
  2984. const validSlotContent = slot && ensureValidVNode(slot(props));
  2985. const rendered = createBlock(Fragment, {
  2986. key: props.key ||
  2987. // slot content array of a dynamic conditional slot may have a branch
  2988. // key attached in the `createSlots` helper, respect that
  2989. (validSlotContent && validSlotContent.key) ||
  2990. `_${name}`
  2991. }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* SlotFlags.STABLE */
  2992. ? 64 /* PatchFlags.STABLE_FRAGMENT */
  2993. : -2 /* PatchFlags.BAIL */);
  2994. if (!noSlotted && rendered.scopeId) {
  2995. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  2996. }
  2997. if (slot && slot._c) {
  2998. slot._d = true;
  2999. }
  3000. return rendered;
  3001. }
  3002. function ensureValidVNode(vnodes) {
  3003. return vnodes.some(child => {
  3004. if (!isVNode(child))
  3005. return true;
  3006. if (child.type === Comment)
  3007. return false;
  3008. if (child.type === Fragment &&
  3009. !ensureValidVNode(child.children))
  3010. return false;
  3011. return true;
  3012. })
  3013. ? vnodes
  3014. : null;
  3015. }
  3016. /**
  3017. * For prefixing keys in v-on="obj" with "on"
  3018. * @private
  3019. */
  3020. function toHandlers(obj, preserveCaseIfNecessary) {
  3021. const ret = {};
  3022. if ((process.env.NODE_ENV !== 'production') && !isObject(obj)) {
  3023. warn(`v-on with no argument expects an object value.`);
  3024. return ret;
  3025. }
  3026. for (const key in obj) {
  3027. ret[preserveCaseIfNecessary && /[A-Z]/.test(key)
  3028. ? `on:${key}`
  3029. : toHandlerKey(key)] = obj[key];
  3030. }
  3031. return ret;
  3032. }
  3033. /**
  3034. * #2437 In Vue 3, functional components do not have a public instance proxy but
  3035. * they exist in the internal parent chain. For code that relies on traversing
  3036. * public $parent chains, skip functional ones and go to the parent instead.
  3037. */
  3038. const getPublicInstance = (i) => {
  3039. if (!i)
  3040. return null;
  3041. if (isStatefulComponent(i))
  3042. return getExposeProxy(i) || i.proxy;
  3043. return getPublicInstance(i.parent);
  3044. };
  3045. const publicPropertiesMap =
  3046. // Move PURE marker to new line to workaround compiler discarding it
  3047. // due to type annotation
  3048. /*#__PURE__*/ extend(Object.create(null), {
  3049. $: i => i,
  3050. $el: i => i.vnode.el,
  3051. $data: i => i.data,
  3052. $props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props),
  3053. $attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs),
  3054. $slots: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.slots) : i.slots),
  3055. $refs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.refs) : i.refs),
  3056. $parent: i => getPublicInstance(i.parent),
  3057. $root: i => getPublicInstance(i.root),
  3058. $emit: i => i.emit,
  3059. $options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
  3060. $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
  3061. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  3062. $watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP)
  3063. });
  3064. const isReservedPrefix = (key) => key === '_' || key === '$';
  3065. const hasSetupBinding = (state, key) => state !== EMPTY_OBJ && !state.__isScriptSetup && hasOwn(state, key);
  3066. const PublicInstanceProxyHandlers = {
  3067. get({ _: instance }, key) {
  3068. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  3069. // for internal formatters to know that this is a Vue instance
  3070. if ((process.env.NODE_ENV !== 'production') && key === '__isVue') {
  3071. return true;
  3072. }
  3073. // data / props / ctx
  3074. // This getter gets called for every property access on the render context
  3075. // during render and is a major hotspot. The most expensive part of this
  3076. // is the multiple hasOwn() calls. It's much faster to do a simple property
  3077. // access on a plain object, so we use an accessCache object (with null
  3078. // prototype) to memoize what access type a key corresponds to.
  3079. let normalizedProps;
  3080. if (key[0] !== '$') {
  3081. const n = accessCache[key];
  3082. if (n !== undefined) {
  3083. switch (n) {
  3084. case 1 /* AccessTypes.SETUP */:
  3085. return setupState[key];
  3086. case 2 /* AccessTypes.DATA */:
  3087. return data[key];
  3088. case 4 /* AccessTypes.CONTEXT */:
  3089. return ctx[key];
  3090. case 3 /* AccessTypes.PROPS */:
  3091. return props[key];
  3092. // default: just fallthrough
  3093. }
  3094. }
  3095. else if (hasSetupBinding(setupState, key)) {
  3096. accessCache[key] = 1 /* AccessTypes.SETUP */;
  3097. return setupState[key];
  3098. }
  3099. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  3100. accessCache[key] = 2 /* AccessTypes.DATA */;
  3101. return data[key];
  3102. }
  3103. else if (
  3104. // only cache other properties when instance has declared (thus stable)
  3105. // props
  3106. (normalizedProps = instance.propsOptions[0]) &&
  3107. hasOwn(normalizedProps, key)) {
  3108. accessCache[key] = 3 /* AccessTypes.PROPS */;
  3109. return props[key];
  3110. }
  3111. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  3112. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  3113. return ctx[key];
  3114. }
  3115. else if (!__VUE_OPTIONS_API__ || shouldCacheAccess) {
  3116. accessCache[key] = 0 /* AccessTypes.OTHER */;
  3117. }
  3118. }
  3119. const publicGetter = publicPropertiesMap[key];
  3120. let cssModule, globalProperties;
  3121. // public $xxx properties
  3122. if (publicGetter) {
  3123. if (key === '$attrs') {
  3124. track(instance, "get" /* TrackOpTypes.GET */, key);
  3125. (process.env.NODE_ENV !== 'production') && markAttrsAccessed();
  3126. }
  3127. return publicGetter(instance);
  3128. }
  3129. else if (
  3130. // css module (injected by vue-loader)
  3131. (cssModule = type.__cssModules) &&
  3132. (cssModule = cssModule[key])) {
  3133. return cssModule;
  3134. }
  3135. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  3136. // user may set custom properties to `this` that start with `$`
  3137. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  3138. return ctx[key];
  3139. }
  3140. else if (
  3141. // global properties
  3142. ((globalProperties = appContext.config.globalProperties),
  3143. hasOwn(globalProperties, key))) {
  3144. {
  3145. return globalProperties[key];
  3146. }
  3147. }
  3148. else if ((process.env.NODE_ENV !== 'production') &&
  3149. currentRenderingInstance &&
  3150. (!isString(key) ||
  3151. // #1091 avoid internal isRef/isVNode checks on component instance leading
  3152. // to infinite warning loop
  3153. key.indexOf('__v') !== 0)) {
  3154. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  3155. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  3156. `character ("$" or "_") and is not proxied on the render context.`);
  3157. }
  3158. else if (instance === currentRenderingInstance) {
  3159. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  3160. `but is not defined on instance.`);
  3161. }
  3162. }
  3163. },
  3164. set({ _: instance }, key, value) {
  3165. const { data, setupState, ctx } = instance;
  3166. if (hasSetupBinding(setupState, key)) {
  3167. setupState[key] = value;
  3168. return true;
  3169. }
  3170. else if ((process.env.NODE_ENV !== 'production') &&
  3171. setupState.__isScriptSetup &&
  3172. hasOwn(setupState, key)) {
  3173. warn(`Cannot mutate <script setup> binding "${key}" from Options API.`);
  3174. return false;
  3175. }
  3176. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  3177. data[key] = value;
  3178. return true;
  3179. }
  3180. else if (hasOwn(instance.props, key)) {
  3181. (process.env.NODE_ENV !== 'production') && warn(`Attempting to mutate prop "${key}". Props are readonly.`);
  3182. return false;
  3183. }
  3184. if (key[0] === '$' && key.slice(1) in instance) {
  3185. (process.env.NODE_ENV !== 'production') &&
  3186. warn(`Attempting to mutate public property "${key}". ` +
  3187. `Properties starting with $ are reserved and readonly.`);
  3188. return false;
  3189. }
  3190. else {
  3191. if ((process.env.NODE_ENV !== 'production') && key in instance.appContext.config.globalProperties) {
  3192. Object.defineProperty(ctx, key, {
  3193. enumerable: true,
  3194. configurable: true,
  3195. value
  3196. });
  3197. }
  3198. else {
  3199. ctx[key] = value;
  3200. }
  3201. }
  3202. return true;
  3203. },
  3204. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  3205. let normalizedProps;
  3206. return (!!accessCache[key] ||
  3207. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  3208. hasSetupBinding(setupState, key) ||
  3209. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  3210. hasOwn(ctx, key) ||
  3211. hasOwn(publicPropertiesMap, key) ||
  3212. hasOwn(appContext.config.globalProperties, key));
  3213. },
  3214. defineProperty(target, key, descriptor) {
  3215. if (descriptor.get != null) {
  3216. // invalidate key cache of a getter based property #5417
  3217. target._.accessCache[key] = 0;
  3218. }
  3219. else if (hasOwn(descriptor, 'value')) {
  3220. this.set(target, key, descriptor.value, null);
  3221. }
  3222. return Reflect.defineProperty(target, key, descriptor);
  3223. }
  3224. };
  3225. if ((process.env.NODE_ENV !== 'production') && !false) {
  3226. PublicInstanceProxyHandlers.ownKeys = (target) => {
  3227. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  3228. `The keys will be empty in production mode to avoid performance overhead.`);
  3229. return Reflect.ownKeys(target);
  3230. };
  3231. }
  3232. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  3233. get(target, key) {
  3234. // fast path for unscopables when using `with` block
  3235. if (key === Symbol.unscopables) {
  3236. return;
  3237. }
  3238. return PublicInstanceProxyHandlers.get(target, key, target);
  3239. },
  3240. has(_, key) {
  3241. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  3242. if ((process.env.NODE_ENV !== 'production') && !has && PublicInstanceProxyHandlers.has(_, key)) {
  3243. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  3244. }
  3245. return has;
  3246. }
  3247. });
  3248. // dev only
  3249. // In dev mode, the proxy target exposes the same properties as seen on `this`
  3250. // for easier console inspection. In prod mode it will be an empty object so
  3251. // these properties definitions can be skipped.
  3252. function createDevRenderContext(instance) {
  3253. const target = {};
  3254. // expose internal instance for proxy handlers
  3255. Object.defineProperty(target, `_`, {
  3256. configurable: true,
  3257. enumerable: false,
  3258. get: () => instance
  3259. });
  3260. // expose public properties
  3261. Object.keys(publicPropertiesMap).forEach(key => {
  3262. Object.defineProperty(target, key, {
  3263. configurable: true,
  3264. enumerable: false,
  3265. get: () => publicPropertiesMap[key](instance),
  3266. // intercepted by the proxy so no need for implementation,
  3267. // but needed to prevent set errors
  3268. set: NOOP
  3269. });
  3270. });
  3271. return target;
  3272. }
  3273. // dev only
  3274. function exposePropsOnRenderContext(instance) {
  3275. const { ctx, propsOptions: [propsOptions] } = instance;
  3276. if (propsOptions) {
  3277. Object.keys(propsOptions).forEach(key => {
  3278. Object.defineProperty(ctx, key, {
  3279. enumerable: true,
  3280. configurable: true,
  3281. get: () => instance.props[key],
  3282. set: NOOP
  3283. });
  3284. });
  3285. }
  3286. }
  3287. // dev only
  3288. function exposeSetupStateOnRenderContext(instance) {
  3289. const { ctx, setupState } = instance;
  3290. Object.keys(toRaw(setupState)).forEach(key => {
  3291. if (!setupState.__isScriptSetup) {
  3292. if (isReservedPrefix(key[0])) {
  3293. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  3294. `which are reserved prefixes for Vue internals.`);
  3295. return;
  3296. }
  3297. Object.defineProperty(ctx, key, {
  3298. enumerable: true,
  3299. configurable: true,
  3300. get: () => setupState[key],
  3301. set: NOOP
  3302. });
  3303. }
  3304. });
  3305. }
  3306. function createDuplicateChecker() {
  3307. const cache = Object.create(null);
  3308. return (type, key) => {
  3309. if (cache[key]) {
  3310. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  3311. }
  3312. else {
  3313. cache[key] = type;
  3314. }
  3315. };
  3316. }
  3317. let shouldCacheAccess = true;
  3318. function applyOptions(instance) {
  3319. const options = resolveMergedOptions(instance);
  3320. const publicThis = instance.proxy;
  3321. const ctx = instance.ctx;
  3322. // do not cache property access on public proxy during state initialization
  3323. shouldCacheAccess = false;
  3324. // call beforeCreate first before accessing other options since
  3325. // the hook may mutate resolved options (#2791)
  3326. if (options.beforeCreate) {
  3327. callHook(options.beforeCreate, instance, "bc" /* LifecycleHooks.BEFORE_CREATE */);
  3328. }
  3329. const {
  3330. // state
  3331. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  3332. // lifecycle
  3333. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  3334. // public API
  3335. expose, inheritAttrs,
  3336. // assets
  3337. components, directives, filters } = options;
  3338. const checkDuplicateProperties = (process.env.NODE_ENV !== 'production') ? createDuplicateChecker() : null;
  3339. if ((process.env.NODE_ENV !== 'production')) {
  3340. const [propsOptions] = instance.propsOptions;
  3341. if (propsOptions) {
  3342. for (const key in propsOptions) {
  3343. checkDuplicateProperties("Props" /* OptionTypes.PROPS */, key);
  3344. }
  3345. }
  3346. }
  3347. // options initialization order (to be consistent with Vue 2):
  3348. // - props (already done outside of this function)
  3349. // - inject
  3350. // - methods
  3351. // - data (deferred since it relies on `this` access)
  3352. // - computed
  3353. // - watch (deferred since it relies on `this` access)
  3354. if (injectOptions) {
  3355. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  3356. }
  3357. if (methods) {
  3358. for (const key in methods) {
  3359. const methodHandler = methods[key];
  3360. if (isFunction(methodHandler)) {
  3361. // In dev mode, we use the `createRenderContext` function to define
  3362. // methods to the proxy target, and those are read-only but
  3363. // reconfigurable, so it needs to be redefined here
  3364. if ((process.env.NODE_ENV !== 'production')) {
  3365. Object.defineProperty(ctx, key, {
  3366. value: methodHandler.bind(publicThis),
  3367. configurable: true,
  3368. enumerable: true,
  3369. writable: true
  3370. });
  3371. }
  3372. else {
  3373. ctx[key] = methodHandler.bind(publicThis);
  3374. }
  3375. if ((process.env.NODE_ENV !== 'production')) {
  3376. checkDuplicateProperties("Methods" /* OptionTypes.METHODS */, key);
  3377. }
  3378. }
  3379. else if ((process.env.NODE_ENV !== 'production')) {
  3380. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  3381. `Did you reference the function correctly?`);
  3382. }
  3383. }
  3384. }
  3385. if (dataOptions) {
  3386. if ((process.env.NODE_ENV !== 'production') && !isFunction(dataOptions)) {
  3387. warn(`The data option must be a function. ` +
  3388. `Plain object usage is no longer supported.`);
  3389. }
  3390. const data = dataOptions.call(publicThis, publicThis);
  3391. if ((process.env.NODE_ENV !== 'production') && isPromise(data)) {
  3392. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  3393. `intend to perform data fetching before component renders, use ` +
  3394. `async setup() + <Suspense>.`);
  3395. }
  3396. if (!isObject(data)) {
  3397. (process.env.NODE_ENV !== 'production') && warn(`data() should return an object.`);
  3398. }
  3399. else {
  3400. instance.data = reactive(data);
  3401. if ((process.env.NODE_ENV !== 'production')) {
  3402. for (const key in data) {
  3403. checkDuplicateProperties("Data" /* OptionTypes.DATA */, key);
  3404. // expose data on ctx during dev
  3405. if (!isReservedPrefix(key[0])) {
  3406. Object.defineProperty(ctx, key, {
  3407. configurable: true,
  3408. enumerable: true,
  3409. get: () => data[key],
  3410. set: NOOP
  3411. });
  3412. }
  3413. }
  3414. }
  3415. }
  3416. }
  3417. // state initialization complete at this point - start caching access
  3418. shouldCacheAccess = true;
  3419. if (computedOptions) {
  3420. for (const key in computedOptions) {
  3421. const opt = computedOptions[key];
  3422. const get = isFunction(opt)
  3423. ? opt.bind(publicThis, publicThis)
  3424. : isFunction(opt.get)
  3425. ? opt.get.bind(publicThis, publicThis)
  3426. : NOOP;
  3427. if ((process.env.NODE_ENV !== 'production') && get === NOOP) {
  3428. warn(`Computed property "${key}" has no getter.`);
  3429. }
  3430. const set = !isFunction(opt) && isFunction(opt.set)
  3431. ? opt.set.bind(publicThis)
  3432. : (process.env.NODE_ENV !== 'production')
  3433. ? () => {
  3434. warn(`Write operation failed: computed property "${key}" is readonly.`);
  3435. }
  3436. : NOOP;
  3437. const c = computed({
  3438. get,
  3439. set
  3440. });
  3441. Object.defineProperty(ctx, key, {
  3442. enumerable: true,
  3443. configurable: true,
  3444. get: () => c.value,
  3445. set: v => (c.value = v)
  3446. });
  3447. if ((process.env.NODE_ENV !== 'production')) {
  3448. checkDuplicateProperties("Computed" /* OptionTypes.COMPUTED */, key);
  3449. }
  3450. }
  3451. }
  3452. if (watchOptions) {
  3453. for (const key in watchOptions) {
  3454. createWatcher(watchOptions[key], ctx, publicThis, key);
  3455. }
  3456. }
  3457. if (provideOptions) {
  3458. const provides = isFunction(provideOptions)
  3459. ? provideOptions.call(publicThis)
  3460. : provideOptions;
  3461. Reflect.ownKeys(provides).forEach(key => {
  3462. provide(key, provides[key]);
  3463. });
  3464. }
  3465. if (created) {
  3466. callHook(created, instance, "c" /* LifecycleHooks.CREATED */);
  3467. }
  3468. function registerLifecycleHook(register, hook) {
  3469. if (isArray(hook)) {
  3470. hook.forEach(_hook => register(_hook.bind(publicThis)));
  3471. }
  3472. else if (hook) {
  3473. register(hook.bind(publicThis));
  3474. }
  3475. }
  3476. registerLifecycleHook(onBeforeMount, beforeMount);
  3477. registerLifecycleHook(onMounted, mounted);
  3478. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  3479. registerLifecycleHook(onUpdated, updated);
  3480. registerLifecycleHook(onActivated, activated);
  3481. registerLifecycleHook(onDeactivated, deactivated);
  3482. registerLifecycleHook(onErrorCaptured, errorCaptured);
  3483. registerLifecycleHook(onRenderTracked, renderTracked);
  3484. registerLifecycleHook(onRenderTriggered, renderTriggered);
  3485. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  3486. registerLifecycleHook(onUnmounted, unmounted);
  3487. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  3488. if (isArray(expose)) {
  3489. if (expose.length) {
  3490. const exposed = instance.exposed || (instance.exposed = {});
  3491. expose.forEach(key => {
  3492. Object.defineProperty(exposed, key, {
  3493. get: () => publicThis[key],
  3494. set: val => (publicThis[key] = val)
  3495. });
  3496. });
  3497. }
  3498. else if (!instance.exposed) {
  3499. instance.exposed = {};
  3500. }
  3501. }
  3502. // options that are handled when creating the instance but also need to be
  3503. // applied from mixins
  3504. if (render && instance.render === NOOP) {
  3505. instance.render = render;
  3506. }
  3507. if (inheritAttrs != null) {
  3508. instance.inheritAttrs = inheritAttrs;
  3509. }
  3510. // asset options.
  3511. if (components)
  3512. instance.components = components;
  3513. if (directives)
  3514. instance.directives = directives;
  3515. }
  3516. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  3517. if (isArray(injectOptions)) {
  3518. injectOptions = normalizeInject(injectOptions);
  3519. }
  3520. for (const key in injectOptions) {
  3521. const opt = injectOptions[key];
  3522. let injected;
  3523. if (isObject(opt)) {
  3524. if ('default' in opt) {
  3525. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  3526. }
  3527. else {
  3528. injected = inject(opt.from || key);
  3529. }
  3530. }
  3531. else {
  3532. injected = inject(opt);
  3533. }
  3534. if (isRef(injected)) {
  3535. // TODO remove the check in 3.3
  3536. if (unwrapRef) {
  3537. Object.defineProperty(ctx, key, {
  3538. enumerable: true,
  3539. configurable: true,
  3540. get: () => injected.value,
  3541. set: v => (injected.value = v)
  3542. });
  3543. }
  3544. else {
  3545. if ((process.env.NODE_ENV !== 'production')) {
  3546. warn(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  3547. `and no longer needs \`.value\` in the next minor release. ` +
  3548. `To opt-in to the new behavior now, ` +
  3549. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  3550. `temporary and will not be needed in the future.)`);
  3551. }
  3552. ctx[key] = injected;
  3553. }
  3554. }
  3555. else {
  3556. ctx[key] = injected;
  3557. }
  3558. if ((process.env.NODE_ENV !== 'production')) {
  3559. checkDuplicateProperties("Inject" /* OptionTypes.INJECT */, key);
  3560. }
  3561. }
  3562. }
  3563. function callHook(hook, instance, type) {
  3564. callWithAsyncErrorHandling(isArray(hook)
  3565. ? hook.map(h => h.bind(instance.proxy))
  3566. : hook.bind(instance.proxy), instance, type);
  3567. }
  3568. function createWatcher(raw, ctx, publicThis, key) {
  3569. const getter = key.includes('.')
  3570. ? createPathGetter(publicThis, key)
  3571. : () => publicThis[key];
  3572. if (isString(raw)) {
  3573. const handler = ctx[raw];
  3574. if (isFunction(handler)) {
  3575. watch(getter, handler);
  3576. }
  3577. else if ((process.env.NODE_ENV !== 'production')) {
  3578. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  3579. }
  3580. }
  3581. else if (isFunction(raw)) {
  3582. watch(getter, raw.bind(publicThis));
  3583. }
  3584. else if (isObject(raw)) {
  3585. if (isArray(raw)) {
  3586. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  3587. }
  3588. else {
  3589. const handler = isFunction(raw.handler)
  3590. ? raw.handler.bind(publicThis)
  3591. : ctx[raw.handler];
  3592. if (isFunction(handler)) {
  3593. watch(getter, handler, raw);
  3594. }
  3595. else if ((process.env.NODE_ENV !== 'production')) {
  3596. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  3597. }
  3598. }
  3599. }
  3600. else if ((process.env.NODE_ENV !== 'production')) {
  3601. warn(`Invalid watch option: "${key}"`, raw);
  3602. }
  3603. }
  3604. /**
  3605. * Resolve merged options and cache it on the component.
  3606. * This is done only once per-component since the merging does not involve
  3607. * instances.
  3608. */
  3609. function resolveMergedOptions(instance) {
  3610. const base = instance.type;
  3611. const { mixins, extends: extendsOptions } = base;
  3612. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  3613. const cached = cache.get(base);
  3614. let resolved;
  3615. if (cached) {
  3616. resolved = cached;
  3617. }
  3618. else if (!globalMixins.length && !mixins && !extendsOptions) {
  3619. {
  3620. resolved = base;
  3621. }
  3622. }
  3623. else {
  3624. resolved = {};
  3625. if (globalMixins.length) {
  3626. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  3627. }
  3628. mergeOptions(resolved, base, optionMergeStrategies);
  3629. }
  3630. if (isObject(base)) {
  3631. cache.set(base, resolved);
  3632. }
  3633. return resolved;
  3634. }
  3635. function mergeOptions(to, from, strats, asMixin = false) {
  3636. const { mixins, extends: extendsOptions } = from;
  3637. if (extendsOptions) {
  3638. mergeOptions(to, extendsOptions, strats, true);
  3639. }
  3640. if (mixins) {
  3641. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  3642. }
  3643. for (const key in from) {
  3644. if (asMixin && key === 'expose') {
  3645. (process.env.NODE_ENV !== 'production') &&
  3646. warn(`"expose" option is ignored when declared in mixins or extends. ` +
  3647. `It should only be declared in the base component itself.`);
  3648. }
  3649. else {
  3650. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  3651. to[key] = strat ? strat(to[key], from[key]) : from[key];
  3652. }
  3653. }
  3654. return to;
  3655. }
  3656. const internalOptionMergeStrats = {
  3657. data: mergeDataFn,
  3658. props: mergeObjectOptions,
  3659. emits: mergeObjectOptions,
  3660. // objects
  3661. methods: mergeObjectOptions,
  3662. computed: mergeObjectOptions,
  3663. // lifecycle
  3664. beforeCreate: mergeAsArray,
  3665. created: mergeAsArray,
  3666. beforeMount: mergeAsArray,
  3667. mounted: mergeAsArray,
  3668. beforeUpdate: mergeAsArray,
  3669. updated: mergeAsArray,
  3670. beforeDestroy: mergeAsArray,
  3671. beforeUnmount: mergeAsArray,
  3672. destroyed: mergeAsArray,
  3673. unmounted: mergeAsArray,
  3674. activated: mergeAsArray,
  3675. deactivated: mergeAsArray,
  3676. errorCaptured: mergeAsArray,
  3677. serverPrefetch: mergeAsArray,
  3678. // assets
  3679. components: mergeObjectOptions,
  3680. directives: mergeObjectOptions,
  3681. // watch
  3682. watch: mergeWatchOptions,
  3683. // provide / inject
  3684. provide: mergeDataFn,
  3685. inject: mergeInject
  3686. };
  3687. function mergeDataFn(to, from) {
  3688. if (!from) {
  3689. return to;
  3690. }
  3691. if (!to) {
  3692. return from;
  3693. }
  3694. return function mergedDataFn() {
  3695. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  3696. };
  3697. }
  3698. function mergeInject(to, from) {
  3699. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  3700. }
  3701. function normalizeInject(raw) {
  3702. if (isArray(raw)) {
  3703. const res = {};
  3704. for (let i = 0; i < raw.length; i++) {
  3705. res[raw[i]] = raw[i];
  3706. }
  3707. return res;
  3708. }
  3709. return raw;
  3710. }
  3711. function mergeAsArray(to, from) {
  3712. return to ? [...new Set([].concat(to, from))] : from;
  3713. }
  3714. function mergeObjectOptions(to, from) {
  3715. return to ? extend(extend(Object.create(null), to), from) : from;
  3716. }
  3717. function mergeWatchOptions(to, from) {
  3718. if (!to)
  3719. return from;
  3720. if (!from)
  3721. return to;
  3722. const merged = extend(Object.create(null), to);
  3723. for (const key in from) {
  3724. merged[key] = mergeAsArray(to[key], from[key]);
  3725. }
  3726. return merged;
  3727. }
  3728. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  3729. isSSR = false) {
  3730. const props = {};
  3731. const attrs = {};
  3732. def(attrs, InternalObjectKey, 1);
  3733. instance.propsDefaults = Object.create(null);
  3734. setFullProps(instance, rawProps, props, attrs);
  3735. // ensure all declared prop keys are present
  3736. for (const key in instance.propsOptions[0]) {
  3737. if (!(key in props)) {
  3738. props[key] = undefined;
  3739. }
  3740. }
  3741. // validation
  3742. if ((process.env.NODE_ENV !== 'production')) {
  3743. validateProps(rawProps || {}, props, instance);
  3744. }
  3745. if (isStateful) {
  3746. // stateful
  3747. instance.props = isSSR ? props : shallowReactive(props);
  3748. }
  3749. else {
  3750. if (!instance.type.props) {
  3751. // functional w/ optional props, props === attrs
  3752. instance.props = attrs;
  3753. }
  3754. else {
  3755. // functional w/ declared props
  3756. instance.props = props;
  3757. }
  3758. }
  3759. instance.attrs = attrs;
  3760. }
  3761. function isInHmrContext(instance) {
  3762. while (instance) {
  3763. if (instance.type.__hmrId)
  3764. return true;
  3765. instance = instance.parent;
  3766. }
  3767. }
  3768. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  3769. const { props, attrs, vnode: { patchFlag } } = instance;
  3770. const rawCurrentProps = toRaw(props);
  3771. const [options] = instance.propsOptions;
  3772. let hasAttrsChanged = false;
  3773. if (
  3774. // always force full diff in dev
  3775. // - #1942 if hmr is enabled with sfc component
  3776. // - vite#872 non-sfc component used by sfc component
  3777. !((process.env.NODE_ENV !== 'production') && isInHmrContext(instance)) &&
  3778. (optimized || patchFlag > 0) &&
  3779. !(patchFlag & 16 /* PatchFlags.FULL_PROPS */)) {
  3780. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  3781. // Compiler-generated props & no keys change, just set the updated
  3782. // the props.
  3783. const propsToUpdate = instance.vnode.dynamicProps;
  3784. for (let i = 0; i < propsToUpdate.length; i++) {
  3785. let key = propsToUpdate[i];
  3786. // skip if the prop key is a declared emit event listener
  3787. if (isEmitListener(instance.emitsOptions, key)) {
  3788. continue;
  3789. }
  3790. // PROPS flag guarantees rawProps to be non-null
  3791. const value = rawProps[key];
  3792. if (options) {
  3793. // attr / props separation was done on init and will be consistent
  3794. // in this code path, so just check if attrs have it.
  3795. if (hasOwn(attrs, key)) {
  3796. if (value !== attrs[key]) {
  3797. attrs[key] = value;
  3798. hasAttrsChanged = true;
  3799. }
  3800. }
  3801. else {
  3802. const camelizedKey = camelize(key);
  3803. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  3804. }
  3805. }
  3806. else {
  3807. if (value !== attrs[key]) {
  3808. attrs[key] = value;
  3809. hasAttrsChanged = true;
  3810. }
  3811. }
  3812. }
  3813. }
  3814. }
  3815. else {
  3816. // full props update.
  3817. if (setFullProps(instance, rawProps, props, attrs)) {
  3818. hasAttrsChanged = true;
  3819. }
  3820. // in case of dynamic props, check if we need to delete keys from
  3821. // the props object
  3822. let kebabKey;
  3823. for (const key in rawCurrentProps) {
  3824. if (!rawProps ||
  3825. // for camelCase
  3826. (!hasOwn(rawProps, key) &&
  3827. // it's possible the original props was passed in as kebab-case
  3828. // and converted to camelCase (#955)
  3829. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  3830. if (options) {
  3831. if (rawPrevProps &&
  3832. // for camelCase
  3833. (rawPrevProps[key] !== undefined ||
  3834. // for kebab-case
  3835. rawPrevProps[kebabKey] !== undefined)) {
  3836. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  3837. }
  3838. }
  3839. else {
  3840. delete props[key];
  3841. }
  3842. }
  3843. }
  3844. // in the case of functional component w/o props declaration, props and
  3845. // attrs point to the same object so it should already have been updated.
  3846. if (attrs !== rawCurrentProps) {
  3847. for (const key in attrs) {
  3848. if (!rawProps ||
  3849. (!hasOwn(rawProps, key) &&
  3850. (!false ))) {
  3851. delete attrs[key];
  3852. hasAttrsChanged = true;
  3853. }
  3854. }
  3855. }
  3856. }
  3857. // trigger updates for $attrs in case it's used in component slots
  3858. if (hasAttrsChanged) {
  3859. trigger(instance, "set" /* TriggerOpTypes.SET */, '$attrs');
  3860. }
  3861. if ((process.env.NODE_ENV !== 'production')) {
  3862. validateProps(rawProps || {}, props, instance);
  3863. }
  3864. }
  3865. function setFullProps(instance, rawProps, props, attrs) {
  3866. const [options, needCastKeys] = instance.propsOptions;
  3867. let hasAttrsChanged = false;
  3868. let rawCastValues;
  3869. if (rawProps) {
  3870. for (let key in rawProps) {
  3871. // key, ref are reserved and never passed down
  3872. if (isReservedProp(key)) {
  3873. continue;
  3874. }
  3875. const value = rawProps[key];
  3876. // prop option names are camelized during normalization, so to support
  3877. // kebab -> camel conversion here we need to camelize the key.
  3878. let camelKey;
  3879. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  3880. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  3881. props[camelKey] = value;
  3882. }
  3883. else {
  3884. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  3885. }
  3886. }
  3887. else if (!isEmitListener(instance.emitsOptions, key)) {
  3888. if (!(key in attrs) || value !== attrs[key]) {
  3889. attrs[key] = value;
  3890. hasAttrsChanged = true;
  3891. }
  3892. }
  3893. }
  3894. }
  3895. if (needCastKeys) {
  3896. const rawCurrentProps = toRaw(props);
  3897. const castValues = rawCastValues || EMPTY_OBJ;
  3898. for (let i = 0; i < needCastKeys.length; i++) {
  3899. const key = needCastKeys[i];
  3900. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  3901. }
  3902. }
  3903. return hasAttrsChanged;
  3904. }
  3905. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  3906. const opt = options[key];
  3907. if (opt != null) {
  3908. const hasDefault = hasOwn(opt, 'default');
  3909. // default values
  3910. if (hasDefault && value === undefined) {
  3911. const defaultValue = opt.default;
  3912. if (opt.type !== Function && isFunction(defaultValue)) {
  3913. const { propsDefaults } = instance;
  3914. if (key in propsDefaults) {
  3915. value = propsDefaults[key];
  3916. }
  3917. else {
  3918. setCurrentInstance(instance);
  3919. value = propsDefaults[key] = defaultValue.call(null, props);
  3920. unsetCurrentInstance();
  3921. }
  3922. }
  3923. else {
  3924. value = defaultValue;
  3925. }
  3926. }
  3927. // boolean casting
  3928. if (opt[0 /* BooleanFlags.shouldCast */]) {
  3929. if (isAbsent && !hasDefault) {
  3930. value = false;
  3931. }
  3932. else if (opt[1 /* BooleanFlags.shouldCastTrue */] &&
  3933. (value === '' || value === hyphenate(key))) {
  3934. value = true;
  3935. }
  3936. }
  3937. }
  3938. return value;
  3939. }
  3940. function normalizePropsOptions(comp, appContext, asMixin = false) {
  3941. const cache = appContext.propsCache;
  3942. const cached = cache.get(comp);
  3943. if (cached) {
  3944. return cached;
  3945. }
  3946. const raw = comp.props;
  3947. const normalized = {};
  3948. const needCastKeys = [];
  3949. // apply mixin/extends props
  3950. let hasExtends = false;
  3951. if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
  3952. const extendProps = (raw) => {
  3953. hasExtends = true;
  3954. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  3955. extend(normalized, props);
  3956. if (keys)
  3957. needCastKeys.push(...keys);
  3958. };
  3959. if (!asMixin && appContext.mixins.length) {
  3960. appContext.mixins.forEach(extendProps);
  3961. }
  3962. if (comp.extends) {
  3963. extendProps(comp.extends);
  3964. }
  3965. if (comp.mixins) {
  3966. comp.mixins.forEach(extendProps);
  3967. }
  3968. }
  3969. if (!raw && !hasExtends) {
  3970. if (isObject(comp)) {
  3971. cache.set(comp, EMPTY_ARR);
  3972. }
  3973. return EMPTY_ARR;
  3974. }
  3975. if (isArray(raw)) {
  3976. for (let i = 0; i < raw.length; i++) {
  3977. if ((process.env.NODE_ENV !== 'production') && !isString(raw[i])) {
  3978. warn(`props must be strings when using array syntax.`, raw[i]);
  3979. }
  3980. const normalizedKey = camelize(raw[i]);
  3981. if (validatePropName(normalizedKey)) {
  3982. normalized[normalizedKey] = EMPTY_OBJ;
  3983. }
  3984. }
  3985. }
  3986. else if (raw) {
  3987. if ((process.env.NODE_ENV !== 'production') && !isObject(raw)) {
  3988. warn(`invalid props options`, raw);
  3989. }
  3990. for (const key in raw) {
  3991. const normalizedKey = camelize(key);
  3992. if (validatePropName(normalizedKey)) {
  3993. const opt = raw[key];
  3994. const prop = (normalized[normalizedKey] =
  3995. isArray(opt) || isFunction(opt) ? { type: opt } : Object.assign({}, opt));
  3996. if (prop) {
  3997. const booleanIndex = getTypeIndex(Boolean, prop.type);
  3998. const stringIndex = getTypeIndex(String, prop.type);
  3999. prop[0 /* BooleanFlags.shouldCast */] = booleanIndex > -1;
  4000. prop[1 /* BooleanFlags.shouldCastTrue */] =
  4001. stringIndex < 0 || booleanIndex < stringIndex;
  4002. // if the prop needs boolean casting or default value
  4003. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  4004. needCastKeys.push(normalizedKey);
  4005. }
  4006. }
  4007. }
  4008. }
  4009. }
  4010. const res = [normalized, needCastKeys];
  4011. if (isObject(comp)) {
  4012. cache.set(comp, res);
  4013. }
  4014. return res;
  4015. }
  4016. function validatePropName(key) {
  4017. if (key[0] !== '$') {
  4018. return true;
  4019. }
  4020. else if ((process.env.NODE_ENV !== 'production')) {
  4021. warn(`Invalid prop name: "${key}" is a reserved property.`);
  4022. }
  4023. return false;
  4024. }
  4025. // use function string name to check type constructors
  4026. // so that it works across vms / iframes.
  4027. function getType(ctor) {
  4028. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  4029. return match ? match[1] : ctor === null ? 'null' : '';
  4030. }
  4031. function isSameType(a, b) {
  4032. return getType(a) === getType(b);
  4033. }
  4034. function getTypeIndex(type, expectedTypes) {
  4035. if (isArray(expectedTypes)) {
  4036. return expectedTypes.findIndex(t => isSameType(t, type));
  4037. }
  4038. else if (isFunction(expectedTypes)) {
  4039. return isSameType(expectedTypes, type) ? 0 : -1;
  4040. }
  4041. return -1;
  4042. }
  4043. /**
  4044. * dev only
  4045. */
  4046. function validateProps(rawProps, props, instance) {
  4047. const resolvedValues = toRaw(props);
  4048. const options = instance.propsOptions[0];
  4049. for (const key in options) {
  4050. let opt = options[key];
  4051. if (opt == null)
  4052. continue;
  4053. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  4054. }
  4055. }
  4056. /**
  4057. * dev only
  4058. */
  4059. function validateProp(name, value, prop, isAbsent) {
  4060. const { type, required, validator } = prop;
  4061. // required!
  4062. if (required && isAbsent) {
  4063. warn('Missing required prop: "' + name + '"');
  4064. return;
  4065. }
  4066. // missing but optional
  4067. if (value == null && !prop.required) {
  4068. return;
  4069. }
  4070. // type check
  4071. if (type != null && type !== true) {
  4072. let isValid = false;
  4073. const types = isArray(type) ? type : [type];
  4074. const expectedTypes = [];
  4075. // value is valid as long as one of the specified types match
  4076. for (let i = 0; i < types.length && !isValid; i++) {
  4077. const { valid, expectedType } = assertType(value, types[i]);
  4078. expectedTypes.push(expectedType || '');
  4079. isValid = valid;
  4080. }
  4081. if (!isValid) {
  4082. warn(getInvalidTypeMessage(name, value, expectedTypes));
  4083. return;
  4084. }
  4085. }
  4086. // custom validator
  4087. if (validator && !validator(value)) {
  4088. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  4089. }
  4090. }
  4091. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  4092. /**
  4093. * dev only
  4094. */
  4095. function assertType(value, type) {
  4096. let valid;
  4097. const expectedType = getType(type);
  4098. if (isSimpleType(expectedType)) {
  4099. const t = typeof value;
  4100. valid = t === expectedType.toLowerCase();
  4101. // for primitive wrapper objects
  4102. if (!valid && t === 'object') {
  4103. valid = value instanceof type;
  4104. }
  4105. }
  4106. else if (expectedType === 'Object') {
  4107. valid = isObject(value);
  4108. }
  4109. else if (expectedType === 'Array') {
  4110. valid = isArray(value);
  4111. }
  4112. else if (expectedType === 'null') {
  4113. valid = value === null;
  4114. }
  4115. else {
  4116. valid = value instanceof type;
  4117. }
  4118. return {
  4119. valid,
  4120. expectedType
  4121. };
  4122. }
  4123. /**
  4124. * dev only
  4125. */
  4126. function getInvalidTypeMessage(name, value, expectedTypes) {
  4127. let message = `Invalid prop: type check failed for prop "${name}".` +
  4128. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  4129. const expectedType = expectedTypes[0];
  4130. const receivedType = toRawType(value);
  4131. const expectedValue = styleValue(value, expectedType);
  4132. const receivedValue = styleValue(value, receivedType);
  4133. // check if we need to specify expected value
  4134. if (expectedTypes.length === 1 &&
  4135. isExplicable(expectedType) &&
  4136. !isBoolean(expectedType, receivedType)) {
  4137. message += ` with value ${expectedValue}`;
  4138. }
  4139. message += `, got ${receivedType} `;
  4140. // check if we need to specify received value
  4141. if (isExplicable(receivedType)) {
  4142. message += `with value ${receivedValue}.`;
  4143. }
  4144. return message;
  4145. }
  4146. /**
  4147. * dev only
  4148. */
  4149. function styleValue(value, type) {
  4150. if (type === 'String') {
  4151. return `"${value}"`;
  4152. }
  4153. else if (type === 'Number') {
  4154. return `${Number(value)}`;
  4155. }
  4156. else {
  4157. return `${value}`;
  4158. }
  4159. }
  4160. /**
  4161. * dev only
  4162. */
  4163. function isExplicable(type) {
  4164. const explicitTypes = ['string', 'number', 'boolean'];
  4165. return explicitTypes.some(elem => type.toLowerCase() === elem);
  4166. }
  4167. /**
  4168. * dev only
  4169. */
  4170. function isBoolean(...args) {
  4171. return args.some(elem => elem.toLowerCase() === 'boolean');
  4172. }
  4173. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  4174. const normalizeSlotValue = (value) => isArray(value)
  4175. ? value.map(normalizeVNode)
  4176. : [normalizeVNode(value)];
  4177. const normalizeSlot = (key, rawSlot, ctx) => {
  4178. if (rawSlot._n) {
  4179. // already normalized - #5353
  4180. return rawSlot;
  4181. }
  4182. const normalized = withCtx((...args) => {
  4183. if ((process.env.NODE_ENV !== 'production') && currentInstance) {
  4184. warn(`Slot "${key}" invoked outside of the render function: ` +
  4185. `this will not track dependencies used in the slot. ` +
  4186. `Invoke the slot function inside the render function instead.`);
  4187. }
  4188. return normalizeSlotValue(rawSlot(...args));
  4189. }, ctx);
  4190. normalized._c = false;
  4191. return normalized;
  4192. };
  4193. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  4194. const ctx = rawSlots._ctx;
  4195. for (const key in rawSlots) {
  4196. if (isInternalKey(key))
  4197. continue;
  4198. const value = rawSlots[key];
  4199. if (isFunction(value)) {
  4200. slots[key] = normalizeSlot(key, value, ctx);
  4201. }
  4202. else if (value != null) {
  4203. if ((process.env.NODE_ENV !== 'production') &&
  4204. !(false )) {
  4205. warn(`Non-function value encountered for slot "${key}". ` +
  4206. `Prefer function slots for better performance.`);
  4207. }
  4208. const normalized = normalizeSlotValue(value);
  4209. slots[key] = () => normalized;
  4210. }
  4211. }
  4212. };
  4213. const normalizeVNodeSlots = (instance, children) => {
  4214. if ((process.env.NODE_ENV !== 'production') &&
  4215. !isKeepAlive(instance.vnode) &&
  4216. !(false )) {
  4217. warn(`Non-function value encountered for default slot. ` +
  4218. `Prefer function slots for better performance.`);
  4219. }
  4220. const normalized = normalizeSlotValue(children);
  4221. instance.slots.default = () => normalized;
  4222. };
  4223. const initSlots = (instance, children) => {
  4224. if (instance.vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  4225. const type = children._;
  4226. if (type) {
  4227. // users can get the shallow readonly version of the slots object through `this.$slots`,
  4228. // we should avoid the proxy object polluting the slots of the internal instance
  4229. instance.slots = toRaw(children);
  4230. // make compiler marker non-enumerable
  4231. def(children, '_', type);
  4232. }
  4233. else {
  4234. normalizeObjectSlots(children, (instance.slots = {}));
  4235. }
  4236. }
  4237. else {
  4238. instance.slots = {};
  4239. if (children) {
  4240. normalizeVNodeSlots(instance, children);
  4241. }
  4242. }
  4243. def(instance.slots, InternalObjectKey, 1);
  4244. };
  4245. const updateSlots = (instance, children, optimized) => {
  4246. const { vnode, slots } = instance;
  4247. let needDeletionCheck = true;
  4248. let deletionComparisonTarget = EMPTY_OBJ;
  4249. if (vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  4250. const type = children._;
  4251. if (type) {
  4252. // compiled slots.
  4253. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  4254. // Parent was HMR updated so slot content may have changed.
  4255. // force update slots and mark instance for hmr as well
  4256. extend(slots, children);
  4257. }
  4258. else if (optimized && type === 1 /* SlotFlags.STABLE */) {
  4259. // compiled AND stable.
  4260. // no need to update, and skip stale slots removal.
  4261. needDeletionCheck = false;
  4262. }
  4263. else {
  4264. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  4265. // normalization.
  4266. extend(slots, children);
  4267. // #2893
  4268. // when rendering the optimized slots by manually written render function,
  4269. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  4270. // i.e. let the `renderSlot` create the bailed Fragment
  4271. if (!optimized && type === 1 /* SlotFlags.STABLE */) {
  4272. delete slots._;
  4273. }
  4274. }
  4275. }
  4276. else {
  4277. needDeletionCheck = !children.$stable;
  4278. normalizeObjectSlots(children, slots);
  4279. }
  4280. deletionComparisonTarget = children;
  4281. }
  4282. else if (children) {
  4283. // non slot object children (direct value) passed to a component
  4284. normalizeVNodeSlots(instance, children);
  4285. deletionComparisonTarget = { default: 1 };
  4286. }
  4287. // delete stale slots
  4288. if (needDeletionCheck) {
  4289. for (const key in slots) {
  4290. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  4291. delete slots[key];
  4292. }
  4293. }
  4294. }
  4295. };
  4296. function createAppContext() {
  4297. return {
  4298. app: null,
  4299. config: {
  4300. isNativeTag: NO,
  4301. performance: false,
  4302. globalProperties: {},
  4303. optionMergeStrategies: {},
  4304. errorHandler: undefined,
  4305. warnHandler: undefined,
  4306. compilerOptions: {}
  4307. },
  4308. mixins: [],
  4309. components: {},
  4310. directives: {},
  4311. provides: Object.create(null),
  4312. optionsCache: new WeakMap(),
  4313. propsCache: new WeakMap(),
  4314. emitsCache: new WeakMap()
  4315. };
  4316. }
  4317. let uid = 0;
  4318. function createAppAPI(render, hydrate) {
  4319. return function createApp(rootComponent, rootProps = null) {
  4320. if (!isFunction(rootComponent)) {
  4321. rootComponent = Object.assign({}, rootComponent);
  4322. }
  4323. if (rootProps != null && !isObject(rootProps)) {
  4324. (process.env.NODE_ENV !== 'production') && warn(`root props passed to app.mount() must be an object.`);
  4325. rootProps = null;
  4326. }
  4327. const context = createAppContext();
  4328. const installedPlugins = new Set();
  4329. let isMounted = false;
  4330. const app = (context.app = {
  4331. _uid: uid++,
  4332. _component: rootComponent,
  4333. _props: rootProps,
  4334. _container: null,
  4335. _context: context,
  4336. _instance: null,
  4337. version,
  4338. get config() {
  4339. return context.config;
  4340. },
  4341. set config(v) {
  4342. if ((process.env.NODE_ENV !== 'production')) {
  4343. warn(`app.config cannot be replaced. Modify individual options instead.`);
  4344. }
  4345. },
  4346. use(plugin, ...options) {
  4347. if (installedPlugins.has(plugin)) {
  4348. (process.env.NODE_ENV !== 'production') && warn(`Plugin has already been applied to target app.`);
  4349. }
  4350. else if (plugin && isFunction(plugin.install)) {
  4351. installedPlugins.add(plugin);
  4352. plugin.install(app, ...options);
  4353. }
  4354. else if (isFunction(plugin)) {
  4355. installedPlugins.add(plugin);
  4356. plugin(app, ...options);
  4357. }
  4358. else if ((process.env.NODE_ENV !== 'production')) {
  4359. warn(`A plugin must either be a function or an object with an "install" ` +
  4360. `function.`);
  4361. }
  4362. return app;
  4363. },
  4364. mixin(mixin) {
  4365. if (__VUE_OPTIONS_API__) {
  4366. if (!context.mixins.includes(mixin)) {
  4367. context.mixins.push(mixin);
  4368. }
  4369. else if ((process.env.NODE_ENV !== 'production')) {
  4370. warn('Mixin has already been applied to target app' +
  4371. (mixin.name ? `: ${mixin.name}` : ''));
  4372. }
  4373. }
  4374. else if ((process.env.NODE_ENV !== 'production')) {
  4375. warn('Mixins are only available in builds supporting Options API');
  4376. }
  4377. return app;
  4378. },
  4379. component(name, component) {
  4380. if ((process.env.NODE_ENV !== 'production')) {
  4381. validateComponentName(name, context.config);
  4382. }
  4383. if (!component) {
  4384. return context.components[name];
  4385. }
  4386. if ((process.env.NODE_ENV !== 'production') && context.components[name]) {
  4387. warn(`Component "${name}" has already been registered in target app.`);
  4388. }
  4389. context.components[name] = component;
  4390. return app;
  4391. },
  4392. directive(name, directive) {
  4393. if ((process.env.NODE_ENV !== 'production')) {
  4394. validateDirectiveName(name);
  4395. }
  4396. if (!directive) {
  4397. return context.directives[name];
  4398. }
  4399. if ((process.env.NODE_ENV !== 'production') && context.directives[name]) {
  4400. warn(`Directive "${name}" has already been registered in target app.`);
  4401. }
  4402. context.directives[name] = directive;
  4403. return app;
  4404. },
  4405. mount(rootContainer, isHydrate, isSVG) {
  4406. if (!isMounted) {
  4407. // #5571
  4408. if ((process.env.NODE_ENV !== 'production') && rootContainer.__vue_app__) {
  4409. warn(`There is already an app instance mounted on the host container.\n` +
  4410. ` If you want to mount another app on the same host container,` +
  4411. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  4412. }
  4413. const vnode = createVNode(rootComponent, rootProps);
  4414. // store app context on the root VNode.
  4415. // this will be set on the root instance on initial mount.
  4416. vnode.appContext = context;
  4417. // HMR root reload
  4418. if ((process.env.NODE_ENV !== 'production')) {
  4419. context.reload = () => {
  4420. render(cloneVNode(vnode), rootContainer, isSVG);
  4421. };
  4422. }
  4423. if (isHydrate && hydrate) {
  4424. hydrate(vnode, rootContainer);
  4425. }
  4426. else {
  4427. render(vnode, rootContainer, isSVG);
  4428. }
  4429. isMounted = true;
  4430. app._container = rootContainer;
  4431. rootContainer.__vue_app__ = app;
  4432. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  4433. app._instance = vnode.component;
  4434. devtoolsInitApp(app, version);
  4435. }
  4436. return getExposeProxy(vnode.component) || vnode.component.proxy;
  4437. }
  4438. else if ((process.env.NODE_ENV !== 'production')) {
  4439. warn(`App has already been mounted.\n` +
  4440. `If you want to remount the same app, move your app creation logic ` +
  4441. `into a factory function and create fresh app instances for each ` +
  4442. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  4443. }
  4444. },
  4445. unmount() {
  4446. if (isMounted) {
  4447. render(null, app._container);
  4448. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  4449. app._instance = null;
  4450. devtoolsUnmountApp(app);
  4451. }
  4452. delete app._container.__vue_app__;
  4453. }
  4454. else if ((process.env.NODE_ENV !== 'production')) {
  4455. warn(`Cannot unmount an app that is not mounted.`);
  4456. }
  4457. },
  4458. provide(key, value) {
  4459. if ((process.env.NODE_ENV !== 'production') && key in context.provides) {
  4460. warn(`App already provides property with key "${String(key)}". ` +
  4461. `It will be overwritten with the new value.`);
  4462. }
  4463. context.provides[key] = value;
  4464. return app;
  4465. }
  4466. });
  4467. return app;
  4468. };
  4469. }
  4470. /**
  4471. * Function for handling a template ref
  4472. */
  4473. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  4474. if (isArray(rawRef)) {
  4475. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  4476. return;
  4477. }
  4478. if (isAsyncWrapper(vnode) && !isUnmount) {
  4479. // when mounting async components, nothing needs to be done,
  4480. // because the template ref is forwarded to inner component
  4481. return;
  4482. }
  4483. const refValue = vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */
  4484. ? getExposeProxy(vnode.component) || vnode.component.proxy
  4485. : vnode.el;
  4486. const value = isUnmount ? null : refValue;
  4487. const { i: owner, r: ref } = rawRef;
  4488. if ((process.env.NODE_ENV !== 'production') && !owner) {
  4489. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  4490. `A vnode with ref must be created inside the render function.`);
  4491. return;
  4492. }
  4493. const oldRef = oldRawRef && oldRawRef.r;
  4494. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  4495. const setupState = owner.setupState;
  4496. // dynamic ref changed. unset old ref
  4497. if (oldRef != null && oldRef !== ref) {
  4498. if (isString(oldRef)) {
  4499. refs[oldRef] = null;
  4500. if (hasOwn(setupState, oldRef)) {
  4501. setupState[oldRef] = null;
  4502. }
  4503. }
  4504. else if (isRef(oldRef)) {
  4505. oldRef.value = null;
  4506. }
  4507. }
  4508. if (isFunction(ref)) {
  4509. callWithErrorHandling(ref, owner, 12 /* ErrorCodes.FUNCTION_REF */, [value, refs]);
  4510. }
  4511. else {
  4512. const _isString = isString(ref);
  4513. const _isRef = isRef(ref);
  4514. if (_isString || _isRef) {
  4515. const doSet = () => {
  4516. if (rawRef.f) {
  4517. const existing = _isString
  4518. ? hasOwn(setupState, ref)
  4519. ? setupState[ref]
  4520. : refs[ref]
  4521. : ref.value;
  4522. if (isUnmount) {
  4523. isArray(existing) && remove(existing, refValue);
  4524. }
  4525. else {
  4526. if (!isArray(existing)) {
  4527. if (_isString) {
  4528. refs[ref] = [refValue];
  4529. if (hasOwn(setupState, ref)) {
  4530. setupState[ref] = refs[ref];
  4531. }
  4532. }
  4533. else {
  4534. ref.value = [refValue];
  4535. if (rawRef.k)
  4536. refs[rawRef.k] = ref.value;
  4537. }
  4538. }
  4539. else if (!existing.includes(refValue)) {
  4540. existing.push(refValue);
  4541. }
  4542. }
  4543. }
  4544. else if (_isString) {
  4545. refs[ref] = value;
  4546. if (hasOwn(setupState, ref)) {
  4547. setupState[ref] = value;
  4548. }
  4549. }
  4550. else if (_isRef) {
  4551. ref.value = value;
  4552. if (rawRef.k)
  4553. refs[rawRef.k] = value;
  4554. }
  4555. else if ((process.env.NODE_ENV !== 'production')) {
  4556. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  4557. }
  4558. };
  4559. if (value) {
  4560. doSet.id = -1;
  4561. queuePostRenderEffect(doSet, parentSuspense);
  4562. }
  4563. else {
  4564. doSet();
  4565. }
  4566. }
  4567. else if ((process.env.NODE_ENV !== 'production')) {
  4568. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  4569. }
  4570. }
  4571. }
  4572. let hasMismatch = false;
  4573. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  4574. const isComment = (node) => node.nodeType === 8 /* DOMNodeTypes.COMMENT */;
  4575. // Note: hydration is DOM-specific
  4576. // But we have to place it in core due to tight coupling with core - splitting
  4577. // it out creates a ton of unnecessary complexity.
  4578. // Hydration also depends on some renderer internal logic which needs to be
  4579. // passed in via arguments.
  4580. function createHydrationFunctions(rendererInternals) {
  4581. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  4582. const hydrate = (vnode, container) => {
  4583. if (!container.hasChildNodes()) {
  4584. (process.env.NODE_ENV !== 'production') &&
  4585. warn(`Attempting to hydrate existing markup but container is empty. ` +
  4586. `Performing full mount instead.`);
  4587. patch(null, vnode, container);
  4588. flushPostFlushCbs();
  4589. container._vnode = vnode;
  4590. return;
  4591. }
  4592. hasMismatch = false;
  4593. hydrateNode(container.firstChild, vnode, null, null, null);
  4594. flushPostFlushCbs();
  4595. container._vnode = vnode;
  4596. if (hasMismatch && !false) {
  4597. // this error should show up in production
  4598. console.error(`Hydration completed but contains mismatches.`);
  4599. }
  4600. };
  4601. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  4602. const isFragmentStart = isComment(node) && node.data === '[';
  4603. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  4604. const { type, ref, shapeFlag, patchFlag } = vnode;
  4605. let domType = node.nodeType;
  4606. vnode.el = node;
  4607. if (patchFlag === -2 /* PatchFlags.BAIL */) {
  4608. optimized = false;
  4609. vnode.dynamicChildren = null;
  4610. }
  4611. let nextNode = null;
  4612. switch (type) {
  4613. case Text:
  4614. if (domType !== 3 /* DOMNodeTypes.TEXT */) {
  4615. // #5728 empty text node inside a slot can cause hydration failure
  4616. // because the server rendered HTML won't contain a text node
  4617. if (vnode.children === '') {
  4618. insert((vnode.el = createText('')), parentNode(node), node);
  4619. nextNode = node;
  4620. }
  4621. else {
  4622. nextNode = onMismatch();
  4623. }
  4624. }
  4625. else {
  4626. if (node.data !== vnode.children) {
  4627. hasMismatch = true;
  4628. (process.env.NODE_ENV !== 'production') &&
  4629. warn(`Hydration text mismatch:` +
  4630. `\n- Client: ${JSON.stringify(node.data)}` +
  4631. `\n- Server: ${JSON.stringify(vnode.children)}`);
  4632. node.data = vnode.children;
  4633. }
  4634. nextNode = nextSibling(node);
  4635. }
  4636. break;
  4637. case Comment:
  4638. if (domType !== 8 /* DOMNodeTypes.COMMENT */ || isFragmentStart) {
  4639. nextNode = onMismatch();
  4640. }
  4641. else {
  4642. nextNode = nextSibling(node);
  4643. }
  4644. break;
  4645. case Static:
  4646. if (isFragmentStart) {
  4647. // entire template is static but SSRed as a fragment
  4648. node = nextSibling(node);
  4649. domType = node.nodeType;
  4650. }
  4651. if (domType === 1 /* DOMNodeTypes.ELEMENT */ || domType === 3 /* DOMNodeTypes.TEXT */) {
  4652. // determine anchor, adopt content
  4653. nextNode = node;
  4654. // if the static vnode has its content stripped during build,
  4655. // adopt it from the server-rendered HTML.
  4656. const needToAdoptContent = !vnode.children.length;
  4657. for (let i = 0; i < vnode.staticCount; i++) {
  4658. if (needToAdoptContent)
  4659. vnode.children +=
  4660. nextNode.nodeType === 1 /* DOMNodeTypes.ELEMENT */
  4661. ? nextNode.outerHTML
  4662. : nextNode.data;
  4663. if (i === vnode.staticCount - 1) {
  4664. vnode.anchor = nextNode;
  4665. }
  4666. nextNode = nextSibling(nextNode);
  4667. }
  4668. return isFragmentStart ? nextSibling(nextNode) : nextNode;
  4669. }
  4670. else {
  4671. onMismatch();
  4672. }
  4673. break;
  4674. case Fragment:
  4675. if (!isFragmentStart) {
  4676. nextNode = onMismatch();
  4677. }
  4678. else {
  4679. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  4680. }
  4681. break;
  4682. default:
  4683. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  4684. if (domType !== 1 /* DOMNodeTypes.ELEMENT */ ||
  4685. vnode.type.toLowerCase() !==
  4686. node.tagName.toLowerCase()) {
  4687. nextNode = onMismatch();
  4688. }
  4689. else {
  4690. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  4691. }
  4692. }
  4693. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  4694. // when setting up the render effect, if the initial vnode already
  4695. // has .el set, the component will perform hydration instead of mount
  4696. // on its sub-tree.
  4697. vnode.slotScopeIds = slotScopeIds;
  4698. const container = parentNode(node);
  4699. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  4700. // component may be async, so in the case of fragments we cannot rely
  4701. // on component's rendered output to determine the end of the fragment
  4702. // instead, we do a lookahead to find the end anchor node.
  4703. nextNode = isFragmentStart
  4704. ? locateClosingAsyncAnchor(node)
  4705. : nextSibling(node);
  4706. // #4293 teleport as component root
  4707. if (nextNode &&
  4708. isComment(nextNode) &&
  4709. nextNode.data === 'teleport end') {
  4710. nextNode = nextSibling(nextNode);
  4711. }
  4712. // #3787
  4713. // if component is async, it may get moved / unmounted before its
  4714. // inner component is loaded, so we need to give it a placeholder
  4715. // vnode that matches its adopted DOM.
  4716. if (isAsyncWrapper(vnode)) {
  4717. let subTree;
  4718. if (isFragmentStart) {
  4719. subTree = createVNode(Fragment);
  4720. subTree.anchor = nextNode
  4721. ? nextNode.previousSibling
  4722. : container.lastChild;
  4723. }
  4724. else {
  4725. subTree =
  4726. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  4727. }
  4728. subTree.el = node;
  4729. vnode.component.subTree = subTree;
  4730. }
  4731. }
  4732. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  4733. if (domType !== 8 /* DOMNodeTypes.COMMENT */) {
  4734. nextNode = onMismatch();
  4735. }
  4736. else {
  4737. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  4738. }
  4739. }
  4740. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  4741. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  4742. }
  4743. else if ((process.env.NODE_ENV !== 'production')) {
  4744. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  4745. }
  4746. }
  4747. if (ref != null) {
  4748. setRef(ref, null, parentSuspense, vnode);
  4749. }
  4750. return nextNode;
  4751. };
  4752. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  4753. optimized = optimized || !!vnode.dynamicChildren;
  4754. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  4755. // #4006 for form elements with non-string v-model value bindings
  4756. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  4757. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  4758. // skip props & children if this is hoisted static nodes
  4759. // #5405 in dev, always hydrate children for HMR
  4760. if ((process.env.NODE_ENV !== 'production') || forcePatchValue || patchFlag !== -1 /* PatchFlags.HOISTED */) {
  4761. if (dirs) {
  4762. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  4763. }
  4764. // props
  4765. if (props) {
  4766. if (forcePatchValue ||
  4767. !optimized ||
  4768. patchFlag & (16 /* PatchFlags.FULL_PROPS */ | 32 /* PatchFlags.HYDRATE_EVENTS */)) {
  4769. for (const key in props) {
  4770. if ((forcePatchValue && key.endsWith('value')) ||
  4771. (isOn(key) && !isReservedProp(key))) {
  4772. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  4773. }
  4774. }
  4775. }
  4776. else if (props.onClick) {
  4777. // Fast path for click listeners (which is most often) to avoid
  4778. // iterating through props.
  4779. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  4780. }
  4781. }
  4782. // vnode / directive hooks
  4783. let vnodeHooks;
  4784. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  4785. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4786. }
  4787. if (dirs) {
  4788. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  4789. }
  4790. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  4791. queueEffectWithSuspense(() => {
  4792. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4793. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  4794. }, parentSuspense);
  4795. }
  4796. // children
  4797. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */ &&
  4798. // skip if element has innerHTML / textContent
  4799. !(props && (props.innerHTML || props.textContent))) {
  4800. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  4801. let hasWarned = false;
  4802. while (next) {
  4803. hasMismatch = true;
  4804. if ((process.env.NODE_ENV !== 'production') && !hasWarned) {
  4805. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  4806. `server rendered element contains more child nodes than client vdom.`);
  4807. hasWarned = true;
  4808. }
  4809. // The SSRed DOM contains more nodes than it should. Remove them.
  4810. const cur = next;
  4811. next = next.nextSibling;
  4812. remove(cur);
  4813. }
  4814. }
  4815. else if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  4816. if (el.textContent !== vnode.children) {
  4817. hasMismatch = true;
  4818. (process.env.NODE_ENV !== 'production') &&
  4819. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  4820. `- Client: ${el.textContent}\n` +
  4821. `- Server: ${vnode.children}`);
  4822. el.textContent = vnode.children;
  4823. }
  4824. }
  4825. }
  4826. return el.nextSibling;
  4827. };
  4828. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  4829. optimized = optimized || !!parentVNode.dynamicChildren;
  4830. const children = parentVNode.children;
  4831. const l = children.length;
  4832. let hasWarned = false;
  4833. for (let i = 0; i < l; i++) {
  4834. const vnode = optimized
  4835. ? children[i]
  4836. : (children[i] = normalizeVNode(children[i]));
  4837. if (node) {
  4838. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  4839. }
  4840. else if (vnode.type === Text && !vnode.children) {
  4841. continue;
  4842. }
  4843. else {
  4844. hasMismatch = true;
  4845. if ((process.env.NODE_ENV !== 'production') && !hasWarned) {
  4846. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  4847. `server rendered element contains fewer child nodes than client vdom.`);
  4848. hasWarned = true;
  4849. }
  4850. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  4851. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  4852. }
  4853. }
  4854. return node;
  4855. };
  4856. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  4857. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  4858. if (fragmentSlotScopeIds) {
  4859. slotScopeIds = slotScopeIds
  4860. ? slotScopeIds.concat(fragmentSlotScopeIds)
  4861. : fragmentSlotScopeIds;
  4862. }
  4863. const container = parentNode(node);
  4864. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  4865. if (next && isComment(next) && next.data === ']') {
  4866. return nextSibling((vnode.anchor = next));
  4867. }
  4868. else {
  4869. // fragment didn't hydrate successfully, since we didn't get a end anchor
  4870. // back. This should have led to node/children mismatch warnings.
  4871. hasMismatch = true;
  4872. // since the anchor is missing, we need to create one and insert it
  4873. insert((vnode.anchor = createComment(`]`)), container, next);
  4874. return next;
  4875. }
  4876. };
  4877. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  4878. hasMismatch = true;
  4879. (process.env.NODE_ENV !== 'production') &&
  4880. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* DOMNodeTypes.TEXT */
  4881. ? `(text)`
  4882. : isComment(node) && node.data === '['
  4883. ? `(start of fragment)`
  4884. : ``);
  4885. vnode.el = null;
  4886. if (isFragment) {
  4887. // remove excessive fragment nodes
  4888. const end = locateClosingAsyncAnchor(node);
  4889. while (true) {
  4890. const next = nextSibling(node);
  4891. if (next && next !== end) {
  4892. remove(next);
  4893. }
  4894. else {
  4895. break;
  4896. }
  4897. }
  4898. }
  4899. const next = nextSibling(node);
  4900. const container = parentNode(node);
  4901. remove(node);
  4902. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  4903. return next;
  4904. };
  4905. const locateClosingAsyncAnchor = (node) => {
  4906. let match = 0;
  4907. while (node) {
  4908. node = nextSibling(node);
  4909. if (node && isComment(node)) {
  4910. if (node.data === '[')
  4911. match++;
  4912. if (node.data === ']') {
  4913. if (match === 0) {
  4914. return nextSibling(node);
  4915. }
  4916. else {
  4917. match--;
  4918. }
  4919. }
  4920. }
  4921. }
  4922. return node;
  4923. };
  4924. return [hydrate, hydrateNode];
  4925. }
  4926. /* eslint-disable no-restricted-globals */
  4927. let supported;
  4928. let perf;
  4929. function startMeasure(instance, type) {
  4930. if (instance.appContext.config.performance && isSupported()) {
  4931. perf.mark(`vue-${type}-${instance.uid}`);
  4932. }
  4933. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  4934. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  4935. }
  4936. }
  4937. function endMeasure(instance, type) {
  4938. if (instance.appContext.config.performance && isSupported()) {
  4939. const startTag = `vue-${type}-${instance.uid}`;
  4940. const endTag = startTag + `:end`;
  4941. perf.mark(endTag);
  4942. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  4943. perf.clearMarks(startTag);
  4944. perf.clearMarks(endTag);
  4945. }
  4946. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  4947. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  4948. }
  4949. }
  4950. function isSupported() {
  4951. if (supported !== undefined) {
  4952. return supported;
  4953. }
  4954. if (typeof window !== 'undefined' && window.performance) {
  4955. supported = true;
  4956. perf = window.performance;
  4957. }
  4958. else {
  4959. supported = false;
  4960. }
  4961. return supported;
  4962. }
  4963. /**
  4964. * This is only called in esm-bundler builds.
  4965. * It is called when a renderer is created, in `baseCreateRenderer` so that
  4966. * importing runtime-core is side-effects free.
  4967. *
  4968. * istanbul-ignore-next
  4969. */
  4970. function initFeatureFlags() {
  4971. const needWarn = [];
  4972. if (typeof __VUE_OPTIONS_API__ !== 'boolean') {
  4973. (process.env.NODE_ENV !== 'production') && needWarn.push(`__VUE_OPTIONS_API__`);
  4974. getGlobalThis().__VUE_OPTIONS_API__ = true;
  4975. }
  4976. if (typeof __VUE_PROD_DEVTOOLS__ !== 'boolean') {
  4977. (process.env.NODE_ENV !== 'production') && needWarn.push(`__VUE_PROD_DEVTOOLS__`);
  4978. getGlobalThis().__VUE_PROD_DEVTOOLS__ = false;
  4979. }
  4980. if ((process.env.NODE_ENV !== 'production') && needWarn.length) {
  4981. const multi = needWarn.length > 1;
  4982. console.warn(`Feature flag${multi ? `s` : ``} ${needWarn.join(', ')} ${multi ? `are` : `is`} not explicitly defined. You are running the esm-bundler build of Vue, ` +
  4983. `which expects these compile-time feature flags to be globally injected ` +
  4984. `via the bundler config in order to get better tree-shaking in the ` +
  4985. `production bundle.\n\n` +
  4986. `For more details, see https://link.vuejs.org/feature-flags.`);
  4987. }
  4988. }
  4989. const queuePostRenderEffect = queueEffectWithSuspense
  4990. ;
  4991. /**
  4992. * The createRenderer function accepts two generic arguments:
  4993. * HostNode and HostElement, corresponding to Node and Element types in the
  4994. * host environment. For example, for runtime-dom, HostNode would be the DOM
  4995. * `Node` interface and HostElement would be the DOM `Element` interface.
  4996. *
  4997. * Custom renderers can pass in the platform specific types like this:
  4998. *
  4999. * ``` js
  5000. * const { render, createApp } = createRenderer<Node, Element>({
  5001. * patchProp,
  5002. * ...nodeOps
  5003. * })
  5004. * ```
  5005. */
  5006. function createRenderer(options) {
  5007. return baseCreateRenderer(options);
  5008. }
  5009. // Separate API for creating hydration-enabled renderer.
  5010. // Hydration logic is only used when calling this function, making it
  5011. // tree-shakable.
  5012. function createHydrationRenderer(options) {
  5013. return baseCreateRenderer(options, createHydrationFunctions);
  5014. }
  5015. // implementation
  5016. function baseCreateRenderer(options, createHydrationFns) {
  5017. // compile-time feature flags check
  5018. {
  5019. initFeatureFlags();
  5020. }
  5021. const target = getGlobalThis();
  5022. target.__VUE__ = true;
  5023. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5024. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  5025. }
  5026. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, insertStaticContent: hostInsertStaticContent } = options;
  5027. // Note: functions inside this closure should use `const xxx = () => {}`
  5028. // style in order to prevent being inlined by minifiers.
  5029. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = (process.env.NODE_ENV !== 'production') && isHmrUpdating ? false : !!n2.dynamicChildren) => {
  5030. if (n1 === n2) {
  5031. return;
  5032. }
  5033. // patching & not same type, unmount old tree
  5034. if (n1 && !isSameVNodeType(n1, n2)) {
  5035. anchor = getNextHostNode(n1);
  5036. unmount(n1, parentComponent, parentSuspense, true);
  5037. n1 = null;
  5038. }
  5039. if (n2.patchFlag === -2 /* PatchFlags.BAIL */) {
  5040. optimized = false;
  5041. n2.dynamicChildren = null;
  5042. }
  5043. const { type, ref, shapeFlag } = n2;
  5044. switch (type) {
  5045. case Text:
  5046. processText(n1, n2, container, anchor);
  5047. break;
  5048. case Comment:
  5049. processCommentNode(n1, n2, container, anchor);
  5050. break;
  5051. case Static:
  5052. if (n1 == null) {
  5053. mountStaticNode(n2, container, anchor, isSVG);
  5054. }
  5055. else if ((process.env.NODE_ENV !== 'production')) {
  5056. patchStaticNode(n1, n2, container, isSVG);
  5057. }
  5058. break;
  5059. case Fragment:
  5060. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5061. break;
  5062. default:
  5063. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  5064. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5065. }
  5066. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  5067. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5068. }
  5069. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  5070. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5071. }
  5072. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  5073. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5074. }
  5075. else if ((process.env.NODE_ENV !== 'production')) {
  5076. warn('Invalid VNode type:', type, `(${typeof type})`);
  5077. }
  5078. }
  5079. // set ref
  5080. if (ref != null && parentComponent) {
  5081. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  5082. }
  5083. };
  5084. const processText = (n1, n2, container, anchor) => {
  5085. if (n1 == null) {
  5086. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  5087. }
  5088. else {
  5089. const el = (n2.el = n1.el);
  5090. if (n2.children !== n1.children) {
  5091. hostSetText(el, n2.children);
  5092. }
  5093. }
  5094. };
  5095. const processCommentNode = (n1, n2, container, anchor) => {
  5096. if (n1 == null) {
  5097. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  5098. }
  5099. else {
  5100. // there's no support for dynamic comments
  5101. n2.el = n1.el;
  5102. }
  5103. };
  5104. const mountStaticNode = (n2, container, anchor, isSVG) => {
  5105. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  5106. };
  5107. /**
  5108. * Dev / HMR only
  5109. */
  5110. const patchStaticNode = (n1, n2, container, isSVG) => {
  5111. // static nodes are only patched during dev for HMR
  5112. if (n2.children !== n1.children) {
  5113. const anchor = hostNextSibling(n1.anchor);
  5114. // remove existing
  5115. removeStaticNode(n1);
  5116. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5117. }
  5118. else {
  5119. n2.el = n1.el;
  5120. n2.anchor = n1.anchor;
  5121. }
  5122. };
  5123. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  5124. let next;
  5125. while (el && el !== anchor) {
  5126. next = hostNextSibling(el);
  5127. hostInsert(el, container, nextSibling);
  5128. el = next;
  5129. }
  5130. hostInsert(anchor, container, nextSibling);
  5131. };
  5132. const removeStaticNode = ({ el, anchor }) => {
  5133. let next;
  5134. while (el && el !== anchor) {
  5135. next = hostNextSibling(el);
  5136. hostRemove(el);
  5137. el = next;
  5138. }
  5139. hostRemove(anchor);
  5140. };
  5141. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5142. isSVG = isSVG || n2.type === 'svg';
  5143. if (n1 == null) {
  5144. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5145. }
  5146. else {
  5147. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5148. }
  5149. };
  5150. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5151. let el;
  5152. let vnodeHook;
  5153. const { type, props, shapeFlag, transition, dirs } = vnode;
  5154. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  5155. // mount children first, since some props may rely on child content
  5156. // being already rendered, e.g. `<select value>`
  5157. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  5158. hostSetElementText(el, vnode.children);
  5159. }
  5160. else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  5161. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  5162. }
  5163. if (dirs) {
  5164. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5165. }
  5166. // props
  5167. if (props) {
  5168. for (const key in props) {
  5169. if (key !== 'value' && !isReservedProp(key)) {
  5170. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5171. }
  5172. }
  5173. /**
  5174. * Special case for setting value on DOM elements:
  5175. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  5176. * - it needs to be forced (#1471)
  5177. * #2353 proposes adding another renderer option to configure this, but
  5178. * the properties affects are so finite it is worth special casing it
  5179. * here to reduce the complexity. (Special casing it also should not
  5180. * affect non-DOM renderers)
  5181. */
  5182. if ('value' in props) {
  5183. hostPatchProp(el, 'value', null, props.value);
  5184. }
  5185. if ((vnodeHook = props.onVnodeBeforeMount)) {
  5186. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5187. }
  5188. }
  5189. // scopeId
  5190. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  5191. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5192. Object.defineProperty(el, '__vnode', {
  5193. value: vnode,
  5194. enumerable: false
  5195. });
  5196. Object.defineProperty(el, '__vueParentComponent', {
  5197. value: parentComponent,
  5198. enumerable: false
  5199. });
  5200. }
  5201. if (dirs) {
  5202. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  5203. }
  5204. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  5205. // #1689 For inside suspense + suspense resolved case, just call it
  5206. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  5207. transition &&
  5208. !transition.persisted;
  5209. if (needCallTransitionHooks) {
  5210. transition.beforeEnter(el);
  5211. }
  5212. hostInsert(el, container, anchor);
  5213. if ((vnodeHook = props && props.onVnodeMounted) ||
  5214. needCallTransitionHooks ||
  5215. dirs) {
  5216. queuePostRenderEffect(() => {
  5217. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5218. needCallTransitionHooks && transition.enter(el);
  5219. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  5220. }, parentSuspense);
  5221. }
  5222. };
  5223. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  5224. if (scopeId) {
  5225. hostSetScopeId(el, scopeId);
  5226. }
  5227. if (slotScopeIds) {
  5228. for (let i = 0; i < slotScopeIds.length; i++) {
  5229. hostSetScopeId(el, slotScopeIds[i]);
  5230. }
  5231. }
  5232. if (parentComponent) {
  5233. let subTree = parentComponent.subTree;
  5234. if ((process.env.NODE_ENV !== 'production') &&
  5235. subTree.patchFlag > 0 &&
  5236. subTree.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  5237. subTree =
  5238. filterSingleRoot(subTree.children) || subTree;
  5239. }
  5240. if (vnode === subTree) {
  5241. const parentVNode = parentComponent.vnode;
  5242. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  5243. }
  5244. }
  5245. };
  5246. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  5247. for (let i = start; i < children.length; i++) {
  5248. const child = (children[i] = optimized
  5249. ? cloneIfMounted(children[i])
  5250. : normalizeVNode(children[i]));
  5251. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5252. }
  5253. };
  5254. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5255. const el = (n2.el = n1.el);
  5256. let { patchFlag, dynamicChildren, dirs } = n2;
  5257. // #1426 take the old vnode's patch flag into account since user may clone a
  5258. // compiler-generated vnode, which de-opts to FULL_PROPS
  5259. patchFlag |= n1.patchFlag & 16 /* PatchFlags.FULL_PROPS */;
  5260. const oldProps = n1.props || EMPTY_OBJ;
  5261. const newProps = n2.props || EMPTY_OBJ;
  5262. let vnodeHook;
  5263. // disable recurse in beforeUpdate hooks
  5264. parentComponent && toggleRecurse(parentComponent, false);
  5265. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  5266. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5267. }
  5268. if (dirs) {
  5269. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  5270. }
  5271. parentComponent && toggleRecurse(parentComponent, true);
  5272. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  5273. // HMR updated, force full diff
  5274. patchFlag = 0;
  5275. optimized = false;
  5276. dynamicChildren = null;
  5277. }
  5278. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  5279. if (dynamicChildren) {
  5280. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  5281. if ((process.env.NODE_ENV !== 'production') && parentComponent && parentComponent.type.__hmrId) {
  5282. traverseStaticChildren(n1, n2);
  5283. }
  5284. }
  5285. else if (!optimized) {
  5286. // full diff
  5287. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  5288. }
  5289. if (patchFlag > 0) {
  5290. // the presence of a patchFlag means this element's render code was
  5291. // generated by the compiler and can take the fast path.
  5292. // in this path old node and new node are guaranteed to have the same shape
  5293. // (i.e. at the exact same position in the source template)
  5294. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  5295. // element props contain dynamic keys, full diff needed
  5296. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5297. }
  5298. else {
  5299. // class
  5300. // this flag is matched when the element has dynamic class bindings.
  5301. if (patchFlag & 2 /* PatchFlags.CLASS */) {
  5302. if (oldProps.class !== newProps.class) {
  5303. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  5304. }
  5305. }
  5306. // style
  5307. // this flag is matched when the element has dynamic style bindings
  5308. if (patchFlag & 4 /* PatchFlags.STYLE */) {
  5309. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  5310. }
  5311. // props
  5312. // This flag is matched when the element has dynamic prop/attr bindings
  5313. // other than class and style. The keys of dynamic prop/attrs are saved for
  5314. // faster iteration.
  5315. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  5316. // bail out and go through a full diff because we need to unset the old key
  5317. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  5318. // if the flag is present then dynamicProps must be non-null
  5319. const propsToUpdate = n2.dynamicProps;
  5320. for (let i = 0; i < propsToUpdate.length; i++) {
  5321. const key = propsToUpdate[i];
  5322. const prev = oldProps[key];
  5323. const next = newProps[key];
  5324. // #1471 force patch value
  5325. if (next !== prev || key === 'value') {
  5326. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  5327. }
  5328. }
  5329. }
  5330. }
  5331. // text
  5332. // This flag is matched when the element has only dynamic text children.
  5333. if (patchFlag & 1 /* PatchFlags.TEXT */) {
  5334. if (n1.children !== n2.children) {
  5335. hostSetElementText(el, n2.children);
  5336. }
  5337. }
  5338. }
  5339. else if (!optimized && dynamicChildren == null) {
  5340. // unoptimized, full diff
  5341. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5342. }
  5343. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  5344. queuePostRenderEffect(() => {
  5345. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5346. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  5347. }, parentSuspense);
  5348. }
  5349. };
  5350. // The fast path for blocks.
  5351. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  5352. for (let i = 0; i < newChildren.length; i++) {
  5353. const oldVNode = oldChildren[i];
  5354. const newVNode = newChildren[i];
  5355. // Determine the container (parent element) for the patch.
  5356. const container =
  5357. // oldVNode may be an errored async setup() component inside Suspense
  5358. // which will not have a mounted element
  5359. oldVNode.el &&
  5360. // - In the case of a Fragment, we need to provide the actual parent
  5361. // of the Fragment itself so it can move its children.
  5362. (oldVNode.type === Fragment ||
  5363. // - In the case of different nodes, there is going to be a replacement
  5364. // which also requires the correct parent container
  5365. !isSameVNodeType(oldVNode, newVNode) ||
  5366. // - In the case of a component, it could contain anything.
  5367. oldVNode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 64 /* ShapeFlags.TELEPORT */))
  5368. ? hostParentNode(oldVNode.el)
  5369. : // In other cases, the parent container is not actually used so we
  5370. // just pass the block element here to avoid a DOM parentNode call.
  5371. fallbackContainer;
  5372. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  5373. }
  5374. };
  5375. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  5376. if (oldProps !== newProps) {
  5377. if (oldProps !== EMPTY_OBJ) {
  5378. for (const key in oldProps) {
  5379. if (!isReservedProp(key) && !(key in newProps)) {
  5380. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5381. }
  5382. }
  5383. }
  5384. for (const key in newProps) {
  5385. // empty string is not valid prop
  5386. if (isReservedProp(key))
  5387. continue;
  5388. const next = newProps[key];
  5389. const prev = oldProps[key];
  5390. // defer patching value
  5391. if (next !== prev && key !== 'value') {
  5392. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5393. }
  5394. }
  5395. if ('value' in newProps) {
  5396. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  5397. }
  5398. }
  5399. };
  5400. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5401. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  5402. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  5403. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  5404. if ((process.env.NODE_ENV !== 'production') &&
  5405. // #5523 dev root fragment may inherit directives
  5406. (isHmrUpdating || patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */)) {
  5407. // HMR updated / Dev root fragment (w/ comments), force full diff
  5408. patchFlag = 0;
  5409. optimized = false;
  5410. dynamicChildren = null;
  5411. }
  5412. // check if this is a slot fragment with :slotted scope ids
  5413. if (fragmentSlotScopeIds) {
  5414. slotScopeIds = slotScopeIds
  5415. ? slotScopeIds.concat(fragmentSlotScopeIds)
  5416. : fragmentSlotScopeIds;
  5417. }
  5418. if (n1 == null) {
  5419. hostInsert(fragmentStartAnchor, container, anchor);
  5420. hostInsert(fragmentEndAnchor, container, anchor);
  5421. // a fragment can only have array children
  5422. // since they are either generated by the compiler, or implicitly created
  5423. // from arrays.
  5424. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5425. }
  5426. else {
  5427. if (patchFlag > 0 &&
  5428. patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */ &&
  5429. dynamicChildren &&
  5430. // #2715 the previous fragment could've been a BAILed one as a result
  5431. // of renderSlot() with no valid children
  5432. n1.dynamicChildren) {
  5433. // a stable fragment (template root or <template v-for>) doesn't need to
  5434. // patch children order, but it may contain dynamicChildren.
  5435. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  5436. if ((process.env.NODE_ENV !== 'production') && parentComponent && parentComponent.type.__hmrId) {
  5437. traverseStaticChildren(n1, n2);
  5438. }
  5439. else if (
  5440. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  5441. // get moved around. Make sure all root level vnodes inherit el.
  5442. // #2134 or if it's a component root, it may also get moved around
  5443. // as the component is being moved.
  5444. n2.key != null ||
  5445. (parentComponent && n2 === parentComponent.subTree)) {
  5446. traverseStaticChildren(n1, n2, true /* shallow */);
  5447. }
  5448. }
  5449. else {
  5450. // keyed / unkeyed, or manual fragments.
  5451. // for keyed & unkeyed, since they are compiler generated from v-for,
  5452. // each child is guaranteed to be a block so the fragment will never
  5453. // have dynamicChildren.
  5454. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5455. }
  5456. }
  5457. };
  5458. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5459. n2.slotScopeIds = slotScopeIds;
  5460. if (n1 == null) {
  5461. if (n2.shapeFlag & 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */) {
  5462. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  5463. }
  5464. else {
  5465. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5466. }
  5467. }
  5468. else {
  5469. updateComponent(n1, n2, optimized);
  5470. }
  5471. };
  5472. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5473. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  5474. if ((process.env.NODE_ENV !== 'production') && instance.type.__hmrId) {
  5475. registerHMR(instance);
  5476. }
  5477. if ((process.env.NODE_ENV !== 'production')) {
  5478. pushWarningContext(initialVNode);
  5479. startMeasure(instance, `mount`);
  5480. }
  5481. // inject renderer internals for keepAlive
  5482. if (isKeepAlive(initialVNode)) {
  5483. instance.ctx.renderer = internals;
  5484. }
  5485. // resolve props and slots for setup context
  5486. {
  5487. if ((process.env.NODE_ENV !== 'production')) {
  5488. startMeasure(instance, `init`);
  5489. }
  5490. setupComponent(instance);
  5491. if ((process.env.NODE_ENV !== 'production')) {
  5492. endMeasure(instance, `init`);
  5493. }
  5494. }
  5495. // setup() is async. This component relies on async logic to be resolved
  5496. // before proceeding
  5497. if (instance.asyncDep) {
  5498. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  5499. // Give it a placeholder if this is not hydration
  5500. // TODO handle self-defined fallback
  5501. if (!initialVNode.el) {
  5502. const placeholder = (instance.subTree = createVNode(Comment));
  5503. processCommentNode(null, placeholder, container, anchor);
  5504. }
  5505. return;
  5506. }
  5507. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  5508. if ((process.env.NODE_ENV !== 'production')) {
  5509. popWarningContext();
  5510. endMeasure(instance, `mount`);
  5511. }
  5512. };
  5513. const updateComponent = (n1, n2, optimized) => {
  5514. const instance = (n2.component = n1.component);
  5515. if (shouldUpdateComponent(n1, n2, optimized)) {
  5516. if (instance.asyncDep &&
  5517. !instance.asyncResolved) {
  5518. // async & still pending - just update props and slots
  5519. // since the component's reactive effect for render isn't set-up yet
  5520. if ((process.env.NODE_ENV !== 'production')) {
  5521. pushWarningContext(n2);
  5522. }
  5523. updateComponentPreRender(instance, n2, optimized);
  5524. if ((process.env.NODE_ENV !== 'production')) {
  5525. popWarningContext();
  5526. }
  5527. return;
  5528. }
  5529. else {
  5530. // normal update
  5531. instance.next = n2;
  5532. // in case the child component is also queued, remove it to avoid
  5533. // double updating the same child component in the same flush.
  5534. invalidateJob(instance.update);
  5535. // instance.update is the reactive effect.
  5536. instance.update();
  5537. }
  5538. }
  5539. else {
  5540. // no update needed. just copy over properties
  5541. n2.el = n1.el;
  5542. instance.vnode = n2;
  5543. }
  5544. };
  5545. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  5546. const componentUpdateFn = () => {
  5547. if (!instance.isMounted) {
  5548. let vnodeHook;
  5549. const { el, props } = initialVNode;
  5550. const { bm, m, parent } = instance;
  5551. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  5552. toggleRecurse(instance, false);
  5553. // beforeMount hook
  5554. if (bm) {
  5555. invokeArrayFns(bm);
  5556. }
  5557. // onVnodeBeforeMount
  5558. if (!isAsyncWrapperVNode &&
  5559. (vnodeHook = props && props.onVnodeBeforeMount)) {
  5560. invokeVNodeHook(vnodeHook, parent, initialVNode);
  5561. }
  5562. toggleRecurse(instance, true);
  5563. if (el && hydrateNode) {
  5564. // vnode has adopted host node - perform hydration instead of mount.
  5565. const hydrateSubTree = () => {
  5566. if ((process.env.NODE_ENV !== 'production')) {
  5567. startMeasure(instance, `render`);
  5568. }
  5569. instance.subTree = renderComponentRoot(instance);
  5570. if ((process.env.NODE_ENV !== 'production')) {
  5571. endMeasure(instance, `render`);
  5572. }
  5573. if ((process.env.NODE_ENV !== 'production')) {
  5574. startMeasure(instance, `hydrate`);
  5575. }
  5576. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  5577. if ((process.env.NODE_ENV !== 'production')) {
  5578. endMeasure(instance, `hydrate`);
  5579. }
  5580. };
  5581. if (isAsyncWrapperVNode) {
  5582. initialVNode.type.__asyncLoader().then(
  5583. // note: we are moving the render call into an async callback,
  5584. // which means it won't track dependencies - but it's ok because
  5585. // a server-rendered async wrapper is already in resolved state
  5586. // and it will never need to change.
  5587. () => !instance.isUnmounted && hydrateSubTree());
  5588. }
  5589. else {
  5590. hydrateSubTree();
  5591. }
  5592. }
  5593. else {
  5594. if ((process.env.NODE_ENV !== 'production')) {
  5595. startMeasure(instance, `render`);
  5596. }
  5597. const subTree = (instance.subTree = renderComponentRoot(instance));
  5598. if ((process.env.NODE_ENV !== 'production')) {
  5599. endMeasure(instance, `render`);
  5600. }
  5601. if ((process.env.NODE_ENV !== 'production')) {
  5602. startMeasure(instance, `patch`);
  5603. }
  5604. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  5605. if ((process.env.NODE_ENV !== 'production')) {
  5606. endMeasure(instance, `patch`);
  5607. }
  5608. initialVNode.el = subTree.el;
  5609. }
  5610. // mounted hook
  5611. if (m) {
  5612. queuePostRenderEffect(m, parentSuspense);
  5613. }
  5614. // onVnodeMounted
  5615. if (!isAsyncWrapperVNode &&
  5616. (vnodeHook = props && props.onVnodeMounted)) {
  5617. const scopedInitialVNode = initialVNode;
  5618. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  5619. }
  5620. // activated hook for keep-alive roots.
  5621. // #1742 activated hook must be accessed after first render
  5622. // since the hook may be injected by a child keep-alive
  5623. if (initialVNode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */ ||
  5624. (parent &&
  5625. isAsyncWrapper(parent.vnode) &&
  5626. parent.vnode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */)) {
  5627. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  5628. }
  5629. instance.isMounted = true;
  5630. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5631. devtoolsComponentAdded(instance);
  5632. }
  5633. // #2458: deference mount-only object parameters to prevent memleaks
  5634. initialVNode = container = anchor = null;
  5635. }
  5636. else {
  5637. // updateComponent
  5638. // This is triggered by mutation of component's own state (next: null)
  5639. // OR parent calling processComponent (next: VNode)
  5640. let { next, bu, u, parent, vnode } = instance;
  5641. let originNext = next;
  5642. let vnodeHook;
  5643. if ((process.env.NODE_ENV !== 'production')) {
  5644. pushWarningContext(next || instance.vnode);
  5645. }
  5646. // Disallow component effect recursion during pre-lifecycle hooks.
  5647. toggleRecurse(instance, false);
  5648. if (next) {
  5649. next.el = vnode.el;
  5650. updateComponentPreRender(instance, next, optimized);
  5651. }
  5652. else {
  5653. next = vnode;
  5654. }
  5655. // beforeUpdate hook
  5656. if (bu) {
  5657. invokeArrayFns(bu);
  5658. }
  5659. // onVnodeBeforeUpdate
  5660. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  5661. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5662. }
  5663. toggleRecurse(instance, true);
  5664. // render
  5665. if ((process.env.NODE_ENV !== 'production')) {
  5666. startMeasure(instance, `render`);
  5667. }
  5668. const nextTree = renderComponentRoot(instance);
  5669. if ((process.env.NODE_ENV !== 'production')) {
  5670. endMeasure(instance, `render`);
  5671. }
  5672. const prevTree = instance.subTree;
  5673. instance.subTree = nextTree;
  5674. if ((process.env.NODE_ENV !== 'production')) {
  5675. startMeasure(instance, `patch`);
  5676. }
  5677. patch(prevTree, nextTree,
  5678. // parent may have changed if it's in a teleport
  5679. hostParentNode(prevTree.el),
  5680. // anchor may have changed if it's in a fragment
  5681. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  5682. if ((process.env.NODE_ENV !== 'production')) {
  5683. endMeasure(instance, `patch`);
  5684. }
  5685. next.el = nextTree.el;
  5686. if (originNext === null) {
  5687. // self-triggered update. In case of HOC, update parent component
  5688. // vnode el. HOC is indicated by parent instance's subTree pointing
  5689. // to child component's vnode
  5690. updateHOCHostEl(instance, nextTree.el);
  5691. }
  5692. // updated hook
  5693. if (u) {
  5694. queuePostRenderEffect(u, parentSuspense);
  5695. }
  5696. // onVnodeUpdated
  5697. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  5698. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  5699. }
  5700. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  5701. devtoolsComponentUpdated(instance);
  5702. }
  5703. if ((process.env.NODE_ENV !== 'production')) {
  5704. popWarningContext();
  5705. }
  5706. }
  5707. };
  5708. // create reactive effect for rendering
  5709. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  5710. ));
  5711. const update = (instance.update = () => effect.run());
  5712. update.id = instance.uid;
  5713. // allowRecurse
  5714. // #1801, #2043 component render effects should allow recursive updates
  5715. toggleRecurse(instance, true);
  5716. if ((process.env.NODE_ENV !== 'production')) {
  5717. effect.onTrack = instance.rtc
  5718. ? e => invokeArrayFns(instance.rtc, e)
  5719. : void 0;
  5720. effect.onTrigger = instance.rtg
  5721. ? e => invokeArrayFns(instance.rtg, e)
  5722. : void 0;
  5723. update.ownerInstance = instance;
  5724. }
  5725. update();
  5726. };
  5727. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  5728. nextVNode.component = instance;
  5729. const prevProps = instance.vnode.props;
  5730. instance.vnode = nextVNode;
  5731. instance.next = null;
  5732. updateProps(instance, nextVNode.props, prevProps, optimized);
  5733. updateSlots(instance, nextVNode.children, optimized);
  5734. pauseTracking();
  5735. // props update may have triggered pre-flush watchers.
  5736. // flush them before the render update.
  5737. flushPreFlushCbs();
  5738. resetTracking();
  5739. };
  5740. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  5741. const c1 = n1 && n1.children;
  5742. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  5743. const c2 = n2.children;
  5744. const { patchFlag, shapeFlag } = n2;
  5745. // fast path
  5746. if (patchFlag > 0) {
  5747. if (patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */) {
  5748. // this could be either fully-keyed or mixed (some keyed some not)
  5749. // presence of patchFlag means children are guaranteed to be arrays
  5750. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5751. return;
  5752. }
  5753. else if (patchFlag & 256 /* PatchFlags.UNKEYED_FRAGMENT */) {
  5754. // unkeyed
  5755. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5756. return;
  5757. }
  5758. }
  5759. // children has 3 possibilities: text, array or no children.
  5760. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  5761. // text children fast path
  5762. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  5763. unmountChildren(c1, parentComponent, parentSuspense);
  5764. }
  5765. if (c2 !== c1) {
  5766. hostSetElementText(container, c2);
  5767. }
  5768. }
  5769. else {
  5770. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  5771. // prev children was array
  5772. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  5773. // two arrays, cannot assume anything, do full diff
  5774. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5775. }
  5776. else {
  5777. // no new children, just unmount old
  5778. unmountChildren(c1, parentComponent, parentSuspense, true);
  5779. }
  5780. }
  5781. else {
  5782. // prev children was text OR null
  5783. // new children is array OR null
  5784. if (prevShapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  5785. hostSetElementText(container, '');
  5786. }
  5787. // mount new if array
  5788. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  5789. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5790. }
  5791. }
  5792. }
  5793. };
  5794. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5795. c1 = c1 || EMPTY_ARR;
  5796. c2 = c2 || EMPTY_ARR;
  5797. const oldLength = c1.length;
  5798. const newLength = c2.length;
  5799. const commonLength = Math.min(oldLength, newLength);
  5800. let i;
  5801. for (i = 0; i < commonLength; i++) {
  5802. const nextChild = (c2[i] = optimized
  5803. ? cloneIfMounted(c2[i])
  5804. : normalizeVNode(c2[i]));
  5805. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5806. }
  5807. if (oldLength > newLength) {
  5808. // remove old
  5809. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  5810. }
  5811. else {
  5812. // mount new
  5813. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  5814. }
  5815. };
  5816. // can be all-keyed or mixed
  5817. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5818. let i = 0;
  5819. const l2 = c2.length;
  5820. let e1 = c1.length - 1; // prev ending index
  5821. let e2 = l2 - 1; // next ending index
  5822. // 1. sync from start
  5823. // (a b) c
  5824. // (a b) d e
  5825. while (i <= e1 && i <= e2) {
  5826. const n1 = c1[i];
  5827. const n2 = (c2[i] = optimized
  5828. ? cloneIfMounted(c2[i])
  5829. : normalizeVNode(c2[i]));
  5830. if (isSameVNodeType(n1, n2)) {
  5831. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5832. }
  5833. else {
  5834. break;
  5835. }
  5836. i++;
  5837. }
  5838. // 2. sync from end
  5839. // a (b c)
  5840. // d e (b c)
  5841. while (i <= e1 && i <= e2) {
  5842. const n1 = c1[e1];
  5843. const n2 = (c2[e2] = optimized
  5844. ? cloneIfMounted(c2[e2])
  5845. : normalizeVNode(c2[e2]));
  5846. if (isSameVNodeType(n1, n2)) {
  5847. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5848. }
  5849. else {
  5850. break;
  5851. }
  5852. e1--;
  5853. e2--;
  5854. }
  5855. // 3. common sequence + mount
  5856. // (a b)
  5857. // (a b) c
  5858. // i = 2, e1 = 1, e2 = 2
  5859. // (a b)
  5860. // c (a b)
  5861. // i = 0, e1 = -1, e2 = 0
  5862. if (i > e1) {
  5863. if (i <= e2) {
  5864. const nextPos = e2 + 1;
  5865. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  5866. while (i <= e2) {
  5867. patch(null, (c2[i] = optimized
  5868. ? cloneIfMounted(c2[i])
  5869. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5870. i++;
  5871. }
  5872. }
  5873. }
  5874. // 4. common sequence + unmount
  5875. // (a b) c
  5876. // (a b)
  5877. // i = 2, e1 = 2, e2 = 1
  5878. // a (b c)
  5879. // (b c)
  5880. // i = 0, e1 = 0, e2 = -1
  5881. else if (i > e2) {
  5882. while (i <= e1) {
  5883. unmount(c1[i], parentComponent, parentSuspense, true);
  5884. i++;
  5885. }
  5886. }
  5887. // 5. unknown sequence
  5888. // [i ... e1 + 1]: a b [c d e] f g
  5889. // [i ... e2 + 1]: a b [e d c h] f g
  5890. // i = 2, e1 = 4, e2 = 5
  5891. else {
  5892. const s1 = i; // prev starting index
  5893. const s2 = i; // next starting index
  5894. // 5.1 build key:index map for newChildren
  5895. const keyToNewIndexMap = new Map();
  5896. for (i = s2; i <= e2; i++) {
  5897. const nextChild = (c2[i] = optimized
  5898. ? cloneIfMounted(c2[i])
  5899. : normalizeVNode(c2[i]));
  5900. if (nextChild.key != null) {
  5901. if ((process.env.NODE_ENV !== 'production') && keyToNewIndexMap.has(nextChild.key)) {
  5902. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  5903. }
  5904. keyToNewIndexMap.set(nextChild.key, i);
  5905. }
  5906. }
  5907. // 5.2 loop through old children left to be patched and try to patch
  5908. // matching nodes & remove nodes that are no longer present
  5909. let j;
  5910. let patched = 0;
  5911. const toBePatched = e2 - s2 + 1;
  5912. let moved = false;
  5913. // used to track whether any node has moved
  5914. let maxNewIndexSoFar = 0;
  5915. // works as Map<newIndex, oldIndex>
  5916. // Note that oldIndex is offset by +1
  5917. // and oldIndex = 0 is a special value indicating the new node has
  5918. // no corresponding old node.
  5919. // used for determining longest stable subsequence
  5920. const newIndexToOldIndexMap = new Array(toBePatched);
  5921. for (i = 0; i < toBePatched; i++)
  5922. newIndexToOldIndexMap[i] = 0;
  5923. for (i = s1; i <= e1; i++) {
  5924. const prevChild = c1[i];
  5925. if (patched >= toBePatched) {
  5926. // all new children have been patched so this can only be a removal
  5927. unmount(prevChild, parentComponent, parentSuspense, true);
  5928. continue;
  5929. }
  5930. let newIndex;
  5931. if (prevChild.key != null) {
  5932. newIndex = keyToNewIndexMap.get(prevChild.key);
  5933. }
  5934. else {
  5935. // key-less node, try to locate a key-less node of the same type
  5936. for (j = s2; j <= e2; j++) {
  5937. if (newIndexToOldIndexMap[j - s2] === 0 &&
  5938. isSameVNodeType(prevChild, c2[j])) {
  5939. newIndex = j;
  5940. break;
  5941. }
  5942. }
  5943. }
  5944. if (newIndex === undefined) {
  5945. unmount(prevChild, parentComponent, parentSuspense, true);
  5946. }
  5947. else {
  5948. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  5949. if (newIndex >= maxNewIndexSoFar) {
  5950. maxNewIndexSoFar = newIndex;
  5951. }
  5952. else {
  5953. moved = true;
  5954. }
  5955. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5956. patched++;
  5957. }
  5958. }
  5959. // 5.3 move and mount
  5960. // generate longest stable subsequence only when nodes have moved
  5961. const increasingNewIndexSequence = moved
  5962. ? getSequence(newIndexToOldIndexMap)
  5963. : EMPTY_ARR;
  5964. j = increasingNewIndexSequence.length - 1;
  5965. // looping backwards so that we can use last patched node as anchor
  5966. for (i = toBePatched - 1; i >= 0; i--) {
  5967. const nextIndex = s2 + i;
  5968. const nextChild = c2[nextIndex];
  5969. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  5970. if (newIndexToOldIndexMap[i] === 0) {
  5971. // mount new
  5972. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5973. }
  5974. else if (moved) {
  5975. // move if:
  5976. // There is no stable subsequence (e.g. a reverse)
  5977. // OR current node is not among the stable sequence
  5978. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  5979. move(nextChild, container, anchor, 2 /* MoveType.REORDER */);
  5980. }
  5981. else {
  5982. j--;
  5983. }
  5984. }
  5985. }
  5986. }
  5987. };
  5988. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  5989. const { el, type, transition, children, shapeFlag } = vnode;
  5990. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  5991. move(vnode.component.subTree, container, anchor, moveType);
  5992. return;
  5993. }
  5994. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  5995. vnode.suspense.move(container, anchor, moveType);
  5996. return;
  5997. }
  5998. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  5999. type.move(vnode, container, anchor, internals);
  6000. return;
  6001. }
  6002. if (type === Fragment) {
  6003. hostInsert(el, container, anchor);
  6004. for (let i = 0; i < children.length; i++) {
  6005. move(children[i], container, anchor, moveType);
  6006. }
  6007. hostInsert(vnode.anchor, container, anchor);
  6008. return;
  6009. }
  6010. if (type === Static) {
  6011. moveStaticNode(vnode, container, anchor);
  6012. return;
  6013. }
  6014. // single nodes
  6015. const needTransition = moveType !== 2 /* MoveType.REORDER */ &&
  6016. shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  6017. transition;
  6018. if (needTransition) {
  6019. if (moveType === 0 /* MoveType.ENTER */) {
  6020. transition.beforeEnter(el);
  6021. hostInsert(el, container, anchor);
  6022. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  6023. }
  6024. else {
  6025. const { leave, delayLeave, afterLeave } = transition;
  6026. const remove = () => hostInsert(el, container, anchor);
  6027. const performLeave = () => {
  6028. leave(el, () => {
  6029. remove();
  6030. afterLeave && afterLeave();
  6031. });
  6032. };
  6033. if (delayLeave) {
  6034. delayLeave(el, remove, performLeave);
  6035. }
  6036. else {
  6037. performLeave();
  6038. }
  6039. }
  6040. }
  6041. else {
  6042. hostInsert(el, container, anchor);
  6043. }
  6044. };
  6045. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  6046. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  6047. // unset ref
  6048. if (ref != null) {
  6049. setRef(ref, null, parentSuspense, vnode, true);
  6050. }
  6051. if (shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */) {
  6052. parentComponent.ctx.deactivate(vnode);
  6053. return;
  6054. }
  6055. const shouldInvokeDirs = shapeFlag & 1 /* ShapeFlags.ELEMENT */ && dirs;
  6056. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  6057. let vnodeHook;
  6058. if (shouldInvokeVnodeHook &&
  6059. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  6060. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6061. }
  6062. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6063. unmountComponent(vnode.component, parentSuspense, doRemove);
  6064. }
  6065. else {
  6066. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6067. vnode.suspense.unmount(parentSuspense, doRemove);
  6068. return;
  6069. }
  6070. if (shouldInvokeDirs) {
  6071. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  6072. }
  6073. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6074. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  6075. }
  6076. else if (dynamicChildren &&
  6077. // #1153: fast path should not be taken for non-stable (v-for) fragments
  6078. (type !== Fragment ||
  6079. (patchFlag > 0 && patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */))) {
  6080. // fast path for block nodes: only need to unmount dynamic children.
  6081. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  6082. }
  6083. else if ((type === Fragment &&
  6084. patchFlag &
  6085. (128 /* PatchFlags.KEYED_FRAGMENT */ | 256 /* PatchFlags.UNKEYED_FRAGMENT */)) ||
  6086. (!optimized && shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */)) {
  6087. unmountChildren(children, parentComponent, parentSuspense);
  6088. }
  6089. if (doRemove) {
  6090. remove(vnode);
  6091. }
  6092. }
  6093. if ((shouldInvokeVnodeHook &&
  6094. (vnodeHook = props && props.onVnodeUnmounted)) ||
  6095. shouldInvokeDirs) {
  6096. queuePostRenderEffect(() => {
  6097. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6098. shouldInvokeDirs &&
  6099. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  6100. }, parentSuspense);
  6101. }
  6102. };
  6103. const remove = vnode => {
  6104. const { type, el, anchor, transition } = vnode;
  6105. if (type === Fragment) {
  6106. if ((process.env.NODE_ENV !== 'production') &&
  6107. vnode.patchFlag > 0 &&
  6108. vnode.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */ &&
  6109. transition &&
  6110. !transition.persisted) {
  6111. vnode.children.forEach(child => {
  6112. if (child.type === Comment) {
  6113. hostRemove(child.el);
  6114. }
  6115. else {
  6116. remove(child);
  6117. }
  6118. });
  6119. }
  6120. else {
  6121. removeFragment(el, anchor);
  6122. }
  6123. return;
  6124. }
  6125. if (type === Static) {
  6126. removeStaticNode(vnode);
  6127. return;
  6128. }
  6129. const performRemove = () => {
  6130. hostRemove(el);
  6131. if (transition && !transition.persisted && transition.afterLeave) {
  6132. transition.afterLeave();
  6133. }
  6134. };
  6135. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  6136. transition &&
  6137. !transition.persisted) {
  6138. const { leave, delayLeave } = transition;
  6139. const performLeave = () => leave(el, performRemove);
  6140. if (delayLeave) {
  6141. delayLeave(vnode.el, performRemove, performLeave);
  6142. }
  6143. else {
  6144. performLeave();
  6145. }
  6146. }
  6147. else {
  6148. performRemove();
  6149. }
  6150. };
  6151. const removeFragment = (cur, end) => {
  6152. // For fragments, directly remove all contained DOM nodes.
  6153. // (fragment child nodes cannot have transition)
  6154. let next;
  6155. while (cur !== end) {
  6156. next = hostNextSibling(cur);
  6157. hostRemove(cur);
  6158. cur = next;
  6159. }
  6160. hostRemove(end);
  6161. };
  6162. const unmountComponent = (instance, parentSuspense, doRemove) => {
  6163. if ((process.env.NODE_ENV !== 'production') && instance.type.__hmrId) {
  6164. unregisterHMR(instance);
  6165. }
  6166. const { bum, scope, update, subTree, um } = instance;
  6167. // beforeUnmount hook
  6168. if (bum) {
  6169. invokeArrayFns(bum);
  6170. }
  6171. // stop effects in component scope
  6172. scope.stop();
  6173. // update may be null if a component is unmounted before its async
  6174. // setup has resolved.
  6175. if (update) {
  6176. // so that scheduler will no longer invoke it
  6177. update.active = false;
  6178. unmount(subTree, instance, parentSuspense, doRemove);
  6179. }
  6180. // unmounted hook
  6181. if (um) {
  6182. queuePostRenderEffect(um, parentSuspense);
  6183. }
  6184. queuePostRenderEffect(() => {
  6185. instance.isUnmounted = true;
  6186. }, parentSuspense);
  6187. // A component with async dep inside a pending suspense is unmounted before
  6188. // its async dep resolves. This should remove the dep from the suspense, and
  6189. // cause the suspense to resolve immediately if that was the last dep.
  6190. if (parentSuspense &&
  6191. parentSuspense.pendingBranch &&
  6192. !parentSuspense.isUnmounted &&
  6193. instance.asyncDep &&
  6194. !instance.asyncResolved &&
  6195. instance.suspenseId === parentSuspense.pendingId) {
  6196. parentSuspense.deps--;
  6197. if (parentSuspense.deps === 0) {
  6198. parentSuspense.resolve();
  6199. }
  6200. }
  6201. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  6202. devtoolsComponentRemoved(instance);
  6203. }
  6204. };
  6205. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  6206. for (let i = start; i < children.length; i++) {
  6207. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  6208. }
  6209. };
  6210. const getNextHostNode = vnode => {
  6211. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6212. return getNextHostNode(vnode.component.subTree);
  6213. }
  6214. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6215. return vnode.suspense.next();
  6216. }
  6217. return hostNextSibling((vnode.anchor || vnode.el));
  6218. };
  6219. const render = (vnode, container, isSVG) => {
  6220. if (vnode == null) {
  6221. if (container._vnode) {
  6222. unmount(container._vnode, null, null, true);
  6223. }
  6224. }
  6225. else {
  6226. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  6227. }
  6228. flushPreFlushCbs();
  6229. flushPostFlushCbs();
  6230. container._vnode = vnode;
  6231. };
  6232. const internals = {
  6233. p: patch,
  6234. um: unmount,
  6235. m: move,
  6236. r: remove,
  6237. mt: mountComponent,
  6238. mc: mountChildren,
  6239. pc: patchChildren,
  6240. pbc: patchBlockChildren,
  6241. n: getNextHostNode,
  6242. o: options
  6243. };
  6244. let hydrate;
  6245. let hydrateNode;
  6246. if (createHydrationFns) {
  6247. [hydrate, hydrateNode] = createHydrationFns(internals);
  6248. }
  6249. return {
  6250. render,
  6251. hydrate,
  6252. createApp: createAppAPI(render, hydrate)
  6253. };
  6254. }
  6255. function toggleRecurse({ effect, update }, allowed) {
  6256. effect.allowRecurse = update.allowRecurse = allowed;
  6257. }
  6258. /**
  6259. * #1156
  6260. * When a component is HMR-enabled, we need to make sure that all static nodes
  6261. * inside a block also inherit the DOM element from the previous tree so that
  6262. * HMR updates (which are full updates) can retrieve the element for patching.
  6263. *
  6264. * #2080
  6265. * Inside keyed `template` fragment static children, if a fragment is moved,
  6266. * the children will always be moved. Therefore, in order to ensure correct move
  6267. * position, el should be inherited from previous nodes.
  6268. */
  6269. function traverseStaticChildren(n1, n2, shallow = false) {
  6270. const ch1 = n1.children;
  6271. const ch2 = n2.children;
  6272. if (isArray(ch1) && isArray(ch2)) {
  6273. for (let i = 0; i < ch1.length; i++) {
  6274. // this is only called in the optimized path so array children are
  6275. // guaranteed to be vnodes
  6276. const c1 = ch1[i];
  6277. let c2 = ch2[i];
  6278. if (c2.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && !c2.dynamicChildren) {
  6279. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) {
  6280. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  6281. c2.el = c1.el;
  6282. }
  6283. if (!shallow)
  6284. traverseStaticChildren(c1, c2);
  6285. }
  6286. // #6852 also inherit for text nodes
  6287. if (c2.type === Text) {
  6288. c2.el = c1.el;
  6289. }
  6290. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  6291. // would have received .el during block patch)
  6292. if ((process.env.NODE_ENV !== 'production') && c2.type === Comment && !c2.el) {
  6293. c2.el = c1.el;
  6294. }
  6295. }
  6296. }
  6297. }
  6298. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  6299. function getSequence(arr) {
  6300. const p = arr.slice();
  6301. const result = [0];
  6302. let i, j, u, v, c;
  6303. const len = arr.length;
  6304. for (i = 0; i < len; i++) {
  6305. const arrI = arr[i];
  6306. if (arrI !== 0) {
  6307. j = result[result.length - 1];
  6308. if (arr[j] < arrI) {
  6309. p[i] = j;
  6310. result.push(i);
  6311. continue;
  6312. }
  6313. u = 0;
  6314. v = result.length - 1;
  6315. while (u < v) {
  6316. c = (u + v) >> 1;
  6317. if (arr[result[c]] < arrI) {
  6318. u = c + 1;
  6319. }
  6320. else {
  6321. v = c;
  6322. }
  6323. }
  6324. if (arrI < arr[result[u]]) {
  6325. if (u > 0) {
  6326. p[i] = result[u - 1];
  6327. }
  6328. result[u] = i;
  6329. }
  6330. }
  6331. }
  6332. u = result.length;
  6333. v = result[u - 1];
  6334. while (u-- > 0) {
  6335. result[u] = v;
  6336. v = p[v];
  6337. }
  6338. return result;
  6339. }
  6340. const isTeleport = (type) => type.__isTeleport;
  6341. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  6342. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  6343. const resolveTarget = (props, select) => {
  6344. const targetSelector = props && props.to;
  6345. if (isString(targetSelector)) {
  6346. if (!select) {
  6347. (process.env.NODE_ENV !== 'production') &&
  6348. warn(`Current renderer does not support string target for Teleports. ` +
  6349. `(missing querySelector renderer option)`);
  6350. return null;
  6351. }
  6352. else {
  6353. const target = select(targetSelector);
  6354. if (!target) {
  6355. (process.env.NODE_ENV !== 'production') &&
  6356. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  6357. `Note the target element must exist before the component is mounted - ` +
  6358. `i.e. the target cannot be rendered by the component itself, and ` +
  6359. `ideally should be outside of the entire Vue component tree.`);
  6360. }
  6361. return target;
  6362. }
  6363. }
  6364. else {
  6365. if ((process.env.NODE_ENV !== 'production') && !targetSelector && !isTeleportDisabled(props)) {
  6366. warn(`Invalid Teleport target: ${targetSelector}`);
  6367. }
  6368. return targetSelector;
  6369. }
  6370. };
  6371. const TeleportImpl = {
  6372. __isTeleport: true,
  6373. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  6374. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  6375. const disabled = isTeleportDisabled(n2.props);
  6376. let { shapeFlag, children, dynamicChildren } = n2;
  6377. // #3302
  6378. // HMR updated, force full diff
  6379. if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
  6380. optimized = false;
  6381. dynamicChildren = null;
  6382. }
  6383. if (n1 == null) {
  6384. // insert anchors in the main view
  6385. const placeholder = (n2.el = (process.env.NODE_ENV !== 'production')
  6386. ? createComment('teleport start')
  6387. : createText(''));
  6388. const mainAnchor = (n2.anchor = (process.env.NODE_ENV !== 'production')
  6389. ? createComment('teleport end')
  6390. : createText(''));
  6391. insert(placeholder, container, anchor);
  6392. insert(mainAnchor, container, anchor);
  6393. const target = (n2.target = resolveTarget(n2.props, querySelector));
  6394. const targetAnchor = (n2.targetAnchor = createText(''));
  6395. if (target) {
  6396. insert(targetAnchor, target);
  6397. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  6398. isSVG = isSVG || isTargetSVG(target);
  6399. }
  6400. else if ((process.env.NODE_ENV !== 'production') && !disabled) {
  6401. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  6402. }
  6403. const mount = (container, anchor) => {
  6404. // Teleport *always* has Array children. This is enforced in both the
  6405. // compiler and vnode children normalization.
  6406. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6407. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6408. }
  6409. };
  6410. if (disabled) {
  6411. mount(container, mainAnchor);
  6412. }
  6413. else if (target) {
  6414. mount(target, targetAnchor);
  6415. }
  6416. }
  6417. else {
  6418. // update content
  6419. n2.el = n1.el;
  6420. const mainAnchor = (n2.anchor = n1.anchor);
  6421. const target = (n2.target = n1.target);
  6422. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  6423. const wasDisabled = isTeleportDisabled(n1.props);
  6424. const currentContainer = wasDisabled ? container : target;
  6425. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  6426. isSVG = isSVG || isTargetSVG(target);
  6427. if (dynamicChildren) {
  6428. // fast path when the teleport happens to be a block root
  6429. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6430. // even in block tree mode we need to make sure all root-level nodes
  6431. // in the teleport inherit previous DOM references so that they can
  6432. // be moved in future patches.
  6433. traverseStaticChildren(n1, n2, true);
  6434. }
  6435. else if (!optimized) {
  6436. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  6437. }
  6438. if (disabled) {
  6439. if (!wasDisabled) {
  6440. // enabled -> disabled
  6441. // move into main container
  6442. moveTeleport(n2, container, mainAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  6443. }
  6444. }
  6445. else {
  6446. // target changed
  6447. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  6448. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  6449. if (nextTarget) {
  6450. moveTeleport(n2, nextTarget, null, internals, 0 /* TeleportMoveTypes.TARGET_CHANGE */);
  6451. }
  6452. else if ((process.env.NODE_ENV !== 'production')) {
  6453. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  6454. }
  6455. }
  6456. else if (wasDisabled) {
  6457. // disabled -> enabled
  6458. // move into teleport target
  6459. moveTeleport(n2, target, targetAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  6460. }
  6461. }
  6462. }
  6463. updateCssVars(n2);
  6464. },
  6465. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  6466. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  6467. if (target) {
  6468. hostRemove(targetAnchor);
  6469. }
  6470. // an unmounted teleport should always remove its children if not disabled
  6471. if (doRemove || !isTeleportDisabled(props)) {
  6472. hostRemove(anchor);
  6473. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6474. for (let i = 0; i < children.length; i++) {
  6475. const child = children[i];
  6476. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  6477. }
  6478. }
  6479. }
  6480. },
  6481. move: moveTeleport,
  6482. hydrate: hydrateTeleport
  6483. };
  6484. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* TeleportMoveTypes.REORDER */) {
  6485. // move target anchor if this is a target change.
  6486. if (moveType === 0 /* TeleportMoveTypes.TARGET_CHANGE */) {
  6487. insert(vnode.targetAnchor, container, parentAnchor);
  6488. }
  6489. const { el, anchor, shapeFlag, children, props } = vnode;
  6490. const isReorder = moveType === 2 /* TeleportMoveTypes.REORDER */;
  6491. // move main view anchor if this is a re-order.
  6492. if (isReorder) {
  6493. insert(el, container, parentAnchor);
  6494. }
  6495. // if this is a re-order and teleport is enabled (content is in target)
  6496. // do not move children. So the opposite is: only move children if this
  6497. // is not a reorder, or the teleport is disabled
  6498. if (!isReorder || isTeleportDisabled(props)) {
  6499. // Teleport has either Array children or no children.
  6500. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6501. for (let i = 0; i < children.length; i++) {
  6502. move(children[i], container, parentAnchor, 2 /* MoveType.REORDER */);
  6503. }
  6504. }
  6505. }
  6506. // move main view anchor if this is a re-order.
  6507. if (isReorder) {
  6508. insert(anchor, container, parentAnchor);
  6509. }
  6510. }
  6511. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  6512. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  6513. if (target) {
  6514. // if multiple teleports rendered to the same target element, we need to
  6515. // pick up from where the last teleport finished instead of the first node
  6516. const targetNode = target._lpa || target.firstChild;
  6517. if (vnode.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6518. if (isTeleportDisabled(vnode.props)) {
  6519. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  6520. vnode.targetAnchor = targetNode;
  6521. }
  6522. else {
  6523. vnode.anchor = nextSibling(node);
  6524. // lookahead until we find the target anchor
  6525. // we cannot rely on return value of hydrateChildren() because there
  6526. // could be nested teleports
  6527. let targetAnchor = targetNode;
  6528. while (targetAnchor) {
  6529. targetAnchor = nextSibling(targetAnchor);
  6530. if (targetAnchor &&
  6531. targetAnchor.nodeType === 8 &&
  6532. targetAnchor.data === 'teleport anchor') {
  6533. vnode.targetAnchor = targetAnchor;
  6534. target._lpa =
  6535. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  6536. break;
  6537. }
  6538. }
  6539. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  6540. }
  6541. }
  6542. updateCssVars(vnode);
  6543. }
  6544. return vnode.anchor && nextSibling(vnode.anchor);
  6545. }
  6546. // Force-casted public typing for h and TSX props inference
  6547. const Teleport = TeleportImpl;
  6548. function updateCssVars(vnode) {
  6549. // presence of .ut method indicates owner component uses css vars.
  6550. // code path here can assume browser environment.
  6551. const ctx = vnode.ctx;
  6552. if (ctx && ctx.ut) {
  6553. let node = vnode.children[0].el;
  6554. while (node !== vnode.targetAnchor) {
  6555. if (node.nodeType === 1)
  6556. node.setAttribute('data-v-owner', ctx.uid);
  6557. node = node.nextSibling;
  6558. }
  6559. ctx.ut();
  6560. }
  6561. }
  6562. const Fragment = Symbol((process.env.NODE_ENV !== 'production') ? 'Fragment' : undefined);
  6563. const Text = Symbol((process.env.NODE_ENV !== 'production') ? 'Text' : undefined);
  6564. const Comment = Symbol((process.env.NODE_ENV !== 'production') ? 'Comment' : undefined);
  6565. const Static = Symbol((process.env.NODE_ENV !== 'production') ? 'Static' : undefined);
  6566. // Since v-if and v-for are the two possible ways node structure can dynamically
  6567. // change, once we consider v-if branches and each v-for fragment a block, we
  6568. // can divide a template into nested blocks, and within each block the node
  6569. // structure would be stable. This allows us to skip most children diffing
  6570. // and only worry about the dynamic nodes (indicated by patch flags).
  6571. const blockStack = [];
  6572. let currentBlock = null;
  6573. /**
  6574. * Open a block.
  6575. * This must be called before `createBlock`. It cannot be part of `createBlock`
  6576. * because the children of the block are evaluated before `createBlock` itself
  6577. * is called. The generated code typically looks like this:
  6578. *
  6579. * ```js
  6580. * function render() {
  6581. * return (openBlock(),createBlock('div', null, [...]))
  6582. * }
  6583. * ```
  6584. * disableTracking is true when creating a v-for fragment block, since a v-for
  6585. * fragment always diffs its children.
  6586. *
  6587. * @private
  6588. */
  6589. function openBlock(disableTracking = false) {
  6590. blockStack.push((currentBlock = disableTracking ? null : []));
  6591. }
  6592. function closeBlock() {
  6593. blockStack.pop();
  6594. currentBlock = blockStack[blockStack.length - 1] || null;
  6595. }
  6596. // Whether we should be tracking dynamic child nodes inside a block.
  6597. // Only tracks when this value is > 0
  6598. // We are not using a simple boolean because this value may need to be
  6599. // incremented/decremented by nested usage of v-once (see below)
  6600. let isBlockTreeEnabled = 1;
  6601. /**
  6602. * Block tracking sometimes needs to be disabled, for example during the
  6603. * creation of a tree that needs to be cached by v-once. The compiler generates
  6604. * code like this:
  6605. *
  6606. * ``` js
  6607. * _cache[1] || (
  6608. * setBlockTracking(-1),
  6609. * _cache[1] = createVNode(...),
  6610. * setBlockTracking(1),
  6611. * _cache[1]
  6612. * )
  6613. * ```
  6614. *
  6615. * @private
  6616. */
  6617. function setBlockTracking(value) {
  6618. isBlockTreeEnabled += value;
  6619. }
  6620. function setupBlock(vnode) {
  6621. // save current block children on the block vnode
  6622. vnode.dynamicChildren =
  6623. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  6624. // close block
  6625. closeBlock();
  6626. // a block is always going to be patched, so track it as a child of its
  6627. // parent block
  6628. if (isBlockTreeEnabled > 0 && currentBlock) {
  6629. currentBlock.push(vnode);
  6630. }
  6631. return vnode;
  6632. }
  6633. /**
  6634. * @private
  6635. */
  6636. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  6637. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  6638. }
  6639. /**
  6640. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  6641. * A block root keeps track of dynamic nodes within the block in the
  6642. * `dynamicChildren` array.
  6643. *
  6644. * @private
  6645. */
  6646. function createBlock(type, props, children, patchFlag, dynamicProps) {
  6647. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  6648. }
  6649. function isVNode(value) {
  6650. return value ? value.__v_isVNode === true : false;
  6651. }
  6652. function isSameVNodeType(n1, n2) {
  6653. if ((process.env.NODE_ENV !== 'production') &&
  6654. n2.shapeFlag & 6 /* ShapeFlags.COMPONENT */ &&
  6655. hmrDirtyComponents.has(n2.type)) {
  6656. // #7042, ensure the vnode being unmounted during HMR
  6657. // bitwise operations to remove keep alive flags
  6658. n1.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  6659. n2.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  6660. // HMR only: if the component has been hot-updated, force a reload.
  6661. return false;
  6662. }
  6663. return n1.type === n2.type && n1.key === n2.key;
  6664. }
  6665. let vnodeArgsTransformer;
  6666. /**
  6667. * Internal API for registering an arguments transform for createVNode
  6668. * used for creating stubs in the test-utils
  6669. * It is *internal* but needs to be exposed for test-utils to pick up proper
  6670. * typings
  6671. */
  6672. function transformVNodeArgs(transformer) {
  6673. vnodeArgsTransformer = transformer;
  6674. }
  6675. const createVNodeWithArgsTransform = (...args) => {
  6676. return _createVNode(...(vnodeArgsTransformer
  6677. ? vnodeArgsTransformer(args, currentRenderingInstance)
  6678. : args));
  6679. };
  6680. const InternalObjectKey = `__vInternal`;
  6681. const normalizeKey = ({ key }) => key != null ? key : null;
  6682. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  6683. return (ref != null
  6684. ? isString(ref) || isRef(ref) || isFunction(ref)
  6685. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  6686. : ref
  6687. : null);
  6688. };
  6689. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ShapeFlags.ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  6690. const vnode = {
  6691. __v_isVNode: true,
  6692. __v_skip: true,
  6693. type,
  6694. props,
  6695. key: props && normalizeKey(props),
  6696. ref: props && normalizeRef(props),
  6697. scopeId: currentScopeId,
  6698. slotScopeIds: null,
  6699. children,
  6700. component: null,
  6701. suspense: null,
  6702. ssContent: null,
  6703. ssFallback: null,
  6704. dirs: null,
  6705. transition: null,
  6706. el: null,
  6707. anchor: null,
  6708. target: null,
  6709. targetAnchor: null,
  6710. staticCount: 0,
  6711. shapeFlag,
  6712. patchFlag,
  6713. dynamicProps,
  6714. dynamicChildren: null,
  6715. appContext: null,
  6716. ctx: currentRenderingInstance
  6717. };
  6718. if (needFullChildrenNormalization) {
  6719. normalizeChildren(vnode, children);
  6720. // normalize suspense children
  6721. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6722. type.normalize(vnode);
  6723. }
  6724. }
  6725. else if (children) {
  6726. // compiled element vnode - if children is passed, only possible types are
  6727. // string or Array.
  6728. vnode.shapeFlag |= isString(children)
  6729. ? 8 /* ShapeFlags.TEXT_CHILDREN */
  6730. : 16 /* ShapeFlags.ARRAY_CHILDREN */;
  6731. }
  6732. // validate key
  6733. if ((process.env.NODE_ENV !== 'production') && vnode.key !== vnode.key) {
  6734. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  6735. }
  6736. // track vnode for block tree
  6737. if (isBlockTreeEnabled > 0 &&
  6738. // avoid a block node from tracking itself
  6739. !isBlockNode &&
  6740. // has current parent block
  6741. currentBlock &&
  6742. // presence of a patch flag indicates this node needs patching on updates.
  6743. // component nodes also should always be patched, because even if the
  6744. // component doesn't need to update, it needs to persist the instance on to
  6745. // the next vnode so that it can be properly unmounted later.
  6746. (vnode.patchFlag > 0 || shapeFlag & 6 /* ShapeFlags.COMPONENT */) &&
  6747. // the EVENTS flag is only for hydration and if it is the only flag, the
  6748. // vnode should not be considered dynamic due to handler caching.
  6749. vnode.patchFlag !== 32 /* PatchFlags.HYDRATE_EVENTS */) {
  6750. currentBlock.push(vnode);
  6751. }
  6752. return vnode;
  6753. }
  6754. const createVNode = ((process.env.NODE_ENV !== 'production') ? createVNodeWithArgsTransform : _createVNode);
  6755. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  6756. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  6757. if ((process.env.NODE_ENV !== 'production') && !type) {
  6758. warn(`Invalid vnode type when creating vnode: ${type}.`);
  6759. }
  6760. type = Comment;
  6761. }
  6762. if (isVNode(type)) {
  6763. // createVNode receiving an existing vnode. This happens in cases like
  6764. // <component :is="vnode"/>
  6765. // #2078 make sure to merge refs during the clone instead of overwriting it
  6766. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  6767. if (children) {
  6768. normalizeChildren(cloned, children);
  6769. }
  6770. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  6771. if (cloned.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6772. currentBlock[currentBlock.indexOf(type)] = cloned;
  6773. }
  6774. else {
  6775. currentBlock.push(cloned);
  6776. }
  6777. }
  6778. cloned.patchFlag |= -2 /* PatchFlags.BAIL */;
  6779. return cloned;
  6780. }
  6781. // class component normalization.
  6782. if (isClassComponent(type)) {
  6783. type = type.__vccOpts;
  6784. }
  6785. // class & style normalization.
  6786. if (props) {
  6787. // for reactive or proxy objects, we need to clone it to enable mutation.
  6788. props = guardReactiveProps(props);
  6789. let { class: klass, style } = props;
  6790. if (klass && !isString(klass)) {
  6791. props.class = normalizeClass(klass);
  6792. }
  6793. if (isObject(style)) {
  6794. // reactive state objects need to be cloned since they are likely to be
  6795. // mutated
  6796. if (isProxy(style) && !isArray(style)) {
  6797. style = extend({}, style);
  6798. }
  6799. props.style = normalizeStyle(style);
  6800. }
  6801. }
  6802. // encode the vnode type information into a bitmap
  6803. const shapeFlag = isString(type)
  6804. ? 1 /* ShapeFlags.ELEMENT */
  6805. : isSuspense(type)
  6806. ? 128 /* ShapeFlags.SUSPENSE */
  6807. : isTeleport(type)
  6808. ? 64 /* ShapeFlags.TELEPORT */
  6809. : isObject(type)
  6810. ? 4 /* ShapeFlags.STATEFUL_COMPONENT */
  6811. : isFunction(type)
  6812. ? 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */
  6813. : 0;
  6814. if ((process.env.NODE_ENV !== 'production') && shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ && isProxy(type)) {
  6815. type = toRaw(type);
  6816. warn(`Vue received a Component which was made a reactive object. This can ` +
  6817. `lead to unnecessary performance overhead, and should be avoided by ` +
  6818. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  6819. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  6820. }
  6821. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  6822. }
  6823. function guardReactiveProps(props) {
  6824. if (!props)
  6825. return null;
  6826. return isProxy(props) || InternalObjectKey in props
  6827. ? extend({}, props)
  6828. : props;
  6829. }
  6830. function cloneVNode(vnode, extraProps, mergeRef = false) {
  6831. // This is intentionally NOT using spread or extend to avoid the runtime
  6832. // key enumeration cost.
  6833. const { props, ref, patchFlag, children } = vnode;
  6834. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  6835. const cloned = {
  6836. __v_isVNode: true,
  6837. __v_skip: true,
  6838. type: vnode.type,
  6839. props: mergedProps,
  6840. key: mergedProps && normalizeKey(mergedProps),
  6841. ref: extraProps && extraProps.ref
  6842. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  6843. // if the vnode itself already has a ref, cloneVNode will need to merge
  6844. // the refs so the single vnode can be set on multiple refs
  6845. mergeRef && ref
  6846. ? isArray(ref)
  6847. ? ref.concat(normalizeRef(extraProps))
  6848. : [ref, normalizeRef(extraProps)]
  6849. : normalizeRef(extraProps)
  6850. : ref,
  6851. scopeId: vnode.scopeId,
  6852. slotScopeIds: vnode.slotScopeIds,
  6853. children: (process.env.NODE_ENV !== 'production') && patchFlag === -1 /* PatchFlags.HOISTED */ && isArray(children)
  6854. ? children.map(deepCloneVNode)
  6855. : children,
  6856. target: vnode.target,
  6857. targetAnchor: vnode.targetAnchor,
  6858. staticCount: vnode.staticCount,
  6859. shapeFlag: vnode.shapeFlag,
  6860. // if the vnode is cloned with extra props, we can no longer assume its
  6861. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  6862. // note: preserve flag for fragments since they use the flag for children
  6863. // fast paths only.
  6864. patchFlag: extraProps && vnode.type !== Fragment
  6865. ? patchFlag === -1 // hoisted node
  6866. ? 16 /* PatchFlags.FULL_PROPS */
  6867. : patchFlag | 16 /* PatchFlags.FULL_PROPS */
  6868. : patchFlag,
  6869. dynamicProps: vnode.dynamicProps,
  6870. dynamicChildren: vnode.dynamicChildren,
  6871. appContext: vnode.appContext,
  6872. dirs: vnode.dirs,
  6873. transition: vnode.transition,
  6874. // These should technically only be non-null on mounted VNodes. However,
  6875. // they *should* be copied for kept-alive vnodes. So we just always copy
  6876. // them since them being non-null during a mount doesn't affect the logic as
  6877. // they will simply be overwritten.
  6878. component: vnode.component,
  6879. suspense: vnode.suspense,
  6880. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  6881. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  6882. el: vnode.el,
  6883. anchor: vnode.anchor,
  6884. ctx: vnode.ctx
  6885. };
  6886. return cloned;
  6887. }
  6888. /**
  6889. * Dev only, for HMR of hoisted vnodes reused in v-for
  6890. * https://github.com/vitejs/vite/issues/2022
  6891. */
  6892. function deepCloneVNode(vnode) {
  6893. const cloned = cloneVNode(vnode);
  6894. if (isArray(vnode.children)) {
  6895. cloned.children = vnode.children.map(deepCloneVNode);
  6896. }
  6897. return cloned;
  6898. }
  6899. /**
  6900. * @private
  6901. */
  6902. function createTextVNode(text = ' ', flag = 0) {
  6903. return createVNode(Text, null, text, flag);
  6904. }
  6905. /**
  6906. * @private
  6907. */
  6908. function createStaticVNode(content, numberOfNodes) {
  6909. // A static vnode can contain multiple stringified elements, and the number
  6910. // of elements is necessary for hydration.
  6911. const vnode = createVNode(Static, null, content);
  6912. vnode.staticCount = numberOfNodes;
  6913. return vnode;
  6914. }
  6915. /**
  6916. * @private
  6917. */
  6918. function createCommentVNode(text = '',
  6919. // when used as the v-else branch, the comment node must be created as a
  6920. // block to ensure correct updates.
  6921. asBlock = false) {
  6922. return asBlock
  6923. ? (openBlock(), createBlock(Comment, null, text))
  6924. : createVNode(Comment, null, text);
  6925. }
  6926. function normalizeVNode(child) {
  6927. if (child == null || typeof child === 'boolean') {
  6928. // empty placeholder
  6929. return createVNode(Comment);
  6930. }
  6931. else if (isArray(child)) {
  6932. // fragment
  6933. return createVNode(Fragment, null,
  6934. // #3666, avoid reference pollution when reusing vnode
  6935. child.slice());
  6936. }
  6937. else if (typeof child === 'object') {
  6938. // already vnode, this should be the most common since compiled templates
  6939. // always produce all-vnode children arrays
  6940. return cloneIfMounted(child);
  6941. }
  6942. else {
  6943. // strings and numbers
  6944. return createVNode(Text, null, String(child));
  6945. }
  6946. }
  6947. // optimized normalization for template-compiled render fns
  6948. function cloneIfMounted(child) {
  6949. return (child.el === null && child.patchFlag !== -1 /* PatchFlags.HOISTED */) ||
  6950. child.memo
  6951. ? child
  6952. : cloneVNode(child);
  6953. }
  6954. function normalizeChildren(vnode, children) {
  6955. let type = 0;
  6956. const { shapeFlag } = vnode;
  6957. if (children == null) {
  6958. children = null;
  6959. }
  6960. else if (isArray(children)) {
  6961. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  6962. }
  6963. else if (typeof children === 'object') {
  6964. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 64 /* ShapeFlags.TELEPORT */)) {
  6965. // Normalize slot to plain children for plain element and Teleport
  6966. const slot = children.default;
  6967. if (slot) {
  6968. // _c marker is added by withCtx() indicating this is a compiled slot
  6969. slot._c && (slot._d = false);
  6970. normalizeChildren(vnode, slot());
  6971. slot._c && (slot._d = true);
  6972. }
  6973. return;
  6974. }
  6975. else {
  6976. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  6977. const slotFlag = children._;
  6978. if (!slotFlag && !(InternalObjectKey in children)) {
  6979. children._ctx = currentRenderingInstance;
  6980. }
  6981. else if (slotFlag === 3 /* SlotFlags.FORWARDED */ && currentRenderingInstance) {
  6982. // a child component receives forwarded slots from the parent.
  6983. // its slot type is determined by its parent's slot type.
  6984. if (currentRenderingInstance.slots._ === 1 /* SlotFlags.STABLE */) {
  6985. children._ = 1 /* SlotFlags.STABLE */;
  6986. }
  6987. else {
  6988. children._ = 2 /* SlotFlags.DYNAMIC */;
  6989. vnode.patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  6990. }
  6991. }
  6992. }
  6993. }
  6994. else if (isFunction(children)) {
  6995. children = { default: children, _ctx: currentRenderingInstance };
  6996. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  6997. }
  6998. else {
  6999. children = String(children);
  7000. // force teleport children to array so it can be moved around
  7001. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7002. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  7003. children = [createTextVNode(children)];
  7004. }
  7005. else {
  7006. type = 8 /* ShapeFlags.TEXT_CHILDREN */;
  7007. }
  7008. }
  7009. vnode.children = children;
  7010. vnode.shapeFlag |= type;
  7011. }
  7012. function mergeProps(...args) {
  7013. const ret = {};
  7014. for (let i = 0; i < args.length; i++) {
  7015. const toMerge = args[i];
  7016. for (const key in toMerge) {
  7017. if (key === 'class') {
  7018. if (ret.class !== toMerge.class) {
  7019. ret.class = normalizeClass([ret.class, toMerge.class]);
  7020. }
  7021. }
  7022. else if (key === 'style') {
  7023. ret.style = normalizeStyle([ret.style, toMerge.style]);
  7024. }
  7025. else if (isOn(key)) {
  7026. const existing = ret[key];
  7027. const incoming = toMerge[key];
  7028. if (incoming &&
  7029. existing !== incoming &&
  7030. !(isArray(existing) && existing.includes(incoming))) {
  7031. ret[key] = existing
  7032. ? [].concat(existing, incoming)
  7033. : incoming;
  7034. }
  7035. }
  7036. else if (key !== '') {
  7037. ret[key] = toMerge[key];
  7038. }
  7039. }
  7040. }
  7041. return ret;
  7042. }
  7043. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  7044. callWithAsyncErrorHandling(hook, instance, 7 /* ErrorCodes.VNODE_HOOK */, [
  7045. vnode,
  7046. prevVNode
  7047. ]);
  7048. }
  7049. const emptyAppContext = createAppContext();
  7050. let uid$1 = 0;
  7051. function createComponentInstance(vnode, parent, suspense) {
  7052. const type = vnode.type;
  7053. // inherit parent app context - or - if root, adopt from root vnode
  7054. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  7055. const instance = {
  7056. uid: uid$1++,
  7057. vnode,
  7058. type,
  7059. parent,
  7060. appContext,
  7061. root: null,
  7062. next: null,
  7063. subTree: null,
  7064. effect: null,
  7065. update: null,
  7066. scope: new EffectScope(true /* detached */),
  7067. render: null,
  7068. proxy: null,
  7069. exposed: null,
  7070. exposeProxy: null,
  7071. withProxy: null,
  7072. provides: parent ? parent.provides : Object.create(appContext.provides),
  7073. accessCache: null,
  7074. renderCache: [],
  7075. // local resolved assets
  7076. components: null,
  7077. directives: null,
  7078. // resolved props and emits options
  7079. propsOptions: normalizePropsOptions(type, appContext),
  7080. emitsOptions: normalizeEmitsOptions(type, appContext),
  7081. // emit
  7082. emit: null,
  7083. emitted: null,
  7084. // props default value
  7085. propsDefaults: EMPTY_OBJ,
  7086. // inheritAttrs
  7087. inheritAttrs: type.inheritAttrs,
  7088. // state
  7089. ctx: EMPTY_OBJ,
  7090. data: EMPTY_OBJ,
  7091. props: EMPTY_OBJ,
  7092. attrs: EMPTY_OBJ,
  7093. slots: EMPTY_OBJ,
  7094. refs: EMPTY_OBJ,
  7095. setupState: EMPTY_OBJ,
  7096. setupContext: null,
  7097. // suspense related
  7098. suspense,
  7099. suspenseId: suspense ? suspense.pendingId : 0,
  7100. asyncDep: null,
  7101. asyncResolved: false,
  7102. // lifecycle hooks
  7103. // not using enums here because it results in computed properties
  7104. isMounted: false,
  7105. isUnmounted: false,
  7106. isDeactivated: false,
  7107. bc: null,
  7108. c: null,
  7109. bm: null,
  7110. m: null,
  7111. bu: null,
  7112. u: null,
  7113. um: null,
  7114. bum: null,
  7115. da: null,
  7116. a: null,
  7117. rtg: null,
  7118. rtc: null,
  7119. ec: null,
  7120. sp: null
  7121. };
  7122. if ((process.env.NODE_ENV !== 'production')) {
  7123. instance.ctx = createDevRenderContext(instance);
  7124. }
  7125. else {
  7126. instance.ctx = { _: instance };
  7127. }
  7128. instance.root = parent ? parent.root : instance;
  7129. instance.emit = emit$1.bind(null, instance);
  7130. // apply custom element special handling
  7131. if (vnode.ce) {
  7132. vnode.ce(instance);
  7133. }
  7134. return instance;
  7135. }
  7136. let currentInstance = null;
  7137. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  7138. const setCurrentInstance = (instance) => {
  7139. currentInstance = instance;
  7140. instance.scope.on();
  7141. };
  7142. const unsetCurrentInstance = () => {
  7143. currentInstance && currentInstance.scope.off();
  7144. currentInstance = null;
  7145. };
  7146. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  7147. function validateComponentName(name, config) {
  7148. const appIsNativeTag = config.isNativeTag || NO;
  7149. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  7150. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  7151. }
  7152. }
  7153. function isStatefulComponent(instance) {
  7154. return instance.vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */;
  7155. }
  7156. let isInSSRComponentSetup = false;
  7157. function setupComponent(instance, isSSR = false) {
  7158. isInSSRComponentSetup = isSSR;
  7159. const { props, children } = instance.vnode;
  7160. const isStateful = isStatefulComponent(instance);
  7161. initProps(instance, props, isStateful, isSSR);
  7162. initSlots(instance, children);
  7163. const setupResult = isStateful
  7164. ? setupStatefulComponent(instance, isSSR)
  7165. : undefined;
  7166. isInSSRComponentSetup = false;
  7167. return setupResult;
  7168. }
  7169. function setupStatefulComponent(instance, isSSR) {
  7170. var _a;
  7171. const Component = instance.type;
  7172. if ((process.env.NODE_ENV !== 'production')) {
  7173. if (Component.name) {
  7174. validateComponentName(Component.name, instance.appContext.config);
  7175. }
  7176. if (Component.components) {
  7177. const names = Object.keys(Component.components);
  7178. for (let i = 0; i < names.length; i++) {
  7179. validateComponentName(names[i], instance.appContext.config);
  7180. }
  7181. }
  7182. if (Component.directives) {
  7183. const names = Object.keys(Component.directives);
  7184. for (let i = 0; i < names.length; i++) {
  7185. validateDirectiveName(names[i]);
  7186. }
  7187. }
  7188. if (Component.compilerOptions && isRuntimeOnly()) {
  7189. warn(`"compilerOptions" is only supported when using a build of Vue that ` +
  7190. `includes the runtime compiler. Since you are using a runtime-only ` +
  7191. `build, the options should be passed via your build tool config instead.`);
  7192. }
  7193. }
  7194. // 0. create render proxy property access cache
  7195. instance.accessCache = Object.create(null);
  7196. // 1. create public instance / render proxy
  7197. // also mark it raw so it's never observed
  7198. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  7199. if ((process.env.NODE_ENV !== 'production')) {
  7200. exposePropsOnRenderContext(instance);
  7201. }
  7202. // 2. call setup()
  7203. const { setup } = Component;
  7204. if (setup) {
  7205. const setupContext = (instance.setupContext =
  7206. setup.length > 1 ? createSetupContext(instance) : null);
  7207. setCurrentInstance(instance);
  7208. pauseTracking();
  7209. const setupResult = callWithErrorHandling(setup, instance, 0 /* ErrorCodes.SETUP_FUNCTION */, [(process.env.NODE_ENV !== 'production') ? shallowReadonly(instance.props) : instance.props, setupContext]);
  7210. resetTracking();
  7211. unsetCurrentInstance();
  7212. if (isPromise(setupResult)) {
  7213. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  7214. if (isSSR) {
  7215. // return the promise so server-renderer can wait on it
  7216. return setupResult
  7217. .then((resolvedResult) => {
  7218. handleSetupResult(instance, resolvedResult, isSSR);
  7219. })
  7220. .catch(e => {
  7221. handleError(e, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  7222. });
  7223. }
  7224. else {
  7225. // async setup returned Promise.
  7226. // bail here and wait for re-entry.
  7227. instance.asyncDep = setupResult;
  7228. if ((process.env.NODE_ENV !== 'production') && !instance.suspense) {
  7229. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  7230. warn(`Component <${name}>: setup function returned a promise, but no ` +
  7231. `<Suspense> boundary was found in the parent component tree. ` +
  7232. `A component with async setup() must be nested in a <Suspense> ` +
  7233. `in order to be rendered.`);
  7234. }
  7235. }
  7236. }
  7237. else {
  7238. handleSetupResult(instance, setupResult, isSSR);
  7239. }
  7240. }
  7241. else {
  7242. finishComponentSetup(instance, isSSR);
  7243. }
  7244. }
  7245. function handleSetupResult(instance, setupResult, isSSR) {
  7246. if (isFunction(setupResult)) {
  7247. // setup returned an inline render function
  7248. if (instance.type.__ssrInlineRender) {
  7249. // when the function's name is `ssrRender` (compiled by SFC inline mode),
  7250. // set it as ssrRender instead.
  7251. instance.ssrRender = setupResult;
  7252. }
  7253. else {
  7254. instance.render = setupResult;
  7255. }
  7256. }
  7257. else if (isObject(setupResult)) {
  7258. if ((process.env.NODE_ENV !== 'production') && isVNode(setupResult)) {
  7259. warn(`setup() should not return VNodes directly - ` +
  7260. `return a render function instead.`);
  7261. }
  7262. // setup returned bindings.
  7263. // assuming a render function compiled from template is present.
  7264. if ((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) {
  7265. instance.devtoolsRawSetupState = setupResult;
  7266. }
  7267. instance.setupState = proxyRefs(setupResult);
  7268. if ((process.env.NODE_ENV !== 'production')) {
  7269. exposeSetupStateOnRenderContext(instance);
  7270. }
  7271. }
  7272. else if ((process.env.NODE_ENV !== 'production') && setupResult !== undefined) {
  7273. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  7274. }
  7275. finishComponentSetup(instance, isSSR);
  7276. }
  7277. let compile;
  7278. let installWithProxy;
  7279. /**
  7280. * For runtime-dom to register the compiler.
  7281. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  7282. */
  7283. function registerRuntimeCompiler(_compile) {
  7284. compile = _compile;
  7285. installWithProxy = i => {
  7286. if (i.render._rc) {
  7287. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  7288. }
  7289. };
  7290. }
  7291. // dev only
  7292. const isRuntimeOnly = () => !compile;
  7293. function finishComponentSetup(instance, isSSR, skipOptions) {
  7294. const Component = instance.type;
  7295. // template / render function normalization
  7296. // could be already set when returned from setup()
  7297. if (!instance.render) {
  7298. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  7299. // is done by server-renderer
  7300. if (!isSSR && compile && !Component.render) {
  7301. const template = Component.template ||
  7302. resolveMergedOptions(instance).template;
  7303. if (template) {
  7304. if ((process.env.NODE_ENV !== 'production')) {
  7305. startMeasure(instance, `compile`);
  7306. }
  7307. const { isCustomElement, compilerOptions } = instance.appContext.config;
  7308. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  7309. const finalCompilerOptions = extend(extend({
  7310. isCustomElement,
  7311. delimiters
  7312. }, compilerOptions), componentCompilerOptions);
  7313. Component.render = compile(template, finalCompilerOptions);
  7314. if ((process.env.NODE_ENV !== 'production')) {
  7315. endMeasure(instance, `compile`);
  7316. }
  7317. }
  7318. }
  7319. instance.render = (Component.render || NOOP);
  7320. // for runtime-compiled render functions using `with` blocks, the render
  7321. // proxy used needs a different `has` handler which is more performant and
  7322. // also only allows a whitelist of globals to fallthrough.
  7323. if (installWithProxy) {
  7324. installWithProxy(instance);
  7325. }
  7326. }
  7327. // support for 2.x options
  7328. if (__VUE_OPTIONS_API__ && !(false )) {
  7329. setCurrentInstance(instance);
  7330. pauseTracking();
  7331. applyOptions(instance);
  7332. resetTracking();
  7333. unsetCurrentInstance();
  7334. }
  7335. // warn missing template/render
  7336. // the runtime compilation of template in SSR is done by server-render
  7337. if ((process.env.NODE_ENV !== 'production') && !Component.render && instance.render === NOOP && !isSSR) {
  7338. /* istanbul ignore if */
  7339. if (!compile && Component.template) {
  7340. warn(`Component provided template option but ` +
  7341. `runtime compilation is not supported in this build of Vue.` +
  7342. (` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
  7343. ) /* should not happen */);
  7344. }
  7345. else {
  7346. warn(`Component is missing template or render function.`);
  7347. }
  7348. }
  7349. }
  7350. function createAttrsProxy(instance) {
  7351. return new Proxy(instance.attrs, (process.env.NODE_ENV !== 'production')
  7352. ? {
  7353. get(target, key) {
  7354. markAttrsAccessed();
  7355. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  7356. return target[key];
  7357. },
  7358. set() {
  7359. warn(`setupContext.attrs is readonly.`);
  7360. return false;
  7361. },
  7362. deleteProperty() {
  7363. warn(`setupContext.attrs is readonly.`);
  7364. return false;
  7365. }
  7366. }
  7367. : {
  7368. get(target, key) {
  7369. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  7370. return target[key];
  7371. }
  7372. });
  7373. }
  7374. function createSetupContext(instance) {
  7375. const expose = exposed => {
  7376. if ((process.env.NODE_ENV !== 'production') && instance.exposed) {
  7377. warn(`expose() should be called only once per setup().`);
  7378. }
  7379. instance.exposed = exposed || {};
  7380. };
  7381. let attrs;
  7382. if ((process.env.NODE_ENV !== 'production')) {
  7383. // We use getters in dev in case libs like test-utils overwrite instance
  7384. // properties (overwrites should not be done in prod)
  7385. return Object.freeze({
  7386. get attrs() {
  7387. return attrs || (attrs = createAttrsProxy(instance));
  7388. },
  7389. get slots() {
  7390. return shallowReadonly(instance.slots);
  7391. },
  7392. get emit() {
  7393. return (event, ...args) => instance.emit(event, ...args);
  7394. },
  7395. expose
  7396. });
  7397. }
  7398. else {
  7399. return {
  7400. get attrs() {
  7401. return attrs || (attrs = createAttrsProxy(instance));
  7402. },
  7403. slots: instance.slots,
  7404. emit: instance.emit,
  7405. expose
  7406. };
  7407. }
  7408. }
  7409. function getExposeProxy(instance) {
  7410. if (instance.exposed) {
  7411. return (instance.exposeProxy ||
  7412. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  7413. get(target, key) {
  7414. if (key in target) {
  7415. return target[key];
  7416. }
  7417. else if (key in publicPropertiesMap) {
  7418. return publicPropertiesMap[key](instance);
  7419. }
  7420. },
  7421. has(target, key) {
  7422. return key in target || key in publicPropertiesMap;
  7423. }
  7424. })));
  7425. }
  7426. }
  7427. const classifyRE = /(?:^|[-_])(\w)/g;
  7428. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  7429. function getComponentName(Component, includeInferred = true) {
  7430. return isFunction(Component)
  7431. ? Component.displayName || Component.name
  7432. : Component.name || (includeInferred && Component.__name);
  7433. }
  7434. /* istanbul ignore next */
  7435. function formatComponentName(instance, Component, isRoot = false) {
  7436. let name = getComponentName(Component);
  7437. if (!name && Component.__file) {
  7438. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  7439. if (match) {
  7440. name = match[1];
  7441. }
  7442. }
  7443. if (!name && instance && instance.parent) {
  7444. // try to infer the name based on reverse resolution
  7445. const inferFromRegistry = (registry) => {
  7446. for (const key in registry) {
  7447. if (registry[key] === Component) {
  7448. return key;
  7449. }
  7450. }
  7451. };
  7452. name =
  7453. inferFromRegistry(instance.components ||
  7454. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  7455. }
  7456. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  7457. }
  7458. function isClassComponent(value) {
  7459. return isFunction(value) && '__vccOpts' in value;
  7460. }
  7461. const computed = ((getterOrOptions, debugOptions) => {
  7462. // @ts-ignore
  7463. return computed$1(getterOrOptions, debugOptions, isInSSRComponentSetup);
  7464. });
  7465. // dev only
  7466. const warnRuntimeUsage = (method) => warn(`${method}() is a compiler-hint helper that is only usable inside ` +
  7467. `<script setup> of a single file component. Its arguments should be ` +
  7468. `compiled away and passing it at runtime has no effect.`);
  7469. // implementation
  7470. function defineProps() {
  7471. if ((process.env.NODE_ENV !== 'production')) {
  7472. warnRuntimeUsage(`defineProps`);
  7473. }
  7474. return null;
  7475. }
  7476. // implementation
  7477. function defineEmits() {
  7478. if ((process.env.NODE_ENV !== 'production')) {
  7479. warnRuntimeUsage(`defineEmits`);
  7480. }
  7481. return null;
  7482. }
  7483. /**
  7484. * Vue `<script setup>` compiler macro for declaring a component's exposed
  7485. * instance properties when it is accessed by a parent component via template
  7486. * refs.
  7487. *
  7488. * `<script setup>` components are closed by default - i.e. variables inside
  7489. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  7490. * via `defineExpose`.
  7491. *
  7492. * This is only usable inside `<script setup>`, is compiled away in the
  7493. * output and should **not** be actually called at runtime.
  7494. */
  7495. function defineExpose(exposed) {
  7496. if ((process.env.NODE_ENV !== 'production')) {
  7497. warnRuntimeUsage(`defineExpose`);
  7498. }
  7499. }
  7500. /**
  7501. * Vue `<script setup>` compiler macro for providing props default values when
  7502. * using type-based `defineProps` declaration.
  7503. *
  7504. * Example usage:
  7505. * ```ts
  7506. * withDefaults(defineProps<{
  7507. * size?: number
  7508. * labels?: string[]
  7509. * }>(), {
  7510. * size: 3,
  7511. * labels: () => ['default label']
  7512. * })
  7513. * ```
  7514. *
  7515. * This is only usable inside `<script setup>`, is compiled away in the output
  7516. * and should **not** be actually called at runtime.
  7517. */
  7518. function withDefaults(props, defaults) {
  7519. if ((process.env.NODE_ENV !== 'production')) {
  7520. warnRuntimeUsage(`withDefaults`);
  7521. }
  7522. return null;
  7523. }
  7524. function useSlots() {
  7525. return getContext().slots;
  7526. }
  7527. function useAttrs() {
  7528. return getContext().attrs;
  7529. }
  7530. function getContext() {
  7531. const i = getCurrentInstance();
  7532. if ((process.env.NODE_ENV !== 'production') && !i) {
  7533. warn(`useContext() called without active instance.`);
  7534. }
  7535. return i.setupContext || (i.setupContext = createSetupContext(i));
  7536. }
  7537. /**
  7538. * Runtime helper for merging default declarations. Imported by compiled code
  7539. * only.
  7540. * @internal
  7541. */
  7542. function mergeDefaults(raw, defaults) {
  7543. const props = isArray(raw)
  7544. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  7545. : raw;
  7546. for (const key in defaults) {
  7547. const opt = props[key];
  7548. if (opt) {
  7549. if (isArray(opt) || isFunction(opt)) {
  7550. props[key] = { type: opt, default: defaults[key] };
  7551. }
  7552. else {
  7553. opt.default = defaults[key];
  7554. }
  7555. }
  7556. else if (opt === null) {
  7557. props[key] = { default: defaults[key] };
  7558. }
  7559. else if ((process.env.NODE_ENV !== 'production')) {
  7560. warn(`props default key "${key}" has no corresponding declaration.`);
  7561. }
  7562. }
  7563. return props;
  7564. }
  7565. /**
  7566. * Used to create a proxy for the rest element when destructuring props with
  7567. * defineProps().
  7568. * @internal
  7569. */
  7570. function createPropsRestProxy(props, excludedKeys) {
  7571. const ret = {};
  7572. for (const key in props) {
  7573. if (!excludedKeys.includes(key)) {
  7574. Object.defineProperty(ret, key, {
  7575. enumerable: true,
  7576. get: () => props[key]
  7577. });
  7578. }
  7579. }
  7580. return ret;
  7581. }
  7582. /**
  7583. * `<script setup>` helper for persisting the current instance context over
  7584. * async/await flows.
  7585. *
  7586. * `@vue/compiler-sfc` converts the following:
  7587. *
  7588. * ```ts
  7589. * const x = await foo()
  7590. * ```
  7591. *
  7592. * into:
  7593. *
  7594. * ```ts
  7595. * let __temp, __restore
  7596. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  7597. * ```
  7598. * @internal
  7599. */
  7600. function withAsyncContext(getAwaitable) {
  7601. const ctx = getCurrentInstance();
  7602. if ((process.env.NODE_ENV !== 'production') && !ctx) {
  7603. warn(`withAsyncContext called without active current instance. ` +
  7604. `This is likely a bug.`);
  7605. }
  7606. let awaitable = getAwaitable();
  7607. unsetCurrentInstance();
  7608. if (isPromise(awaitable)) {
  7609. awaitable = awaitable.catch(e => {
  7610. setCurrentInstance(ctx);
  7611. throw e;
  7612. });
  7613. }
  7614. return [awaitable, () => setCurrentInstance(ctx)];
  7615. }
  7616. // Actual implementation
  7617. function h(type, propsOrChildren, children) {
  7618. const l = arguments.length;
  7619. if (l === 2) {
  7620. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  7621. // single vnode without props
  7622. if (isVNode(propsOrChildren)) {
  7623. return createVNode(type, null, [propsOrChildren]);
  7624. }
  7625. // props without children
  7626. return createVNode(type, propsOrChildren);
  7627. }
  7628. else {
  7629. // omit props
  7630. return createVNode(type, null, propsOrChildren);
  7631. }
  7632. }
  7633. else {
  7634. if (l > 3) {
  7635. children = Array.prototype.slice.call(arguments, 2);
  7636. }
  7637. else if (l === 3 && isVNode(children)) {
  7638. children = [children];
  7639. }
  7640. return createVNode(type, propsOrChildren, children);
  7641. }
  7642. }
  7643. const ssrContextKey = Symbol((process.env.NODE_ENV !== 'production') ? `ssrContext` : ``);
  7644. const useSSRContext = () => {
  7645. {
  7646. const ctx = inject(ssrContextKey);
  7647. if (!ctx) {
  7648. (process.env.NODE_ENV !== 'production') &&
  7649. warn(`Server rendering context not provided. Make sure to only call ` +
  7650. `useSSRContext() conditionally in the server build.`);
  7651. }
  7652. return ctx;
  7653. }
  7654. };
  7655. function isShallow(value) {
  7656. return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
  7657. }
  7658. function initCustomFormatter() {
  7659. /* eslint-disable no-restricted-globals */
  7660. if (!(process.env.NODE_ENV !== 'production') || typeof window === 'undefined') {
  7661. return;
  7662. }
  7663. const vueStyle = { style: 'color:#3ba776' };
  7664. const numberStyle = { style: 'color:#0b1bc9' };
  7665. const stringStyle = { style: 'color:#b62e24' };
  7666. const keywordStyle = { style: 'color:#9d288c' };
  7667. // custom formatter for Chrome
  7668. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  7669. const formatter = {
  7670. header(obj) {
  7671. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  7672. if (!isObject(obj)) {
  7673. return null;
  7674. }
  7675. if (obj.__isVue) {
  7676. return ['div', vueStyle, `VueInstance`];
  7677. }
  7678. else if (isRef(obj)) {
  7679. return [
  7680. 'div',
  7681. {},
  7682. ['span', vueStyle, genRefFlag(obj)],
  7683. '<',
  7684. formatValue(obj.value),
  7685. `>`
  7686. ];
  7687. }
  7688. else if (isReactive(obj)) {
  7689. return [
  7690. 'div',
  7691. {},
  7692. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  7693. '<',
  7694. formatValue(obj),
  7695. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  7696. ];
  7697. }
  7698. else if (isReadonly(obj)) {
  7699. return [
  7700. 'div',
  7701. {},
  7702. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  7703. '<',
  7704. formatValue(obj),
  7705. '>'
  7706. ];
  7707. }
  7708. return null;
  7709. },
  7710. hasBody(obj) {
  7711. return obj && obj.__isVue;
  7712. },
  7713. body(obj) {
  7714. if (obj && obj.__isVue) {
  7715. return [
  7716. 'div',
  7717. {},
  7718. ...formatInstance(obj.$)
  7719. ];
  7720. }
  7721. }
  7722. };
  7723. function formatInstance(instance) {
  7724. const blocks = [];
  7725. if (instance.type.props && instance.props) {
  7726. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  7727. }
  7728. if (instance.setupState !== EMPTY_OBJ) {
  7729. blocks.push(createInstanceBlock('setup', instance.setupState));
  7730. }
  7731. if (instance.data !== EMPTY_OBJ) {
  7732. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  7733. }
  7734. const computed = extractKeys(instance, 'computed');
  7735. if (computed) {
  7736. blocks.push(createInstanceBlock('computed', computed));
  7737. }
  7738. const injected = extractKeys(instance, 'inject');
  7739. if (injected) {
  7740. blocks.push(createInstanceBlock('injected', injected));
  7741. }
  7742. blocks.push([
  7743. 'div',
  7744. {},
  7745. [
  7746. 'span',
  7747. {
  7748. style: keywordStyle.style + ';opacity:0.66'
  7749. },
  7750. '$ (internal): '
  7751. ],
  7752. ['object', { object: instance }]
  7753. ]);
  7754. return blocks;
  7755. }
  7756. function createInstanceBlock(type, target) {
  7757. target = extend({}, target);
  7758. if (!Object.keys(target).length) {
  7759. return ['span', {}];
  7760. }
  7761. return [
  7762. 'div',
  7763. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  7764. [
  7765. 'div',
  7766. {
  7767. style: 'color:#476582'
  7768. },
  7769. type
  7770. ],
  7771. [
  7772. 'div',
  7773. {
  7774. style: 'padding-left:1.25em'
  7775. },
  7776. ...Object.keys(target).map(key => {
  7777. return [
  7778. 'div',
  7779. {},
  7780. ['span', keywordStyle, key + ': '],
  7781. formatValue(target[key], false)
  7782. ];
  7783. })
  7784. ]
  7785. ];
  7786. }
  7787. function formatValue(v, asRaw = true) {
  7788. if (typeof v === 'number') {
  7789. return ['span', numberStyle, v];
  7790. }
  7791. else if (typeof v === 'string') {
  7792. return ['span', stringStyle, JSON.stringify(v)];
  7793. }
  7794. else if (typeof v === 'boolean') {
  7795. return ['span', keywordStyle, v];
  7796. }
  7797. else if (isObject(v)) {
  7798. return ['object', { object: asRaw ? toRaw(v) : v }];
  7799. }
  7800. else {
  7801. return ['span', stringStyle, String(v)];
  7802. }
  7803. }
  7804. function extractKeys(instance, type) {
  7805. const Comp = instance.type;
  7806. if (isFunction(Comp)) {
  7807. return;
  7808. }
  7809. const extracted = {};
  7810. for (const key in instance.ctx) {
  7811. if (isKeyOfType(Comp, key, type)) {
  7812. extracted[key] = instance.ctx[key];
  7813. }
  7814. }
  7815. return extracted;
  7816. }
  7817. function isKeyOfType(Comp, key, type) {
  7818. const opts = Comp[type];
  7819. if ((isArray(opts) && opts.includes(key)) ||
  7820. (isObject(opts) && key in opts)) {
  7821. return true;
  7822. }
  7823. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  7824. return true;
  7825. }
  7826. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  7827. return true;
  7828. }
  7829. }
  7830. function genRefFlag(v) {
  7831. if (isShallow(v)) {
  7832. return `ShallowRef`;
  7833. }
  7834. if (v.effect) {
  7835. return `ComputedRef`;
  7836. }
  7837. return `Ref`;
  7838. }
  7839. if (window.devtoolsFormatters) {
  7840. window.devtoolsFormatters.push(formatter);
  7841. }
  7842. else {
  7843. window.devtoolsFormatters = [formatter];
  7844. }
  7845. }
  7846. function withMemo(memo, render, cache, index) {
  7847. const cached = cache[index];
  7848. if (cached && isMemoSame(cached, memo)) {
  7849. return cached;
  7850. }
  7851. const ret = render();
  7852. // shallow clone
  7853. ret.memo = memo.slice();
  7854. return (cache[index] = ret);
  7855. }
  7856. function isMemoSame(cached, memo) {
  7857. const prev = cached.memo;
  7858. if (prev.length != memo.length) {
  7859. return false;
  7860. }
  7861. for (let i = 0; i < prev.length; i++) {
  7862. if (hasChanged(prev[i], memo[i])) {
  7863. return false;
  7864. }
  7865. }
  7866. // make sure to let parent block track it when returning cached
  7867. if (isBlockTreeEnabled > 0 && currentBlock) {
  7868. currentBlock.push(cached);
  7869. }
  7870. return true;
  7871. }
  7872. // Core API ------------------------------------------------------------------
  7873. const version = "3.2.45";
  7874. const _ssrUtils = {
  7875. createComponentInstance,
  7876. setupComponent,
  7877. renderComponentRoot,
  7878. setCurrentRenderingInstance,
  7879. isVNode,
  7880. normalizeVNode
  7881. };
  7882. /**
  7883. * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
  7884. * @internal
  7885. */
  7886. const ssrUtils = (_ssrUtils );
  7887. /**
  7888. * @internal only exposed in compat builds
  7889. */
  7890. const resolveFilter = null;
  7891. /**
  7892. * @internal only exposed in compat builds.
  7893. */
  7894. const compatUtils = (null);
  7895. export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compatUtils, computed, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSlots, createStaticVNode, createTextVNode, createVNode, defineAsyncComponent, defineComponent, defineEmits, defineExpose, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, guardReactiveProps, h, handleError, initCustomFormatter, inject, isMemoSame, isRuntimeOnly, isVNode, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, pushScopeId, queuePostFlushCb, registerRuntimeCompiler, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, ssrContextKey, ssrUtils, toHandlers, transformVNodeArgs, useAttrs, useSSRContext, useSlots, useTransitionState, version, warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withMemo, withScopeId };