runtime-dom.esm-browser.js 327 KB

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