server-renderer.esm-browser.js 293 KB

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