runtime-core.cjs.js 296 KB

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