vue.runtime.esm-browser.js 389 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795
  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. /**
  34. * Boolean attributes should be included if the value is truthy or ''.
  35. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  36. */
  37. function includeBooleanAttr(value) {
  38. return !!value || value === '';
  39. }
  40. function normalizeStyle(value) {
  41. if (isArray(value)) {
  42. const res = {};
  43. for (let i = 0; i < value.length; i++) {
  44. const item = value[i];
  45. const normalized = isString(item)
  46. ? parseStringStyle(item)
  47. : normalizeStyle(item);
  48. if (normalized) {
  49. for (const key in normalized) {
  50. res[key] = normalized[key];
  51. }
  52. }
  53. }
  54. return res;
  55. }
  56. else if (isString(value)) {
  57. return value;
  58. }
  59. else if (isObject(value)) {
  60. return value;
  61. }
  62. }
  63. const listDelimiterRE = /;(?![^(]*\))/g;
  64. const propertyDelimiterRE = /:(.+)/;
  65. function parseStringStyle(cssText) {
  66. const ret = {};
  67. cssText.split(listDelimiterRE).forEach(item => {
  68. if (item) {
  69. const tmp = item.split(propertyDelimiterRE);
  70. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  71. }
  72. });
  73. return ret;
  74. }
  75. function normalizeClass(value) {
  76. let res = '';
  77. if (isString(value)) {
  78. res = value;
  79. }
  80. else if (isArray(value)) {
  81. for (let i = 0; i < value.length; i++) {
  82. const normalized = normalizeClass(value[i]);
  83. if (normalized) {
  84. res += normalized + ' ';
  85. }
  86. }
  87. }
  88. else if (isObject(value)) {
  89. for (const name in value) {
  90. if (value[name]) {
  91. res += name + ' ';
  92. }
  93. }
  94. }
  95. return res.trim();
  96. }
  97. function normalizeProps(props) {
  98. if (!props)
  99. return null;
  100. let { class: klass, style } = props;
  101. if (klass && !isString(klass)) {
  102. props.class = normalizeClass(klass);
  103. }
  104. if (style) {
  105. props.style = normalizeStyle(style);
  106. }
  107. return props;
  108. }
  109. // These tag configs are shared between compiler-dom and runtime-dom, so they
  110. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  111. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  112. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  113. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  114. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  115. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  116. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  117. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  118. 'option,output,progress,select,textarea,details,dialog,menu,' +
  119. 'summary,template,blockquote,iframe,tfoot';
  120. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  121. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  122. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  123. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  124. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  125. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  126. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  127. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  128. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  129. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  130. 'text,textPath,title,tspan,unknown,use,view';
  131. /**
  132. * Compiler only.
  133. * Do NOT use in runtime code paths unless behind `true` flag.
  134. */
  135. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  136. /**
  137. * Compiler only.
  138. * Do NOT use in runtime code paths unless behind `true` flag.
  139. */
  140. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  141. function looseCompareArrays(a, b) {
  142. if (a.length !== b.length)
  143. return false;
  144. let equal = true;
  145. for (let i = 0; equal && i < a.length; i++) {
  146. equal = looseEqual(a[i], b[i]);
  147. }
  148. return equal;
  149. }
  150. function looseEqual(a, b) {
  151. if (a === b)
  152. return true;
  153. let aValidType = isDate(a);
  154. let bValidType = isDate(b);
  155. if (aValidType || bValidType) {
  156. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  157. }
  158. aValidType = isArray(a);
  159. bValidType = isArray(b);
  160. if (aValidType || bValidType) {
  161. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  162. }
  163. aValidType = isObject(a);
  164. bValidType = isObject(b);
  165. if (aValidType || bValidType) {
  166. /* istanbul ignore if: this if will probably never be called */
  167. if (!aValidType || !bValidType) {
  168. return false;
  169. }
  170. const aKeysCount = Object.keys(a).length;
  171. const bKeysCount = Object.keys(b).length;
  172. if (aKeysCount !== bKeysCount) {
  173. return false;
  174. }
  175. for (const key in a) {
  176. const aHasKey = a.hasOwnProperty(key);
  177. const bHasKey = b.hasOwnProperty(key);
  178. if ((aHasKey && !bHasKey) ||
  179. (!aHasKey && bHasKey) ||
  180. !looseEqual(a[key], b[key])) {
  181. return false;
  182. }
  183. }
  184. }
  185. return String(a) === String(b);
  186. }
  187. function looseIndexOf(arr, val) {
  188. return arr.findIndex(item => looseEqual(item, val));
  189. }
  190. /**
  191. * For converting {{ interpolation }} values to displayed strings.
  192. * @private
  193. */
  194. const toDisplayString = (val) => {
  195. return isString(val)
  196. ? val
  197. : val == null
  198. ? ''
  199. : isArray(val) ||
  200. (isObject(val) &&
  201. (val.toString === objectToString || !isFunction(val.toString)))
  202. ? JSON.stringify(val, replacer, 2)
  203. : String(val);
  204. };
  205. const replacer = (_key, val) => {
  206. // can't use isRef here since @vue/shared has no deps
  207. if (val && val.__v_isRef) {
  208. return replacer(_key, val.value);
  209. }
  210. else if (isMap(val)) {
  211. return {
  212. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  213. entries[`${key} =>`] = val;
  214. return entries;
  215. }, {})
  216. };
  217. }
  218. else if (isSet(val)) {
  219. return {
  220. [`Set(${val.size})`]: [...val.values()]
  221. };
  222. }
  223. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  224. return String(val);
  225. }
  226. return val;
  227. };
  228. const EMPTY_OBJ = Object.freeze({})
  229. ;
  230. const EMPTY_ARR = Object.freeze([]) ;
  231. const NOOP = () => { };
  232. /**
  233. * Always return false.
  234. */
  235. const NO = () => false;
  236. const onRE = /^on[^a-z]/;
  237. const isOn = (key) => onRE.test(key);
  238. const isModelListener = (key) => key.startsWith('onUpdate:');
  239. const extend = Object.assign;
  240. const remove = (arr, el) => {
  241. const i = arr.indexOf(el);
  242. if (i > -1) {
  243. arr.splice(i, 1);
  244. }
  245. };
  246. const hasOwnProperty = Object.prototype.hasOwnProperty;
  247. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  248. const isArray = Array.isArray;
  249. const isMap = (val) => toTypeString(val) === '[object Map]';
  250. const isSet = (val) => toTypeString(val) === '[object Set]';
  251. const isDate = (val) => val instanceof Date;
  252. const isFunction = (val) => typeof val === 'function';
  253. const isString = (val) => typeof val === 'string';
  254. const isSymbol = (val) => typeof val === 'symbol';
  255. const isObject = (val) => val !== null && typeof val === 'object';
  256. const isPromise = (val) => {
  257. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  258. };
  259. const objectToString = Object.prototype.toString;
  260. const toTypeString = (value) => objectToString.call(value);
  261. const toRawType = (value) => {
  262. // extract "RawType" from strings like "[object RawType]"
  263. return toTypeString(value).slice(8, -1);
  264. };
  265. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  266. const isIntegerKey = (key) => isString(key) &&
  267. key !== 'NaN' &&
  268. key[0] !== '-' &&
  269. '' + parseInt(key, 10) === key;
  270. const isReservedProp = /*#__PURE__*/ makeMap(
  271. // the leading comma is intentional so empty string "" is also included
  272. ',key,ref,ref_for,ref_key,' +
  273. 'onVnodeBeforeMount,onVnodeMounted,' +
  274. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  275. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  276. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  277. const cacheStringFunction = (fn) => {
  278. const cache = Object.create(null);
  279. return ((str) => {
  280. const hit = cache[str];
  281. return hit || (cache[str] = fn(str));
  282. });
  283. };
  284. const camelizeRE = /-(\w)/g;
  285. /**
  286. * @private
  287. */
  288. const camelize = cacheStringFunction((str) => {
  289. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  290. });
  291. const hyphenateRE = /\B([A-Z])/g;
  292. /**
  293. * @private
  294. */
  295. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  296. /**
  297. * @private
  298. */
  299. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  300. /**
  301. * @private
  302. */
  303. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  304. // compare whether a value has changed, accounting for NaN.
  305. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  306. const invokeArrayFns = (fns, arg) => {
  307. for (let i = 0; i < fns.length; i++) {
  308. fns[i](arg);
  309. }
  310. };
  311. const def = (obj, key, value) => {
  312. Object.defineProperty(obj, key, {
  313. configurable: true,
  314. enumerable: false,
  315. value
  316. });
  317. };
  318. const toNumber = (val) => {
  319. const n = parseFloat(val);
  320. return isNaN(n) ? val : n;
  321. };
  322. let _globalThis;
  323. const getGlobalThis = () => {
  324. return (_globalThis ||
  325. (_globalThis =
  326. typeof globalThis !== 'undefined'
  327. ? globalThis
  328. : typeof self !== 'undefined'
  329. ? self
  330. : typeof window !== 'undefined'
  331. ? window
  332. : typeof global !== 'undefined'
  333. ? global
  334. : {}));
  335. };
  336. function warn(msg, ...args) {
  337. console.warn(`[Vue warn] ${msg}`, ...args);
  338. }
  339. let activeEffectScope;
  340. class EffectScope {
  341. constructor(detached = false) {
  342. /**
  343. * @internal
  344. */
  345. this.active = true;
  346. /**
  347. * @internal
  348. */
  349. this.effects = [];
  350. /**
  351. * @internal
  352. */
  353. this.cleanups = [];
  354. if (!detached && activeEffectScope) {
  355. this.parent = activeEffectScope;
  356. this.index =
  357. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  358. }
  359. }
  360. run(fn) {
  361. if (this.active) {
  362. const currentEffectScope = activeEffectScope;
  363. try {
  364. activeEffectScope = this;
  365. return fn();
  366. }
  367. finally {
  368. activeEffectScope = currentEffectScope;
  369. }
  370. }
  371. else {
  372. warn(`cannot run an inactive effect scope.`);
  373. }
  374. }
  375. /**
  376. * This should only be called on non-detached scopes
  377. * @internal
  378. */
  379. on() {
  380. activeEffectScope = this;
  381. }
  382. /**
  383. * This should only be called on non-detached scopes
  384. * @internal
  385. */
  386. off() {
  387. activeEffectScope = this.parent;
  388. }
  389. stop(fromParent) {
  390. if (this.active) {
  391. let i, l;
  392. for (i = 0, l = this.effects.length; i < l; i++) {
  393. this.effects[i].stop();
  394. }
  395. for (i = 0, l = this.cleanups.length; i < l; i++) {
  396. this.cleanups[i]();
  397. }
  398. if (this.scopes) {
  399. for (i = 0, l = this.scopes.length; i < l; i++) {
  400. this.scopes[i].stop(true);
  401. }
  402. }
  403. // nested scope, dereference from parent to avoid memory leaks
  404. if (this.parent && !fromParent) {
  405. // optimized O(1) removal
  406. const last = this.parent.scopes.pop();
  407. if (last && last !== this) {
  408. this.parent.scopes[this.index] = last;
  409. last.index = this.index;
  410. }
  411. }
  412. this.active = false;
  413. }
  414. }
  415. }
  416. function effectScope(detached) {
  417. return new EffectScope(detached);
  418. }
  419. function recordEffectScope(effect, scope = activeEffectScope) {
  420. if (scope && scope.active) {
  421. scope.effects.push(effect);
  422. }
  423. }
  424. function getCurrentScope() {
  425. return activeEffectScope;
  426. }
  427. function onScopeDispose(fn) {
  428. if (activeEffectScope) {
  429. activeEffectScope.cleanups.push(fn);
  430. }
  431. else {
  432. warn(`onScopeDispose() is called when there is no active effect scope` +
  433. ` to be associated with.`);
  434. }
  435. }
  436. const createDep = (effects) => {
  437. const dep = new Set(effects);
  438. dep.w = 0;
  439. dep.n = 0;
  440. return dep;
  441. };
  442. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  443. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  444. const initDepMarkers = ({ deps }) => {
  445. if (deps.length) {
  446. for (let i = 0; i < deps.length; i++) {
  447. deps[i].w |= trackOpBit; // set was tracked
  448. }
  449. }
  450. };
  451. const finalizeDepMarkers = (effect) => {
  452. const { deps } = effect;
  453. if (deps.length) {
  454. let ptr = 0;
  455. for (let i = 0; i < deps.length; i++) {
  456. const dep = deps[i];
  457. if (wasTracked(dep) && !newTracked(dep)) {
  458. dep.delete(effect);
  459. }
  460. else {
  461. deps[ptr++] = dep;
  462. }
  463. // clear bits
  464. dep.w &= ~trackOpBit;
  465. dep.n &= ~trackOpBit;
  466. }
  467. deps.length = ptr;
  468. }
  469. };
  470. const targetMap = new WeakMap();
  471. // The number of effects currently being tracked recursively.
  472. let effectTrackDepth = 0;
  473. let trackOpBit = 1;
  474. /**
  475. * The bitwise track markers support at most 30 levels of recursion.
  476. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  477. * When recursion depth is greater, fall back to using a full cleanup.
  478. */
  479. const maxMarkerBits = 30;
  480. let activeEffect;
  481. const ITERATE_KEY = Symbol('iterate' );
  482. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  483. class ReactiveEffect {
  484. constructor(fn, scheduler = null, scope) {
  485. this.fn = fn;
  486. this.scheduler = scheduler;
  487. this.active = true;
  488. this.deps = [];
  489. this.parent = undefined;
  490. recordEffectScope(this, scope);
  491. }
  492. run() {
  493. if (!this.active) {
  494. return this.fn();
  495. }
  496. let parent = activeEffect;
  497. let lastShouldTrack = shouldTrack;
  498. while (parent) {
  499. if (parent === this) {
  500. return;
  501. }
  502. parent = parent.parent;
  503. }
  504. try {
  505. this.parent = activeEffect;
  506. activeEffect = this;
  507. shouldTrack = true;
  508. trackOpBit = 1 << ++effectTrackDepth;
  509. if (effectTrackDepth <= maxMarkerBits) {
  510. initDepMarkers(this);
  511. }
  512. else {
  513. cleanupEffect(this);
  514. }
  515. return this.fn();
  516. }
  517. finally {
  518. if (effectTrackDepth <= maxMarkerBits) {
  519. finalizeDepMarkers(this);
  520. }
  521. trackOpBit = 1 << --effectTrackDepth;
  522. activeEffect = this.parent;
  523. shouldTrack = lastShouldTrack;
  524. this.parent = undefined;
  525. if (this.deferStop) {
  526. this.stop();
  527. }
  528. }
  529. }
  530. stop() {
  531. // stopped while running itself - defer the cleanup
  532. if (activeEffect === this) {
  533. this.deferStop = true;
  534. }
  535. else if (this.active) {
  536. cleanupEffect(this);
  537. if (this.onStop) {
  538. this.onStop();
  539. }
  540. this.active = false;
  541. }
  542. }
  543. }
  544. function cleanupEffect(effect) {
  545. const { deps } = effect;
  546. if (deps.length) {
  547. for (let i = 0; i < deps.length; i++) {
  548. deps[i].delete(effect);
  549. }
  550. deps.length = 0;
  551. }
  552. }
  553. function effect(fn, options) {
  554. if (fn.effect) {
  555. fn = fn.effect.fn;
  556. }
  557. const _effect = new ReactiveEffect(fn);
  558. if (options) {
  559. extend(_effect, options);
  560. if (options.scope)
  561. recordEffectScope(_effect, options.scope);
  562. }
  563. if (!options || !options.lazy) {
  564. _effect.run();
  565. }
  566. const runner = _effect.run.bind(_effect);
  567. runner.effect = _effect;
  568. return runner;
  569. }
  570. function stop(runner) {
  571. runner.effect.stop();
  572. }
  573. let shouldTrack = true;
  574. const trackStack = [];
  575. function pauseTracking() {
  576. trackStack.push(shouldTrack);
  577. shouldTrack = false;
  578. }
  579. function resetTracking() {
  580. const last = trackStack.pop();
  581. shouldTrack = last === undefined ? true : last;
  582. }
  583. function track(target, type, key) {
  584. if (shouldTrack && activeEffect) {
  585. let depsMap = targetMap.get(target);
  586. if (!depsMap) {
  587. targetMap.set(target, (depsMap = new Map()));
  588. }
  589. let dep = depsMap.get(key);
  590. if (!dep) {
  591. depsMap.set(key, (dep = createDep()));
  592. }
  593. const eventInfo = { effect: activeEffect, target, type, key }
  594. ;
  595. trackEffects(dep, eventInfo);
  596. }
  597. }
  598. function trackEffects(dep, debuggerEventExtraInfo) {
  599. let shouldTrack = false;
  600. if (effectTrackDepth <= maxMarkerBits) {
  601. if (!newTracked(dep)) {
  602. dep.n |= trackOpBit; // set newly tracked
  603. shouldTrack = !wasTracked(dep);
  604. }
  605. }
  606. else {
  607. // Full cleanup mode.
  608. shouldTrack = !dep.has(activeEffect);
  609. }
  610. if (shouldTrack) {
  611. dep.add(activeEffect);
  612. activeEffect.deps.push(dep);
  613. if (activeEffect.onTrack) {
  614. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  615. }
  616. }
  617. }
  618. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  619. const depsMap = targetMap.get(target);
  620. if (!depsMap) {
  621. // never been tracked
  622. return;
  623. }
  624. let deps = [];
  625. if (type === "clear" /* CLEAR */) {
  626. // collection being cleared
  627. // trigger all effects for target
  628. deps = [...depsMap.values()];
  629. }
  630. else if (key === 'length' && isArray(target)) {
  631. depsMap.forEach((dep, key) => {
  632. if (key === 'length' || key >= newValue) {
  633. deps.push(dep);
  634. }
  635. });
  636. }
  637. else {
  638. // schedule runs for SET | ADD | DELETE
  639. if (key !== void 0) {
  640. deps.push(depsMap.get(key));
  641. }
  642. // also run for iteration key on ADD | DELETE | Map.SET
  643. switch (type) {
  644. case "add" /* ADD */:
  645. if (!isArray(target)) {
  646. deps.push(depsMap.get(ITERATE_KEY));
  647. if (isMap(target)) {
  648. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  649. }
  650. }
  651. else if (isIntegerKey(key)) {
  652. // new index added to array -> length changes
  653. deps.push(depsMap.get('length'));
  654. }
  655. break;
  656. case "delete" /* DELETE */:
  657. if (!isArray(target)) {
  658. deps.push(depsMap.get(ITERATE_KEY));
  659. if (isMap(target)) {
  660. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  661. }
  662. }
  663. break;
  664. case "set" /* SET */:
  665. if (isMap(target)) {
  666. deps.push(depsMap.get(ITERATE_KEY));
  667. }
  668. break;
  669. }
  670. }
  671. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  672. ;
  673. if (deps.length === 1) {
  674. if (deps[0]) {
  675. {
  676. triggerEffects(deps[0], eventInfo);
  677. }
  678. }
  679. }
  680. else {
  681. const effects = [];
  682. for (const dep of deps) {
  683. if (dep) {
  684. effects.push(...dep);
  685. }
  686. }
  687. {
  688. triggerEffects(createDep(effects), eventInfo);
  689. }
  690. }
  691. }
  692. function triggerEffects(dep, debuggerEventExtraInfo) {
  693. // spread into array for stabilization
  694. for (const effect of isArray(dep) ? dep : [...dep]) {
  695. if (effect !== activeEffect || effect.allowRecurse) {
  696. if (effect.onTrigger) {
  697. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  698. }
  699. if (effect.scheduler) {
  700. effect.scheduler();
  701. }
  702. else {
  703. effect.run();
  704. }
  705. }
  706. }
  707. }
  708. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  709. const builtInSymbols = new Set(
  710. /*#__PURE__*/
  711. Object.getOwnPropertyNames(Symbol)
  712. .map(key => Symbol[key])
  713. .filter(isSymbol));
  714. const get = /*#__PURE__*/ createGetter();
  715. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  716. const readonlyGet = /*#__PURE__*/ createGetter(true);
  717. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  718. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  719. function createArrayInstrumentations() {
  720. const instrumentations = {};
  721. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  722. instrumentations[key] = function (...args) {
  723. const arr = toRaw(this);
  724. for (let i = 0, l = this.length; i < l; i++) {
  725. track(arr, "get" /* GET */, i + '');
  726. }
  727. // we run the method using the original args first (which may be reactive)
  728. const res = arr[key](...args);
  729. if (res === -1 || res === false) {
  730. // if that didn't work, run it again using raw values.
  731. return arr[key](...args.map(toRaw));
  732. }
  733. else {
  734. return res;
  735. }
  736. };
  737. });
  738. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  739. instrumentations[key] = function (...args) {
  740. pauseTracking();
  741. const res = toRaw(this)[key].apply(this, args);
  742. resetTracking();
  743. return res;
  744. };
  745. });
  746. return instrumentations;
  747. }
  748. function createGetter(isReadonly = false, shallow = false) {
  749. return function get(target, key, receiver) {
  750. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  751. return !isReadonly;
  752. }
  753. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  754. return isReadonly;
  755. }
  756. else if (key === "__v_isShallow" /* IS_SHALLOW */) {
  757. return shallow;
  758. }
  759. else if (key === "__v_raw" /* RAW */ &&
  760. receiver ===
  761. (isReadonly
  762. ? shallow
  763. ? shallowReadonlyMap
  764. : readonlyMap
  765. : shallow
  766. ? shallowReactiveMap
  767. : reactiveMap).get(target)) {
  768. return target;
  769. }
  770. const targetIsArray = isArray(target);
  771. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  772. return Reflect.get(arrayInstrumentations, key, receiver);
  773. }
  774. const res = Reflect.get(target, key, receiver);
  775. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  776. return res;
  777. }
  778. if (!isReadonly) {
  779. track(target, "get" /* GET */, key);
  780. }
  781. if (shallow) {
  782. return res;
  783. }
  784. if (isRef(res)) {
  785. // ref unwrapping - does not apply for Array + integer key.
  786. const shouldUnwrap = !targetIsArray || !isIntegerKey(key);
  787. return shouldUnwrap ? res.value : res;
  788. }
  789. if (isObject(res)) {
  790. // Convert returned value into a proxy as well. we do the isObject check
  791. // here to avoid invalid value warning. Also need to lazy access readonly
  792. // and reactive here to avoid circular dependency.
  793. return isReadonly ? readonly(res) : reactive(res);
  794. }
  795. return res;
  796. };
  797. }
  798. const set = /*#__PURE__*/ createSetter();
  799. const shallowSet = /*#__PURE__*/ createSetter(true);
  800. function createSetter(shallow = false) {
  801. return function set(target, key, value, receiver) {
  802. let oldValue = target[key];
  803. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  804. return false;
  805. }
  806. if (!shallow && !isReadonly(value)) {
  807. if (!isShallow(value)) {
  808. value = toRaw(value);
  809. oldValue = toRaw(oldValue);
  810. }
  811. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  812. oldValue.value = value;
  813. return true;
  814. }
  815. }
  816. const hadKey = isArray(target) && isIntegerKey(key)
  817. ? Number(key) < target.length
  818. : hasOwn(target, key);
  819. const result = Reflect.set(target, key, value, receiver);
  820. // don't trigger if target is something up in the prototype chain of original
  821. if (target === toRaw(receiver)) {
  822. if (!hadKey) {
  823. trigger(target, "add" /* ADD */, key, value);
  824. }
  825. else if (hasChanged(value, oldValue)) {
  826. trigger(target, "set" /* SET */, key, value, oldValue);
  827. }
  828. }
  829. return result;
  830. };
  831. }
  832. function deleteProperty(target, key) {
  833. const hadKey = hasOwn(target, key);
  834. const oldValue = target[key];
  835. const result = Reflect.deleteProperty(target, key);
  836. if (result && hadKey) {
  837. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  838. }
  839. return result;
  840. }
  841. function has(target, key) {
  842. const result = Reflect.has(target, key);
  843. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  844. track(target, "has" /* HAS */, key);
  845. }
  846. return result;
  847. }
  848. function ownKeys(target) {
  849. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  850. return Reflect.ownKeys(target);
  851. }
  852. const mutableHandlers = {
  853. get,
  854. set,
  855. deleteProperty,
  856. has,
  857. ownKeys
  858. };
  859. const readonlyHandlers = {
  860. get: readonlyGet,
  861. set(target, key) {
  862. {
  863. warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  864. }
  865. return true;
  866. },
  867. deleteProperty(target, key) {
  868. {
  869. warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  870. }
  871. return true;
  872. }
  873. };
  874. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  875. get: shallowGet,
  876. set: shallowSet
  877. });
  878. // Props handlers are special in the sense that it should not unwrap top-level
  879. // refs (in order to allow refs to be explicitly passed down), but should
  880. // retain the reactivity of the normal readonly object.
  881. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  882. get: shallowReadonlyGet
  883. });
  884. const toShallow = (value) => value;
  885. const getProto = (v) => Reflect.getPrototypeOf(v);
  886. function get$1(target, key, isReadonly = false, isShallow = false) {
  887. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  888. // of the value
  889. target = target["__v_raw" /* RAW */];
  890. const rawTarget = toRaw(target);
  891. const rawKey = toRaw(key);
  892. if (key !== rawKey) {
  893. !isReadonly && track(rawTarget, "get" /* GET */, key);
  894. }
  895. !isReadonly && track(rawTarget, "get" /* GET */, rawKey);
  896. const { has } = getProto(rawTarget);
  897. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  898. if (has.call(rawTarget, key)) {
  899. return wrap(target.get(key));
  900. }
  901. else if (has.call(rawTarget, rawKey)) {
  902. return wrap(target.get(rawKey));
  903. }
  904. else if (target !== rawTarget) {
  905. // #3602 readonly(reactive(Map))
  906. // ensure that the nested reactive `Map` can do tracking for itself
  907. target.get(key);
  908. }
  909. }
  910. function has$1(key, isReadonly = false) {
  911. const target = this["__v_raw" /* RAW */];
  912. const rawTarget = toRaw(target);
  913. const rawKey = toRaw(key);
  914. if (key !== rawKey) {
  915. !isReadonly && track(rawTarget, "has" /* HAS */, key);
  916. }
  917. !isReadonly && track(rawTarget, "has" /* HAS */, rawKey);
  918. return key === rawKey
  919. ? target.has(key)
  920. : target.has(key) || target.has(rawKey);
  921. }
  922. function size(target, isReadonly = false) {
  923. target = target["__v_raw" /* RAW */];
  924. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  925. return Reflect.get(target, 'size', target);
  926. }
  927. function add(value) {
  928. value = toRaw(value);
  929. const target = toRaw(this);
  930. const proto = getProto(target);
  931. const hadKey = proto.has.call(target, value);
  932. if (!hadKey) {
  933. target.add(value);
  934. trigger(target, "add" /* ADD */, value, value);
  935. }
  936. return this;
  937. }
  938. function set$1(key, value) {
  939. value = toRaw(value);
  940. const target = toRaw(this);
  941. const { has, get } = getProto(target);
  942. let hadKey = has.call(target, key);
  943. if (!hadKey) {
  944. key = toRaw(key);
  945. hadKey = has.call(target, key);
  946. }
  947. else {
  948. checkIdentityKeys(target, has, key);
  949. }
  950. const oldValue = get.call(target, key);
  951. target.set(key, value);
  952. if (!hadKey) {
  953. trigger(target, "add" /* ADD */, key, value);
  954. }
  955. else if (hasChanged(value, oldValue)) {
  956. trigger(target, "set" /* SET */, key, value, oldValue);
  957. }
  958. return this;
  959. }
  960. function deleteEntry(key) {
  961. const target = toRaw(this);
  962. const { has, get } = getProto(target);
  963. let hadKey = has.call(target, key);
  964. if (!hadKey) {
  965. key = toRaw(key);
  966. hadKey = has.call(target, key);
  967. }
  968. else {
  969. checkIdentityKeys(target, has, key);
  970. }
  971. const oldValue = get ? get.call(target, key) : undefined;
  972. // forward the operation before queueing reactions
  973. const result = target.delete(key);
  974. if (hadKey) {
  975. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  976. }
  977. return result;
  978. }
  979. function clear() {
  980. const target = toRaw(this);
  981. const hadItems = target.size !== 0;
  982. const oldTarget = isMap(target)
  983. ? new Map(target)
  984. : new Set(target)
  985. ;
  986. // forward the operation before queueing reactions
  987. const result = target.clear();
  988. if (hadItems) {
  989. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  990. }
  991. return result;
  992. }
  993. function createForEach(isReadonly, isShallow) {
  994. return function forEach(callback, thisArg) {
  995. const observed = this;
  996. const target = observed["__v_raw" /* RAW */];
  997. const rawTarget = toRaw(target);
  998. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  999. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  1000. return target.forEach((value, key) => {
  1001. // important: make sure the callback is
  1002. // 1. invoked with the reactive map as `this` and 3rd arg
  1003. // 2. the value received should be a corresponding reactive/readonly.
  1004. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1005. });
  1006. };
  1007. }
  1008. function createIterableMethod(method, isReadonly, isShallow) {
  1009. return function (...args) {
  1010. const target = this["__v_raw" /* RAW */];
  1011. const rawTarget = toRaw(target);
  1012. const targetIsMap = isMap(rawTarget);
  1013. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1014. const isKeyOnly = method === 'keys' && targetIsMap;
  1015. const innerIterator = target[method](...args);
  1016. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1017. !isReadonly &&
  1018. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1019. // return a wrapped iterator which returns observed versions of the
  1020. // values emitted from the real iterator
  1021. return {
  1022. // iterator protocol
  1023. next() {
  1024. const { value, done } = innerIterator.next();
  1025. return done
  1026. ? { value, done }
  1027. : {
  1028. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1029. done
  1030. };
  1031. },
  1032. // iterable protocol
  1033. [Symbol.iterator]() {
  1034. return this;
  1035. }
  1036. };
  1037. };
  1038. }
  1039. function createReadonlyMethod(type) {
  1040. return function (...args) {
  1041. {
  1042. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1043. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1044. }
  1045. return type === "delete" /* DELETE */ ? false : this;
  1046. };
  1047. }
  1048. function createInstrumentations() {
  1049. const mutableInstrumentations = {
  1050. get(key) {
  1051. return get$1(this, key);
  1052. },
  1053. get size() {
  1054. return size(this);
  1055. },
  1056. has: has$1,
  1057. add,
  1058. set: set$1,
  1059. delete: deleteEntry,
  1060. clear,
  1061. forEach: createForEach(false, false)
  1062. };
  1063. const shallowInstrumentations = {
  1064. get(key) {
  1065. return get$1(this, key, false, true);
  1066. },
  1067. get size() {
  1068. return size(this);
  1069. },
  1070. has: has$1,
  1071. add,
  1072. set: set$1,
  1073. delete: deleteEntry,
  1074. clear,
  1075. forEach: createForEach(false, true)
  1076. };
  1077. const readonlyInstrumentations = {
  1078. get(key) {
  1079. return get$1(this, key, true);
  1080. },
  1081. get size() {
  1082. return size(this, true);
  1083. },
  1084. has(key) {
  1085. return has$1.call(this, key, true);
  1086. },
  1087. add: createReadonlyMethod("add" /* ADD */),
  1088. set: createReadonlyMethod("set" /* SET */),
  1089. delete: createReadonlyMethod("delete" /* DELETE */),
  1090. clear: createReadonlyMethod("clear" /* CLEAR */),
  1091. forEach: createForEach(true, false)
  1092. };
  1093. const shallowReadonlyInstrumentations = {
  1094. get(key) {
  1095. return get$1(this, key, true, true);
  1096. },
  1097. get size() {
  1098. return size(this, true);
  1099. },
  1100. has(key) {
  1101. return has$1.call(this, key, true);
  1102. },
  1103. add: createReadonlyMethod("add" /* ADD */),
  1104. set: createReadonlyMethod("set" /* SET */),
  1105. delete: createReadonlyMethod("delete" /* DELETE */),
  1106. clear: createReadonlyMethod("clear" /* CLEAR */),
  1107. forEach: createForEach(true, true)
  1108. };
  1109. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1110. iteratorMethods.forEach(method => {
  1111. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1112. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1113. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1114. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1115. });
  1116. return [
  1117. mutableInstrumentations,
  1118. readonlyInstrumentations,
  1119. shallowInstrumentations,
  1120. shallowReadonlyInstrumentations
  1121. ];
  1122. }
  1123. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1124. function createInstrumentationGetter(isReadonly, shallow) {
  1125. const instrumentations = shallow
  1126. ? isReadonly
  1127. ? shallowReadonlyInstrumentations
  1128. : shallowInstrumentations
  1129. : isReadonly
  1130. ? readonlyInstrumentations
  1131. : mutableInstrumentations;
  1132. return (target, key, receiver) => {
  1133. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  1134. return !isReadonly;
  1135. }
  1136. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  1137. return isReadonly;
  1138. }
  1139. else if (key === "__v_raw" /* RAW */) {
  1140. return target;
  1141. }
  1142. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1143. ? instrumentations
  1144. : target, key, receiver);
  1145. };
  1146. }
  1147. const mutableCollectionHandlers = {
  1148. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1149. };
  1150. const shallowCollectionHandlers = {
  1151. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1152. };
  1153. const readonlyCollectionHandlers = {
  1154. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1155. };
  1156. const shallowReadonlyCollectionHandlers = {
  1157. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1158. };
  1159. function checkIdentityKeys(target, has, key) {
  1160. const rawKey = toRaw(key);
  1161. if (rawKey !== key && has.call(target, rawKey)) {
  1162. const type = toRawType(target);
  1163. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1164. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1165. `which can lead to inconsistencies. ` +
  1166. `Avoid differentiating between the raw and reactive versions ` +
  1167. `of an object and only use the reactive version if possible.`);
  1168. }
  1169. }
  1170. const reactiveMap = new WeakMap();
  1171. const shallowReactiveMap = new WeakMap();
  1172. const readonlyMap = new WeakMap();
  1173. const shallowReadonlyMap = new WeakMap();
  1174. function targetTypeMap(rawType) {
  1175. switch (rawType) {
  1176. case 'Object':
  1177. case 'Array':
  1178. return 1 /* COMMON */;
  1179. case 'Map':
  1180. case 'Set':
  1181. case 'WeakMap':
  1182. case 'WeakSet':
  1183. return 2 /* COLLECTION */;
  1184. default:
  1185. return 0 /* INVALID */;
  1186. }
  1187. }
  1188. function getTargetType(value) {
  1189. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  1190. ? 0 /* INVALID */
  1191. : targetTypeMap(toRawType(value));
  1192. }
  1193. function reactive(target) {
  1194. // if trying to observe a readonly proxy, return the readonly version.
  1195. if (isReadonly(target)) {
  1196. return target;
  1197. }
  1198. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1199. }
  1200. /**
  1201. * Return a shallowly-reactive copy of the original object, where only the root
  1202. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1203. * root level).
  1204. */
  1205. function shallowReactive(target) {
  1206. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1207. }
  1208. /**
  1209. * Creates a readonly copy of the original object. Note the returned copy is not
  1210. * made reactive, but `readonly` can be called on an already reactive object.
  1211. */
  1212. function readonly(target) {
  1213. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1214. }
  1215. /**
  1216. * Returns a reactive-copy of the original object, where only the root level
  1217. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1218. * returned properties.
  1219. * This is used for creating the props proxy object for stateful components.
  1220. */
  1221. function shallowReadonly(target) {
  1222. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1223. }
  1224. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1225. if (!isObject(target)) {
  1226. {
  1227. console.warn(`value cannot be made reactive: ${String(target)}`);
  1228. }
  1229. return target;
  1230. }
  1231. // target is already a Proxy, return it.
  1232. // exception: calling readonly() on a reactive object
  1233. if (target["__v_raw" /* RAW */] &&
  1234. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1235. return target;
  1236. }
  1237. // target already has corresponding Proxy
  1238. const existingProxy = proxyMap.get(target);
  1239. if (existingProxy) {
  1240. return existingProxy;
  1241. }
  1242. // only a whitelist of value types can be observed.
  1243. const targetType = getTargetType(target);
  1244. if (targetType === 0 /* INVALID */) {
  1245. return target;
  1246. }
  1247. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1248. proxyMap.set(target, proxy);
  1249. return proxy;
  1250. }
  1251. function isReactive(value) {
  1252. if (isReadonly(value)) {
  1253. return isReactive(value["__v_raw" /* RAW */]);
  1254. }
  1255. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1256. }
  1257. function isReadonly(value) {
  1258. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1259. }
  1260. function isShallow(value) {
  1261. return !!(value && value["__v_isShallow" /* IS_SHALLOW */]);
  1262. }
  1263. function isProxy(value) {
  1264. return isReactive(value) || isReadonly(value);
  1265. }
  1266. function toRaw(observed) {
  1267. const raw = observed && observed["__v_raw" /* RAW */];
  1268. return raw ? toRaw(raw) : observed;
  1269. }
  1270. function markRaw(value) {
  1271. def(value, "__v_skip" /* SKIP */, true);
  1272. return value;
  1273. }
  1274. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1275. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1276. function trackRefValue(ref) {
  1277. if (shouldTrack && activeEffect) {
  1278. ref = toRaw(ref);
  1279. {
  1280. trackEffects(ref.dep || (ref.dep = createDep()), {
  1281. target: ref,
  1282. type: "get" /* GET */,
  1283. key: 'value'
  1284. });
  1285. }
  1286. }
  1287. }
  1288. function triggerRefValue(ref, newVal) {
  1289. ref = toRaw(ref);
  1290. if (ref.dep) {
  1291. {
  1292. triggerEffects(ref.dep, {
  1293. target: ref,
  1294. type: "set" /* SET */,
  1295. key: 'value',
  1296. newValue: newVal
  1297. });
  1298. }
  1299. }
  1300. }
  1301. function isRef(r) {
  1302. return !!(r && r.__v_isRef === true);
  1303. }
  1304. function ref(value) {
  1305. return createRef(value, false);
  1306. }
  1307. function shallowRef(value) {
  1308. return createRef(value, true);
  1309. }
  1310. function createRef(rawValue, shallow) {
  1311. if (isRef(rawValue)) {
  1312. return rawValue;
  1313. }
  1314. return new RefImpl(rawValue, shallow);
  1315. }
  1316. class RefImpl {
  1317. constructor(value, __v_isShallow) {
  1318. this.__v_isShallow = __v_isShallow;
  1319. this.dep = undefined;
  1320. this.__v_isRef = true;
  1321. this._rawValue = __v_isShallow ? value : toRaw(value);
  1322. this._value = __v_isShallow ? value : toReactive(value);
  1323. }
  1324. get value() {
  1325. trackRefValue(this);
  1326. return this._value;
  1327. }
  1328. set value(newVal) {
  1329. newVal = this.__v_isShallow ? newVal : toRaw(newVal);
  1330. if (hasChanged(newVal, this._rawValue)) {
  1331. this._rawValue = newVal;
  1332. this._value = this.__v_isShallow ? newVal : toReactive(newVal);
  1333. triggerRefValue(this, newVal);
  1334. }
  1335. }
  1336. }
  1337. function triggerRef(ref) {
  1338. triggerRefValue(ref, ref.value );
  1339. }
  1340. function unref(ref) {
  1341. return isRef(ref) ? ref.value : ref;
  1342. }
  1343. const shallowUnwrapHandlers = {
  1344. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1345. set: (target, key, value, receiver) => {
  1346. const oldValue = target[key];
  1347. if (isRef(oldValue) && !isRef(value)) {
  1348. oldValue.value = value;
  1349. return true;
  1350. }
  1351. else {
  1352. return Reflect.set(target, key, value, receiver);
  1353. }
  1354. }
  1355. };
  1356. function proxyRefs(objectWithRefs) {
  1357. return isReactive(objectWithRefs)
  1358. ? objectWithRefs
  1359. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1360. }
  1361. class CustomRefImpl {
  1362. constructor(factory) {
  1363. this.dep = undefined;
  1364. this.__v_isRef = true;
  1365. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1366. this._get = get;
  1367. this._set = set;
  1368. }
  1369. get value() {
  1370. return this._get();
  1371. }
  1372. set value(newVal) {
  1373. this._set(newVal);
  1374. }
  1375. }
  1376. function customRef(factory) {
  1377. return new CustomRefImpl(factory);
  1378. }
  1379. function toRefs(object) {
  1380. if (!isProxy(object)) {
  1381. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1382. }
  1383. const ret = isArray(object) ? new Array(object.length) : {};
  1384. for (const key in object) {
  1385. ret[key] = toRef(object, key);
  1386. }
  1387. return ret;
  1388. }
  1389. class ObjectRefImpl {
  1390. constructor(_object, _key, _defaultValue) {
  1391. this._object = _object;
  1392. this._key = _key;
  1393. this._defaultValue = _defaultValue;
  1394. this.__v_isRef = true;
  1395. }
  1396. get value() {
  1397. const val = this._object[this._key];
  1398. return val === undefined ? this._defaultValue : val;
  1399. }
  1400. set value(newVal) {
  1401. this._object[this._key] = newVal;
  1402. }
  1403. }
  1404. function toRef(object, key, defaultValue) {
  1405. const val = object[key];
  1406. return isRef(val)
  1407. ? val
  1408. : new ObjectRefImpl(object, key, defaultValue);
  1409. }
  1410. class ComputedRefImpl {
  1411. constructor(getter, _setter, isReadonly, isSSR) {
  1412. this._setter = _setter;
  1413. this.dep = undefined;
  1414. this.__v_isRef = true;
  1415. this._dirty = true;
  1416. this.effect = new ReactiveEffect(getter, () => {
  1417. if (!this._dirty) {
  1418. this._dirty = true;
  1419. triggerRefValue(this);
  1420. }
  1421. });
  1422. this.effect.computed = this;
  1423. this.effect.active = this._cacheable = !isSSR;
  1424. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1425. }
  1426. get value() {
  1427. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1428. const self = toRaw(this);
  1429. trackRefValue(self);
  1430. if (self._dirty || !self._cacheable) {
  1431. self._dirty = false;
  1432. self._value = self.effect.run();
  1433. }
  1434. return self._value;
  1435. }
  1436. set value(newValue) {
  1437. this._setter(newValue);
  1438. }
  1439. }
  1440. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1441. let getter;
  1442. let setter;
  1443. const onlyGetter = isFunction(getterOrOptions);
  1444. if (onlyGetter) {
  1445. getter = getterOrOptions;
  1446. setter = () => {
  1447. console.warn('Write operation failed: computed value is readonly');
  1448. }
  1449. ;
  1450. }
  1451. else {
  1452. getter = getterOrOptions.get;
  1453. setter = getterOrOptions.set;
  1454. }
  1455. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1456. if (debugOptions && !isSSR) {
  1457. cRef.effect.onTrack = debugOptions.onTrack;
  1458. cRef.effect.onTrigger = debugOptions.onTrigger;
  1459. }
  1460. return cRef;
  1461. }
  1462. const stack = [];
  1463. function pushWarningContext(vnode) {
  1464. stack.push(vnode);
  1465. }
  1466. function popWarningContext() {
  1467. stack.pop();
  1468. }
  1469. function warn$1(msg, ...args) {
  1470. // avoid props formatting or warn handler tracking deps that might be mutated
  1471. // during patch, leading to infinite recursion.
  1472. pauseTracking();
  1473. const instance = stack.length ? stack[stack.length - 1].component : null;
  1474. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1475. const trace = getComponentTrace();
  1476. if (appWarnHandler) {
  1477. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1478. msg + args.join(''),
  1479. instance && instance.proxy,
  1480. trace
  1481. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1482. .join('\n'),
  1483. trace
  1484. ]);
  1485. }
  1486. else {
  1487. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1488. /* istanbul ignore if */
  1489. if (trace.length &&
  1490. // avoid spamming console during tests
  1491. !false) {
  1492. warnArgs.push(`\n`, ...formatTrace(trace));
  1493. }
  1494. console.warn(...warnArgs);
  1495. }
  1496. resetTracking();
  1497. }
  1498. function getComponentTrace() {
  1499. let currentVNode = stack[stack.length - 1];
  1500. if (!currentVNode) {
  1501. return [];
  1502. }
  1503. // we can't just use the stack because it will be incomplete during updates
  1504. // that did not start from the root. Re-construct the parent chain using
  1505. // instance parent pointers.
  1506. const normalizedStack = [];
  1507. while (currentVNode) {
  1508. const last = normalizedStack[0];
  1509. if (last && last.vnode === currentVNode) {
  1510. last.recurseCount++;
  1511. }
  1512. else {
  1513. normalizedStack.push({
  1514. vnode: currentVNode,
  1515. recurseCount: 0
  1516. });
  1517. }
  1518. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1519. currentVNode = parentInstance && parentInstance.vnode;
  1520. }
  1521. return normalizedStack;
  1522. }
  1523. /* istanbul ignore next */
  1524. function formatTrace(trace) {
  1525. const logs = [];
  1526. trace.forEach((entry, i) => {
  1527. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1528. });
  1529. return logs;
  1530. }
  1531. function formatTraceEntry({ vnode, recurseCount }) {
  1532. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1533. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1534. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1535. const close = `>` + postfix;
  1536. return vnode.props
  1537. ? [open, ...formatProps(vnode.props), close]
  1538. : [open + close];
  1539. }
  1540. /* istanbul ignore next */
  1541. function formatProps(props) {
  1542. const res = [];
  1543. const keys = Object.keys(props);
  1544. keys.slice(0, 3).forEach(key => {
  1545. res.push(...formatProp(key, props[key]));
  1546. });
  1547. if (keys.length > 3) {
  1548. res.push(` ...`);
  1549. }
  1550. return res;
  1551. }
  1552. /* istanbul ignore next */
  1553. function formatProp(key, value, raw) {
  1554. if (isString(value)) {
  1555. value = JSON.stringify(value);
  1556. return raw ? value : [`${key}=${value}`];
  1557. }
  1558. else if (typeof value === 'number' ||
  1559. typeof value === 'boolean' ||
  1560. value == null) {
  1561. return raw ? value : [`${key}=${value}`];
  1562. }
  1563. else if (isRef(value)) {
  1564. value = formatProp(key, toRaw(value.value), true);
  1565. return raw ? value : [`${key}=Ref<`, value, `>`];
  1566. }
  1567. else if (isFunction(value)) {
  1568. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1569. }
  1570. else {
  1571. value = toRaw(value);
  1572. return raw ? value : [`${key}=`, value];
  1573. }
  1574. }
  1575. const ErrorTypeStrings = {
  1576. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  1577. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1578. ["c" /* CREATED */]: 'created hook',
  1579. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1580. ["m" /* MOUNTED */]: 'mounted hook',
  1581. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1582. ["u" /* UPDATED */]: 'updated',
  1583. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1584. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1585. ["a" /* ACTIVATED */]: 'activated hook',
  1586. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1587. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1588. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1589. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1590. [0 /* SETUP_FUNCTION */]: 'setup function',
  1591. [1 /* RENDER_FUNCTION */]: 'render function',
  1592. [2 /* WATCH_GETTER */]: 'watcher getter',
  1593. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1594. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1595. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1596. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1597. [7 /* VNODE_HOOK */]: 'vnode hook',
  1598. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1599. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1600. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1601. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1602. [12 /* FUNCTION_REF */]: 'ref function',
  1603. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1604. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1605. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1606. };
  1607. function callWithErrorHandling(fn, instance, type, args) {
  1608. let res;
  1609. try {
  1610. res = args ? fn(...args) : fn();
  1611. }
  1612. catch (err) {
  1613. handleError(err, instance, type);
  1614. }
  1615. return res;
  1616. }
  1617. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1618. if (isFunction(fn)) {
  1619. const res = callWithErrorHandling(fn, instance, type, args);
  1620. if (res && isPromise(res)) {
  1621. res.catch(err => {
  1622. handleError(err, instance, type);
  1623. });
  1624. }
  1625. return res;
  1626. }
  1627. const values = [];
  1628. for (let i = 0; i < fn.length; i++) {
  1629. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1630. }
  1631. return values;
  1632. }
  1633. function handleError(err, instance, type, throwInDev = true) {
  1634. const contextVNode = instance ? instance.vnode : null;
  1635. if (instance) {
  1636. let cur = instance.parent;
  1637. // the exposed instance is the render proxy to keep it consistent with 2.x
  1638. const exposedInstance = instance.proxy;
  1639. // in production the hook receives only the error code
  1640. const errorInfo = ErrorTypeStrings[type] ;
  1641. while (cur) {
  1642. const errorCapturedHooks = cur.ec;
  1643. if (errorCapturedHooks) {
  1644. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1645. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1646. return;
  1647. }
  1648. }
  1649. }
  1650. cur = cur.parent;
  1651. }
  1652. // app-level handling
  1653. const appErrorHandler = instance.appContext.config.errorHandler;
  1654. if (appErrorHandler) {
  1655. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1656. return;
  1657. }
  1658. }
  1659. logError(err, type, contextVNode, throwInDev);
  1660. }
  1661. function logError(err, type, contextVNode, throwInDev = true) {
  1662. {
  1663. const info = ErrorTypeStrings[type];
  1664. if (contextVNode) {
  1665. pushWarningContext(contextVNode);
  1666. }
  1667. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1668. if (contextVNode) {
  1669. popWarningContext();
  1670. }
  1671. // crash in dev by default so it's more noticeable
  1672. if (throwInDev) {
  1673. throw err;
  1674. }
  1675. else {
  1676. console.error(err);
  1677. }
  1678. }
  1679. }
  1680. let isFlushing = false;
  1681. let isFlushPending = false;
  1682. const queue = [];
  1683. let flushIndex = 0;
  1684. const pendingPreFlushCbs = [];
  1685. let activePreFlushCbs = null;
  1686. let preFlushIndex = 0;
  1687. const pendingPostFlushCbs = [];
  1688. let activePostFlushCbs = null;
  1689. let postFlushIndex = 0;
  1690. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1691. let currentFlushPromise = null;
  1692. let currentPreFlushParentJob = null;
  1693. const RECURSION_LIMIT = 100;
  1694. function nextTick(fn) {
  1695. const p = currentFlushPromise || resolvedPromise;
  1696. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1697. }
  1698. // #2768
  1699. // Use binary-search to find a suitable position in the queue,
  1700. // so that the queue maintains the increasing order of job's id,
  1701. // which can prevent the job from being skipped and also can avoid repeated patching.
  1702. function findInsertionIndex(id) {
  1703. // the start index should be `flushIndex + 1`
  1704. let start = flushIndex + 1;
  1705. let end = queue.length;
  1706. while (start < end) {
  1707. const middle = (start + end) >>> 1;
  1708. const middleJobId = getId(queue[middle]);
  1709. middleJobId < id ? (start = middle + 1) : (end = middle);
  1710. }
  1711. return start;
  1712. }
  1713. function queueJob(job) {
  1714. // the dedupe search uses the startIndex argument of Array.includes()
  1715. // by default the search index includes the current job that is being run
  1716. // so it cannot recursively trigger itself again.
  1717. // if the job is a watch() callback, the search will start with a +1 index to
  1718. // allow it recursively trigger itself - it is the user's responsibility to
  1719. // ensure it doesn't end up in an infinite loop.
  1720. if ((!queue.length ||
  1721. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1722. job !== currentPreFlushParentJob) {
  1723. if (job.id == null) {
  1724. queue.push(job);
  1725. }
  1726. else {
  1727. queue.splice(findInsertionIndex(job.id), 0, job);
  1728. }
  1729. queueFlush();
  1730. }
  1731. }
  1732. function queueFlush() {
  1733. if (!isFlushing && !isFlushPending) {
  1734. isFlushPending = true;
  1735. currentFlushPromise = resolvedPromise.then(flushJobs);
  1736. }
  1737. }
  1738. function invalidateJob(job) {
  1739. const i = queue.indexOf(job);
  1740. if (i > flushIndex) {
  1741. queue.splice(i, 1);
  1742. }
  1743. }
  1744. function queueCb(cb, activeQueue, pendingQueue, index) {
  1745. if (!isArray(cb)) {
  1746. if (!activeQueue ||
  1747. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1748. pendingQueue.push(cb);
  1749. }
  1750. }
  1751. else {
  1752. // if cb is an array, it is a component lifecycle hook which can only be
  1753. // triggered by a job, which is already deduped in the main queue, so
  1754. // we can skip duplicate check here to improve perf
  1755. pendingQueue.push(...cb);
  1756. }
  1757. queueFlush();
  1758. }
  1759. function queuePreFlushCb(cb) {
  1760. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1761. }
  1762. function queuePostFlushCb(cb) {
  1763. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1764. }
  1765. function flushPreFlushCbs(seen, parentJob = null) {
  1766. if (pendingPreFlushCbs.length) {
  1767. currentPreFlushParentJob = parentJob;
  1768. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1769. pendingPreFlushCbs.length = 0;
  1770. {
  1771. seen = seen || new Map();
  1772. }
  1773. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1774. if (checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  1775. continue;
  1776. }
  1777. activePreFlushCbs[preFlushIndex]();
  1778. }
  1779. activePreFlushCbs = null;
  1780. preFlushIndex = 0;
  1781. currentPreFlushParentJob = null;
  1782. // recursively flush until it drains
  1783. flushPreFlushCbs(seen, parentJob);
  1784. }
  1785. }
  1786. function flushPostFlushCbs(seen) {
  1787. if (pendingPostFlushCbs.length) {
  1788. const deduped = [...new Set(pendingPostFlushCbs)];
  1789. pendingPostFlushCbs.length = 0;
  1790. // #1947 already has active queue, nested flushPostFlushCbs call
  1791. if (activePostFlushCbs) {
  1792. activePostFlushCbs.push(...deduped);
  1793. return;
  1794. }
  1795. activePostFlushCbs = deduped;
  1796. {
  1797. seen = seen || new Map();
  1798. }
  1799. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1800. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1801. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1802. continue;
  1803. }
  1804. activePostFlushCbs[postFlushIndex]();
  1805. }
  1806. activePostFlushCbs = null;
  1807. postFlushIndex = 0;
  1808. }
  1809. }
  1810. const getId = (job) => job.id == null ? Infinity : job.id;
  1811. function flushJobs(seen) {
  1812. isFlushPending = false;
  1813. isFlushing = true;
  1814. {
  1815. seen = seen || new Map();
  1816. }
  1817. flushPreFlushCbs(seen);
  1818. // Sort queue before flush.
  1819. // This ensures that:
  1820. // 1. Components are updated from parent to child. (because parent is always
  1821. // created before the child so its render effect will have smaller
  1822. // priority number)
  1823. // 2. If a component is unmounted during a parent component's update,
  1824. // its update can be skipped.
  1825. queue.sort((a, b) => getId(a) - getId(b));
  1826. // conditional usage of checkRecursiveUpdate must be determined out of
  1827. // try ... catch block since Rollup by default de-optimizes treeshaking
  1828. // inside try-catch. This can leave all warning code unshaked. Although
  1829. // they would get eventually shaken by a minifier like terser, some minifiers
  1830. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1831. const check = (job) => checkRecursiveUpdates(seen, job)
  1832. ;
  1833. try {
  1834. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1835. const job = queue[flushIndex];
  1836. if (job && job.active !== false) {
  1837. if (true && check(job)) {
  1838. continue;
  1839. }
  1840. // console.log(`running:`, job.id)
  1841. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1842. }
  1843. }
  1844. }
  1845. finally {
  1846. flushIndex = 0;
  1847. queue.length = 0;
  1848. flushPostFlushCbs(seen);
  1849. isFlushing = false;
  1850. currentFlushPromise = null;
  1851. // some postFlushCb queued jobs!
  1852. // keep flushing until it drains.
  1853. if (queue.length ||
  1854. pendingPreFlushCbs.length ||
  1855. pendingPostFlushCbs.length) {
  1856. flushJobs(seen);
  1857. }
  1858. }
  1859. }
  1860. function checkRecursiveUpdates(seen, fn) {
  1861. if (!seen.has(fn)) {
  1862. seen.set(fn, 1);
  1863. }
  1864. else {
  1865. const count = seen.get(fn);
  1866. if (count > RECURSION_LIMIT) {
  1867. const instance = fn.ownerInstance;
  1868. const componentName = instance && getComponentName(instance.type);
  1869. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1870. `This means you have a reactive effect that is mutating its own ` +
  1871. `dependencies and thus recursively triggering itself. Possible sources ` +
  1872. `include component template, render function, updated hook or ` +
  1873. `watcher source function.`);
  1874. return true;
  1875. }
  1876. else {
  1877. seen.set(fn, count + 1);
  1878. }
  1879. }
  1880. }
  1881. /* eslint-disable no-restricted-globals */
  1882. let isHmrUpdating = false;
  1883. const hmrDirtyComponents = new Set();
  1884. // Expose the HMR runtime on the global object
  1885. // This makes it entirely tree-shakable without polluting the exports and makes
  1886. // it easier to be used in toolings like vue-loader
  1887. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1888. // to be set so that its instances can be registered / removed.
  1889. {
  1890. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1891. createRecord: tryWrap(createRecord),
  1892. rerender: tryWrap(rerender),
  1893. reload: tryWrap(reload)
  1894. };
  1895. }
  1896. const map = new Map();
  1897. function registerHMR(instance) {
  1898. const id = instance.type.__hmrId;
  1899. let record = map.get(id);
  1900. if (!record) {
  1901. createRecord(id, instance.type);
  1902. record = map.get(id);
  1903. }
  1904. record.instances.add(instance);
  1905. }
  1906. function unregisterHMR(instance) {
  1907. map.get(instance.type.__hmrId).instances.delete(instance);
  1908. }
  1909. function createRecord(id, initialDef) {
  1910. if (map.has(id)) {
  1911. return false;
  1912. }
  1913. map.set(id, {
  1914. initialDef: normalizeClassComponent(initialDef),
  1915. instances: new Set()
  1916. });
  1917. return true;
  1918. }
  1919. function normalizeClassComponent(component) {
  1920. return isClassComponent(component) ? component.__vccOpts : component;
  1921. }
  1922. function rerender(id, newRender) {
  1923. const record = map.get(id);
  1924. if (!record) {
  1925. return;
  1926. }
  1927. // update initial record (for not-yet-rendered component)
  1928. record.initialDef.render = newRender;
  1929. [...record.instances].forEach(instance => {
  1930. if (newRender) {
  1931. instance.render = newRender;
  1932. normalizeClassComponent(instance.type).render = newRender;
  1933. }
  1934. instance.renderCache = [];
  1935. // this flag forces child components with slot content to update
  1936. isHmrUpdating = true;
  1937. instance.update();
  1938. isHmrUpdating = false;
  1939. });
  1940. }
  1941. function reload(id, newComp) {
  1942. const record = map.get(id);
  1943. if (!record)
  1944. return;
  1945. newComp = normalizeClassComponent(newComp);
  1946. // update initial def (for not-yet-rendered components)
  1947. updateComponentDef(record.initialDef, newComp);
  1948. // create a snapshot which avoids the set being mutated during updates
  1949. const instances = [...record.instances];
  1950. for (const instance of instances) {
  1951. const oldComp = normalizeClassComponent(instance.type);
  1952. if (!hmrDirtyComponents.has(oldComp)) {
  1953. // 1. Update existing comp definition to match new one
  1954. if (oldComp !== record.initialDef) {
  1955. updateComponentDef(oldComp, newComp);
  1956. }
  1957. // 2. mark definition dirty. This forces the renderer to replace the
  1958. // component on patch.
  1959. hmrDirtyComponents.add(oldComp);
  1960. }
  1961. // 3. invalidate options resolution cache
  1962. instance.appContext.optionsCache.delete(instance.type);
  1963. // 4. actually update
  1964. if (instance.ceReload) {
  1965. // custom element
  1966. hmrDirtyComponents.add(oldComp);
  1967. instance.ceReload(newComp.styles);
  1968. hmrDirtyComponents.delete(oldComp);
  1969. }
  1970. else if (instance.parent) {
  1971. // 4. Force the parent instance to re-render. This will cause all updated
  1972. // components to be unmounted and re-mounted. Queue the update so that we
  1973. // don't end up forcing the same parent to re-render multiple times.
  1974. queueJob(instance.parent.update);
  1975. // instance is the inner component of an async custom element
  1976. // invoke to reset styles
  1977. if (instance.parent.type.__asyncLoader &&
  1978. instance.parent.ceReload) {
  1979. instance.parent.ceReload(newComp.styles);
  1980. }
  1981. }
  1982. else if (instance.appContext.reload) {
  1983. // root instance mounted via createApp() has a reload method
  1984. instance.appContext.reload();
  1985. }
  1986. else if (typeof window !== 'undefined') {
  1987. // root instance inside tree created via raw render(). Force reload.
  1988. window.location.reload();
  1989. }
  1990. else {
  1991. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  1992. }
  1993. }
  1994. // 5. make sure to cleanup dirty hmr components after update
  1995. queuePostFlushCb(() => {
  1996. for (const instance of instances) {
  1997. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  1998. }
  1999. });
  2000. }
  2001. function updateComponentDef(oldComp, newComp) {
  2002. extend(oldComp, newComp);
  2003. for (const key in oldComp) {
  2004. if (key !== '__file' && !(key in newComp)) {
  2005. delete oldComp[key];
  2006. }
  2007. }
  2008. }
  2009. function tryWrap(fn) {
  2010. return (id, arg) => {
  2011. try {
  2012. return fn(id, arg);
  2013. }
  2014. catch (e) {
  2015. console.error(e);
  2016. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2017. `Full reload required.`);
  2018. }
  2019. };
  2020. }
  2021. let devtools;
  2022. let buffer = [];
  2023. let devtoolsNotInstalled = false;
  2024. function emit(event, ...args) {
  2025. if (devtools) {
  2026. devtools.emit(event, ...args);
  2027. }
  2028. else if (!devtoolsNotInstalled) {
  2029. buffer.push({ event, args });
  2030. }
  2031. }
  2032. function setDevtoolsHook(hook, target) {
  2033. var _a, _b;
  2034. devtools = hook;
  2035. if (devtools) {
  2036. devtools.enabled = true;
  2037. buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
  2038. buffer = [];
  2039. }
  2040. else if (
  2041. // handle late devtools injection - only do this if we are in an actual
  2042. // browser environment to avoid the timer handle stalling test runner exit
  2043. // (#4815)
  2044. // eslint-disable-next-line no-restricted-globals
  2045. typeof window !== 'undefined' &&
  2046. // some envs mock window but not fully
  2047. window.HTMLElement &&
  2048. // also exclude jsdom
  2049. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2050. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2051. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2052. replay.push((newHook) => {
  2053. setDevtoolsHook(newHook, target);
  2054. });
  2055. // clear buffer after 3s - the user probably doesn't have devtools installed
  2056. // at all, and keeping the buffer will cause memory leaks (#4738)
  2057. setTimeout(() => {
  2058. if (!devtools) {
  2059. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2060. devtoolsNotInstalled = true;
  2061. buffer = [];
  2062. }
  2063. }, 3000);
  2064. }
  2065. else {
  2066. // non-browser env, assume not installed
  2067. devtoolsNotInstalled = true;
  2068. buffer = [];
  2069. }
  2070. }
  2071. function devtoolsInitApp(app, version) {
  2072. emit("app:init" /* APP_INIT */, app, version, {
  2073. Fragment,
  2074. Text,
  2075. Comment,
  2076. Static
  2077. });
  2078. }
  2079. function devtoolsUnmountApp(app) {
  2080. emit("app:unmount" /* APP_UNMOUNT */, app);
  2081. }
  2082. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  2083. const devtoolsComponentUpdated =
  2084. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  2085. const devtoolsComponentRemoved =
  2086. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  2087. function createDevtoolsComponentHook(hook) {
  2088. return (component) => {
  2089. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2090. };
  2091. }
  2092. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  2093. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  2094. function createDevtoolsPerformanceHook(hook) {
  2095. return (component, type, time) => {
  2096. emit(hook, component.appContext.app, component.uid, component, type, time);
  2097. };
  2098. }
  2099. function devtoolsComponentEmit(component, event, params) {
  2100. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2101. }
  2102. function emit$1(instance, event, ...rawArgs) {
  2103. if (instance.isUnmounted)
  2104. return;
  2105. const props = instance.vnode.props || EMPTY_OBJ;
  2106. {
  2107. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2108. if (emitsOptions) {
  2109. if (!(event in emitsOptions) &&
  2110. !(false )) {
  2111. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2112. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  2113. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2114. }
  2115. }
  2116. else {
  2117. const validator = emitsOptions[event];
  2118. if (isFunction(validator)) {
  2119. const isValid = validator(...rawArgs);
  2120. if (!isValid) {
  2121. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  2122. }
  2123. }
  2124. }
  2125. }
  2126. }
  2127. let args = rawArgs;
  2128. const isModelListener = event.startsWith('update:');
  2129. // for v-model update:xxx events, apply modifiers on args
  2130. const modelArg = isModelListener && event.slice(7);
  2131. if (modelArg && modelArg in props) {
  2132. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2133. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2134. if (trim) {
  2135. args = rawArgs.map(a => a.trim());
  2136. }
  2137. else if (number) {
  2138. args = rawArgs.map(toNumber);
  2139. }
  2140. }
  2141. {
  2142. devtoolsComponentEmit(instance, event, args);
  2143. }
  2144. {
  2145. const lowerCaseEvent = event.toLowerCase();
  2146. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2147. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  2148. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2149. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2150. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2151. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2152. }
  2153. }
  2154. let handlerName;
  2155. let handler = props[(handlerName = toHandlerKey(event))] ||
  2156. // also try camelCase event handler (#2249)
  2157. props[(handlerName = toHandlerKey(camelize(event)))];
  2158. // for v-model update:xxx events, also trigger kebab-case equivalent
  2159. // for props passed via kebab-case
  2160. if (!handler && isModelListener) {
  2161. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2162. }
  2163. if (handler) {
  2164. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2165. }
  2166. const onceHandler = props[handlerName + `Once`];
  2167. if (onceHandler) {
  2168. if (!instance.emitted) {
  2169. instance.emitted = {};
  2170. }
  2171. else if (instance.emitted[handlerName]) {
  2172. return;
  2173. }
  2174. instance.emitted[handlerName] = true;
  2175. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2176. }
  2177. }
  2178. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2179. const cache = appContext.emitsCache;
  2180. const cached = cache.get(comp);
  2181. if (cached !== undefined) {
  2182. return cached;
  2183. }
  2184. const raw = comp.emits;
  2185. let normalized = {};
  2186. // apply mixin/extends props
  2187. let hasExtends = false;
  2188. if (!isFunction(comp)) {
  2189. const extendEmits = (raw) => {
  2190. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2191. if (normalizedFromExtend) {
  2192. hasExtends = true;
  2193. extend(normalized, normalizedFromExtend);
  2194. }
  2195. };
  2196. if (!asMixin && appContext.mixins.length) {
  2197. appContext.mixins.forEach(extendEmits);
  2198. }
  2199. if (comp.extends) {
  2200. extendEmits(comp.extends);
  2201. }
  2202. if (comp.mixins) {
  2203. comp.mixins.forEach(extendEmits);
  2204. }
  2205. }
  2206. if (!raw && !hasExtends) {
  2207. cache.set(comp, null);
  2208. return null;
  2209. }
  2210. if (isArray(raw)) {
  2211. raw.forEach(key => (normalized[key] = null));
  2212. }
  2213. else {
  2214. extend(normalized, raw);
  2215. }
  2216. cache.set(comp, normalized);
  2217. return normalized;
  2218. }
  2219. // Check if an incoming prop key is a declared emit event listener.
  2220. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2221. // both considered matched listeners.
  2222. function isEmitListener(options, key) {
  2223. if (!options || !isOn(key)) {
  2224. return false;
  2225. }
  2226. key = key.slice(2).replace(/Once$/, '');
  2227. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2228. hasOwn(options, hyphenate(key)) ||
  2229. hasOwn(options, key));
  2230. }
  2231. /**
  2232. * mark the current rendering instance for asset resolution (e.g.
  2233. * resolveComponent, resolveDirective) during render
  2234. */
  2235. let currentRenderingInstance = null;
  2236. let currentScopeId = null;
  2237. /**
  2238. * Note: rendering calls maybe nested. The function returns the parent rendering
  2239. * instance if present, which should be restored after the render is done:
  2240. *
  2241. * ```js
  2242. * const prev = setCurrentRenderingInstance(i)
  2243. * // ...render
  2244. * setCurrentRenderingInstance(prev)
  2245. * ```
  2246. */
  2247. function setCurrentRenderingInstance(instance) {
  2248. const prev = currentRenderingInstance;
  2249. currentRenderingInstance = instance;
  2250. currentScopeId = (instance && instance.type.__scopeId) || null;
  2251. return prev;
  2252. }
  2253. /**
  2254. * Set scope id when creating hoisted vnodes.
  2255. * @private compiler helper
  2256. */
  2257. function pushScopeId(id) {
  2258. currentScopeId = id;
  2259. }
  2260. /**
  2261. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2262. * API for backwards compat w/ code generated by compilers.
  2263. * @private
  2264. */
  2265. function popScopeId() {
  2266. currentScopeId = null;
  2267. }
  2268. /**
  2269. * Only for backwards compat
  2270. * @private
  2271. */
  2272. const withScopeId = (_id) => withCtx;
  2273. /**
  2274. * Wrap a slot function to memoize current rendering instance
  2275. * @private compiler helper
  2276. */
  2277. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2278. ) {
  2279. if (!ctx)
  2280. return fn;
  2281. // already normalized
  2282. if (fn._n) {
  2283. return fn;
  2284. }
  2285. const renderFnWithContext = (...args) => {
  2286. // If a user calls a compiled slot inside a template expression (#1745), it
  2287. // can mess up block tracking, so by default we disable block tracking and
  2288. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2289. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2290. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2291. if (renderFnWithContext._d) {
  2292. setBlockTracking(-1);
  2293. }
  2294. const prevInstance = setCurrentRenderingInstance(ctx);
  2295. const res = fn(...args);
  2296. setCurrentRenderingInstance(prevInstance);
  2297. if (renderFnWithContext._d) {
  2298. setBlockTracking(1);
  2299. }
  2300. {
  2301. devtoolsComponentUpdated(ctx);
  2302. }
  2303. return res;
  2304. };
  2305. // mark normalized to avoid duplicated wrapping
  2306. renderFnWithContext._n = true;
  2307. // mark this as compiled by default
  2308. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2309. // rendering flag.
  2310. renderFnWithContext._c = true;
  2311. // disable block tracking by default
  2312. renderFnWithContext._d = true;
  2313. return renderFnWithContext;
  2314. }
  2315. /**
  2316. * dev only flag to track whether $attrs was used during render.
  2317. * If $attrs was used during render then the warning for failed attrs
  2318. * fallthrough can be suppressed.
  2319. */
  2320. let accessedAttrs = false;
  2321. function markAttrsAccessed() {
  2322. accessedAttrs = true;
  2323. }
  2324. function renderComponentRoot(instance) {
  2325. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2326. let result;
  2327. let fallthroughAttrs;
  2328. const prev = setCurrentRenderingInstance(instance);
  2329. {
  2330. accessedAttrs = false;
  2331. }
  2332. try {
  2333. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  2334. // withProxy is a proxy with a different `has` trap only for
  2335. // runtime-compiled render functions using `with` block.
  2336. const proxyToUse = withProxy || proxy;
  2337. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2338. fallthroughAttrs = attrs;
  2339. }
  2340. else {
  2341. // functional
  2342. const render = Component;
  2343. // in dev, mark attrs accessed if optional props (attrs === props)
  2344. if (true && attrs === props) {
  2345. markAttrsAccessed();
  2346. }
  2347. result = normalizeVNode(render.length > 1
  2348. ? render(props, true
  2349. ? {
  2350. get attrs() {
  2351. markAttrsAccessed();
  2352. return attrs;
  2353. },
  2354. slots,
  2355. emit
  2356. }
  2357. : { attrs, slots, emit })
  2358. : render(props, null /* we know it doesn't need it */));
  2359. fallthroughAttrs = Component.props
  2360. ? attrs
  2361. : getFunctionalFallthrough(attrs);
  2362. }
  2363. }
  2364. catch (err) {
  2365. blockStack.length = 0;
  2366. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  2367. result = createVNode(Comment);
  2368. }
  2369. // attr merging
  2370. // in dev mode, comments are preserved, and it's possible for a template
  2371. // to have comments along side the root element which makes it a fragment
  2372. let root = result;
  2373. let setRoot = undefined;
  2374. if (result.patchFlag > 0 &&
  2375. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  2376. [root, setRoot] = getChildRoot(result);
  2377. }
  2378. if (fallthroughAttrs && inheritAttrs !== false) {
  2379. const keys = Object.keys(fallthroughAttrs);
  2380. const { shapeFlag } = root;
  2381. if (keys.length) {
  2382. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  2383. if (propsOptions && keys.some(isModelListener)) {
  2384. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2385. // prop, it indicates this component expects to handle v-model and
  2386. // it should not fallthrough.
  2387. // related: #1543, #1643, #1989
  2388. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2389. }
  2390. root = cloneVNode(root, fallthroughAttrs);
  2391. }
  2392. else if (!accessedAttrs && root.type !== Comment) {
  2393. const allAttrs = Object.keys(attrs);
  2394. const eventAttrs = [];
  2395. const extraAttrs = [];
  2396. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2397. const key = allAttrs[i];
  2398. if (isOn(key)) {
  2399. // ignore v-model handlers when they fail to fallthrough
  2400. if (!isModelListener(key)) {
  2401. // remove `on`, lowercase first letter to reflect event casing
  2402. // accurately
  2403. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2404. }
  2405. }
  2406. else {
  2407. extraAttrs.push(key);
  2408. }
  2409. }
  2410. if (extraAttrs.length) {
  2411. warn$1(`Extraneous non-props attributes (` +
  2412. `${extraAttrs.join(', ')}) ` +
  2413. `were passed to component but could not be automatically inherited ` +
  2414. `because component renders fragment or text root nodes.`);
  2415. }
  2416. if (eventAttrs.length) {
  2417. warn$1(`Extraneous non-emits event listeners (` +
  2418. `${eventAttrs.join(', ')}) ` +
  2419. `were passed to component but could not be automatically inherited ` +
  2420. `because component renders fragment or text root nodes. ` +
  2421. `If the listener is intended to be a component custom event listener only, ` +
  2422. `declare it using the "emits" option.`);
  2423. }
  2424. }
  2425. }
  2426. }
  2427. // inherit directives
  2428. if (vnode.dirs) {
  2429. if (!isElementRoot(root)) {
  2430. warn$1(`Runtime directive used on component with non-element root node. ` +
  2431. `The directives will not function as intended.`);
  2432. }
  2433. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2434. }
  2435. // inherit transition data
  2436. if (vnode.transition) {
  2437. if (!isElementRoot(root)) {
  2438. warn$1(`Component inside <Transition> renders non-element root node ` +
  2439. `that cannot be animated.`);
  2440. }
  2441. root.transition = vnode.transition;
  2442. }
  2443. if (setRoot) {
  2444. setRoot(root);
  2445. }
  2446. else {
  2447. result = root;
  2448. }
  2449. setCurrentRenderingInstance(prev);
  2450. return result;
  2451. }
  2452. /**
  2453. * dev only
  2454. * In dev mode, template root level comments are rendered, which turns the
  2455. * template into a fragment root, but we need to locate the single element
  2456. * root for attrs and scope id processing.
  2457. */
  2458. const getChildRoot = (vnode) => {
  2459. const rawChildren = vnode.children;
  2460. const dynamicChildren = vnode.dynamicChildren;
  2461. const childRoot = filterSingleRoot(rawChildren);
  2462. if (!childRoot) {
  2463. return [vnode, undefined];
  2464. }
  2465. const index = rawChildren.indexOf(childRoot);
  2466. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2467. const setRoot = (updatedRoot) => {
  2468. rawChildren[index] = updatedRoot;
  2469. if (dynamicChildren) {
  2470. if (dynamicIndex > -1) {
  2471. dynamicChildren[dynamicIndex] = updatedRoot;
  2472. }
  2473. else if (updatedRoot.patchFlag > 0) {
  2474. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2475. }
  2476. }
  2477. };
  2478. return [normalizeVNode(childRoot), setRoot];
  2479. };
  2480. function filterSingleRoot(children) {
  2481. let singleRoot;
  2482. for (let i = 0; i < children.length; i++) {
  2483. const child = children[i];
  2484. if (isVNode(child)) {
  2485. // ignore user comment
  2486. if (child.type !== Comment || child.children === 'v-if') {
  2487. if (singleRoot) {
  2488. // has more than 1 non-comment child, return now
  2489. return;
  2490. }
  2491. else {
  2492. singleRoot = child;
  2493. }
  2494. }
  2495. }
  2496. else {
  2497. return;
  2498. }
  2499. }
  2500. return singleRoot;
  2501. }
  2502. const getFunctionalFallthrough = (attrs) => {
  2503. let res;
  2504. for (const key in attrs) {
  2505. if (key === 'class' || key === 'style' || isOn(key)) {
  2506. (res || (res = {}))[key] = attrs[key];
  2507. }
  2508. }
  2509. return res;
  2510. };
  2511. const filterModelListeners = (attrs, props) => {
  2512. const res = {};
  2513. for (const key in attrs) {
  2514. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2515. res[key] = attrs[key];
  2516. }
  2517. }
  2518. return res;
  2519. };
  2520. const isElementRoot = (vnode) => {
  2521. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  2522. vnode.type === Comment // potential v-if branch switch
  2523. );
  2524. };
  2525. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2526. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2527. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2528. const emits = component.emitsOptions;
  2529. // Parent component's render function was hot-updated. Since this may have
  2530. // caused the child component's slots content to have changed, we need to
  2531. // force the child to update as well.
  2532. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2533. return true;
  2534. }
  2535. // force child update for runtime directive or transition on component vnode.
  2536. if (nextVNode.dirs || nextVNode.transition) {
  2537. return true;
  2538. }
  2539. if (optimized && patchFlag >= 0) {
  2540. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2541. // slot content that references values that might have changed,
  2542. // e.g. in a v-for
  2543. return true;
  2544. }
  2545. if (patchFlag & 16 /* FULL_PROPS */) {
  2546. if (!prevProps) {
  2547. return !!nextProps;
  2548. }
  2549. // presence of this flag indicates props are always non-null
  2550. return hasPropsChanged(prevProps, nextProps, emits);
  2551. }
  2552. else if (patchFlag & 8 /* PROPS */) {
  2553. const dynamicProps = nextVNode.dynamicProps;
  2554. for (let i = 0; i < dynamicProps.length; i++) {
  2555. const key = dynamicProps[i];
  2556. if (nextProps[key] !== prevProps[key] &&
  2557. !isEmitListener(emits, key)) {
  2558. return true;
  2559. }
  2560. }
  2561. }
  2562. }
  2563. else {
  2564. // this path is only taken by manually written render functions
  2565. // so presence of any children leads to a forced update
  2566. if (prevChildren || nextChildren) {
  2567. if (!nextChildren || !nextChildren.$stable) {
  2568. return true;
  2569. }
  2570. }
  2571. if (prevProps === nextProps) {
  2572. return false;
  2573. }
  2574. if (!prevProps) {
  2575. return !!nextProps;
  2576. }
  2577. if (!nextProps) {
  2578. return true;
  2579. }
  2580. return hasPropsChanged(prevProps, nextProps, emits);
  2581. }
  2582. return false;
  2583. }
  2584. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2585. const nextKeys = Object.keys(nextProps);
  2586. if (nextKeys.length !== Object.keys(prevProps).length) {
  2587. return true;
  2588. }
  2589. for (let i = 0; i < nextKeys.length; i++) {
  2590. const key = nextKeys[i];
  2591. if (nextProps[key] !== prevProps[key] &&
  2592. !isEmitListener(emitsOptions, key)) {
  2593. return true;
  2594. }
  2595. }
  2596. return false;
  2597. }
  2598. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2599. ) {
  2600. while (parent && parent.subTree === vnode) {
  2601. (vnode = parent.vnode).el = el;
  2602. parent = parent.parent;
  2603. }
  2604. }
  2605. const isSuspense = (type) => type.__isSuspense;
  2606. // Suspense exposes a component-like API, and is treated like a component
  2607. // in the compiler, but internally it's a special built-in type that hooks
  2608. // directly into the renderer.
  2609. const SuspenseImpl = {
  2610. name: 'Suspense',
  2611. // In order to make Suspense tree-shakable, we need to avoid importing it
  2612. // directly in the renderer. The renderer checks for the __isSuspense flag
  2613. // on a vnode's type and calls the `process` method, passing in renderer
  2614. // internals.
  2615. __isSuspense: true,
  2616. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2617. // platform-specific impl passed from renderer
  2618. rendererInternals) {
  2619. if (n1 == null) {
  2620. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2621. }
  2622. else {
  2623. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2624. }
  2625. },
  2626. hydrate: hydrateSuspense,
  2627. create: createSuspenseBoundary,
  2628. normalize: normalizeSuspenseChildren
  2629. };
  2630. // Force-casted public typing for h and TSX props inference
  2631. const Suspense = (SuspenseImpl );
  2632. function triggerEvent(vnode, name) {
  2633. const eventListener = vnode.props && vnode.props[name];
  2634. if (isFunction(eventListener)) {
  2635. eventListener();
  2636. }
  2637. }
  2638. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2639. const { p: patch, o: { createElement } } = rendererInternals;
  2640. const hiddenContainer = createElement('div');
  2641. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2642. // start mounting the content subtree in an off-dom container
  2643. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2644. // now check if we have encountered any async deps
  2645. if (suspense.deps > 0) {
  2646. // has async
  2647. // invoke @fallback event
  2648. triggerEvent(vnode, 'onPending');
  2649. triggerEvent(vnode, 'onFallback');
  2650. // mount the fallback tree
  2651. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2652. isSVG, slotScopeIds);
  2653. setActiveBranch(suspense, vnode.ssFallback);
  2654. }
  2655. else {
  2656. // Suspense has no async deps. Just resolve.
  2657. suspense.resolve();
  2658. }
  2659. }
  2660. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2661. const suspense = (n2.suspense = n1.suspense);
  2662. suspense.vnode = n2;
  2663. n2.el = n1.el;
  2664. const newBranch = n2.ssContent;
  2665. const newFallback = n2.ssFallback;
  2666. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2667. if (pendingBranch) {
  2668. suspense.pendingBranch = newBranch;
  2669. if (isSameVNodeType(newBranch, pendingBranch)) {
  2670. // same root type but content may have changed.
  2671. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2672. if (suspense.deps <= 0) {
  2673. suspense.resolve();
  2674. }
  2675. else if (isInFallback) {
  2676. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2677. isSVG, slotScopeIds, optimized);
  2678. setActiveBranch(suspense, newFallback);
  2679. }
  2680. }
  2681. else {
  2682. // toggled before pending tree is resolved
  2683. suspense.pendingId++;
  2684. if (isHydrating) {
  2685. // if toggled before hydration is finished, the current DOM tree is
  2686. // no longer valid. set it as the active branch so it will be unmounted
  2687. // when resolved
  2688. suspense.isHydrating = false;
  2689. suspense.activeBranch = pendingBranch;
  2690. }
  2691. else {
  2692. unmount(pendingBranch, parentComponent, suspense);
  2693. }
  2694. // increment pending ID. this is used to invalidate async callbacks
  2695. // reset suspense state
  2696. suspense.deps = 0;
  2697. // discard effects from pending branch
  2698. suspense.effects.length = 0;
  2699. // discard previous container
  2700. suspense.hiddenContainer = createElement('div');
  2701. if (isInFallback) {
  2702. // already in fallback state
  2703. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2704. if (suspense.deps <= 0) {
  2705. suspense.resolve();
  2706. }
  2707. else {
  2708. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2709. isSVG, slotScopeIds, optimized);
  2710. setActiveBranch(suspense, newFallback);
  2711. }
  2712. }
  2713. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2714. // toggled "back" to current active branch
  2715. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2716. // force resolve
  2717. suspense.resolve(true);
  2718. }
  2719. else {
  2720. // switched to a 3rd branch
  2721. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2722. if (suspense.deps <= 0) {
  2723. suspense.resolve();
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else {
  2729. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2730. // root did not change, just normal patch
  2731. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2732. setActiveBranch(suspense, newBranch);
  2733. }
  2734. else {
  2735. // root node toggled
  2736. // invoke @pending event
  2737. triggerEvent(n2, 'onPending');
  2738. // mount pending branch in off-dom container
  2739. suspense.pendingBranch = newBranch;
  2740. suspense.pendingId++;
  2741. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2742. if (suspense.deps <= 0) {
  2743. // incoming branch has no async deps, resolve now.
  2744. suspense.resolve();
  2745. }
  2746. else {
  2747. const { timeout, pendingId } = suspense;
  2748. if (timeout > 0) {
  2749. setTimeout(() => {
  2750. if (suspense.pendingId === pendingId) {
  2751. suspense.fallback(newFallback);
  2752. }
  2753. }, timeout);
  2754. }
  2755. else if (timeout === 0) {
  2756. suspense.fallback(newFallback);
  2757. }
  2758. }
  2759. }
  2760. }
  2761. }
  2762. let hasWarned = false;
  2763. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2764. /* istanbul ignore if */
  2765. if (!hasWarned) {
  2766. hasWarned = true;
  2767. // @ts-ignore `console.info` cannot be null error
  2768. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2769. }
  2770. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2771. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2772. const suspense = {
  2773. vnode,
  2774. parent,
  2775. parentComponent,
  2776. isSVG,
  2777. container,
  2778. hiddenContainer,
  2779. anchor,
  2780. deps: 0,
  2781. pendingId: 0,
  2782. timeout: typeof timeout === 'number' ? timeout : -1,
  2783. activeBranch: null,
  2784. pendingBranch: null,
  2785. isInFallback: true,
  2786. isHydrating,
  2787. isUnmounted: false,
  2788. effects: [],
  2789. resolve(resume = false) {
  2790. {
  2791. if (!resume && !suspense.pendingBranch) {
  2792. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2793. }
  2794. if (suspense.isUnmounted) {
  2795. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2796. }
  2797. }
  2798. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2799. if (suspense.isHydrating) {
  2800. suspense.isHydrating = false;
  2801. }
  2802. else if (!resume) {
  2803. const delayEnter = activeBranch &&
  2804. pendingBranch.transition &&
  2805. pendingBranch.transition.mode === 'out-in';
  2806. if (delayEnter) {
  2807. activeBranch.transition.afterLeave = () => {
  2808. if (pendingId === suspense.pendingId) {
  2809. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2810. }
  2811. };
  2812. }
  2813. // this is initial anchor on mount
  2814. let { anchor } = suspense;
  2815. // unmount current active tree
  2816. if (activeBranch) {
  2817. // if the fallback tree was mounted, it may have been moved
  2818. // as part of a parent suspense. get the latest anchor for insertion
  2819. anchor = next(activeBranch);
  2820. unmount(activeBranch, parentComponent, suspense, true);
  2821. }
  2822. if (!delayEnter) {
  2823. // move content from off-dom container to actual container
  2824. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2825. }
  2826. }
  2827. setActiveBranch(suspense, pendingBranch);
  2828. suspense.pendingBranch = null;
  2829. suspense.isInFallback = false;
  2830. // flush buffered effects
  2831. // check if there is a pending parent suspense
  2832. let parent = suspense.parent;
  2833. let hasUnresolvedAncestor = false;
  2834. while (parent) {
  2835. if (parent.pendingBranch) {
  2836. // found a pending parent suspense, merge buffered post jobs
  2837. // into that parent
  2838. parent.effects.push(...effects);
  2839. hasUnresolvedAncestor = true;
  2840. break;
  2841. }
  2842. parent = parent.parent;
  2843. }
  2844. // no pending parent suspense, flush all jobs
  2845. if (!hasUnresolvedAncestor) {
  2846. queuePostFlushCb(effects);
  2847. }
  2848. suspense.effects = [];
  2849. // invoke @resolve event
  2850. triggerEvent(vnode, 'onResolve');
  2851. },
  2852. fallback(fallbackVNode) {
  2853. if (!suspense.pendingBranch) {
  2854. return;
  2855. }
  2856. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2857. // invoke @fallback event
  2858. triggerEvent(vnode, 'onFallback');
  2859. const anchor = next(activeBranch);
  2860. const mountFallback = () => {
  2861. if (!suspense.isInFallback) {
  2862. return;
  2863. }
  2864. // mount the fallback tree
  2865. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2866. isSVG, slotScopeIds, optimized);
  2867. setActiveBranch(suspense, fallbackVNode);
  2868. };
  2869. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2870. if (delayEnter) {
  2871. activeBranch.transition.afterLeave = mountFallback;
  2872. }
  2873. suspense.isInFallback = true;
  2874. // unmount current active branch
  2875. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2876. true // shouldRemove
  2877. );
  2878. if (!delayEnter) {
  2879. mountFallback();
  2880. }
  2881. },
  2882. move(container, anchor, type) {
  2883. suspense.activeBranch &&
  2884. move(suspense.activeBranch, container, anchor, type);
  2885. suspense.container = container;
  2886. },
  2887. next() {
  2888. return suspense.activeBranch && next(suspense.activeBranch);
  2889. },
  2890. registerDep(instance, setupRenderEffect) {
  2891. const isInPendingSuspense = !!suspense.pendingBranch;
  2892. if (isInPendingSuspense) {
  2893. suspense.deps++;
  2894. }
  2895. const hydratedEl = instance.vnode.el;
  2896. instance
  2897. .asyncDep.catch(err => {
  2898. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  2899. })
  2900. .then(asyncSetupResult => {
  2901. // retry when the setup() promise resolves.
  2902. // component may have been unmounted before resolve.
  2903. if (instance.isUnmounted ||
  2904. suspense.isUnmounted ||
  2905. suspense.pendingId !== instance.suspenseId) {
  2906. return;
  2907. }
  2908. // retry from this component
  2909. instance.asyncResolved = true;
  2910. const { vnode } = instance;
  2911. {
  2912. pushWarningContext(vnode);
  2913. }
  2914. handleSetupResult(instance, asyncSetupResult, false);
  2915. if (hydratedEl) {
  2916. // vnode may have been replaced if an update happened before the
  2917. // async dep is resolved.
  2918. vnode.el = hydratedEl;
  2919. }
  2920. const placeholder = !hydratedEl && instance.subTree.el;
  2921. setupRenderEffect(instance, vnode,
  2922. // component may have been moved before resolve.
  2923. // if this is not a hydration, instance.subTree will be the comment
  2924. // placeholder.
  2925. parentNode(hydratedEl || instance.subTree.el),
  2926. // anchor will not be used if this is hydration, so only need to
  2927. // consider the comment placeholder case.
  2928. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2929. if (placeholder) {
  2930. remove(placeholder);
  2931. }
  2932. updateHOCHostEl(instance, vnode.el);
  2933. {
  2934. popWarningContext();
  2935. }
  2936. // only decrease deps count if suspense is not already resolved
  2937. if (isInPendingSuspense && --suspense.deps === 0) {
  2938. suspense.resolve();
  2939. }
  2940. });
  2941. },
  2942. unmount(parentSuspense, doRemove) {
  2943. suspense.isUnmounted = true;
  2944. if (suspense.activeBranch) {
  2945. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2946. }
  2947. if (suspense.pendingBranch) {
  2948. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2949. }
  2950. }
  2951. };
  2952. return suspense;
  2953. }
  2954. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  2955. /* eslint-disable no-restricted-globals */
  2956. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  2957. // there are two possible scenarios for server-rendered suspense:
  2958. // - success: ssr content should be fully resolved
  2959. // - failure: ssr content should be the fallback branch.
  2960. // however, on the client we don't really know if it has failed or not
  2961. // attempt to hydrate the DOM assuming it has succeeded, but we still
  2962. // need to construct a suspense boundary first
  2963. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  2964. if (suspense.deps === 0) {
  2965. suspense.resolve();
  2966. }
  2967. return result;
  2968. /* eslint-enable no-restricted-globals */
  2969. }
  2970. function normalizeSuspenseChildren(vnode) {
  2971. const { shapeFlag, children } = vnode;
  2972. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  2973. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  2974. vnode.ssFallback = isSlotChildren
  2975. ? normalizeSuspenseSlot(children.fallback)
  2976. : createVNode(Comment);
  2977. }
  2978. function normalizeSuspenseSlot(s) {
  2979. let block;
  2980. if (isFunction(s)) {
  2981. const trackBlock = isBlockTreeEnabled && s._c;
  2982. if (trackBlock) {
  2983. // disableTracking: false
  2984. // allow block tracking for compiled slots
  2985. // (see ./componentRenderContext.ts)
  2986. s._d = false;
  2987. openBlock();
  2988. }
  2989. s = s();
  2990. if (trackBlock) {
  2991. s._d = true;
  2992. block = currentBlock;
  2993. closeBlock();
  2994. }
  2995. }
  2996. if (isArray(s)) {
  2997. const singleChild = filterSingleRoot(s);
  2998. if (!singleChild) {
  2999. warn$1(`<Suspense> slots expect a single root node.`);
  3000. }
  3001. s = singleChild;
  3002. }
  3003. s = normalizeVNode(s);
  3004. if (block && !s.dynamicChildren) {
  3005. s.dynamicChildren = block.filter(c => c !== s);
  3006. }
  3007. return s;
  3008. }
  3009. function queueEffectWithSuspense(fn, suspense) {
  3010. if (suspense && suspense.pendingBranch) {
  3011. if (isArray(fn)) {
  3012. suspense.effects.push(...fn);
  3013. }
  3014. else {
  3015. suspense.effects.push(fn);
  3016. }
  3017. }
  3018. else {
  3019. queuePostFlushCb(fn);
  3020. }
  3021. }
  3022. function setActiveBranch(suspense, branch) {
  3023. suspense.activeBranch = branch;
  3024. const { vnode, parentComponent } = suspense;
  3025. const el = (vnode.el = branch.el);
  3026. // in case suspense is the root node of a component,
  3027. // recursively update the HOC el
  3028. if (parentComponent && parentComponent.subTree === vnode) {
  3029. parentComponent.vnode.el = el;
  3030. updateHOCHostEl(parentComponent, el);
  3031. }
  3032. }
  3033. function provide(key, value) {
  3034. if (!currentInstance) {
  3035. {
  3036. warn$1(`provide() can only be used inside setup().`);
  3037. }
  3038. }
  3039. else {
  3040. let provides = currentInstance.provides;
  3041. // by default an instance inherits its parent's provides object
  3042. // but when it needs to provide values of its own, it creates its
  3043. // own provides object using parent provides object as prototype.
  3044. // this way in `inject` we can simply look up injections from direct
  3045. // parent and let the prototype chain do the work.
  3046. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3047. if (parentProvides === provides) {
  3048. provides = currentInstance.provides = Object.create(parentProvides);
  3049. }
  3050. // TS doesn't allow symbol as index type
  3051. provides[key] = value;
  3052. }
  3053. }
  3054. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3055. // fallback to `currentRenderingInstance` so that this can be called in
  3056. // a functional component
  3057. const instance = currentInstance || currentRenderingInstance;
  3058. if (instance) {
  3059. // #2400
  3060. // to support `app.use` plugins,
  3061. // fallback to appContext's `provides` if the instance is at root
  3062. const provides = instance.parent == null
  3063. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3064. : instance.parent.provides;
  3065. if (provides && key in provides) {
  3066. // TS doesn't allow symbol as index type
  3067. return provides[key];
  3068. }
  3069. else if (arguments.length > 1) {
  3070. return treatDefaultAsFactory && isFunction(defaultValue)
  3071. ? defaultValue.call(instance.proxy)
  3072. : defaultValue;
  3073. }
  3074. else {
  3075. warn$1(`injection "${String(key)}" not found.`);
  3076. }
  3077. }
  3078. else {
  3079. warn$1(`inject() can only be used inside setup() or functional components.`);
  3080. }
  3081. }
  3082. // Simple effect.
  3083. function watchEffect(effect, options) {
  3084. return doWatch(effect, null, options);
  3085. }
  3086. function watchPostEffect(effect, options) {
  3087. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'post' }) ));
  3088. }
  3089. function watchSyncEffect(effect, options) {
  3090. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'sync' }) ));
  3091. }
  3092. // initial value for watchers to trigger on undefined initial values
  3093. const INITIAL_WATCHER_VALUE = {};
  3094. // implementation
  3095. function watch(source, cb, options) {
  3096. if (!isFunction(cb)) {
  3097. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3098. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3099. `supports \`watch(source, cb, options?) signature.`);
  3100. }
  3101. return doWatch(source, cb, options);
  3102. }
  3103. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3104. if (!cb) {
  3105. if (immediate !== undefined) {
  3106. warn$1(`watch() "immediate" option is only respected when using the ` +
  3107. `watch(source, callback, options?) signature.`);
  3108. }
  3109. if (deep !== undefined) {
  3110. warn$1(`watch() "deep" option is only respected when using the ` +
  3111. `watch(source, callback, options?) signature.`);
  3112. }
  3113. }
  3114. const warnInvalidSource = (s) => {
  3115. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3116. `a reactive object, or an array of these types.`);
  3117. };
  3118. const instance = currentInstance;
  3119. let getter;
  3120. let forceTrigger = false;
  3121. let isMultiSource = false;
  3122. if (isRef(source)) {
  3123. getter = () => source.value;
  3124. forceTrigger = isShallow(source);
  3125. }
  3126. else if (isReactive(source)) {
  3127. getter = () => source;
  3128. deep = true;
  3129. }
  3130. else if (isArray(source)) {
  3131. isMultiSource = true;
  3132. forceTrigger = source.some(isReactive);
  3133. getter = () => source.map(s => {
  3134. if (isRef(s)) {
  3135. return s.value;
  3136. }
  3137. else if (isReactive(s)) {
  3138. return traverse(s);
  3139. }
  3140. else if (isFunction(s)) {
  3141. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  3142. }
  3143. else {
  3144. warnInvalidSource(s);
  3145. }
  3146. });
  3147. }
  3148. else if (isFunction(source)) {
  3149. if (cb) {
  3150. // getter with cb
  3151. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  3152. }
  3153. else {
  3154. // no cb -> simple effect
  3155. getter = () => {
  3156. if (instance && instance.isUnmounted) {
  3157. return;
  3158. }
  3159. if (cleanup) {
  3160. cleanup();
  3161. }
  3162. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onCleanup]);
  3163. };
  3164. }
  3165. }
  3166. else {
  3167. getter = NOOP;
  3168. warnInvalidSource(source);
  3169. }
  3170. if (cb && deep) {
  3171. const baseGetter = getter;
  3172. getter = () => traverse(baseGetter());
  3173. }
  3174. let cleanup;
  3175. let onCleanup = (fn) => {
  3176. cleanup = effect.onStop = () => {
  3177. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  3178. };
  3179. };
  3180. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  3181. const job = () => {
  3182. if (!effect.active) {
  3183. return;
  3184. }
  3185. if (cb) {
  3186. // watch(source, cb)
  3187. const newValue = effect.run();
  3188. if (deep ||
  3189. forceTrigger ||
  3190. (isMultiSource
  3191. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3192. : hasChanged(newValue, oldValue)) ||
  3193. (false )) {
  3194. // cleanup before running cb again
  3195. if (cleanup) {
  3196. cleanup();
  3197. }
  3198. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  3199. newValue,
  3200. // pass undefined as the old value when it's changed for the first time
  3201. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  3202. onCleanup
  3203. ]);
  3204. oldValue = newValue;
  3205. }
  3206. }
  3207. else {
  3208. // watchEffect
  3209. effect.run();
  3210. }
  3211. };
  3212. // important: mark the job as a watcher callback so that scheduler knows
  3213. // it is allowed to self-trigger (#1727)
  3214. job.allowRecurse = !!cb;
  3215. let scheduler;
  3216. if (flush === 'sync') {
  3217. scheduler = job; // the scheduler function gets called directly
  3218. }
  3219. else if (flush === 'post') {
  3220. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3221. }
  3222. else {
  3223. // default: 'pre'
  3224. scheduler = () => {
  3225. if (!instance || instance.isMounted) {
  3226. queuePreFlushCb(job);
  3227. }
  3228. else {
  3229. // with 'pre' option, the first call must happen before
  3230. // the component is mounted so it is called synchronously.
  3231. job();
  3232. }
  3233. };
  3234. }
  3235. const effect = new ReactiveEffect(getter, scheduler);
  3236. {
  3237. effect.onTrack = onTrack;
  3238. effect.onTrigger = onTrigger;
  3239. }
  3240. // initial run
  3241. if (cb) {
  3242. if (immediate) {
  3243. job();
  3244. }
  3245. else {
  3246. oldValue = effect.run();
  3247. }
  3248. }
  3249. else if (flush === 'post') {
  3250. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3251. }
  3252. else {
  3253. effect.run();
  3254. }
  3255. return () => {
  3256. effect.stop();
  3257. if (instance && instance.scope) {
  3258. remove(instance.scope.effects, effect);
  3259. }
  3260. };
  3261. }
  3262. // this.$watch
  3263. function instanceWatch(source, value, options) {
  3264. const publicThis = this.proxy;
  3265. const getter = isString(source)
  3266. ? source.includes('.')
  3267. ? createPathGetter(publicThis, source)
  3268. : () => publicThis[source]
  3269. : source.bind(publicThis, publicThis);
  3270. let cb;
  3271. if (isFunction(value)) {
  3272. cb = value;
  3273. }
  3274. else {
  3275. cb = value.handler;
  3276. options = value;
  3277. }
  3278. const cur = currentInstance;
  3279. setCurrentInstance(this);
  3280. const res = doWatch(getter, cb.bind(publicThis), options);
  3281. if (cur) {
  3282. setCurrentInstance(cur);
  3283. }
  3284. else {
  3285. unsetCurrentInstance();
  3286. }
  3287. return res;
  3288. }
  3289. function createPathGetter(ctx, path) {
  3290. const segments = path.split('.');
  3291. return () => {
  3292. let cur = ctx;
  3293. for (let i = 0; i < segments.length && cur; i++) {
  3294. cur = cur[segments[i]];
  3295. }
  3296. return cur;
  3297. };
  3298. }
  3299. function traverse(value, seen) {
  3300. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  3301. return value;
  3302. }
  3303. seen = seen || new Set();
  3304. if (seen.has(value)) {
  3305. return value;
  3306. }
  3307. seen.add(value);
  3308. if (isRef(value)) {
  3309. traverse(value.value, seen);
  3310. }
  3311. else if (isArray(value)) {
  3312. for (let i = 0; i < value.length; i++) {
  3313. traverse(value[i], seen);
  3314. }
  3315. }
  3316. else if (isSet(value) || isMap(value)) {
  3317. value.forEach((v) => {
  3318. traverse(v, seen);
  3319. });
  3320. }
  3321. else if (isPlainObject(value)) {
  3322. for (const key in value) {
  3323. traverse(value[key], seen);
  3324. }
  3325. }
  3326. return value;
  3327. }
  3328. function useTransitionState() {
  3329. const state = {
  3330. isMounted: false,
  3331. isLeaving: false,
  3332. isUnmounting: false,
  3333. leavingVNodes: new Map()
  3334. };
  3335. onMounted(() => {
  3336. state.isMounted = true;
  3337. });
  3338. onBeforeUnmount(() => {
  3339. state.isUnmounting = true;
  3340. });
  3341. return state;
  3342. }
  3343. const TransitionHookValidator = [Function, Array];
  3344. const BaseTransitionImpl = {
  3345. name: `BaseTransition`,
  3346. props: {
  3347. mode: String,
  3348. appear: Boolean,
  3349. persisted: Boolean,
  3350. // enter
  3351. onBeforeEnter: TransitionHookValidator,
  3352. onEnter: TransitionHookValidator,
  3353. onAfterEnter: TransitionHookValidator,
  3354. onEnterCancelled: TransitionHookValidator,
  3355. // leave
  3356. onBeforeLeave: TransitionHookValidator,
  3357. onLeave: TransitionHookValidator,
  3358. onAfterLeave: TransitionHookValidator,
  3359. onLeaveCancelled: TransitionHookValidator,
  3360. // appear
  3361. onBeforeAppear: TransitionHookValidator,
  3362. onAppear: TransitionHookValidator,
  3363. onAfterAppear: TransitionHookValidator,
  3364. onAppearCancelled: TransitionHookValidator
  3365. },
  3366. setup(props, { slots }) {
  3367. const instance = getCurrentInstance();
  3368. const state = useTransitionState();
  3369. let prevTransitionKey;
  3370. return () => {
  3371. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3372. if (!children || !children.length) {
  3373. return;
  3374. }
  3375. let child = children[0];
  3376. if (children.length > 1) {
  3377. let hasFound = false;
  3378. // locate first non-comment child
  3379. for (const c of children) {
  3380. if (c.type !== Comment) {
  3381. if (hasFound) {
  3382. // warn more than one non-comment child
  3383. warn$1('<transition> can only be used on a single element or component. ' +
  3384. 'Use <transition-group> for lists.');
  3385. break;
  3386. }
  3387. child = c;
  3388. hasFound = true;
  3389. }
  3390. }
  3391. }
  3392. // there's no need to track reactivity for these props so use the raw
  3393. // props for a bit better perf
  3394. const rawProps = toRaw(props);
  3395. const { mode } = rawProps;
  3396. // check mode
  3397. if (mode &&
  3398. mode !== 'in-out' &&
  3399. mode !== 'out-in' &&
  3400. mode !== 'default') {
  3401. warn$1(`invalid <transition> mode: ${mode}`);
  3402. }
  3403. if (state.isLeaving) {
  3404. return emptyPlaceholder(child);
  3405. }
  3406. // in the case of <transition><keep-alive/></transition>, we need to
  3407. // compare the type of the kept-alive children.
  3408. const innerChild = getKeepAliveChild(child);
  3409. if (!innerChild) {
  3410. return emptyPlaceholder(child);
  3411. }
  3412. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3413. setTransitionHooks(innerChild, enterHooks);
  3414. const oldChild = instance.subTree;
  3415. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3416. let transitionKeyChanged = false;
  3417. const { getTransitionKey } = innerChild.type;
  3418. if (getTransitionKey) {
  3419. const key = getTransitionKey();
  3420. if (prevTransitionKey === undefined) {
  3421. prevTransitionKey = key;
  3422. }
  3423. else if (key !== prevTransitionKey) {
  3424. prevTransitionKey = key;
  3425. transitionKeyChanged = true;
  3426. }
  3427. }
  3428. // handle mode
  3429. if (oldInnerChild &&
  3430. oldInnerChild.type !== Comment &&
  3431. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3432. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3433. // update old tree's hooks in case of dynamic transition
  3434. setTransitionHooks(oldInnerChild, leavingHooks);
  3435. // switching between different views
  3436. if (mode === 'out-in') {
  3437. state.isLeaving = true;
  3438. // return placeholder node and queue update when leave finishes
  3439. leavingHooks.afterLeave = () => {
  3440. state.isLeaving = false;
  3441. instance.update();
  3442. };
  3443. return emptyPlaceholder(child);
  3444. }
  3445. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3446. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3447. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3448. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3449. // early removal callback
  3450. el._leaveCb = () => {
  3451. earlyRemove();
  3452. el._leaveCb = undefined;
  3453. delete enterHooks.delayedLeave;
  3454. };
  3455. enterHooks.delayedLeave = delayedLeave;
  3456. };
  3457. }
  3458. }
  3459. return child;
  3460. };
  3461. }
  3462. };
  3463. // export the public type for h/tsx inference
  3464. // also to avoid inline import() in generated d.ts files
  3465. const BaseTransition = BaseTransitionImpl;
  3466. function getLeavingNodesForType(state, vnode) {
  3467. const { leavingVNodes } = state;
  3468. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3469. if (!leavingVNodesCache) {
  3470. leavingVNodesCache = Object.create(null);
  3471. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3472. }
  3473. return leavingVNodesCache;
  3474. }
  3475. // The transition hooks are attached to the vnode as vnode.transition
  3476. // and will be called at appropriate timing in the renderer.
  3477. function resolveTransitionHooks(vnode, props, state, instance) {
  3478. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3479. const key = String(vnode.key);
  3480. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3481. const callHook = (hook, args) => {
  3482. hook &&
  3483. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3484. };
  3485. const hooks = {
  3486. mode,
  3487. persisted,
  3488. beforeEnter(el) {
  3489. let hook = onBeforeEnter;
  3490. if (!state.isMounted) {
  3491. if (appear) {
  3492. hook = onBeforeAppear || onBeforeEnter;
  3493. }
  3494. else {
  3495. return;
  3496. }
  3497. }
  3498. // for same element (v-show)
  3499. if (el._leaveCb) {
  3500. el._leaveCb(true /* cancelled */);
  3501. }
  3502. // for toggled element with same key (v-if)
  3503. const leavingVNode = leavingVNodesCache[key];
  3504. if (leavingVNode &&
  3505. isSameVNodeType(vnode, leavingVNode) &&
  3506. leavingVNode.el._leaveCb) {
  3507. // force early removal (not cancelled)
  3508. leavingVNode.el._leaveCb();
  3509. }
  3510. callHook(hook, [el]);
  3511. },
  3512. enter(el) {
  3513. let hook = onEnter;
  3514. let afterHook = onAfterEnter;
  3515. let cancelHook = onEnterCancelled;
  3516. if (!state.isMounted) {
  3517. if (appear) {
  3518. hook = onAppear || onEnter;
  3519. afterHook = onAfterAppear || onAfterEnter;
  3520. cancelHook = onAppearCancelled || onEnterCancelled;
  3521. }
  3522. else {
  3523. return;
  3524. }
  3525. }
  3526. let called = false;
  3527. const done = (el._enterCb = (cancelled) => {
  3528. if (called)
  3529. return;
  3530. called = true;
  3531. if (cancelled) {
  3532. callHook(cancelHook, [el]);
  3533. }
  3534. else {
  3535. callHook(afterHook, [el]);
  3536. }
  3537. if (hooks.delayedLeave) {
  3538. hooks.delayedLeave();
  3539. }
  3540. el._enterCb = undefined;
  3541. });
  3542. if (hook) {
  3543. hook(el, done);
  3544. if (hook.length <= 1) {
  3545. done();
  3546. }
  3547. }
  3548. else {
  3549. done();
  3550. }
  3551. },
  3552. leave(el, remove) {
  3553. const key = String(vnode.key);
  3554. if (el._enterCb) {
  3555. el._enterCb(true /* cancelled */);
  3556. }
  3557. if (state.isUnmounting) {
  3558. return remove();
  3559. }
  3560. callHook(onBeforeLeave, [el]);
  3561. let called = false;
  3562. const done = (el._leaveCb = (cancelled) => {
  3563. if (called)
  3564. return;
  3565. called = true;
  3566. remove();
  3567. if (cancelled) {
  3568. callHook(onLeaveCancelled, [el]);
  3569. }
  3570. else {
  3571. callHook(onAfterLeave, [el]);
  3572. }
  3573. el._leaveCb = undefined;
  3574. if (leavingVNodesCache[key] === vnode) {
  3575. delete leavingVNodesCache[key];
  3576. }
  3577. });
  3578. leavingVNodesCache[key] = vnode;
  3579. if (onLeave) {
  3580. onLeave(el, done);
  3581. if (onLeave.length <= 1) {
  3582. done();
  3583. }
  3584. }
  3585. else {
  3586. done();
  3587. }
  3588. },
  3589. clone(vnode) {
  3590. return resolveTransitionHooks(vnode, props, state, instance);
  3591. }
  3592. };
  3593. return hooks;
  3594. }
  3595. // the placeholder really only handles one special case: KeepAlive
  3596. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3597. // placeholder with empty content to avoid the KeepAlive instance from being
  3598. // unmounted.
  3599. function emptyPlaceholder(vnode) {
  3600. if (isKeepAlive(vnode)) {
  3601. vnode = cloneVNode(vnode);
  3602. vnode.children = null;
  3603. return vnode;
  3604. }
  3605. }
  3606. function getKeepAliveChild(vnode) {
  3607. return isKeepAlive(vnode)
  3608. ? vnode.children
  3609. ? vnode.children[0]
  3610. : undefined
  3611. : vnode;
  3612. }
  3613. function setTransitionHooks(vnode, hooks) {
  3614. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3615. setTransitionHooks(vnode.component.subTree, hooks);
  3616. }
  3617. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3618. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3619. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3620. }
  3621. else {
  3622. vnode.transition = hooks;
  3623. }
  3624. }
  3625. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3626. let ret = [];
  3627. let keyedFragmentCount = 0;
  3628. for (let i = 0; i < children.length; i++) {
  3629. let child = children[i];
  3630. // #5360 inherit parent key in case of <template v-for>
  3631. const key = parentKey == null
  3632. ? child.key
  3633. : String(parentKey) + String(child.key != null ? child.key : i);
  3634. // handle fragment children case, e.g. v-for
  3635. if (child.type === Fragment) {
  3636. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  3637. keyedFragmentCount++;
  3638. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3639. }
  3640. // comment placeholders should be skipped, e.g. v-if
  3641. else if (keepComment || child.type !== Comment) {
  3642. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3643. }
  3644. }
  3645. // #1126 if a transition children list contains multiple sub fragments, these
  3646. // fragments will be merged into a flat children array. Since each v-for
  3647. // fragment may contain different static bindings inside, we need to de-op
  3648. // these children to force full diffs to ensure correct behavior.
  3649. if (keyedFragmentCount > 1) {
  3650. for (let i = 0; i < ret.length; i++) {
  3651. ret[i].patchFlag = -2 /* BAIL */;
  3652. }
  3653. }
  3654. return ret;
  3655. }
  3656. // implementation, close to no-op
  3657. function defineComponent(options) {
  3658. return isFunction(options) ? { setup: options, name: options.name } : options;
  3659. }
  3660. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3661. function defineAsyncComponent(source) {
  3662. if (isFunction(source)) {
  3663. source = { loader: source };
  3664. }
  3665. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3666. suspensible = true, onError: userOnError } = source;
  3667. let pendingRequest = null;
  3668. let resolvedComp;
  3669. let retries = 0;
  3670. const retry = () => {
  3671. retries++;
  3672. pendingRequest = null;
  3673. return load();
  3674. };
  3675. const load = () => {
  3676. let thisRequest;
  3677. return (pendingRequest ||
  3678. (thisRequest = pendingRequest =
  3679. loader()
  3680. .catch(err => {
  3681. err = err instanceof Error ? err : new Error(String(err));
  3682. if (userOnError) {
  3683. return new Promise((resolve, reject) => {
  3684. const userRetry = () => resolve(retry());
  3685. const userFail = () => reject(err);
  3686. userOnError(err, userRetry, userFail, retries + 1);
  3687. });
  3688. }
  3689. else {
  3690. throw err;
  3691. }
  3692. })
  3693. .then((comp) => {
  3694. if (thisRequest !== pendingRequest && pendingRequest) {
  3695. return pendingRequest;
  3696. }
  3697. if (!comp) {
  3698. warn$1(`Async component loader resolved to undefined. ` +
  3699. `If you are using retry(), make sure to return its return value.`);
  3700. }
  3701. // interop module default
  3702. if (comp &&
  3703. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3704. comp = comp.default;
  3705. }
  3706. if (comp && !isObject(comp) && !isFunction(comp)) {
  3707. throw new Error(`Invalid async component load result: ${comp}`);
  3708. }
  3709. resolvedComp = comp;
  3710. return comp;
  3711. })));
  3712. };
  3713. return defineComponent({
  3714. name: 'AsyncComponentWrapper',
  3715. __asyncLoader: load,
  3716. get __asyncResolved() {
  3717. return resolvedComp;
  3718. },
  3719. setup() {
  3720. const instance = currentInstance;
  3721. // already resolved
  3722. if (resolvedComp) {
  3723. return () => createInnerComp(resolvedComp, instance);
  3724. }
  3725. const onError = (err) => {
  3726. pendingRequest = null;
  3727. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3728. };
  3729. // suspense-controlled or SSR.
  3730. if ((suspensible && instance.suspense) ||
  3731. (false )) {
  3732. return load()
  3733. .then(comp => {
  3734. return () => createInnerComp(comp, instance);
  3735. })
  3736. .catch(err => {
  3737. onError(err);
  3738. return () => errorComponent
  3739. ? createVNode(errorComponent, {
  3740. error: err
  3741. })
  3742. : null;
  3743. });
  3744. }
  3745. const loaded = ref(false);
  3746. const error = ref();
  3747. const delayed = ref(!!delay);
  3748. if (delay) {
  3749. setTimeout(() => {
  3750. delayed.value = false;
  3751. }, delay);
  3752. }
  3753. if (timeout != null) {
  3754. setTimeout(() => {
  3755. if (!loaded.value && !error.value) {
  3756. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3757. onError(err);
  3758. error.value = err;
  3759. }
  3760. }, timeout);
  3761. }
  3762. load()
  3763. .then(() => {
  3764. loaded.value = true;
  3765. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3766. // parent is keep-alive, force update so the loaded component's
  3767. // name is taken into account
  3768. queueJob(instance.parent.update);
  3769. }
  3770. })
  3771. .catch(err => {
  3772. onError(err);
  3773. error.value = err;
  3774. });
  3775. return () => {
  3776. if (loaded.value && resolvedComp) {
  3777. return createInnerComp(resolvedComp, instance);
  3778. }
  3779. else if (error.value && errorComponent) {
  3780. return createVNode(errorComponent, {
  3781. error: error.value
  3782. });
  3783. }
  3784. else if (loadingComponent && !delayed.value) {
  3785. return createVNode(loadingComponent);
  3786. }
  3787. };
  3788. }
  3789. });
  3790. }
  3791. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  3792. const vnode = createVNode(comp, props, children);
  3793. // ensure inner component inherits the async wrapper's ref owner
  3794. vnode.ref = ref;
  3795. return vnode;
  3796. }
  3797. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3798. const KeepAliveImpl = {
  3799. name: `KeepAlive`,
  3800. // Marker for special handling inside the renderer. We are not using a ===
  3801. // check directly on KeepAlive in the renderer, because importing it directly
  3802. // would prevent it from being tree-shaken.
  3803. __isKeepAlive: true,
  3804. props: {
  3805. include: [String, RegExp, Array],
  3806. exclude: [String, RegExp, Array],
  3807. max: [String, Number]
  3808. },
  3809. setup(props, { slots }) {
  3810. const instance = getCurrentInstance();
  3811. // KeepAlive communicates with the instantiated renderer via the
  3812. // ctx where the renderer passes in its internals,
  3813. // and the KeepAlive instance exposes activate/deactivate implementations.
  3814. // The whole point of this is to avoid importing KeepAlive directly in the
  3815. // renderer to facilitate tree-shaking.
  3816. const sharedContext = instance.ctx;
  3817. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  3818. // for KeepAlive, we just need to render its children
  3819. if (!sharedContext.renderer) {
  3820. return slots.default;
  3821. }
  3822. const cache = new Map();
  3823. const keys = new Set();
  3824. let current = null;
  3825. {
  3826. instance.__v_cache = cache;
  3827. }
  3828. const parentSuspense = instance.suspense;
  3829. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3830. const storageContainer = createElement('div');
  3831. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3832. const instance = vnode.component;
  3833. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3834. // in case props have changed
  3835. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3836. queuePostRenderEffect(() => {
  3837. instance.isDeactivated = false;
  3838. if (instance.a) {
  3839. invokeArrayFns(instance.a);
  3840. }
  3841. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3842. if (vnodeHook) {
  3843. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3844. }
  3845. }, parentSuspense);
  3846. {
  3847. // Update components tree
  3848. devtoolsComponentAdded(instance);
  3849. }
  3850. };
  3851. sharedContext.deactivate = (vnode) => {
  3852. const instance = vnode.component;
  3853. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3854. queuePostRenderEffect(() => {
  3855. if (instance.da) {
  3856. invokeArrayFns(instance.da);
  3857. }
  3858. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3859. if (vnodeHook) {
  3860. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3861. }
  3862. instance.isDeactivated = true;
  3863. }, parentSuspense);
  3864. {
  3865. // Update components tree
  3866. devtoolsComponentAdded(instance);
  3867. }
  3868. };
  3869. function unmount(vnode) {
  3870. // reset the shapeFlag so it can be properly unmounted
  3871. resetShapeFlag(vnode);
  3872. _unmount(vnode, instance, parentSuspense, true);
  3873. }
  3874. function pruneCache(filter) {
  3875. cache.forEach((vnode, key) => {
  3876. const name = getComponentName(vnode.type);
  3877. if (name && (!filter || !filter(name))) {
  3878. pruneCacheEntry(key);
  3879. }
  3880. });
  3881. }
  3882. function pruneCacheEntry(key) {
  3883. const cached = cache.get(key);
  3884. if (!current || cached.type !== current.type) {
  3885. unmount(cached);
  3886. }
  3887. else if (current) {
  3888. // current active instance should no longer be kept-alive.
  3889. // we can't unmount it now but it might be later, so reset its flag now.
  3890. resetShapeFlag(current);
  3891. }
  3892. cache.delete(key);
  3893. keys.delete(key);
  3894. }
  3895. // prune cache on include/exclude prop change
  3896. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3897. include && pruneCache(name => matches(include, name));
  3898. exclude && pruneCache(name => !matches(exclude, name));
  3899. },
  3900. // prune post-render after `current` has been updated
  3901. { flush: 'post', deep: true });
  3902. // cache sub tree after render
  3903. let pendingCacheKey = null;
  3904. const cacheSubtree = () => {
  3905. // fix #1621, the pendingCacheKey could be 0
  3906. if (pendingCacheKey != null) {
  3907. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3908. }
  3909. };
  3910. onMounted(cacheSubtree);
  3911. onUpdated(cacheSubtree);
  3912. onBeforeUnmount(() => {
  3913. cache.forEach(cached => {
  3914. const { subTree, suspense } = instance;
  3915. const vnode = getInnerChild(subTree);
  3916. if (cached.type === vnode.type) {
  3917. // current instance will be unmounted as part of keep-alive's unmount
  3918. resetShapeFlag(vnode);
  3919. // but invoke its deactivated hook here
  3920. const da = vnode.component.da;
  3921. da && queuePostRenderEffect(da, suspense);
  3922. return;
  3923. }
  3924. unmount(cached);
  3925. });
  3926. });
  3927. return () => {
  3928. pendingCacheKey = null;
  3929. if (!slots.default) {
  3930. return null;
  3931. }
  3932. const children = slots.default();
  3933. const rawVNode = children[0];
  3934. if (children.length > 1) {
  3935. {
  3936. warn$1(`KeepAlive should contain exactly one component child.`);
  3937. }
  3938. current = null;
  3939. return children;
  3940. }
  3941. else if (!isVNode(rawVNode) ||
  3942. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  3943. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  3944. current = null;
  3945. return rawVNode;
  3946. }
  3947. let vnode = getInnerChild(rawVNode);
  3948. const comp = vnode.type;
  3949. // for async components, name check should be based in its loaded
  3950. // inner component if available
  3951. const name = getComponentName(isAsyncWrapper(vnode)
  3952. ? vnode.type.__asyncResolved || {}
  3953. : comp);
  3954. const { include, exclude, max } = props;
  3955. if ((include && (!name || !matches(include, name))) ||
  3956. (exclude && name && matches(exclude, name))) {
  3957. current = vnode;
  3958. return rawVNode;
  3959. }
  3960. const key = vnode.key == null ? comp : vnode.key;
  3961. const cachedVNode = cache.get(key);
  3962. // clone vnode if it's reused because we are going to mutate it
  3963. if (vnode.el) {
  3964. vnode = cloneVNode(vnode);
  3965. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  3966. rawVNode.ssContent = vnode;
  3967. }
  3968. }
  3969. // #1513 it's possible for the returned vnode to be cloned due to attr
  3970. // fallthrough or scopeId, so the vnode here may not be the final vnode
  3971. // that is mounted. Instead of caching it directly, we store the pending
  3972. // key and cache `instance.subTree` (the normalized vnode) in
  3973. // beforeMount/beforeUpdate hooks.
  3974. pendingCacheKey = key;
  3975. if (cachedVNode) {
  3976. // copy over mounted state
  3977. vnode.el = cachedVNode.el;
  3978. vnode.component = cachedVNode.component;
  3979. if (vnode.transition) {
  3980. // recursively update transition hooks on subTree
  3981. setTransitionHooks(vnode, vnode.transition);
  3982. }
  3983. // avoid vnode being mounted as fresh
  3984. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  3985. // make this key the freshest
  3986. keys.delete(key);
  3987. keys.add(key);
  3988. }
  3989. else {
  3990. keys.add(key);
  3991. // prune oldest entry
  3992. if (max && keys.size > parseInt(max, 10)) {
  3993. pruneCacheEntry(keys.values().next().value);
  3994. }
  3995. }
  3996. // avoid vnode being unmounted
  3997. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3998. current = vnode;
  3999. return rawVNode;
  4000. };
  4001. }
  4002. };
  4003. // export the public type for h/tsx inference
  4004. // also to avoid inline import() in generated d.ts files
  4005. const KeepAlive = KeepAliveImpl;
  4006. function matches(pattern, name) {
  4007. if (isArray(pattern)) {
  4008. return pattern.some((p) => matches(p, name));
  4009. }
  4010. else if (isString(pattern)) {
  4011. return pattern.split(',').includes(name);
  4012. }
  4013. else if (pattern.test) {
  4014. return pattern.test(name);
  4015. }
  4016. /* istanbul ignore next */
  4017. return false;
  4018. }
  4019. function onActivated(hook, target) {
  4020. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  4021. }
  4022. function onDeactivated(hook, target) {
  4023. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  4024. }
  4025. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4026. // cache the deactivate branch check wrapper for injected hooks so the same
  4027. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4028. // deactivation check".
  4029. const wrappedHook = hook.__wdc ||
  4030. (hook.__wdc = () => {
  4031. // only fire the hook if the target instance is NOT in a deactivated branch.
  4032. let current = target;
  4033. while (current) {
  4034. if (current.isDeactivated) {
  4035. return;
  4036. }
  4037. current = current.parent;
  4038. }
  4039. return hook();
  4040. });
  4041. injectHook(type, wrappedHook, target);
  4042. // In addition to registering it on the target instance, we walk up the parent
  4043. // chain and register it on all ancestor instances that are keep-alive roots.
  4044. // This avoids the need to walk the entire component tree when invoking these
  4045. // hooks, and more importantly, avoids the need to track child components in
  4046. // arrays.
  4047. if (target) {
  4048. let current = target.parent;
  4049. while (current && current.parent) {
  4050. if (isKeepAlive(current.parent.vnode)) {
  4051. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4052. }
  4053. current = current.parent;
  4054. }
  4055. }
  4056. }
  4057. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4058. // injectHook wraps the original for error handling, so make sure to remove
  4059. // the wrapped version.
  4060. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4061. onUnmounted(() => {
  4062. remove(keepAliveRoot[type], injected);
  4063. }, target);
  4064. }
  4065. function resetShapeFlag(vnode) {
  4066. let shapeFlag = vnode.shapeFlag;
  4067. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4068. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4069. }
  4070. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  4071. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  4072. }
  4073. vnode.shapeFlag = shapeFlag;
  4074. }
  4075. function getInnerChild(vnode) {
  4076. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  4077. }
  4078. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4079. if (target) {
  4080. const hooks = target[type] || (target[type] = []);
  4081. // cache the error handling wrapper for injected hooks so the same hook
  4082. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4083. // handling".
  4084. const wrappedHook = hook.__weh ||
  4085. (hook.__weh = (...args) => {
  4086. if (target.isUnmounted) {
  4087. return;
  4088. }
  4089. // disable tracking inside all lifecycle hooks
  4090. // since they can potentially be called inside effects.
  4091. pauseTracking();
  4092. // Set currentInstance during hook invocation.
  4093. // This assumes the hook does not synchronously trigger other hooks, which
  4094. // can only be false when the user does something really funky.
  4095. setCurrentInstance(target);
  4096. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4097. unsetCurrentInstance();
  4098. resetTracking();
  4099. return res;
  4100. });
  4101. if (prepend) {
  4102. hooks.unshift(wrappedHook);
  4103. }
  4104. else {
  4105. hooks.push(wrappedHook);
  4106. }
  4107. return wrappedHook;
  4108. }
  4109. else {
  4110. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4111. warn$1(`${apiName} is called when there is no active component instance to be ` +
  4112. `associated with. ` +
  4113. `Lifecycle injection APIs can only be used during execution of setup().` +
  4114. (` If you are using async setup(), make sure to register lifecycle ` +
  4115. `hooks before the first await statement.`
  4116. ));
  4117. }
  4118. }
  4119. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4120. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4121. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  4122. injectHook(lifecycle, hook, target);
  4123. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  4124. const onMounted = createHook("m" /* MOUNTED */);
  4125. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  4126. const onUpdated = createHook("u" /* UPDATED */);
  4127. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  4128. const onUnmounted = createHook("um" /* UNMOUNTED */);
  4129. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  4130. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  4131. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  4132. function onErrorCaptured(hook, target = currentInstance) {
  4133. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  4134. }
  4135. function createDuplicateChecker() {
  4136. const cache = Object.create(null);
  4137. return (type, key) => {
  4138. if (cache[key]) {
  4139. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4140. }
  4141. else {
  4142. cache[key] = type;
  4143. }
  4144. };
  4145. }
  4146. let shouldCacheAccess = true;
  4147. function applyOptions(instance) {
  4148. const options = resolveMergedOptions(instance);
  4149. const publicThis = instance.proxy;
  4150. const ctx = instance.ctx;
  4151. // do not cache property access on public proxy during state initialization
  4152. shouldCacheAccess = false;
  4153. // call beforeCreate first before accessing other options since
  4154. // the hook may mutate resolved options (#2791)
  4155. if (options.beforeCreate) {
  4156. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  4157. }
  4158. const {
  4159. // state
  4160. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4161. // lifecycle
  4162. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4163. // public API
  4164. expose, inheritAttrs,
  4165. // assets
  4166. components, directives, filters } = options;
  4167. const checkDuplicateProperties = createDuplicateChecker() ;
  4168. {
  4169. const [propsOptions] = instance.propsOptions;
  4170. if (propsOptions) {
  4171. for (const key in propsOptions) {
  4172. checkDuplicateProperties("Props" /* PROPS */, key);
  4173. }
  4174. }
  4175. }
  4176. // options initialization order (to be consistent with Vue 2):
  4177. // - props (already done outside of this function)
  4178. // - inject
  4179. // - methods
  4180. // - data (deferred since it relies on `this` access)
  4181. // - computed
  4182. // - watch (deferred since it relies on `this` access)
  4183. if (injectOptions) {
  4184. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4185. }
  4186. if (methods) {
  4187. for (const key in methods) {
  4188. const methodHandler = methods[key];
  4189. if (isFunction(methodHandler)) {
  4190. // In dev mode, we use the `createRenderContext` function to define
  4191. // methods to the proxy target, and those are read-only but
  4192. // reconfigurable, so it needs to be redefined here
  4193. {
  4194. Object.defineProperty(ctx, key, {
  4195. value: methodHandler.bind(publicThis),
  4196. configurable: true,
  4197. enumerable: true,
  4198. writable: true
  4199. });
  4200. }
  4201. {
  4202. checkDuplicateProperties("Methods" /* METHODS */, key);
  4203. }
  4204. }
  4205. else {
  4206. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4207. `Did you reference the function correctly?`);
  4208. }
  4209. }
  4210. }
  4211. if (dataOptions) {
  4212. if (!isFunction(dataOptions)) {
  4213. warn$1(`The data option must be a function. ` +
  4214. `Plain object usage is no longer supported.`);
  4215. }
  4216. const data = dataOptions.call(publicThis, publicThis);
  4217. if (isPromise(data)) {
  4218. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  4219. `intend to perform data fetching before component renders, use ` +
  4220. `async setup() + <Suspense>.`);
  4221. }
  4222. if (!isObject(data)) {
  4223. warn$1(`data() should return an object.`);
  4224. }
  4225. else {
  4226. instance.data = reactive(data);
  4227. {
  4228. for (const key in data) {
  4229. checkDuplicateProperties("Data" /* DATA */, key);
  4230. // expose data on ctx during dev
  4231. if (key[0] !== '$' && key[0] !== '_') {
  4232. Object.defineProperty(ctx, key, {
  4233. configurable: true,
  4234. enumerable: true,
  4235. get: () => data[key],
  4236. set: NOOP
  4237. });
  4238. }
  4239. }
  4240. }
  4241. }
  4242. }
  4243. // state initialization complete at this point - start caching access
  4244. shouldCacheAccess = true;
  4245. if (computedOptions) {
  4246. for (const key in computedOptions) {
  4247. const opt = computedOptions[key];
  4248. const get = isFunction(opt)
  4249. ? opt.bind(publicThis, publicThis)
  4250. : isFunction(opt.get)
  4251. ? opt.get.bind(publicThis, publicThis)
  4252. : NOOP;
  4253. if (get === NOOP) {
  4254. warn$1(`Computed property "${key}" has no getter.`);
  4255. }
  4256. const set = !isFunction(opt) && isFunction(opt.set)
  4257. ? opt.set.bind(publicThis)
  4258. : () => {
  4259. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  4260. }
  4261. ;
  4262. const c = computed$1({
  4263. get,
  4264. set
  4265. });
  4266. Object.defineProperty(ctx, key, {
  4267. enumerable: true,
  4268. configurable: true,
  4269. get: () => c.value,
  4270. set: v => (c.value = v)
  4271. });
  4272. {
  4273. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  4274. }
  4275. }
  4276. }
  4277. if (watchOptions) {
  4278. for (const key in watchOptions) {
  4279. createWatcher(watchOptions[key], ctx, publicThis, key);
  4280. }
  4281. }
  4282. if (provideOptions) {
  4283. const provides = isFunction(provideOptions)
  4284. ? provideOptions.call(publicThis)
  4285. : provideOptions;
  4286. Reflect.ownKeys(provides).forEach(key => {
  4287. provide(key, provides[key]);
  4288. });
  4289. }
  4290. if (created) {
  4291. callHook(created, instance, "c" /* CREATED */);
  4292. }
  4293. function registerLifecycleHook(register, hook) {
  4294. if (isArray(hook)) {
  4295. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4296. }
  4297. else if (hook) {
  4298. register(hook.bind(publicThis));
  4299. }
  4300. }
  4301. registerLifecycleHook(onBeforeMount, beforeMount);
  4302. registerLifecycleHook(onMounted, mounted);
  4303. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4304. registerLifecycleHook(onUpdated, updated);
  4305. registerLifecycleHook(onActivated, activated);
  4306. registerLifecycleHook(onDeactivated, deactivated);
  4307. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4308. registerLifecycleHook(onRenderTracked, renderTracked);
  4309. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4310. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4311. registerLifecycleHook(onUnmounted, unmounted);
  4312. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4313. if (isArray(expose)) {
  4314. if (expose.length) {
  4315. const exposed = instance.exposed || (instance.exposed = {});
  4316. expose.forEach(key => {
  4317. Object.defineProperty(exposed, key, {
  4318. get: () => publicThis[key],
  4319. set: val => (publicThis[key] = val)
  4320. });
  4321. });
  4322. }
  4323. else if (!instance.exposed) {
  4324. instance.exposed = {};
  4325. }
  4326. }
  4327. // options that are handled when creating the instance but also need to be
  4328. // applied from mixins
  4329. if (render && instance.render === NOOP) {
  4330. instance.render = render;
  4331. }
  4332. if (inheritAttrs != null) {
  4333. instance.inheritAttrs = inheritAttrs;
  4334. }
  4335. // asset options.
  4336. if (components)
  4337. instance.components = components;
  4338. if (directives)
  4339. instance.directives = directives;
  4340. }
  4341. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  4342. if (isArray(injectOptions)) {
  4343. injectOptions = normalizeInject(injectOptions);
  4344. }
  4345. for (const key in injectOptions) {
  4346. const opt = injectOptions[key];
  4347. let injected;
  4348. if (isObject(opt)) {
  4349. if ('default' in opt) {
  4350. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4351. }
  4352. else {
  4353. injected = inject(opt.from || key);
  4354. }
  4355. }
  4356. else {
  4357. injected = inject(opt);
  4358. }
  4359. if (isRef(injected)) {
  4360. // TODO remove the check in 3.3
  4361. if (unwrapRef) {
  4362. Object.defineProperty(ctx, key, {
  4363. enumerable: true,
  4364. configurable: true,
  4365. get: () => injected.value,
  4366. set: v => (injected.value = v)
  4367. });
  4368. }
  4369. else {
  4370. {
  4371. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  4372. `and no longer needs \`.value\` in the next minor release. ` +
  4373. `To opt-in to the new behavior now, ` +
  4374. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  4375. `temporary and will not be needed in the future.)`);
  4376. }
  4377. ctx[key] = injected;
  4378. }
  4379. }
  4380. else {
  4381. ctx[key] = injected;
  4382. }
  4383. {
  4384. checkDuplicateProperties("Inject" /* INJECT */, key);
  4385. }
  4386. }
  4387. }
  4388. function callHook(hook, instance, type) {
  4389. callWithAsyncErrorHandling(isArray(hook)
  4390. ? hook.map(h => h.bind(instance.proxy))
  4391. : hook.bind(instance.proxy), instance, type);
  4392. }
  4393. function createWatcher(raw, ctx, publicThis, key) {
  4394. const getter = key.includes('.')
  4395. ? createPathGetter(publicThis, key)
  4396. : () => publicThis[key];
  4397. if (isString(raw)) {
  4398. const handler = ctx[raw];
  4399. if (isFunction(handler)) {
  4400. watch(getter, handler);
  4401. }
  4402. else {
  4403. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  4404. }
  4405. }
  4406. else if (isFunction(raw)) {
  4407. watch(getter, raw.bind(publicThis));
  4408. }
  4409. else if (isObject(raw)) {
  4410. if (isArray(raw)) {
  4411. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  4412. }
  4413. else {
  4414. const handler = isFunction(raw.handler)
  4415. ? raw.handler.bind(publicThis)
  4416. : ctx[raw.handler];
  4417. if (isFunction(handler)) {
  4418. watch(getter, handler, raw);
  4419. }
  4420. else {
  4421. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  4422. }
  4423. }
  4424. }
  4425. else {
  4426. warn$1(`Invalid watch option: "${key}"`, raw);
  4427. }
  4428. }
  4429. /**
  4430. * Resolve merged options and cache it on the component.
  4431. * This is done only once per-component since the merging does not involve
  4432. * instances.
  4433. */
  4434. function resolveMergedOptions(instance) {
  4435. const base = instance.type;
  4436. const { mixins, extends: extendsOptions } = base;
  4437. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  4438. const cached = cache.get(base);
  4439. let resolved;
  4440. if (cached) {
  4441. resolved = cached;
  4442. }
  4443. else if (!globalMixins.length && !mixins && !extendsOptions) {
  4444. {
  4445. resolved = base;
  4446. }
  4447. }
  4448. else {
  4449. resolved = {};
  4450. if (globalMixins.length) {
  4451. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  4452. }
  4453. mergeOptions(resolved, base, optionMergeStrategies);
  4454. }
  4455. cache.set(base, resolved);
  4456. return resolved;
  4457. }
  4458. function mergeOptions(to, from, strats, asMixin = false) {
  4459. const { mixins, extends: extendsOptions } = from;
  4460. if (extendsOptions) {
  4461. mergeOptions(to, extendsOptions, strats, true);
  4462. }
  4463. if (mixins) {
  4464. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  4465. }
  4466. for (const key in from) {
  4467. if (asMixin && key === 'expose') {
  4468. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  4469. `It should only be declared in the base component itself.`);
  4470. }
  4471. else {
  4472. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  4473. to[key] = strat ? strat(to[key], from[key]) : from[key];
  4474. }
  4475. }
  4476. return to;
  4477. }
  4478. const internalOptionMergeStrats = {
  4479. data: mergeDataFn,
  4480. props: mergeObjectOptions,
  4481. emits: mergeObjectOptions,
  4482. // objects
  4483. methods: mergeObjectOptions,
  4484. computed: mergeObjectOptions,
  4485. // lifecycle
  4486. beforeCreate: mergeAsArray,
  4487. created: mergeAsArray,
  4488. beforeMount: mergeAsArray,
  4489. mounted: mergeAsArray,
  4490. beforeUpdate: mergeAsArray,
  4491. updated: mergeAsArray,
  4492. beforeDestroy: mergeAsArray,
  4493. beforeUnmount: mergeAsArray,
  4494. destroyed: mergeAsArray,
  4495. unmounted: mergeAsArray,
  4496. activated: mergeAsArray,
  4497. deactivated: mergeAsArray,
  4498. errorCaptured: mergeAsArray,
  4499. serverPrefetch: mergeAsArray,
  4500. // assets
  4501. components: mergeObjectOptions,
  4502. directives: mergeObjectOptions,
  4503. // watch
  4504. watch: mergeWatchOptions,
  4505. // provide / inject
  4506. provide: mergeDataFn,
  4507. inject: mergeInject
  4508. };
  4509. function mergeDataFn(to, from) {
  4510. if (!from) {
  4511. return to;
  4512. }
  4513. if (!to) {
  4514. return from;
  4515. }
  4516. return function mergedDataFn() {
  4517. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  4518. };
  4519. }
  4520. function mergeInject(to, from) {
  4521. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  4522. }
  4523. function normalizeInject(raw) {
  4524. if (isArray(raw)) {
  4525. const res = {};
  4526. for (let i = 0; i < raw.length; i++) {
  4527. res[raw[i]] = raw[i];
  4528. }
  4529. return res;
  4530. }
  4531. return raw;
  4532. }
  4533. function mergeAsArray(to, from) {
  4534. return to ? [...new Set([].concat(to, from))] : from;
  4535. }
  4536. function mergeObjectOptions(to, from) {
  4537. return to ? extend(extend(Object.create(null), to), from) : from;
  4538. }
  4539. function mergeWatchOptions(to, from) {
  4540. if (!to)
  4541. return from;
  4542. if (!from)
  4543. return to;
  4544. const merged = extend(Object.create(null), to);
  4545. for (const key in from) {
  4546. merged[key] = mergeAsArray(to[key], from[key]);
  4547. }
  4548. return merged;
  4549. }
  4550. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  4551. isSSR = false) {
  4552. const props = {};
  4553. const attrs = {};
  4554. def(attrs, InternalObjectKey, 1);
  4555. instance.propsDefaults = Object.create(null);
  4556. setFullProps(instance, rawProps, props, attrs);
  4557. // ensure all declared prop keys are present
  4558. for (const key in instance.propsOptions[0]) {
  4559. if (!(key in props)) {
  4560. props[key] = undefined;
  4561. }
  4562. }
  4563. // validation
  4564. {
  4565. validateProps(rawProps || {}, props, instance);
  4566. }
  4567. if (isStateful) {
  4568. // stateful
  4569. instance.props = isSSR ? props : shallowReactive(props);
  4570. }
  4571. else {
  4572. if (!instance.type.props) {
  4573. // functional w/ optional props, props === attrs
  4574. instance.props = attrs;
  4575. }
  4576. else {
  4577. // functional w/ declared props
  4578. instance.props = props;
  4579. }
  4580. }
  4581. instance.attrs = attrs;
  4582. }
  4583. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  4584. const { props, attrs, vnode: { patchFlag } } = instance;
  4585. const rawCurrentProps = toRaw(props);
  4586. const [options] = instance.propsOptions;
  4587. let hasAttrsChanged = false;
  4588. if (
  4589. // always force full diff in dev
  4590. // - #1942 if hmr is enabled with sfc component
  4591. // - vite#872 non-sfc component used by sfc component
  4592. !((instance.type.__hmrId ||
  4593. (instance.parent && instance.parent.type.__hmrId))) &&
  4594. (optimized || patchFlag > 0) &&
  4595. !(patchFlag & 16 /* FULL_PROPS */)) {
  4596. if (patchFlag & 8 /* PROPS */) {
  4597. // Compiler-generated props & no keys change, just set the updated
  4598. // the props.
  4599. const propsToUpdate = instance.vnode.dynamicProps;
  4600. for (let i = 0; i < propsToUpdate.length; i++) {
  4601. let key = propsToUpdate[i];
  4602. // skip if the prop key is a declared emit event listener
  4603. if (isEmitListener(instance.emitsOptions, key)) {
  4604. continue;
  4605. }
  4606. // PROPS flag guarantees rawProps to be non-null
  4607. const value = rawProps[key];
  4608. if (options) {
  4609. // attr / props separation was done on init and will be consistent
  4610. // in this code path, so just check if attrs have it.
  4611. if (hasOwn(attrs, key)) {
  4612. if (value !== attrs[key]) {
  4613. attrs[key] = value;
  4614. hasAttrsChanged = true;
  4615. }
  4616. }
  4617. else {
  4618. const camelizedKey = camelize(key);
  4619. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  4620. }
  4621. }
  4622. else {
  4623. if (value !== attrs[key]) {
  4624. attrs[key] = value;
  4625. hasAttrsChanged = true;
  4626. }
  4627. }
  4628. }
  4629. }
  4630. }
  4631. else {
  4632. // full props update.
  4633. if (setFullProps(instance, rawProps, props, attrs)) {
  4634. hasAttrsChanged = true;
  4635. }
  4636. // in case of dynamic props, check if we need to delete keys from
  4637. // the props object
  4638. let kebabKey;
  4639. for (const key in rawCurrentProps) {
  4640. if (!rawProps ||
  4641. // for camelCase
  4642. (!hasOwn(rawProps, key) &&
  4643. // it's possible the original props was passed in as kebab-case
  4644. // and converted to camelCase (#955)
  4645. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  4646. if (options) {
  4647. if (rawPrevProps &&
  4648. // for camelCase
  4649. (rawPrevProps[key] !== undefined ||
  4650. // for kebab-case
  4651. rawPrevProps[kebabKey] !== undefined)) {
  4652. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  4653. }
  4654. }
  4655. else {
  4656. delete props[key];
  4657. }
  4658. }
  4659. }
  4660. // in the case of functional component w/o props declaration, props and
  4661. // attrs point to the same object so it should already have been updated.
  4662. if (attrs !== rawCurrentProps) {
  4663. for (const key in attrs) {
  4664. if (!rawProps ||
  4665. (!hasOwn(rawProps, key) &&
  4666. (!false ))) {
  4667. delete attrs[key];
  4668. hasAttrsChanged = true;
  4669. }
  4670. }
  4671. }
  4672. }
  4673. // trigger updates for $attrs in case it's used in component slots
  4674. if (hasAttrsChanged) {
  4675. trigger(instance, "set" /* SET */, '$attrs');
  4676. }
  4677. {
  4678. validateProps(rawProps || {}, props, instance);
  4679. }
  4680. }
  4681. function setFullProps(instance, rawProps, props, attrs) {
  4682. const [options, needCastKeys] = instance.propsOptions;
  4683. let hasAttrsChanged = false;
  4684. let rawCastValues;
  4685. if (rawProps) {
  4686. for (let key in rawProps) {
  4687. // key, ref are reserved and never passed down
  4688. if (isReservedProp(key)) {
  4689. continue;
  4690. }
  4691. const value = rawProps[key];
  4692. // prop option names are camelized during normalization, so to support
  4693. // kebab -> camel conversion here we need to camelize the key.
  4694. let camelKey;
  4695. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  4696. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  4697. props[camelKey] = value;
  4698. }
  4699. else {
  4700. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  4701. }
  4702. }
  4703. else if (!isEmitListener(instance.emitsOptions, key)) {
  4704. if (!(key in attrs) || value !== attrs[key]) {
  4705. attrs[key] = value;
  4706. hasAttrsChanged = true;
  4707. }
  4708. }
  4709. }
  4710. }
  4711. if (needCastKeys) {
  4712. const rawCurrentProps = toRaw(props);
  4713. const castValues = rawCastValues || EMPTY_OBJ;
  4714. for (let i = 0; i < needCastKeys.length; i++) {
  4715. const key = needCastKeys[i];
  4716. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  4717. }
  4718. }
  4719. return hasAttrsChanged;
  4720. }
  4721. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  4722. const opt = options[key];
  4723. if (opt != null) {
  4724. const hasDefault = hasOwn(opt, 'default');
  4725. // default values
  4726. if (hasDefault && value === undefined) {
  4727. const defaultValue = opt.default;
  4728. if (opt.type !== Function && isFunction(defaultValue)) {
  4729. const { propsDefaults } = instance;
  4730. if (key in propsDefaults) {
  4731. value = propsDefaults[key];
  4732. }
  4733. else {
  4734. setCurrentInstance(instance);
  4735. value = propsDefaults[key] = defaultValue.call(null, props);
  4736. unsetCurrentInstance();
  4737. }
  4738. }
  4739. else {
  4740. value = defaultValue;
  4741. }
  4742. }
  4743. // boolean casting
  4744. if (opt[0 /* shouldCast */]) {
  4745. if (isAbsent && !hasDefault) {
  4746. value = false;
  4747. }
  4748. else if (opt[1 /* shouldCastTrue */] &&
  4749. (value === '' || value === hyphenate(key))) {
  4750. value = true;
  4751. }
  4752. }
  4753. }
  4754. return value;
  4755. }
  4756. function normalizePropsOptions(comp, appContext, asMixin = false) {
  4757. const cache = appContext.propsCache;
  4758. const cached = cache.get(comp);
  4759. if (cached) {
  4760. return cached;
  4761. }
  4762. const raw = comp.props;
  4763. const normalized = {};
  4764. const needCastKeys = [];
  4765. // apply mixin/extends props
  4766. let hasExtends = false;
  4767. if (!isFunction(comp)) {
  4768. const extendProps = (raw) => {
  4769. hasExtends = true;
  4770. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  4771. extend(normalized, props);
  4772. if (keys)
  4773. needCastKeys.push(...keys);
  4774. };
  4775. if (!asMixin && appContext.mixins.length) {
  4776. appContext.mixins.forEach(extendProps);
  4777. }
  4778. if (comp.extends) {
  4779. extendProps(comp.extends);
  4780. }
  4781. if (comp.mixins) {
  4782. comp.mixins.forEach(extendProps);
  4783. }
  4784. }
  4785. if (!raw && !hasExtends) {
  4786. cache.set(comp, EMPTY_ARR);
  4787. return EMPTY_ARR;
  4788. }
  4789. if (isArray(raw)) {
  4790. for (let i = 0; i < raw.length; i++) {
  4791. if (!isString(raw[i])) {
  4792. warn$1(`props must be strings when using array syntax.`, raw[i]);
  4793. }
  4794. const normalizedKey = camelize(raw[i]);
  4795. if (validatePropName(normalizedKey)) {
  4796. normalized[normalizedKey] = EMPTY_OBJ;
  4797. }
  4798. }
  4799. }
  4800. else if (raw) {
  4801. if (!isObject(raw)) {
  4802. warn$1(`invalid props options`, raw);
  4803. }
  4804. for (const key in raw) {
  4805. const normalizedKey = camelize(key);
  4806. if (validatePropName(normalizedKey)) {
  4807. const opt = raw[key];
  4808. const prop = (normalized[normalizedKey] =
  4809. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  4810. if (prop) {
  4811. const booleanIndex = getTypeIndex(Boolean, prop.type);
  4812. const stringIndex = getTypeIndex(String, prop.type);
  4813. prop[0 /* shouldCast */] = booleanIndex > -1;
  4814. prop[1 /* shouldCastTrue */] =
  4815. stringIndex < 0 || booleanIndex < stringIndex;
  4816. // if the prop needs boolean casting or default value
  4817. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  4818. needCastKeys.push(normalizedKey);
  4819. }
  4820. }
  4821. }
  4822. }
  4823. }
  4824. const res = [normalized, needCastKeys];
  4825. cache.set(comp, res);
  4826. return res;
  4827. }
  4828. function validatePropName(key) {
  4829. if (key[0] !== '$') {
  4830. return true;
  4831. }
  4832. else {
  4833. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  4834. }
  4835. return false;
  4836. }
  4837. // use function string name to check type constructors
  4838. // so that it works across vms / iframes.
  4839. function getType(ctor) {
  4840. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  4841. return match ? match[1] : ctor === null ? 'null' : '';
  4842. }
  4843. function isSameType(a, b) {
  4844. return getType(a) === getType(b);
  4845. }
  4846. function getTypeIndex(type, expectedTypes) {
  4847. if (isArray(expectedTypes)) {
  4848. return expectedTypes.findIndex(t => isSameType(t, type));
  4849. }
  4850. else if (isFunction(expectedTypes)) {
  4851. return isSameType(expectedTypes, type) ? 0 : -1;
  4852. }
  4853. return -1;
  4854. }
  4855. /**
  4856. * dev only
  4857. */
  4858. function validateProps(rawProps, props, instance) {
  4859. const resolvedValues = toRaw(props);
  4860. const options = instance.propsOptions[0];
  4861. for (const key in options) {
  4862. let opt = options[key];
  4863. if (opt == null)
  4864. continue;
  4865. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  4866. }
  4867. }
  4868. /**
  4869. * dev only
  4870. */
  4871. function validateProp(name, value, prop, isAbsent) {
  4872. const { type, required, validator } = prop;
  4873. // required!
  4874. if (required && isAbsent) {
  4875. warn$1('Missing required prop: "' + name + '"');
  4876. return;
  4877. }
  4878. // missing but optional
  4879. if (value == null && !prop.required) {
  4880. return;
  4881. }
  4882. // type check
  4883. if (type != null && type !== true) {
  4884. let isValid = false;
  4885. const types = isArray(type) ? type : [type];
  4886. const expectedTypes = [];
  4887. // value is valid as long as one of the specified types match
  4888. for (let i = 0; i < types.length && !isValid; i++) {
  4889. const { valid, expectedType } = assertType(value, types[i]);
  4890. expectedTypes.push(expectedType || '');
  4891. isValid = valid;
  4892. }
  4893. if (!isValid) {
  4894. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  4895. return;
  4896. }
  4897. }
  4898. // custom validator
  4899. if (validator && !validator(value)) {
  4900. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  4901. }
  4902. }
  4903. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  4904. /**
  4905. * dev only
  4906. */
  4907. function assertType(value, type) {
  4908. let valid;
  4909. const expectedType = getType(type);
  4910. if (isSimpleType(expectedType)) {
  4911. const t = typeof value;
  4912. valid = t === expectedType.toLowerCase();
  4913. // for primitive wrapper objects
  4914. if (!valid && t === 'object') {
  4915. valid = value instanceof type;
  4916. }
  4917. }
  4918. else if (expectedType === 'Object') {
  4919. valid = isObject(value);
  4920. }
  4921. else if (expectedType === 'Array') {
  4922. valid = isArray(value);
  4923. }
  4924. else if (expectedType === 'null') {
  4925. valid = value === null;
  4926. }
  4927. else {
  4928. valid = value instanceof type;
  4929. }
  4930. return {
  4931. valid,
  4932. expectedType
  4933. };
  4934. }
  4935. /**
  4936. * dev only
  4937. */
  4938. function getInvalidTypeMessage(name, value, expectedTypes) {
  4939. let message = `Invalid prop: type check failed for prop "${name}".` +
  4940. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  4941. const expectedType = expectedTypes[0];
  4942. const receivedType = toRawType(value);
  4943. const expectedValue = styleValue(value, expectedType);
  4944. const receivedValue = styleValue(value, receivedType);
  4945. // check if we need to specify expected value
  4946. if (expectedTypes.length === 1 &&
  4947. isExplicable(expectedType) &&
  4948. !isBoolean(expectedType, receivedType)) {
  4949. message += ` with value ${expectedValue}`;
  4950. }
  4951. message += `, got ${receivedType} `;
  4952. // check if we need to specify received value
  4953. if (isExplicable(receivedType)) {
  4954. message += `with value ${receivedValue}.`;
  4955. }
  4956. return message;
  4957. }
  4958. /**
  4959. * dev only
  4960. */
  4961. function styleValue(value, type) {
  4962. if (type === 'String') {
  4963. return `"${value}"`;
  4964. }
  4965. else if (type === 'Number') {
  4966. return `${Number(value)}`;
  4967. }
  4968. else {
  4969. return `${value}`;
  4970. }
  4971. }
  4972. /**
  4973. * dev only
  4974. */
  4975. function isExplicable(type) {
  4976. const explicitTypes = ['string', 'number', 'boolean'];
  4977. return explicitTypes.some(elem => type.toLowerCase() === elem);
  4978. }
  4979. /**
  4980. * dev only
  4981. */
  4982. function isBoolean(...args) {
  4983. return args.some(elem => elem.toLowerCase() === 'boolean');
  4984. }
  4985. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  4986. const normalizeSlotValue = (value) => isArray(value)
  4987. ? value.map(normalizeVNode)
  4988. : [normalizeVNode(value)];
  4989. const normalizeSlot = (key, rawSlot, ctx) => {
  4990. const normalized = withCtx((...args) => {
  4991. if (currentInstance) {
  4992. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  4993. `this will not track dependencies used in the slot. ` +
  4994. `Invoke the slot function inside the render function instead.`);
  4995. }
  4996. return normalizeSlotValue(rawSlot(...args));
  4997. }, ctx);
  4998. normalized._c = false;
  4999. return normalized;
  5000. };
  5001. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5002. const ctx = rawSlots._ctx;
  5003. for (const key in rawSlots) {
  5004. if (isInternalKey(key))
  5005. continue;
  5006. const value = rawSlots[key];
  5007. if (isFunction(value)) {
  5008. slots[key] = normalizeSlot(key, value, ctx);
  5009. }
  5010. else if (value != null) {
  5011. {
  5012. warn$1(`Non-function value encountered for slot "${key}". ` +
  5013. `Prefer function slots for better performance.`);
  5014. }
  5015. const normalized = normalizeSlotValue(value);
  5016. slots[key] = () => normalized;
  5017. }
  5018. }
  5019. };
  5020. const normalizeVNodeSlots = (instance, children) => {
  5021. if (!isKeepAlive(instance.vnode) &&
  5022. !(false )) {
  5023. warn$1(`Non-function value encountered for default slot. ` +
  5024. `Prefer function slots for better performance.`);
  5025. }
  5026. const normalized = normalizeSlotValue(children);
  5027. instance.slots.default = () => normalized;
  5028. };
  5029. const initSlots = (instance, children) => {
  5030. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5031. const type = children._;
  5032. if (type) {
  5033. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5034. // we should avoid the proxy object polluting the slots of the internal instance
  5035. instance.slots = toRaw(children);
  5036. // make compiler marker non-enumerable
  5037. def(children, '_', type);
  5038. }
  5039. else {
  5040. normalizeObjectSlots(children, (instance.slots = {}));
  5041. }
  5042. }
  5043. else {
  5044. instance.slots = {};
  5045. if (children) {
  5046. normalizeVNodeSlots(instance, children);
  5047. }
  5048. }
  5049. def(instance.slots, InternalObjectKey, 1);
  5050. };
  5051. const updateSlots = (instance, children, optimized) => {
  5052. const { vnode, slots } = instance;
  5053. let needDeletionCheck = true;
  5054. let deletionComparisonTarget = EMPTY_OBJ;
  5055. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5056. const type = children._;
  5057. if (type) {
  5058. // compiled slots.
  5059. if (isHmrUpdating) {
  5060. // Parent was HMR updated so slot content may have changed.
  5061. // force update slots and mark instance for hmr as well
  5062. extend(slots, children);
  5063. }
  5064. else if (optimized && type === 1 /* STABLE */) {
  5065. // compiled AND stable.
  5066. // no need to update, and skip stale slots removal.
  5067. needDeletionCheck = false;
  5068. }
  5069. else {
  5070. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5071. // normalization.
  5072. extend(slots, children);
  5073. // #2893
  5074. // when rendering the optimized slots by manually written render function,
  5075. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5076. // i.e. let the `renderSlot` create the bailed Fragment
  5077. if (!optimized && type === 1 /* STABLE */) {
  5078. delete slots._;
  5079. }
  5080. }
  5081. }
  5082. else {
  5083. needDeletionCheck = !children.$stable;
  5084. normalizeObjectSlots(children, slots);
  5085. }
  5086. deletionComparisonTarget = children;
  5087. }
  5088. else if (children) {
  5089. // non slot object children (direct value) passed to a component
  5090. normalizeVNodeSlots(instance, children);
  5091. deletionComparisonTarget = { default: 1 };
  5092. }
  5093. // delete stale slots
  5094. if (needDeletionCheck) {
  5095. for (const key in slots) {
  5096. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5097. delete slots[key];
  5098. }
  5099. }
  5100. }
  5101. };
  5102. /**
  5103. Runtime helper for applying directives to a vnode. Example usage:
  5104. const comp = resolveComponent('comp')
  5105. const foo = resolveDirective('foo')
  5106. const bar = resolveDirective('bar')
  5107. return withDirectives(h(comp), [
  5108. [foo, this.x],
  5109. [bar, this.y]
  5110. ])
  5111. */
  5112. function validateDirectiveName(name) {
  5113. if (isBuiltInDirective(name)) {
  5114. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  5115. }
  5116. }
  5117. /**
  5118. * Adds directives to a VNode.
  5119. */
  5120. function withDirectives(vnode, directives) {
  5121. const internalInstance = currentRenderingInstance;
  5122. if (internalInstance === null) {
  5123. warn$1(`withDirectives can only be used inside render functions.`);
  5124. return vnode;
  5125. }
  5126. const instance = getExposeProxy(internalInstance) ||
  5127. internalInstance.proxy;
  5128. const bindings = vnode.dirs || (vnode.dirs = []);
  5129. for (let i = 0; i < directives.length; i++) {
  5130. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  5131. if (isFunction(dir)) {
  5132. dir = {
  5133. mounted: dir,
  5134. updated: dir
  5135. };
  5136. }
  5137. if (dir.deep) {
  5138. traverse(value);
  5139. }
  5140. bindings.push({
  5141. dir,
  5142. instance,
  5143. value,
  5144. oldValue: void 0,
  5145. arg,
  5146. modifiers
  5147. });
  5148. }
  5149. return vnode;
  5150. }
  5151. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  5152. const bindings = vnode.dirs;
  5153. const oldBindings = prevVNode && prevVNode.dirs;
  5154. for (let i = 0; i < bindings.length; i++) {
  5155. const binding = bindings[i];
  5156. if (oldBindings) {
  5157. binding.oldValue = oldBindings[i].value;
  5158. }
  5159. let hook = binding.dir[name];
  5160. if (hook) {
  5161. // disable tracking inside all lifecycle hooks
  5162. // since they can potentially be called inside effects.
  5163. pauseTracking();
  5164. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  5165. vnode.el,
  5166. binding,
  5167. vnode,
  5168. prevVNode
  5169. ]);
  5170. resetTracking();
  5171. }
  5172. }
  5173. }
  5174. function createAppContext() {
  5175. return {
  5176. app: null,
  5177. config: {
  5178. isNativeTag: NO,
  5179. performance: false,
  5180. globalProperties: {},
  5181. optionMergeStrategies: {},
  5182. errorHandler: undefined,
  5183. warnHandler: undefined,
  5184. compilerOptions: {}
  5185. },
  5186. mixins: [],
  5187. components: {},
  5188. directives: {},
  5189. provides: Object.create(null),
  5190. optionsCache: new WeakMap(),
  5191. propsCache: new WeakMap(),
  5192. emitsCache: new WeakMap()
  5193. };
  5194. }
  5195. let uid = 0;
  5196. function createAppAPI(render, hydrate) {
  5197. return function createApp(rootComponent, rootProps = null) {
  5198. if (!isFunction(rootComponent)) {
  5199. rootComponent = Object.assign({}, rootComponent);
  5200. }
  5201. if (rootProps != null && !isObject(rootProps)) {
  5202. warn$1(`root props passed to app.mount() must be an object.`);
  5203. rootProps = null;
  5204. }
  5205. const context = createAppContext();
  5206. const installedPlugins = new Set();
  5207. let isMounted = false;
  5208. const app = (context.app = {
  5209. _uid: uid++,
  5210. _component: rootComponent,
  5211. _props: rootProps,
  5212. _container: null,
  5213. _context: context,
  5214. _instance: null,
  5215. version,
  5216. get config() {
  5217. return context.config;
  5218. },
  5219. set config(v) {
  5220. {
  5221. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  5222. }
  5223. },
  5224. use(plugin, ...options) {
  5225. if (installedPlugins.has(plugin)) {
  5226. warn$1(`Plugin has already been applied to target app.`);
  5227. }
  5228. else if (plugin && isFunction(plugin.install)) {
  5229. installedPlugins.add(plugin);
  5230. plugin.install(app, ...options);
  5231. }
  5232. else if (isFunction(plugin)) {
  5233. installedPlugins.add(plugin);
  5234. plugin(app, ...options);
  5235. }
  5236. else {
  5237. warn$1(`A plugin must either be a function or an object with an "install" ` +
  5238. `function.`);
  5239. }
  5240. return app;
  5241. },
  5242. mixin(mixin) {
  5243. {
  5244. if (!context.mixins.includes(mixin)) {
  5245. context.mixins.push(mixin);
  5246. }
  5247. else {
  5248. warn$1('Mixin has already been applied to target app' +
  5249. (mixin.name ? `: ${mixin.name}` : ''));
  5250. }
  5251. }
  5252. return app;
  5253. },
  5254. component(name, component) {
  5255. {
  5256. validateComponentName(name, context.config);
  5257. }
  5258. if (!component) {
  5259. return context.components[name];
  5260. }
  5261. if (context.components[name]) {
  5262. warn$1(`Component "${name}" has already been registered in target app.`);
  5263. }
  5264. context.components[name] = component;
  5265. return app;
  5266. },
  5267. directive(name, directive) {
  5268. {
  5269. validateDirectiveName(name);
  5270. }
  5271. if (!directive) {
  5272. return context.directives[name];
  5273. }
  5274. if (context.directives[name]) {
  5275. warn$1(`Directive "${name}" has already been registered in target app.`);
  5276. }
  5277. context.directives[name] = directive;
  5278. return app;
  5279. },
  5280. mount(rootContainer, isHydrate, isSVG) {
  5281. if (!isMounted) {
  5282. const vnode = createVNode(rootComponent, rootProps);
  5283. // store app context on the root VNode.
  5284. // this will be set on the root instance on initial mount.
  5285. vnode.appContext = context;
  5286. // HMR root reload
  5287. {
  5288. context.reload = () => {
  5289. render(cloneVNode(vnode), rootContainer, isSVG);
  5290. };
  5291. }
  5292. if (isHydrate && hydrate) {
  5293. hydrate(vnode, rootContainer);
  5294. }
  5295. else {
  5296. render(vnode, rootContainer, isSVG);
  5297. }
  5298. isMounted = true;
  5299. app._container = rootContainer;
  5300. rootContainer.__vue_app__ = app;
  5301. {
  5302. app._instance = vnode.component;
  5303. devtoolsInitApp(app, version);
  5304. }
  5305. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5306. }
  5307. else {
  5308. warn$1(`App has already been mounted.\n` +
  5309. `If you want to remount the same app, move your app creation logic ` +
  5310. `into a factory function and create fresh app instances for each ` +
  5311. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5312. }
  5313. },
  5314. unmount() {
  5315. if (isMounted) {
  5316. render(null, app._container);
  5317. {
  5318. app._instance = null;
  5319. devtoolsUnmountApp(app);
  5320. }
  5321. delete app._container.__vue_app__;
  5322. }
  5323. else {
  5324. warn$1(`Cannot unmount an app that is not mounted.`);
  5325. }
  5326. },
  5327. provide(key, value) {
  5328. if (key in context.provides) {
  5329. warn$1(`App already provides property with key "${String(key)}". ` +
  5330. `It will be overwritten with the new value.`);
  5331. }
  5332. // TypeScript doesn't allow symbols as index type
  5333. // https://github.com/Microsoft/TypeScript/issues/24587
  5334. context.provides[key] = value;
  5335. return app;
  5336. }
  5337. });
  5338. return app;
  5339. };
  5340. }
  5341. /**
  5342. * Function for handling a template ref
  5343. */
  5344. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5345. if (isArray(rawRef)) {
  5346. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5347. return;
  5348. }
  5349. if (isAsyncWrapper(vnode) && !isUnmount) {
  5350. // when mounting async components, nothing needs to be done,
  5351. // because the template ref is forwarded to inner component
  5352. return;
  5353. }
  5354. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  5355. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5356. : vnode.el;
  5357. const value = isUnmount ? null : refValue;
  5358. const { i: owner, r: ref } = rawRef;
  5359. if (!owner) {
  5360. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5361. `A vnode with ref must be created inside the render function.`);
  5362. return;
  5363. }
  5364. const oldRef = oldRawRef && oldRawRef.r;
  5365. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5366. const setupState = owner.setupState;
  5367. // dynamic ref changed. unset old ref
  5368. if (oldRef != null && oldRef !== ref) {
  5369. if (isString(oldRef)) {
  5370. refs[oldRef] = null;
  5371. if (hasOwn(setupState, oldRef)) {
  5372. setupState[oldRef] = null;
  5373. }
  5374. }
  5375. else if (isRef(oldRef)) {
  5376. oldRef.value = null;
  5377. }
  5378. }
  5379. if (isFunction(ref)) {
  5380. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  5381. }
  5382. else {
  5383. const _isString = isString(ref);
  5384. const _isRef = isRef(ref);
  5385. if (_isString || _isRef) {
  5386. const doSet = () => {
  5387. if (rawRef.f) {
  5388. const existing = _isString ? refs[ref] : ref.value;
  5389. if (isUnmount) {
  5390. isArray(existing) && remove(existing, refValue);
  5391. }
  5392. else {
  5393. if (!isArray(existing)) {
  5394. if (_isString) {
  5395. refs[ref] = [refValue];
  5396. if (hasOwn(setupState, ref)) {
  5397. setupState[ref] = refs[ref];
  5398. }
  5399. }
  5400. else {
  5401. ref.value = [refValue];
  5402. if (rawRef.k)
  5403. refs[rawRef.k] = ref.value;
  5404. }
  5405. }
  5406. else if (!existing.includes(refValue)) {
  5407. existing.push(refValue);
  5408. }
  5409. }
  5410. }
  5411. else if (_isString) {
  5412. refs[ref] = value;
  5413. if (hasOwn(setupState, ref)) {
  5414. setupState[ref] = value;
  5415. }
  5416. }
  5417. else if (isRef(ref)) {
  5418. ref.value = value;
  5419. if (rawRef.k)
  5420. refs[rawRef.k] = value;
  5421. }
  5422. else {
  5423. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  5424. }
  5425. };
  5426. if (value) {
  5427. doSet.id = -1;
  5428. queuePostRenderEffect(doSet, parentSuspense);
  5429. }
  5430. else {
  5431. doSet();
  5432. }
  5433. }
  5434. else {
  5435. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  5436. }
  5437. }
  5438. }
  5439. let hasMismatch = false;
  5440. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  5441. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  5442. // Note: hydration is DOM-specific
  5443. // But we have to place it in core due to tight coupling with core - splitting
  5444. // it out creates a ton of unnecessary complexity.
  5445. // Hydration also depends on some renderer internal logic which needs to be
  5446. // passed in via arguments.
  5447. function createHydrationFunctions(rendererInternals) {
  5448. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  5449. const hydrate = (vnode, container) => {
  5450. if (!container.hasChildNodes()) {
  5451. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  5452. `Performing full mount instead.`);
  5453. patch(null, vnode, container);
  5454. flushPostFlushCbs();
  5455. return;
  5456. }
  5457. hasMismatch = false;
  5458. hydrateNode(container.firstChild, vnode, null, null, null);
  5459. flushPostFlushCbs();
  5460. if (hasMismatch && !false) {
  5461. // this error should show up in production
  5462. console.error(`Hydration completed but contains mismatches.`);
  5463. }
  5464. };
  5465. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  5466. const isFragmentStart = isComment(node) && node.data === '[';
  5467. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  5468. const { type, ref, shapeFlag } = vnode;
  5469. const domType = node.nodeType;
  5470. vnode.el = node;
  5471. let nextNode = null;
  5472. switch (type) {
  5473. case Text:
  5474. if (domType !== 3 /* TEXT */) {
  5475. nextNode = onMismatch();
  5476. }
  5477. else {
  5478. if (node.data !== vnode.children) {
  5479. hasMismatch = true;
  5480. warn$1(`Hydration text mismatch:` +
  5481. `\n- Client: ${JSON.stringify(node.data)}` +
  5482. `\n- Server: ${JSON.stringify(vnode.children)}`);
  5483. node.data = vnode.children;
  5484. }
  5485. nextNode = nextSibling(node);
  5486. }
  5487. break;
  5488. case Comment:
  5489. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  5490. nextNode = onMismatch();
  5491. }
  5492. else {
  5493. nextNode = nextSibling(node);
  5494. }
  5495. break;
  5496. case Static:
  5497. if (domType !== 1 /* ELEMENT */) {
  5498. nextNode = onMismatch();
  5499. }
  5500. else {
  5501. // determine anchor, adopt content
  5502. nextNode = node;
  5503. // if the static vnode has its content stripped during build,
  5504. // adopt it from the server-rendered HTML.
  5505. const needToAdoptContent = !vnode.children.length;
  5506. for (let i = 0; i < vnode.staticCount; i++) {
  5507. if (needToAdoptContent)
  5508. vnode.children += nextNode.outerHTML;
  5509. if (i === vnode.staticCount - 1) {
  5510. vnode.anchor = nextNode;
  5511. }
  5512. nextNode = nextSibling(nextNode);
  5513. }
  5514. return nextNode;
  5515. }
  5516. break;
  5517. case Fragment:
  5518. if (!isFragmentStart) {
  5519. nextNode = onMismatch();
  5520. }
  5521. else {
  5522. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5523. }
  5524. break;
  5525. default:
  5526. if (shapeFlag & 1 /* ELEMENT */) {
  5527. if (domType !== 1 /* ELEMENT */ ||
  5528. vnode.type.toLowerCase() !==
  5529. node.tagName.toLowerCase()) {
  5530. nextNode = onMismatch();
  5531. }
  5532. else {
  5533. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5534. }
  5535. }
  5536. else if (shapeFlag & 6 /* COMPONENT */) {
  5537. // when setting up the render effect, if the initial vnode already
  5538. // has .el set, the component will perform hydration instead of mount
  5539. // on its sub-tree.
  5540. vnode.slotScopeIds = slotScopeIds;
  5541. const container = parentNode(node);
  5542. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  5543. // component may be async, so in the case of fragments we cannot rely
  5544. // on component's rendered output to determine the end of the fragment
  5545. // instead, we do a lookahead to find the end anchor node.
  5546. nextNode = isFragmentStart
  5547. ? locateClosingAsyncAnchor(node)
  5548. : nextSibling(node);
  5549. // #3787
  5550. // if component is async, it may get moved / unmounted before its
  5551. // inner component is loaded, so we need to give it a placeholder
  5552. // vnode that matches its adopted DOM.
  5553. if (isAsyncWrapper(vnode)) {
  5554. let subTree;
  5555. if (isFragmentStart) {
  5556. subTree = createVNode(Fragment);
  5557. subTree.anchor = nextNode
  5558. ? nextNode.previousSibling
  5559. : container.lastChild;
  5560. }
  5561. else {
  5562. subTree =
  5563. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  5564. }
  5565. subTree.el = node;
  5566. vnode.component.subTree = subTree;
  5567. }
  5568. }
  5569. else if (shapeFlag & 64 /* TELEPORT */) {
  5570. if (domType !== 8 /* COMMENT */) {
  5571. nextNode = onMismatch();
  5572. }
  5573. else {
  5574. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  5575. }
  5576. }
  5577. else if (shapeFlag & 128 /* SUSPENSE */) {
  5578. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  5579. }
  5580. else {
  5581. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  5582. }
  5583. }
  5584. if (ref != null) {
  5585. setRef(ref, null, parentSuspense, vnode);
  5586. }
  5587. return nextNode;
  5588. };
  5589. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5590. optimized = optimized || !!vnode.dynamicChildren;
  5591. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  5592. // #4006 for form elements with non-string v-model value bindings
  5593. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  5594. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  5595. // skip props & children if this is hoisted static nodes
  5596. // #5405 in dev, always hydrate children for HMR
  5597. {
  5598. if (dirs) {
  5599. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5600. }
  5601. // props
  5602. if (props) {
  5603. if (forcePatchValue ||
  5604. !optimized ||
  5605. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  5606. for (const key in props) {
  5607. if ((forcePatchValue && key.endsWith('value')) ||
  5608. (isOn(key) && !isReservedProp(key))) {
  5609. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  5610. }
  5611. }
  5612. }
  5613. else if (props.onClick) {
  5614. // Fast path for click listeners (which is most often) to avoid
  5615. // iterating through props.
  5616. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  5617. }
  5618. }
  5619. // vnode / directive hooks
  5620. let vnodeHooks;
  5621. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  5622. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  5623. }
  5624. if (dirs) {
  5625. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  5626. }
  5627. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  5628. queueEffectWithSuspense(() => {
  5629. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  5630. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  5631. }, parentSuspense);
  5632. }
  5633. // children
  5634. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  5635. // skip if element has innerHTML / textContent
  5636. !(props && (props.innerHTML || props.textContent))) {
  5637. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  5638. let hasWarned = false;
  5639. while (next) {
  5640. hasMismatch = true;
  5641. if (!hasWarned) {
  5642. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  5643. `server rendered element contains more child nodes than client vdom.`);
  5644. hasWarned = true;
  5645. }
  5646. // The SSRed DOM contains more nodes than it should. Remove them.
  5647. const cur = next;
  5648. next = next.nextSibling;
  5649. remove(cur);
  5650. }
  5651. }
  5652. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5653. if (el.textContent !== vnode.children) {
  5654. hasMismatch = true;
  5655. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  5656. `- Client: ${el.textContent}\n` +
  5657. `- Server: ${vnode.children}`);
  5658. el.textContent = vnode.children;
  5659. }
  5660. }
  5661. }
  5662. return el.nextSibling;
  5663. };
  5664. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5665. optimized = optimized || !!parentVNode.dynamicChildren;
  5666. const children = parentVNode.children;
  5667. const l = children.length;
  5668. let hasWarned = false;
  5669. for (let i = 0; i < l; i++) {
  5670. const vnode = optimized
  5671. ? children[i]
  5672. : (children[i] = normalizeVNode(children[i]));
  5673. if (node) {
  5674. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5675. }
  5676. else if (vnode.type === Text && !vnode.children) {
  5677. continue;
  5678. }
  5679. else {
  5680. hasMismatch = true;
  5681. if (!hasWarned) {
  5682. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  5683. `server rendered element contains fewer child nodes than client vdom.`);
  5684. hasWarned = true;
  5685. }
  5686. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  5687. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  5688. }
  5689. }
  5690. return node;
  5691. };
  5692. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5693. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  5694. if (fragmentSlotScopeIds) {
  5695. slotScopeIds = slotScopeIds
  5696. ? slotScopeIds.concat(fragmentSlotScopeIds)
  5697. : fragmentSlotScopeIds;
  5698. }
  5699. const container = parentNode(node);
  5700. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  5701. if (next && isComment(next) && next.data === ']') {
  5702. return nextSibling((vnode.anchor = next));
  5703. }
  5704. else {
  5705. // fragment didn't hydrate successfully, since we didn't get a end anchor
  5706. // back. This should have led to node/children mismatch warnings.
  5707. hasMismatch = true;
  5708. // since the anchor is missing, we need to create one and insert it
  5709. insert((vnode.anchor = createComment(`]`)), container, next);
  5710. return next;
  5711. }
  5712. };
  5713. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  5714. hasMismatch = true;
  5715. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  5716. ? `(text)`
  5717. : isComment(node) && node.data === '['
  5718. ? `(start of fragment)`
  5719. : ``);
  5720. vnode.el = null;
  5721. if (isFragment) {
  5722. // remove excessive fragment nodes
  5723. const end = locateClosingAsyncAnchor(node);
  5724. while (true) {
  5725. const next = nextSibling(node);
  5726. if (next && next !== end) {
  5727. remove(next);
  5728. }
  5729. else {
  5730. break;
  5731. }
  5732. }
  5733. }
  5734. const next = nextSibling(node);
  5735. const container = parentNode(node);
  5736. remove(node);
  5737. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  5738. return next;
  5739. };
  5740. const locateClosingAsyncAnchor = (node) => {
  5741. let match = 0;
  5742. while (node) {
  5743. node = nextSibling(node);
  5744. if (node && isComment(node)) {
  5745. if (node.data === '[')
  5746. match++;
  5747. if (node.data === ']') {
  5748. if (match === 0) {
  5749. return nextSibling(node);
  5750. }
  5751. else {
  5752. match--;
  5753. }
  5754. }
  5755. }
  5756. }
  5757. return node;
  5758. };
  5759. return [hydrate, hydrateNode];
  5760. }
  5761. /* eslint-disable no-restricted-globals */
  5762. let supported;
  5763. let perf;
  5764. function startMeasure(instance, type) {
  5765. if (instance.appContext.config.performance && isSupported()) {
  5766. perf.mark(`vue-${type}-${instance.uid}`);
  5767. }
  5768. {
  5769. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  5770. }
  5771. }
  5772. function endMeasure(instance, type) {
  5773. if (instance.appContext.config.performance && isSupported()) {
  5774. const startTag = `vue-${type}-${instance.uid}`;
  5775. const endTag = startTag + `:end`;
  5776. perf.mark(endTag);
  5777. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  5778. perf.clearMarks(startTag);
  5779. perf.clearMarks(endTag);
  5780. }
  5781. {
  5782. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  5783. }
  5784. }
  5785. function isSupported() {
  5786. if (supported !== undefined) {
  5787. return supported;
  5788. }
  5789. if (typeof window !== 'undefined' && window.performance) {
  5790. supported = true;
  5791. perf = window.performance;
  5792. }
  5793. else {
  5794. supported = false;
  5795. }
  5796. return supported;
  5797. }
  5798. const queuePostRenderEffect = queueEffectWithSuspense
  5799. ;
  5800. /**
  5801. * The createRenderer function accepts two generic arguments:
  5802. * HostNode and HostElement, corresponding to Node and Element types in the
  5803. * host environment. For example, for runtime-dom, HostNode would be the DOM
  5804. * `Node` interface and HostElement would be the DOM `Element` interface.
  5805. *
  5806. * Custom renderers can pass in the platform specific types like this:
  5807. *
  5808. * ``` js
  5809. * const { render, createApp } = createRenderer<Node, Element>({
  5810. * patchProp,
  5811. * ...nodeOps
  5812. * })
  5813. * ```
  5814. */
  5815. function createRenderer(options) {
  5816. return baseCreateRenderer(options);
  5817. }
  5818. // Separate API for creating hydration-enabled renderer.
  5819. // Hydration logic is only used when calling this function, making it
  5820. // tree-shakable.
  5821. function createHydrationRenderer(options) {
  5822. return baseCreateRenderer(options, createHydrationFunctions);
  5823. }
  5824. // implementation
  5825. function baseCreateRenderer(options, createHydrationFns) {
  5826. const target = getGlobalThis();
  5827. target.__VUE__ = true;
  5828. {
  5829. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  5830. }
  5831. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
  5832. // Note: functions inside this closure should use `const xxx = () => {}`
  5833. // style in order to prevent being inlined by minifiers.
  5834. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  5835. if (n1 === n2) {
  5836. return;
  5837. }
  5838. // patching & not same type, unmount old tree
  5839. if (n1 && !isSameVNodeType(n1, n2)) {
  5840. anchor = getNextHostNode(n1);
  5841. unmount(n1, parentComponent, parentSuspense, true);
  5842. n1 = null;
  5843. }
  5844. if (n2.patchFlag === -2 /* BAIL */) {
  5845. optimized = false;
  5846. n2.dynamicChildren = null;
  5847. }
  5848. const { type, ref, shapeFlag } = n2;
  5849. switch (type) {
  5850. case Text:
  5851. processText(n1, n2, container, anchor);
  5852. break;
  5853. case Comment:
  5854. processCommentNode(n1, n2, container, anchor);
  5855. break;
  5856. case Static:
  5857. if (n1 == null) {
  5858. mountStaticNode(n2, container, anchor, isSVG);
  5859. }
  5860. else {
  5861. patchStaticNode(n1, n2, container, isSVG);
  5862. }
  5863. break;
  5864. case Fragment:
  5865. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5866. break;
  5867. default:
  5868. if (shapeFlag & 1 /* ELEMENT */) {
  5869. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5870. }
  5871. else if (shapeFlag & 6 /* COMPONENT */) {
  5872. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5873. }
  5874. else if (shapeFlag & 64 /* TELEPORT */) {
  5875. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5876. }
  5877. else if (shapeFlag & 128 /* SUSPENSE */) {
  5878. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5879. }
  5880. else {
  5881. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  5882. }
  5883. }
  5884. // set ref
  5885. if (ref != null && parentComponent) {
  5886. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  5887. }
  5888. };
  5889. const processText = (n1, n2, container, anchor) => {
  5890. if (n1 == null) {
  5891. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  5892. }
  5893. else {
  5894. const el = (n2.el = n1.el);
  5895. if (n2.children !== n1.children) {
  5896. hostSetText(el, n2.children);
  5897. }
  5898. }
  5899. };
  5900. const processCommentNode = (n1, n2, container, anchor) => {
  5901. if (n1 == null) {
  5902. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  5903. }
  5904. else {
  5905. // there's no support for dynamic comments
  5906. n2.el = n1.el;
  5907. }
  5908. };
  5909. const mountStaticNode = (n2, container, anchor, isSVG) => {
  5910. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  5911. };
  5912. /**
  5913. * Dev / HMR only
  5914. */
  5915. const patchStaticNode = (n1, n2, container, isSVG) => {
  5916. // static nodes are only patched during dev for HMR
  5917. if (n2.children !== n1.children) {
  5918. const anchor = hostNextSibling(n1.anchor);
  5919. // remove existing
  5920. removeStaticNode(n1);
  5921. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5922. }
  5923. else {
  5924. n2.el = n1.el;
  5925. n2.anchor = n1.anchor;
  5926. }
  5927. };
  5928. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  5929. let next;
  5930. while (el && el !== anchor) {
  5931. next = hostNextSibling(el);
  5932. hostInsert(el, container, nextSibling);
  5933. el = next;
  5934. }
  5935. hostInsert(anchor, container, nextSibling);
  5936. };
  5937. const removeStaticNode = ({ el, anchor }) => {
  5938. let next;
  5939. while (el && el !== anchor) {
  5940. next = hostNextSibling(el);
  5941. hostRemove(el);
  5942. el = next;
  5943. }
  5944. hostRemove(anchor);
  5945. };
  5946. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5947. isSVG = isSVG || n2.type === 'svg';
  5948. if (n1 == null) {
  5949. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5950. }
  5951. else {
  5952. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5953. }
  5954. };
  5955. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5956. let el;
  5957. let vnodeHook;
  5958. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  5959. {
  5960. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  5961. // mount children first, since some props may rely on child content
  5962. // being already rendered, e.g. `<select value>`
  5963. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5964. hostSetElementText(el, vnode.children);
  5965. }
  5966. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5967. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  5968. }
  5969. if (dirs) {
  5970. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5971. }
  5972. // props
  5973. if (props) {
  5974. for (const key in props) {
  5975. if (key !== 'value' && !isReservedProp(key)) {
  5976. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5977. }
  5978. }
  5979. /**
  5980. * Special case for setting value on DOM elements:
  5981. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  5982. * - it needs to be forced (#1471)
  5983. * #2353 proposes adding another renderer option to configure this, but
  5984. * the properties affects are so finite it is worth special casing it
  5985. * here to reduce the complexity. (Special casing it also should not
  5986. * affect non-DOM renderers)
  5987. */
  5988. if ('value' in props) {
  5989. hostPatchProp(el, 'value', null, props.value);
  5990. }
  5991. if ((vnodeHook = props.onVnodeBeforeMount)) {
  5992. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5993. }
  5994. }
  5995. // scopeId
  5996. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  5997. }
  5998. {
  5999. Object.defineProperty(el, '__vnode', {
  6000. value: vnode,
  6001. enumerable: false
  6002. });
  6003. Object.defineProperty(el, '__vueParentComponent', {
  6004. value: parentComponent,
  6005. enumerable: false
  6006. });
  6007. }
  6008. if (dirs) {
  6009. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6010. }
  6011. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6012. // #1689 For inside suspense + suspense resolved case, just call it
  6013. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6014. transition &&
  6015. !transition.persisted;
  6016. if (needCallTransitionHooks) {
  6017. transition.beforeEnter(el);
  6018. }
  6019. hostInsert(el, container, anchor);
  6020. if ((vnodeHook = props && props.onVnodeMounted) ||
  6021. needCallTransitionHooks ||
  6022. dirs) {
  6023. queuePostRenderEffect(() => {
  6024. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6025. needCallTransitionHooks && transition.enter(el);
  6026. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6027. }, parentSuspense);
  6028. }
  6029. };
  6030. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6031. if (scopeId) {
  6032. hostSetScopeId(el, scopeId);
  6033. }
  6034. if (slotScopeIds) {
  6035. for (let i = 0; i < slotScopeIds.length; i++) {
  6036. hostSetScopeId(el, slotScopeIds[i]);
  6037. }
  6038. }
  6039. if (parentComponent) {
  6040. let subTree = parentComponent.subTree;
  6041. if (subTree.patchFlag > 0 &&
  6042. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  6043. subTree =
  6044. filterSingleRoot(subTree.children) || subTree;
  6045. }
  6046. if (vnode === subTree) {
  6047. const parentVNode = parentComponent.vnode;
  6048. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6049. }
  6050. }
  6051. };
  6052. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6053. for (let i = start; i < children.length; i++) {
  6054. const child = (children[i] = optimized
  6055. ? cloneIfMounted(children[i])
  6056. : normalizeVNode(children[i]));
  6057. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6058. }
  6059. };
  6060. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6061. const el = (n2.el = n1.el);
  6062. let { patchFlag, dynamicChildren, dirs } = n2;
  6063. // #1426 take the old vnode's patch flag into account since user may clone a
  6064. // compiler-generated vnode, which de-opts to FULL_PROPS
  6065. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  6066. const oldProps = n1.props || EMPTY_OBJ;
  6067. const newProps = n2.props || EMPTY_OBJ;
  6068. let vnodeHook;
  6069. // disable recurse in beforeUpdate hooks
  6070. parentComponent && toggleRecurse(parentComponent, false);
  6071. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6072. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6073. }
  6074. if (dirs) {
  6075. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6076. }
  6077. parentComponent && toggleRecurse(parentComponent, true);
  6078. if (isHmrUpdating) {
  6079. // HMR updated, force full diff
  6080. patchFlag = 0;
  6081. optimized = false;
  6082. dynamicChildren = null;
  6083. }
  6084. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6085. if (dynamicChildren) {
  6086. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6087. if (parentComponent && parentComponent.type.__hmrId) {
  6088. traverseStaticChildren(n1, n2);
  6089. }
  6090. }
  6091. else if (!optimized) {
  6092. // full diff
  6093. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6094. }
  6095. if (patchFlag > 0) {
  6096. // the presence of a patchFlag means this element's render code was
  6097. // generated by the compiler and can take the fast path.
  6098. // in this path old node and new node are guaranteed to have the same shape
  6099. // (i.e. at the exact same position in the source template)
  6100. if (patchFlag & 16 /* FULL_PROPS */) {
  6101. // element props contain dynamic keys, full diff needed
  6102. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6103. }
  6104. else {
  6105. // class
  6106. // this flag is matched when the element has dynamic class bindings.
  6107. if (patchFlag & 2 /* CLASS */) {
  6108. if (oldProps.class !== newProps.class) {
  6109. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6110. }
  6111. }
  6112. // style
  6113. // this flag is matched when the element has dynamic style bindings
  6114. if (patchFlag & 4 /* STYLE */) {
  6115. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6116. }
  6117. // props
  6118. // This flag is matched when the element has dynamic prop/attr bindings
  6119. // other than class and style. The keys of dynamic prop/attrs are saved for
  6120. // faster iteration.
  6121. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6122. // bail out and go through a full diff because we need to unset the old key
  6123. if (patchFlag & 8 /* PROPS */) {
  6124. // if the flag is present then dynamicProps must be non-null
  6125. const propsToUpdate = n2.dynamicProps;
  6126. for (let i = 0; i < propsToUpdate.length; i++) {
  6127. const key = propsToUpdate[i];
  6128. const prev = oldProps[key];
  6129. const next = newProps[key];
  6130. // #1471 force patch value
  6131. if (next !== prev || key === 'value') {
  6132. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6133. }
  6134. }
  6135. }
  6136. }
  6137. // text
  6138. // This flag is matched when the element has only dynamic text children.
  6139. if (patchFlag & 1 /* TEXT */) {
  6140. if (n1.children !== n2.children) {
  6141. hostSetElementText(el, n2.children);
  6142. }
  6143. }
  6144. }
  6145. else if (!optimized && dynamicChildren == null) {
  6146. // unoptimized, full diff
  6147. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6148. }
  6149. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6150. queuePostRenderEffect(() => {
  6151. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6152. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6153. }, parentSuspense);
  6154. }
  6155. };
  6156. // The fast path for blocks.
  6157. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6158. for (let i = 0; i < newChildren.length; i++) {
  6159. const oldVNode = oldChildren[i];
  6160. const newVNode = newChildren[i];
  6161. // Determine the container (parent element) for the patch.
  6162. const container =
  6163. // oldVNode may be an errored async setup() component inside Suspense
  6164. // which will not have a mounted element
  6165. oldVNode.el &&
  6166. // - In the case of a Fragment, we need to provide the actual parent
  6167. // of the Fragment itself so it can move its children.
  6168. (oldVNode.type === Fragment ||
  6169. // - In the case of different nodes, there is going to be a replacement
  6170. // which also requires the correct parent container
  6171. !isSameVNodeType(oldVNode, newVNode) ||
  6172. // - In the case of a component, it could contain anything.
  6173. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  6174. ? hostParentNode(oldVNode.el)
  6175. : // In other cases, the parent container is not actually used so we
  6176. // just pass the block element here to avoid a DOM parentNode call.
  6177. fallbackContainer;
  6178. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6179. }
  6180. };
  6181. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6182. if (oldProps !== newProps) {
  6183. for (const key in newProps) {
  6184. // empty string is not valid prop
  6185. if (isReservedProp(key))
  6186. continue;
  6187. const next = newProps[key];
  6188. const prev = oldProps[key];
  6189. // defer patching value
  6190. if (next !== prev && key !== 'value') {
  6191. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6192. }
  6193. }
  6194. if (oldProps !== EMPTY_OBJ) {
  6195. for (const key in oldProps) {
  6196. if (!isReservedProp(key) && !(key in newProps)) {
  6197. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6198. }
  6199. }
  6200. }
  6201. if ('value' in newProps) {
  6202. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6203. }
  6204. }
  6205. };
  6206. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6207. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6208. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6209. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6210. if (isHmrUpdating) {
  6211. // HMR updated, force full diff
  6212. patchFlag = 0;
  6213. optimized = false;
  6214. dynamicChildren = null;
  6215. }
  6216. // check if this is a slot fragment with :slotted scope ids
  6217. if (fragmentSlotScopeIds) {
  6218. slotScopeIds = slotScopeIds
  6219. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6220. : fragmentSlotScopeIds;
  6221. }
  6222. if (n1 == null) {
  6223. hostInsert(fragmentStartAnchor, container, anchor);
  6224. hostInsert(fragmentEndAnchor, container, anchor);
  6225. // a fragment can only have array children
  6226. // since they are either generated by the compiler, or implicitly created
  6227. // from arrays.
  6228. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6229. }
  6230. else {
  6231. if (patchFlag > 0 &&
  6232. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  6233. dynamicChildren &&
  6234. // #2715 the previous fragment could've been a BAILed one as a result
  6235. // of renderSlot() with no valid children
  6236. n1.dynamicChildren) {
  6237. // a stable fragment (template root or <template v-for>) doesn't need to
  6238. // patch children order, but it may contain dynamicChildren.
  6239. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6240. if (parentComponent && parentComponent.type.__hmrId) {
  6241. traverseStaticChildren(n1, n2);
  6242. }
  6243. else if (
  6244. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6245. // get moved around. Make sure all root level vnodes inherit el.
  6246. // #2134 or if it's a component root, it may also get moved around
  6247. // as the component is being moved.
  6248. n2.key != null ||
  6249. (parentComponent && n2 === parentComponent.subTree)) {
  6250. traverseStaticChildren(n1, n2, true /* shallow */);
  6251. }
  6252. }
  6253. else {
  6254. // keyed / unkeyed, or manual fragments.
  6255. // for keyed & unkeyed, since they are compiler generated from v-for,
  6256. // each child is guaranteed to be a block so the fragment will never
  6257. // have dynamicChildren.
  6258. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6259. }
  6260. }
  6261. };
  6262. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6263. n2.slotScopeIds = slotScopeIds;
  6264. if (n1 == null) {
  6265. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  6266. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6267. }
  6268. else {
  6269. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6270. }
  6271. }
  6272. else {
  6273. updateComponent(n1, n2, optimized);
  6274. }
  6275. };
  6276. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6277. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6278. if (instance.type.__hmrId) {
  6279. registerHMR(instance);
  6280. }
  6281. {
  6282. pushWarningContext(initialVNode);
  6283. startMeasure(instance, `mount`);
  6284. }
  6285. // inject renderer internals for keepAlive
  6286. if (isKeepAlive(initialVNode)) {
  6287. instance.ctx.renderer = internals;
  6288. }
  6289. // resolve props and slots for setup context
  6290. {
  6291. {
  6292. startMeasure(instance, `init`);
  6293. }
  6294. setupComponent(instance);
  6295. {
  6296. endMeasure(instance, `init`);
  6297. }
  6298. }
  6299. // setup() is async. This component relies on async logic to be resolved
  6300. // before proceeding
  6301. if (instance.asyncDep) {
  6302. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6303. // Give it a placeholder if this is not hydration
  6304. // TODO handle self-defined fallback
  6305. if (!initialVNode.el) {
  6306. const placeholder = (instance.subTree = createVNode(Comment));
  6307. processCommentNode(null, placeholder, container, anchor);
  6308. }
  6309. return;
  6310. }
  6311. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6312. {
  6313. popWarningContext();
  6314. endMeasure(instance, `mount`);
  6315. }
  6316. };
  6317. const updateComponent = (n1, n2, optimized) => {
  6318. const instance = (n2.component = n1.component);
  6319. if (shouldUpdateComponent(n1, n2, optimized)) {
  6320. if (instance.asyncDep &&
  6321. !instance.asyncResolved) {
  6322. // async & still pending - just update props and slots
  6323. // since the component's reactive effect for render isn't set-up yet
  6324. {
  6325. pushWarningContext(n2);
  6326. }
  6327. updateComponentPreRender(instance, n2, optimized);
  6328. {
  6329. popWarningContext();
  6330. }
  6331. return;
  6332. }
  6333. else {
  6334. // normal update
  6335. instance.next = n2;
  6336. // in case the child component is also queued, remove it to avoid
  6337. // double updating the same child component in the same flush.
  6338. invalidateJob(instance.update);
  6339. // instance.update is the reactive effect.
  6340. instance.update();
  6341. }
  6342. }
  6343. else {
  6344. // no update needed. just copy over properties
  6345. n2.component = n1.component;
  6346. n2.el = n1.el;
  6347. instance.vnode = n2;
  6348. }
  6349. };
  6350. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6351. const componentUpdateFn = () => {
  6352. if (!instance.isMounted) {
  6353. let vnodeHook;
  6354. const { el, props } = initialVNode;
  6355. const { bm, m, parent } = instance;
  6356. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6357. toggleRecurse(instance, false);
  6358. // beforeMount hook
  6359. if (bm) {
  6360. invokeArrayFns(bm);
  6361. }
  6362. // onVnodeBeforeMount
  6363. if (!isAsyncWrapperVNode &&
  6364. (vnodeHook = props && props.onVnodeBeforeMount)) {
  6365. invokeVNodeHook(vnodeHook, parent, initialVNode);
  6366. }
  6367. toggleRecurse(instance, true);
  6368. if (el && hydrateNode) {
  6369. // vnode has adopted host node - perform hydration instead of mount.
  6370. const hydrateSubTree = () => {
  6371. {
  6372. startMeasure(instance, `render`);
  6373. }
  6374. instance.subTree = renderComponentRoot(instance);
  6375. {
  6376. endMeasure(instance, `render`);
  6377. }
  6378. {
  6379. startMeasure(instance, `hydrate`);
  6380. }
  6381. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  6382. {
  6383. endMeasure(instance, `hydrate`);
  6384. }
  6385. };
  6386. if (isAsyncWrapperVNode) {
  6387. initialVNode.type.__asyncLoader().then(
  6388. // note: we are moving the render call into an async callback,
  6389. // which means it won't track dependencies - but it's ok because
  6390. // a server-rendered async wrapper is already in resolved state
  6391. // and it will never need to change.
  6392. () => !instance.isUnmounted && hydrateSubTree());
  6393. }
  6394. else {
  6395. hydrateSubTree();
  6396. }
  6397. }
  6398. else {
  6399. {
  6400. startMeasure(instance, `render`);
  6401. }
  6402. const subTree = (instance.subTree = renderComponentRoot(instance));
  6403. {
  6404. endMeasure(instance, `render`);
  6405. }
  6406. {
  6407. startMeasure(instance, `patch`);
  6408. }
  6409. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  6410. {
  6411. endMeasure(instance, `patch`);
  6412. }
  6413. initialVNode.el = subTree.el;
  6414. }
  6415. // mounted hook
  6416. if (m) {
  6417. queuePostRenderEffect(m, parentSuspense);
  6418. }
  6419. // onVnodeMounted
  6420. if (!isAsyncWrapperVNode &&
  6421. (vnodeHook = props && props.onVnodeMounted)) {
  6422. const scopedInitialVNode = initialVNode;
  6423. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  6424. }
  6425. // activated hook for keep-alive roots.
  6426. // #1742 activated hook must be accessed after first render
  6427. // since the hook may be injected by a child keep-alive
  6428. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6429. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  6430. }
  6431. instance.isMounted = true;
  6432. {
  6433. devtoolsComponentAdded(instance);
  6434. }
  6435. // #2458: deference mount-only object parameters to prevent memleaks
  6436. initialVNode = container = anchor = null;
  6437. }
  6438. else {
  6439. // updateComponent
  6440. // This is triggered by mutation of component's own state (next: null)
  6441. // OR parent calling processComponent (next: VNode)
  6442. let { next, bu, u, parent, vnode } = instance;
  6443. let originNext = next;
  6444. let vnodeHook;
  6445. {
  6446. pushWarningContext(next || instance.vnode);
  6447. }
  6448. // Disallow component effect recursion during pre-lifecycle hooks.
  6449. toggleRecurse(instance, false);
  6450. if (next) {
  6451. next.el = vnode.el;
  6452. updateComponentPreRender(instance, next, optimized);
  6453. }
  6454. else {
  6455. next = vnode;
  6456. }
  6457. // beforeUpdate hook
  6458. if (bu) {
  6459. invokeArrayFns(bu);
  6460. }
  6461. // onVnodeBeforeUpdate
  6462. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  6463. invokeVNodeHook(vnodeHook, parent, next, vnode);
  6464. }
  6465. toggleRecurse(instance, true);
  6466. // render
  6467. {
  6468. startMeasure(instance, `render`);
  6469. }
  6470. const nextTree = renderComponentRoot(instance);
  6471. {
  6472. endMeasure(instance, `render`);
  6473. }
  6474. const prevTree = instance.subTree;
  6475. instance.subTree = nextTree;
  6476. {
  6477. startMeasure(instance, `patch`);
  6478. }
  6479. patch(prevTree, nextTree,
  6480. // parent may have changed if it's in a teleport
  6481. hostParentNode(prevTree.el),
  6482. // anchor may have changed if it's in a fragment
  6483. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  6484. {
  6485. endMeasure(instance, `patch`);
  6486. }
  6487. next.el = nextTree.el;
  6488. if (originNext === null) {
  6489. // self-triggered update. In case of HOC, update parent component
  6490. // vnode el. HOC is indicated by parent instance's subTree pointing
  6491. // to child component's vnode
  6492. updateHOCHostEl(instance, nextTree.el);
  6493. }
  6494. // updated hook
  6495. if (u) {
  6496. queuePostRenderEffect(u, parentSuspense);
  6497. }
  6498. // onVnodeUpdated
  6499. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  6500. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  6501. }
  6502. {
  6503. devtoolsComponentUpdated(instance);
  6504. }
  6505. {
  6506. popWarningContext();
  6507. }
  6508. }
  6509. };
  6510. // create reactive effect for rendering
  6511. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
  6512. ));
  6513. const update = (instance.update = effect.run.bind(effect));
  6514. update.id = instance.uid;
  6515. // allowRecurse
  6516. // #1801, #2043 component render effects should allow recursive updates
  6517. toggleRecurse(instance, true);
  6518. {
  6519. effect.onTrack = instance.rtc
  6520. ? e => invokeArrayFns(instance.rtc, e)
  6521. : void 0;
  6522. effect.onTrigger = instance.rtg
  6523. ? e => invokeArrayFns(instance.rtg, e)
  6524. : void 0;
  6525. // @ts-ignore (for scheduler)
  6526. update.ownerInstance = instance;
  6527. }
  6528. update();
  6529. };
  6530. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  6531. nextVNode.component = instance;
  6532. const prevProps = instance.vnode.props;
  6533. instance.vnode = nextVNode;
  6534. instance.next = null;
  6535. updateProps(instance, nextVNode.props, prevProps, optimized);
  6536. updateSlots(instance, nextVNode.children, optimized);
  6537. pauseTracking();
  6538. // props update may have triggered pre-flush watchers.
  6539. // flush them before the render update.
  6540. flushPreFlushCbs(undefined, instance.update);
  6541. resetTracking();
  6542. };
  6543. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  6544. const c1 = n1 && n1.children;
  6545. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  6546. const c2 = n2.children;
  6547. const { patchFlag, shapeFlag } = n2;
  6548. // fast path
  6549. if (patchFlag > 0) {
  6550. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  6551. // this could be either fully-keyed or mixed (some keyed some not)
  6552. // presence of patchFlag means children are guaranteed to be arrays
  6553. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6554. return;
  6555. }
  6556. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  6557. // unkeyed
  6558. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6559. return;
  6560. }
  6561. }
  6562. // children has 3 possibilities: text, array or no children.
  6563. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6564. // text children fast path
  6565. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  6566. unmountChildren(c1, parentComponent, parentSuspense);
  6567. }
  6568. if (c2 !== c1) {
  6569. hostSetElementText(container, c2);
  6570. }
  6571. }
  6572. else {
  6573. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  6574. // prev children was array
  6575. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6576. // two arrays, cannot assume anything, do full diff
  6577. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6578. }
  6579. else {
  6580. // no new children, just unmount old
  6581. unmountChildren(c1, parentComponent, parentSuspense, true);
  6582. }
  6583. }
  6584. else {
  6585. // prev children was text OR null
  6586. // new children is array OR null
  6587. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  6588. hostSetElementText(container, '');
  6589. }
  6590. // mount new if array
  6591. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6592. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6593. }
  6594. }
  6595. }
  6596. };
  6597. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6598. c1 = c1 || EMPTY_ARR;
  6599. c2 = c2 || EMPTY_ARR;
  6600. const oldLength = c1.length;
  6601. const newLength = c2.length;
  6602. const commonLength = Math.min(oldLength, newLength);
  6603. let i;
  6604. for (i = 0; i < commonLength; i++) {
  6605. const nextChild = (c2[i] = optimized
  6606. ? cloneIfMounted(c2[i])
  6607. : normalizeVNode(c2[i]));
  6608. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6609. }
  6610. if (oldLength > newLength) {
  6611. // remove old
  6612. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  6613. }
  6614. else {
  6615. // mount new
  6616. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  6617. }
  6618. };
  6619. // can be all-keyed or mixed
  6620. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6621. let i = 0;
  6622. const l2 = c2.length;
  6623. let e1 = c1.length - 1; // prev ending index
  6624. let e2 = l2 - 1; // next ending index
  6625. // 1. sync from start
  6626. // (a b) c
  6627. // (a b) d e
  6628. while (i <= e1 && i <= e2) {
  6629. const n1 = c1[i];
  6630. const n2 = (c2[i] = optimized
  6631. ? cloneIfMounted(c2[i])
  6632. : normalizeVNode(c2[i]));
  6633. if (isSameVNodeType(n1, n2)) {
  6634. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6635. }
  6636. else {
  6637. break;
  6638. }
  6639. i++;
  6640. }
  6641. // 2. sync from end
  6642. // a (b c)
  6643. // d e (b c)
  6644. while (i <= e1 && i <= e2) {
  6645. const n1 = c1[e1];
  6646. const n2 = (c2[e2] = optimized
  6647. ? cloneIfMounted(c2[e2])
  6648. : normalizeVNode(c2[e2]));
  6649. if (isSameVNodeType(n1, n2)) {
  6650. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6651. }
  6652. else {
  6653. break;
  6654. }
  6655. e1--;
  6656. e2--;
  6657. }
  6658. // 3. common sequence + mount
  6659. // (a b)
  6660. // (a b) c
  6661. // i = 2, e1 = 1, e2 = 2
  6662. // (a b)
  6663. // c (a b)
  6664. // i = 0, e1 = -1, e2 = 0
  6665. if (i > e1) {
  6666. if (i <= e2) {
  6667. const nextPos = e2 + 1;
  6668. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  6669. while (i <= e2) {
  6670. patch(null, (c2[i] = optimized
  6671. ? cloneIfMounted(c2[i])
  6672. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6673. i++;
  6674. }
  6675. }
  6676. }
  6677. // 4. common sequence + unmount
  6678. // (a b) c
  6679. // (a b)
  6680. // i = 2, e1 = 2, e2 = 1
  6681. // a (b c)
  6682. // (b c)
  6683. // i = 0, e1 = 0, e2 = -1
  6684. else if (i > e2) {
  6685. while (i <= e1) {
  6686. unmount(c1[i], parentComponent, parentSuspense, true);
  6687. i++;
  6688. }
  6689. }
  6690. // 5. unknown sequence
  6691. // [i ... e1 + 1]: a b [c d e] f g
  6692. // [i ... e2 + 1]: a b [e d c h] f g
  6693. // i = 2, e1 = 4, e2 = 5
  6694. else {
  6695. const s1 = i; // prev starting index
  6696. const s2 = i; // next starting index
  6697. // 5.1 build key:index map for newChildren
  6698. const keyToNewIndexMap = new Map();
  6699. for (i = s2; i <= e2; i++) {
  6700. const nextChild = (c2[i] = optimized
  6701. ? cloneIfMounted(c2[i])
  6702. : normalizeVNode(c2[i]));
  6703. if (nextChild.key != null) {
  6704. if (keyToNewIndexMap.has(nextChild.key)) {
  6705. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  6706. }
  6707. keyToNewIndexMap.set(nextChild.key, i);
  6708. }
  6709. }
  6710. // 5.2 loop through old children left to be patched and try to patch
  6711. // matching nodes & remove nodes that are no longer present
  6712. let j;
  6713. let patched = 0;
  6714. const toBePatched = e2 - s2 + 1;
  6715. let moved = false;
  6716. // used to track whether any node has moved
  6717. let maxNewIndexSoFar = 0;
  6718. // works as Map<newIndex, oldIndex>
  6719. // Note that oldIndex is offset by +1
  6720. // and oldIndex = 0 is a special value indicating the new node has
  6721. // no corresponding old node.
  6722. // used for determining longest stable subsequence
  6723. const newIndexToOldIndexMap = new Array(toBePatched);
  6724. for (i = 0; i < toBePatched; i++)
  6725. newIndexToOldIndexMap[i] = 0;
  6726. for (i = s1; i <= e1; i++) {
  6727. const prevChild = c1[i];
  6728. if (patched >= toBePatched) {
  6729. // all new children have been patched so this can only be a removal
  6730. unmount(prevChild, parentComponent, parentSuspense, true);
  6731. continue;
  6732. }
  6733. let newIndex;
  6734. if (prevChild.key != null) {
  6735. newIndex = keyToNewIndexMap.get(prevChild.key);
  6736. }
  6737. else {
  6738. // key-less node, try to locate a key-less node of the same type
  6739. for (j = s2; j <= e2; j++) {
  6740. if (newIndexToOldIndexMap[j - s2] === 0 &&
  6741. isSameVNodeType(prevChild, c2[j])) {
  6742. newIndex = j;
  6743. break;
  6744. }
  6745. }
  6746. }
  6747. if (newIndex === undefined) {
  6748. unmount(prevChild, parentComponent, parentSuspense, true);
  6749. }
  6750. else {
  6751. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  6752. if (newIndex >= maxNewIndexSoFar) {
  6753. maxNewIndexSoFar = newIndex;
  6754. }
  6755. else {
  6756. moved = true;
  6757. }
  6758. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6759. patched++;
  6760. }
  6761. }
  6762. // 5.3 move and mount
  6763. // generate longest stable subsequence only when nodes have moved
  6764. const increasingNewIndexSequence = moved
  6765. ? getSequence(newIndexToOldIndexMap)
  6766. : EMPTY_ARR;
  6767. j = increasingNewIndexSequence.length - 1;
  6768. // looping backwards so that we can use last patched node as anchor
  6769. for (i = toBePatched - 1; i >= 0; i--) {
  6770. const nextIndex = s2 + i;
  6771. const nextChild = c2[nextIndex];
  6772. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  6773. if (newIndexToOldIndexMap[i] === 0) {
  6774. // mount new
  6775. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6776. }
  6777. else if (moved) {
  6778. // move if:
  6779. // There is no stable subsequence (e.g. a reverse)
  6780. // OR current node is not among the stable sequence
  6781. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  6782. move(nextChild, container, anchor, 2 /* REORDER */);
  6783. }
  6784. else {
  6785. j--;
  6786. }
  6787. }
  6788. }
  6789. }
  6790. };
  6791. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  6792. const { el, type, transition, children, shapeFlag } = vnode;
  6793. if (shapeFlag & 6 /* COMPONENT */) {
  6794. move(vnode.component.subTree, container, anchor, moveType);
  6795. return;
  6796. }
  6797. if (shapeFlag & 128 /* SUSPENSE */) {
  6798. vnode.suspense.move(container, anchor, moveType);
  6799. return;
  6800. }
  6801. if (shapeFlag & 64 /* TELEPORT */) {
  6802. type.move(vnode, container, anchor, internals);
  6803. return;
  6804. }
  6805. if (type === Fragment) {
  6806. hostInsert(el, container, anchor);
  6807. for (let i = 0; i < children.length; i++) {
  6808. move(children[i], container, anchor, moveType);
  6809. }
  6810. hostInsert(vnode.anchor, container, anchor);
  6811. return;
  6812. }
  6813. if (type === Static) {
  6814. moveStaticNode(vnode, container, anchor);
  6815. return;
  6816. }
  6817. // single nodes
  6818. const needTransition = moveType !== 2 /* REORDER */ &&
  6819. shapeFlag & 1 /* ELEMENT */ &&
  6820. transition;
  6821. if (needTransition) {
  6822. if (moveType === 0 /* ENTER */) {
  6823. transition.beforeEnter(el);
  6824. hostInsert(el, container, anchor);
  6825. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  6826. }
  6827. else {
  6828. const { leave, delayLeave, afterLeave } = transition;
  6829. const remove = () => hostInsert(el, container, anchor);
  6830. const performLeave = () => {
  6831. leave(el, () => {
  6832. remove();
  6833. afterLeave && afterLeave();
  6834. });
  6835. };
  6836. if (delayLeave) {
  6837. delayLeave(el, remove, performLeave);
  6838. }
  6839. else {
  6840. performLeave();
  6841. }
  6842. }
  6843. }
  6844. else {
  6845. hostInsert(el, container, anchor);
  6846. }
  6847. };
  6848. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  6849. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  6850. // unset ref
  6851. if (ref != null) {
  6852. setRef(ref, null, parentSuspense, vnode, true);
  6853. }
  6854. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6855. parentComponent.ctx.deactivate(vnode);
  6856. return;
  6857. }
  6858. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  6859. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  6860. let vnodeHook;
  6861. if (shouldInvokeVnodeHook &&
  6862. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  6863. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6864. }
  6865. if (shapeFlag & 6 /* COMPONENT */) {
  6866. unmountComponent(vnode.component, parentSuspense, doRemove);
  6867. }
  6868. else {
  6869. if (shapeFlag & 128 /* SUSPENSE */) {
  6870. vnode.suspense.unmount(parentSuspense, doRemove);
  6871. return;
  6872. }
  6873. if (shouldInvokeDirs) {
  6874. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  6875. }
  6876. if (shapeFlag & 64 /* TELEPORT */) {
  6877. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  6878. }
  6879. else if (dynamicChildren &&
  6880. // #1153: fast path should not be taken for non-stable (v-for) fragments
  6881. (type !== Fragment ||
  6882. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  6883. // fast path for block nodes: only need to unmount dynamic children.
  6884. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  6885. }
  6886. else if ((type === Fragment &&
  6887. patchFlag &
  6888. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  6889. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  6890. unmountChildren(children, parentComponent, parentSuspense);
  6891. }
  6892. if (doRemove) {
  6893. remove(vnode);
  6894. }
  6895. }
  6896. if ((shouldInvokeVnodeHook &&
  6897. (vnodeHook = props && props.onVnodeUnmounted)) ||
  6898. shouldInvokeDirs) {
  6899. queuePostRenderEffect(() => {
  6900. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6901. shouldInvokeDirs &&
  6902. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  6903. }, parentSuspense);
  6904. }
  6905. };
  6906. const remove = vnode => {
  6907. const { type, el, anchor, transition } = vnode;
  6908. if (type === Fragment) {
  6909. if (vnode.patchFlag > 0 &&
  6910. vnode.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */ &&
  6911. transition &&
  6912. !transition.persisted) {
  6913. vnode.children.forEach(child => {
  6914. if (child.type === Comment) {
  6915. hostRemove(child.el);
  6916. }
  6917. else {
  6918. remove(child);
  6919. }
  6920. });
  6921. }
  6922. else {
  6923. removeFragment(el, anchor);
  6924. }
  6925. return;
  6926. }
  6927. if (type === Static) {
  6928. removeStaticNode(vnode);
  6929. return;
  6930. }
  6931. const performRemove = () => {
  6932. hostRemove(el);
  6933. if (transition && !transition.persisted && transition.afterLeave) {
  6934. transition.afterLeave();
  6935. }
  6936. };
  6937. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  6938. transition &&
  6939. !transition.persisted) {
  6940. const { leave, delayLeave } = transition;
  6941. const performLeave = () => leave(el, performRemove);
  6942. if (delayLeave) {
  6943. delayLeave(vnode.el, performRemove, performLeave);
  6944. }
  6945. else {
  6946. performLeave();
  6947. }
  6948. }
  6949. else {
  6950. performRemove();
  6951. }
  6952. };
  6953. const removeFragment = (cur, end) => {
  6954. // For fragments, directly remove all contained DOM nodes.
  6955. // (fragment child nodes cannot have transition)
  6956. let next;
  6957. while (cur !== end) {
  6958. next = hostNextSibling(cur);
  6959. hostRemove(cur);
  6960. cur = next;
  6961. }
  6962. hostRemove(end);
  6963. };
  6964. const unmountComponent = (instance, parentSuspense, doRemove) => {
  6965. if (instance.type.__hmrId) {
  6966. unregisterHMR(instance);
  6967. }
  6968. const { bum, scope, update, subTree, um } = instance;
  6969. // beforeUnmount hook
  6970. if (bum) {
  6971. invokeArrayFns(bum);
  6972. }
  6973. // stop effects in component scope
  6974. scope.stop();
  6975. // update may be null if a component is unmounted before its async
  6976. // setup has resolved.
  6977. if (update) {
  6978. // so that scheduler will no longer invoke it
  6979. update.active = false;
  6980. unmount(subTree, instance, parentSuspense, doRemove);
  6981. }
  6982. // unmounted hook
  6983. if (um) {
  6984. queuePostRenderEffect(um, parentSuspense);
  6985. }
  6986. queuePostRenderEffect(() => {
  6987. instance.isUnmounted = true;
  6988. }, parentSuspense);
  6989. // A component with async dep inside a pending suspense is unmounted before
  6990. // its async dep resolves. This should remove the dep from the suspense, and
  6991. // cause the suspense to resolve immediately if that was the last dep.
  6992. if (parentSuspense &&
  6993. parentSuspense.pendingBranch &&
  6994. !parentSuspense.isUnmounted &&
  6995. instance.asyncDep &&
  6996. !instance.asyncResolved &&
  6997. instance.suspenseId === parentSuspense.pendingId) {
  6998. parentSuspense.deps--;
  6999. if (parentSuspense.deps === 0) {
  7000. parentSuspense.resolve();
  7001. }
  7002. }
  7003. {
  7004. devtoolsComponentRemoved(instance);
  7005. }
  7006. };
  7007. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7008. for (let i = start; i < children.length; i++) {
  7009. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7010. }
  7011. };
  7012. const getNextHostNode = vnode => {
  7013. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  7014. return getNextHostNode(vnode.component.subTree);
  7015. }
  7016. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  7017. return vnode.suspense.next();
  7018. }
  7019. return hostNextSibling((vnode.anchor || vnode.el));
  7020. };
  7021. const render = (vnode, container, isSVG) => {
  7022. if (vnode == null) {
  7023. if (container._vnode) {
  7024. unmount(container._vnode, null, null, true);
  7025. }
  7026. }
  7027. else {
  7028. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7029. }
  7030. flushPostFlushCbs();
  7031. container._vnode = vnode;
  7032. };
  7033. const internals = {
  7034. p: patch,
  7035. um: unmount,
  7036. m: move,
  7037. r: remove,
  7038. mt: mountComponent,
  7039. mc: mountChildren,
  7040. pc: patchChildren,
  7041. pbc: patchBlockChildren,
  7042. n: getNextHostNode,
  7043. o: options
  7044. };
  7045. let hydrate;
  7046. let hydrateNode;
  7047. if (createHydrationFns) {
  7048. [hydrate, hydrateNode] = createHydrationFns(internals);
  7049. }
  7050. return {
  7051. render,
  7052. hydrate,
  7053. createApp: createAppAPI(render, hydrate)
  7054. };
  7055. }
  7056. function toggleRecurse({ effect, update }, allowed) {
  7057. effect.allowRecurse = update.allowRecurse = allowed;
  7058. }
  7059. /**
  7060. * #1156
  7061. * When a component is HMR-enabled, we need to make sure that all static nodes
  7062. * inside a block also inherit the DOM element from the previous tree so that
  7063. * HMR updates (which are full updates) can retrieve the element for patching.
  7064. *
  7065. * #2080
  7066. * Inside keyed `template` fragment static children, if a fragment is moved,
  7067. * the children will always be moved. Therefore, in order to ensure correct move
  7068. * position, el should be inherited from previous nodes.
  7069. */
  7070. function traverseStaticChildren(n1, n2, shallow = false) {
  7071. const ch1 = n1.children;
  7072. const ch2 = n2.children;
  7073. if (isArray(ch1) && isArray(ch2)) {
  7074. for (let i = 0; i < ch1.length; i++) {
  7075. // this is only called in the optimized path so array children are
  7076. // guaranteed to be vnodes
  7077. const c1 = ch1[i];
  7078. let c2 = ch2[i];
  7079. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  7080. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  7081. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7082. c2.el = c1.el;
  7083. }
  7084. if (!shallow)
  7085. traverseStaticChildren(c1, c2);
  7086. }
  7087. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7088. // would have received .el during block patch)
  7089. if (c2.type === Comment && !c2.el) {
  7090. c2.el = c1.el;
  7091. }
  7092. }
  7093. }
  7094. }
  7095. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7096. function getSequence(arr) {
  7097. const p = arr.slice();
  7098. const result = [0];
  7099. let i, j, u, v, c;
  7100. const len = arr.length;
  7101. for (i = 0; i < len; i++) {
  7102. const arrI = arr[i];
  7103. if (arrI !== 0) {
  7104. j = result[result.length - 1];
  7105. if (arr[j] < arrI) {
  7106. p[i] = j;
  7107. result.push(i);
  7108. continue;
  7109. }
  7110. u = 0;
  7111. v = result.length - 1;
  7112. while (u < v) {
  7113. c = (u + v) >> 1;
  7114. if (arr[result[c]] < arrI) {
  7115. u = c + 1;
  7116. }
  7117. else {
  7118. v = c;
  7119. }
  7120. }
  7121. if (arrI < arr[result[u]]) {
  7122. if (u > 0) {
  7123. p[i] = result[u - 1];
  7124. }
  7125. result[u] = i;
  7126. }
  7127. }
  7128. }
  7129. u = result.length;
  7130. v = result[u - 1];
  7131. while (u-- > 0) {
  7132. result[u] = v;
  7133. v = p[v];
  7134. }
  7135. return result;
  7136. }
  7137. const isTeleport = (type) => type.__isTeleport;
  7138. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7139. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7140. const resolveTarget = (props, select) => {
  7141. const targetSelector = props && props.to;
  7142. if (isString(targetSelector)) {
  7143. if (!select) {
  7144. warn$1(`Current renderer does not support string target for Teleports. ` +
  7145. `(missing querySelector renderer option)`);
  7146. return null;
  7147. }
  7148. else {
  7149. const target = select(targetSelector);
  7150. if (!target) {
  7151. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7152. `Note the target element must exist before the component is mounted - ` +
  7153. `i.e. the target cannot be rendered by the component itself, and ` +
  7154. `ideally should be outside of the entire Vue component tree.`);
  7155. }
  7156. return target;
  7157. }
  7158. }
  7159. else {
  7160. if (!targetSelector && !isTeleportDisabled(props)) {
  7161. warn$1(`Invalid Teleport target: ${targetSelector}`);
  7162. }
  7163. return targetSelector;
  7164. }
  7165. };
  7166. const TeleportImpl = {
  7167. __isTeleport: true,
  7168. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7169. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7170. const disabled = isTeleportDisabled(n2.props);
  7171. let { shapeFlag, children, dynamicChildren } = n2;
  7172. // #3302
  7173. // HMR updated, force full diff
  7174. if (isHmrUpdating) {
  7175. optimized = false;
  7176. dynamicChildren = null;
  7177. }
  7178. if (n1 == null) {
  7179. // insert anchors in the main view
  7180. const placeholder = (n2.el = createComment('teleport start')
  7181. );
  7182. const mainAnchor = (n2.anchor = createComment('teleport end')
  7183. );
  7184. insert(placeholder, container, anchor);
  7185. insert(mainAnchor, container, anchor);
  7186. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7187. const targetAnchor = (n2.targetAnchor = createText(''));
  7188. if (target) {
  7189. insert(targetAnchor, target);
  7190. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7191. isSVG = isSVG || isTargetSVG(target);
  7192. }
  7193. else if (!disabled) {
  7194. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7195. }
  7196. const mount = (container, anchor) => {
  7197. // Teleport *always* has Array children. This is enforced in both the
  7198. // compiler and vnode children normalization.
  7199. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7200. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7201. }
  7202. };
  7203. if (disabled) {
  7204. mount(container, mainAnchor);
  7205. }
  7206. else if (target) {
  7207. mount(target, targetAnchor);
  7208. }
  7209. }
  7210. else {
  7211. // update content
  7212. n2.el = n1.el;
  7213. const mainAnchor = (n2.anchor = n1.anchor);
  7214. const target = (n2.target = n1.target);
  7215. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7216. const wasDisabled = isTeleportDisabled(n1.props);
  7217. const currentContainer = wasDisabled ? container : target;
  7218. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7219. isSVG = isSVG || isTargetSVG(target);
  7220. if (dynamicChildren) {
  7221. // fast path when the teleport happens to be a block root
  7222. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7223. // even in block tree mode we need to make sure all root-level nodes
  7224. // in the teleport inherit previous DOM references so that they can
  7225. // be moved in future patches.
  7226. traverseStaticChildren(n1, n2, true);
  7227. }
  7228. else if (!optimized) {
  7229. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7230. }
  7231. if (disabled) {
  7232. if (!wasDisabled) {
  7233. // enabled -> disabled
  7234. // move into main container
  7235. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  7236. }
  7237. }
  7238. else {
  7239. // target changed
  7240. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7241. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7242. if (nextTarget) {
  7243. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  7244. }
  7245. else {
  7246. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  7247. }
  7248. }
  7249. else if (wasDisabled) {
  7250. // disabled -> enabled
  7251. // move into teleport target
  7252. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  7253. }
  7254. }
  7255. }
  7256. },
  7257. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7258. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7259. if (target) {
  7260. hostRemove(targetAnchor);
  7261. }
  7262. // an unmounted teleport should always remove its children if not disabled
  7263. if (doRemove || !isTeleportDisabled(props)) {
  7264. hostRemove(anchor);
  7265. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7266. for (let i = 0; i < children.length; i++) {
  7267. const child = children[i];
  7268. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7269. }
  7270. }
  7271. }
  7272. },
  7273. move: moveTeleport,
  7274. hydrate: hydrateTeleport
  7275. };
  7276. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  7277. // move target anchor if this is a target change.
  7278. if (moveType === 0 /* TARGET_CHANGE */) {
  7279. insert(vnode.targetAnchor, container, parentAnchor);
  7280. }
  7281. const { el, anchor, shapeFlag, children, props } = vnode;
  7282. const isReorder = moveType === 2 /* REORDER */;
  7283. // move main view anchor if this is a re-order.
  7284. if (isReorder) {
  7285. insert(el, container, parentAnchor);
  7286. }
  7287. // if this is a re-order and teleport is enabled (content is in target)
  7288. // do not move children. So the opposite is: only move children if this
  7289. // is not a reorder, or the teleport is disabled
  7290. if (!isReorder || isTeleportDisabled(props)) {
  7291. // Teleport has either Array children or no children.
  7292. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7293. for (let i = 0; i < children.length; i++) {
  7294. move(children[i], container, parentAnchor, 2 /* REORDER */);
  7295. }
  7296. }
  7297. }
  7298. // move main view anchor if this is a re-order.
  7299. if (isReorder) {
  7300. insert(anchor, container, parentAnchor);
  7301. }
  7302. }
  7303. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7304. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7305. if (target) {
  7306. // if multiple teleports rendered to the same target element, we need to
  7307. // pick up from where the last teleport finished instead of the first node
  7308. const targetNode = target._lpa || target.firstChild;
  7309. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7310. if (isTeleportDisabled(vnode.props)) {
  7311. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7312. vnode.targetAnchor = targetNode;
  7313. }
  7314. else {
  7315. vnode.anchor = nextSibling(node);
  7316. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7317. }
  7318. target._lpa =
  7319. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7320. }
  7321. }
  7322. return vnode.anchor && nextSibling(vnode.anchor);
  7323. }
  7324. // Force-casted public typing for h and TSX props inference
  7325. const Teleport = TeleportImpl;
  7326. const COMPONENTS = 'components';
  7327. const DIRECTIVES = 'directives';
  7328. /**
  7329. * @private
  7330. */
  7331. function resolveComponent(name, maybeSelfReference) {
  7332. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  7333. }
  7334. const NULL_DYNAMIC_COMPONENT = Symbol();
  7335. /**
  7336. * @private
  7337. */
  7338. function resolveDynamicComponent(component) {
  7339. if (isString(component)) {
  7340. return resolveAsset(COMPONENTS, component, false) || component;
  7341. }
  7342. else {
  7343. // invalid types will fallthrough to createVNode and raise warning
  7344. return (component || NULL_DYNAMIC_COMPONENT);
  7345. }
  7346. }
  7347. /**
  7348. * @private
  7349. */
  7350. function resolveDirective(name) {
  7351. return resolveAsset(DIRECTIVES, name);
  7352. }
  7353. // implementation
  7354. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  7355. const instance = currentRenderingInstance || currentInstance;
  7356. if (instance) {
  7357. const Component = instance.type;
  7358. // explicit self name has highest priority
  7359. if (type === COMPONENTS) {
  7360. const selfName = getComponentName(Component);
  7361. if (selfName &&
  7362. (selfName === name ||
  7363. selfName === camelize(name) ||
  7364. selfName === capitalize(camelize(name)))) {
  7365. return Component;
  7366. }
  7367. }
  7368. const res =
  7369. // local registration
  7370. // check instance[type] first which is resolved for options API
  7371. resolve(instance[type] || Component[type], name) ||
  7372. // global registration
  7373. resolve(instance.appContext[type], name);
  7374. if (!res && maybeSelfReference) {
  7375. // fallback to implicit self-reference
  7376. return Component;
  7377. }
  7378. if (warnMissing && !res) {
  7379. const extra = type === COMPONENTS
  7380. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  7381. `component resolution via compilerOptions.isCustomElement.`
  7382. : ``;
  7383. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  7384. }
  7385. return res;
  7386. }
  7387. else {
  7388. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  7389. `can only be used in render() or setup().`);
  7390. }
  7391. }
  7392. function resolve(registry, name) {
  7393. return (registry &&
  7394. (registry[name] ||
  7395. registry[camelize(name)] ||
  7396. registry[capitalize(camelize(name))]));
  7397. }
  7398. const Fragment = Symbol('Fragment' );
  7399. const Text = Symbol('Text' );
  7400. const Comment = Symbol('Comment' );
  7401. const Static = Symbol('Static' );
  7402. // Since v-if and v-for are the two possible ways node structure can dynamically
  7403. // change, once we consider v-if branches and each v-for fragment a block, we
  7404. // can divide a template into nested blocks, and within each block the node
  7405. // structure would be stable. This allows us to skip most children diffing
  7406. // and only worry about the dynamic nodes (indicated by patch flags).
  7407. const blockStack = [];
  7408. let currentBlock = null;
  7409. /**
  7410. * Open a block.
  7411. * This must be called before `createBlock`. It cannot be part of `createBlock`
  7412. * because the children of the block are evaluated before `createBlock` itself
  7413. * is called. The generated code typically looks like this:
  7414. *
  7415. * ```js
  7416. * function render() {
  7417. * return (openBlock(),createBlock('div', null, [...]))
  7418. * }
  7419. * ```
  7420. * disableTracking is true when creating a v-for fragment block, since a v-for
  7421. * fragment always diffs its children.
  7422. *
  7423. * @private
  7424. */
  7425. function openBlock(disableTracking = false) {
  7426. blockStack.push((currentBlock = disableTracking ? null : []));
  7427. }
  7428. function closeBlock() {
  7429. blockStack.pop();
  7430. currentBlock = blockStack[blockStack.length - 1] || null;
  7431. }
  7432. // Whether we should be tracking dynamic child nodes inside a block.
  7433. // Only tracks when this value is > 0
  7434. // We are not using a simple boolean because this value may need to be
  7435. // incremented/decremented by nested usage of v-once (see below)
  7436. let isBlockTreeEnabled = 1;
  7437. /**
  7438. * Block tracking sometimes needs to be disabled, for example during the
  7439. * creation of a tree that needs to be cached by v-once. The compiler generates
  7440. * code like this:
  7441. *
  7442. * ``` js
  7443. * _cache[1] || (
  7444. * setBlockTracking(-1),
  7445. * _cache[1] = createVNode(...),
  7446. * setBlockTracking(1),
  7447. * _cache[1]
  7448. * )
  7449. * ```
  7450. *
  7451. * @private
  7452. */
  7453. function setBlockTracking(value) {
  7454. isBlockTreeEnabled += value;
  7455. }
  7456. function setupBlock(vnode) {
  7457. // save current block children on the block vnode
  7458. vnode.dynamicChildren =
  7459. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  7460. // close block
  7461. closeBlock();
  7462. // a block is always going to be patched, so track it as a child of its
  7463. // parent block
  7464. if (isBlockTreeEnabled > 0 && currentBlock) {
  7465. currentBlock.push(vnode);
  7466. }
  7467. return vnode;
  7468. }
  7469. /**
  7470. * @private
  7471. */
  7472. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  7473. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  7474. }
  7475. /**
  7476. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  7477. * A block root keeps track of dynamic nodes within the block in the
  7478. * `dynamicChildren` array.
  7479. *
  7480. * @private
  7481. */
  7482. function createBlock(type, props, children, patchFlag, dynamicProps) {
  7483. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  7484. }
  7485. function isVNode(value) {
  7486. return value ? value.__v_isVNode === true : false;
  7487. }
  7488. function isSameVNodeType(n1, n2) {
  7489. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  7490. hmrDirtyComponents.has(n2.type)) {
  7491. // HMR only: if the component has been hot-updated, force a reload.
  7492. return false;
  7493. }
  7494. return n1.type === n2.type && n1.key === n2.key;
  7495. }
  7496. let vnodeArgsTransformer;
  7497. /**
  7498. * Internal API for registering an arguments transform for createVNode
  7499. * used for creating stubs in the test-utils
  7500. * It is *internal* but needs to be exposed for test-utils to pick up proper
  7501. * typings
  7502. */
  7503. function transformVNodeArgs(transformer) {
  7504. vnodeArgsTransformer = transformer;
  7505. }
  7506. const createVNodeWithArgsTransform = (...args) => {
  7507. return _createVNode(...(vnodeArgsTransformer
  7508. ? vnodeArgsTransformer(args, currentRenderingInstance)
  7509. : args));
  7510. };
  7511. const InternalObjectKey = `__vInternal`;
  7512. const normalizeKey = ({ key }) => key != null ? key : null;
  7513. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  7514. return (ref != null
  7515. ? isString(ref) || isRef(ref) || isFunction(ref)
  7516. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  7517. : ref
  7518. : null);
  7519. };
  7520. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  7521. const vnode = {
  7522. __v_isVNode: true,
  7523. __v_skip: true,
  7524. type,
  7525. props,
  7526. key: props && normalizeKey(props),
  7527. ref: props && normalizeRef(props),
  7528. scopeId: currentScopeId,
  7529. slotScopeIds: null,
  7530. children,
  7531. component: null,
  7532. suspense: null,
  7533. ssContent: null,
  7534. ssFallback: null,
  7535. dirs: null,
  7536. transition: null,
  7537. el: null,
  7538. anchor: null,
  7539. target: null,
  7540. targetAnchor: null,
  7541. staticCount: 0,
  7542. shapeFlag,
  7543. patchFlag,
  7544. dynamicProps,
  7545. dynamicChildren: null,
  7546. appContext: null
  7547. };
  7548. if (needFullChildrenNormalization) {
  7549. normalizeChildren(vnode, children);
  7550. // normalize suspense children
  7551. if (shapeFlag & 128 /* SUSPENSE */) {
  7552. type.normalize(vnode);
  7553. }
  7554. }
  7555. else if (children) {
  7556. // compiled element vnode - if children is passed, only possible types are
  7557. // string or Array.
  7558. vnode.shapeFlag |= isString(children)
  7559. ? 8 /* TEXT_CHILDREN */
  7560. : 16 /* ARRAY_CHILDREN */;
  7561. }
  7562. // validate key
  7563. if (vnode.key !== vnode.key) {
  7564. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  7565. }
  7566. // track vnode for block tree
  7567. if (isBlockTreeEnabled > 0 &&
  7568. // avoid a block node from tracking itself
  7569. !isBlockNode &&
  7570. // has current parent block
  7571. currentBlock &&
  7572. // presence of a patch flag indicates this node needs patching on updates.
  7573. // component nodes also should always be patched, because even if the
  7574. // component doesn't need to update, it needs to persist the instance on to
  7575. // the next vnode so that it can be properly unmounted later.
  7576. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  7577. // the EVENTS flag is only for hydration and if it is the only flag, the
  7578. // vnode should not be considered dynamic due to handler caching.
  7579. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  7580. currentBlock.push(vnode);
  7581. }
  7582. return vnode;
  7583. }
  7584. const createVNode = (createVNodeWithArgsTransform );
  7585. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  7586. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  7587. if (!type) {
  7588. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  7589. }
  7590. type = Comment;
  7591. }
  7592. if (isVNode(type)) {
  7593. // createVNode receiving an existing vnode. This happens in cases like
  7594. // <component :is="vnode"/>
  7595. // #2078 make sure to merge refs during the clone instead of overwriting it
  7596. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  7597. if (children) {
  7598. normalizeChildren(cloned, children);
  7599. }
  7600. return cloned;
  7601. }
  7602. // class component normalization.
  7603. if (isClassComponent(type)) {
  7604. type = type.__vccOpts;
  7605. }
  7606. // class & style normalization.
  7607. if (props) {
  7608. // for reactive or proxy objects, we need to clone it to enable mutation.
  7609. props = guardReactiveProps(props);
  7610. let { class: klass, style } = props;
  7611. if (klass && !isString(klass)) {
  7612. props.class = normalizeClass(klass);
  7613. }
  7614. if (isObject(style)) {
  7615. // reactive state objects need to be cloned since they are likely to be
  7616. // mutated
  7617. if (isProxy(style) && !isArray(style)) {
  7618. style = extend({}, style);
  7619. }
  7620. props.style = normalizeStyle(style);
  7621. }
  7622. }
  7623. // encode the vnode type information into a bitmap
  7624. const shapeFlag = isString(type)
  7625. ? 1 /* ELEMENT */
  7626. : isSuspense(type)
  7627. ? 128 /* SUSPENSE */
  7628. : isTeleport(type)
  7629. ? 64 /* TELEPORT */
  7630. : isObject(type)
  7631. ? 4 /* STATEFUL_COMPONENT */
  7632. : isFunction(type)
  7633. ? 2 /* FUNCTIONAL_COMPONENT */
  7634. : 0;
  7635. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  7636. type = toRaw(type);
  7637. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  7638. `lead to unnecessary performance overhead, and should be avoided by ` +
  7639. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  7640. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  7641. }
  7642. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  7643. }
  7644. function guardReactiveProps(props) {
  7645. if (!props)
  7646. return null;
  7647. return isProxy(props) || InternalObjectKey in props
  7648. ? extend({}, props)
  7649. : props;
  7650. }
  7651. function cloneVNode(vnode, extraProps, mergeRef = false) {
  7652. // This is intentionally NOT using spread or extend to avoid the runtime
  7653. // key enumeration cost.
  7654. const { props, ref, patchFlag, children } = vnode;
  7655. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  7656. const cloned = {
  7657. __v_isVNode: true,
  7658. __v_skip: true,
  7659. type: vnode.type,
  7660. props: mergedProps,
  7661. key: mergedProps && normalizeKey(mergedProps),
  7662. ref: extraProps && extraProps.ref
  7663. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  7664. // if the vnode itself already has a ref, cloneVNode will need to merge
  7665. // the refs so the single vnode can be set on multiple refs
  7666. mergeRef && ref
  7667. ? isArray(ref)
  7668. ? ref.concat(normalizeRef(extraProps))
  7669. : [ref, normalizeRef(extraProps)]
  7670. : normalizeRef(extraProps)
  7671. : ref,
  7672. scopeId: vnode.scopeId,
  7673. slotScopeIds: vnode.slotScopeIds,
  7674. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  7675. ? children.map(deepCloneVNode)
  7676. : children,
  7677. target: vnode.target,
  7678. targetAnchor: vnode.targetAnchor,
  7679. staticCount: vnode.staticCount,
  7680. shapeFlag: vnode.shapeFlag,
  7681. // if the vnode is cloned with extra props, we can no longer assume its
  7682. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  7683. // note: preserve flag for fragments since they use the flag for children
  7684. // fast paths only.
  7685. patchFlag: extraProps && vnode.type !== Fragment
  7686. ? patchFlag === -1 // hoisted node
  7687. ? 16 /* FULL_PROPS */
  7688. : patchFlag | 16 /* FULL_PROPS */
  7689. : patchFlag,
  7690. dynamicProps: vnode.dynamicProps,
  7691. dynamicChildren: vnode.dynamicChildren,
  7692. appContext: vnode.appContext,
  7693. dirs: vnode.dirs,
  7694. transition: vnode.transition,
  7695. // These should technically only be non-null on mounted VNodes. However,
  7696. // they *should* be copied for kept-alive vnodes. So we just always copy
  7697. // them since them being non-null during a mount doesn't affect the logic as
  7698. // they will simply be overwritten.
  7699. component: vnode.component,
  7700. suspense: vnode.suspense,
  7701. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  7702. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  7703. el: vnode.el,
  7704. anchor: vnode.anchor
  7705. };
  7706. return cloned;
  7707. }
  7708. /**
  7709. * Dev only, for HMR of hoisted vnodes reused in v-for
  7710. * https://github.com/vitejs/vite/issues/2022
  7711. */
  7712. function deepCloneVNode(vnode) {
  7713. const cloned = cloneVNode(vnode);
  7714. if (isArray(vnode.children)) {
  7715. cloned.children = vnode.children.map(deepCloneVNode);
  7716. }
  7717. return cloned;
  7718. }
  7719. /**
  7720. * @private
  7721. */
  7722. function createTextVNode(text = ' ', flag = 0) {
  7723. return createVNode(Text, null, text, flag);
  7724. }
  7725. /**
  7726. * @private
  7727. */
  7728. function createStaticVNode(content, numberOfNodes) {
  7729. // A static vnode can contain multiple stringified elements, and the number
  7730. // of elements is necessary for hydration.
  7731. const vnode = createVNode(Static, null, content);
  7732. vnode.staticCount = numberOfNodes;
  7733. return vnode;
  7734. }
  7735. /**
  7736. * @private
  7737. */
  7738. function createCommentVNode(text = '',
  7739. // when used as the v-else branch, the comment node must be created as a
  7740. // block to ensure correct updates.
  7741. asBlock = false) {
  7742. return asBlock
  7743. ? (openBlock(), createBlock(Comment, null, text))
  7744. : createVNode(Comment, null, text);
  7745. }
  7746. function normalizeVNode(child) {
  7747. if (child == null || typeof child === 'boolean') {
  7748. // empty placeholder
  7749. return createVNode(Comment);
  7750. }
  7751. else if (isArray(child)) {
  7752. // fragment
  7753. return createVNode(Fragment, null,
  7754. // #3666, avoid reference pollution when reusing vnode
  7755. child.slice());
  7756. }
  7757. else if (typeof child === 'object') {
  7758. // already vnode, this should be the most common since compiled templates
  7759. // always produce all-vnode children arrays
  7760. return cloneIfMounted(child);
  7761. }
  7762. else {
  7763. // strings and numbers
  7764. return createVNode(Text, null, String(child));
  7765. }
  7766. }
  7767. // optimized normalization for template-compiled render fns
  7768. function cloneIfMounted(child) {
  7769. return child.el === null || child.memo ? child : cloneVNode(child);
  7770. }
  7771. function normalizeChildren(vnode, children) {
  7772. let type = 0;
  7773. const { shapeFlag } = vnode;
  7774. if (children == null) {
  7775. children = null;
  7776. }
  7777. else if (isArray(children)) {
  7778. type = 16 /* ARRAY_CHILDREN */;
  7779. }
  7780. else if (typeof children === 'object') {
  7781. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  7782. // Normalize slot to plain children for plain element and Teleport
  7783. const slot = children.default;
  7784. if (slot) {
  7785. // _c marker is added by withCtx() indicating this is a compiled slot
  7786. slot._c && (slot._d = false);
  7787. normalizeChildren(vnode, slot());
  7788. slot._c && (slot._d = true);
  7789. }
  7790. return;
  7791. }
  7792. else {
  7793. type = 32 /* SLOTS_CHILDREN */;
  7794. const slotFlag = children._;
  7795. if (!slotFlag && !(InternalObjectKey in children)) {
  7796. children._ctx = currentRenderingInstance;
  7797. }
  7798. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  7799. // a child component receives forwarded slots from the parent.
  7800. // its slot type is determined by its parent's slot type.
  7801. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  7802. children._ = 1 /* STABLE */;
  7803. }
  7804. else {
  7805. children._ = 2 /* DYNAMIC */;
  7806. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  7807. }
  7808. }
  7809. }
  7810. }
  7811. else if (isFunction(children)) {
  7812. children = { default: children, _ctx: currentRenderingInstance };
  7813. type = 32 /* SLOTS_CHILDREN */;
  7814. }
  7815. else {
  7816. children = String(children);
  7817. // force teleport children to array so it can be moved around
  7818. if (shapeFlag & 64 /* TELEPORT */) {
  7819. type = 16 /* ARRAY_CHILDREN */;
  7820. children = [createTextVNode(children)];
  7821. }
  7822. else {
  7823. type = 8 /* TEXT_CHILDREN */;
  7824. }
  7825. }
  7826. vnode.children = children;
  7827. vnode.shapeFlag |= type;
  7828. }
  7829. function mergeProps(...args) {
  7830. const ret = {};
  7831. for (let i = 0; i < args.length; i++) {
  7832. const toMerge = args[i];
  7833. for (const key in toMerge) {
  7834. if (key === 'class') {
  7835. if (ret.class !== toMerge.class) {
  7836. ret.class = normalizeClass([ret.class, toMerge.class]);
  7837. }
  7838. }
  7839. else if (key === 'style') {
  7840. ret.style = normalizeStyle([ret.style, toMerge.style]);
  7841. }
  7842. else if (isOn(key)) {
  7843. const existing = ret[key];
  7844. const incoming = toMerge[key];
  7845. if (incoming &&
  7846. existing !== incoming &&
  7847. !(isArray(existing) && existing.includes(incoming))) {
  7848. ret[key] = existing
  7849. ? [].concat(existing, incoming)
  7850. : incoming;
  7851. }
  7852. }
  7853. else if (key !== '') {
  7854. ret[key] = toMerge[key];
  7855. }
  7856. }
  7857. }
  7858. return ret;
  7859. }
  7860. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  7861. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  7862. vnode,
  7863. prevVNode
  7864. ]);
  7865. }
  7866. /**
  7867. * Actual implementation
  7868. */
  7869. function renderList(source, renderItem, cache, index) {
  7870. let ret;
  7871. const cached = (cache && cache[index]);
  7872. if (isArray(source) || isString(source)) {
  7873. ret = new Array(source.length);
  7874. for (let i = 0, l = source.length; i < l; i++) {
  7875. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  7876. }
  7877. }
  7878. else if (typeof source === 'number') {
  7879. if (!Number.isInteger(source)) {
  7880. warn$1(`The v-for range expect an integer value but got ${source}.`);
  7881. return [];
  7882. }
  7883. ret = new Array(source);
  7884. for (let i = 0; i < source; i++) {
  7885. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  7886. }
  7887. }
  7888. else if (isObject(source)) {
  7889. if (source[Symbol.iterator]) {
  7890. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  7891. }
  7892. else {
  7893. const keys = Object.keys(source);
  7894. ret = new Array(keys.length);
  7895. for (let i = 0, l = keys.length; i < l; i++) {
  7896. const key = keys[i];
  7897. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  7898. }
  7899. }
  7900. }
  7901. else {
  7902. ret = [];
  7903. }
  7904. if (cache) {
  7905. cache[index] = ret;
  7906. }
  7907. return ret;
  7908. }
  7909. /**
  7910. * Compiler runtime helper for creating dynamic slots object
  7911. * @private
  7912. */
  7913. function createSlots(slots, dynamicSlots) {
  7914. for (let i = 0; i < dynamicSlots.length; i++) {
  7915. const slot = dynamicSlots[i];
  7916. // array of dynamic slot generated by <template v-for="..." #[...]>
  7917. if (isArray(slot)) {
  7918. for (let j = 0; j < slot.length; j++) {
  7919. slots[slot[j].name] = slot[j].fn;
  7920. }
  7921. }
  7922. else if (slot) {
  7923. // conditional single slot generated by <template v-if="..." #foo>
  7924. slots[slot.name] = slot.fn;
  7925. }
  7926. }
  7927. return slots;
  7928. }
  7929. /**
  7930. * Compiler runtime helper for rendering `<slot/>`
  7931. * @private
  7932. */
  7933. function renderSlot(slots, name, props = {},
  7934. // this is not a user-facing function, so the fallback is always generated by
  7935. // the compiler and guaranteed to be a function returning an array
  7936. fallback, noSlotted) {
  7937. if (currentRenderingInstance.isCE ||
  7938. (currentRenderingInstance.parent &&
  7939. isAsyncWrapper(currentRenderingInstance.parent) &&
  7940. currentRenderingInstance.parent.isCE)) {
  7941. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  7942. }
  7943. let slot = slots[name];
  7944. if (slot && slot.length > 1) {
  7945. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  7946. `function. You need to mark this component with $dynamic-slots in the ` +
  7947. `parent template.`);
  7948. slot = () => [];
  7949. }
  7950. // a compiled slot disables block tracking by default to avoid manual
  7951. // invocation interfering with template-based block tracking, but in
  7952. // `renderSlot` we can be sure that it's template-based so we can force
  7953. // enable it.
  7954. if (slot && slot._c) {
  7955. slot._d = false;
  7956. }
  7957. openBlock();
  7958. const validSlotContent = slot && ensureValidVNode(slot(props));
  7959. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  7960. ? 64 /* STABLE_FRAGMENT */
  7961. : -2 /* BAIL */);
  7962. if (!noSlotted && rendered.scopeId) {
  7963. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  7964. }
  7965. if (slot && slot._c) {
  7966. slot._d = true;
  7967. }
  7968. return rendered;
  7969. }
  7970. function ensureValidVNode(vnodes) {
  7971. return vnodes.some(child => {
  7972. if (!isVNode(child))
  7973. return true;
  7974. if (child.type === Comment)
  7975. return false;
  7976. if (child.type === Fragment &&
  7977. !ensureValidVNode(child.children))
  7978. return false;
  7979. return true;
  7980. })
  7981. ? vnodes
  7982. : null;
  7983. }
  7984. /**
  7985. * For prefixing keys in v-on="obj" with "on"
  7986. * @private
  7987. */
  7988. function toHandlers(obj) {
  7989. const ret = {};
  7990. if (!isObject(obj)) {
  7991. warn$1(`v-on with no argument expects an object value.`);
  7992. return ret;
  7993. }
  7994. for (const key in obj) {
  7995. ret[toHandlerKey(key)] = obj[key];
  7996. }
  7997. return ret;
  7998. }
  7999. /**
  8000. * #2437 In Vue 3, functional components do not have a public instance proxy but
  8001. * they exist in the internal parent chain. For code that relies on traversing
  8002. * public $parent chains, skip functional ones and go to the parent instead.
  8003. */
  8004. const getPublicInstance = (i) => {
  8005. if (!i)
  8006. return null;
  8007. if (isStatefulComponent(i))
  8008. return getExposeProxy(i) || i.proxy;
  8009. return getPublicInstance(i.parent);
  8010. };
  8011. const publicPropertiesMap =
  8012. // Move PURE marker to new line to workaround compiler discarding it
  8013. // due to type annotation
  8014. /*#__PURE__*/ extend(Object.create(null), {
  8015. $: i => i,
  8016. $el: i => i.vnode.el,
  8017. $data: i => i.data,
  8018. $props: i => (shallowReadonly(i.props) ),
  8019. $attrs: i => (shallowReadonly(i.attrs) ),
  8020. $slots: i => (shallowReadonly(i.slots) ),
  8021. $refs: i => (shallowReadonly(i.refs) ),
  8022. $parent: i => getPublicInstance(i.parent),
  8023. $root: i => getPublicInstance(i.root),
  8024. $emit: i => i.emit,
  8025. $options: i => (resolveMergedOptions(i) ),
  8026. $forceUpdate: i => () => queueJob(i.update),
  8027. $nextTick: i => nextTick.bind(i.proxy),
  8028. $watch: i => (instanceWatch.bind(i) )
  8029. });
  8030. const PublicInstanceProxyHandlers = {
  8031. get({ _: instance }, key) {
  8032. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  8033. // for internal formatters to know that this is a Vue instance
  8034. if (key === '__isVue') {
  8035. return true;
  8036. }
  8037. // prioritize <script setup> bindings during dev.
  8038. // this allows even properties that start with _ or $ to be used - so that
  8039. // it aligns with the production behavior where the render fn is inlined and
  8040. // indeed has access to all declared variables.
  8041. if (setupState !== EMPTY_OBJ &&
  8042. setupState.__isScriptSetup &&
  8043. hasOwn(setupState, key)) {
  8044. return setupState[key];
  8045. }
  8046. // data / props / ctx
  8047. // This getter gets called for every property access on the render context
  8048. // during render and is a major hotspot. The most expensive part of this
  8049. // is the multiple hasOwn() calls. It's much faster to do a simple property
  8050. // access on a plain object, so we use an accessCache object (with null
  8051. // prototype) to memoize what access type a key corresponds to.
  8052. let normalizedProps;
  8053. if (key[0] !== '$') {
  8054. const n = accessCache[key];
  8055. if (n !== undefined) {
  8056. switch (n) {
  8057. case 1 /* SETUP */:
  8058. return setupState[key];
  8059. case 2 /* DATA */:
  8060. return data[key];
  8061. case 4 /* CONTEXT */:
  8062. return ctx[key];
  8063. case 3 /* PROPS */:
  8064. return props[key];
  8065. // default: just fallthrough
  8066. }
  8067. }
  8068. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  8069. accessCache[key] = 1 /* SETUP */;
  8070. return setupState[key];
  8071. }
  8072. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  8073. accessCache[key] = 2 /* DATA */;
  8074. return data[key];
  8075. }
  8076. else if (
  8077. // only cache other properties when instance has declared (thus stable)
  8078. // props
  8079. (normalizedProps = instance.propsOptions[0]) &&
  8080. hasOwn(normalizedProps, key)) {
  8081. accessCache[key] = 3 /* PROPS */;
  8082. return props[key];
  8083. }
  8084. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  8085. accessCache[key] = 4 /* CONTEXT */;
  8086. return ctx[key];
  8087. }
  8088. else if (shouldCacheAccess) {
  8089. accessCache[key] = 0 /* OTHER */;
  8090. }
  8091. }
  8092. const publicGetter = publicPropertiesMap[key];
  8093. let cssModule, globalProperties;
  8094. // public $xxx properties
  8095. if (publicGetter) {
  8096. if (key === '$attrs') {
  8097. track(instance, "get" /* GET */, key);
  8098. markAttrsAccessed();
  8099. }
  8100. return publicGetter(instance);
  8101. }
  8102. else if (
  8103. // css module (injected by vue-loader)
  8104. (cssModule = type.__cssModules) &&
  8105. (cssModule = cssModule[key])) {
  8106. return cssModule;
  8107. }
  8108. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  8109. // user may set custom properties to `this` that start with `$`
  8110. accessCache[key] = 4 /* CONTEXT */;
  8111. return ctx[key];
  8112. }
  8113. else if (
  8114. // global properties
  8115. ((globalProperties = appContext.config.globalProperties),
  8116. hasOwn(globalProperties, key))) {
  8117. {
  8118. return globalProperties[key];
  8119. }
  8120. }
  8121. else if (currentRenderingInstance &&
  8122. (!isString(key) ||
  8123. // #1091 avoid internal isRef/isVNode checks on component instance leading
  8124. // to infinite warning loop
  8125. key.indexOf('__v') !== 0)) {
  8126. if (data !== EMPTY_OBJ &&
  8127. (key[0] === '$' || key[0] === '_') &&
  8128. hasOwn(data, key)) {
  8129. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  8130. `character ("$" or "_") and is not proxied on the render context.`);
  8131. }
  8132. else if (instance === currentRenderingInstance) {
  8133. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  8134. `but is not defined on instance.`);
  8135. }
  8136. }
  8137. },
  8138. set({ _: instance }, key, value) {
  8139. const { data, setupState, ctx } = instance;
  8140. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  8141. setupState[key] = value;
  8142. return true;
  8143. }
  8144. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  8145. data[key] = value;
  8146. return true;
  8147. }
  8148. else if (hasOwn(instance.props, key)) {
  8149. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  8150. return false;
  8151. }
  8152. if (key[0] === '$' && key.slice(1) in instance) {
  8153. warn$1(`Attempting to mutate public property "${key}". ` +
  8154. `Properties starting with $ are reserved and readonly.`, instance);
  8155. return false;
  8156. }
  8157. else {
  8158. if (key in instance.appContext.config.globalProperties) {
  8159. Object.defineProperty(ctx, key, {
  8160. enumerable: true,
  8161. configurable: true,
  8162. value
  8163. });
  8164. }
  8165. else {
  8166. ctx[key] = value;
  8167. }
  8168. }
  8169. return true;
  8170. },
  8171. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  8172. let normalizedProps;
  8173. return (!!accessCache[key] ||
  8174. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  8175. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  8176. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  8177. hasOwn(ctx, key) ||
  8178. hasOwn(publicPropertiesMap, key) ||
  8179. hasOwn(appContext.config.globalProperties, key));
  8180. },
  8181. defineProperty(target, key, descriptor) {
  8182. if (descriptor.get != null) {
  8183. // invalidate key cache of a getter based property #5417
  8184. target._.accessCache[key] = 0;
  8185. }
  8186. else if (hasOwn(descriptor, 'value')) {
  8187. this.set(target, key, descriptor.value, null);
  8188. }
  8189. return Reflect.defineProperty(target, key, descriptor);
  8190. }
  8191. };
  8192. {
  8193. PublicInstanceProxyHandlers.ownKeys = (target) => {
  8194. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  8195. `The keys will be empty in production mode to avoid performance overhead.`);
  8196. return Reflect.ownKeys(target);
  8197. };
  8198. }
  8199. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  8200. get(target, key) {
  8201. // fast path for unscopables when using `with` block
  8202. if (key === Symbol.unscopables) {
  8203. return;
  8204. }
  8205. return PublicInstanceProxyHandlers.get(target, key, target);
  8206. },
  8207. has(_, key) {
  8208. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  8209. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  8210. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  8211. }
  8212. return has;
  8213. }
  8214. });
  8215. // dev only
  8216. // In dev mode, the proxy target exposes the same properties as seen on `this`
  8217. // for easier console inspection. In prod mode it will be an empty object so
  8218. // these properties definitions can be skipped.
  8219. function createDevRenderContext(instance) {
  8220. const target = {};
  8221. // expose internal instance for proxy handlers
  8222. Object.defineProperty(target, `_`, {
  8223. configurable: true,
  8224. enumerable: false,
  8225. get: () => instance
  8226. });
  8227. // expose public properties
  8228. Object.keys(publicPropertiesMap).forEach(key => {
  8229. Object.defineProperty(target, key, {
  8230. configurable: true,
  8231. enumerable: false,
  8232. get: () => publicPropertiesMap[key](instance),
  8233. // intercepted by the proxy so no need for implementation,
  8234. // but needed to prevent set errors
  8235. set: NOOP
  8236. });
  8237. });
  8238. return target;
  8239. }
  8240. // dev only
  8241. function exposePropsOnRenderContext(instance) {
  8242. const { ctx, propsOptions: [propsOptions] } = instance;
  8243. if (propsOptions) {
  8244. Object.keys(propsOptions).forEach(key => {
  8245. Object.defineProperty(ctx, key, {
  8246. enumerable: true,
  8247. configurable: true,
  8248. get: () => instance.props[key],
  8249. set: NOOP
  8250. });
  8251. });
  8252. }
  8253. }
  8254. // dev only
  8255. function exposeSetupStateOnRenderContext(instance) {
  8256. const { ctx, setupState } = instance;
  8257. Object.keys(toRaw(setupState)).forEach(key => {
  8258. if (!setupState.__isScriptSetup) {
  8259. if (key[0] === '$' || key[0] === '_') {
  8260. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  8261. `which are reserved prefixes for Vue internals.`);
  8262. return;
  8263. }
  8264. Object.defineProperty(ctx, key, {
  8265. enumerable: true,
  8266. configurable: true,
  8267. get: () => setupState[key],
  8268. set: NOOP
  8269. });
  8270. }
  8271. });
  8272. }
  8273. const emptyAppContext = createAppContext();
  8274. let uid$1 = 0;
  8275. function createComponentInstance(vnode, parent, suspense) {
  8276. const type = vnode.type;
  8277. // inherit parent app context - or - if root, adopt from root vnode
  8278. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8279. const instance = {
  8280. uid: uid$1++,
  8281. vnode,
  8282. type,
  8283. parent,
  8284. appContext,
  8285. root: null,
  8286. next: null,
  8287. subTree: null,
  8288. effect: null,
  8289. update: null,
  8290. scope: new EffectScope(true /* detached */),
  8291. render: null,
  8292. proxy: null,
  8293. exposed: null,
  8294. exposeProxy: null,
  8295. withProxy: null,
  8296. provides: parent ? parent.provides : Object.create(appContext.provides),
  8297. accessCache: null,
  8298. renderCache: [],
  8299. // local resovled assets
  8300. components: null,
  8301. directives: null,
  8302. // resolved props and emits options
  8303. propsOptions: normalizePropsOptions(type, appContext),
  8304. emitsOptions: normalizeEmitsOptions(type, appContext),
  8305. // emit
  8306. emit: null,
  8307. emitted: null,
  8308. // props default value
  8309. propsDefaults: EMPTY_OBJ,
  8310. // inheritAttrs
  8311. inheritAttrs: type.inheritAttrs,
  8312. // state
  8313. ctx: EMPTY_OBJ,
  8314. data: EMPTY_OBJ,
  8315. props: EMPTY_OBJ,
  8316. attrs: EMPTY_OBJ,
  8317. slots: EMPTY_OBJ,
  8318. refs: EMPTY_OBJ,
  8319. setupState: EMPTY_OBJ,
  8320. setupContext: null,
  8321. // suspense related
  8322. suspense,
  8323. suspenseId: suspense ? suspense.pendingId : 0,
  8324. asyncDep: null,
  8325. asyncResolved: false,
  8326. // lifecycle hooks
  8327. // not using enums here because it results in computed properties
  8328. isMounted: false,
  8329. isUnmounted: false,
  8330. isDeactivated: false,
  8331. bc: null,
  8332. c: null,
  8333. bm: null,
  8334. m: null,
  8335. bu: null,
  8336. u: null,
  8337. um: null,
  8338. bum: null,
  8339. da: null,
  8340. a: null,
  8341. rtg: null,
  8342. rtc: null,
  8343. ec: null,
  8344. sp: null
  8345. };
  8346. {
  8347. instance.ctx = createDevRenderContext(instance);
  8348. }
  8349. instance.root = parent ? parent.root : instance;
  8350. instance.emit = emit$1.bind(null, instance);
  8351. // apply custom element special handling
  8352. if (vnode.ce) {
  8353. vnode.ce(instance);
  8354. }
  8355. return instance;
  8356. }
  8357. let currentInstance = null;
  8358. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8359. const setCurrentInstance = (instance) => {
  8360. currentInstance = instance;
  8361. instance.scope.on();
  8362. };
  8363. const unsetCurrentInstance = () => {
  8364. currentInstance && currentInstance.scope.off();
  8365. currentInstance = null;
  8366. };
  8367. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8368. function validateComponentName(name, config) {
  8369. const appIsNativeTag = config.isNativeTag || NO;
  8370. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8371. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  8372. }
  8373. }
  8374. function isStatefulComponent(instance) {
  8375. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  8376. }
  8377. let isInSSRComponentSetup = false;
  8378. function setupComponent(instance, isSSR = false) {
  8379. isInSSRComponentSetup = isSSR;
  8380. const { props, children } = instance.vnode;
  8381. const isStateful = isStatefulComponent(instance);
  8382. initProps(instance, props, isStateful, isSSR);
  8383. initSlots(instance, children);
  8384. const setupResult = isStateful
  8385. ? setupStatefulComponent(instance, isSSR)
  8386. : undefined;
  8387. isInSSRComponentSetup = false;
  8388. return setupResult;
  8389. }
  8390. function setupStatefulComponent(instance, isSSR) {
  8391. var _a;
  8392. const Component = instance.type;
  8393. {
  8394. if (Component.name) {
  8395. validateComponentName(Component.name, instance.appContext.config);
  8396. }
  8397. if (Component.components) {
  8398. const names = Object.keys(Component.components);
  8399. for (let i = 0; i < names.length; i++) {
  8400. validateComponentName(names[i], instance.appContext.config);
  8401. }
  8402. }
  8403. if (Component.directives) {
  8404. const names = Object.keys(Component.directives);
  8405. for (let i = 0; i < names.length; i++) {
  8406. validateDirectiveName(names[i]);
  8407. }
  8408. }
  8409. if (Component.compilerOptions && isRuntimeOnly()) {
  8410. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  8411. `includes the runtime compiler. Since you are using a runtime-only ` +
  8412. `build, the options should be passed via your build tool config instead.`);
  8413. }
  8414. }
  8415. // 0. create render proxy property access cache
  8416. instance.accessCache = Object.create(null);
  8417. // 1. create public instance / render proxy
  8418. // also mark it raw so it's never observed
  8419. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8420. {
  8421. exposePropsOnRenderContext(instance);
  8422. }
  8423. // 2. call setup()
  8424. const { setup } = Component;
  8425. if (setup) {
  8426. const setupContext = (instance.setupContext =
  8427. setup.length > 1 ? createSetupContext(instance) : null);
  8428. setCurrentInstance(instance);
  8429. pauseTracking();
  8430. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8431. resetTracking();
  8432. unsetCurrentInstance();
  8433. if (isPromise(setupResult)) {
  8434. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8435. if (isSSR) {
  8436. // return the promise so server-renderer can wait on it
  8437. return setupResult
  8438. .then((resolvedResult) => {
  8439. handleSetupResult(instance, resolvedResult, isSSR);
  8440. })
  8441. .catch(e => {
  8442. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  8443. });
  8444. }
  8445. else {
  8446. // async setup returned Promise.
  8447. // bail here and wait for re-entry.
  8448. instance.asyncDep = setupResult;
  8449. if (!instance.suspense) {
  8450. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8451. warn$1(`Component <${name}>: setup function returned a promise, but no ` +
  8452. `<Suspense> boundary was found in the parent component tree. ` +
  8453. `A component with async setup() must be nested in a <Suspense> ` +
  8454. `in order to be rendered.`);
  8455. }
  8456. }
  8457. }
  8458. else {
  8459. handleSetupResult(instance, setupResult, isSSR);
  8460. }
  8461. }
  8462. else {
  8463. finishComponentSetup(instance, isSSR);
  8464. }
  8465. }
  8466. function handleSetupResult(instance, setupResult, isSSR) {
  8467. if (isFunction(setupResult)) {
  8468. // setup returned an inline render function
  8469. {
  8470. instance.render = setupResult;
  8471. }
  8472. }
  8473. else if (isObject(setupResult)) {
  8474. if (isVNode(setupResult)) {
  8475. warn$1(`setup() should not return VNodes directly - ` +
  8476. `return a render function instead.`);
  8477. }
  8478. // setup returned bindings.
  8479. // assuming a render function compiled from template is present.
  8480. {
  8481. instance.devtoolsRawSetupState = setupResult;
  8482. }
  8483. instance.setupState = proxyRefs(setupResult);
  8484. {
  8485. exposeSetupStateOnRenderContext(instance);
  8486. }
  8487. }
  8488. else if (setupResult !== undefined) {
  8489. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8490. }
  8491. finishComponentSetup(instance, isSSR);
  8492. }
  8493. let compile;
  8494. let installWithProxy;
  8495. /**
  8496. * For runtime-dom to register the compiler.
  8497. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8498. */
  8499. function registerRuntimeCompiler(_compile) {
  8500. compile = _compile;
  8501. installWithProxy = i => {
  8502. if (i.render._rc) {
  8503. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8504. }
  8505. };
  8506. }
  8507. // dev only
  8508. const isRuntimeOnly = () => !compile;
  8509. function finishComponentSetup(instance, isSSR, skipOptions) {
  8510. const Component = instance.type;
  8511. // template / render function normalization
  8512. // could be already set when returned from setup()
  8513. if (!instance.render) {
  8514. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8515. // is done by server-renderer
  8516. if (!isSSR && compile && !Component.render) {
  8517. const template = Component.template;
  8518. if (template) {
  8519. {
  8520. startMeasure(instance, `compile`);
  8521. }
  8522. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8523. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8524. const finalCompilerOptions = extend(extend({
  8525. isCustomElement,
  8526. delimiters
  8527. }, compilerOptions), componentCompilerOptions);
  8528. Component.render = compile(template, finalCompilerOptions);
  8529. {
  8530. endMeasure(instance, `compile`);
  8531. }
  8532. }
  8533. }
  8534. instance.render = (Component.render || NOOP);
  8535. // for runtime-compiled render functions using `with` blocks, the render
  8536. // proxy used needs a different `has` handler which is more performant and
  8537. // also only allows a whitelist of globals to fallthrough.
  8538. if (installWithProxy) {
  8539. installWithProxy(instance);
  8540. }
  8541. }
  8542. // support for 2.x options
  8543. {
  8544. setCurrentInstance(instance);
  8545. pauseTracking();
  8546. applyOptions(instance);
  8547. resetTracking();
  8548. unsetCurrentInstance();
  8549. }
  8550. // warn missing template/render
  8551. // the runtime compilation of template in SSR is done by server-render
  8552. if (!Component.render && instance.render === NOOP && !isSSR) {
  8553. /* istanbul ignore if */
  8554. if (!compile && Component.template) {
  8555. warn$1(`Component provided template option but ` +
  8556. `runtime compilation is not supported in this build of Vue.` +
  8557. (` Use "vue.esm-browser.js" instead.`
  8558. ) /* should not happen */);
  8559. }
  8560. else {
  8561. warn$1(`Component is missing template or render function.`);
  8562. }
  8563. }
  8564. }
  8565. function createAttrsProxy(instance) {
  8566. return new Proxy(instance.attrs, {
  8567. get(target, key) {
  8568. markAttrsAccessed();
  8569. track(instance, "get" /* GET */, '$attrs');
  8570. return target[key];
  8571. },
  8572. set() {
  8573. warn$1(`setupContext.attrs is readonly.`);
  8574. return false;
  8575. },
  8576. deleteProperty() {
  8577. warn$1(`setupContext.attrs is readonly.`);
  8578. return false;
  8579. }
  8580. }
  8581. );
  8582. }
  8583. function createSetupContext(instance) {
  8584. const expose = exposed => {
  8585. if (instance.exposed) {
  8586. warn$1(`expose() should be called only once per setup().`);
  8587. }
  8588. instance.exposed = exposed || {};
  8589. };
  8590. let attrs;
  8591. {
  8592. // We use getters in dev in case libs like test-utils overwrite instance
  8593. // properties (overwrites should not be done in prod)
  8594. return Object.freeze({
  8595. get attrs() {
  8596. return attrs || (attrs = createAttrsProxy(instance));
  8597. },
  8598. get slots() {
  8599. return shallowReadonly(instance.slots);
  8600. },
  8601. get emit() {
  8602. return (event, ...args) => instance.emit(event, ...args);
  8603. },
  8604. expose
  8605. });
  8606. }
  8607. }
  8608. function getExposeProxy(instance) {
  8609. if (instance.exposed) {
  8610. return (instance.exposeProxy ||
  8611. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8612. get(target, key) {
  8613. if (key in target) {
  8614. return target[key];
  8615. }
  8616. else if (key in publicPropertiesMap) {
  8617. return publicPropertiesMap[key](instance);
  8618. }
  8619. }
  8620. })));
  8621. }
  8622. }
  8623. const classifyRE = /(?:^|[-_])(\w)/g;
  8624. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8625. function getComponentName(Component) {
  8626. return isFunction(Component)
  8627. ? Component.displayName || Component.name
  8628. : Component.name;
  8629. }
  8630. /* istanbul ignore next */
  8631. function formatComponentName(instance, Component, isRoot = false) {
  8632. let name = getComponentName(Component);
  8633. if (!name && Component.__file) {
  8634. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8635. if (match) {
  8636. name = match[1];
  8637. }
  8638. }
  8639. if (!name && instance && instance.parent) {
  8640. // try to infer the name based on reverse resolution
  8641. const inferFromRegistry = (registry) => {
  8642. for (const key in registry) {
  8643. if (registry[key] === Component) {
  8644. return key;
  8645. }
  8646. }
  8647. };
  8648. name =
  8649. inferFromRegistry(instance.components ||
  8650. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8651. }
  8652. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8653. }
  8654. function isClassComponent(value) {
  8655. return isFunction(value) && '__vccOpts' in value;
  8656. }
  8657. const computed$1 = ((getterOrOptions, debugOptions) => {
  8658. // @ts-ignore
  8659. return computed(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8660. });
  8661. // dev only
  8662. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8663. `<script setup> of a single file component. Its arguments should be ` +
  8664. `compiled away and passing it at runtime has no effect.`);
  8665. // implementation
  8666. function defineProps() {
  8667. {
  8668. warnRuntimeUsage(`defineProps`);
  8669. }
  8670. return null;
  8671. }
  8672. // implementation
  8673. function defineEmits() {
  8674. {
  8675. warnRuntimeUsage(`defineEmits`);
  8676. }
  8677. return null;
  8678. }
  8679. /**
  8680. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8681. * instance properties when it is accessed by a parent component via template
  8682. * refs.
  8683. *
  8684. * `<script setup>` components are closed by default - i.e. variables inside
  8685. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8686. * via `defineExpose`.
  8687. *
  8688. * This is only usable inside `<script setup>`, is compiled away in the
  8689. * output and should **not** be actually called at runtime.
  8690. */
  8691. function defineExpose(exposed) {
  8692. {
  8693. warnRuntimeUsage(`defineExpose`);
  8694. }
  8695. }
  8696. /**
  8697. * Vue `<script setup>` compiler macro for providing props default values when
  8698. * using type-based `defineProps` declaration.
  8699. *
  8700. * Example usage:
  8701. * ```ts
  8702. * withDefaults(defineProps<{
  8703. * size?: number
  8704. * labels?: string[]
  8705. * }>(), {
  8706. * size: 3,
  8707. * labels: () => ['default label']
  8708. * })
  8709. * ```
  8710. *
  8711. * This is only usable inside `<script setup>`, is compiled away in the output
  8712. * and should **not** be actually called at runtime.
  8713. */
  8714. function withDefaults(props, defaults) {
  8715. {
  8716. warnRuntimeUsage(`withDefaults`);
  8717. }
  8718. return null;
  8719. }
  8720. function useSlots() {
  8721. return getContext().slots;
  8722. }
  8723. function useAttrs() {
  8724. return getContext().attrs;
  8725. }
  8726. function getContext() {
  8727. const i = getCurrentInstance();
  8728. if (!i) {
  8729. warn$1(`useContext() called without active instance.`);
  8730. }
  8731. return i.setupContext || (i.setupContext = createSetupContext(i));
  8732. }
  8733. /**
  8734. * Runtime helper for merging default declarations. Imported by compiled code
  8735. * only.
  8736. * @internal
  8737. */
  8738. function mergeDefaults(raw, defaults) {
  8739. const props = isArray(raw)
  8740. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8741. : raw;
  8742. for (const key in defaults) {
  8743. const opt = props[key];
  8744. if (opt) {
  8745. if (isArray(opt) || isFunction(opt)) {
  8746. props[key] = { type: opt, default: defaults[key] };
  8747. }
  8748. else {
  8749. opt.default = defaults[key];
  8750. }
  8751. }
  8752. else if (opt === null) {
  8753. props[key] = { default: defaults[key] };
  8754. }
  8755. else {
  8756. warn$1(`props default key "${key}" has no corresponding declaration.`);
  8757. }
  8758. }
  8759. return props;
  8760. }
  8761. /**
  8762. * Used to create a proxy for the rest element when destructuring props with
  8763. * defineProps().
  8764. * @internal
  8765. */
  8766. function createPropsRestProxy(props, excludedKeys) {
  8767. const ret = {};
  8768. for (const key in props) {
  8769. if (!excludedKeys.includes(key)) {
  8770. Object.defineProperty(ret, key, {
  8771. enumerable: true,
  8772. get: () => props[key]
  8773. });
  8774. }
  8775. }
  8776. return ret;
  8777. }
  8778. /**
  8779. * `<script setup>` helper for persisting the current instance context over
  8780. * async/await flows.
  8781. *
  8782. * `@vue/compiler-sfc` converts the following:
  8783. *
  8784. * ```ts
  8785. * const x = await foo()
  8786. * ```
  8787. *
  8788. * into:
  8789. *
  8790. * ```ts
  8791. * let __temp, __restore
  8792. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8793. * ```
  8794. * @internal
  8795. */
  8796. function withAsyncContext(getAwaitable) {
  8797. const ctx = getCurrentInstance();
  8798. if (!ctx) {
  8799. warn$1(`withAsyncContext called without active current instance. ` +
  8800. `This is likely a bug.`);
  8801. }
  8802. let awaitable = getAwaitable();
  8803. unsetCurrentInstance();
  8804. if (isPromise(awaitable)) {
  8805. awaitable = awaitable.catch(e => {
  8806. setCurrentInstance(ctx);
  8807. throw e;
  8808. });
  8809. }
  8810. return [awaitable, () => setCurrentInstance(ctx)];
  8811. }
  8812. // Actual implementation
  8813. function h(type, propsOrChildren, children) {
  8814. const l = arguments.length;
  8815. if (l === 2) {
  8816. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  8817. // single vnode without props
  8818. if (isVNode(propsOrChildren)) {
  8819. return createVNode(type, null, [propsOrChildren]);
  8820. }
  8821. // props without children
  8822. return createVNode(type, propsOrChildren);
  8823. }
  8824. else {
  8825. // omit props
  8826. return createVNode(type, null, propsOrChildren);
  8827. }
  8828. }
  8829. else {
  8830. if (l > 3) {
  8831. children = Array.prototype.slice.call(arguments, 2);
  8832. }
  8833. else if (l === 3 && isVNode(children)) {
  8834. children = [children];
  8835. }
  8836. return createVNode(type, propsOrChildren, children);
  8837. }
  8838. }
  8839. const ssrContextKey = Symbol(`ssrContext` );
  8840. const useSSRContext = () => {
  8841. {
  8842. const ctx = inject(ssrContextKey);
  8843. if (!ctx) {
  8844. warn$1(`Server rendering context not provided. Make sure to only call ` +
  8845. `useSSRContext() conditionally in the server build.`);
  8846. }
  8847. return ctx;
  8848. }
  8849. };
  8850. function initCustomFormatter() {
  8851. /* eslint-disable no-restricted-globals */
  8852. if (typeof window === 'undefined') {
  8853. return;
  8854. }
  8855. const vueStyle = { style: 'color:#3ba776' };
  8856. const numberStyle = { style: 'color:#0b1bc9' };
  8857. const stringStyle = { style: 'color:#b62e24' };
  8858. const keywordStyle = { style: 'color:#9d288c' };
  8859. // custom formatter for Chrome
  8860. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  8861. const formatter = {
  8862. header(obj) {
  8863. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  8864. if (!isObject(obj)) {
  8865. return null;
  8866. }
  8867. if (obj.__isVue) {
  8868. return ['div', vueStyle, `VueInstance`];
  8869. }
  8870. else if (isRef(obj)) {
  8871. return [
  8872. 'div',
  8873. {},
  8874. ['span', vueStyle, genRefFlag(obj)],
  8875. '<',
  8876. formatValue(obj.value),
  8877. `>`
  8878. ];
  8879. }
  8880. else if (isReactive(obj)) {
  8881. return [
  8882. 'div',
  8883. {},
  8884. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  8885. '<',
  8886. formatValue(obj),
  8887. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  8888. ];
  8889. }
  8890. else if (isReadonly(obj)) {
  8891. return [
  8892. 'div',
  8893. {},
  8894. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  8895. '<',
  8896. formatValue(obj),
  8897. '>'
  8898. ];
  8899. }
  8900. return null;
  8901. },
  8902. hasBody(obj) {
  8903. return obj && obj.__isVue;
  8904. },
  8905. body(obj) {
  8906. if (obj && obj.__isVue) {
  8907. return [
  8908. 'div',
  8909. {},
  8910. ...formatInstance(obj.$)
  8911. ];
  8912. }
  8913. }
  8914. };
  8915. function formatInstance(instance) {
  8916. const blocks = [];
  8917. if (instance.type.props && instance.props) {
  8918. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  8919. }
  8920. if (instance.setupState !== EMPTY_OBJ) {
  8921. blocks.push(createInstanceBlock('setup', instance.setupState));
  8922. }
  8923. if (instance.data !== EMPTY_OBJ) {
  8924. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  8925. }
  8926. const computed = extractKeys(instance, 'computed');
  8927. if (computed) {
  8928. blocks.push(createInstanceBlock('computed', computed));
  8929. }
  8930. const injected = extractKeys(instance, 'inject');
  8931. if (injected) {
  8932. blocks.push(createInstanceBlock('injected', injected));
  8933. }
  8934. blocks.push([
  8935. 'div',
  8936. {},
  8937. [
  8938. 'span',
  8939. {
  8940. style: keywordStyle.style + ';opacity:0.66'
  8941. },
  8942. '$ (internal): '
  8943. ],
  8944. ['object', { object: instance }]
  8945. ]);
  8946. return blocks;
  8947. }
  8948. function createInstanceBlock(type, target) {
  8949. target = extend({}, target);
  8950. if (!Object.keys(target).length) {
  8951. return ['span', {}];
  8952. }
  8953. return [
  8954. 'div',
  8955. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  8956. [
  8957. 'div',
  8958. {
  8959. style: 'color:#476582'
  8960. },
  8961. type
  8962. ],
  8963. [
  8964. 'div',
  8965. {
  8966. style: 'padding-left:1.25em'
  8967. },
  8968. ...Object.keys(target).map(key => {
  8969. return [
  8970. 'div',
  8971. {},
  8972. ['span', keywordStyle, key + ': '],
  8973. formatValue(target[key], false)
  8974. ];
  8975. })
  8976. ]
  8977. ];
  8978. }
  8979. function formatValue(v, asRaw = true) {
  8980. if (typeof v === 'number') {
  8981. return ['span', numberStyle, v];
  8982. }
  8983. else if (typeof v === 'string') {
  8984. return ['span', stringStyle, JSON.stringify(v)];
  8985. }
  8986. else if (typeof v === 'boolean') {
  8987. return ['span', keywordStyle, v];
  8988. }
  8989. else if (isObject(v)) {
  8990. return ['object', { object: asRaw ? toRaw(v) : v }];
  8991. }
  8992. else {
  8993. return ['span', stringStyle, String(v)];
  8994. }
  8995. }
  8996. function extractKeys(instance, type) {
  8997. const Comp = instance.type;
  8998. if (isFunction(Comp)) {
  8999. return;
  9000. }
  9001. const extracted = {};
  9002. for (const key in instance.ctx) {
  9003. if (isKeyOfType(Comp, key, type)) {
  9004. extracted[key] = instance.ctx[key];
  9005. }
  9006. }
  9007. return extracted;
  9008. }
  9009. function isKeyOfType(Comp, key, type) {
  9010. const opts = Comp[type];
  9011. if ((isArray(opts) && opts.includes(key)) ||
  9012. (isObject(opts) && key in opts)) {
  9013. return true;
  9014. }
  9015. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9016. return true;
  9017. }
  9018. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9019. return true;
  9020. }
  9021. }
  9022. function genRefFlag(v) {
  9023. if (isShallow(v)) {
  9024. return `ShallowRef`;
  9025. }
  9026. if (v.effect) {
  9027. return `ComputedRef`;
  9028. }
  9029. return `Ref`;
  9030. }
  9031. if (window.devtoolsFormatters) {
  9032. window.devtoolsFormatters.push(formatter);
  9033. }
  9034. else {
  9035. window.devtoolsFormatters = [formatter];
  9036. }
  9037. }
  9038. function withMemo(memo, render, cache, index) {
  9039. const cached = cache[index];
  9040. if (cached && isMemoSame(cached, memo)) {
  9041. return cached;
  9042. }
  9043. const ret = render();
  9044. // shallow clone
  9045. ret.memo = memo.slice();
  9046. return (cache[index] = ret);
  9047. }
  9048. function isMemoSame(cached, memo) {
  9049. const prev = cached.memo;
  9050. if (prev.length != memo.length) {
  9051. return false;
  9052. }
  9053. for (let i = 0; i < prev.length; i++) {
  9054. if (prev[i] !== memo[i]) {
  9055. return false;
  9056. }
  9057. }
  9058. // make sure to let parent block track it when returning cached
  9059. if (isBlockTreeEnabled > 0 && currentBlock) {
  9060. currentBlock.push(cached);
  9061. }
  9062. return true;
  9063. }
  9064. // Core API ------------------------------------------------------------------
  9065. const version = "3.2.33";
  9066. /**
  9067. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  9068. * @internal
  9069. */
  9070. const ssrUtils = (null);
  9071. /**
  9072. * @internal only exposed in compat builds
  9073. */
  9074. const resolveFilter = null;
  9075. /**
  9076. * @internal only exposed in compat builds.
  9077. */
  9078. const compatUtils = (null);
  9079. const svgNS = 'http://www.w3.org/2000/svg';
  9080. const doc = (typeof document !== 'undefined' ? document : null);
  9081. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9082. const nodeOps = {
  9083. insert: (child, parent, anchor) => {
  9084. parent.insertBefore(child, anchor || null);
  9085. },
  9086. remove: child => {
  9087. const parent = child.parentNode;
  9088. if (parent) {
  9089. parent.removeChild(child);
  9090. }
  9091. },
  9092. createElement: (tag, isSVG, is, props) => {
  9093. const el = isSVG
  9094. ? doc.createElementNS(svgNS, tag)
  9095. : doc.createElement(tag, is ? { is } : undefined);
  9096. if (tag === 'select' && props && props.multiple != null) {
  9097. el.setAttribute('multiple', props.multiple);
  9098. }
  9099. return el;
  9100. },
  9101. createText: text => doc.createTextNode(text),
  9102. createComment: text => doc.createComment(text),
  9103. setText: (node, text) => {
  9104. node.nodeValue = text;
  9105. },
  9106. setElementText: (el, text) => {
  9107. el.textContent = text;
  9108. },
  9109. parentNode: node => node.parentNode,
  9110. nextSibling: node => node.nextSibling,
  9111. querySelector: selector => doc.querySelector(selector),
  9112. setScopeId(el, id) {
  9113. el.setAttribute(id, '');
  9114. },
  9115. cloneNode(el) {
  9116. const cloned = el.cloneNode(true);
  9117. // #3072
  9118. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  9119. // - normally, elements using `:value` bindings will not be hoisted, but if
  9120. // the bound value is a constant, e.g. `:value="true"` - they do get
  9121. // hoisted.
  9122. // - in production, hoisted nodes are cloned when subsequent inserts, but
  9123. // cloneNode() does not copy the custom property we attached.
  9124. // - This may need to account for other custom DOM properties we attach to
  9125. // elements in addition to `_value` in the future.
  9126. if (`_value` in el) {
  9127. cloned._value = el._value;
  9128. }
  9129. return cloned;
  9130. },
  9131. // __UNSAFE__
  9132. // Reason: innerHTML.
  9133. // Static content here can only come from compiled templates.
  9134. // As long as the user only uses trusted templates, this is safe.
  9135. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9136. // <parent> before | first ... last | anchor </parent>
  9137. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9138. // #5308 can only take cached path if:
  9139. // - has a single root node
  9140. // - nextSibling info is still available
  9141. if (start && (start === end || start.nextSibling)) {
  9142. // cached
  9143. while (true) {
  9144. parent.insertBefore(start.cloneNode(true), anchor);
  9145. if (start === end || !(start = start.nextSibling))
  9146. break;
  9147. }
  9148. }
  9149. else {
  9150. // fresh insert
  9151. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9152. const template = templateContainer.content;
  9153. if (isSVG) {
  9154. // remove outer svg wrapper
  9155. const wrapper = template.firstChild;
  9156. while (wrapper.firstChild) {
  9157. template.appendChild(wrapper.firstChild);
  9158. }
  9159. template.removeChild(wrapper);
  9160. }
  9161. parent.insertBefore(template, anchor);
  9162. }
  9163. return [
  9164. // first
  9165. before ? before.nextSibling : parent.firstChild,
  9166. // last
  9167. anchor ? anchor.previousSibling : parent.lastChild
  9168. ];
  9169. }
  9170. };
  9171. // compiler should normalize class + :class bindings on the same element
  9172. // into a single binding ['staticClass', dynamic]
  9173. function patchClass(el, value, isSVG) {
  9174. // directly setting className should be faster than setAttribute in theory
  9175. // if this is an element during a transition, take the temporary transition
  9176. // classes into account.
  9177. const transitionClasses = el._vtc;
  9178. if (transitionClasses) {
  9179. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9180. }
  9181. if (value == null) {
  9182. el.removeAttribute('class');
  9183. }
  9184. else if (isSVG) {
  9185. el.setAttribute('class', value);
  9186. }
  9187. else {
  9188. el.className = value;
  9189. }
  9190. }
  9191. function patchStyle(el, prev, next) {
  9192. const style = el.style;
  9193. const isCssString = isString(next);
  9194. if (next && !isCssString) {
  9195. for (const key in next) {
  9196. setStyle(style, key, next[key]);
  9197. }
  9198. if (prev && !isString(prev)) {
  9199. for (const key in prev) {
  9200. if (next[key] == null) {
  9201. setStyle(style, key, '');
  9202. }
  9203. }
  9204. }
  9205. }
  9206. else {
  9207. const currentDisplay = style.display;
  9208. if (isCssString) {
  9209. if (prev !== next) {
  9210. style.cssText = next;
  9211. }
  9212. }
  9213. else if (prev) {
  9214. el.removeAttribute('style');
  9215. }
  9216. // indicates that the `display` of the element is controlled by `v-show`,
  9217. // so we always keep the current `display` value regardless of the `style`
  9218. // value, thus handing over control to `v-show`.
  9219. if ('_vod' in el) {
  9220. style.display = currentDisplay;
  9221. }
  9222. }
  9223. }
  9224. const importantRE = /\s*!important$/;
  9225. function setStyle(style, name, val) {
  9226. if (isArray(val)) {
  9227. val.forEach(v => setStyle(style, name, v));
  9228. }
  9229. else {
  9230. if (val == null)
  9231. val = '';
  9232. if (name.startsWith('--')) {
  9233. // custom property definition
  9234. style.setProperty(name, val);
  9235. }
  9236. else {
  9237. const prefixed = autoPrefix(style, name);
  9238. if (importantRE.test(val)) {
  9239. // !important
  9240. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9241. }
  9242. else {
  9243. style[prefixed] = val;
  9244. }
  9245. }
  9246. }
  9247. }
  9248. const prefixes = ['Webkit', 'Moz', 'ms'];
  9249. const prefixCache = {};
  9250. function autoPrefix(style, rawName) {
  9251. const cached = prefixCache[rawName];
  9252. if (cached) {
  9253. return cached;
  9254. }
  9255. let name = camelize(rawName);
  9256. if (name !== 'filter' && name in style) {
  9257. return (prefixCache[rawName] = name);
  9258. }
  9259. name = capitalize(name);
  9260. for (let i = 0; i < prefixes.length; i++) {
  9261. const prefixed = prefixes[i] + name;
  9262. if (prefixed in style) {
  9263. return (prefixCache[rawName] = prefixed);
  9264. }
  9265. }
  9266. return rawName;
  9267. }
  9268. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9269. function patchAttr(el, key, value, isSVG, instance) {
  9270. if (isSVG && key.startsWith('xlink:')) {
  9271. if (value == null) {
  9272. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9273. }
  9274. else {
  9275. el.setAttributeNS(xlinkNS, key, value);
  9276. }
  9277. }
  9278. else {
  9279. // note we are only checking boolean attributes that don't have a
  9280. // corresponding dom prop of the same name here.
  9281. const isBoolean = isSpecialBooleanAttr(key);
  9282. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9283. el.removeAttribute(key);
  9284. }
  9285. else {
  9286. el.setAttribute(key, isBoolean ? '' : value);
  9287. }
  9288. }
  9289. }
  9290. // __UNSAFE__
  9291. // functions. The user is responsible for using them with only trusted content.
  9292. function patchDOMProp(el, key, value,
  9293. // the following args are passed only due to potential innerHTML/textContent
  9294. // overriding existing VNodes, in which case the old tree must be properly
  9295. // unmounted.
  9296. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9297. if (key === 'innerHTML' || key === 'textContent') {
  9298. if (prevChildren) {
  9299. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9300. }
  9301. el[key] = value == null ? '' : value;
  9302. return;
  9303. }
  9304. if (key === 'value' &&
  9305. el.tagName !== 'PROGRESS' &&
  9306. // custom elements may use _value internally
  9307. !el.tagName.includes('-')) {
  9308. // store value as _value as well since
  9309. // non-string values will be stringified.
  9310. el._value = value;
  9311. const newValue = value == null ? '' : value;
  9312. if (el.value !== newValue ||
  9313. // #4956: always set for OPTION elements because its value falls back to
  9314. // textContent if no value attribute is present. And setting .value for
  9315. // OPTION has no side effect
  9316. el.tagName === 'OPTION') {
  9317. el.value = newValue;
  9318. }
  9319. if (value == null) {
  9320. el.removeAttribute(key);
  9321. }
  9322. return;
  9323. }
  9324. let needRemove = false;
  9325. if (value === '' || value == null) {
  9326. const type = typeof el[key];
  9327. if (type === 'boolean') {
  9328. // e.g. <select multiple> compiles to { multiple: '' }
  9329. value = includeBooleanAttr(value);
  9330. }
  9331. else if (value == null && type === 'string') {
  9332. // e.g. <div :id="null">
  9333. value = '';
  9334. needRemove = true;
  9335. }
  9336. else if (type === 'number') {
  9337. // e.g. <img :width="null">
  9338. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  9339. value = 0;
  9340. needRemove = true;
  9341. }
  9342. }
  9343. // some properties perform value validation and throw,
  9344. // some properties has getter, no setter, will error in 'use strict'
  9345. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9346. try {
  9347. el[key] = value;
  9348. }
  9349. catch (e) {
  9350. {
  9351. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9352. `value ${value} is invalid.`, e);
  9353. }
  9354. }
  9355. needRemove && el.removeAttribute(key);
  9356. }
  9357. // Async edge case fix requires storing an event listener's attach timestamp.
  9358. const [_getNow, skipTimestampCheck] = /*#__PURE__*/ (() => {
  9359. let _getNow = Date.now;
  9360. let skipTimestampCheck = false;
  9361. if (typeof window !== 'undefined') {
  9362. // Determine what event timestamp the browser is using. Annoyingly, the
  9363. // timestamp can either be hi-res (relative to page load) or low-res
  9364. // (relative to UNIX epoch), so in order to compare time we have to use the
  9365. // same timestamp type when saving the flush timestamp.
  9366. if (Date.now() > document.createEvent('Event').timeStamp) {
  9367. // if the low-res timestamp which is bigger than the event timestamp
  9368. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  9369. // and we need to use the hi-res version for event listeners as well.
  9370. _getNow = () => performance.now();
  9371. }
  9372. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  9373. // and does not fire microtasks in between event propagation, so safe to exclude.
  9374. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  9375. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  9376. }
  9377. return [_getNow, skipTimestampCheck];
  9378. })();
  9379. // To avoid the overhead of repeatedly calling performance.now(), we cache
  9380. // and use the same timestamp for all event listeners attached in the same tick.
  9381. let cachedNow = 0;
  9382. const p = /*#__PURE__*/ Promise.resolve();
  9383. const reset = () => {
  9384. cachedNow = 0;
  9385. };
  9386. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  9387. function addEventListener(el, event, handler, options) {
  9388. el.addEventListener(event, handler, options);
  9389. }
  9390. function removeEventListener(el, event, handler, options) {
  9391. el.removeEventListener(event, handler, options);
  9392. }
  9393. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9394. // vei = vue event invokers
  9395. const invokers = el._vei || (el._vei = {});
  9396. const existingInvoker = invokers[rawName];
  9397. if (nextValue && existingInvoker) {
  9398. // patch
  9399. existingInvoker.value = nextValue;
  9400. }
  9401. else {
  9402. const [name, options] = parseName(rawName);
  9403. if (nextValue) {
  9404. // add
  9405. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9406. addEventListener(el, name, invoker, options);
  9407. }
  9408. else if (existingInvoker) {
  9409. // remove
  9410. removeEventListener(el, name, existingInvoker, options);
  9411. invokers[rawName] = undefined;
  9412. }
  9413. }
  9414. }
  9415. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9416. function parseName(name) {
  9417. let options;
  9418. if (optionsModifierRE.test(name)) {
  9419. options = {};
  9420. let m;
  9421. while ((m = name.match(optionsModifierRE))) {
  9422. name = name.slice(0, name.length - m[0].length);
  9423. options[m[0].toLowerCase()] = true;
  9424. }
  9425. }
  9426. return [hyphenate(name.slice(2)), options];
  9427. }
  9428. function createInvoker(initialValue, instance) {
  9429. const invoker = (e) => {
  9430. // async edge case #6566: inner click event triggers patch, event handler
  9431. // attached to outer element during patch, and triggered again. This
  9432. // happens because browsers fire microtask ticks between event propagation.
  9433. // the solution is simple: we save the timestamp when a handler is attached,
  9434. // and the handler would only fire if the event passed to it was fired
  9435. // AFTER it was attached.
  9436. const timeStamp = e.timeStamp || _getNow();
  9437. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  9438. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  9439. }
  9440. };
  9441. invoker.value = initialValue;
  9442. invoker.attached = getNow();
  9443. return invoker;
  9444. }
  9445. function patchStopImmediatePropagation(e, value) {
  9446. if (isArray(value)) {
  9447. const originalStop = e.stopImmediatePropagation;
  9448. e.stopImmediatePropagation = () => {
  9449. originalStop.call(e);
  9450. e._stopped = true;
  9451. };
  9452. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9453. }
  9454. else {
  9455. return value;
  9456. }
  9457. }
  9458. const nativeOnRE = /^on[a-z]/;
  9459. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9460. if (key === 'class') {
  9461. patchClass(el, nextValue, isSVG);
  9462. }
  9463. else if (key === 'style') {
  9464. patchStyle(el, prevValue, nextValue);
  9465. }
  9466. else if (isOn(key)) {
  9467. // ignore v-model listeners
  9468. if (!isModelListener(key)) {
  9469. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9470. }
  9471. }
  9472. else if (key[0] === '.'
  9473. ? ((key = key.slice(1)), true)
  9474. : key[0] === '^'
  9475. ? ((key = key.slice(1)), false)
  9476. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9477. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9478. }
  9479. else {
  9480. // special case for <input v-model type="checkbox"> with
  9481. // :true-value & :false-value
  9482. // store value as dom properties since non-string values will be
  9483. // stringified.
  9484. if (key === 'true-value') {
  9485. el._trueValue = nextValue;
  9486. }
  9487. else if (key === 'false-value') {
  9488. el._falseValue = nextValue;
  9489. }
  9490. patchAttr(el, key, nextValue, isSVG);
  9491. }
  9492. };
  9493. function shouldSetAsProp(el, key, value, isSVG) {
  9494. if (isSVG) {
  9495. // most keys must be set as attribute on svg elements to work
  9496. // ...except innerHTML & textContent
  9497. if (key === 'innerHTML' || key === 'textContent') {
  9498. return true;
  9499. }
  9500. // or native onclick with function values
  9501. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9502. return true;
  9503. }
  9504. return false;
  9505. }
  9506. // these are enumerated attrs, however their corresponding DOM properties
  9507. // are actually booleans - this leads to setting it with a string "false"
  9508. // value leading it to be coerced to `true`, so we need to always treat
  9509. // them as attributes.
  9510. // Note that `contentEditable` doesn't have this problem: its DOM
  9511. // property is also enumerated string values.
  9512. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9513. return false;
  9514. }
  9515. // #1787, #2840 form property on form elements is readonly and must be set as
  9516. // attribute.
  9517. if (key === 'form') {
  9518. return false;
  9519. }
  9520. // #1526 <input list> must be set as attribute
  9521. if (key === 'list' && el.tagName === 'INPUT') {
  9522. return false;
  9523. }
  9524. // #2766 <textarea type> must be set as attribute
  9525. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9526. return false;
  9527. }
  9528. // native onclick with string value, must be set as attribute
  9529. if (nativeOnRE.test(key) && isString(value)) {
  9530. return false;
  9531. }
  9532. return key in el;
  9533. }
  9534. function defineCustomElement(options, hydate) {
  9535. const Comp = defineComponent(options);
  9536. class VueCustomElement extends VueElement {
  9537. constructor(initialProps) {
  9538. super(Comp, initialProps, hydate);
  9539. }
  9540. }
  9541. VueCustomElement.def = Comp;
  9542. return VueCustomElement;
  9543. }
  9544. const defineSSRCustomElement = ((options) => {
  9545. // @ts-ignore
  9546. return defineCustomElement(options, hydrate);
  9547. });
  9548. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9549. });
  9550. class VueElement extends BaseClass {
  9551. constructor(_def, _props = {}, hydrate) {
  9552. super();
  9553. this._def = _def;
  9554. this._props = _props;
  9555. /**
  9556. * @internal
  9557. */
  9558. this._instance = null;
  9559. this._connected = false;
  9560. this._resolved = false;
  9561. this._numberProps = null;
  9562. if (this.shadowRoot && hydrate) {
  9563. hydrate(this._createVNode(), this.shadowRoot);
  9564. }
  9565. else {
  9566. if (this.shadowRoot) {
  9567. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9568. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9569. }
  9570. this.attachShadow({ mode: 'open' });
  9571. }
  9572. }
  9573. connectedCallback() {
  9574. this._connected = true;
  9575. if (!this._instance) {
  9576. this._resolveDef();
  9577. }
  9578. }
  9579. disconnectedCallback() {
  9580. this._connected = false;
  9581. nextTick(() => {
  9582. if (!this._connected) {
  9583. render(null, this.shadowRoot);
  9584. this._instance = null;
  9585. }
  9586. });
  9587. }
  9588. /**
  9589. * resolve inner component definition (handle possible async component)
  9590. */
  9591. _resolveDef() {
  9592. if (this._resolved) {
  9593. return;
  9594. }
  9595. this._resolved = true;
  9596. // set initial attrs
  9597. for (let i = 0; i < this.attributes.length; i++) {
  9598. this._setAttr(this.attributes[i].name);
  9599. }
  9600. // watch future attr changes
  9601. new MutationObserver(mutations => {
  9602. for (const m of mutations) {
  9603. this._setAttr(m.attributeName);
  9604. }
  9605. }).observe(this, { attributes: true });
  9606. const resolve = (def) => {
  9607. const { props, styles } = def;
  9608. const hasOptions = !isArray(props);
  9609. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  9610. // cast Number-type props set before resolve
  9611. let numberProps;
  9612. if (hasOptions) {
  9613. for (const key in this._props) {
  9614. const opt = props[key];
  9615. if (opt === Number || (opt && opt.type === Number)) {
  9616. this._props[key] = toNumber(this._props[key]);
  9617. (numberProps || (numberProps = Object.create(null)))[key] = true;
  9618. }
  9619. }
  9620. }
  9621. this._numberProps = numberProps;
  9622. // check if there are props set pre-upgrade or connect
  9623. for (const key of Object.keys(this)) {
  9624. if (key[0] !== '_') {
  9625. this._setProp(key, this[key], true, false);
  9626. }
  9627. }
  9628. // defining getter/setters on prototype
  9629. for (const key of rawKeys.map(camelize)) {
  9630. Object.defineProperty(this, key, {
  9631. get() {
  9632. return this._getProp(key);
  9633. },
  9634. set(val) {
  9635. this._setProp(key, val);
  9636. }
  9637. });
  9638. }
  9639. // apply CSS
  9640. this._applyStyles(styles);
  9641. // initial render
  9642. this._update();
  9643. };
  9644. const asyncDef = this._def.__asyncLoader;
  9645. if (asyncDef) {
  9646. asyncDef().then(resolve);
  9647. }
  9648. else {
  9649. resolve(this._def);
  9650. }
  9651. }
  9652. _setAttr(key) {
  9653. let value = this.getAttribute(key);
  9654. if (this._numberProps && this._numberProps[key]) {
  9655. value = toNumber(value);
  9656. }
  9657. this._setProp(camelize(key), value, false);
  9658. }
  9659. /**
  9660. * @internal
  9661. */
  9662. _getProp(key) {
  9663. return this._props[key];
  9664. }
  9665. /**
  9666. * @internal
  9667. */
  9668. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9669. if (val !== this._props[key]) {
  9670. this._props[key] = val;
  9671. if (shouldUpdate && this._instance) {
  9672. this._update();
  9673. }
  9674. // reflect
  9675. if (shouldReflect) {
  9676. if (val === true) {
  9677. this.setAttribute(hyphenate(key), '');
  9678. }
  9679. else if (typeof val === 'string' || typeof val === 'number') {
  9680. this.setAttribute(hyphenate(key), val + '');
  9681. }
  9682. else if (!val) {
  9683. this.removeAttribute(hyphenate(key));
  9684. }
  9685. }
  9686. }
  9687. }
  9688. _update() {
  9689. render(this._createVNode(), this.shadowRoot);
  9690. }
  9691. _createVNode() {
  9692. const vnode = createVNode(this._def, extend({}, this._props));
  9693. if (!this._instance) {
  9694. vnode.ce = instance => {
  9695. this._instance = instance;
  9696. instance.isCE = true;
  9697. // HMR
  9698. {
  9699. instance.ceReload = newStyles => {
  9700. // always reset styles
  9701. if (this._styles) {
  9702. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9703. this._styles.length = 0;
  9704. }
  9705. this._applyStyles(newStyles);
  9706. // if this is an async component, ceReload is called from the inner
  9707. // component so no need to reload the async wrapper
  9708. if (!this._def.__asyncLoader) {
  9709. // reload
  9710. this._instance = null;
  9711. this._update();
  9712. }
  9713. };
  9714. }
  9715. // intercept emit
  9716. instance.emit = (event, ...args) => {
  9717. this.dispatchEvent(new CustomEvent(event, {
  9718. detail: args
  9719. }));
  9720. };
  9721. // locate nearest Vue custom element parent for provide/inject
  9722. let parent = this;
  9723. while ((parent =
  9724. parent && (parent.parentNode || parent.host))) {
  9725. if (parent instanceof VueElement) {
  9726. instance.parent = parent._instance;
  9727. break;
  9728. }
  9729. }
  9730. };
  9731. }
  9732. return vnode;
  9733. }
  9734. _applyStyles(styles) {
  9735. if (styles) {
  9736. styles.forEach(css => {
  9737. const s = document.createElement('style');
  9738. s.textContent = css;
  9739. this.shadowRoot.appendChild(s);
  9740. // record for HMR
  9741. {
  9742. (this._styles || (this._styles = [])).push(s);
  9743. }
  9744. });
  9745. }
  9746. }
  9747. }
  9748. function useCssModule(name = '$style') {
  9749. /* istanbul ignore else */
  9750. {
  9751. const instance = getCurrentInstance();
  9752. if (!instance) {
  9753. warn$1(`useCssModule must be called inside setup()`);
  9754. return EMPTY_OBJ;
  9755. }
  9756. const modules = instance.type.__cssModules;
  9757. if (!modules) {
  9758. warn$1(`Current instance does not have CSS modules injected.`);
  9759. return EMPTY_OBJ;
  9760. }
  9761. const mod = modules[name];
  9762. if (!mod) {
  9763. warn$1(`Current instance does not have CSS module named "${name}".`);
  9764. return EMPTY_OBJ;
  9765. }
  9766. return mod;
  9767. }
  9768. }
  9769. /**
  9770. * Runtime helper for SFC's CSS variable injection feature.
  9771. * @private
  9772. */
  9773. function useCssVars(getter) {
  9774. const instance = getCurrentInstance();
  9775. /* istanbul ignore next */
  9776. if (!instance) {
  9777. warn$1(`useCssVars is called without current active component instance.`);
  9778. return;
  9779. }
  9780. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  9781. watchPostEffect(setVars);
  9782. onMounted(() => {
  9783. const ob = new MutationObserver(setVars);
  9784. ob.observe(instance.subTree.el.parentNode, { childList: true });
  9785. onUnmounted(() => ob.disconnect());
  9786. });
  9787. }
  9788. function setVarsOnVNode(vnode, vars) {
  9789. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  9790. const suspense = vnode.suspense;
  9791. vnode = suspense.activeBranch;
  9792. if (suspense.pendingBranch && !suspense.isHydrating) {
  9793. suspense.effects.push(() => {
  9794. setVarsOnVNode(suspense.activeBranch, vars);
  9795. });
  9796. }
  9797. }
  9798. // drill down HOCs until it's a non-component vnode
  9799. while (vnode.component) {
  9800. vnode = vnode.component.subTree;
  9801. }
  9802. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  9803. setVarsOnNode(vnode.el, vars);
  9804. }
  9805. else if (vnode.type === Fragment) {
  9806. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  9807. }
  9808. else if (vnode.type === Static) {
  9809. let { el, anchor } = vnode;
  9810. while (el) {
  9811. setVarsOnNode(el, vars);
  9812. if (el === anchor)
  9813. break;
  9814. el = el.nextSibling;
  9815. }
  9816. }
  9817. }
  9818. function setVarsOnNode(el, vars) {
  9819. if (el.nodeType === 1) {
  9820. const style = el.style;
  9821. for (const key in vars) {
  9822. style.setProperty(`--${key}`, vars[key]);
  9823. }
  9824. }
  9825. }
  9826. const TRANSITION = 'transition';
  9827. const ANIMATION = 'animation';
  9828. // DOM Transition is a higher-order-component based on the platform-agnostic
  9829. // base Transition component, with DOM-specific logic.
  9830. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  9831. Transition.displayName = 'Transition';
  9832. const DOMTransitionPropsValidators = {
  9833. name: String,
  9834. type: String,
  9835. css: {
  9836. type: Boolean,
  9837. default: true
  9838. },
  9839. duration: [String, Number, Object],
  9840. enterFromClass: String,
  9841. enterActiveClass: String,
  9842. enterToClass: String,
  9843. appearFromClass: String,
  9844. appearActiveClass: String,
  9845. appearToClass: String,
  9846. leaveFromClass: String,
  9847. leaveActiveClass: String,
  9848. leaveToClass: String
  9849. };
  9850. const TransitionPropsValidators = (Transition.props =
  9851. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  9852. /**
  9853. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  9854. * with custom HOCs.
  9855. */
  9856. const callHook$1 = (hook, args = []) => {
  9857. if (isArray(hook)) {
  9858. hook.forEach(h => h(...args));
  9859. }
  9860. else if (hook) {
  9861. hook(...args);
  9862. }
  9863. };
  9864. /**
  9865. * Check if a hook expects a callback (2nd arg), which means the user
  9866. * intends to explicitly control the end of the transition.
  9867. */
  9868. const hasExplicitCallback = (hook) => {
  9869. return hook
  9870. ? isArray(hook)
  9871. ? hook.some(h => h.length > 1)
  9872. : hook.length > 1
  9873. : false;
  9874. };
  9875. function resolveTransitionProps(rawProps) {
  9876. const baseProps = {};
  9877. for (const key in rawProps) {
  9878. if (!(key in DOMTransitionPropsValidators)) {
  9879. baseProps[key] = rawProps[key];
  9880. }
  9881. }
  9882. if (rawProps.css === false) {
  9883. return baseProps;
  9884. }
  9885. const { name = 'v', type, 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;
  9886. const durations = normalizeDuration(duration);
  9887. const enterDuration = durations && durations[0];
  9888. const leaveDuration = durations && durations[1];
  9889. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  9890. const finishEnter = (el, isAppear, done) => {
  9891. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9892. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  9893. done && done();
  9894. };
  9895. const finishLeave = (el, done) => {
  9896. removeTransitionClass(el, leaveToClass);
  9897. removeTransitionClass(el, leaveActiveClass);
  9898. done && done();
  9899. };
  9900. const makeEnterHook = (isAppear) => {
  9901. return (el, done) => {
  9902. const hook = isAppear ? onAppear : onEnter;
  9903. const resolve = () => finishEnter(el, isAppear, done);
  9904. callHook$1(hook, [el, resolve]);
  9905. nextFrame(() => {
  9906. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  9907. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9908. if (!hasExplicitCallback(hook)) {
  9909. whenTransitionEnds(el, type, enterDuration, resolve);
  9910. }
  9911. });
  9912. };
  9913. };
  9914. return extend(baseProps, {
  9915. onBeforeEnter(el) {
  9916. callHook$1(onBeforeEnter, [el]);
  9917. addTransitionClass(el, enterFromClass);
  9918. addTransitionClass(el, enterActiveClass);
  9919. },
  9920. onBeforeAppear(el) {
  9921. callHook$1(onBeforeAppear, [el]);
  9922. addTransitionClass(el, appearFromClass);
  9923. addTransitionClass(el, appearActiveClass);
  9924. },
  9925. onEnter: makeEnterHook(false),
  9926. onAppear: makeEnterHook(true),
  9927. onLeave(el, done) {
  9928. const resolve = () => finishLeave(el, done);
  9929. addTransitionClass(el, leaveFromClass);
  9930. // force reflow so *-leave-from classes immediately take effect (#2593)
  9931. forceReflow();
  9932. addTransitionClass(el, leaveActiveClass);
  9933. nextFrame(() => {
  9934. removeTransitionClass(el, leaveFromClass);
  9935. addTransitionClass(el, leaveToClass);
  9936. if (!hasExplicitCallback(onLeave)) {
  9937. whenTransitionEnds(el, type, leaveDuration, resolve);
  9938. }
  9939. });
  9940. callHook$1(onLeave, [el, resolve]);
  9941. },
  9942. onEnterCancelled(el) {
  9943. finishEnter(el, false);
  9944. callHook$1(onEnterCancelled, [el]);
  9945. },
  9946. onAppearCancelled(el) {
  9947. finishEnter(el, true);
  9948. callHook$1(onAppearCancelled, [el]);
  9949. },
  9950. onLeaveCancelled(el) {
  9951. finishLeave(el);
  9952. callHook$1(onLeaveCancelled, [el]);
  9953. }
  9954. });
  9955. }
  9956. function normalizeDuration(duration) {
  9957. if (duration == null) {
  9958. return null;
  9959. }
  9960. else if (isObject(duration)) {
  9961. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  9962. }
  9963. else {
  9964. const n = NumberOf(duration);
  9965. return [n, n];
  9966. }
  9967. }
  9968. function NumberOf(val) {
  9969. const res = toNumber(val);
  9970. validateDuration(res);
  9971. return res;
  9972. }
  9973. function validateDuration(val) {
  9974. if (typeof val !== 'number') {
  9975. warn$1(`<transition> explicit duration is not a valid number - ` +
  9976. `got ${JSON.stringify(val)}.`);
  9977. }
  9978. else if (isNaN(val)) {
  9979. warn$1(`<transition> explicit duration is NaN - ` +
  9980. 'the duration expression might be incorrect.');
  9981. }
  9982. }
  9983. function addTransitionClass(el, cls) {
  9984. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  9985. (el._vtc ||
  9986. (el._vtc = new Set())).add(cls);
  9987. }
  9988. function removeTransitionClass(el, cls) {
  9989. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  9990. const { _vtc } = el;
  9991. if (_vtc) {
  9992. _vtc.delete(cls);
  9993. if (!_vtc.size) {
  9994. el._vtc = undefined;
  9995. }
  9996. }
  9997. }
  9998. function nextFrame(cb) {
  9999. requestAnimationFrame(() => {
  10000. requestAnimationFrame(cb);
  10001. });
  10002. }
  10003. let endId = 0;
  10004. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10005. const id = (el._endId = ++endId);
  10006. const resolveIfNotStale = () => {
  10007. if (id === el._endId) {
  10008. resolve();
  10009. }
  10010. };
  10011. if (explicitTimeout) {
  10012. return setTimeout(resolveIfNotStale, explicitTimeout);
  10013. }
  10014. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10015. if (!type) {
  10016. return resolve();
  10017. }
  10018. const endEvent = type + 'end';
  10019. let ended = 0;
  10020. const end = () => {
  10021. el.removeEventListener(endEvent, onEnd);
  10022. resolveIfNotStale();
  10023. };
  10024. const onEnd = (e) => {
  10025. if (e.target === el && ++ended >= propCount) {
  10026. end();
  10027. }
  10028. };
  10029. setTimeout(() => {
  10030. if (ended < propCount) {
  10031. end();
  10032. }
  10033. }, timeout + 1);
  10034. el.addEventListener(endEvent, onEnd);
  10035. }
  10036. function getTransitionInfo(el, expectedType) {
  10037. const styles = window.getComputedStyle(el);
  10038. // JSDOM may return undefined for transition properties
  10039. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10040. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  10041. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  10042. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10043. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  10044. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  10045. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10046. let type = null;
  10047. let timeout = 0;
  10048. let propCount = 0;
  10049. /* istanbul ignore if */
  10050. if (expectedType === TRANSITION) {
  10051. if (transitionTimeout > 0) {
  10052. type = TRANSITION;
  10053. timeout = transitionTimeout;
  10054. propCount = transitionDurations.length;
  10055. }
  10056. }
  10057. else if (expectedType === ANIMATION) {
  10058. if (animationTimeout > 0) {
  10059. type = ANIMATION;
  10060. timeout = animationTimeout;
  10061. propCount = animationDurations.length;
  10062. }
  10063. }
  10064. else {
  10065. timeout = Math.max(transitionTimeout, animationTimeout);
  10066. type =
  10067. timeout > 0
  10068. ? transitionTimeout > animationTimeout
  10069. ? TRANSITION
  10070. : ANIMATION
  10071. : null;
  10072. propCount = type
  10073. ? type === TRANSITION
  10074. ? transitionDurations.length
  10075. : animationDurations.length
  10076. : 0;
  10077. }
  10078. const hasTransform = type === TRANSITION &&
  10079. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  10080. return {
  10081. type,
  10082. timeout,
  10083. propCount,
  10084. hasTransform
  10085. };
  10086. }
  10087. function getTimeout(delays, durations) {
  10088. while (delays.length < durations.length) {
  10089. delays = delays.concat(delays);
  10090. }
  10091. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10092. }
  10093. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10094. // numbers in a locale-dependent way, using a comma instead of a dot.
  10095. // If comma is not replaced with a dot, the input will be rounded down
  10096. // (i.e. acting as a floor function) causing unexpected behaviors
  10097. function toMs(s) {
  10098. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10099. }
  10100. // synchronously force layout to put elements into a certain state
  10101. function forceReflow() {
  10102. return document.body.offsetHeight;
  10103. }
  10104. const positionMap = new WeakMap();
  10105. const newPositionMap = new WeakMap();
  10106. const TransitionGroupImpl = {
  10107. name: 'TransitionGroup',
  10108. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10109. tag: String,
  10110. moveClass: String
  10111. }),
  10112. setup(props, { slots }) {
  10113. const instance = getCurrentInstance();
  10114. const state = useTransitionState();
  10115. let prevChildren;
  10116. let children;
  10117. onUpdated(() => {
  10118. // children is guaranteed to exist after initial render
  10119. if (!prevChildren.length) {
  10120. return;
  10121. }
  10122. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10123. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10124. return;
  10125. }
  10126. // we divide the work into three loops to avoid mixing DOM reads and writes
  10127. // in each iteration - which helps prevent layout thrashing.
  10128. prevChildren.forEach(callPendingCbs);
  10129. prevChildren.forEach(recordPosition);
  10130. const movedChildren = prevChildren.filter(applyTranslation);
  10131. // force reflow to put everything in position
  10132. forceReflow();
  10133. movedChildren.forEach(c => {
  10134. const el = c.el;
  10135. const style = el.style;
  10136. addTransitionClass(el, moveClass);
  10137. style.transform = style.webkitTransform = style.transitionDuration = '';
  10138. const cb = (el._moveCb = (e) => {
  10139. if (e && e.target !== el) {
  10140. return;
  10141. }
  10142. if (!e || /transform$/.test(e.propertyName)) {
  10143. el.removeEventListener('transitionend', cb);
  10144. el._moveCb = null;
  10145. removeTransitionClass(el, moveClass);
  10146. }
  10147. });
  10148. el.addEventListener('transitionend', cb);
  10149. });
  10150. });
  10151. return () => {
  10152. const rawProps = toRaw(props);
  10153. const cssTransitionProps = resolveTransitionProps(rawProps);
  10154. let tag = rawProps.tag || Fragment;
  10155. prevChildren = children;
  10156. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10157. for (let i = 0; i < children.length; i++) {
  10158. const child = children[i];
  10159. if (child.key != null) {
  10160. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10161. }
  10162. else {
  10163. warn$1(`<TransitionGroup> children must be keyed.`);
  10164. }
  10165. }
  10166. if (prevChildren) {
  10167. for (let i = 0; i < prevChildren.length; i++) {
  10168. const child = prevChildren[i];
  10169. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10170. positionMap.set(child, child.el.getBoundingClientRect());
  10171. }
  10172. }
  10173. return createVNode(tag, null, children);
  10174. };
  10175. }
  10176. };
  10177. const TransitionGroup = TransitionGroupImpl;
  10178. function callPendingCbs(c) {
  10179. const el = c.el;
  10180. if (el._moveCb) {
  10181. el._moveCb();
  10182. }
  10183. if (el._enterCb) {
  10184. el._enterCb();
  10185. }
  10186. }
  10187. function recordPosition(c) {
  10188. newPositionMap.set(c, c.el.getBoundingClientRect());
  10189. }
  10190. function applyTranslation(c) {
  10191. const oldPos = positionMap.get(c);
  10192. const newPos = newPositionMap.get(c);
  10193. const dx = oldPos.left - newPos.left;
  10194. const dy = oldPos.top - newPos.top;
  10195. if (dx || dy) {
  10196. const s = c.el.style;
  10197. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10198. s.transitionDuration = '0s';
  10199. return c;
  10200. }
  10201. }
  10202. function hasCSSTransform(el, root, moveClass) {
  10203. // Detect whether an element with the move class applied has
  10204. // CSS transitions. Since the element may be inside an entering
  10205. // transition at this very moment, we make a clone of it and remove
  10206. // all other transition classes applied to ensure only the move class
  10207. // is applied.
  10208. const clone = el.cloneNode();
  10209. if (el._vtc) {
  10210. el._vtc.forEach(cls => {
  10211. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10212. });
  10213. }
  10214. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10215. clone.style.display = 'none';
  10216. const container = (root.nodeType === 1 ? root : root.parentNode);
  10217. container.appendChild(clone);
  10218. const { hasTransform } = getTransitionInfo(clone);
  10219. container.removeChild(clone);
  10220. return hasTransform;
  10221. }
  10222. const getModelAssigner = (vnode) => {
  10223. const fn = vnode.props['onUpdate:modelValue'];
  10224. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10225. };
  10226. function onCompositionStart(e) {
  10227. e.target.composing = true;
  10228. }
  10229. function onCompositionEnd(e) {
  10230. const target = e.target;
  10231. if (target.composing) {
  10232. target.composing = false;
  10233. trigger$1(target, 'input');
  10234. }
  10235. }
  10236. function trigger$1(el, type) {
  10237. const e = document.createEvent('HTMLEvents');
  10238. e.initEvent(type, true, true);
  10239. el.dispatchEvent(e);
  10240. }
  10241. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10242. // be tree-shaken in case v-model is never used.
  10243. const vModelText = {
  10244. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10245. el._assign = getModelAssigner(vnode);
  10246. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10247. addEventListener(el, lazy ? 'change' : 'input', e => {
  10248. if (e.target.composing)
  10249. return;
  10250. let domValue = el.value;
  10251. if (trim) {
  10252. domValue = domValue.trim();
  10253. }
  10254. else if (castToNumber) {
  10255. domValue = toNumber(domValue);
  10256. }
  10257. el._assign(domValue);
  10258. });
  10259. if (trim) {
  10260. addEventListener(el, 'change', () => {
  10261. el.value = el.value.trim();
  10262. });
  10263. }
  10264. if (!lazy) {
  10265. addEventListener(el, 'compositionstart', onCompositionStart);
  10266. addEventListener(el, 'compositionend', onCompositionEnd);
  10267. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10268. // switching focus before confirming composition choice
  10269. // this also fixes the issue where some browsers e.g. iOS Chrome
  10270. // fires "change" instead of "input" on autocomplete.
  10271. addEventListener(el, 'change', onCompositionEnd);
  10272. }
  10273. },
  10274. // set value on mounted so it's after min/max for type="range"
  10275. mounted(el, { value }) {
  10276. el.value = value == null ? '' : value;
  10277. },
  10278. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10279. el._assign = getModelAssigner(vnode);
  10280. // avoid clearing unresolved text. #2302
  10281. if (el.composing)
  10282. return;
  10283. if (document.activeElement === el) {
  10284. if (lazy) {
  10285. return;
  10286. }
  10287. if (trim && el.value.trim() === value) {
  10288. return;
  10289. }
  10290. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10291. return;
  10292. }
  10293. }
  10294. const newValue = value == null ? '' : value;
  10295. if (el.value !== newValue) {
  10296. el.value = newValue;
  10297. }
  10298. }
  10299. };
  10300. const vModelCheckbox = {
  10301. // #4096 array checkboxes need to be deep traversed
  10302. deep: true,
  10303. created(el, _, vnode) {
  10304. el._assign = getModelAssigner(vnode);
  10305. addEventListener(el, 'change', () => {
  10306. const modelValue = el._modelValue;
  10307. const elementValue = getValue(el);
  10308. const checked = el.checked;
  10309. const assign = el._assign;
  10310. if (isArray(modelValue)) {
  10311. const index = looseIndexOf(modelValue, elementValue);
  10312. const found = index !== -1;
  10313. if (checked && !found) {
  10314. assign(modelValue.concat(elementValue));
  10315. }
  10316. else if (!checked && found) {
  10317. const filtered = [...modelValue];
  10318. filtered.splice(index, 1);
  10319. assign(filtered);
  10320. }
  10321. }
  10322. else if (isSet(modelValue)) {
  10323. const cloned = new Set(modelValue);
  10324. if (checked) {
  10325. cloned.add(elementValue);
  10326. }
  10327. else {
  10328. cloned.delete(elementValue);
  10329. }
  10330. assign(cloned);
  10331. }
  10332. else {
  10333. assign(getCheckboxValue(el, checked));
  10334. }
  10335. });
  10336. },
  10337. // set initial checked on mount to wait for true-value/false-value
  10338. mounted: setChecked,
  10339. beforeUpdate(el, binding, vnode) {
  10340. el._assign = getModelAssigner(vnode);
  10341. setChecked(el, binding, vnode);
  10342. }
  10343. };
  10344. function setChecked(el, { value, oldValue }, vnode) {
  10345. el._modelValue = value;
  10346. if (isArray(value)) {
  10347. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10348. }
  10349. else if (isSet(value)) {
  10350. el.checked = value.has(vnode.props.value);
  10351. }
  10352. else if (value !== oldValue) {
  10353. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10354. }
  10355. }
  10356. const vModelRadio = {
  10357. created(el, { value }, vnode) {
  10358. el.checked = looseEqual(value, vnode.props.value);
  10359. el._assign = getModelAssigner(vnode);
  10360. addEventListener(el, 'change', () => {
  10361. el._assign(getValue(el));
  10362. });
  10363. },
  10364. beforeUpdate(el, { value, oldValue }, vnode) {
  10365. el._assign = getModelAssigner(vnode);
  10366. if (value !== oldValue) {
  10367. el.checked = looseEqual(value, vnode.props.value);
  10368. }
  10369. }
  10370. };
  10371. const vModelSelect = {
  10372. // <select multiple> value need to be deep traversed
  10373. deep: true,
  10374. created(el, { value, modifiers: { number } }, vnode) {
  10375. const isSetModel = isSet(value);
  10376. addEventListener(el, 'change', () => {
  10377. const selectedVal = Array.prototype.filter
  10378. .call(el.options, (o) => o.selected)
  10379. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10380. el._assign(el.multiple
  10381. ? isSetModel
  10382. ? new Set(selectedVal)
  10383. : selectedVal
  10384. : selectedVal[0]);
  10385. });
  10386. el._assign = getModelAssigner(vnode);
  10387. },
  10388. // set value in mounted & updated because <select> relies on its children
  10389. // <option>s.
  10390. mounted(el, { value }) {
  10391. setSelected(el, value);
  10392. },
  10393. beforeUpdate(el, _binding, vnode) {
  10394. el._assign = getModelAssigner(vnode);
  10395. },
  10396. updated(el, { value }) {
  10397. setSelected(el, value);
  10398. }
  10399. };
  10400. function setSelected(el, value) {
  10401. const isMultiple = el.multiple;
  10402. if (isMultiple && !isArray(value) && !isSet(value)) {
  10403. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10404. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10405. return;
  10406. }
  10407. for (let i = 0, l = el.options.length; i < l; i++) {
  10408. const option = el.options[i];
  10409. const optionValue = getValue(option);
  10410. if (isMultiple) {
  10411. if (isArray(value)) {
  10412. option.selected = looseIndexOf(value, optionValue) > -1;
  10413. }
  10414. else {
  10415. option.selected = value.has(optionValue);
  10416. }
  10417. }
  10418. else {
  10419. if (looseEqual(getValue(option), value)) {
  10420. if (el.selectedIndex !== i)
  10421. el.selectedIndex = i;
  10422. return;
  10423. }
  10424. }
  10425. }
  10426. if (!isMultiple && el.selectedIndex !== -1) {
  10427. el.selectedIndex = -1;
  10428. }
  10429. }
  10430. // retrieve raw value set via :value bindings
  10431. function getValue(el) {
  10432. return '_value' in el ? el._value : el.value;
  10433. }
  10434. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10435. function getCheckboxValue(el, checked) {
  10436. const key = checked ? '_trueValue' : '_falseValue';
  10437. return key in el ? el[key] : checked;
  10438. }
  10439. const vModelDynamic = {
  10440. created(el, binding, vnode) {
  10441. callModelHook(el, binding, vnode, null, 'created');
  10442. },
  10443. mounted(el, binding, vnode) {
  10444. callModelHook(el, binding, vnode, null, 'mounted');
  10445. },
  10446. beforeUpdate(el, binding, vnode, prevVNode) {
  10447. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10448. },
  10449. updated(el, binding, vnode, prevVNode) {
  10450. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10451. }
  10452. };
  10453. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10454. let modelToUse;
  10455. switch (el.tagName) {
  10456. case 'SELECT':
  10457. modelToUse = vModelSelect;
  10458. break;
  10459. case 'TEXTAREA':
  10460. modelToUse = vModelText;
  10461. break;
  10462. default:
  10463. switch (vnode.props && vnode.props.type) {
  10464. case 'checkbox':
  10465. modelToUse = vModelCheckbox;
  10466. break;
  10467. case 'radio':
  10468. modelToUse = vModelRadio;
  10469. break;
  10470. default:
  10471. modelToUse = vModelText;
  10472. }
  10473. }
  10474. const fn = modelToUse[hook];
  10475. fn && fn(el, binding, vnode, prevVNode);
  10476. }
  10477. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10478. const modifierGuards = {
  10479. stop: e => e.stopPropagation(),
  10480. prevent: e => e.preventDefault(),
  10481. self: e => e.target !== e.currentTarget,
  10482. ctrl: e => !e.ctrlKey,
  10483. shift: e => !e.shiftKey,
  10484. alt: e => !e.altKey,
  10485. meta: e => !e.metaKey,
  10486. left: e => 'button' in e && e.button !== 0,
  10487. middle: e => 'button' in e && e.button !== 1,
  10488. right: e => 'button' in e && e.button !== 2,
  10489. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10490. };
  10491. /**
  10492. * @private
  10493. */
  10494. const withModifiers = (fn, modifiers) => {
  10495. return (event, ...args) => {
  10496. for (let i = 0; i < modifiers.length; i++) {
  10497. const guard = modifierGuards[modifiers[i]];
  10498. if (guard && guard(event, modifiers))
  10499. return;
  10500. }
  10501. return fn(event, ...args);
  10502. };
  10503. };
  10504. // Kept for 2.x compat.
  10505. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10506. const keyNames = {
  10507. esc: 'escape',
  10508. space: ' ',
  10509. up: 'arrow-up',
  10510. left: 'arrow-left',
  10511. right: 'arrow-right',
  10512. down: 'arrow-down',
  10513. delete: 'backspace'
  10514. };
  10515. /**
  10516. * @private
  10517. */
  10518. const withKeys = (fn, modifiers) => {
  10519. return (event) => {
  10520. if (!('key' in event)) {
  10521. return;
  10522. }
  10523. const eventKey = hyphenate(event.key);
  10524. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10525. return fn(event);
  10526. }
  10527. };
  10528. };
  10529. const vShow = {
  10530. beforeMount(el, { value }, { transition }) {
  10531. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10532. if (transition && value) {
  10533. transition.beforeEnter(el);
  10534. }
  10535. else {
  10536. setDisplay(el, value);
  10537. }
  10538. },
  10539. mounted(el, { value }, { transition }) {
  10540. if (transition && value) {
  10541. transition.enter(el);
  10542. }
  10543. },
  10544. updated(el, { value, oldValue }, { transition }) {
  10545. if (!value === !oldValue)
  10546. return;
  10547. if (transition) {
  10548. if (value) {
  10549. transition.beforeEnter(el);
  10550. setDisplay(el, true);
  10551. transition.enter(el);
  10552. }
  10553. else {
  10554. transition.leave(el, () => {
  10555. setDisplay(el, false);
  10556. });
  10557. }
  10558. }
  10559. else {
  10560. setDisplay(el, value);
  10561. }
  10562. },
  10563. beforeUnmount(el, { value }) {
  10564. setDisplay(el, value);
  10565. }
  10566. };
  10567. function setDisplay(el, value) {
  10568. el.style.display = value ? el._vod : 'none';
  10569. }
  10570. const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
  10571. // lazy create the renderer - this makes core renderer logic tree-shakable
  10572. // in case the user only imports reactivity utilities from Vue.
  10573. let renderer;
  10574. let enabledHydration = false;
  10575. function ensureRenderer() {
  10576. return (renderer ||
  10577. (renderer = createRenderer(rendererOptions)));
  10578. }
  10579. function ensureHydrationRenderer() {
  10580. renderer = enabledHydration
  10581. ? renderer
  10582. : createHydrationRenderer(rendererOptions);
  10583. enabledHydration = true;
  10584. return renderer;
  10585. }
  10586. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10587. const render = ((...args) => {
  10588. ensureRenderer().render(...args);
  10589. });
  10590. const hydrate = ((...args) => {
  10591. ensureHydrationRenderer().hydrate(...args);
  10592. });
  10593. const createApp = ((...args) => {
  10594. const app = ensureRenderer().createApp(...args);
  10595. {
  10596. injectNativeTagCheck(app);
  10597. injectCompilerOptionsCheck(app);
  10598. }
  10599. const { mount } = app;
  10600. app.mount = (containerOrSelector) => {
  10601. const container = normalizeContainer(containerOrSelector);
  10602. if (!container)
  10603. return;
  10604. const component = app._component;
  10605. if (!isFunction(component) && !component.render && !component.template) {
  10606. // __UNSAFE__
  10607. // Reason: potential execution of JS expressions in in-DOM template.
  10608. // The user must make sure the in-DOM template is trusted. If it's
  10609. // rendered by the server, the template should not contain any user data.
  10610. component.template = container.innerHTML;
  10611. }
  10612. // clear content before mounting
  10613. container.innerHTML = '';
  10614. const proxy = mount(container, false, container instanceof SVGElement);
  10615. if (container instanceof Element) {
  10616. container.removeAttribute('v-cloak');
  10617. container.setAttribute('data-v-app', '');
  10618. }
  10619. return proxy;
  10620. };
  10621. return app;
  10622. });
  10623. const createSSRApp = ((...args) => {
  10624. const app = ensureHydrationRenderer().createApp(...args);
  10625. {
  10626. injectNativeTagCheck(app);
  10627. injectCompilerOptionsCheck(app);
  10628. }
  10629. const { mount } = app;
  10630. app.mount = (containerOrSelector) => {
  10631. const container = normalizeContainer(containerOrSelector);
  10632. if (container) {
  10633. return mount(container, true, container instanceof SVGElement);
  10634. }
  10635. };
  10636. return app;
  10637. });
  10638. function injectNativeTagCheck(app) {
  10639. // Inject `isNativeTag`
  10640. // this is used for component name validation (dev only)
  10641. Object.defineProperty(app.config, 'isNativeTag', {
  10642. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10643. writable: false
  10644. });
  10645. }
  10646. // dev only
  10647. function injectCompilerOptionsCheck(app) {
  10648. if (isRuntimeOnly()) {
  10649. const isCustomElement = app.config.isCustomElement;
  10650. Object.defineProperty(app.config, 'isCustomElement', {
  10651. get() {
  10652. return isCustomElement;
  10653. },
  10654. set() {
  10655. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10656. `\`compilerOptions.isCustomElement\` instead.`);
  10657. }
  10658. });
  10659. const compilerOptions = app.config.compilerOptions;
  10660. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10661. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10662. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10663. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10664. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10665. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10666. `- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom`;
  10667. Object.defineProperty(app.config, 'compilerOptions', {
  10668. get() {
  10669. warn$1(msg);
  10670. return compilerOptions;
  10671. },
  10672. set() {
  10673. warn$1(msg);
  10674. }
  10675. });
  10676. }
  10677. }
  10678. function normalizeContainer(container) {
  10679. if (isString(container)) {
  10680. const res = document.querySelector(container);
  10681. if (!res) {
  10682. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10683. }
  10684. return res;
  10685. }
  10686. if (window.ShadowRoot &&
  10687. container instanceof window.ShadowRoot &&
  10688. container.mode === 'closed') {
  10689. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10690. }
  10691. return container;
  10692. }
  10693. /**
  10694. * @internal
  10695. */
  10696. const initDirectivesForSSR = NOOP;
  10697. function initDev() {
  10698. {
  10699. {
  10700. console.info(`You are running a development build of Vue.\n` +
  10701. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10702. }
  10703. initCustomFormatter();
  10704. }
  10705. }
  10706. // This entry exports the runtime only, and is built as
  10707. {
  10708. initDev();
  10709. }
  10710. const compile$1 = () => {
  10711. {
  10712. warn$1(`Runtime compilation is not supported in this build of Vue.` +
  10713. (` Use "vue.esm-browser.js" instead.`
  10714. ) /* should not happen */);
  10715. }
  10716. };
  10717. export { BaseTransition, Comment, EffectScope, Fragment, KeepAlive, ReactiveEffect, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VueElement, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compatUtils, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineCustomElement, defineEmits, defineExpose, defineProps, defineSSRCustomElement, devtools, effect, effectScope, getCurrentInstance, getCurrentScope, getTransitionRawChildren, guardReactiveProps, h, handleError, hydrate, initCustomFormatter, initDirectivesForSSR, inject, isMemoSame, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isShallow, isVNode, markRaw, mergeDefaults, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, stop, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withKeys, withMemo, withModifiers, withScopeId };