runtime-core.esm-bundler.js 266 KB

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