vue.runtime.esm-browser.js 334 KB

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