runtime-core.esm-bundler.js 300 KB

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