runtime-core.cjs.prod.js 237 KB

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