server-renderer.esm-browser.js 288 KB

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