vue.runtime.esm-browser.js 394 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665
  1. /**
  2. * Make a map and return a function for checking if a key
  3. * is in that map.
  4. * IMPORTANT: all calls of this function must be prefixed with
  5. * \/\*#\_\_PURE\_\_\*\/
  6. * So that rollup can tree-shake them if necessary.
  7. */
  8. function makeMap(str, expectsLowerCase) {
  9. const map = Object.create(null);
  10. const list = str.split(',');
  11. for (let i = 0; i < list.length; i++) {
  12. map[list[i]] = true;
  13. }
  14. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  15. }
  16. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  17. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  18. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  19. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  20. /**
  21. * On the client we only need to offer special cases for boolean attributes that
  22. * have different names from their corresponding dom properties:
  23. * - itemscope -> N/A
  24. * - allowfullscreen -> allowFullscreen
  25. * - formnovalidate -> formNoValidate
  26. * - ismap -> isMap
  27. * - nomodule -> noModule
  28. * - novalidate -> noValidate
  29. * - readonly -> readOnly
  30. */
  31. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  32. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  33. /**
  34. * Boolean attributes should be included if the value is truthy or ''.
  35. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  36. */
  37. function includeBooleanAttr(value) {
  38. return !!value || value === '';
  39. }
  40. function normalizeStyle(value) {
  41. if (isArray(value)) {
  42. const res = {};
  43. for (let i = 0; i < value.length; i++) {
  44. const item = value[i];
  45. const normalized = isString(item)
  46. ? parseStringStyle(item)
  47. : normalizeStyle(item);
  48. if (normalized) {
  49. for (const key in normalized) {
  50. res[key] = normalized[key];
  51. }
  52. }
  53. }
  54. return res;
  55. }
  56. else if (isString(value)) {
  57. return value;
  58. }
  59. else if (isObject(value)) {
  60. return value;
  61. }
  62. }
  63. const listDelimiterRE = /;(?![^(]*\))/g;
  64. const propertyDelimiterRE = /:(.+)/;
  65. function parseStringStyle(cssText) {
  66. const ret = {};
  67. cssText.split(listDelimiterRE).forEach(item => {
  68. if (item) {
  69. const tmp = item.split(propertyDelimiterRE);
  70. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  71. }
  72. });
  73. return ret;
  74. }
  75. function normalizeClass(value) {
  76. let res = '';
  77. if (isString(value)) {
  78. res = value;
  79. }
  80. else if (isArray(value)) {
  81. for (let i = 0; i < value.length; i++) {
  82. const normalized = normalizeClass(value[i]);
  83. if (normalized) {
  84. res += normalized + ' ';
  85. }
  86. }
  87. }
  88. else if (isObject(value)) {
  89. for (const name in value) {
  90. if (value[name]) {
  91. res += name + ' ';
  92. }
  93. }
  94. }
  95. return res.trim();
  96. }
  97. function normalizeProps(props) {
  98. if (!props)
  99. return null;
  100. let { class: klass, style } = props;
  101. if (klass && !isString(klass)) {
  102. props.class = normalizeClass(klass);
  103. }
  104. if (style) {
  105. props.style = normalizeStyle(style);
  106. }
  107. return props;
  108. }
  109. // These tag configs are shared between compiler-dom and runtime-dom, so they
  110. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  111. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  112. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  113. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  114. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  115. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  116. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  117. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  118. 'option,output,progress,select,textarea,details,dialog,menu,' +
  119. 'summary,template,blockquote,iframe,tfoot';
  120. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  121. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  122. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  123. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  124. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  125. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  126. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  127. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  128. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  129. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  130. 'text,textPath,title,tspan,unknown,use,view';
  131. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  132. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  133. function looseCompareArrays(a, b) {
  134. if (a.length !== b.length)
  135. return false;
  136. let equal = true;
  137. for (let i = 0; equal && i < a.length; i++) {
  138. equal = looseEqual(a[i], b[i]);
  139. }
  140. return equal;
  141. }
  142. function looseEqual(a, b) {
  143. if (a === b)
  144. return true;
  145. let aValidType = isDate(a);
  146. let bValidType = isDate(b);
  147. if (aValidType || bValidType) {
  148. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  149. }
  150. aValidType = isArray(a);
  151. bValidType = isArray(b);
  152. if (aValidType || bValidType) {
  153. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  154. }
  155. aValidType = isObject(a);
  156. bValidType = isObject(b);
  157. if (aValidType || bValidType) {
  158. /* istanbul ignore if: this if will probably never be called */
  159. if (!aValidType || !bValidType) {
  160. return false;
  161. }
  162. const aKeysCount = Object.keys(a).length;
  163. const bKeysCount = Object.keys(b).length;
  164. if (aKeysCount !== bKeysCount) {
  165. return false;
  166. }
  167. for (const key in a) {
  168. const aHasKey = a.hasOwnProperty(key);
  169. const bHasKey = b.hasOwnProperty(key);
  170. if ((aHasKey && !bHasKey) ||
  171. (!aHasKey && bHasKey) ||
  172. !looseEqual(a[key], b[key])) {
  173. return false;
  174. }
  175. }
  176. }
  177. return String(a) === String(b);
  178. }
  179. function looseIndexOf(arr, val) {
  180. return arr.findIndex(item => looseEqual(item, val));
  181. }
  182. /**
  183. * For converting {{ interpolation }} values to displayed strings.
  184. * @private
  185. */
  186. const toDisplayString = (val) => {
  187. return val == null
  188. ? ''
  189. : isArray(val) ||
  190. (isObject(val) &&
  191. (val.toString === objectToString || !isFunction(val.toString)))
  192. ? JSON.stringify(val, replacer, 2)
  193. : String(val);
  194. };
  195. const replacer = (_key, val) => {
  196. // can't use isRef here since @vue/shared has no deps
  197. if (val && val.__v_isRef) {
  198. return replacer(_key, val.value);
  199. }
  200. else if (isMap(val)) {
  201. return {
  202. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  203. entries[`${key} =>`] = val;
  204. return entries;
  205. }, {})
  206. };
  207. }
  208. else if (isSet(val)) {
  209. return {
  210. [`Set(${val.size})`]: [...val.values()]
  211. };
  212. }
  213. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  214. return String(val);
  215. }
  216. return val;
  217. };
  218. const EMPTY_OBJ = Object.freeze({})
  219. ;
  220. const EMPTY_ARR = Object.freeze([]) ;
  221. const NOOP = () => { };
  222. /**
  223. * Always return false.
  224. */
  225. const NO = () => false;
  226. const onRE = /^on[^a-z]/;
  227. const isOn = (key) => onRE.test(key);
  228. const isModelListener = (key) => key.startsWith('onUpdate:');
  229. const extend = Object.assign;
  230. const remove = (arr, el) => {
  231. const i = arr.indexOf(el);
  232. if (i > -1) {
  233. arr.splice(i, 1);
  234. }
  235. };
  236. const hasOwnProperty = Object.prototype.hasOwnProperty;
  237. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  238. const isArray = Array.isArray;
  239. const isMap = (val) => toTypeString(val) === '[object Map]';
  240. const isSet = (val) => toTypeString(val) === '[object Set]';
  241. const isDate = (val) => val instanceof Date;
  242. const isFunction = (val) => typeof val === 'function';
  243. const isString = (val) => typeof val === 'string';
  244. const isSymbol = (val) => typeof val === 'symbol';
  245. const isObject = (val) => val !== null && typeof val === 'object';
  246. const isPromise = (val) => {
  247. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  248. };
  249. const objectToString = Object.prototype.toString;
  250. const toTypeString = (value) => objectToString.call(value);
  251. const toRawType = (value) => {
  252. // extract "RawType" from strings like "[object RawType]"
  253. return toTypeString(value).slice(8, -1);
  254. };
  255. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  256. const isIntegerKey = (key) => isString(key) &&
  257. key !== 'NaN' &&
  258. key[0] !== '-' &&
  259. '' + parseInt(key, 10) === key;
  260. const isReservedProp = /*#__PURE__*/ makeMap(
  261. // the leading comma is intentional so empty string "" is also included
  262. ',key,ref,ref_for,ref_key,' +
  263. 'onVnodeBeforeMount,onVnodeMounted,' +
  264. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  265. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  266. const cacheStringFunction = (fn) => {
  267. const cache = Object.create(null);
  268. return ((str) => {
  269. const hit = cache[str];
  270. return hit || (cache[str] = fn(str));
  271. });
  272. };
  273. const camelizeRE = /-(\w)/g;
  274. /**
  275. * @private
  276. */
  277. const camelize = cacheStringFunction((str) => {
  278. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  279. });
  280. const hyphenateRE = /\B([A-Z])/g;
  281. /**
  282. * @private
  283. */
  284. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  285. /**
  286. * @private
  287. */
  288. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  289. /**
  290. * @private
  291. */
  292. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  293. // compare whether a value has changed, accounting for NaN.
  294. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  295. const invokeArrayFns = (fns, arg) => {
  296. for (let i = 0; i < fns.length; i++) {
  297. fns[i](arg);
  298. }
  299. };
  300. const def = (obj, key, value) => {
  301. Object.defineProperty(obj, key, {
  302. configurable: true,
  303. enumerable: false,
  304. value
  305. });
  306. };
  307. const toNumber = (val) => {
  308. const n = parseFloat(val);
  309. return isNaN(n) ? val : n;
  310. };
  311. let _globalThis;
  312. const getGlobalThis = () => {
  313. return (_globalThis ||
  314. (_globalThis =
  315. typeof globalThis !== 'undefined'
  316. ? globalThis
  317. : typeof self !== 'undefined'
  318. ? self
  319. : typeof window !== 'undefined'
  320. ? window
  321. : typeof global !== 'undefined'
  322. ? global
  323. : {}));
  324. };
  325. function warn(msg, ...args) {
  326. console.warn(`[Vue warn] ${msg}`, ...args);
  327. }
  328. let activeEffectScope;
  329. const effectScopeStack = [];
  330. class EffectScope {
  331. constructor(detached = false) {
  332. this.active = true;
  333. this.effects = [];
  334. this.cleanups = [];
  335. if (!detached && activeEffectScope) {
  336. this.parent = activeEffectScope;
  337. this.index =
  338. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  339. }
  340. }
  341. run(fn) {
  342. if (this.active) {
  343. try {
  344. this.on();
  345. return fn();
  346. }
  347. finally {
  348. this.off();
  349. }
  350. }
  351. else {
  352. warn(`cannot run an inactive effect scope.`);
  353. }
  354. }
  355. on() {
  356. if (this.active) {
  357. effectScopeStack.push(this);
  358. activeEffectScope = this;
  359. }
  360. }
  361. off() {
  362. if (this.active) {
  363. effectScopeStack.pop();
  364. activeEffectScope = effectScopeStack[effectScopeStack.length - 1];
  365. }
  366. }
  367. stop(fromParent) {
  368. if (this.active) {
  369. this.effects.forEach(e => e.stop());
  370. this.cleanups.forEach(cleanup => cleanup());
  371. if (this.scopes) {
  372. this.scopes.forEach(e => e.stop(true));
  373. }
  374. // nested scope, dereference from parent to avoid memory leaks
  375. if (this.parent && !fromParent) {
  376. // optimized O(1) removal
  377. const last = this.parent.scopes.pop();
  378. if (last && last !== this) {
  379. this.parent.scopes[this.index] = last;
  380. last.index = this.index;
  381. }
  382. }
  383. this.active = false;
  384. }
  385. }
  386. }
  387. function effectScope(detached) {
  388. return new EffectScope(detached);
  389. }
  390. function recordEffectScope(effect, scope) {
  391. scope = scope || activeEffectScope;
  392. if (scope && scope.active) {
  393. scope.effects.push(effect);
  394. }
  395. }
  396. function getCurrentScope() {
  397. return activeEffectScope;
  398. }
  399. function onScopeDispose(fn) {
  400. if (activeEffectScope) {
  401. activeEffectScope.cleanups.push(fn);
  402. }
  403. else {
  404. warn(`onScopeDispose() is called when there is no active effect scope` +
  405. ` to be associated with.`);
  406. }
  407. }
  408. const createDep = (effects) => {
  409. const dep = new Set(effects);
  410. dep.w = 0;
  411. dep.n = 0;
  412. return dep;
  413. };
  414. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  415. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  416. const initDepMarkers = ({ deps }) => {
  417. if (deps.length) {
  418. for (let i = 0; i < deps.length; i++) {
  419. deps[i].w |= trackOpBit; // set was tracked
  420. }
  421. }
  422. };
  423. const finalizeDepMarkers = (effect) => {
  424. const { deps } = effect;
  425. if (deps.length) {
  426. let ptr = 0;
  427. for (let i = 0; i < deps.length; i++) {
  428. const dep = deps[i];
  429. if (wasTracked(dep) && !newTracked(dep)) {
  430. dep.delete(effect);
  431. }
  432. else {
  433. deps[ptr++] = dep;
  434. }
  435. // clear bits
  436. dep.w &= ~trackOpBit;
  437. dep.n &= ~trackOpBit;
  438. }
  439. deps.length = ptr;
  440. }
  441. };
  442. const targetMap = new WeakMap();
  443. // The number of effects currently being tracked recursively.
  444. let effectTrackDepth = 0;
  445. let trackOpBit = 1;
  446. /**
  447. * The bitwise track markers support at most 30 levels of recursion.
  448. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  449. * When recursion depth is greater, fall back to using a full cleanup.
  450. */
  451. const maxMarkerBits = 30;
  452. const effectStack = [];
  453. let activeEffect;
  454. const ITERATE_KEY = Symbol('iterate' );
  455. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  456. class ReactiveEffect {
  457. constructor(fn, scheduler = null, scope) {
  458. this.fn = fn;
  459. this.scheduler = scheduler;
  460. this.active = true;
  461. this.deps = [];
  462. recordEffectScope(this, scope);
  463. }
  464. run() {
  465. if (!this.active) {
  466. return this.fn();
  467. }
  468. if (!effectStack.includes(this)) {
  469. try {
  470. effectStack.push((activeEffect = this));
  471. enableTracking();
  472. trackOpBit = 1 << ++effectTrackDepth;
  473. if (effectTrackDepth <= maxMarkerBits) {
  474. initDepMarkers(this);
  475. }
  476. else {
  477. cleanupEffect(this);
  478. }
  479. return this.fn();
  480. }
  481. finally {
  482. if (effectTrackDepth <= maxMarkerBits) {
  483. finalizeDepMarkers(this);
  484. }
  485. trackOpBit = 1 << --effectTrackDepth;
  486. resetTracking();
  487. effectStack.pop();
  488. const n = effectStack.length;
  489. activeEffect = n > 0 ? effectStack[n - 1] : undefined;
  490. }
  491. }
  492. }
  493. stop() {
  494. if (this.active) {
  495. cleanupEffect(this);
  496. if (this.onStop) {
  497. this.onStop();
  498. }
  499. this.active = false;
  500. }
  501. }
  502. }
  503. function cleanupEffect(effect) {
  504. const { deps } = effect;
  505. if (deps.length) {
  506. for (let i = 0; i < deps.length; i++) {
  507. deps[i].delete(effect);
  508. }
  509. deps.length = 0;
  510. }
  511. }
  512. function effect(fn, options) {
  513. if (fn.effect) {
  514. fn = fn.effect.fn;
  515. }
  516. const _effect = new ReactiveEffect(fn);
  517. if (options) {
  518. extend(_effect, options);
  519. if (options.scope)
  520. recordEffectScope(_effect, options.scope);
  521. }
  522. if (!options || !options.lazy) {
  523. _effect.run();
  524. }
  525. const runner = _effect.run.bind(_effect);
  526. runner.effect = _effect;
  527. return runner;
  528. }
  529. function stop(runner) {
  530. runner.effect.stop();
  531. }
  532. let shouldTrack = true;
  533. const trackStack = [];
  534. function pauseTracking() {
  535. trackStack.push(shouldTrack);
  536. shouldTrack = false;
  537. }
  538. function enableTracking() {
  539. trackStack.push(shouldTrack);
  540. shouldTrack = true;
  541. }
  542. function resetTracking() {
  543. const last = trackStack.pop();
  544. shouldTrack = last === undefined ? true : last;
  545. }
  546. function track(target, type, key) {
  547. if (!isTracking()) {
  548. return;
  549. }
  550. let depsMap = targetMap.get(target);
  551. if (!depsMap) {
  552. targetMap.set(target, (depsMap = new Map()));
  553. }
  554. let dep = depsMap.get(key);
  555. if (!dep) {
  556. depsMap.set(key, (dep = createDep()));
  557. }
  558. const eventInfo = { effect: activeEffect, target, type, key }
  559. ;
  560. trackEffects(dep, eventInfo);
  561. }
  562. function isTracking() {
  563. return shouldTrack && activeEffect !== undefined;
  564. }
  565. function trackEffects(dep, debuggerEventExtraInfo) {
  566. let shouldTrack = false;
  567. if (effectTrackDepth <= maxMarkerBits) {
  568. if (!newTracked(dep)) {
  569. dep.n |= trackOpBit; // set newly tracked
  570. shouldTrack = !wasTracked(dep);
  571. }
  572. }
  573. else {
  574. // Full cleanup mode.
  575. shouldTrack = !dep.has(activeEffect);
  576. }
  577. if (shouldTrack) {
  578. dep.add(activeEffect);
  579. activeEffect.deps.push(dep);
  580. if (activeEffect.onTrack) {
  581. activeEffect.onTrack(Object.assign({
  582. effect: activeEffect
  583. }, debuggerEventExtraInfo));
  584. }
  585. }
  586. }
  587. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  588. const depsMap = targetMap.get(target);
  589. if (!depsMap) {
  590. // never been tracked
  591. return;
  592. }
  593. let deps = [];
  594. if (type === "clear" /* CLEAR */) {
  595. // collection being cleared
  596. // trigger all effects for target
  597. deps = [...depsMap.values()];
  598. }
  599. else if (key === 'length' && isArray(target)) {
  600. depsMap.forEach((dep, key) => {
  601. if (key === 'length' || key >= newValue) {
  602. deps.push(dep);
  603. }
  604. });
  605. }
  606. else {
  607. // schedule runs for SET | ADD | DELETE
  608. if (key !== void 0) {
  609. deps.push(depsMap.get(key));
  610. }
  611. // also run for iteration key on ADD | DELETE | Map.SET
  612. switch (type) {
  613. case "add" /* ADD */:
  614. if (!isArray(target)) {
  615. deps.push(depsMap.get(ITERATE_KEY));
  616. if (isMap(target)) {
  617. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  618. }
  619. }
  620. else if (isIntegerKey(key)) {
  621. // new index added to array -> length changes
  622. deps.push(depsMap.get('length'));
  623. }
  624. break;
  625. case "delete" /* DELETE */:
  626. if (!isArray(target)) {
  627. deps.push(depsMap.get(ITERATE_KEY));
  628. if (isMap(target)) {
  629. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  630. }
  631. }
  632. break;
  633. case "set" /* SET */:
  634. if (isMap(target)) {
  635. deps.push(depsMap.get(ITERATE_KEY));
  636. }
  637. break;
  638. }
  639. }
  640. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  641. ;
  642. if (deps.length === 1) {
  643. if (deps[0]) {
  644. {
  645. triggerEffects(deps[0], eventInfo);
  646. }
  647. }
  648. }
  649. else {
  650. const effects = [];
  651. for (const dep of deps) {
  652. if (dep) {
  653. effects.push(...dep);
  654. }
  655. }
  656. {
  657. triggerEffects(createDep(effects), eventInfo);
  658. }
  659. }
  660. }
  661. function triggerEffects(dep, debuggerEventExtraInfo) {
  662. // spread into array for stabilization
  663. for (const effect of isArray(dep) ? dep : [...dep]) {
  664. if (effect !== activeEffect || effect.allowRecurse) {
  665. if (effect.onTrigger) {
  666. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  667. }
  668. if (effect.scheduler) {
  669. effect.scheduler();
  670. }
  671. else {
  672. effect.run();
  673. }
  674. }
  675. }
  676. }
  677. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  678. const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
  679. .map(key => Symbol[key])
  680. .filter(isSymbol));
  681. const get = /*#__PURE__*/ createGetter();
  682. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  683. const readonlyGet = /*#__PURE__*/ createGetter(true);
  684. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  685. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  686. function createArrayInstrumentations() {
  687. const instrumentations = {};
  688. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  689. instrumentations[key] = function (...args) {
  690. const arr = toRaw(this);
  691. for (let i = 0, l = this.length; i < l; i++) {
  692. track(arr, "get" /* GET */, i + '');
  693. }
  694. // we run the method using the original args first (which may be reactive)
  695. const res = arr[key](...args);
  696. if (res === -1 || res === false) {
  697. // if that didn't work, run it again using raw values.
  698. return arr[key](...args.map(toRaw));
  699. }
  700. else {
  701. return res;
  702. }
  703. };
  704. });
  705. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  706. instrumentations[key] = function (...args) {
  707. pauseTracking();
  708. const res = toRaw(this)[key].apply(this, args);
  709. resetTracking();
  710. return res;
  711. };
  712. });
  713. return instrumentations;
  714. }
  715. function createGetter(isReadonly = false, shallow = false) {
  716. return function get(target, key, receiver) {
  717. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  718. return !isReadonly;
  719. }
  720. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  721. return isReadonly;
  722. }
  723. else if (key === "__v_raw" /* RAW */ &&
  724. receiver ===
  725. (isReadonly
  726. ? shallow
  727. ? shallowReadonlyMap
  728. : readonlyMap
  729. : shallow
  730. ? shallowReactiveMap
  731. : reactiveMap).get(target)) {
  732. return target;
  733. }
  734. const targetIsArray = isArray(target);
  735. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  736. return Reflect.get(arrayInstrumentations, key, receiver);
  737. }
  738. const res = Reflect.get(target, key, receiver);
  739. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  740. return res;
  741. }
  742. if (!isReadonly) {
  743. track(target, "get" /* GET */, key);
  744. }
  745. if (shallow) {
  746. return res;
  747. }
  748. if (isRef(res)) {
  749. // ref unwrapping - does not apply for Array + integer key.
  750. const shouldUnwrap = !targetIsArray || !isIntegerKey(key);
  751. return shouldUnwrap ? res.value : res;
  752. }
  753. if (isObject(res)) {
  754. // Convert returned value into a proxy as well. we do the isObject check
  755. // here to avoid invalid value warning. Also need to lazy access readonly
  756. // and reactive here to avoid circular dependency.
  757. return isReadonly ? readonly(res) : reactive(res);
  758. }
  759. return res;
  760. };
  761. }
  762. const set = /*#__PURE__*/ createSetter();
  763. const shallowSet = /*#__PURE__*/ createSetter(true);
  764. function createSetter(shallow = false) {
  765. return function set(target, key, value, receiver) {
  766. let oldValue = target[key];
  767. if (!shallow && !isReadonly(value)) {
  768. value = toRaw(value);
  769. oldValue = toRaw(oldValue);
  770. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  771. oldValue.value = value;
  772. return true;
  773. }
  774. }
  775. const hadKey = isArray(target) && isIntegerKey(key)
  776. ? Number(key) < target.length
  777. : hasOwn(target, key);
  778. const result = Reflect.set(target, key, value, receiver);
  779. // don't trigger if target is something up in the prototype chain of original
  780. if (target === toRaw(receiver)) {
  781. if (!hadKey) {
  782. trigger(target, "add" /* ADD */, key, value);
  783. }
  784. else if (hasChanged(value, oldValue)) {
  785. trigger(target, "set" /* SET */, key, value, oldValue);
  786. }
  787. }
  788. return result;
  789. };
  790. }
  791. function deleteProperty(target, key) {
  792. const hadKey = hasOwn(target, key);
  793. const oldValue = target[key];
  794. const result = Reflect.deleteProperty(target, key);
  795. if (result && hadKey) {
  796. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  797. }
  798. return result;
  799. }
  800. function has(target, key) {
  801. const result = Reflect.has(target, key);
  802. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  803. track(target, "has" /* HAS */, key);
  804. }
  805. return result;
  806. }
  807. function ownKeys(target) {
  808. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  809. return Reflect.ownKeys(target);
  810. }
  811. const mutableHandlers = {
  812. get,
  813. set,
  814. deleteProperty,
  815. has,
  816. ownKeys
  817. };
  818. const readonlyHandlers = {
  819. get: readonlyGet,
  820. set(target, key) {
  821. {
  822. console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  823. }
  824. return true;
  825. },
  826. deleteProperty(target, key) {
  827. {
  828. console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  829. }
  830. return true;
  831. }
  832. };
  833. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  834. get: shallowGet,
  835. set: shallowSet
  836. });
  837. // Props handlers are special in the sense that it should not unwrap top-level
  838. // refs (in order to allow refs to be explicitly passed down), but should
  839. // retain the reactivity of the normal readonly object.
  840. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  841. get: shallowReadonlyGet
  842. });
  843. const toShallow = (value) => value;
  844. const getProto = (v) => Reflect.getPrototypeOf(v);
  845. function get$1(target, key, isReadonly = false, isShallow = false) {
  846. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  847. // of the value
  848. target = target["__v_raw" /* RAW */];
  849. const rawTarget = toRaw(target);
  850. const rawKey = toRaw(key);
  851. if (key !== rawKey) {
  852. !isReadonly && track(rawTarget, "get" /* GET */, key);
  853. }
  854. !isReadonly && track(rawTarget, "get" /* GET */, rawKey);
  855. const { has } = getProto(rawTarget);
  856. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  857. if (has.call(rawTarget, key)) {
  858. return wrap(target.get(key));
  859. }
  860. else if (has.call(rawTarget, rawKey)) {
  861. return wrap(target.get(rawKey));
  862. }
  863. else if (target !== rawTarget) {
  864. // #3602 readonly(reactive(Map))
  865. // ensure that the nested reactive `Map` can do tracking for itself
  866. target.get(key);
  867. }
  868. }
  869. function has$1(key, isReadonly = false) {
  870. const target = this["__v_raw" /* RAW */];
  871. const rawTarget = toRaw(target);
  872. const rawKey = toRaw(key);
  873. if (key !== rawKey) {
  874. !isReadonly && track(rawTarget, "has" /* HAS */, key);
  875. }
  876. !isReadonly && track(rawTarget, "has" /* HAS */, rawKey);
  877. return key === rawKey
  878. ? target.has(key)
  879. : target.has(key) || target.has(rawKey);
  880. }
  881. function size(target, isReadonly = false) {
  882. target = target["__v_raw" /* RAW */];
  883. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  884. return Reflect.get(target, 'size', target);
  885. }
  886. function add(value) {
  887. value = toRaw(value);
  888. const target = toRaw(this);
  889. const proto = getProto(target);
  890. const hadKey = proto.has.call(target, value);
  891. if (!hadKey) {
  892. target.add(value);
  893. trigger(target, "add" /* ADD */, value, value);
  894. }
  895. return this;
  896. }
  897. function set$1(key, value) {
  898. value = toRaw(value);
  899. const target = toRaw(this);
  900. const { has, get } = getProto(target);
  901. let hadKey = has.call(target, key);
  902. if (!hadKey) {
  903. key = toRaw(key);
  904. hadKey = has.call(target, key);
  905. }
  906. else {
  907. checkIdentityKeys(target, has, key);
  908. }
  909. const oldValue = get.call(target, key);
  910. target.set(key, value);
  911. if (!hadKey) {
  912. trigger(target, "add" /* ADD */, key, value);
  913. }
  914. else if (hasChanged(value, oldValue)) {
  915. trigger(target, "set" /* SET */, key, value, oldValue);
  916. }
  917. return this;
  918. }
  919. function deleteEntry(key) {
  920. const target = toRaw(this);
  921. const { has, get } = getProto(target);
  922. let hadKey = has.call(target, key);
  923. if (!hadKey) {
  924. key = toRaw(key);
  925. hadKey = has.call(target, key);
  926. }
  927. else {
  928. checkIdentityKeys(target, has, key);
  929. }
  930. const oldValue = get ? get.call(target, key) : undefined;
  931. // forward the operation before queueing reactions
  932. const result = target.delete(key);
  933. if (hadKey) {
  934. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  935. }
  936. return result;
  937. }
  938. function clear() {
  939. const target = toRaw(this);
  940. const hadItems = target.size !== 0;
  941. const oldTarget = isMap(target)
  942. ? new Map(target)
  943. : new Set(target)
  944. ;
  945. // forward the operation before queueing reactions
  946. const result = target.clear();
  947. if (hadItems) {
  948. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  949. }
  950. return result;
  951. }
  952. function createForEach(isReadonly, isShallow) {
  953. return function forEach(callback, thisArg) {
  954. const observed = this;
  955. const target = observed["__v_raw" /* RAW */];
  956. const rawTarget = toRaw(target);
  957. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  958. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  959. return target.forEach((value, key) => {
  960. // important: make sure the callback is
  961. // 1. invoked with the reactive map as `this` and 3rd arg
  962. // 2. the value received should be a corresponding reactive/readonly.
  963. return callback.call(thisArg, wrap(value), wrap(key), observed);
  964. });
  965. };
  966. }
  967. function createIterableMethod(method, isReadonly, isShallow) {
  968. return function (...args) {
  969. const target = this["__v_raw" /* RAW */];
  970. const rawTarget = toRaw(target);
  971. const targetIsMap = isMap(rawTarget);
  972. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  973. const isKeyOnly = method === 'keys' && targetIsMap;
  974. const innerIterator = target[method](...args);
  975. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  976. !isReadonly &&
  977. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  978. // return a wrapped iterator which returns observed versions of the
  979. // values emitted from the real iterator
  980. return {
  981. // iterator protocol
  982. next() {
  983. const { value, done } = innerIterator.next();
  984. return done
  985. ? { value, done }
  986. : {
  987. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  988. done
  989. };
  990. },
  991. // iterable protocol
  992. [Symbol.iterator]() {
  993. return this;
  994. }
  995. };
  996. };
  997. }
  998. function createReadonlyMethod(type) {
  999. return function (...args) {
  1000. {
  1001. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1002. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1003. }
  1004. return type === "delete" /* DELETE */ ? false : this;
  1005. };
  1006. }
  1007. function createInstrumentations() {
  1008. const mutableInstrumentations = {
  1009. get(key) {
  1010. return get$1(this, key);
  1011. },
  1012. get size() {
  1013. return size(this);
  1014. },
  1015. has: has$1,
  1016. add,
  1017. set: set$1,
  1018. delete: deleteEntry,
  1019. clear,
  1020. forEach: createForEach(false, false)
  1021. };
  1022. const shallowInstrumentations = {
  1023. get(key) {
  1024. return get$1(this, key, false, true);
  1025. },
  1026. get size() {
  1027. return size(this);
  1028. },
  1029. has: has$1,
  1030. add,
  1031. set: set$1,
  1032. delete: deleteEntry,
  1033. clear,
  1034. forEach: createForEach(false, true)
  1035. };
  1036. const readonlyInstrumentations = {
  1037. get(key) {
  1038. return get$1(this, key, true);
  1039. },
  1040. get size() {
  1041. return size(this, true);
  1042. },
  1043. has(key) {
  1044. return has$1.call(this, key, true);
  1045. },
  1046. add: createReadonlyMethod("add" /* ADD */),
  1047. set: createReadonlyMethod("set" /* SET */),
  1048. delete: createReadonlyMethod("delete" /* DELETE */),
  1049. clear: createReadonlyMethod("clear" /* CLEAR */),
  1050. forEach: createForEach(true, false)
  1051. };
  1052. const shallowReadonlyInstrumentations = {
  1053. get(key) {
  1054. return get$1(this, key, true, true);
  1055. },
  1056. get size() {
  1057. return size(this, true);
  1058. },
  1059. has(key) {
  1060. return has$1.call(this, key, true);
  1061. },
  1062. add: createReadonlyMethod("add" /* ADD */),
  1063. set: createReadonlyMethod("set" /* SET */),
  1064. delete: createReadonlyMethod("delete" /* DELETE */),
  1065. clear: createReadonlyMethod("clear" /* CLEAR */),
  1066. forEach: createForEach(true, true)
  1067. };
  1068. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1069. iteratorMethods.forEach(method => {
  1070. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1071. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1072. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1073. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1074. });
  1075. return [
  1076. mutableInstrumentations,
  1077. readonlyInstrumentations,
  1078. shallowInstrumentations,
  1079. shallowReadonlyInstrumentations
  1080. ];
  1081. }
  1082. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1083. function createInstrumentationGetter(isReadonly, shallow) {
  1084. const instrumentations = shallow
  1085. ? isReadonly
  1086. ? shallowReadonlyInstrumentations
  1087. : shallowInstrumentations
  1088. : isReadonly
  1089. ? readonlyInstrumentations
  1090. : mutableInstrumentations;
  1091. return (target, key, receiver) => {
  1092. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  1093. return !isReadonly;
  1094. }
  1095. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  1096. return isReadonly;
  1097. }
  1098. else if (key === "__v_raw" /* RAW */) {
  1099. return target;
  1100. }
  1101. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1102. ? instrumentations
  1103. : target, key, receiver);
  1104. };
  1105. }
  1106. const mutableCollectionHandlers = {
  1107. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1108. };
  1109. const shallowCollectionHandlers = {
  1110. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1111. };
  1112. const readonlyCollectionHandlers = {
  1113. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1114. };
  1115. const shallowReadonlyCollectionHandlers = {
  1116. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1117. };
  1118. function checkIdentityKeys(target, has, key) {
  1119. const rawKey = toRaw(key);
  1120. if (rawKey !== key && has.call(target, rawKey)) {
  1121. const type = toRawType(target);
  1122. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1123. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1124. `which can lead to inconsistencies. ` +
  1125. `Avoid differentiating between the raw and reactive versions ` +
  1126. `of an object and only use the reactive version if possible.`);
  1127. }
  1128. }
  1129. const reactiveMap = new WeakMap();
  1130. const shallowReactiveMap = new WeakMap();
  1131. const readonlyMap = new WeakMap();
  1132. const shallowReadonlyMap = new WeakMap();
  1133. function targetTypeMap(rawType) {
  1134. switch (rawType) {
  1135. case 'Object':
  1136. case 'Array':
  1137. return 1 /* COMMON */;
  1138. case 'Map':
  1139. case 'Set':
  1140. case 'WeakMap':
  1141. case 'WeakSet':
  1142. return 2 /* COLLECTION */;
  1143. default:
  1144. return 0 /* INVALID */;
  1145. }
  1146. }
  1147. function getTargetType(value) {
  1148. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  1149. ? 0 /* INVALID */
  1150. : targetTypeMap(toRawType(value));
  1151. }
  1152. function reactive(target) {
  1153. // if trying to observe a readonly proxy, return the readonly version.
  1154. if (target && target["__v_isReadonly" /* IS_READONLY */]) {
  1155. return target;
  1156. }
  1157. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1158. }
  1159. /**
  1160. * Return a shallowly-reactive copy of the original object, where only the root
  1161. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1162. * root level).
  1163. */
  1164. function shallowReactive(target) {
  1165. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1166. }
  1167. /**
  1168. * Creates a readonly copy of the original object. Note the returned copy is not
  1169. * made reactive, but `readonly` can be called on an already reactive object.
  1170. */
  1171. function readonly(target) {
  1172. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1173. }
  1174. /**
  1175. * Returns a reactive-copy of the original object, where only the root level
  1176. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1177. * returned properties.
  1178. * This is used for creating the props proxy object for stateful components.
  1179. */
  1180. function shallowReadonly(target) {
  1181. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1182. }
  1183. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1184. if (!isObject(target)) {
  1185. {
  1186. console.warn(`value cannot be made reactive: ${String(target)}`);
  1187. }
  1188. return target;
  1189. }
  1190. // target is already a Proxy, return it.
  1191. // exception: calling readonly() on a reactive object
  1192. if (target["__v_raw" /* RAW */] &&
  1193. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1194. return target;
  1195. }
  1196. // target already has corresponding Proxy
  1197. const existingProxy = proxyMap.get(target);
  1198. if (existingProxy) {
  1199. return existingProxy;
  1200. }
  1201. // only a whitelist of value types can be observed.
  1202. const targetType = getTargetType(target);
  1203. if (targetType === 0 /* INVALID */) {
  1204. return target;
  1205. }
  1206. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1207. proxyMap.set(target, proxy);
  1208. return proxy;
  1209. }
  1210. function isReactive(value) {
  1211. if (isReadonly(value)) {
  1212. return isReactive(value["__v_raw" /* RAW */]);
  1213. }
  1214. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1215. }
  1216. function isReadonly(value) {
  1217. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1218. }
  1219. function isProxy(value) {
  1220. return isReactive(value) || isReadonly(value);
  1221. }
  1222. function toRaw(observed) {
  1223. const raw = observed && observed["__v_raw" /* RAW */];
  1224. return raw ? toRaw(raw) : observed;
  1225. }
  1226. function markRaw(value) {
  1227. def(value, "__v_skip" /* SKIP */, true);
  1228. return value;
  1229. }
  1230. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1231. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1232. function trackRefValue(ref) {
  1233. if (isTracking()) {
  1234. ref = toRaw(ref);
  1235. if (!ref.dep) {
  1236. ref.dep = createDep();
  1237. }
  1238. {
  1239. trackEffects(ref.dep, {
  1240. target: ref,
  1241. type: "get" /* GET */,
  1242. key: 'value'
  1243. });
  1244. }
  1245. }
  1246. }
  1247. function triggerRefValue(ref, newVal) {
  1248. ref = toRaw(ref);
  1249. if (ref.dep) {
  1250. {
  1251. triggerEffects(ref.dep, {
  1252. target: ref,
  1253. type: "set" /* SET */,
  1254. key: 'value',
  1255. newValue: newVal
  1256. });
  1257. }
  1258. }
  1259. }
  1260. function isRef(r) {
  1261. return Boolean(r && r.__v_isRef === true);
  1262. }
  1263. function ref(value) {
  1264. return createRef(value, false);
  1265. }
  1266. function shallowRef(value) {
  1267. return createRef(value, true);
  1268. }
  1269. function createRef(rawValue, shallow) {
  1270. if (isRef(rawValue)) {
  1271. return rawValue;
  1272. }
  1273. return new RefImpl(rawValue, shallow);
  1274. }
  1275. class RefImpl {
  1276. constructor(value, _shallow) {
  1277. this._shallow = _shallow;
  1278. this.dep = undefined;
  1279. this.__v_isRef = true;
  1280. this._rawValue = _shallow ? value : toRaw(value);
  1281. this._value = _shallow ? value : toReactive(value);
  1282. }
  1283. get value() {
  1284. trackRefValue(this);
  1285. return this._value;
  1286. }
  1287. set value(newVal) {
  1288. newVal = this._shallow ? newVal : toRaw(newVal);
  1289. if (hasChanged(newVal, this._rawValue)) {
  1290. this._rawValue = newVal;
  1291. this._value = this._shallow ? newVal : toReactive(newVal);
  1292. triggerRefValue(this, newVal);
  1293. }
  1294. }
  1295. }
  1296. function triggerRef(ref) {
  1297. triggerRefValue(ref, ref.value );
  1298. }
  1299. function unref(ref) {
  1300. return isRef(ref) ? ref.value : ref;
  1301. }
  1302. const shallowUnwrapHandlers = {
  1303. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1304. set: (target, key, value, receiver) => {
  1305. const oldValue = target[key];
  1306. if (isRef(oldValue) && !isRef(value)) {
  1307. oldValue.value = value;
  1308. return true;
  1309. }
  1310. else {
  1311. return Reflect.set(target, key, value, receiver);
  1312. }
  1313. }
  1314. };
  1315. function proxyRefs(objectWithRefs) {
  1316. return isReactive(objectWithRefs)
  1317. ? objectWithRefs
  1318. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1319. }
  1320. class CustomRefImpl {
  1321. constructor(factory) {
  1322. this.dep = undefined;
  1323. this.__v_isRef = true;
  1324. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1325. this._get = get;
  1326. this._set = set;
  1327. }
  1328. get value() {
  1329. return this._get();
  1330. }
  1331. set value(newVal) {
  1332. this._set(newVal);
  1333. }
  1334. }
  1335. function customRef(factory) {
  1336. return new CustomRefImpl(factory);
  1337. }
  1338. function toRefs(object) {
  1339. if (!isProxy(object)) {
  1340. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1341. }
  1342. const ret = isArray(object) ? new Array(object.length) : {};
  1343. for (const key in object) {
  1344. ret[key] = toRef(object, key);
  1345. }
  1346. return ret;
  1347. }
  1348. class ObjectRefImpl {
  1349. constructor(_object, _key, _defaultValue) {
  1350. this._object = _object;
  1351. this._key = _key;
  1352. this._defaultValue = _defaultValue;
  1353. this.__v_isRef = true;
  1354. }
  1355. get value() {
  1356. const val = this._object[this._key];
  1357. return val === undefined ? this._defaultValue : val;
  1358. }
  1359. set value(newVal) {
  1360. this._object[this._key] = newVal;
  1361. }
  1362. }
  1363. function toRef(object, key, defaultValue) {
  1364. const val = object[key];
  1365. return isRef(val)
  1366. ? val
  1367. : new ObjectRefImpl(object, key, defaultValue);
  1368. }
  1369. class ComputedRefImpl {
  1370. constructor(getter, _setter, isReadonly) {
  1371. this._setter = _setter;
  1372. this.dep = undefined;
  1373. this._dirty = true;
  1374. this.__v_isRef = true;
  1375. this.effect = new ReactiveEffect(getter, () => {
  1376. if (!this._dirty) {
  1377. this._dirty = true;
  1378. triggerRefValue(this);
  1379. }
  1380. });
  1381. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1382. }
  1383. get value() {
  1384. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1385. const self = toRaw(this);
  1386. trackRefValue(self);
  1387. if (self._dirty) {
  1388. self._dirty = false;
  1389. self._value = self.effect.run();
  1390. }
  1391. return self._value;
  1392. }
  1393. set value(newValue) {
  1394. this._setter(newValue);
  1395. }
  1396. }
  1397. function computed(getterOrOptions, debugOptions) {
  1398. let getter;
  1399. let setter;
  1400. const onlyGetter = isFunction(getterOrOptions);
  1401. if (onlyGetter) {
  1402. getter = getterOrOptions;
  1403. setter = () => {
  1404. console.warn('Write operation failed: computed value is readonly');
  1405. }
  1406. ;
  1407. }
  1408. else {
  1409. getter = getterOrOptions.get;
  1410. setter = getterOrOptions.set;
  1411. }
  1412. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter);
  1413. if (debugOptions) {
  1414. cRef.effect.onTrack = debugOptions.onTrack;
  1415. cRef.effect.onTrigger = debugOptions.onTrigger;
  1416. }
  1417. return cRef;
  1418. }
  1419. /* eslint-disable no-restricted-globals */
  1420. let isHmrUpdating = false;
  1421. const hmrDirtyComponents = new Set();
  1422. // Expose the HMR runtime on the global object
  1423. // This makes it entirely tree-shakable without polluting the exports and makes
  1424. // it easier to be used in toolings like vue-loader
  1425. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1426. // to be set so that its instances can be registered / removed.
  1427. {
  1428. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1429. createRecord: tryWrap(createRecord),
  1430. rerender: tryWrap(rerender),
  1431. reload: tryWrap(reload)
  1432. };
  1433. }
  1434. const map = new Map();
  1435. function registerHMR(instance) {
  1436. const id = instance.type.__hmrId;
  1437. let record = map.get(id);
  1438. if (!record) {
  1439. createRecord(id, instance.type);
  1440. record = map.get(id);
  1441. }
  1442. record.instances.add(instance);
  1443. }
  1444. function unregisterHMR(instance) {
  1445. map.get(instance.type.__hmrId).instances.delete(instance);
  1446. }
  1447. function createRecord(id, initialDef) {
  1448. if (map.has(id)) {
  1449. return false;
  1450. }
  1451. map.set(id, {
  1452. initialDef: normalizeClassComponent(initialDef),
  1453. instances: new Set()
  1454. });
  1455. return true;
  1456. }
  1457. function normalizeClassComponent(component) {
  1458. return isClassComponent(component) ? component.__vccOpts : component;
  1459. }
  1460. function rerender(id, newRender) {
  1461. const record = map.get(id);
  1462. if (!record) {
  1463. return;
  1464. }
  1465. // update initial record (for not-yet-rendered component)
  1466. record.initialDef.render = newRender;
  1467. [...record.instances].forEach(instance => {
  1468. if (newRender) {
  1469. instance.render = newRender;
  1470. normalizeClassComponent(instance.type).render = newRender;
  1471. }
  1472. instance.renderCache = [];
  1473. // this flag forces child components with slot content to update
  1474. isHmrUpdating = true;
  1475. instance.update();
  1476. isHmrUpdating = false;
  1477. });
  1478. }
  1479. function reload(id, newComp) {
  1480. const record = map.get(id);
  1481. if (!record)
  1482. return;
  1483. newComp = normalizeClassComponent(newComp);
  1484. // update initial def (for not-yet-rendered components)
  1485. updateComponentDef(record.initialDef, newComp);
  1486. // create a snapshot which avoids the set being mutated during updates
  1487. const instances = [...record.instances];
  1488. for (const instance of instances) {
  1489. const oldComp = normalizeClassComponent(instance.type);
  1490. if (!hmrDirtyComponents.has(oldComp)) {
  1491. // 1. Update existing comp definition to match new one
  1492. if (oldComp !== record.initialDef) {
  1493. updateComponentDef(oldComp, newComp);
  1494. }
  1495. // 2. mark definition dirty. This forces the renderer to replace the
  1496. // component on patch.
  1497. hmrDirtyComponents.add(oldComp);
  1498. }
  1499. // 3. invalidate options resolution cache
  1500. instance.appContext.optionsCache.delete(instance.type);
  1501. // 4. actually update
  1502. if (instance.ceReload) {
  1503. // custom element
  1504. hmrDirtyComponents.add(oldComp);
  1505. instance.ceReload(newComp.styles);
  1506. hmrDirtyComponents.delete(oldComp);
  1507. }
  1508. else if (instance.parent) {
  1509. // 4. Force the parent instance to re-render. This will cause all updated
  1510. // components to be unmounted and re-mounted. Queue the update so that we
  1511. // don't end up forcing the same parent to re-render multiple times.
  1512. queueJob(instance.parent.update);
  1513. // instance is the inner component of an async custom element
  1514. // invoke to reset styles
  1515. if (instance.parent.type.__asyncLoader &&
  1516. instance.parent.ceReload) {
  1517. instance.parent.ceReload(newComp.styles);
  1518. }
  1519. }
  1520. else if (instance.appContext.reload) {
  1521. // root instance mounted via createApp() has a reload method
  1522. instance.appContext.reload();
  1523. }
  1524. else if (typeof window !== 'undefined') {
  1525. // root instance inside tree created via raw render(). Force reload.
  1526. window.location.reload();
  1527. }
  1528. else {
  1529. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  1530. }
  1531. }
  1532. // 5. make sure to cleanup dirty hmr components after update
  1533. queuePostFlushCb(() => {
  1534. for (const instance of instances) {
  1535. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  1536. }
  1537. });
  1538. }
  1539. function updateComponentDef(oldComp, newComp) {
  1540. extend(oldComp, newComp);
  1541. for (const key in oldComp) {
  1542. if (key !== '__file' && !(key in newComp)) {
  1543. delete oldComp[key];
  1544. }
  1545. }
  1546. }
  1547. function tryWrap(fn) {
  1548. return (id, arg) => {
  1549. try {
  1550. return fn(id, arg);
  1551. }
  1552. catch (e) {
  1553. console.error(e);
  1554. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  1555. `Full reload required.`);
  1556. }
  1557. };
  1558. }
  1559. let devtools;
  1560. let buffer = [];
  1561. let devtoolsNotInstalled = false;
  1562. function emit(event, ...args) {
  1563. if (devtools) {
  1564. devtools.emit(event, ...args);
  1565. }
  1566. else if (!devtoolsNotInstalled) {
  1567. buffer.push({ event, args });
  1568. }
  1569. }
  1570. function setDevtoolsHook(hook, target) {
  1571. var _a, _b;
  1572. devtools = hook;
  1573. if (devtools) {
  1574. devtools.enabled = true;
  1575. buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
  1576. buffer = [];
  1577. }
  1578. else if (
  1579. // handle late devtools injection - only do this if we are in an actual
  1580. // browser environment to avoid the timer handle stalling test runner exit
  1581. // (#4815)
  1582. // eslint-disable-next-line no-restricted-globals
  1583. typeof window !== 'undefined' &&
  1584. // some envs mock window but not fully
  1585. window.HTMLElement &&
  1586. // also exclude jsdom
  1587. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  1588. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  1589. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  1590. replay.push((newHook) => {
  1591. setDevtoolsHook(newHook, target);
  1592. });
  1593. // clear buffer after 3s - the user probably doesn't have devtools installed
  1594. // at all, and keeping the buffer will cause memory leaks (#4738)
  1595. setTimeout(() => {
  1596. if (!devtools) {
  1597. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  1598. devtoolsNotInstalled = true;
  1599. buffer = [];
  1600. }
  1601. }, 3000);
  1602. }
  1603. else {
  1604. // non-browser env, assume not installed
  1605. devtoolsNotInstalled = true;
  1606. buffer = [];
  1607. }
  1608. }
  1609. function devtoolsInitApp(app, version) {
  1610. emit("app:init" /* APP_INIT */, app, version, {
  1611. Fragment,
  1612. Text,
  1613. Comment,
  1614. Static
  1615. });
  1616. }
  1617. function devtoolsUnmountApp(app) {
  1618. emit("app:unmount" /* APP_UNMOUNT */, app);
  1619. }
  1620. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  1621. const devtoolsComponentUpdated =
  1622. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  1623. const devtoolsComponentRemoved =
  1624. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  1625. function createDevtoolsComponentHook(hook) {
  1626. return (component) => {
  1627. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  1628. };
  1629. }
  1630. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  1631. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  1632. function createDevtoolsPerformanceHook(hook) {
  1633. return (component, type, time) => {
  1634. emit(hook, component.appContext.app, component.uid, component, type, time);
  1635. };
  1636. }
  1637. function devtoolsComponentEmit(component, event, params) {
  1638. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  1639. }
  1640. function emit$1(instance, event, ...rawArgs) {
  1641. const props = instance.vnode.props || EMPTY_OBJ;
  1642. {
  1643. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  1644. if (emitsOptions) {
  1645. if (!(event in emitsOptions) &&
  1646. !(false )) {
  1647. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  1648. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  1649. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  1650. }
  1651. }
  1652. else {
  1653. const validator = emitsOptions[event];
  1654. if (isFunction(validator)) {
  1655. const isValid = validator(...rawArgs);
  1656. if (!isValid) {
  1657. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. let args = rawArgs;
  1664. const isModelListener = event.startsWith('update:');
  1665. // for v-model update:xxx events, apply modifiers on args
  1666. const modelArg = isModelListener && event.slice(7);
  1667. if (modelArg && modelArg in props) {
  1668. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  1669. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  1670. if (trim) {
  1671. args = rawArgs.map(a => a.trim());
  1672. }
  1673. else if (number) {
  1674. args = rawArgs.map(toNumber);
  1675. }
  1676. }
  1677. {
  1678. devtoolsComponentEmit(instance, event, args);
  1679. }
  1680. {
  1681. const lowerCaseEvent = event.toLowerCase();
  1682. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  1683. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  1684. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  1685. `Note that HTML attributes are case-insensitive and you cannot use ` +
  1686. `v-on to listen to camelCase events when using in-DOM templates. ` +
  1687. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  1688. }
  1689. }
  1690. let handlerName;
  1691. let handler = props[(handlerName = toHandlerKey(event))] ||
  1692. // also try camelCase event handler (#2249)
  1693. props[(handlerName = toHandlerKey(camelize(event)))];
  1694. // for v-model update:xxx events, also trigger kebab-case equivalent
  1695. // for props passed via kebab-case
  1696. if (!handler && isModelListener) {
  1697. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  1698. }
  1699. if (handler) {
  1700. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1701. }
  1702. const onceHandler = props[handlerName + `Once`];
  1703. if (onceHandler) {
  1704. if (!instance.emitted) {
  1705. instance.emitted = {};
  1706. }
  1707. else if (instance.emitted[handlerName]) {
  1708. return;
  1709. }
  1710. instance.emitted[handlerName] = true;
  1711. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1712. }
  1713. }
  1714. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  1715. const cache = appContext.emitsCache;
  1716. const cached = cache.get(comp);
  1717. if (cached !== undefined) {
  1718. return cached;
  1719. }
  1720. const raw = comp.emits;
  1721. let normalized = {};
  1722. // apply mixin/extends props
  1723. let hasExtends = false;
  1724. if (!isFunction(comp)) {
  1725. const extendEmits = (raw) => {
  1726. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  1727. if (normalizedFromExtend) {
  1728. hasExtends = true;
  1729. extend(normalized, normalizedFromExtend);
  1730. }
  1731. };
  1732. if (!asMixin && appContext.mixins.length) {
  1733. appContext.mixins.forEach(extendEmits);
  1734. }
  1735. if (comp.extends) {
  1736. extendEmits(comp.extends);
  1737. }
  1738. if (comp.mixins) {
  1739. comp.mixins.forEach(extendEmits);
  1740. }
  1741. }
  1742. if (!raw && !hasExtends) {
  1743. cache.set(comp, null);
  1744. return null;
  1745. }
  1746. if (isArray(raw)) {
  1747. raw.forEach(key => (normalized[key] = null));
  1748. }
  1749. else {
  1750. extend(normalized, raw);
  1751. }
  1752. cache.set(comp, normalized);
  1753. return normalized;
  1754. }
  1755. // Check if an incoming prop key is a declared emit event listener.
  1756. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  1757. // both considered matched listeners.
  1758. function isEmitListener(options, key) {
  1759. if (!options || !isOn(key)) {
  1760. return false;
  1761. }
  1762. key = key.slice(2).replace(/Once$/, '');
  1763. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  1764. hasOwn(options, hyphenate(key)) ||
  1765. hasOwn(options, key));
  1766. }
  1767. /**
  1768. * mark the current rendering instance for asset resolution (e.g.
  1769. * resolveComponent, resolveDirective) during render
  1770. */
  1771. let currentRenderingInstance = null;
  1772. let currentScopeId = null;
  1773. /**
  1774. * Note: rendering calls maybe nested. The function returns the parent rendering
  1775. * instance if present, which should be restored after the render is done:
  1776. *
  1777. * ```js
  1778. * const prev = setCurrentRenderingInstance(i)
  1779. * // ...render
  1780. * setCurrentRenderingInstance(prev)
  1781. * ```
  1782. */
  1783. function setCurrentRenderingInstance(instance) {
  1784. const prev = currentRenderingInstance;
  1785. currentRenderingInstance = instance;
  1786. currentScopeId = (instance && instance.type.__scopeId) || null;
  1787. return prev;
  1788. }
  1789. /**
  1790. * Set scope id when creating hoisted vnodes.
  1791. * @private compiler helper
  1792. */
  1793. function pushScopeId(id) {
  1794. currentScopeId = id;
  1795. }
  1796. /**
  1797. * Technically we no longer need this after 3.0.8 but we need to keep the same
  1798. * API for backwards compat w/ code generated by compilers.
  1799. * @private
  1800. */
  1801. function popScopeId() {
  1802. currentScopeId = null;
  1803. }
  1804. /**
  1805. * Only for backwards compat
  1806. * @private
  1807. */
  1808. const withScopeId = (_id) => withCtx;
  1809. /**
  1810. * Wrap a slot function to memoize current rendering instance
  1811. * @private compiler helper
  1812. */
  1813. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  1814. ) {
  1815. if (!ctx)
  1816. return fn;
  1817. // already normalized
  1818. if (fn._n) {
  1819. return fn;
  1820. }
  1821. const renderFnWithContext = (...args) => {
  1822. // If a user calls a compiled slot inside a template expression (#1745), it
  1823. // can mess up block tracking, so by default we disable block tracking and
  1824. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  1825. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  1826. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  1827. if (renderFnWithContext._d) {
  1828. setBlockTracking(-1);
  1829. }
  1830. const prevInstance = setCurrentRenderingInstance(ctx);
  1831. const res = fn(...args);
  1832. setCurrentRenderingInstance(prevInstance);
  1833. if (renderFnWithContext._d) {
  1834. setBlockTracking(1);
  1835. }
  1836. {
  1837. devtoolsComponentUpdated(ctx);
  1838. }
  1839. return res;
  1840. };
  1841. // mark normalized to avoid duplicated wrapping
  1842. renderFnWithContext._n = true;
  1843. // mark this as compiled by default
  1844. // this is used in vnode.ts -> normalizeChildren() to set the slot
  1845. // rendering flag.
  1846. renderFnWithContext._c = true;
  1847. // disable block tracking by default
  1848. renderFnWithContext._d = true;
  1849. return renderFnWithContext;
  1850. }
  1851. /**
  1852. * dev only flag to track whether $attrs was used during render.
  1853. * If $attrs was used during render then the warning for failed attrs
  1854. * fallthrough can be suppressed.
  1855. */
  1856. let accessedAttrs = false;
  1857. function markAttrsAccessed() {
  1858. accessedAttrs = true;
  1859. }
  1860. function renderComponentRoot(instance) {
  1861. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  1862. let result;
  1863. let fallthroughAttrs;
  1864. const prev = setCurrentRenderingInstance(instance);
  1865. {
  1866. accessedAttrs = false;
  1867. }
  1868. try {
  1869. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  1870. // withProxy is a proxy with a different `has` trap only for
  1871. // runtime-compiled render functions using `with` block.
  1872. const proxyToUse = withProxy || proxy;
  1873. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  1874. fallthroughAttrs = attrs;
  1875. }
  1876. else {
  1877. // functional
  1878. const render = Component;
  1879. // in dev, mark attrs accessed if optional props (attrs === props)
  1880. if (true && attrs === props) {
  1881. markAttrsAccessed();
  1882. }
  1883. result = normalizeVNode(render.length > 1
  1884. ? render(props, true
  1885. ? {
  1886. get attrs() {
  1887. markAttrsAccessed();
  1888. return attrs;
  1889. },
  1890. slots,
  1891. emit
  1892. }
  1893. : { attrs, slots, emit })
  1894. : render(props, null /* we know it doesn't need it */));
  1895. fallthroughAttrs = Component.props
  1896. ? attrs
  1897. : getFunctionalFallthrough(attrs);
  1898. }
  1899. }
  1900. catch (err) {
  1901. blockStack.length = 0;
  1902. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  1903. result = createVNode(Comment);
  1904. }
  1905. // attr merging
  1906. // in dev mode, comments are preserved, and it's possible for a template
  1907. // to have comments along side the root element which makes it a fragment
  1908. let root = result;
  1909. let setRoot = undefined;
  1910. if (result.patchFlag > 0 &&
  1911. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  1912. [root, setRoot] = getChildRoot(result);
  1913. }
  1914. if (fallthroughAttrs && inheritAttrs !== false) {
  1915. const keys = Object.keys(fallthroughAttrs);
  1916. const { shapeFlag } = root;
  1917. if (keys.length) {
  1918. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  1919. if (propsOptions && keys.some(isModelListener)) {
  1920. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  1921. // prop, it indicates this component expects to handle v-model and
  1922. // it should not fallthrough.
  1923. // related: #1543, #1643, #1989
  1924. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  1925. }
  1926. root = cloneVNode(root, fallthroughAttrs);
  1927. }
  1928. else if (!accessedAttrs && root.type !== Comment) {
  1929. const allAttrs = Object.keys(attrs);
  1930. const eventAttrs = [];
  1931. const extraAttrs = [];
  1932. for (let i = 0, l = allAttrs.length; i < l; i++) {
  1933. const key = allAttrs[i];
  1934. if (isOn(key)) {
  1935. // ignore v-model handlers when they fail to fallthrough
  1936. if (!isModelListener(key)) {
  1937. // remove `on`, lowercase first letter to reflect event casing
  1938. // accurately
  1939. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  1940. }
  1941. }
  1942. else {
  1943. extraAttrs.push(key);
  1944. }
  1945. }
  1946. if (extraAttrs.length) {
  1947. warn$1(`Extraneous non-props attributes (` +
  1948. `${extraAttrs.join(', ')}) ` +
  1949. `were passed to component but could not be automatically inherited ` +
  1950. `because component renders fragment or text root nodes.`);
  1951. }
  1952. if (eventAttrs.length) {
  1953. warn$1(`Extraneous non-emits event listeners (` +
  1954. `${eventAttrs.join(', ')}) ` +
  1955. `were passed to component but could not be automatically inherited ` +
  1956. `because component renders fragment or text root nodes. ` +
  1957. `If the listener is intended to be a component custom event listener only, ` +
  1958. `declare it using the "emits" option.`);
  1959. }
  1960. }
  1961. }
  1962. }
  1963. // inherit directives
  1964. if (vnode.dirs) {
  1965. if (!isElementRoot(root)) {
  1966. warn$1(`Runtime directive used on component with non-element root node. ` +
  1967. `The directives will not function as intended.`);
  1968. }
  1969. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  1970. }
  1971. // inherit transition data
  1972. if (vnode.transition) {
  1973. if (!isElementRoot(root)) {
  1974. warn$1(`Component inside <Transition> renders non-element root node ` +
  1975. `that cannot be animated.`);
  1976. }
  1977. root.transition = vnode.transition;
  1978. }
  1979. if (setRoot) {
  1980. setRoot(root);
  1981. }
  1982. else {
  1983. result = root;
  1984. }
  1985. setCurrentRenderingInstance(prev);
  1986. return result;
  1987. }
  1988. /**
  1989. * dev only
  1990. * In dev mode, template root level comments are rendered, which turns the
  1991. * template into a fragment root, but we need to locate the single element
  1992. * root for attrs and scope id processing.
  1993. */
  1994. const getChildRoot = (vnode) => {
  1995. const rawChildren = vnode.children;
  1996. const dynamicChildren = vnode.dynamicChildren;
  1997. const childRoot = filterSingleRoot(rawChildren);
  1998. if (!childRoot) {
  1999. return [vnode, undefined];
  2000. }
  2001. const index = rawChildren.indexOf(childRoot);
  2002. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2003. const setRoot = (updatedRoot) => {
  2004. rawChildren[index] = updatedRoot;
  2005. if (dynamicChildren) {
  2006. if (dynamicIndex > -1) {
  2007. dynamicChildren[dynamicIndex] = updatedRoot;
  2008. }
  2009. else if (updatedRoot.patchFlag > 0) {
  2010. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2011. }
  2012. }
  2013. };
  2014. return [normalizeVNode(childRoot), setRoot];
  2015. };
  2016. function filterSingleRoot(children) {
  2017. let singleRoot;
  2018. for (let i = 0; i < children.length; i++) {
  2019. const child = children[i];
  2020. if (isVNode(child)) {
  2021. // ignore user comment
  2022. if (child.type !== Comment || child.children === 'v-if') {
  2023. if (singleRoot) {
  2024. // has more than 1 non-comment child, return now
  2025. return;
  2026. }
  2027. else {
  2028. singleRoot = child;
  2029. }
  2030. }
  2031. }
  2032. else {
  2033. return;
  2034. }
  2035. }
  2036. return singleRoot;
  2037. }
  2038. const getFunctionalFallthrough = (attrs) => {
  2039. let res;
  2040. for (const key in attrs) {
  2041. if (key === 'class' || key === 'style' || isOn(key)) {
  2042. (res || (res = {}))[key] = attrs[key];
  2043. }
  2044. }
  2045. return res;
  2046. };
  2047. const filterModelListeners = (attrs, props) => {
  2048. const res = {};
  2049. for (const key in attrs) {
  2050. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2051. res[key] = attrs[key];
  2052. }
  2053. }
  2054. return res;
  2055. };
  2056. const isElementRoot = (vnode) => {
  2057. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  2058. vnode.type === Comment // potential v-if branch switch
  2059. );
  2060. };
  2061. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2062. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2063. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2064. const emits = component.emitsOptions;
  2065. // Parent component's render function was hot-updated. Since this may have
  2066. // caused the child component's slots content to have changed, we need to
  2067. // force the child to update as well.
  2068. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2069. return true;
  2070. }
  2071. // force child update for runtime directive or transition on component vnode.
  2072. if (nextVNode.dirs || nextVNode.transition) {
  2073. return true;
  2074. }
  2075. if (optimized && patchFlag >= 0) {
  2076. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2077. // slot content that references values that might have changed,
  2078. // e.g. in a v-for
  2079. return true;
  2080. }
  2081. if (patchFlag & 16 /* FULL_PROPS */) {
  2082. if (!prevProps) {
  2083. return !!nextProps;
  2084. }
  2085. // presence of this flag indicates props are always non-null
  2086. return hasPropsChanged(prevProps, nextProps, emits);
  2087. }
  2088. else if (patchFlag & 8 /* PROPS */) {
  2089. const dynamicProps = nextVNode.dynamicProps;
  2090. for (let i = 0; i < dynamicProps.length; i++) {
  2091. const key = dynamicProps[i];
  2092. if (nextProps[key] !== prevProps[key] &&
  2093. !isEmitListener(emits, key)) {
  2094. return true;
  2095. }
  2096. }
  2097. }
  2098. }
  2099. else {
  2100. // this path is only taken by manually written render functions
  2101. // so presence of any children leads to a forced update
  2102. if (prevChildren || nextChildren) {
  2103. if (!nextChildren || !nextChildren.$stable) {
  2104. return true;
  2105. }
  2106. }
  2107. if (prevProps === nextProps) {
  2108. return false;
  2109. }
  2110. if (!prevProps) {
  2111. return !!nextProps;
  2112. }
  2113. if (!nextProps) {
  2114. return true;
  2115. }
  2116. return hasPropsChanged(prevProps, nextProps, emits);
  2117. }
  2118. return false;
  2119. }
  2120. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2121. const nextKeys = Object.keys(nextProps);
  2122. if (nextKeys.length !== Object.keys(prevProps).length) {
  2123. return true;
  2124. }
  2125. for (let i = 0; i < nextKeys.length; i++) {
  2126. const key = nextKeys[i];
  2127. if (nextProps[key] !== prevProps[key] &&
  2128. !isEmitListener(emitsOptions, key)) {
  2129. return true;
  2130. }
  2131. }
  2132. return false;
  2133. }
  2134. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2135. ) {
  2136. while (parent && parent.subTree === vnode) {
  2137. (vnode = parent.vnode).el = el;
  2138. parent = parent.parent;
  2139. }
  2140. }
  2141. const isSuspense = (type) => type.__isSuspense;
  2142. // Suspense exposes a component-like API, and is treated like a component
  2143. // in the compiler, but internally it's a special built-in type that hooks
  2144. // directly into the renderer.
  2145. const SuspenseImpl = {
  2146. name: 'Suspense',
  2147. // In order to make Suspense tree-shakable, we need to avoid importing it
  2148. // directly in the renderer. The renderer checks for the __isSuspense flag
  2149. // on a vnode's type and calls the `process` method, passing in renderer
  2150. // internals.
  2151. __isSuspense: true,
  2152. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2153. // platform-specific impl passed from renderer
  2154. rendererInternals) {
  2155. if (n1 == null) {
  2156. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2157. }
  2158. else {
  2159. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2160. }
  2161. },
  2162. hydrate: hydrateSuspense,
  2163. create: createSuspenseBoundary,
  2164. normalize: normalizeSuspenseChildren
  2165. };
  2166. // Force-casted public typing for h and TSX props inference
  2167. const Suspense = (SuspenseImpl );
  2168. function triggerEvent(vnode, name) {
  2169. const eventListener = vnode.props && vnode.props[name];
  2170. if (isFunction(eventListener)) {
  2171. eventListener();
  2172. }
  2173. }
  2174. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2175. const { p: patch, o: { createElement } } = rendererInternals;
  2176. const hiddenContainer = createElement('div');
  2177. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2178. // start mounting the content subtree in an off-dom container
  2179. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2180. // now check if we have encountered any async deps
  2181. if (suspense.deps > 0) {
  2182. // has async
  2183. // invoke @fallback event
  2184. triggerEvent(vnode, 'onPending');
  2185. triggerEvent(vnode, 'onFallback');
  2186. // mount the fallback tree
  2187. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2188. isSVG, slotScopeIds);
  2189. setActiveBranch(suspense, vnode.ssFallback);
  2190. }
  2191. else {
  2192. // Suspense has no async deps. Just resolve.
  2193. suspense.resolve();
  2194. }
  2195. }
  2196. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2197. const suspense = (n2.suspense = n1.suspense);
  2198. suspense.vnode = n2;
  2199. n2.el = n1.el;
  2200. const newBranch = n2.ssContent;
  2201. const newFallback = n2.ssFallback;
  2202. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2203. if (pendingBranch) {
  2204. suspense.pendingBranch = newBranch;
  2205. if (isSameVNodeType(newBranch, pendingBranch)) {
  2206. // same root type but content may have changed.
  2207. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2208. if (suspense.deps <= 0) {
  2209. suspense.resolve();
  2210. }
  2211. else if (isInFallback) {
  2212. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2213. isSVG, slotScopeIds, optimized);
  2214. setActiveBranch(suspense, newFallback);
  2215. }
  2216. }
  2217. else {
  2218. // toggled before pending tree is resolved
  2219. suspense.pendingId++;
  2220. if (isHydrating) {
  2221. // if toggled before hydration is finished, the current DOM tree is
  2222. // no longer valid. set it as the active branch so it will be unmounted
  2223. // when resolved
  2224. suspense.isHydrating = false;
  2225. suspense.activeBranch = pendingBranch;
  2226. }
  2227. else {
  2228. unmount(pendingBranch, parentComponent, suspense);
  2229. }
  2230. // increment pending ID. this is used to invalidate async callbacks
  2231. // reset suspense state
  2232. suspense.deps = 0;
  2233. // discard effects from pending branch
  2234. suspense.effects.length = 0;
  2235. // discard previous container
  2236. suspense.hiddenContainer = createElement('div');
  2237. if (isInFallback) {
  2238. // already in fallback state
  2239. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2240. if (suspense.deps <= 0) {
  2241. suspense.resolve();
  2242. }
  2243. else {
  2244. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2245. isSVG, slotScopeIds, optimized);
  2246. setActiveBranch(suspense, newFallback);
  2247. }
  2248. }
  2249. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2250. // toggled "back" to current active branch
  2251. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2252. // force resolve
  2253. suspense.resolve(true);
  2254. }
  2255. else {
  2256. // switched to a 3rd branch
  2257. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2258. if (suspense.deps <= 0) {
  2259. suspense.resolve();
  2260. }
  2261. }
  2262. }
  2263. }
  2264. else {
  2265. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2266. // root did not change, just normal patch
  2267. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2268. setActiveBranch(suspense, newBranch);
  2269. }
  2270. else {
  2271. // root node toggled
  2272. // invoke @pending event
  2273. triggerEvent(n2, 'onPending');
  2274. // mount pending branch in off-dom container
  2275. suspense.pendingBranch = newBranch;
  2276. suspense.pendingId++;
  2277. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2278. if (suspense.deps <= 0) {
  2279. // incoming branch has no async deps, resolve now.
  2280. suspense.resolve();
  2281. }
  2282. else {
  2283. const { timeout, pendingId } = suspense;
  2284. if (timeout > 0) {
  2285. setTimeout(() => {
  2286. if (suspense.pendingId === pendingId) {
  2287. suspense.fallback(newFallback);
  2288. }
  2289. }, timeout);
  2290. }
  2291. else if (timeout === 0) {
  2292. suspense.fallback(newFallback);
  2293. }
  2294. }
  2295. }
  2296. }
  2297. }
  2298. let hasWarned = false;
  2299. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2300. /* istanbul ignore if */
  2301. if (!hasWarned) {
  2302. hasWarned = true;
  2303. // @ts-ignore `console.info` cannot be null error
  2304. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2305. }
  2306. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2307. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2308. const suspense = {
  2309. vnode,
  2310. parent,
  2311. parentComponent,
  2312. isSVG,
  2313. container,
  2314. hiddenContainer,
  2315. anchor,
  2316. deps: 0,
  2317. pendingId: 0,
  2318. timeout: typeof timeout === 'number' ? timeout : -1,
  2319. activeBranch: null,
  2320. pendingBranch: null,
  2321. isInFallback: true,
  2322. isHydrating,
  2323. isUnmounted: false,
  2324. effects: [],
  2325. resolve(resume = false) {
  2326. {
  2327. if (!resume && !suspense.pendingBranch) {
  2328. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2329. }
  2330. if (suspense.isUnmounted) {
  2331. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2332. }
  2333. }
  2334. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2335. if (suspense.isHydrating) {
  2336. suspense.isHydrating = false;
  2337. }
  2338. else if (!resume) {
  2339. const delayEnter = activeBranch &&
  2340. pendingBranch.transition &&
  2341. pendingBranch.transition.mode === 'out-in';
  2342. if (delayEnter) {
  2343. activeBranch.transition.afterLeave = () => {
  2344. if (pendingId === suspense.pendingId) {
  2345. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2346. }
  2347. };
  2348. }
  2349. // this is initial anchor on mount
  2350. let { anchor } = suspense;
  2351. // unmount current active tree
  2352. if (activeBranch) {
  2353. // if the fallback tree was mounted, it may have been moved
  2354. // as part of a parent suspense. get the latest anchor for insertion
  2355. anchor = next(activeBranch);
  2356. unmount(activeBranch, parentComponent, suspense, true);
  2357. }
  2358. if (!delayEnter) {
  2359. // move content from off-dom container to actual container
  2360. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2361. }
  2362. }
  2363. setActiveBranch(suspense, pendingBranch);
  2364. suspense.pendingBranch = null;
  2365. suspense.isInFallback = false;
  2366. // flush buffered effects
  2367. // check if there is a pending parent suspense
  2368. let parent = suspense.parent;
  2369. let hasUnresolvedAncestor = false;
  2370. while (parent) {
  2371. if (parent.pendingBranch) {
  2372. // found a pending parent suspense, merge buffered post jobs
  2373. // into that parent
  2374. parent.effects.push(...effects);
  2375. hasUnresolvedAncestor = true;
  2376. break;
  2377. }
  2378. parent = parent.parent;
  2379. }
  2380. // no pending parent suspense, flush all jobs
  2381. if (!hasUnresolvedAncestor) {
  2382. queuePostFlushCb(effects);
  2383. }
  2384. suspense.effects = [];
  2385. // invoke @resolve event
  2386. triggerEvent(vnode, 'onResolve');
  2387. },
  2388. fallback(fallbackVNode) {
  2389. if (!suspense.pendingBranch) {
  2390. return;
  2391. }
  2392. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2393. // invoke @fallback event
  2394. triggerEvent(vnode, 'onFallback');
  2395. const anchor = next(activeBranch);
  2396. const mountFallback = () => {
  2397. if (!suspense.isInFallback) {
  2398. return;
  2399. }
  2400. // mount the fallback tree
  2401. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2402. isSVG, slotScopeIds, optimized);
  2403. setActiveBranch(suspense, fallbackVNode);
  2404. };
  2405. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2406. if (delayEnter) {
  2407. activeBranch.transition.afterLeave = mountFallback;
  2408. }
  2409. suspense.isInFallback = true;
  2410. // unmount current active branch
  2411. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2412. true // shouldRemove
  2413. );
  2414. if (!delayEnter) {
  2415. mountFallback();
  2416. }
  2417. },
  2418. move(container, anchor, type) {
  2419. suspense.activeBranch &&
  2420. move(suspense.activeBranch, container, anchor, type);
  2421. suspense.container = container;
  2422. },
  2423. next() {
  2424. return suspense.activeBranch && next(suspense.activeBranch);
  2425. },
  2426. registerDep(instance, setupRenderEffect) {
  2427. const isInPendingSuspense = !!suspense.pendingBranch;
  2428. if (isInPendingSuspense) {
  2429. suspense.deps++;
  2430. }
  2431. const hydratedEl = instance.vnode.el;
  2432. instance
  2433. .asyncDep.catch(err => {
  2434. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  2435. })
  2436. .then(asyncSetupResult => {
  2437. // retry when the setup() promise resolves.
  2438. // component may have been unmounted before resolve.
  2439. if (instance.isUnmounted ||
  2440. suspense.isUnmounted ||
  2441. suspense.pendingId !== instance.suspenseId) {
  2442. return;
  2443. }
  2444. // retry from this component
  2445. instance.asyncResolved = true;
  2446. const { vnode } = instance;
  2447. {
  2448. pushWarningContext(vnode);
  2449. }
  2450. handleSetupResult(instance, asyncSetupResult, false);
  2451. if (hydratedEl) {
  2452. // vnode may have been replaced if an update happened before the
  2453. // async dep is resolved.
  2454. vnode.el = hydratedEl;
  2455. }
  2456. const placeholder = !hydratedEl && instance.subTree.el;
  2457. setupRenderEffect(instance, vnode,
  2458. // component may have been moved before resolve.
  2459. // if this is not a hydration, instance.subTree will be the comment
  2460. // placeholder.
  2461. parentNode(hydratedEl || instance.subTree.el),
  2462. // anchor will not be used if this is hydration, so only need to
  2463. // consider the comment placeholder case.
  2464. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2465. if (placeholder) {
  2466. remove(placeholder);
  2467. }
  2468. updateHOCHostEl(instance, vnode.el);
  2469. {
  2470. popWarningContext();
  2471. }
  2472. // only decrease deps count if suspense is not already resolved
  2473. if (isInPendingSuspense && --suspense.deps === 0) {
  2474. suspense.resolve();
  2475. }
  2476. });
  2477. },
  2478. unmount(parentSuspense, doRemove) {
  2479. suspense.isUnmounted = true;
  2480. if (suspense.activeBranch) {
  2481. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2482. }
  2483. if (suspense.pendingBranch) {
  2484. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2485. }
  2486. }
  2487. };
  2488. return suspense;
  2489. }
  2490. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  2491. /* eslint-disable no-restricted-globals */
  2492. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  2493. // there are two possible scenarios for server-rendered suspense:
  2494. // - success: ssr content should be fully resolved
  2495. // - failure: ssr content should be the fallback branch.
  2496. // however, on the client we don't really know if it has failed or not
  2497. // attempt to hydrate the DOM assuming it has succeeded, but we still
  2498. // need to construct a suspense boundary first
  2499. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  2500. if (suspense.deps === 0) {
  2501. suspense.resolve();
  2502. }
  2503. return result;
  2504. /* eslint-enable no-restricted-globals */
  2505. }
  2506. function normalizeSuspenseChildren(vnode) {
  2507. const { shapeFlag, children } = vnode;
  2508. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  2509. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  2510. vnode.ssFallback = isSlotChildren
  2511. ? normalizeSuspenseSlot(children.fallback)
  2512. : createVNode(Comment);
  2513. }
  2514. function normalizeSuspenseSlot(s) {
  2515. let block;
  2516. if (isFunction(s)) {
  2517. const trackBlock = isBlockTreeEnabled && s._c;
  2518. if (trackBlock) {
  2519. // disableTracking: false
  2520. // allow block tracking for compiled slots
  2521. // (see ./componentRenderContext.ts)
  2522. s._d = false;
  2523. openBlock();
  2524. }
  2525. s = s();
  2526. if (trackBlock) {
  2527. s._d = true;
  2528. block = currentBlock;
  2529. closeBlock();
  2530. }
  2531. }
  2532. if (isArray(s)) {
  2533. const singleChild = filterSingleRoot(s);
  2534. if (!singleChild) {
  2535. warn$1(`<Suspense> slots expect a single root node.`);
  2536. }
  2537. s = singleChild;
  2538. }
  2539. s = normalizeVNode(s);
  2540. if (block && !s.dynamicChildren) {
  2541. s.dynamicChildren = block.filter(c => c !== s);
  2542. }
  2543. return s;
  2544. }
  2545. function queueEffectWithSuspense(fn, suspense) {
  2546. if (suspense && suspense.pendingBranch) {
  2547. if (isArray(fn)) {
  2548. suspense.effects.push(...fn);
  2549. }
  2550. else {
  2551. suspense.effects.push(fn);
  2552. }
  2553. }
  2554. else {
  2555. queuePostFlushCb(fn);
  2556. }
  2557. }
  2558. function setActiveBranch(suspense, branch) {
  2559. suspense.activeBranch = branch;
  2560. const { vnode, parentComponent } = suspense;
  2561. const el = (vnode.el = branch.el);
  2562. // in case suspense is the root node of a component,
  2563. // recursively update the HOC el
  2564. if (parentComponent && parentComponent.subTree === vnode) {
  2565. parentComponent.vnode.el = el;
  2566. updateHOCHostEl(parentComponent, el);
  2567. }
  2568. }
  2569. function provide(key, value) {
  2570. if (!currentInstance) {
  2571. {
  2572. warn$1(`provide() can only be used inside setup().`);
  2573. }
  2574. }
  2575. else {
  2576. let provides = currentInstance.provides;
  2577. // by default an instance inherits its parent's provides object
  2578. // but when it needs to provide values of its own, it creates its
  2579. // own provides object using parent provides object as prototype.
  2580. // this way in `inject` we can simply look up injections from direct
  2581. // parent and let the prototype chain do the work.
  2582. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  2583. if (parentProvides === provides) {
  2584. provides = currentInstance.provides = Object.create(parentProvides);
  2585. }
  2586. // TS doesn't allow symbol as index type
  2587. provides[key] = value;
  2588. }
  2589. }
  2590. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  2591. // fallback to `currentRenderingInstance` so that this can be called in
  2592. // a functional component
  2593. const instance = currentInstance || currentRenderingInstance;
  2594. if (instance) {
  2595. // #2400
  2596. // to support `app.use` plugins,
  2597. // fallback to appContext's `provides` if the intance is at root
  2598. const provides = instance.parent == null
  2599. ? instance.vnode.appContext && instance.vnode.appContext.provides
  2600. : instance.parent.provides;
  2601. if (provides && key in provides) {
  2602. // TS doesn't allow symbol as index type
  2603. return provides[key];
  2604. }
  2605. else if (arguments.length > 1) {
  2606. return treatDefaultAsFactory && isFunction(defaultValue)
  2607. ? defaultValue.call(instance.proxy)
  2608. : defaultValue;
  2609. }
  2610. else {
  2611. warn$1(`injection "${String(key)}" not found.`);
  2612. }
  2613. }
  2614. else {
  2615. warn$1(`inject() can only be used inside setup() or functional components.`);
  2616. }
  2617. }
  2618. function useTransitionState() {
  2619. const state = {
  2620. isMounted: false,
  2621. isLeaving: false,
  2622. isUnmounting: false,
  2623. leavingVNodes: new Map()
  2624. };
  2625. onMounted(() => {
  2626. state.isMounted = true;
  2627. });
  2628. onBeforeUnmount(() => {
  2629. state.isUnmounting = true;
  2630. });
  2631. return state;
  2632. }
  2633. const TransitionHookValidator = [Function, Array];
  2634. const BaseTransitionImpl = {
  2635. name: `BaseTransition`,
  2636. props: {
  2637. mode: String,
  2638. appear: Boolean,
  2639. persisted: Boolean,
  2640. // enter
  2641. onBeforeEnter: TransitionHookValidator,
  2642. onEnter: TransitionHookValidator,
  2643. onAfterEnter: TransitionHookValidator,
  2644. onEnterCancelled: TransitionHookValidator,
  2645. // leave
  2646. onBeforeLeave: TransitionHookValidator,
  2647. onLeave: TransitionHookValidator,
  2648. onAfterLeave: TransitionHookValidator,
  2649. onLeaveCancelled: TransitionHookValidator,
  2650. // appear
  2651. onBeforeAppear: TransitionHookValidator,
  2652. onAppear: TransitionHookValidator,
  2653. onAfterAppear: TransitionHookValidator,
  2654. onAppearCancelled: TransitionHookValidator
  2655. },
  2656. setup(props, { slots }) {
  2657. const instance = getCurrentInstance();
  2658. const state = useTransitionState();
  2659. let prevTransitionKey;
  2660. return () => {
  2661. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  2662. if (!children || !children.length) {
  2663. return;
  2664. }
  2665. // warn multiple elements
  2666. if (children.length > 1) {
  2667. warn$1('<transition> can only be used on a single element or component. Use ' +
  2668. '<transition-group> for lists.');
  2669. }
  2670. // there's no need to track reactivity for these props so use the raw
  2671. // props for a bit better perf
  2672. const rawProps = toRaw(props);
  2673. const { mode } = rawProps;
  2674. // check mode
  2675. if (mode &&
  2676. mode !== 'in-out' && mode !== 'out-in' && mode !== 'default') {
  2677. warn$1(`invalid <transition> mode: ${mode}`);
  2678. }
  2679. // at this point children has a guaranteed length of 1.
  2680. const child = children[0];
  2681. if (state.isLeaving) {
  2682. return emptyPlaceholder(child);
  2683. }
  2684. // in the case of <transition><keep-alive/></transition>, we need to
  2685. // compare the type of the kept-alive children.
  2686. const innerChild = getKeepAliveChild(child);
  2687. if (!innerChild) {
  2688. return emptyPlaceholder(child);
  2689. }
  2690. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  2691. setTransitionHooks(innerChild, enterHooks);
  2692. const oldChild = instance.subTree;
  2693. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  2694. let transitionKeyChanged = false;
  2695. const { getTransitionKey } = innerChild.type;
  2696. if (getTransitionKey) {
  2697. const key = getTransitionKey();
  2698. if (prevTransitionKey === undefined) {
  2699. prevTransitionKey = key;
  2700. }
  2701. else if (key !== prevTransitionKey) {
  2702. prevTransitionKey = key;
  2703. transitionKeyChanged = true;
  2704. }
  2705. }
  2706. // handle mode
  2707. if (oldInnerChild &&
  2708. oldInnerChild.type !== Comment &&
  2709. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  2710. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  2711. // update old tree's hooks in case of dynamic transition
  2712. setTransitionHooks(oldInnerChild, leavingHooks);
  2713. // switching between different views
  2714. if (mode === 'out-in') {
  2715. state.isLeaving = true;
  2716. // return placeholder node and queue update when leave finishes
  2717. leavingHooks.afterLeave = () => {
  2718. state.isLeaving = false;
  2719. instance.update();
  2720. };
  2721. return emptyPlaceholder(child);
  2722. }
  2723. else if (mode === 'in-out' && innerChild.type !== Comment) {
  2724. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  2725. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  2726. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  2727. // early removal callback
  2728. el._leaveCb = () => {
  2729. earlyRemove();
  2730. el._leaveCb = undefined;
  2731. delete enterHooks.delayedLeave;
  2732. };
  2733. enterHooks.delayedLeave = delayedLeave;
  2734. };
  2735. }
  2736. }
  2737. return child;
  2738. };
  2739. }
  2740. };
  2741. // export the public type for h/tsx inference
  2742. // also to avoid inline import() in generated d.ts files
  2743. const BaseTransition = BaseTransitionImpl;
  2744. function getLeavingNodesForType(state, vnode) {
  2745. const { leavingVNodes } = state;
  2746. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  2747. if (!leavingVNodesCache) {
  2748. leavingVNodesCache = Object.create(null);
  2749. leavingVNodes.set(vnode.type, leavingVNodesCache);
  2750. }
  2751. return leavingVNodesCache;
  2752. }
  2753. // The transition hooks are attached to the vnode as vnode.transition
  2754. // and will be called at appropriate timing in the renderer.
  2755. function resolveTransitionHooks(vnode, props, state, instance) {
  2756. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  2757. const key = String(vnode.key);
  2758. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  2759. const callHook = (hook, args) => {
  2760. hook &&
  2761. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  2762. };
  2763. const hooks = {
  2764. mode,
  2765. persisted,
  2766. beforeEnter(el) {
  2767. let hook = onBeforeEnter;
  2768. if (!state.isMounted) {
  2769. if (appear) {
  2770. hook = onBeforeAppear || onBeforeEnter;
  2771. }
  2772. else {
  2773. return;
  2774. }
  2775. }
  2776. // for same element (v-show)
  2777. if (el._leaveCb) {
  2778. el._leaveCb(true /* cancelled */);
  2779. }
  2780. // for toggled element with same key (v-if)
  2781. const leavingVNode = leavingVNodesCache[key];
  2782. if (leavingVNode &&
  2783. isSameVNodeType(vnode, leavingVNode) &&
  2784. leavingVNode.el._leaveCb) {
  2785. // force early removal (not cancelled)
  2786. leavingVNode.el._leaveCb();
  2787. }
  2788. callHook(hook, [el]);
  2789. },
  2790. enter(el) {
  2791. let hook = onEnter;
  2792. let afterHook = onAfterEnter;
  2793. let cancelHook = onEnterCancelled;
  2794. if (!state.isMounted) {
  2795. if (appear) {
  2796. hook = onAppear || onEnter;
  2797. afterHook = onAfterAppear || onAfterEnter;
  2798. cancelHook = onAppearCancelled || onEnterCancelled;
  2799. }
  2800. else {
  2801. return;
  2802. }
  2803. }
  2804. let called = false;
  2805. const done = (el._enterCb = (cancelled) => {
  2806. if (called)
  2807. return;
  2808. called = true;
  2809. if (cancelled) {
  2810. callHook(cancelHook, [el]);
  2811. }
  2812. else {
  2813. callHook(afterHook, [el]);
  2814. }
  2815. if (hooks.delayedLeave) {
  2816. hooks.delayedLeave();
  2817. }
  2818. el._enterCb = undefined;
  2819. });
  2820. if (hook) {
  2821. hook(el, done);
  2822. if (hook.length <= 1) {
  2823. done();
  2824. }
  2825. }
  2826. else {
  2827. done();
  2828. }
  2829. },
  2830. leave(el, remove) {
  2831. const key = String(vnode.key);
  2832. if (el._enterCb) {
  2833. el._enterCb(true /* cancelled */);
  2834. }
  2835. if (state.isUnmounting) {
  2836. return remove();
  2837. }
  2838. callHook(onBeforeLeave, [el]);
  2839. let called = false;
  2840. const done = (el._leaveCb = (cancelled) => {
  2841. if (called)
  2842. return;
  2843. called = true;
  2844. remove();
  2845. if (cancelled) {
  2846. callHook(onLeaveCancelled, [el]);
  2847. }
  2848. else {
  2849. callHook(onAfterLeave, [el]);
  2850. }
  2851. el._leaveCb = undefined;
  2852. if (leavingVNodesCache[key] === vnode) {
  2853. delete leavingVNodesCache[key];
  2854. }
  2855. });
  2856. leavingVNodesCache[key] = vnode;
  2857. if (onLeave) {
  2858. onLeave(el, done);
  2859. if (onLeave.length <= 1) {
  2860. done();
  2861. }
  2862. }
  2863. else {
  2864. done();
  2865. }
  2866. },
  2867. clone(vnode) {
  2868. return resolveTransitionHooks(vnode, props, state, instance);
  2869. }
  2870. };
  2871. return hooks;
  2872. }
  2873. // the placeholder really only handles one special case: KeepAlive
  2874. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  2875. // placeholder with empty content to avoid the KeepAlive instance from being
  2876. // unmounted.
  2877. function emptyPlaceholder(vnode) {
  2878. if (isKeepAlive(vnode)) {
  2879. vnode = cloneVNode(vnode);
  2880. vnode.children = null;
  2881. return vnode;
  2882. }
  2883. }
  2884. function getKeepAliveChild(vnode) {
  2885. return isKeepAlive(vnode)
  2886. ? vnode.children
  2887. ? vnode.children[0]
  2888. : undefined
  2889. : vnode;
  2890. }
  2891. function setTransitionHooks(vnode, hooks) {
  2892. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  2893. setTransitionHooks(vnode.component.subTree, hooks);
  2894. }
  2895. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  2896. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  2897. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  2898. }
  2899. else {
  2900. vnode.transition = hooks;
  2901. }
  2902. }
  2903. function getTransitionRawChildren(children, keepComment = false) {
  2904. let ret = [];
  2905. let keyedFragmentCount = 0;
  2906. for (let i = 0; i < children.length; i++) {
  2907. const child = children[i];
  2908. // handle fragment children case, e.g. v-for
  2909. if (child.type === Fragment) {
  2910. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  2911. keyedFragmentCount++;
  2912. ret = ret.concat(getTransitionRawChildren(child.children, keepComment));
  2913. }
  2914. // comment placeholders should be skipped, e.g. v-if
  2915. else if (keepComment || child.type !== Comment) {
  2916. ret.push(child);
  2917. }
  2918. }
  2919. // #1126 if a transition children list contains multiple sub fragments, these
  2920. // fragments will be merged into a flat children array. Since each v-for
  2921. // fragment may contain different static bindings inside, we need to de-op
  2922. // these children to force full diffs to ensure correct behavior.
  2923. if (keyedFragmentCount > 1) {
  2924. for (let i = 0; i < ret.length; i++) {
  2925. ret[i].patchFlag = -2 /* BAIL */;
  2926. }
  2927. }
  2928. return ret;
  2929. }
  2930. // implementation, close to no-op
  2931. function defineComponent(options) {
  2932. return isFunction(options) ? { setup: options, name: options.name } : options;
  2933. }
  2934. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  2935. function defineAsyncComponent(source) {
  2936. if (isFunction(source)) {
  2937. source = { loader: source };
  2938. }
  2939. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  2940. suspensible = true, onError: userOnError } = source;
  2941. let pendingRequest = null;
  2942. let resolvedComp;
  2943. let retries = 0;
  2944. const retry = () => {
  2945. retries++;
  2946. pendingRequest = null;
  2947. return load();
  2948. };
  2949. const load = () => {
  2950. let thisRequest;
  2951. return (pendingRequest ||
  2952. (thisRequest = pendingRequest =
  2953. loader()
  2954. .catch(err => {
  2955. err = err instanceof Error ? err : new Error(String(err));
  2956. if (userOnError) {
  2957. return new Promise((resolve, reject) => {
  2958. const userRetry = () => resolve(retry());
  2959. const userFail = () => reject(err);
  2960. userOnError(err, userRetry, userFail, retries + 1);
  2961. });
  2962. }
  2963. else {
  2964. throw err;
  2965. }
  2966. })
  2967. .then((comp) => {
  2968. if (thisRequest !== pendingRequest && pendingRequest) {
  2969. return pendingRequest;
  2970. }
  2971. if (!comp) {
  2972. warn$1(`Async component loader resolved to undefined. ` +
  2973. `If you are using retry(), make sure to return its return value.`);
  2974. }
  2975. // interop module default
  2976. if (comp &&
  2977. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  2978. comp = comp.default;
  2979. }
  2980. if (comp && !isObject(comp) && !isFunction(comp)) {
  2981. throw new Error(`Invalid async component load result: ${comp}`);
  2982. }
  2983. resolvedComp = comp;
  2984. return comp;
  2985. })));
  2986. };
  2987. return defineComponent({
  2988. name: 'AsyncComponentWrapper',
  2989. __asyncLoader: load,
  2990. get __asyncResolved() {
  2991. return resolvedComp;
  2992. },
  2993. setup() {
  2994. const instance = currentInstance;
  2995. // already resolved
  2996. if (resolvedComp) {
  2997. return () => createInnerComp(resolvedComp, instance);
  2998. }
  2999. const onError = (err) => {
  3000. pendingRequest = null;
  3001. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3002. };
  3003. // suspense-controlled or SSR.
  3004. if ((suspensible && instance.suspense) ||
  3005. (false )) {
  3006. return load()
  3007. .then(comp => {
  3008. return () => createInnerComp(comp, instance);
  3009. })
  3010. .catch(err => {
  3011. onError(err);
  3012. return () => errorComponent
  3013. ? createVNode(errorComponent, {
  3014. error: err
  3015. })
  3016. : null;
  3017. });
  3018. }
  3019. const loaded = ref(false);
  3020. const error = ref();
  3021. const delayed = ref(!!delay);
  3022. if (delay) {
  3023. setTimeout(() => {
  3024. delayed.value = false;
  3025. }, delay);
  3026. }
  3027. if (timeout != null) {
  3028. setTimeout(() => {
  3029. if (!loaded.value && !error.value) {
  3030. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3031. onError(err);
  3032. error.value = err;
  3033. }
  3034. }, timeout);
  3035. }
  3036. load()
  3037. .then(() => {
  3038. loaded.value = true;
  3039. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3040. // parent is keep-alive, force update so the loaded component's
  3041. // name is taken into account
  3042. queueJob(instance.parent.update);
  3043. }
  3044. })
  3045. .catch(err => {
  3046. onError(err);
  3047. error.value = err;
  3048. });
  3049. return () => {
  3050. if (loaded.value && resolvedComp) {
  3051. return createInnerComp(resolvedComp, instance);
  3052. }
  3053. else if (error.value && errorComponent) {
  3054. return createVNode(errorComponent, {
  3055. error: error.value
  3056. });
  3057. }
  3058. else if (loadingComponent && !delayed.value) {
  3059. return createVNode(loadingComponent);
  3060. }
  3061. };
  3062. }
  3063. });
  3064. }
  3065. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  3066. const vnode = createVNode(comp, props, children);
  3067. // ensure inner component inherits the async wrapper's ref owner
  3068. vnode.ref = ref;
  3069. return vnode;
  3070. }
  3071. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3072. const KeepAliveImpl = {
  3073. name: `KeepAlive`,
  3074. // Marker for special handling inside the renderer. We are not using a ===
  3075. // check directly on KeepAlive in the renderer, because importing it directly
  3076. // would prevent it from being tree-shaken.
  3077. __isKeepAlive: true,
  3078. props: {
  3079. include: [String, RegExp, Array],
  3080. exclude: [String, RegExp, Array],
  3081. max: [String, Number]
  3082. },
  3083. setup(props, { slots }) {
  3084. const instance = getCurrentInstance();
  3085. // KeepAlive communicates with the instantiated renderer via the
  3086. // ctx where the renderer passes in its internals,
  3087. // and the KeepAlive instance exposes activate/deactivate implementations.
  3088. // The whole point of this is to avoid importing KeepAlive directly in the
  3089. // renderer to facilitate tree-shaking.
  3090. const sharedContext = instance.ctx;
  3091. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  3092. // for KeepAlive, we just need to render its children
  3093. if (!sharedContext.renderer) {
  3094. return slots.default;
  3095. }
  3096. const cache = new Map();
  3097. const keys = new Set();
  3098. let current = null;
  3099. {
  3100. instance.__v_cache = cache;
  3101. }
  3102. const parentSuspense = instance.suspense;
  3103. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3104. const storageContainer = createElement('div');
  3105. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3106. const instance = vnode.component;
  3107. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3108. // in case props have changed
  3109. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3110. queuePostRenderEffect(() => {
  3111. instance.isDeactivated = false;
  3112. if (instance.a) {
  3113. invokeArrayFns(instance.a);
  3114. }
  3115. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3116. if (vnodeHook) {
  3117. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3118. }
  3119. }, parentSuspense);
  3120. {
  3121. // Update components tree
  3122. devtoolsComponentAdded(instance);
  3123. }
  3124. };
  3125. sharedContext.deactivate = (vnode) => {
  3126. const instance = vnode.component;
  3127. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3128. queuePostRenderEffect(() => {
  3129. if (instance.da) {
  3130. invokeArrayFns(instance.da);
  3131. }
  3132. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3133. if (vnodeHook) {
  3134. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3135. }
  3136. instance.isDeactivated = true;
  3137. }, parentSuspense);
  3138. {
  3139. // Update components tree
  3140. devtoolsComponentAdded(instance);
  3141. }
  3142. };
  3143. function unmount(vnode) {
  3144. // reset the shapeFlag so it can be properly unmounted
  3145. resetShapeFlag(vnode);
  3146. _unmount(vnode, instance, parentSuspense);
  3147. }
  3148. function pruneCache(filter) {
  3149. cache.forEach((vnode, key) => {
  3150. const name = getComponentName(vnode.type);
  3151. if (name && (!filter || !filter(name))) {
  3152. pruneCacheEntry(key);
  3153. }
  3154. });
  3155. }
  3156. function pruneCacheEntry(key) {
  3157. const cached = cache.get(key);
  3158. if (!current || cached.type !== current.type) {
  3159. unmount(cached);
  3160. }
  3161. else if (current) {
  3162. // current active instance should no longer be kept-alive.
  3163. // we can't unmount it now but it might be later, so reset its flag now.
  3164. resetShapeFlag(current);
  3165. }
  3166. cache.delete(key);
  3167. keys.delete(key);
  3168. }
  3169. // prune cache on include/exclude prop change
  3170. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3171. include && pruneCache(name => matches(include, name));
  3172. exclude && pruneCache(name => !matches(exclude, name));
  3173. },
  3174. // prune post-render after `current` has been updated
  3175. { flush: 'post', deep: true });
  3176. // cache sub tree after render
  3177. let pendingCacheKey = null;
  3178. const cacheSubtree = () => {
  3179. // fix #1621, the pendingCacheKey could be 0
  3180. if (pendingCacheKey != null) {
  3181. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3182. }
  3183. };
  3184. onMounted(cacheSubtree);
  3185. onUpdated(cacheSubtree);
  3186. onBeforeUnmount(() => {
  3187. cache.forEach(cached => {
  3188. const { subTree, suspense } = instance;
  3189. const vnode = getInnerChild(subTree);
  3190. if (cached.type === vnode.type) {
  3191. // current instance will be unmounted as part of keep-alive's unmount
  3192. resetShapeFlag(vnode);
  3193. // but invoke its deactivated hook here
  3194. const da = vnode.component.da;
  3195. da && queuePostRenderEffect(da, suspense);
  3196. return;
  3197. }
  3198. unmount(cached);
  3199. });
  3200. });
  3201. return () => {
  3202. pendingCacheKey = null;
  3203. if (!slots.default) {
  3204. return null;
  3205. }
  3206. const children = slots.default();
  3207. const rawVNode = children[0];
  3208. if (children.length > 1) {
  3209. {
  3210. warn$1(`KeepAlive should contain exactly one component child.`);
  3211. }
  3212. current = null;
  3213. return children;
  3214. }
  3215. else if (!isVNode(rawVNode) ||
  3216. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  3217. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  3218. current = null;
  3219. return rawVNode;
  3220. }
  3221. let vnode = getInnerChild(rawVNode);
  3222. const comp = vnode.type;
  3223. // for async components, name check should be based in its loaded
  3224. // inner component if available
  3225. const name = getComponentName(isAsyncWrapper(vnode)
  3226. ? vnode.type.__asyncResolved || {}
  3227. : comp);
  3228. const { include, exclude, max } = props;
  3229. if ((include && (!name || !matches(include, name))) ||
  3230. (exclude && name && matches(exclude, name))) {
  3231. current = vnode;
  3232. return rawVNode;
  3233. }
  3234. const key = vnode.key == null ? comp : vnode.key;
  3235. const cachedVNode = cache.get(key);
  3236. // clone vnode if it's reused because we are going to mutate it
  3237. if (vnode.el) {
  3238. vnode = cloneVNode(vnode);
  3239. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  3240. rawVNode.ssContent = vnode;
  3241. }
  3242. }
  3243. // #1513 it's possible for the returned vnode to be cloned due to attr
  3244. // fallthrough or scopeId, so the vnode here may not be the final vnode
  3245. // that is mounted. Instead of caching it directly, we store the pending
  3246. // key and cache `instance.subTree` (the normalized vnode) in
  3247. // beforeMount/beforeUpdate hooks.
  3248. pendingCacheKey = key;
  3249. if (cachedVNode) {
  3250. // copy over mounted state
  3251. vnode.el = cachedVNode.el;
  3252. vnode.component = cachedVNode.component;
  3253. if (vnode.transition) {
  3254. // recursively update transition hooks on subTree
  3255. setTransitionHooks(vnode, vnode.transition);
  3256. }
  3257. // avoid vnode being mounted as fresh
  3258. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  3259. // make this key the freshest
  3260. keys.delete(key);
  3261. keys.add(key);
  3262. }
  3263. else {
  3264. keys.add(key);
  3265. // prune oldest entry
  3266. if (max && keys.size > parseInt(max, 10)) {
  3267. pruneCacheEntry(keys.values().next().value);
  3268. }
  3269. }
  3270. // avoid vnode being unmounted
  3271. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3272. current = vnode;
  3273. return rawVNode;
  3274. };
  3275. }
  3276. };
  3277. // export the public type for h/tsx inference
  3278. // also to avoid inline import() in generated d.ts files
  3279. const KeepAlive = KeepAliveImpl;
  3280. function matches(pattern, name) {
  3281. if (isArray(pattern)) {
  3282. return pattern.some((p) => matches(p, name));
  3283. }
  3284. else if (isString(pattern)) {
  3285. return pattern.split(',').indexOf(name) > -1;
  3286. }
  3287. else if (pattern.test) {
  3288. return pattern.test(name);
  3289. }
  3290. /* istanbul ignore next */
  3291. return false;
  3292. }
  3293. function onActivated(hook, target) {
  3294. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  3295. }
  3296. function onDeactivated(hook, target) {
  3297. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  3298. }
  3299. function registerKeepAliveHook(hook, type, target = currentInstance) {
  3300. // cache the deactivate branch check wrapper for injected hooks so the same
  3301. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  3302. // deactivation check".
  3303. const wrappedHook = hook.__wdc ||
  3304. (hook.__wdc = () => {
  3305. // only fire the hook if the target instance is NOT in a deactivated branch.
  3306. let current = target;
  3307. while (current) {
  3308. if (current.isDeactivated) {
  3309. return;
  3310. }
  3311. current = current.parent;
  3312. }
  3313. return hook();
  3314. });
  3315. injectHook(type, wrappedHook, target);
  3316. // In addition to registering it on the target instance, we walk up the parent
  3317. // chain and register it on all ancestor instances that are keep-alive roots.
  3318. // This avoids the need to walk the entire component tree when invoking these
  3319. // hooks, and more importantly, avoids the need to track child components in
  3320. // arrays.
  3321. if (target) {
  3322. let current = target.parent;
  3323. while (current && current.parent) {
  3324. if (isKeepAlive(current.parent.vnode)) {
  3325. injectToKeepAliveRoot(wrappedHook, type, target, current);
  3326. }
  3327. current = current.parent;
  3328. }
  3329. }
  3330. }
  3331. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  3332. // injectHook wraps the original for error handling, so make sure to remove
  3333. // the wrapped version.
  3334. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  3335. onUnmounted(() => {
  3336. remove(keepAliveRoot[type], injected);
  3337. }, target);
  3338. }
  3339. function resetShapeFlag(vnode) {
  3340. let shapeFlag = vnode.shapeFlag;
  3341. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  3342. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3343. }
  3344. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  3345. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  3346. }
  3347. vnode.shapeFlag = shapeFlag;
  3348. }
  3349. function getInnerChild(vnode) {
  3350. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  3351. }
  3352. function injectHook(type, hook, target = currentInstance, prepend = false) {
  3353. if (target) {
  3354. const hooks = target[type] || (target[type] = []);
  3355. // cache the error handling wrapper for injected hooks so the same hook
  3356. // can be properly deduped by the scheduler. "__weh" stands for "with error
  3357. // handling".
  3358. const wrappedHook = hook.__weh ||
  3359. (hook.__weh = (...args) => {
  3360. if (target.isUnmounted) {
  3361. return;
  3362. }
  3363. // disable tracking inside all lifecycle hooks
  3364. // since they can potentially be called inside effects.
  3365. pauseTracking();
  3366. // Set currentInstance during hook invocation.
  3367. // This assumes the hook does not synchronously trigger other hooks, which
  3368. // can only be false when the user does something really funky.
  3369. setCurrentInstance(target);
  3370. const res = callWithAsyncErrorHandling(hook, target, type, args);
  3371. unsetCurrentInstance();
  3372. resetTracking();
  3373. return res;
  3374. });
  3375. if (prepend) {
  3376. hooks.unshift(wrappedHook);
  3377. }
  3378. else {
  3379. hooks.push(wrappedHook);
  3380. }
  3381. return wrappedHook;
  3382. }
  3383. else {
  3384. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  3385. warn$1(`${apiName} is called when there is no active component instance to be ` +
  3386. `associated with. ` +
  3387. `Lifecycle injection APIs can only be used during execution of setup().` +
  3388. (` If you are using async setup(), make sure to register lifecycle ` +
  3389. `hooks before the first await statement.`
  3390. ));
  3391. }
  3392. }
  3393. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  3394. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  3395. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  3396. injectHook(lifecycle, hook, target);
  3397. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  3398. const onMounted = createHook("m" /* MOUNTED */);
  3399. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  3400. const onUpdated = createHook("u" /* UPDATED */);
  3401. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  3402. const onUnmounted = createHook("um" /* UNMOUNTED */);
  3403. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  3404. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  3405. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  3406. function onErrorCaptured(hook, target = currentInstance) {
  3407. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  3408. }
  3409. function createDuplicateChecker() {
  3410. const cache = Object.create(null);
  3411. return (type, key) => {
  3412. if (cache[key]) {
  3413. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  3414. }
  3415. else {
  3416. cache[key] = type;
  3417. }
  3418. };
  3419. }
  3420. let shouldCacheAccess = true;
  3421. function applyOptions(instance) {
  3422. const options = resolveMergedOptions(instance);
  3423. const publicThis = instance.proxy;
  3424. const ctx = instance.ctx;
  3425. // do not cache property access on public proxy during state initialization
  3426. shouldCacheAccess = false;
  3427. // call beforeCreate first before accessing other options since
  3428. // the hook may mutate resolved options (#2791)
  3429. if (options.beforeCreate) {
  3430. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  3431. }
  3432. const {
  3433. // state
  3434. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  3435. // lifecycle
  3436. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  3437. // public API
  3438. expose, inheritAttrs,
  3439. // assets
  3440. components, directives, filters } = options;
  3441. const checkDuplicateProperties = createDuplicateChecker() ;
  3442. {
  3443. const [propsOptions] = instance.propsOptions;
  3444. if (propsOptions) {
  3445. for (const key in propsOptions) {
  3446. checkDuplicateProperties("Props" /* PROPS */, key);
  3447. }
  3448. }
  3449. }
  3450. // options initialization order (to be consistent with Vue 2):
  3451. // - props (already done outside of this function)
  3452. // - inject
  3453. // - methods
  3454. // - data (deferred since it relies on `this` access)
  3455. // - computed
  3456. // - watch (deferred since it relies on `this` access)
  3457. if (injectOptions) {
  3458. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  3459. }
  3460. if (methods) {
  3461. for (const key in methods) {
  3462. const methodHandler = methods[key];
  3463. if (isFunction(methodHandler)) {
  3464. // In dev mode, we use the `createRenderContext` function to define
  3465. // methods to the proxy target, and those are read-only but
  3466. // reconfigurable, so it needs to be redefined here
  3467. {
  3468. Object.defineProperty(ctx, key, {
  3469. value: methodHandler.bind(publicThis),
  3470. configurable: true,
  3471. enumerable: true,
  3472. writable: true
  3473. });
  3474. }
  3475. {
  3476. checkDuplicateProperties("Methods" /* METHODS */, key);
  3477. }
  3478. }
  3479. else {
  3480. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  3481. `Did you reference the function correctly?`);
  3482. }
  3483. }
  3484. }
  3485. if (dataOptions) {
  3486. if (!isFunction(dataOptions)) {
  3487. warn$1(`The data option must be a function. ` +
  3488. `Plain object usage is no longer supported.`);
  3489. }
  3490. const data = dataOptions.call(publicThis, publicThis);
  3491. if (isPromise(data)) {
  3492. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  3493. `intend to perform data fetching before component renders, use ` +
  3494. `async setup() + <Suspense>.`);
  3495. }
  3496. if (!isObject(data)) {
  3497. warn$1(`data() should return an object.`);
  3498. }
  3499. else {
  3500. instance.data = reactive(data);
  3501. {
  3502. for (const key in data) {
  3503. checkDuplicateProperties("Data" /* DATA */, key);
  3504. // expose data on ctx during dev
  3505. if (key[0] !== '$' && key[0] !== '_') {
  3506. Object.defineProperty(ctx, key, {
  3507. configurable: true,
  3508. enumerable: true,
  3509. get: () => data[key],
  3510. set: NOOP
  3511. });
  3512. }
  3513. }
  3514. }
  3515. }
  3516. }
  3517. // state initialization complete at this point - start caching access
  3518. shouldCacheAccess = true;
  3519. if (computedOptions) {
  3520. for (const key in computedOptions) {
  3521. const opt = computedOptions[key];
  3522. const get = isFunction(opt)
  3523. ? opt.bind(publicThis, publicThis)
  3524. : isFunction(opt.get)
  3525. ? opt.get.bind(publicThis, publicThis)
  3526. : NOOP;
  3527. if (get === NOOP) {
  3528. warn$1(`Computed property "${key}" has no getter.`);
  3529. }
  3530. const set = !isFunction(opt) && isFunction(opt.set)
  3531. ? opt.set.bind(publicThis)
  3532. : () => {
  3533. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  3534. }
  3535. ;
  3536. const c = computed({
  3537. get,
  3538. set
  3539. });
  3540. Object.defineProperty(ctx, key, {
  3541. enumerable: true,
  3542. configurable: true,
  3543. get: () => c.value,
  3544. set: v => (c.value = v)
  3545. });
  3546. {
  3547. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  3548. }
  3549. }
  3550. }
  3551. if (watchOptions) {
  3552. for (const key in watchOptions) {
  3553. createWatcher(watchOptions[key], ctx, publicThis, key);
  3554. }
  3555. }
  3556. if (provideOptions) {
  3557. const provides = isFunction(provideOptions)
  3558. ? provideOptions.call(publicThis)
  3559. : provideOptions;
  3560. Reflect.ownKeys(provides).forEach(key => {
  3561. provide(key, provides[key]);
  3562. });
  3563. }
  3564. if (created) {
  3565. callHook(created, instance, "c" /* CREATED */);
  3566. }
  3567. function registerLifecycleHook(register, hook) {
  3568. if (isArray(hook)) {
  3569. hook.forEach(_hook => register(_hook.bind(publicThis)));
  3570. }
  3571. else if (hook) {
  3572. register(hook.bind(publicThis));
  3573. }
  3574. }
  3575. registerLifecycleHook(onBeforeMount, beforeMount);
  3576. registerLifecycleHook(onMounted, mounted);
  3577. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  3578. registerLifecycleHook(onUpdated, updated);
  3579. registerLifecycleHook(onActivated, activated);
  3580. registerLifecycleHook(onDeactivated, deactivated);
  3581. registerLifecycleHook(onErrorCaptured, errorCaptured);
  3582. registerLifecycleHook(onRenderTracked, renderTracked);
  3583. registerLifecycleHook(onRenderTriggered, renderTriggered);
  3584. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  3585. registerLifecycleHook(onUnmounted, unmounted);
  3586. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  3587. if (isArray(expose)) {
  3588. if (expose.length) {
  3589. const exposed = instance.exposed || (instance.exposed = {});
  3590. expose.forEach(key => {
  3591. Object.defineProperty(exposed, key, {
  3592. get: () => publicThis[key],
  3593. set: val => (publicThis[key] = val)
  3594. });
  3595. });
  3596. }
  3597. else if (!instance.exposed) {
  3598. instance.exposed = {};
  3599. }
  3600. }
  3601. // options that are handled when creating the instance but also need to be
  3602. // applied from mixins
  3603. if (render && instance.render === NOOP) {
  3604. instance.render = render;
  3605. }
  3606. if (inheritAttrs != null) {
  3607. instance.inheritAttrs = inheritAttrs;
  3608. }
  3609. // asset options.
  3610. if (components)
  3611. instance.components = components;
  3612. if (directives)
  3613. instance.directives = directives;
  3614. }
  3615. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  3616. if (isArray(injectOptions)) {
  3617. injectOptions = normalizeInject(injectOptions);
  3618. }
  3619. for (const key in injectOptions) {
  3620. const opt = injectOptions[key];
  3621. let injected;
  3622. if (isObject(opt)) {
  3623. if ('default' in opt) {
  3624. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  3625. }
  3626. else {
  3627. injected = inject(opt.from || key);
  3628. }
  3629. }
  3630. else {
  3631. injected = inject(opt);
  3632. }
  3633. if (isRef(injected)) {
  3634. // TODO remove the check in 3.3
  3635. if (unwrapRef) {
  3636. Object.defineProperty(ctx, key, {
  3637. enumerable: true,
  3638. configurable: true,
  3639. get: () => injected.value,
  3640. set: v => (injected.value = v)
  3641. });
  3642. }
  3643. else {
  3644. {
  3645. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  3646. `and no longer needs \`.value\` in the next minor release. ` +
  3647. `To opt-in to the new behavior now, ` +
  3648. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  3649. `temporary and will not be needed in the future.)`);
  3650. }
  3651. ctx[key] = injected;
  3652. }
  3653. }
  3654. else {
  3655. ctx[key] = injected;
  3656. }
  3657. {
  3658. checkDuplicateProperties("Inject" /* INJECT */, key);
  3659. }
  3660. }
  3661. }
  3662. function callHook(hook, instance, type) {
  3663. callWithAsyncErrorHandling(isArray(hook)
  3664. ? hook.map(h => h.bind(instance.proxy))
  3665. : hook.bind(instance.proxy), instance, type);
  3666. }
  3667. function createWatcher(raw, ctx, publicThis, key) {
  3668. const getter = key.includes('.')
  3669. ? createPathGetter(publicThis, key)
  3670. : () => publicThis[key];
  3671. if (isString(raw)) {
  3672. const handler = ctx[raw];
  3673. if (isFunction(handler)) {
  3674. watch(getter, handler);
  3675. }
  3676. else {
  3677. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  3678. }
  3679. }
  3680. else if (isFunction(raw)) {
  3681. watch(getter, raw.bind(publicThis));
  3682. }
  3683. else if (isObject(raw)) {
  3684. if (isArray(raw)) {
  3685. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  3686. }
  3687. else {
  3688. const handler = isFunction(raw.handler)
  3689. ? raw.handler.bind(publicThis)
  3690. : ctx[raw.handler];
  3691. if (isFunction(handler)) {
  3692. watch(getter, handler, raw);
  3693. }
  3694. else {
  3695. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  3696. }
  3697. }
  3698. }
  3699. else {
  3700. warn$1(`Invalid watch option: "${key}"`, raw);
  3701. }
  3702. }
  3703. /**
  3704. * Resolve merged options and cache it on the component.
  3705. * This is done only once per-component since the merging does not involve
  3706. * instances.
  3707. */
  3708. function resolveMergedOptions(instance) {
  3709. const base = instance.type;
  3710. const { mixins, extends: extendsOptions } = base;
  3711. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  3712. const cached = cache.get(base);
  3713. let resolved;
  3714. if (cached) {
  3715. resolved = cached;
  3716. }
  3717. else if (!globalMixins.length && !mixins && !extendsOptions) {
  3718. {
  3719. resolved = base;
  3720. }
  3721. }
  3722. else {
  3723. resolved = {};
  3724. if (globalMixins.length) {
  3725. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  3726. }
  3727. mergeOptions(resolved, base, optionMergeStrategies);
  3728. }
  3729. cache.set(base, resolved);
  3730. return resolved;
  3731. }
  3732. function mergeOptions(to, from, strats, asMixin = false) {
  3733. const { mixins, extends: extendsOptions } = from;
  3734. if (extendsOptions) {
  3735. mergeOptions(to, extendsOptions, strats, true);
  3736. }
  3737. if (mixins) {
  3738. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  3739. }
  3740. for (const key in from) {
  3741. if (asMixin && key === 'expose') {
  3742. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  3743. `It should only be declared in the base component itself.`);
  3744. }
  3745. else {
  3746. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  3747. to[key] = strat ? strat(to[key], from[key]) : from[key];
  3748. }
  3749. }
  3750. return to;
  3751. }
  3752. const internalOptionMergeStrats = {
  3753. data: mergeDataFn,
  3754. props: mergeObjectOptions,
  3755. emits: mergeObjectOptions,
  3756. // objects
  3757. methods: mergeObjectOptions,
  3758. computed: mergeObjectOptions,
  3759. // lifecycle
  3760. beforeCreate: mergeAsArray,
  3761. created: mergeAsArray,
  3762. beforeMount: mergeAsArray,
  3763. mounted: mergeAsArray,
  3764. beforeUpdate: mergeAsArray,
  3765. updated: mergeAsArray,
  3766. beforeDestroy: mergeAsArray,
  3767. beforeUnmount: mergeAsArray,
  3768. destroyed: mergeAsArray,
  3769. unmounted: mergeAsArray,
  3770. activated: mergeAsArray,
  3771. deactivated: mergeAsArray,
  3772. errorCaptured: mergeAsArray,
  3773. serverPrefetch: mergeAsArray,
  3774. // assets
  3775. components: mergeObjectOptions,
  3776. directives: mergeObjectOptions,
  3777. // watch
  3778. watch: mergeWatchOptions,
  3779. // provide / inject
  3780. provide: mergeDataFn,
  3781. inject: mergeInject
  3782. };
  3783. function mergeDataFn(to, from) {
  3784. if (!from) {
  3785. return to;
  3786. }
  3787. if (!to) {
  3788. return from;
  3789. }
  3790. return function mergedDataFn() {
  3791. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  3792. };
  3793. }
  3794. function mergeInject(to, from) {
  3795. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  3796. }
  3797. function normalizeInject(raw) {
  3798. if (isArray(raw)) {
  3799. const res = {};
  3800. for (let i = 0; i < raw.length; i++) {
  3801. res[raw[i]] = raw[i];
  3802. }
  3803. return res;
  3804. }
  3805. return raw;
  3806. }
  3807. function mergeAsArray(to, from) {
  3808. return to ? [...new Set([].concat(to, from))] : from;
  3809. }
  3810. function mergeObjectOptions(to, from) {
  3811. return to ? extend(extend(Object.create(null), to), from) : from;
  3812. }
  3813. function mergeWatchOptions(to, from) {
  3814. if (!to)
  3815. return from;
  3816. if (!from)
  3817. return to;
  3818. const merged = extend(Object.create(null), to);
  3819. for (const key in from) {
  3820. merged[key] = mergeAsArray(to[key], from[key]);
  3821. }
  3822. return merged;
  3823. }
  3824. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  3825. isSSR = false) {
  3826. const props = {};
  3827. const attrs = {};
  3828. def(attrs, InternalObjectKey, 1);
  3829. instance.propsDefaults = Object.create(null);
  3830. setFullProps(instance, rawProps, props, attrs);
  3831. // ensure all declared prop keys are present
  3832. for (const key in instance.propsOptions[0]) {
  3833. if (!(key in props)) {
  3834. props[key] = undefined;
  3835. }
  3836. }
  3837. // validation
  3838. {
  3839. validateProps(rawProps || {}, props, instance);
  3840. }
  3841. if (isStateful) {
  3842. // stateful
  3843. instance.props = isSSR ? props : shallowReactive(props);
  3844. }
  3845. else {
  3846. if (!instance.type.props) {
  3847. // functional w/ optional props, props === attrs
  3848. instance.props = attrs;
  3849. }
  3850. else {
  3851. // functional w/ declared props
  3852. instance.props = props;
  3853. }
  3854. }
  3855. instance.attrs = attrs;
  3856. }
  3857. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  3858. const { props, attrs, vnode: { patchFlag } } = instance;
  3859. const rawCurrentProps = toRaw(props);
  3860. const [options] = instance.propsOptions;
  3861. let hasAttrsChanged = false;
  3862. if (
  3863. // always force full diff in dev
  3864. // - #1942 if hmr is enabled with sfc component
  3865. // - vite#872 non-sfc component used by sfc component
  3866. !((instance.type.__hmrId ||
  3867. (instance.parent && instance.parent.type.__hmrId))) &&
  3868. (optimized || patchFlag > 0) &&
  3869. !(patchFlag & 16 /* FULL_PROPS */)) {
  3870. if (patchFlag & 8 /* PROPS */) {
  3871. // Compiler-generated props & no keys change, just set the updated
  3872. // the props.
  3873. const propsToUpdate = instance.vnode.dynamicProps;
  3874. for (let i = 0; i < propsToUpdate.length; i++) {
  3875. let key = propsToUpdate[i];
  3876. // PROPS flag guarantees rawProps to be non-null
  3877. const value = rawProps[key];
  3878. if (options) {
  3879. // attr / props separation was done on init and will be consistent
  3880. // in this code path, so just check if attrs have it.
  3881. if (hasOwn(attrs, key)) {
  3882. if (value !== attrs[key]) {
  3883. attrs[key] = value;
  3884. hasAttrsChanged = true;
  3885. }
  3886. }
  3887. else {
  3888. const camelizedKey = camelize(key);
  3889. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  3890. }
  3891. }
  3892. else {
  3893. if (value !== attrs[key]) {
  3894. attrs[key] = value;
  3895. hasAttrsChanged = true;
  3896. }
  3897. }
  3898. }
  3899. }
  3900. }
  3901. else {
  3902. // full props update.
  3903. if (setFullProps(instance, rawProps, props, attrs)) {
  3904. hasAttrsChanged = true;
  3905. }
  3906. // in case of dynamic props, check if we need to delete keys from
  3907. // the props object
  3908. let kebabKey;
  3909. for (const key in rawCurrentProps) {
  3910. if (!rawProps ||
  3911. // for camelCase
  3912. (!hasOwn(rawProps, key) &&
  3913. // it's possible the original props was passed in as kebab-case
  3914. // and converted to camelCase (#955)
  3915. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  3916. if (options) {
  3917. if (rawPrevProps &&
  3918. // for camelCase
  3919. (rawPrevProps[key] !== undefined ||
  3920. // for kebab-case
  3921. rawPrevProps[kebabKey] !== undefined)) {
  3922. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  3923. }
  3924. }
  3925. else {
  3926. delete props[key];
  3927. }
  3928. }
  3929. }
  3930. // in the case of functional component w/o props declaration, props and
  3931. // attrs point to the same object so it should already have been updated.
  3932. if (attrs !== rawCurrentProps) {
  3933. for (const key in attrs) {
  3934. if (!rawProps || !hasOwn(rawProps, key)) {
  3935. delete attrs[key];
  3936. hasAttrsChanged = true;
  3937. }
  3938. }
  3939. }
  3940. }
  3941. // trigger updates for $attrs in case it's used in component slots
  3942. if (hasAttrsChanged) {
  3943. trigger(instance, "set" /* SET */, '$attrs');
  3944. }
  3945. {
  3946. validateProps(rawProps || {}, props, instance);
  3947. }
  3948. }
  3949. function setFullProps(instance, rawProps, props, attrs) {
  3950. const [options, needCastKeys] = instance.propsOptions;
  3951. let hasAttrsChanged = false;
  3952. let rawCastValues;
  3953. if (rawProps) {
  3954. for (let key in rawProps) {
  3955. // key, ref are reserved and never passed down
  3956. if (isReservedProp(key)) {
  3957. continue;
  3958. }
  3959. const value = rawProps[key];
  3960. // prop option names are camelized during normalization, so to support
  3961. // kebab -> camel conversion here we need to camelize the key.
  3962. let camelKey;
  3963. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  3964. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  3965. props[camelKey] = value;
  3966. }
  3967. else {
  3968. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  3969. }
  3970. }
  3971. else if (!isEmitListener(instance.emitsOptions, key)) {
  3972. if (!(key in attrs) || value !== attrs[key]) {
  3973. attrs[key] = value;
  3974. hasAttrsChanged = true;
  3975. }
  3976. }
  3977. }
  3978. }
  3979. if (needCastKeys) {
  3980. const rawCurrentProps = toRaw(props);
  3981. const castValues = rawCastValues || EMPTY_OBJ;
  3982. for (let i = 0; i < needCastKeys.length; i++) {
  3983. const key = needCastKeys[i];
  3984. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  3985. }
  3986. }
  3987. return hasAttrsChanged;
  3988. }
  3989. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  3990. const opt = options[key];
  3991. if (opt != null) {
  3992. const hasDefault = hasOwn(opt, 'default');
  3993. // default values
  3994. if (hasDefault && value === undefined) {
  3995. const defaultValue = opt.default;
  3996. if (opt.type !== Function && isFunction(defaultValue)) {
  3997. const { propsDefaults } = instance;
  3998. if (key in propsDefaults) {
  3999. value = propsDefaults[key];
  4000. }
  4001. else {
  4002. setCurrentInstance(instance);
  4003. value = propsDefaults[key] = defaultValue.call(null, props);
  4004. unsetCurrentInstance();
  4005. }
  4006. }
  4007. else {
  4008. value = defaultValue;
  4009. }
  4010. }
  4011. // boolean casting
  4012. if (opt[0 /* shouldCast */]) {
  4013. if (isAbsent && !hasDefault) {
  4014. value = false;
  4015. }
  4016. else if (opt[1 /* shouldCastTrue */] &&
  4017. (value === '' || value === hyphenate(key))) {
  4018. value = true;
  4019. }
  4020. }
  4021. }
  4022. return value;
  4023. }
  4024. function normalizePropsOptions(comp, appContext, asMixin = false) {
  4025. const cache = appContext.propsCache;
  4026. const cached = cache.get(comp);
  4027. if (cached) {
  4028. return cached;
  4029. }
  4030. const raw = comp.props;
  4031. const normalized = {};
  4032. const needCastKeys = [];
  4033. // apply mixin/extends props
  4034. let hasExtends = false;
  4035. if (!isFunction(comp)) {
  4036. const extendProps = (raw) => {
  4037. hasExtends = true;
  4038. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  4039. extend(normalized, props);
  4040. if (keys)
  4041. needCastKeys.push(...keys);
  4042. };
  4043. if (!asMixin && appContext.mixins.length) {
  4044. appContext.mixins.forEach(extendProps);
  4045. }
  4046. if (comp.extends) {
  4047. extendProps(comp.extends);
  4048. }
  4049. if (comp.mixins) {
  4050. comp.mixins.forEach(extendProps);
  4051. }
  4052. }
  4053. if (!raw && !hasExtends) {
  4054. cache.set(comp, EMPTY_ARR);
  4055. return EMPTY_ARR;
  4056. }
  4057. if (isArray(raw)) {
  4058. for (let i = 0; i < raw.length; i++) {
  4059. if (!isString(raw[i])) {
  4060. warn$1(`props must be strings when using array syntax.`, raw[i]);
  4061. }
  4062. const normalizedKey = camelize(raw[i]);
  4063. if (validatePropName(normalizedKey)) {
  4064. normalized[normalizedKey] = EMPTY_OBJ;
  4065. }
  4066. }
  4067. }
  4068. else if (raw) {
  4069. if (!isObject(raw)) {
  4070. warn$1(`invalid props options`, raw);
  4071. }
  4072. for (const key in raw) {
  4073. const normalizedKey = camelize(key);
  4074. if (validatePropName(normalizedKey)) {
  4075. const opt = raw[key];
  4076. const prop = (normalized[normalizedKey] =
  4077. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  4078. if (prop) {
  4079. const booleanIndex = getTypeIndex(Boolean, prop.type);
  4080. const stringIndex = getTypeIndex(String, prop.type);
  4081. prop[0 /* shouldCast */] = booleanIndex > -1;
  4082. prop[1 /* shouldCastTrue */] =
  4083. stringIndex < 0 || booleanIndex < stringIndex;
  4084. // if the prop needs boolean casting or default value
  4085. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  4086. needCastKeys.push(normalizedKey);
  4087. }
  4088. }
  4089. }
  4090. }
  4091. }
  4092. const res = [normalized, needCastKeys];
  4093. cache.set(comp, res);
  4094. return res;
  4095. }
  4096. function validatePropName(key) {
  4097. if (key[0] !== '$') {
  4098. return true;
  4099. }
  4100. else {
  4101. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  4102. }
  4103. return false;
  4104. }
  4105. // use function string name to check type constructors
  4106. // so that it works across vms / iframes.
  4107. function getType(ctor) {
  4108. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  4109. return match ? match[1] : ctor === null ? 'null' : '';
  4110. }
  4111. function isSameType(a, b) {
  4112. return getType(a) === getType(b);
  4113. }
  4114. function getTypeIndex(type, expectedTypes) {
  4115. if (isArray(expectedTypes)) {
  4116. return expectedTypes.findIndex(t => isSameType(t, type));
  4117. }
  4118. else if (isFunction(expectedTypes)) {
  4119. return isSameType(expectedTypes, type) ? 0 : -1;
  4120. }
  4121. return -1;
  4122. }
  4123. /**
  4124. * dev only
  4125. */
  4126. function validateProps(rawProps, props, instance) {
  4127. const resolvedValues = toRaw(props);
  4128. const options = instance.propsOptions[0];
  4129. for (const key in options) {
  4130. let opt = options[key];
  4131. if (opt == null)
  4132. continue;
  4133. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  4134. }
  4135. }
  4136. /**
  4137. * dev only
  4138. */
  4139. function validateProp(name, value, prop, isAbsent) {
  4140. const { type, required, validator } = prop;
  4141. // required!
  4142. if (required && isAbsent) {
  4143. warn$1('Missing required prop: "' + name + '"');
  4144. return;
  4145. }
  4146. // missing but optional
  4147. if (value == null && !prop.required) {
  4148. return;
  4149. }
  4150. // type check
  4151. if (type != null && type !== true) {
  4152. let isValid = false;
  4153. const types = isArray(type) ? type : [type];
  4154. const expectedTypes = [];
  4155. // value is valid as long as one of the specified types match
  4156. for (let i = 0; i < types.length && !isValid; i++) {
  4157. const { valid, expectedType } = assertType(value, types[i]);
  4158. expectedTypes.push(expectedType || '');
  4159. isValid = valid;
  4160. }
  4161. if (!isValid) {
  4162. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  4163. return;
  4164. }
  4165. }
  4166. // custom validator
  4167. if (validator && !validator(value)) {
  4168. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  4169. }
  4170. }
  4171. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  4172. /**
  4173. * dev only
  4174. */
  4175. function assertType(value, type) {
  4176. let valid;
  4177. const expectedType = getType(type);
  4178. if (isSimpleType(expectedType)) {
  4179. const t = typeof value;
  4180. valid = t === expectedType.toLowerCase();
  4181. // for primitive wrapper objects
  4182. if (!valid && t === 'object') {
  4183. valid = value instanceof type;
  4184. }
  4185. }
  4186. else if (expectedType === 'Object') {
  4187. valid = isObject(value);
  4188. }
  4189. else if (expectedType === 'Array') {
  4190. valid = isArray(value);
  4191. }
  4192. else if (expectedType === 'null') {
  4193. valid = value === null;
  4194. }
  4195. else {
  4196. valid = value instanceof type;
  4197. }
  4198. return {
  4199. valid,
  4200. expectedType
  4201. };
  4202. }
  4203. /**
  4204. * dev only
  4205. */
  4206. function getInvalidTypeMessage(name, value, expectedTypes) {
  4207. let message = `Invalid prop: type check failed for prop "${name}".` +
  4208. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  4209. const expectedType = expectedTypes[0];
  4210. const receivedType = toRawType(value);
  4211. const expectedValue = styleValue(value, expectedType);
  4212. const receivedValue = styleValue(value, receivedType);
  4213. // check if we need to specify expected value
  4214. if (expectedTypes.length === 1 &&
  4215. isExplicable(expectedType) &&
  4216. !isBoolean(expectedType, receivedType)) {
  4217. message += ` with value ${expectedValue}`;
  4218. }
  4219. message += `, got ${receivedType} `;
  4220. // check if we need to specify received value
  4221. if (isExplicable(receivedType)) {
  4222. message += `with value ${receivedValue}.`;
  4223. }
  4224. return message;
  4225. }
  4226. /**
  4227. * dev only
  4228. */
  4229. function styleValue(value, type) {
  4230. if (type === 'String') {
  4231. return `"${value}"`;
  4232. }
  4233. else if (type === 'Number') {
  4234. return `${Number(value)}`;
  4235. }
  4236. else {
  4237. return `${value}`;
  4238. }
  4239. }
  4240. /**
  4241. * dev only
  4242. */
  4243. function isExplicable(type) {
  4244. const explicitTypes = ['string', 'number', 'boolean'];
  4245. return explicitTypes.some(elem => type.toLowerCase() === elem);
  4246. }
  4247. /**
  4248. * dev only
  4249. */
  4250. function isBoolean(...args) {
  4251. return args.some(elem => elem.toLowerCase() === 'boolean');
  4252. }
  4253. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  4254. const normalizeSlotValue = (value) => isArray(value)
  4255. ? value.map(normalizeVNode)
  4256. : [normalizeVNode(value)];
  4257. const normalizeSlot = (key, rawSlot, ctx) => {
  4258. const normalized = withCtx((...args) => {
  4259. if (currentInstance) {
  4260. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  4261. `this will not track dependencies used in the slot. ` +
  4262. `Invoke the slot function inside the render function instead.`);
  4263. }
  4264. return normalizeSlotValue(rawSlot(...args));
  4265. }, ctx);
  4266. normalized._c = false;
  4267. return normalized;
  4268. };
  4269. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  4270. const ctx = rawSlots._ctx;
  4271. for (const key in rawSlots) {
  4272. if (isInternalKey(key))
  4273. continue;
  4274. const value = rawSlots[key];
  4275. if (isFunction(value)) {
  4276. slots[key] = normalizeSlot(key, value, ctx);
  4277. }
  4278. else if (value != null) {
  4279. {
  4280. warn$1(`Non-function value encountered for slot "${key}". ` +
  4281. `Prefer function slots for better performance.`);
  4282. }
  4283. const normalized = normalizeSlotValue(value);
  4284. slots[key] = () => normalized;
  4285. }
  4286. }
  4287. };
  4288. const normalizeVNodeSlots = (instance, children) => {
  4289. if (!isKeepAlive(instance.vnode) &&
  4290. !(false )) {
  4291. warn$1(`Non-function value encountered for default slot. ` +
  4292. `Prefer function slots for better performance.`);
  4293. }
  4294. const normalized = normalizeSlotValue(children);
  4295. instance.slots.default = () => normalized;
  4296. };
  4297. const initSlots = (instance, children) => {
  4298. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  4299. const type = children._;
  4300. if (type) {
  4301. // users can get the shallow readonly version of the slots object through `this.$slots`,
  4302. // we should avoid the proxy object polluting the slots of the internal instance
  4303. instance.slots = toRaw(children);
  4304. // make compiler marker non-enumerable
  4305. def(children, '_', type);
  4306. }
  4307. else {
  4308. normalizeObjectSlots(children, (instance.slots = {}));
  4309. }
  4310. }
  4311. else {
  4312. instance.slots = {};
  4313. if (children) {
  4314. normalizeVNodeSlots(instance, children);
  4315. }
  4316. }
  4317. def(instance.slots, InternalObjectKey, 1);
  4318. };
  4319. const updateSlots = (instance, children, optimized) => {
  4320. const { vnode, slots } = instance;
  4321. let needDeletionCheck = true;
  4322. let deletionComparisonTarget = EMPTY_OBJ;
  4323. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  4324. const type = children._;
  4325. if (type) {
  4326. // compiled slots.
  4327. if (isHmrUpdating) {
  4328. // Parent was HMR updated so slot content may have changed.
  4329. // force update slots and mark instance for hmr as well
  4330. extend(slots, children);
  4331. }
  4332. else if (optimized && type === 1 /* STABLE */) {
  4333. // compiled AND stable.
  4334. // no need to update, and skip stale slots removal.
  4335. needDeletionCheck = false;
  4336. }
  4337. else {
  4338. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  4339. // normalization.
  4340. extend(slots, children);
  4341. // #2893
  4342. // when rendering the optimized slots by manually written render function,
  4343. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  4344. // i.e. let the `renderSlot` create the bailed Fragment
  4345. if (!optimized && type === 1 /* STABLE */) {
  4346. delete slots._;
  4347. }
  4348. }
  4349. }
  4350. else {
  4351. needDeletionCheck = !children.$stable;
  4352. normalizeObjectSlots(children, slots);
  4353. }
  4354. deletionComparisonTarget = children;
  4355. }
  4356. else if (children) {
  4357. // non slot object children (direct value) passed to a component
  4358. normalizeVNodeSlots(instance, children);
  4359. deletionComparisonTarget = { default: 1 };
  4360. }
  4361. // delete stale slots
  4362. if (needDeletionCheck) {
  4363. for (const key in slots) {
  4364. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  4365. delete slots[key];
  4366. }
  4367. }
  4368. }
  4369. };
  4370. /**
  4371. Runtime helper for applying directives to a vnode. Example usage:
  4372. const comp = resolveComponent('comp')
  4373. const foo = resolveDirective('foo')
  4374. const bar = resolveDirective('bar')
  4375. return withDirectives(h(comp), [
  4376. [foo, this.x],
  4377. [bar, this.y]
  4378. ])
  4379. */
  4380. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  4381. function validateDirectiveName(name) {
  4382. if (isBuiltInDirective(name)) {
  4383. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  4384. }
  4385. }
  4386. /**
  4387. * Adds directives to a VNode.
  4388. */
  4389. function withDirectives(vnode, directives) {
  4390. const internalInstance = currentRenderingInstance;
  4391. if (internalInstance === null) {
  4392. warn$1(`withDirectives can only be used inside render functions.`);
  4393. return vnode;
  4394. }
  4395. const instance = internalInstance.proxy;
  4396. const bindings = vnode.dirs || (vnode.dirs = []);
  4397. for (let i = 0; i < directives.length; i++) {
  4398. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4399. if (isFunction(dir)) {
  4400. dir = {
  4401. mounted: dir,
  4402. updated: dir
  4403. };
  4404. }
  4405. if (dir.deep) {
  4406. traverse(value);
  4407. }
  4408. bindings.push({
  4409. dir,
  4410. instance,
  4411. value,
  4412. oldValue: void 0,
  4413. arg,
  4414. modifiers
  4415. });
  4416. }
  4417. return vnode;
  4418. }
  4419. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4420. const bindings = vnode.dirs;
  4421. const oldBindings = prevVNode && prevVNode.dirs;
  4422. for (let i = 0; i < bindings.length; i++) {
  4423. const binding = bindings[i];
  4424. if (oldBindings) {
  4425. binding.oldValue = oldBindings[i].value;
  4426. }
  4427. let hook = binding.dir[name];
  4428. if (hook) {
  4429. // disable tracking inside all lifecycle hooks
  4430. // since they can potentially be called inside effects.
  4431. pauseTracking();
  4432. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  4433. vnode.el,
  4434. binding,
  4435. vnode,
  4436. prevVNode
  4437. ]);
  4438. resetTracking();
  4439. }
  4440. }
  4441. }
  4442. function createAppContext() {
  4443. return {
  4444. app: null,
  4445. config: {
  4446. isNativeTag: NO,
  4447. performance: false,
  4448. globalProperties: {},
  4449. optionMergeStrategies: {},
  4450. errorHandler: undefined,
  4451. warnHandler: undefined,
  4452. compilerOptions: {}
  4453. },
  4454. mixins: [],
  4455. components: {},
  4456. directives: {},
  4457. provides: Object.create(null),
  4458. optionsCache: new WeakMap(),
  4459. propsCache: new WeakMap(),
  4460. emitsCache: new WeakMap()
  4461. };
  4462. }
  4463. let uid = 0;
  4464. function createAppAPI(render, hydrate) {
  4465. return function createApp(rootComponent, rootProps = null) {
  4466. if (rootProps != null && !isObject(rootProps)) {
  4467. warn$1(`root props passed to app.mount() must be an object.`);
  4468. rootProps = null;
  4469. }
  4470. const context = createAppContext();
  4471. const installedPlugins = new Set();
  4472. let isMounted = false;
  4473. const app = (context.app = {
  4474. _uid: uid++,
  4475. _component: rootComponent,
  4476. _props: rootProps,
  4477. _container: null,
  4478. _context: context,
  4479. _instance: null,
  4480. version,
  4481. get config() {
  4482. return context.config;
  4483. },
  4484. set config(v) {
  4485. {
  4486. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  4487. }
  4488. },
  4489. use(plugin, ...options) {
  4490. if (installedPlugins.has(plugin)) {
  4491. warn$1(`Plugin has already been applied to target app.`);
  4492. }
  4493. else if (plugin && isFunction(plugin.install)) {
  4494. installedPlugins.add(plugin);
  4495. plugin.install(app, ...options);
  4496. }
  4497. else if (isFunction(plugin)) {
  4498. installedPlugins.add(plugin);
  4499. plugin(app, ...options);
  4500. }
  4501. else {
  4502. warn$1(`A plugin must either be a function or an object with an "install" ` +
  4503. `function.`);
  4504. }
  4505. return app;
  4506. },
  4507. mixin(mixin) {
  4508. {
  4509. if (!context.mixins.includes(mixin)) {
  4510. context.mixins.push(mixin);
  4511. }
  4512. else {
  4513. warn$1('Mixin has already been applied to target app' +
  4514. (mixin.name ? `: ${mixin.name}` : ''));
  4515. }
  4516. }
  4517. return app;
  4518. },
  4519. component(name, component) {
  4520. {
  4521. validateComponentName(name, context.config);
  4522. }
  4523. if (!component) {
  4524. return context.components[name];
  4525. }
  4526. if (context.components[name]) {
  4527. warn$1(`Component "${name}" has already been registered in target app.`);
  4528. }
  4529. context.components[name] = component;
  4530. return app;
  4531. },
  4532. directive(name, directive) {
  4533. {
  4534. validateDirectiveName(name);
  4535. }
  4536. if (!directive) {
  4537. return context.directives[name];
  4538. }
  4539. if (context.directives[name]) {
  4540. warn$1(`Directive "${name}" has already been registered in target app.`);
  4541. }
  4542. context.directives[name] = directive;
  4543. return app;
  4544. },
  4545. mount(rootContainer, isHydrate, isSVG) {
  4546. if (!isMounted) {
  4547. const vnode = createVNode(rootComponent, rootProps);
  4548. // store app context on the root VNode.
  4549. // this will be set on the root instance on initial mount.
  4550. vnode.appContext = context;
  4551. // HMR root reload
  4552. {
  4553. context.reload = () => {
  4554. render(cloneVNode(vnode), rootContainer, isSVG);
  4555. };
  4556. }
  4557. if (isHydrate && hydrate) {
  4558. hydrate(vnode, rootContainer);
  4559. }
  4560. else {
  4561. render(vnode, rootContainer, isSVG);
  4562. }
  4563. isMounted = true;
  4564. app._container = rootContainer;
  4565. rootContainer.__vue_app__ = app;
  4566. {
  4567. app._instance = vnode.component;
  4568. devtoolsInitApp(app, version);
  4569. }
  4570. return getExposeProxy(vnode.component) || vnode.component.proxy;
  4571. }
  4572. else {
  4573. warn$1(`App has already been mounted.\n` +
  4574. `If you want to remount the same app, move your app creation logic ` +
  4575. `into a factory function and create fresh app instances for each ` +
  4576. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  4577. }
  4578. },
  4579. unmount() {
  4580. if (isMounted) {
  4581. render(null, app._container);
  4582. {
  4583. app._instance = null;
  4584. devtoolsUnmountApp(app);
  4585. }
  4586. delete app._container.__vue_app__;
  4587. }
  4588. else {
  4589. warn$1(`Cannot unmount an app that is not mounted.`);
  4590. }
  4591. },
  4592. provide(key, value) {
  4593. if (key in context.provides) {
  4594. warn$1(`App already provides property with key "${String(key)}". ` +
  4595. `It will be overwritten with the new value.`);
  4596. }
  4597. // TypeScript doesn't allow symbols as index type
  4598. // https://github.com/Microsoft/TypeScript/issues/24587
  4599. context.provides[key] = value;
  4600. return app;
  4601. }
  4602. });
  4603. return app;
  4604. };
  4605. }
  4606. /**
  4607. * Function for handling a template ref
  4608. */
  4609. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  4610. if (isArray(rawRef)) {
  4611. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  4612. return;
  4613. }
  4614. if (isAsyncWrapper(vnode) && !isUnmount) {
  4615. // when mounting async components, nothing needs to be done,
  4616. // because the template ref is forwarded to inner component
  4617. return;
  4618. }
  4619. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  4620. ? getExposeProxy(vnode.component) || vnode.component.proxy
  4621. : vnode.el;
  4622. const value = isUnmount ? null : refValue;
  4623. const { i: owner, r: ref } = rawRef;
  4624. if (!owner) {
  4625. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  4626. `A vnode with ref must be created inside the render function.`);
  4627. return;
  4628. }
  4629. const oldRef = oldRawRef && oldRawRef.r;
  4630. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  4631. const setupState = owner.setupState;
  4632. // dynamic ref changed. unset old ref
  4633. if (oldRef != null && oldRef !== ref) {
  4634. if (isString(oldRef)) {
  4635. refs[oldRef] = null;
  4636. if (hasOwn(setupState, oldRef)) {
  4637. setupState[oldRef] = null;
  4638. }
  4639. }
  4640. else if (isRef(oldRef)) {
  4641. oldRef.value = null;
  4642. }
  4643. }
  4644. if (isFunction(ref)) {
  4645. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  4646. }
  4647. else {
  4648. const _isString = isString(ref);
  4649. const _isRef = isRef(ref);
  4650. if (_isString || _isRef) {
  4651. const doSet = () => {
  4652. if (rawRef.f) {
  4653. const existing = _isString ? refs[ref] : ref.value;
  4654. if (isUnmount) {
  4655. isArray(existing) && remove(existing, refValue);
  4656. }
  4657. else {
  4658. if (!isArray(existing)) {
  4659. if (_isString) {
  4660. refs[ref] = [refValue];
  4661. }
  4662. else {
  4663. ref.value = [refValue];
  4664. if (rawRef.k)
  4665. refs[rawRef.k] = ref.value;
  4666. }
  4667. }
  4668. else if (!existing.includes(refValue)) {
  4669. existing.push(refValue);
  4670. }
  4671. }
  4672. }
  4673. else if (_isString) {
  4674. refs[ref] = value;
  4675. if (hasOwn(setupState, ref)) {
  4676. setupState[ref] = value;
  4677. }
  4678. }
  4679. else if (isRef(ref)) {
  4680. ref.value = value;
  4681. if (rawRef.k)
  4682. refs[rawRef.k] = value;
  4683. }
  4684. else {
  4685. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  4686. }
  4687. };
  4688. if (value) {
  4689. doSet.id = -1;
  4690. queuePostRenderEffect(doSet, parentSuspense);
  4691. }
  4692. else {
  4693. doSet();
  4694. }
  4695. }
  4696. else {
  4697. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  4698. }
  4699. }
  4700. }
  4701. let hasMismatch = false;
  4702. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  4703. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  4704. // Note: hydration is DOM-specific
  4705. // But we have to place it in core due to tight coupling with core - splitting
  4706. // it out creates a ton of unnecessary complexity.
  4707. // Hydration also depends on some renderer internal logic which needs to be
  4708. // passed in via arguments.
  4709. function createHydrationFunctions(rendererInternals) {
  4710. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  4711. const hydrate = (vnode, container) => {
  4712. if (!container.hasChildNodes()) {
  4713. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  4714. `Performing full mount instead.`);
  4715. patch(null, vnode, container);
  4716. flushPostFlushCbs();
  4717. return;
  4718. }
  4719. hasMismatch = false;
  4720. hydrateNode(container.firstChild, vnode, null, null, null);
  4721. flushPostFlushCbs();
  4722. if (hasMismatch && !false) {
  4723. // this error should show up in production
  4724. console.error(`Hydration completed but contains mismatches.`);
  4725. }
  4726. };
  4727. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  4728. const isFragmentStart = isComment(node) && node.data === '[';
  4729. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  4730. const { type, ref, shapeFlag } = vnode;
  4731. const domType = node.nodeType;
  4732. vnode.el = node;
  4733. let nextNode = null;
  4734. switch (type) {
  4735. case Text:
  4736. if (domType !== 3 /* TEXT */) {
  4737. nextNode = onMismatch();
  4738. }
  4739. else {
  4740. if (node.data !== vnode.children) {
  4741. hasMismatch = true;
  4742. warn$1(`Hydration text mismatch:` +
  4743. `\n- Client: ${JSON.stringify(node.data)}` +
  4744. `\n- Server: ${JSON.stringify(vnode.children)}`);
  4745. node.data = vnode.children;
  4746. }
  4747. nextNode = nextSibling(node);
  4748. }
  4749. break;
  4750. case Comment:
  4751. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  4752. nextNode = onMismatch();
  4753. }
  4754. else {
  4755. nextNode = nextSibling(node);
  4756. }
  4757. break;
  4758. case Static:
  4759. if (domType !== 1 /* ELEMENT */) {
  4760. nextNode = onMismatch();
  4761. }
  4762. else {
  4763. // determine anchor, adopt content
  4764. nextNode = node;
  4765. // if the static vnode has its content stripped during build,
  4766. // adopt it from the server-rendered HTML.
  4767. const needToAdoptContent = !vnode.children.length;
  4768. for (let i = 0; i < vnode.staticCount; i++) {
  4769. if (needToAdoptContent)
  4770. vnode.children += nextNode.outerHTML;
  4771. if (i === vnode.staticCount - 1) {
  4772. vnode.anchor = nextNode;
  4773. }
  4774. nextNode = nextSibling(nextNode);
  4775. }
  4776. return nextNode;
  4777. }
  4778. break;
  4779. case Fragment:
  4780. if (!isFragmentStart) {
  4781. nextNode = onMismatch();
  4782. }
  4783. else {
  4784. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  4785. }
  4786. break;
  4787. default:
  4788. if (shapeFlag & 1 /* ELEMENT */) {
  4789. if (domType !== 1 /* ELEMENT */ ||
  4790. vnode.type.toLowerCase() !==
  4791. node.tagName.toLowerCase()) {
  4792. nextNode = onMismatch();
  4793. }
  4794. else {
  4795. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  4796. }
  4797. }
  4798. else if (shapeFlag & 6 /* COMPONENT */) {
  4799. // when setting up the render effect, if the initial vnode already
  4800. // has .el set, the component will perform hydration instead of mount
  4801. // on its sub-tree.
  4802. vnode.slotScopeIds = slotScopeIds;
  4803. const container = parentNode(node);
  4804. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  4805. // component may be async, so in the case of fragments we cannot rely
  4806. // on component's rendered output to determine the end of the fragment
  4807. // instead, we do a lookahead to find the end anchor node.
  4808. nextNode = isFragmentStart
  4809. ? locateClosingAsyncAnchor(node)
  4810. : nextSibling(node);
  4811. // #3787
  4812. // if component is async, it may get moved / unmounted before its
  4813. // inner component is loaded, so we need to give it a placeholder
  4814. // vnode that matches its adopted DOM.
  4815. if (isAsyncWrapper(vnode)) {
  4816. let subTree;
  4817. if (isFragmentStart) {
  4818. subTree = createVNode(Fragment);
  4819. subTree.anchor = nextNode
  4820. ? nextNode.previousSibling
  4821. : container.lastChild;
  4822. }
  4823. else {
  4824. subTree =
  4825. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  4826. }
  4827. subTree.el = node;
  4828. vnode.component.subTree = subTree;
  4829. }
  4830. }
  4831. else if (shapeFlag & 64 /* TELEPORT */) {
  4832. if (domType !== 8 /* COMMENT */) {
  4833. nextNode = onMismatch();
  4834. }
  4835. else {
  4836. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  4837. }
  4838. }
  4839. else if (shapeFlag & 128 /* SUSPENSE */) {
  4840. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  4841. }
  4842. else {
  4843. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  4844. }
  4845. }
  4846. if (ref != null) {
  4847. setRef(ref, null, parentSuspense, vnode);
  4848. }
  4849. return nextNode;
  4850. };
  4851. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  4852. optimized = optimized || !!vnode.dynamicChildren;
  4853. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  4854. // #4006 for form elements with non-string v-model value bindings
  4855. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  4856. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  4857. // skip props & children if this is hoisted static nodes
  4858. if (forcePatchValue || patchFlag !== -1 /* HOISTED */) {
  4859. if (dirs) {
  4860. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  4861. }
  4862. // props
  4863. if (props) {
  4864. if (forcePatchValue ||
  4865. !optimized ||
  4866. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  4867. for (const key in props) {
  4868. if ((forcePatchValue && key.endsWith('value')) ||
  4869. (isOn(key) && !isReservedProp(key))) {
  4870. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  4871. }
  4872. }
  4873. }
  4874. else if (props.onClick) {
  4875. // Fast path for click listeners (which is most often) to avoid
  4876. // iterating through props.
  4877. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  4878. }
  4879. }
  4880. // vnode / directive hooks
  4881. let vnodeHooks;
  4882. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  4883. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4884. }
  4885. if (dirs) {
  4886. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  4887. }
  4888. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  4889. queueEffectWithSuspense(() => {
  4890. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4891. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  4892. }, parentSuspense);
  4893. }
  4894. // children
  4895. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  4896. // skip if element has innerHTML / textContent
  4897. !(props && (props.innerHTML || props.textContent))) {
  4898. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  4899. let hasWarned = false;
  4900. while (next) {
  4901. hasMismatch = true;
  4902. if (!hasWarned) {
  4903. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  4904. `server rendered element contains more child nodes than client vdom.`);
  4905. hasWarned = true;
  4906. }
  4907. // The SSRed DOM contains more nodes than it should. Remove them.
  4908. const cur = next;
  4909. next = next.nextSibling;
  4910. remove(cur);
  4911. }
  4912. }
  4913. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  4914. if (el.textContent !== vnode.children) {
  4915. hasMismatch = true;
  4916. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  4917. `- Client: ${el.textContent}\n` +
  4918. `- Server: ${vnode.children}`);
  4919. el.textContent = vnode.children;
  4920. }
  4921. }
  4922. }
  4923. return el.nextSibling;
  4924. };
  4925. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  4926. optimized = optimized || !!parentVNode.dynamicChildren;
  4927. const children = parentVNode.children;
  4928. const l = children.length;
  4929. let hasWarned = false;
  4930. for (let i = 0; i < l; i++) {
  4931. const vnode = optimized
  4932. ? children[i]
  4933. : (children[i] = normalizeVNode(children[i]));
  4934. if (node) {
  4935. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  4936. }
  4937. else if (vnode.type === Text && !vnode.children) {
  4938. continue;
  4939. }
  4940. else {
  4941. hasMismatch = true;
  4942. if (!hasWarned) {
  4943. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  4944. `server rendered element contains fewer child nodes than client vdom.`);
  4945. hasWarned = true;
  4946. }
  4947. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  4948. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  4949. }
  4950. }
  4951. return node;
  4952. };
  4953. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  4954. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  4955. if (fragmentSlotScopeIds) {
  4956. slotScopeIds = slotScopeIds
  4957. ? slotScopeIds.concat(fragmentSlotScopeIds)
  4958. : fragmentSlotScopeIds;
  4959. }
  4960. const container = parentNode(node);
  4961. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  4962. if (next && isComment(next) && next.data === ']') {
  4963. return nextSibling((vnode.anchor = next));
  4964. }
  4965. else {
  4966. // fragment didn't hydrate successfully, since we didn't get a end anchor
  4967. // back. This should have led to node/children mismatch warnings.
  4968. hasMismatch = true;
  4969. // since the anchor is missing, we need to create one and insert it
  4970. insert((vnode.anchor = createComment(`]`)), container, next);
  4971. return next;
  4972. }
  4973. };
  4974. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  4975. hasMismatch = true;
  4976. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  4977. ? `(text)`
  4978. : isComment(node) && node.data === '['
  4979. ? `(start of fragment)`
  4980. : ``);
  4981. vnode.el = null;
  4982. if (isFragment) {
  4983. // remove excessive fragment nodes
  4984. const end = locateClosingAsyncAnchor(node);
  4985. while (true) {
  4986. const next = nextSibling(node);
  4987. if (next && next !== end) {
  4988. remove(next);
  4989. }
  4990. else {
  4991. break;
  4992. }
  4993. }
  4994. }
  4995. const next = nextSibling(node);
  4996. const container = parentNode(node);
  4997. remove(node);
  4998. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  4999. return next;
  5000. };
  5001. const locateClosingAsyncAnchor = (node) => {
  5002. let match = 0;
  5003. while (node) {
  5004. node = nextSibling(node);
  5005. if (node && isComment(node)) {
  5006. if (node.data === '[')
  5007. match++;
  5008. if (node.data === ']') {
  5009. if (match === 0) {
  5010. return nextSibling(node);
  5011. }
  5012. else {
  5013. match--;
  5014. }
  5015. }
  5016. }
  5017. }
  5018. return node;
  5019. };
  5020. return [hydrate, hydrateNode];
  5021. }
  5022. let supported;
  5023. let perf;
  5024. function startMeasure(instance, type) {
  5025. if (instance.appContext.config.performance && isSupported()) {
  5026. perf.mark(`vue-${type}-${instance.uid}`);
  5027. }
  5028. {
  5029. devtoolsPerfStart(instance, type, supported ? perf.now() : Date.now());
  5030. }
  5031. }
  5032. function endMeasure(instance, type) {
  5033. if (instance.appContext.config.performance && isSupported()) {
  5034. const startTag = `vue-${type}-${instance.uid}`;
  5035. const endTag = startTag + `:end`;
  5036. perf.mark(endTag);
  5037. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  5038. perf.clearMarks(startTag);
  5039. perf.clearMarks(endTag);
  5040. }
  5041. {
  5042. devtoolsPerfEnd(instance, type, supported ? perf.now() : Date.now());
  5043. }
  5044. }
  5045. function isSupported() {
  5046. if (supported !== undefined) {
  5047. return supported;
  5048. }
  5049. /* eslint-disable no-restricted-globals */
  5050. if (typeof window !== 'undefined' && window.performance) {
  5051. supported = true;
  5052. perf = window.performance;
  5053. }
  5054. else {
  5055. supported = false;
  5056. }
  5057. /* eslint-enable no-restricted-globals */
  5058. return supported;
  5059. }
  5060. const queuePostRenderEffect = queueEffectWithSuspense
  5061. ;
  5062. /**
  5063. * The createRenderer function accepts two generic arguments:
  5064. * HostNode and HostElement, corresponding to Node and Element types in the
  5065. * host environment. For example, for runtime-dom, HostNode would be the DOM
  5066. * `Node` interface and HostElement would be the DOM `Element` interface.
  5067. *
  5068. * Custom renderers can pass in the platform specific types like this:
  5069. *
  5070. * ``` js
  5071. * const { render, createApp } = createRenderer<Node, Element>({
  5072. * patchProp,
  5073. * ...nodeOps
  5074. * })
  5075. * ```
  5076. */
  5077. function createRenderer(options) {
  5078. return baseCreateRenderer(options);
  5079. }
  5080. // Separate API for creating hydration-enabled renderer.
  5081. // Hydration logic is only used when calling this function, making it
  5082. // tree-shakable.
  5083. function createHydrationRenderer(options) {
  5084. return baseCreateRenderer(options, createHydrationFunctions);
  5085. }
  5086. // implementation
  5087. function baseCreateRenderer(options, createHydrationFns) {
  5088. const target = getGlobalThis();
  5089. target.__VUE__ = true;
  5090. {
  5091. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  5092. }
  5093. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
  5094. // Note: functions inside this closure should use `const xxx = () => {}`
  5095. // style in order to prevent being inlined by minifiers.
  5096. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  5097. if (n1 === n2) {
  5098. return;
  5099. }
  5100. // patching & not same type, unmount old tree
  5101. if (n1 && !isSameVNodeType(n1, n2)) {
  5102. anchor = getNextHostNode(n1);
  5103. unmount(n1, parentComponent, parentSuspense, true);
  5104. n1 = null;
  5105. }
  5106. if (n2.patchFlag === -2 /* BAIL */) {
  5107. optimized = false;
  5108. n2.dynamicChildren = null;
  5109. }
  5110. const { type, ref, shapeFlag } = n2;
  5111. switch (type) {
  5112. case Text:
  5113. processText(n1, n2, container, anchor);
  5114. break;
  5115. case Comment:
  5116. processCommentNode(n1, n2, container, anchor);
  5117. break;
  5118. case Static:
  5119. if (n1 == null) {
  5120. mountStaticNode(n2, container, anchor, isSVG);
  5121. }
  5122. else {
  5123. patchStaticNode(n1, n2, container, isSVG);
  5124. }
  5125. break;
  5126. case Fragment:
  5127. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5128. break;
  5129. default:
  5130. if (shapeFlag & 1 /* ELEMENT */) {
  5131. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5132. }
  5133. else if (shapeFlag & 6 /* COMPONENT */) {
  5134. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5135. }
  5136. else if (shapeFlag & 64 /* TELEPORT */) {
  5137. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5138. }
  5139. else if (shapeFlag & 128 /* SUSPENSE */) {
  5140. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5141. }
  5142. else {
  5143. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  5144. }
  5145. }
  5146. // set ref
  5147. if (ref != null && parentComponent) {
  5148. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  5149. }
  5150. };
  5151. const processText = (n1, n2, container, anchor) => {
  5152. if (n1 == null) {
  5153. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  5154. }
  5155. else {
  5156. const el = (n2.el = n1.el);
  5157. if (n2.children !== n1.children) {
  5158. hostSetText(el, n2.children);
  5159. }
  5160. }
  5161. };
  5162. const processCommentNode = (n1, n2, container, anchor) => {
  5163. if (n1 == null) {
  5164. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  5165. }
  5166. else {
  5167. // there's no support for dynamic comments
  5168. n2.el = n1.el;
  5169. }
  5170. };
  5171. const mountStaticNode = (n2, container, anchor, isSVG) => {
  5172. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5173. };
  5174. /**
  5175. * Dev / HMR only
  5176. */
  5177. const patchStaticNode = (n1, n2, container, isSVG) => {
  5178. // static nodes are only patched during dev for HMR
  5179. if (n2.children !== n1.children) {
  5180. const anchor = hostNextSibling(n1.anchor);
  5181. // remove existing
  5182. removeStaticNode(n1);
  5183. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5184. }
  5185. else {
  5186. n2.el = n1.el;
  5187. n2.anchor = n1.anchor;
  5188. }
  5189. };
  5190. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  5191. let next;
  5192. while (el && el !== anchor) {
  5193. next = hostNextSibling(el);
  5194. hostInsert(el, container, nextSibling);
  5195. el = next;
  5196. }
  5197. hostInsert(anchor, container, nextSibling);
  5198. };
  5199. const removeStaticNode = ({ el, anchor }) => {
  5200. let next;
  5201. while (el && el !== anchor) {
  5202. next = hostNextSibling(el);
  5203. hostRemove(el);
  5204. el = next;
  5205. }
  5206. hostRemove(anchor);
  5207. };
  5208. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5209. isSVG = isSVG || n2.type === 'svg';
  5210. if (n1 == null) {
  5211. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5212. }
  5213. else {
  5214. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5215. }
  5216. };
  5217. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5218. let el;
  5219. let vnodeHook;
  5220. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  5221. {
  5222. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  5223. // mount children first, since some props may rely on child content
  5224. // being already rendered, e.g. `<select value>`
  5225. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5226. hostSetElementText(el, vnode.children);
  5227. }
  5228. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5229. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  5230. }
  5231. if (dirs) {
  5232. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5233. }
  5234. // props
  5235. if (props) {
  5236. for (const key in props) {
  5237. if (key !== 'value' && !isReservedProp(key)) {
  5238. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5239. }
  5240. }
  5241. /**
  5242. * Special case for setting value on DOM elements:
  5243. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  5244. * - it needs to be forced (#1471)
  5245. * #2353 proposes adding another renderer option to configure this, but
  5246. * the properties affects are so finite it is worth special casing it
  5247. * here to reduce the complexity. (Special casing it also should not
  5248. * affect non-DOM renderers)
  5249. */
  5250. if ('value' in props) {
  5251. hostPatchProp(el, 'value', null, props.value);
  5252. }
  5253. if ((vnodeHook = props.onVnodeBeforeMount)) {
  5254. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5255. }
  5256. }
  5257. // scopeId
  5258. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  5259. }
  5260. {
  5261. Object.defineProperty(el, '__vnode', {
  5262. value: vnode,
  5263. enumerable: false
  5264. });
  5265. Object.defineProperty(el, '__vueParentComponent', {
  5266. value: parentComponent,
  5267. enumerable: false
  5268. });
  5269. }
  5270. if (dirs) {
  5271. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  5272. }
  5273. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  5274. // #1689 For inside suspense + suspense resolved case, just call it
  5275. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  5276. transition &&
  5277. !transition.persisted;
  5278. if (needCallTransitionHooks) {
  5279. transition.beforeEnter(el);
  5280. }
  5281. hostInsert(el, container, anchor);
  5282. if ((vnodeHook = props && props.onVnodeMounted) ||
  5283. needCallTransitionHooks ||
  5284. dirs) {
  5285. queuePostRenderEffect(() => {
  5286. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5287. needCallTransitionHooks && transition.enter(el);
  5288. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  5289. }, parentSuspense);
  5290. }
  5291. };
  5292. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  5293. if (scopeId) {
  5294. hostSetScopeId(el, scopeId);
  5295. }
  5296. if (slotScopeIds) {
  5297. for (let i = 0; i < slotScopeIds.length; i++) {
  5298. hostSetScopeId(el, slotScopeIds[i]);
  5299. }
  5300. }
  5301. if (parentComponent) {
  5302. let subTree = parentComponent.subTree;
  5303. if (subTree.patchFlag > 0 &&
  5304. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  5305. subTree =
  5306. filterSingleRoot(subTree.children) || subTree;
  5307. }
  5308. if (vnode === subTree) {
  5309. const parentVNode = parentComponent.vnode;
  5310. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  5311. }
  5312. }
  5313. };
  5314. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  5315. for (let i = start; i < children.length; i++) {
  5316. const child = (children[i] = optimized
  5317. ? cloneIfMounted(children[i])
  5318. : normalizeVNode(children[i]));
  5319. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5320. }
  5321. };
  5322. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5323. const el = (n2.el = n1.el);
  5324. let { patchFlag, dynamicChildren, dirs } = n2;
  5325. // #1426 take the old vnode's patch flag into account since user may clone a
  5326. // compiler-generated vnode, which de-opts to FULL_PROPS
  5327. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  5328. const oldProps = n1.props || EMPTY_OBJ;
  5329. const newProps = n2.props || EMPTY_OBJ;
  5330. let vnodeHook;
  5331. // disable recurse in beforeUpdate hooks
  5332. parentComponent && toggleRecurse(parentComponent, false);
  5333. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  5334. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5335. }
  5336. if (dirs) {
  5337. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  5338. }
  5339. parentComponent && toggleRecurse(parentComponent, true);
  5340. if (isHmrUpdating) {
  5341. // HMR updated, force full diff
  5342. patchFlag = 0;
  5343. optimized = false;
  5344. dynamicChildren = null;
  5345. }
  5346. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  5347. if (dynamicChildren) {
  5348. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  5349. if (parentComponent && parentComponent.type.__hmrId) {
  5350. traverseStaticChildren(n1, n2);
  5351. }
  5352. }
  5353. else if (!optimized) {
  5354. // full diff
  5355. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  5356. }
  5357. if (patchFlag > 0) {
  5358. // the presence of a patchFlag means this element's render code was
  5359. // generated by the compiler and can take the fast path.
  5360. // in this path old node and new node are guaranteed to have the same shape
  5361. // (i.e. at the exact same position in the source template)
  5362. if (patchFlag & 16 /* FULL_PROPS */) {
  5363. // element props contain dynamic keys, full diff needed
  5364. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5365. }
  5366. else {
  5367. // class
  5368. // this flag is matched when the element has dynamic class bindings.
  5369. if (patchFlag & 2 /* CLASS */) {
  5370. if (oldProps.class !== newProps.class) {
  5371. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  5372. }
  5373. }
  5374. // style
  5375. // this flag is matched when the element has dynamic style bindings
  5376. if (patchFlag & 4 /* STYLE */) {
  5377. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  5378. }
  5379. // props
  5380. // This flag is matched when the element has dynamic prop/attr bindings
  5381. // other than class and style. The keys of dynamic prop/attrs are saved for
  5382. // faster iteration.
  5383. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  5384. // bail out and go through a full diff because we need to unset the old key
  5385. if (patchFlag & 8 /* PROPS */) {
  5386. // if the flag is present then dynamicProps must be non-null
  5387. const propsToUpdate = n2.dynamicProps;
  5388. for (let i = 0; i < propsToUpdate.length; i++) {
  5389. const key = propsToUpdate[i];
  5390. const prev = oldProps[key];
  5391. const next = newProps[key];
  5392. // #1471 force patch value
  5393. if (next !== prev || key === 'value') {
  5394. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  5395. }
  5396. }
  5397. }
  5398. }
  5399. // text
  5400. // This flag is matched when the element has only dynamic text children.
  5401. if (patchFlag & 1 /* TEXT */) {
  5402. if (n1.children !== n2.children) {
  5403. hostSetElementText(el, n2.children);
  5404. }
  5405. }
  5406. }
  5407. else if (!optimized && dynamicChildren == null) {
  5408. // unoptimized, full diff
  5409. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5410. }
  5411. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  5412. queuePostRenderEffect(() => {
  5413. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5414. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  5415. }, parentSuspense);
  5416. }
  5417. };
  5418. // The fast path for blocks.
  5419. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  5420. for (let i = 0; i < newChildren.length; i++) {
  5421. const oldVNode = oldChildren[i];
  5422. const newVNode = newChildren[i];
  5423. // Determine the container (parent element) for the patch.
  5424. const container =
  5425. // oldVNode may be an errored async setup() component inside Suspense
  5426. // which will not have a mounted element
  5427. oldVNode.el &&
  5428. // - In the case of a Fragment, we need to provide the actual parent
  5429. // of the Fragment itself so it can move its children.
  5430. (oldVNode.type === Fragment ||
  5431. // - In the case of different nodes, there is going to be a replacement
  5432. // which also requires the correct parent container
  5433. !isSameVNodeType(oldVNode, newVNode) ||
  5434. // - In the case of a component, it could contain anything.
  5435. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  5436. ? hostParentNode(oldVNode.el)
  5437. : // In other cases, the parent container is not actually used so we
  5438. // just pass the block element here to avoid a DOM parentNode call.
  5439. fallbackContainer;
  5440. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  5441. }
  5442. };
  5443. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  5444. if (oldProps !== newProps) {
  5445. for (const key in newProps) {
  5446. // empty string is not valid prop
  5447. if (isReservedProp(key))
  5448. continue;
  5449. const next = newProps[key];
  5450. const prev = oldProps[key];
  5451. // defer patching value
  5452. if (next !== prev && key !== 'value') {
  5453. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5454. }
  5455. }
  5456. if (oldProps !== EMPTY_OBJ) {
  5457. for (const key in oldProps) {
  5458. if (!isReservedProp(key) && !(key in newProps)) {
  5459. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5460. }
  5461. }
  5462. }
  5463. if ('value' in newProps) {
  5464. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  5465. }
  5466. }
  5467. };
  5468. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5469. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  5470. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  5471. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  5472. if (isHmrUpdating) {
  5473. // HMR updated, force full diff
  5474. patchFlag = 0;
  5475. optimized = false;
  5476. dynamicChildren = null;
  5477. }
  5478. // check if this is a slot fragment with :slotted scope ids
  5479. if (fragmentSlotScopeIds) {
  5480. slotScopeIds = slotScopeIds
  5481. ? slotScopeIds.concat(fragmentSlotScopeIds)
  5482. : fragmentSlotScopeIds;
  5483. }
  5484. if (n1 == null) {
  5485. hostInsert(fragmentStartAnchor, container, anchor);
  5486. hostInsert(fragmentEndAnchor, container, anchor);
  5487. // a fragment can only have array children
  5488. // since they are either generated by the compiler, or implicitly created
  5489. // from arrays.
  5490. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5491. }
  5492. else {
  5493. if (patchFlag > 0 &&
  5494. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  5495. dynamicChildren &&
  5496. // #2715 the previous fragment could've been a BAILed one as a result
  5497. // of renderSlot() with no valid children
  5498. n1.dynamicChildren) {
  5499. // a stable fragment (template root or <template v-for>) doesn't need to
  5500. // patch children order, but it may contain dynamicChildren.
  5501. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  5502. if (parentComponent && parentComponent.type.__hmrId) {
  5503. traverseStaticChildren(n1, n2);
  5504. }
  5505. else if (
  5506. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  5507. // get moved around. Make sure all root level vnodes inherit el.
  5508. // #2134 or if it's a component root, it may also get moved around
  5509. // as the component is being moved.
  5510. n2.key != null ||
  5511. (parentComponent && n2 === parentComponent.subTree)) {
  5512. traverseStaticChildren(n1, n2, true /* shallow */);
  5513. }
  5514. }
  5515. else {
  5516. // keyed / unkeyed, or manual fragments.
  5517. // for keyed & unkeyed, since they are compiler generated from v-for,
  5518. // each child is guaranteed to be a block so the fragment will never
  5519. // have dynamicChildren.
  5520. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5521. }
  5522. }
  5523. };
  5524. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5525. n2.slotScopeIds = slotScopeIds;
  5526. if (n1 == null) {
  5527. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  5528. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  5529. }
  5530. else {
  5531. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5532. }
  5533. }
  5534. else {
  5535. updateComponent(n1, n2, optimized);
  5536. }
  5537. };
  5538. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5539. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  5540. if (instance.type.__hmrId) {
  5541. registerHMR(instance);
  5542. }
  5543. {
  5544. pushWarningContext(initialVNode);
  5545. startMeasure(instance, `mount`);
  5546. }
  5547. // inject renderer internals for keepAlive
  5548. if (isKeepAlive(initialVNode)) {
  5549. instance.ctx.renderer = internals;
  5550. }
  5551. // resolve props and slots for setup context
  5552. {
  5553. {
  5554. startMeasure(instance, `init`);
  5555. }
  5556. setupComponent(instance);
  5557. {
  5558. endMeasure(instance, `init`);
  5559. }
  5560. }
  5561. // setup() is async. This component relies on async logic to be resolved
  5562. // before proceeding
  5563. if (instance.asyncDep) {
  5564. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  5565. // Give it a placeholder if this is not hydration
  5566. // TODO handle self-defined fallback
  5567. if (!initialVNode.el) {
  5568. const placeholder = (instance.subTree = createVNode(Comment));
  5569. processCommentNode(null, placeholder, container, anchor);
  5570. }
  5571. return;
  5572. }
  5573. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  5574. {
  5575. popWarningContext();
  5576. endMeasure(instance, `mount`);
  5577. }
  5578. };
  5579. const updateComponent = (n1, n2, optimized) => {
  5580. const instance = (n2.component = n1.component);
  5581. if (shouldUpdateComponent(n1, n2, optimized)) {
  5582. if (instance.asyncDep &&
  5583. !instance.asyncResolved) {
  5584. // async & still pending - just update props and slots
  5585. // since the component's reactive effect for render isn't set-up yet
  5586. {
  5587. pushWarningContext(n2);
  5588. }
  5589. updateComponentPreRender(instance, n2, optimized);
  5590. {
  5591. popWarningContext();
  5592. }
  5593. return;
  5594. }
  5595. else {
  5596. // normal update
  5597. instance.next = n2;
  5598. // in case the child component is also queued, remove it to avoid
  5599. // double updating the same child component in the same flush.
  5600. invalidateJob(instance.update);
  5601. // instance.update is the reactive effect.
  5602. instance.update();
  5603. }
  5604. }
  5605. else {
  5606. // no update needed. just copy over properties
  5607. n2.component = n1.component;
  5608. n2.el = n1.el;
  5609. instance.vnode = n2;
  5610. }
  5611. };
  5612. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  5613. const componentUpdateFn = () => {
  5614. if (!instance.isMounted) {
  5615. let vnodeHook;
  5616. const { el, props } = initialVNode;
  5617. const { bm, m, parent } = instance;
  5618. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  5619. toggleRecurse(instance, false);
  5620. // beforeMount hook
  5621. if (bm) {
  5622. invokeArrayFns(bm);
  5623. }
  5624. // onVnodeBeforeMount
  5625. if (!isAsyncWrapperVNode &&
  5626. (vnodeHook = props && props.onVnodeBeforeMount)) {
  5627. invokeVNodeHook(vnodeHook, parent, initialVNode);
  5628. }
  5629. toggleRecurse(instance, true);
  5630. if (el && hydrateNode) {
  5631. // vnode has adopted host node - perform hydration instead of mount.
  5632. const hydrateSubTree = () => {
  5633. {
  5634. startMeasure(instance, `render`);
  5635. }
  5636. instance.subTree = renderComponentRoot(instance);
  5637. {
  5638. endMeasure(instance, `render`);
  5639. }
  5640. {
  5641. startMeasure(instance, `hydrate`);
  5642. }
  5643. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  5644. {
  5645. endMeasure(instance, `hydrate`);
  5646. }
  5647. };
  5648. if (isAsyncWrapperVNode) {
  5649. initialVNode.type.__asyncLoader().then(
  5650. // note: we are moving the render call into an async callback,
  5651. // which means it won't track dependencies - but it's ok because
  5652. // a server-rendered async wrapper is already in resolved state
  5653. // and it will never need to change.
  5654. () => !instance.isUnmounted && hydrateSubTree());
  5655. }
  5656. else {
  5657. hydrateSubTree();
  5658. }
  5659. }
  5660. else {
  5661. {
  5662. startMeasure(instance, `render`);
  5663. }
  5664. const subTree = (instance.subTree = renderComponentRoot(instance));
  5665. {
  5666. endMeasure(instance, `render`);
  5667. }
  5668. {
  5669. startMeasure(instance, `patch`);
  5670. }
  5671. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  5672. {
  5673. endMeasure(instance, `patch`);
  5674. }
  5675. initialVNode.el = subTree.el;
  5676. }
  5677. // mounted hook
  5678. if (m) {
  5679. queuePostRenderEffect(m, parentSuspense);
  5680. }
  5681. // onVnodeMounted
  5682. if (!isAsyncWrapperVNode &&
  5683. (vnodeHook = props && props.onVnodeMounted)) {
  5684. const scopedInitialVNode = initialVNode;
  5685. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  5686. }
  5687. // activated hook for keep-alive roots.
  5688. // #1742 activated hook must be accessed after first render
  5689. // since the hook may be injected by a child keep-alive
  5690. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  5691. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  5692. }
  5693. instance.isMounted = true;
  5694. {
  5695. devtoolsComponentAdded(instance);
  5696. }
  5697. // #2458: deference mount-only object parameters to prevent memleaks
  5698. initialVNode = container = anchor = null;
  5699. }
  5700. else {
  5701. // updateComponent
  5702. // This is triggered by mutation of component's own state (next: null)
  5703. // OR parent calling processComponent (next: VNode)
  5704. let { next, bu, u, parent, vnode } = instance;
  5705. let originNext = next;
  5706. let vnodeHook;
  5707. {
  5708. pushWarningContext(next || instance.vnode);
  5709. }
  5710. // Disallow component effect recursion during pre-lifecycle hooks.
  5711. toggleRecurse(instance, false);
  5712. if (next) {
  5713. next.el = vnode.el;
  5714. updateComponentPreRender(instance, next, optimized);
  5715. }
  5716. else {
  5717. next = vnode;
  5718. }
  5719. // beforeUpdate hook
  5720. if (bu) {
  5721. invokeArrayFns(bu);
  5722. }
  5723. // onVnodeBeforeUpdate
  5724. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  5725. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5726. }
  5727. toggleRecurse(instance, true);
  5728. // render
  5729. {
  5730. startMeasure(instance, `render`);
  5731. }
  5732. const nextTree = renderComponentRoot(instance);
  5733. {
  5734. endMeasure(instance, `render`);
  5735. }
  5736. const prevTree = instance.subTree;
  5737. instance.subTree = nextTree;
  5738. {
  5739. startMeasure(instance, `patch`);
  5740. }
  5741. patch(prevTree, nextTree,
  5742. // parent may have changed if it's in a teleport
  5743. hostParentNode(prevTree.el),
  5744. // anchor may have changed if it's in a fragment
  5745. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  5746. {
  5747. endMeasure(instance, `patch`);
  5748. }
  5749. next.el = nextTree.el;
  5750. if (originNext === null) {
  5751. // self-triggered update. In case of HOC, update parent component
  5752. // vnode el. HOC is indicated by parent instance's subTree pointing
  5753. // to child component's vnode
  5754. updateHOCHostEl(instance, nextTree.el);
  5755. }
  5756. // updated hook
  5757. if (u) {
  5758. queuePostRenderEffect(u, parentSuspense);
  5759. }
  5760. // onVnodeUpdated
  5761. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  5762. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  5763. }
  5764. {
  5765. devtoolsComponentUpdated(instance);
  5766. }
  5767. {
  5768. popWarningContext();
  5769. }
  5770. }
  5771. };
  5772. // create reactive effect for rendering
  5773. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
  5774. ));
  5775. const update = (instance.update = effect.run.bind(effect));
  5776. update.id = instance.uid;
  5777. // allowRecurse
  5778. // #1801, #2043 component render effects should allow recursive updates
  5779. toggleRecurse(instance, true);
  5780. {
  5781. effect.onTrack = instance.rtc
  5782. ? e => invokeArrayFns(instance.rtc, e)
  5783. : void 0;
  5784. effect.onTrigger = instance.rtg
  5785. ? e => invokeArrayFns(instance.rtg, e)
  5786. : void 0;
  5787. // @ts-ignore (for scheduler)
  5788. update.ownerInstance = instance;
  5789. }
  5790. update();
  5791. };
  5792. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  5793. nextVNode.component = instance;
  5794. const prevProps = instance.vnode.props;
  5795. instance.vnode = nextVNode;
  5796. instance.next = null;
  5797. updateProps(instance, nextVNode.props, prevProps, optimized);
  5798. updateSlots(instance, nextVNode.children, optimized);
  5799. pauseTracking();
  5800. // props update may have triggered pre-flush watchers.
  5801. // flush them before the render update.
  5802. flushPreFlushCbs(undefined, instance.update);
  5803. resetTracking();
  5804. };
  5805. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  5806. const c1 = n1 && n1.children;
  5807. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  5808. const c2 = n2.children;
  5809. const { patchFlag, shapeFlag } = n2;
  5810. // fast path
  5811. if (patchFlag > 0) {
  5812. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  5813. // this could be either fully-keyed or mixed (some keyed some not)
  5814. // presence of patchFlag means children are guaranteed to be arrays
  5815. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5816. return;
  5817. }
  5818. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  5819. // unkeyed
  5820. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5821. return;
  5822. }
  5823. }
  5824. // children has 3 possibilities: text, array or no children.
  5825. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5826. // text children fast path
  5827. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5828. unmountChildren(c1, parentComponent, parentSuspense);
  5829. }
  5830. if (c2 !== c1) {
  5831. hostSetElementText(container, c2);
  5832. }
  5833. }
  5834. else {
  5835. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5836. // prev children was array
  5837. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5838. // two arrays, cannot assume anything, do full diff
  5839. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5840. }
  5841. else {
  5842. // no new children, just unmount old
  5843. unmountChildren(c1, parentComponent, parentSuspense, true);
  5844. }
  5845. }
  5846. else {
  5847. // prev children was text OR null
  5848. // new children is array OR null
  5849. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  5850. hostSetElementText(container, '');
  5851. }
  5852. // mount new if array
  5853. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5854. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5855. }
  5856. }
  5857. }
  5858. };
  5859. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5860. c1 = c1 || EMPTY_ARR;
  5861. c2 = c2 || EMPTY_ARR;
  5862. const oldLength = c1.length;
  5863. const newLength = c2.length;
  5864. const commonLength = Math.min(oldLength, newLength);
  5865. let i;
  5866. for (i = 0; i < commonLength; i++) {
  5867. const nextChild = (c2[i] = optimized
  5868. ? cloneIfMounted(c2[i])
  5869. : normalizeVNode(c2[i]));
  5870. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5871. }
  5872. if (oldLength > newLength) {
  5873. // remove old
  5874. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  5875. }
  5876. else {
  5877. // mount new
  5878. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  5879. }
  5880. };
  5881. // can be all-keyed or mixed
  5882. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5883. let i = 0;
  5884. const l2 = c2.length;
  5885. let e1 = c1.length - 1; // prev ending index
  5886. let e2 = l2 - 1; // next ending index
  5887. // 1. sync from start
  5888. // (a b) c
  5889. // (a b) d e
  5890. while (i <= e1 && i <= e2) {
  5891. const n1 = c1[i];
  5892. const n2 = (c2[i] = optimized
  5893. ? cloneIfMounted(c2[i])
  5894. : normalizeVNode(c2[i]));
  5895. if (isSameVNodeType(n1, n2)) {
  5896. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5897. }
  5898. else {
  5899. break;
  5900. }
  5901. i++;
  5902. }
  5903. // 2. sync from end
  5904. // a (b c)
  5905. // d e (b c)
  5906. while (i <= e1 && i <= e2) {
  5907. const n1 = c1[e1];
  5908. const n2 = (c2[e2] = optimized
  5909. ? cloneIfMounted(c2[e2])
  5910. : normalizeVNode(c2[e2]));
  5911. if (isSameVNodeType(n1, n2)) {
  5912. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5913. }
  5914. else {
  5915. break;
  5916. }
  5917. e1--;
  5918. e2--;
  5919. }
  5920. // 3. common sequence + mount
  5921. // (a b)
  5922. // (a b) c
  5923. // i = 2, e1 = 1, e2 = 2
  5924. // (a b)
  5925. // c (a b)
  5926. // i = 0, e1 = -1, e2 = 0
  5927. if (i > e1) {
  5928. if (i <= e2) {
  5929. const nextPos = e2 + 1;
  5930. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  5931. while (i <= e2) {
  5932. patch(null, (c2[i] = optimized
  5933. ? cloneIfMounted(c2[i])
  5934. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5935. i++;
  5936. }
  5937. }
  5938. }
  5939. // 4. common sequence + unmount
  5940. // (a b) c
  5941. // (a b)
  5942. // i = 2, e1 = 2, e2 = 1
  5943. // a (b c)
  5944. // (b c)
  5945. // i = 0, e1 = 0, e2 = -1
  5946. else if (i > e2) {
  5947. while (i <= e1) {
  5948. unmount(c1[i], parentComponent, parentSuspense, true);
  5949. i++;
  5950. }
  5951. }
  5952. // 5. unknown sequence
  5953. // [i ... e1 + 1]: a b [c d e] f g
  5954. // [i ... e2 + 1]: a b [e d c h] f g
  5955. // i = 2, e1 = 4, e2 = 5
  5956. else {
  5957. const s1 = i; // prev starting index
  5958. const s2 = i; // next starting index
  5959. // 5.1 build key:index map for newChildren
  5960. const keyToNewIndexMap = new Map();
  5961. for (i = s2; i <= e2; i++) {
  5962. const nextChild = (c2[i] = optimized
  5963. ? cloneIfMounted(c2[i])
  5964. : normalizeVNode(c2[i]));
  5965. if (nextChild.key != null) {
  5966. if (keyToNewIndexMap.has(nextChild.key)) {
  5967. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  5968. }
  5969. keyToNewIndexMap.set(nextChild.key, i);
  5970. }
  5971. }
  5972. // 5.2 loop through old children left to be patched and try to patch
  5973. // matching nodes & remove nodes that are no longer present
  5974. let j;
  5975. let patched = 0;
  5976. const toBePatched = e2 - s2 + 1;
  5977. let moved = false;
  5978. // used to track whether any node has moved
  5979. let maxNewIndexSoFar = 0;
  5980. // works as Map<newIndex, oldIndex>
  5981. // Note that oldIndex is offset by +1
  5982. // and oldIndex = 0 is a special value indicating the new node has
  5983. // no corresponding old node.
  5984. // used for determining longest stable subsequence
  5985. const newIndexToOldIndexMap = new Array(toBePatched);
  5986. for (i = 0; i < toBePatched; i++)
  5987. newIndexToOldIndexMap[i] = 0;
  5988. for (i = s1; i <= e1; i++) {
  5989. const prevChild = c1[i];
  5990. if (patched >= toBePatched) {
  5991. // all new children have been patched so this can only be a removal
  5992. unmount(prevChild, parentComponent, parentSuspense, true);
  5993. continue;
  5994. }
  5995. let newIndex;
  5996. if (prevChild.key != null) {
  5997. newIndex = keyToNewIndexMap.get(prevChild.key);
  5998. }
  5999. else {
  6000. // key-less node, try to locate a key-less node of the same type
  6001. for (j = s2; j <= e2; j++) {
  6002. if (newIndexToOldIndexMap[j - s2] === 0 &&
  6003. isSameVNodeType(prevChild, c2[j])) {
  6004. newIndex = j;
  6005. break;
  6006. }
  6007. }
  6008. }
  6009. if (newIndex === undefined) {
  6010. unmount(prevChild, parentComponent, parentSuspense, true);
  6011. }
  6012. else {
  6013. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  6014. if (newIndex >= maxNewIndexSoFar) {
  6015. maxNewIndexSoFar = newIndex;
  6016. }
  6017. else {
  6018. moved = true;
  6019. }
  6020. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6021. patched++;
  6022. }
  6023. }
  6024. // 5.3 move and mount
  6025. // generate longest stable subsequence only when nodes have moved
  6026. const increasingNewIndexSequence = moved
  6027. ? getSequence(newIndexToOldIndexMap)
  6028. : EMPTY_ARR;
  6029. j = increasingNewIndexSequence.length - 1;
  6030. // looping backwards so that we can use last patched node as anchor
  6031. for (i = toBePatched - 1; i >= 0; i--) {
  6032. const nextIndex = s2 + i;
  6033. const nextChild = c2[nextIndex];
  6034. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  6035. if (newIndexToOldIndexMap[i] === 0) {
  6036. // mount new
  6037. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6038. }
  6039. else if (moved) {
  6040. // move if:
  6041. // There is no stable subsequence (e.g. a reverse)
  6042. // OR current node is not among the stable sequence
  6043. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  6044. move(nextChild, container, anchor, 2 /* REORDER */);
  6045. }
  6046. else {
  6047. j--;
  6048. }
  6049. }
  6050. }
  6051. }
  6052. };
  6053. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  6054. const { el, type, transition, children, shapeFlag } = vnode;
  6055. if (shapeFlag & 6 /* COMPONENT */) {
  6056. move(vnode.component.subTree, container, anchor, moveType);
  6057. return;
  6058. }
  6059. if (shapeFlag & 128 /* SUSPENSE */) {
  6060. vnode.suspense.move(container, anchor, moveType);
  6061. return;
  6062. }
  6063. if (shapeFlag & 64 /* TELEPORT */) {
  6064. type.move(vnode, container, anchor, internals);
  6065. return;
  6066. }
  6067. if (type === Fragment) {
  6068. hostInsert(el, container, anchor);
  6069. for (let i = 0; i < children.length; i++) {
  6070. move(children[i], container, anchor, moveType);
  6071. }
  6072. hostInsert(vnode.anchor, container, anchor);
  6073. return;
  6074. }
  6075. if (type === Static) {
  6076. moveStaticNode(vnode, container, anchor);
  6077. return;
  6078. }
  6079. // single nodes
  6080. const needTransition = moveType !== 2 /* REORDER */ &&
  6081. shapeFlag & 1 /* ELEMENT */ &&
  6082. transition;
  6083. if (needTransition) {
  6084. if (moveType === 0 /* ENTER */) {
  6085. transition.beforeEnter(el);
  6086. hostInsert(el, container, anchor);
  6087. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  6088. }
  6089. else {
  6090. const { leave, delayLeave, afterLeave } = transition;
  6091. const remove = () => hostInsert(el, container, anchor);
  6092. const performLeave = () => {
  6093. leave(el, () => {
  6094. remove();
  6095. afterLeave && afterLeave();
  6096. });
  6097. };
  6098. if (delayLeave) {
  6099. delayLeave(el, remove, performLeave);
  6100. }
  6101. else {
  6102. performLeave();
  6103. }
  6104. }
  6105. }
  6106. else {
  6107. hostInsert(el, container, anchor);
  6108. }
  6109. };
  6110. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  6111. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  6112. // unset ref
  6113. if (ref != null) {
  6114. setRef(ref, null, parentSuspense, vnode, true);
  6115. }
  6116. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6117. parentComponent.ctx.deactivate(vnode);
  6118. return;
  6119. }
  6120. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  6121. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  6122. let vnodeHook;
  6123. if (shouldInvokeVnodeHook &&
  6124. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  6125. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6126. }
  6127. if (shapeFlag & 6 /* COMPONENT */) {
  6128. unmountComponent(vnode.component, parentSuspense, doRemove);
  6129. }
  6130. else {
  6131. if (shapeFlag & 128 /* SUSPENSE */) {
  6132. vnode.suspense.unmount(parentSuspense, doRemove);
  6133. return;
  6134. }
  6135. if (shouldInvokeDirs) {
  6136. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  6137. }
  6138. if (shapeFlag & 64 /* TELEPORT */) {
  6139. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  6140. }
  6141. else if (dynamicChildren &&
  6142. // #1153: fast path should not be taken for non-stable (v-for) fragments
  6143. (type !== Fragment ||
  6144. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  6145. // fast path for block nodes: only need to unmount dynamic children.
  6146. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  6147. }
  6148. else if ((type === Fragment &&
  6149. patchFlag &
  6150. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  6151. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  6152. unmountChildren(children, parentComponent, parentSuspense);
  6153. }
  6154. if (doRemove) {
  6155. remove(vnode);
  6156. }
  6157. }
  6158. if ((shouldInvokeVnodeHook &&
  6159. (vnodeHook = props && props.onVnodeUnmounted)) ||
  6160. shouldInvokeDirs) {
  6161. queuePostRenderEffect(() => {
  6162. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6163. shouldInvokeDirs &&
  6164. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  6165. }, parentSuspense);
  6166. }
  6167. };
  6168. const remove = vnode => {
  6169. const { type, el, anchor, transition } = vnode;
  6170. if (type === Fragment) {
  6171. removeFragment(el, anchor);
  6172. return;
  6173. }
  6174. if (type === Static) {
  6175. removeStaticNode(vnode);
  6176. return;
  6177. }
  6178. const performRemove = () => {
  6179. hostRemove(el);
  6180. if (transition && !transition.persisted && transition.afterLeave) {
  6181. transition.afterLeave();
  6182. }
  6183. };
  6184. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  6185. transition &&
  6186. !transition.persisted) {
  6187. const { leave, delayLeave } = transition;
  6188. const performLeave = () => leave(el, performRemove);
  6189. if (delayLeave) {
  6190. delayLeave(vnode.el, performRemove, performLeave);
  6191. }
  6192. else {
  6193. performLeave();
  6194. }
  6195. }
  6196. else {
  6197. performRemove();
  6198. }
  6199. };
  6200. const removeFragment = (cur, end) => {
  6201. // For fragments, directly remove all contained DOM nodes.
  6202. // (fragment child nodes cannot have transition)
  6203. let next;
  6204. while (cur !== end) {
  6205. next = hostNextSibling(cur);
  6206. hostRemove(cur);
  6207. cur = next;
  6208. }
  6209. hostRemove(end);
  6210. };
  6211. const unmountComponent = (instance, parentSuspense, doRemove) => {
  6212. if (instance.type.__hmrId) {
  6213. unregisterHMR(instance);
  6214. }
  6215. const { bum, scope, update, subTree, um } = instance;
  6216. // beforeUnmount hook
  6217. if (bum) {
  6218. invokeArrayFns(bum);
  6219. }
  6220. // stop effects in component scope
  6221. scope.stop();
  6222. // update may be null if a component is unmounted before its async
  6223. // setup has resolved.
  6224. if (update) {
  6225. // so that scheduler will no longer invoke it
  6226. update.active = false;
  6227. unmount(subTree, instance, parentSuspense, doRemove);
  6228. }
  6229. // unmounted hook
  6230. if (um) {
  6231. queuePostRenderEffect(um, parentSuspense);
  6232. }
  6233. queuePostRenderEffect(() => {
  6234. instance.isUnmounted = true;
  6235. }, parentSuspense);
  6236. // A component with async dep inside a pending suspense is unmounted before
  6237. // its async dep resolves. This should remove the dep from the suspense, and
  6238. // cause the suspense to resolve immediately if that was the last dep.
  6239. if (parentSuspense &&
  6240. parentSuspense.pendingBranch &&
  6241. !parentSuspense.isUnmounted &&
  6242. instance.asyncDep &&
  6243. !instance.asyncResolved &&
  6244. instance.suspenseId === parentSuspense.pendingId) {
  6245. parentSuspense.deps--;
  6246. if (parentSuspense.deps === 0) {
  6247. parentSuspense.resolve();
  6248. }
  6249. }
  6250. {
  6251. devtoolsComponentRemoved(instance);
  6252. }
  6253. };
  6254. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  6255. for (let i = start; i < children.length; i++) {
  6256. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  6257. }
  6258. };
  6259. const getNextHostNode = vnode => {
  6260. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  6261. return getNextHostNode(vnode.component.subTree);
  6262. }
  6263. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  6264. return vnode.suspense.next();
  6265. }
  6266. return hostNextSibling((vnode.anchor || vnode.el));
  6267. };
  6268. const render = (vnode, container, isSVG) => {
  6269. if (vnode == null) {
  6270. if (container._vnode) {
  6271. unmount(container._vnode, null, null, true);
  6272. }
  6273. }
  6274. else {
  6275. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  6276. }
  6277. flushPostFlushCbs();
  6278. container._vnode = vnode;
  6279. };
  6280. const internals = {
  6281. p: patch,
  6282. um: unmount,
  6283. m: move,
  6284. r: remove,
  6285. mt: mountComponent,
  6286. mc: mountChildren,
  6287. pc: patchChildren,
  6288. pbc: patchBlockChildren,
  6289. n: getNextHostNode,
  6290. o: options
  6291. };
  6292. let hydrate;
  6293. let hydrateNode;
  6294. if (createHydrationFns) {
  6295. [hydrate, hydrateNode] = createHydrationFns(internals);
  6296. }
  6297. return {
  6298. render,
  6299. hydrate,
  6300. createApp: createAppAPI(render, hydrate)
  6301. };
  6302. }
  6303. function toggleRecurse({ effect, update }, allowed) {
  6304. effect.allowRecurse = update.allowRecurse = allowed;
  6305. }
  6306. /**
  6307. * #1156
  6308. * When a component is HMR-enabled, we need to make sure that all static nodes
  6309. * inside a block also inherit the DOM element from the previous tree so that
  6310. * HMR updates (which are full updates) can retrieve the element for patching.
  6311. *
  6312. * #2080
  6313. * Inside keyed `template` fragment static children, if a fragment is moved,
  6314. * the children will always be moved. Therefore, in order to ensure correct move
  6315. * position, el should be inherited from previous nodes.
  6316. */
  6317. function traverseStaticChildren(n1, n2, shallow = false) {
  6318. const ch1 = n1.children;
  6319. const ch2 = n2.children;
  6320. if (isArray(ch1) && isArray(ch2)) {
  6321. for (let i = 0; i < ch1.length; i++) {
  6322. // this is only called in the optimized path so array children are
  6323. // guaranteed to be vnodes
  6324. const c1 = ch1[i];
  6325. let c2 = ch2[i];
  6326. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  6327. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  6328. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  6329. c2.el = c1.el;
  6330. }
  6331. if (!shallow)
  6332. traverseStaticChildren(c1, c2);
  6333. }
  6334. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  6335. // would have received .el during block patch)
  6336. if (c2.type === Comment && !c2.el) {
  6337. c2.el = c1.el;
  6338. }
  6339. }
  6340. }
  6341. }
  6342. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  6343. function getSequence(arr) {
  6344. const p = arr.slice();
  6345. const result = [0];
  6346. let i, j, u, v, c;
  6347. const len = arr.length;
  6348. for (i = 0; i < len; i++) {
  6349. const arrI = arr[i];
  6350. if (arrI !== 0) {
  6351. j = result[result.length - 1];
  6352. if (arr[j] < arrI) {
  6353. p[i] = j;
  6354. result.push(i);
  6355. continue;
  6356. }
  6357. u = 0;
  6358. v = result.length - 1;
  6359. while (u < v) {
  6360. c = (u + v) >> 1;
  6361. if (arr[result[c]] < arrI) {
  6362. u = c + 1;
  6363. }
  6364. else {
  6365. v = c;
  6366. }
  6367. }
  6368. if (arrI < arr[result[u]]) {
  6369. if (u > 0) {
  6370. p[i] = result[u - 1];
  6371. }
  6372. result[u] = i;
  6373. }
  6374. }
  6375. }
  6376. u = result.length;
  6377. v = result[u - 1];
  6378. while (u-- > 0) {
  6379. result[u] = v;
  6380. v = p[v];
  6381. }
  6382. return result;
  6383. }
  6384. const isTeleport = (type) => type.__isTeleport;
  6385. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  6386. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  6387. const resolveTarget = (props, select) => {
  6388. const targetSelector = props && props.to;
  6389. if (isString(targetSelector)) {
  6390. if (!select) {
  6391. warn$1(`Current renderer does not support string target for Teleports. ` +
  6392. `(missing querySelector renderer option)`);
  6393. return null;
  6394. }
  6395. else {
  6396. const target = select(targetSelector);
  6397. if (!target) {
  6398. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  6399. `Note the target element must exist before the component is mounted - ` +
  6400. `i.e. the target cannot be rendered by the component itself, and ` +
  6401. `ideally should be outside of the entire Vue component tree.`);
  6402. }
  6403. return target;
  6404. }
  6405. }
  6406. else {
  6407. if (!targetSelector && !isTeleportDisabled(props)) {
  6408. warn$1(`Invalid Teleport target: ${targetSelector}`);
  6409. }
  6410. return targetSelector;
  6411. }
  6412. };
  6413. const TeleportImpl = {
  6414. __isTeleport: true,
  6415. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  6416. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  6417. const disabled = isTeleportDisabled(n2.props);
  6418. let { shapeFlag, children, dynamicChildren } = n2;
  6419. // #3302
  6420. // HMR updated, force full diff
  6421. if (isHmrUpdating) {
  6422. optimized = false;
  6423. dynamicChildren = null;
  6424. }
  6425. if (n1 == null) {
  6426. // insert anchors in the main view
  6427. const placeholder = (n2.el = createComment('teleport start')
  6428. );
  6429. const mainAnchor = (n2.anchor = createComment('teleport end')
  6430. );
  6431. insert(placeholder, container, anchor);
  6432. insert(mainAnchor, container, anchor);
  6433. const target = (n2.target = resolveTarget(n2.props, querySelector));
  6434. const targetAnchor = (n2.targetAnchor = createText(''));
  6435. if (target) {
  6436. insert(targetAnchor, target);
  6437. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  6438. isSVG = isSVG || isTargetSVG(target);
  6439. }
  6440. else if (!disabled) {
  6441. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  6442. }
  6443. const mount = (container, anchor) => {
  6444. // Teleport *always* has Array children. This is enforced in both the
  6445. // compiler and vnode children normalization.
  6446. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6447. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6448. }
  6449. };
  6450. if (disabled) {
  6451. mount(container, mainAnchor);
  6452. }
  6453. else if (target) {
  6454. mount(target, targetAnchor);
  6455. }
  6456. }
  6457. else {
  6458. // update content
  6459. n2.el = n1.el;
  6460. const mainAnchor = (n2.anchor = n1.anchor);
  6461. const target = (n2.target = n1.target);
  6462. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  6463. const wasDisabled = isTeleportDisabled(n1.props);
  6464. const currentContainer = wasDisabled ? container : target;
  6465. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  6466. isSVG = isSVG || isTargetSVG(target);
  6467. if (dynamicChildren) {
  6468. // fast path when the teleport happens to be a block root
  6469. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6470. // even in block tree mode we need to make sure all root-level nodes
  6471. // in the teleport inherit previous DOM references so that they can
  6472. // be moved in future patches.
  6473. traverseStaticChildren(n1, n2, true);
  6474. }
  6475. else if (!optimized) {
  6476. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  6477. }
  6478. if (disabled) {
  6479. if (!wasDisabled) {
  6480. // enabled -> disabled
  6481. // move into main container
  6482. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  6483. }
  6484. }
  6485. else {
  6486. // target changed
  6487. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  6488. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  6489. if (nextTarget) {
  6490. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  6491. }
  6492. else {
  6493. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  6494. }
  6495. }
  6496. else if (wasDisabled) {
  6497. // disabled -> enabled
  6498. // move into teleport target
  6499. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  6500. }
  6501. }
  6502. }
  6503. },
  6504. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  6505. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  6506. if (target) {
  6507. hostRemove(targetAnchor);
  6508. }
  6509. // an unmounted teleport should always remove its children if not disabled
  6510. if (doRemove || !isTeleportDisabled(props)) {
  6511. hostRemove(anchor);
  6512. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6513. for (let i = 0; i < children.length; i++) {
  6514. const child = children[i];
  6515. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  6516. }
  6517. }
  6518. }
  6519. },
  6520. move: moveTeleport,
  6521. hydrate: hydrateTeleport
  6522. };
  6523. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  6524. // move target anchor if this is a target change.
  6525. if (moveType === 0 /* TARGET_CHANGE */) {
  6526. insert(vnode.targetAnchor, container, parentAnchor);
  6527. }
  6528. const { el, anchor, shapeFlag, children, props } = vnode;
  6529. const isReorder = moveType === 2 /* REORDER */;
  6530. // move main view anchor if this is a re-order.
  6531. if (isReorder) {
  6532. insert(el, container, parentAnchor);
  6533. }
  6534. // if this is a re-order and teleport is enabled (content is in target)
  6535. // do not move children. So the opposite is: only move children if this
  6536. // is not a reorder, or the teleport is disabled
  6537. if (!isReorder || isTeleportDisabled(props)) {
  6538. // Teleport has either Array children or no children.
  6539. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6540. for (let i = 0; i < children.length; i++) {
  6541. move(children[i], container, parentAnchor, 2 /* REORDER */);
  6542. }
  6543. }
  6544. }
  6545. // move main view anchor if this is a re-order.
  6546. if (isReorder) {
  6547. insert(anchor, container, parentAnchor);
  6548. }
  6549. }
  6550. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  6551. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  6552. if (target) {
  6553. // if multiple teleports rendered to the same target element, we need to
  6554. // pick up from where the last teleport finished instead of the first node
  6555. const targetNode = target._lpa || target.firstChild;
  6556. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6557. if (isTeleportDisabled(vnode.props)) {
  6558. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  6559. vnode.targetAnchor = targetNode;
  6560. }
  6561. else {
  6562. vnode.anchor = nextSibling(node);
  6563. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  6564. }
  6565. target._lpa =
  6566. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  6567. }
  6568. }
  6569. return vnode.anchor && nextSibling(vnode.anchor);
  6570. }
  6571. // Force-casted public typing for h and TSX props inference
  6572. const Teleport = TeleportImpl;
  6573. const COMPONENTS = 'components';
  6574. const DIRECTIVES = 'directives';
  6575. /**
  6576. * @private
  6577. */
  6578. function resolveComponent(name, maybeSelfReference) {
  6579. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  6580. }
  6581. const NULL_DYNAMIC_COMPONENT = Symbol();
  6582. /**
  6583. * @private
  6584. */
  6585. function resolveDynamicComponent(component) {
  6586. if (isString(component)) {
  6587. return resolveAsset(COMPONENTS, component, false) || component;
  6588. }
  6589. else {
  6590. // invalid types will fallthrough to createVNode and raise warning
  6591. return (component || NULL_DYNAMIC_COMPONENT);
  6592. }
  6593. }
  6594. /**
  6595. * @private
  6596. */
  6597. function resolveDirective(name) {
  6598. return resolveAsset(DIRECTIVES, name);
  6599. }
  6600. // implementation
  6601. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  6602. const instance = currentRenderingInstance || currentInstance;
  6603. if (instance) {
  6604. const Component = instance.type;
  6605. // explicit self name has highest priority
  6606. if (type === COMPONENTS) {
  6607. const selfName = getComponentName(Component);
  6608. if (selfName &&
  6609. (selfName === name ||
  6610. selfName === camelize(name) ||
  6611. selfName === capitalize(camelize(name)))) {
  6612. return Component;
  6613. }
  6614. }
  6615. const res =
  6616. // local registration
  6617. // check instance[type] first which is resolved for options API
  6618. resolve(instance[type] || Component[type], name) ||
  6619. // global registration
  6620. resolve(instance.appContext[type], name);
  6621. if (!res && maybeSelfReference) {
  6622. // fallback to implicit self-reference
  6623. return Component;
  6624. }
  6625. if (warnMissing && !res) {
  6626. const extra = type === COMPONENTS
  6627. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  6628. `component resolution via compilerOptions.isCustomElement.`
  6629. : ``;
  6630. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  6631. }
  6632. return res;
  6633. }
  6634. else {
  6635. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  6636. `can only be used in render() or setup().`);
  6637. }
  6638. }
  6639. function resolve(registry, name) {
  6640. return (registry &&
  6641. (registry[name] ||
  6642. registry[camelize(name)] ||
  6643. registry[capitalize(camelize(name))]));
  6644. }
  6645. const Fragment = Symbol('Fragment' );
  6646. const Text = Symbol('Text' );
  6647. const Comment = Symbol('Comment' );
  6648. const Static = Symbol('Static' );
  6649. // Since v-if and v-for are the two possible ways node structure can dynamically
  6650. // change, once we consider v-if branches and each v-for fragment a block, we
  6651. // can divide a template into nested blocks, and within each block the node
  6652. // structure would be stable. This allows us to skip most children diffing
  6653. // and only worry about the dynamic nodes (indicated by patch flags).
  6654. const blockStack = [];
  6655. let currentBlock = null;
  6656. /**
  6657. * Open a block.
  6658. * This must be called before `createBlock`. It cannot be part of `createBlock`
  6659. * because the children of the block are evaluated before `createBlock` itself
  6660. * is called. The generated code typically looks like this:
  6661. *
  6662. * ```js
  6663. * function render() {
  6664. * return (openBlock(),createBlock('div', null, [...]))
  6665. * }
  6666. * ```
  6667. * disableTracking is true when creating a v-for fragment block, since a v-for
  6668. * fragment always diffs its children.
  6669. *
  6670. * @private
  6671. */
  6672. function openBlock(disableTracking = false) {
  6673. blockStack.push((currentBlock = disableTracking ? null : []));
  6674. }
  6675. function closeBlock() {
  6676. blockStack.pop();
  6677. currentBlock = blockStack[blockStack.length - 1] || null;
  6678. }
  6679. // Whether we should be tracking dynamic child nodes inside a block.
  6680. // Only tracks when this value is > 0
  6681. // We are not using a simple boolean because this value may need to be
  6682. // incremented/decremented by nested usage of v-once (see below)
  6683. let isBlockTreeEnabled = 1;
  6684. /**
  6685. * Block tracking sometimes needs to be disabled, for example during the
  6686. * creation of a tree that needs to be cached by v-once. The compiler generates
  6687. * code like this:
  6688. *
  6689. * ``` js
  6690. * _cache[1] || (
  6691. * setBlockTracking(-1),
  6692. * _cache[1] = createVNode(...),
  6693. * setBlockTracking(1),
  6694. * _cache[1]
  6695. * )
  6696. * ```
  6697. *
  6698. * @private
  6699. */
  6700. function setBlockTracking(value) {
  6701. isBlockTreeEnabled += value;
  6702. }
  6703. function setupBlock(vnode) {
  6704. // save current block children on the block vnode
  6705. vnode.dynamicChildren =
  6706. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  6707. // close block
  6708. closeBlock();
  6709. // a block is always going to be patched, so track it as a child of its
  6710. // parent block
  6711. if (isBlockTreeEnabled > 0 && currentBlock) {
  6712. currentBlock.push(vnode);
  6713. }
  6714. return vnode;
  6715. }
  6716. /**
  6717. * @private
  6718. */
  6719. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  6720. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  6721. }
  6722. /**
  6723. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  6724. * A block root keeps track of dynamic nodes within the block in the
  6725. * `dynamicChildren` array.
  6726. *
  6727. * @private
  6728. */
  6729. function createBlock(type, props, children, patchFlag, dynamicProps) {
  6730. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  6731. }
  6732. function isVNode(value) {
  6733. return value ? value.__v_isVNode === true : false;
  6734. }
  6735. function isSameVNodeType(n1, n2) {
  6736. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  6737. hmrDirtyComponents.has(n2.type)) {
  6738. // HMR only: if the component has been hot-updated, force a reload.
  6739. return false;
  6740. }
  6741. return n1.type === n2.type && n1.key === n2.key;
  6742. }
  6743. let vnodeArgsTransformer;
  6744. /**
  6745. * Internal API for registering an arguments transform for createVNode
  6746. * used for creating stubs in the test-utils
  6747. * It is *internal* but needs to be exposed for test-utils to pick up proper
  6748. * typings
  6749. */
  6750. function transformVNodeArgs(transformer) {
  6751. vnodeArgsTransformer = transformer;
  6752. }
  6753. const createVNodeWithArgsTransform = (...args) => {
  6754. return _createVNode(...(vnodeArgsTransformer
  6755. ? vnodeArgsTransformer(args, currentRenderingInstance)
  6756. : args));
  6757. };
  6758. const InternalObjectKey = `__vInternal`;
  6759. const normalizeKey = ({ key }) => key != null ? key : null;
  6760. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  6761. return (ref != null
  6762. ? isString(ref) || isRef(ref) || isFunction(ref)
  6763. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  6764. : ref
  6765. : null);
  6766. };
  6767. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  6768. const vnode = {
  6769. __v_isVNode: true,
  6770. __v_skip: true,
  6771. type,
  6772. props,
  6773. key: props && normalizeKey(props),
  6774. ref: props && normalizeRef(props),
  6775. scopeId: currentScopeId,
  6776. slotScopeIds: null,
  6777. children,
  6778. component: null,
  6779. suspense: null,
  6780. ssContent: null,
  6781. ssFallback: null,
  6782. dirs: null,
  6783. transition: null,
  6784. el: null,
  6785. anchor: null,
  6786. target: null,
  6787. targetAnchor: null,
  6788. staticCount: 0,
  6789. shapeFlag,
  6790. patchFlag,
  6791. dynamicProps,
  6792. dynamicChildren: null,
  6793. appContext: null
  6794. };
  6795. if (needFullChildrenNormalization) {
  6796. normalizeChildren(vnode, children);
  6797. // normalize suspense children
  6798. if (shapeFlag & 128 /* SUSPENSE */) {
  6799. type.normalize(vnode);
  6800. }
  6801. }
  6802. else if (children) {
  6803. // compiled element vnode - if children is passed, only possible types are
  6804. // string or Array.
  6805. vnode.shapeFlag |= isString(children)
  6806. ? 8 /* TEXT_CHILDREN */
  6807. : 16 /* ARRAY_CHILDREN */;
  6808. }
  6809. // validate key
  6810. if (vnode.key !== vnode.key) {
  6811. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  6812. }
  6813. // track vnode for block tree
  6814. if (isBlockTreeEnabled > 0 &&
  6815. // avoid a block node from tracking itself
  6816. !isBlockNode &&
  6817. // has current parent block
  6818. currentBlock &&
  6819. // presence of a patch flag indicates this node needs patching on updates.
  6820. // component nodes also should always be patched, because even if the
  6821. // component doesn't need to update, it needs to persist the instance on to
  6822. // the next vnode so that it can be properly unmounted later.
  6823. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  6824. // the EVENTS flag is only for hydration and if it is the only flag, the
  6825. // vnode should not be considered dynamic due to handler caching.
  6826. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  6827. currentBlock.push(vnode);
  6828. }
  6829. return vnode;
  6830. }
  6831. const createVNode = (createVNodeWithArgsTransform );
  6832. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  6833. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  6834. if (!type) {
  6835. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  6836. }
  6837. type = Comment;
  6838. }
  6839. if (isVNode(type)) {
  6840. // createVNode receiving an existing vnode. This happens in cases like
  6841. // <component :is="vnode"/>
  6842. // #2078 make sure to merge refs during the clone instead of overwriting it
  6843. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  6844. if (children) {
  6845. normalizeChildren(cloned, children);
  6846. }
  6847. return cloned;
  6848. }
  6849. // class component normalization.
  6850. if (isClassComponent(type)) {
  6851. type = type.__vccOpts;
  6852. }
  6853. // class & style normalization.
  6854. if (props) {
  6855. // for reactive or proxy objects, we need to clone it to enable mutation.
  6856. props = guardReactiveProps(props);
  6857. let { class: klass, style } = props;
  6858. if (klass && !isString(klass)) {
  6859. props.class = normalizeClass(klass);
  6860. }
  6861. if (isObject(style)) {
  6862. // reactive state objects need to be cloned since they are likely to be
  6863. // mutated
  6864. if (isProxy(style) && !isArray(style)) {
  6865. style = extend({}, style);
  6866. }
  6867. props.style = normalizeStyle(style);
  6868. }
  6869. }
  6870. // encode the vnode type information into a bitmap
  6871. const shapeFlag = isString(type)
  6872. ? 1 /* ELEMENT */
  6873. : isSuspense(type)
  6874. ? 128 /* SUSPENSE */
  6875. : isTeleport(type)
  6876. ? 64 /* TELEPORT */
  6877. : isObject(type)
  6878. ? 4 /* STATEFUL_COMPONENT */
  6879. : isFunction(type)
  6880. ? 2 /* FUNCTIONAL_COMPONENT */
  6881. : 0;
  6882. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  6883. type = toRaw(type);
  6884. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  6885. `lead to unnecessary performance overhead, and should be avoided by ` +
  6886. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  6887. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  6888. }
  6889. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  6890. }
  6891. function guardReactiveProps(props) {
  6892. if (!props)
  6893. return null;
  6894. return isProxy(props) || InternalObjectKey in props
  6895. ? extend({}, props)
  6896. : props;
  6897. }
  6898. function cloneVNode(vnode, extraProps, mergeRef = false) {
  6899. // This is intentionally NOT using spread or extend to avoid the runtime
  6900. // key enumeration cost.
  6901. const { props, ref, patchFlag, children } = vnode;
  6902. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  6903. const cloned = {
  6904. __v_isVNode: true,
  6905. __v_skip: true,
  6906. type: vnode.type,
  6907. props: mergedProps,
  6908. key: mergedProps && normalizeKey(mergedProps),
  6909. ref: extraProps && extraProps.ref
  6910. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  6911. // if the vnode itself already has a ref, cloneVNode will need to merge
  6912. // the refs so the single vnode can be set on multiple refs
  6913. mergeRef && ref
  6914. ? isArray(ref)
  6915. ? ref.concat(normalizeRef(extraProps))
  6916. : [ref, normalizeRef(extraProps)]
  6917. : normalizeRef(extraProps)
  6918. : ref,
  6919. scopeId: vnode.scopeId,
  6920. slotScopeIds: vnode.slotScopeIds,
  6921. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  6922. ? children.map(deepCloneVNode)
  6923. : children,
  6924. target: vnode.target,
  6925. targetAnchor: vnode.targetAnchor,
  6926. staticCount: vnode.staticCount,
  6927. shapeFlag: vnode.shapeFlag,
  6928. // if the vnode is cloned with extra props, we can no longer assume its
  6929. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  6930. // note: perserve flag for fragments since they use the flag for children
  6931. // fast paths only.
  6932. patchFlag: extraProps && vnode.type !== Fragment
  6933. ? patchFlag === -1 // hoisted node
  6934. ? 16 /* FULL_PROPS */
  6935. : patchFlag | 16 /* FULL_PROPS */
  6936. : patchFlag,
  6937. dynamicProps: vnode.dynamicProps,
  6938. dynamicChildren: vnode.dynamicChildren,
  6939. appContext: vnode.appContext,
  6940. dirs: vnode.dirs,
  6941. transition: vnode.transition,
  6942. // These should technically only be non-null on mounted VNodes. However,
  6943. // they *should* be copied for kept-alive vnodes. So we just always copy
  6944. // them since them being non-null during a mount doesn't affect the logic as
  6945. // they will simply be overwritten.
  6946. component: vnode.component,
  6947. suspense: vnode.suspense,
  6948. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  6949. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  6950. el: vnode.el,
  6951. anchor: vnode.anchor
  6952. };
  6953. return cloned;
  6954. }
  6955. /**
  6956. * Dev only, for HMR of hoisted vnodes reused in v-for
  6957. * https://github.com/vitejs/vite/issues/2022
  6958. */
  6959. function deepCloneVNode(vnode) {
  6960. const cloned = cloneVNode(vnode);
  6961. if (isArray(vnode.children)) {
  6962. cloned.children = vnode.children.map(deepCloneVNode);
  6963. }
  6964. return cloned;
  6965. }
  6966. /**
  6967. * @private
  6968. */
  6969. function createTextVNode(text = ' ', flag = 0) {
  6970. return createVNode(Text, null, text, flag);
  6971. }
  6972. /**
  6973. * @private
  6974. */
  6975. function createStaticVNode(content, numberOfNodes) {
  6976. // A static vnode can contain multiple stringified elements, and the number
  6977. // of elements is necessary for hydration.
  6978. const vnode = createVNode(Static, null, content);
  6979. vnode.staticCount = numberOfNodes;
  6980. return vnode;
  6981. }
  6982. /**
  6983. * @private
  6984. */
  6985. function createCommentVNode(text = '',
  6986. // when used as the v-else branch, the comment node must be created as a
  6987. // block to ensure correct updates.
  6988. asBlock = false) {
  6989. return asBlock
  6990. ? (openBlock(), createBlock(Comment, null, text))
  6991. : createVNode(Comment, null, text);
  6992. }
  6993. function normalizeVNode(child) {
  6994. if (child == null || typeof child === 'boolean') {
  6995. // empty placeholder
  6996. return createVNode(Comment);
  6997. }
  6998. else if (isArray(child)) {
  6999. // fragment
  7000. return createVNode(Fragment, null,
  7001. // #3666, avoid reference pollution when reusing vnode
  7002. child.slice());
  7003. }
  7004. else if (typeof child === 'object') {
  7005. // already vnode, this should be the most common since compiled templates
  7006. // always produce all-vnode children arrays
  7007. return cloneIfMounted(child);
  7008. }
  7009. else {
  7010. // strings and numbers
  7011. return createVNode(Text, null, String(child));
  7012. }
  7013. }
  7014. // optimized normalization for template-compiled render fns
  7015. function cloneIfMounted(child) {
  7016. return child.el === null || child.memo ? child : cloneVNode(child);
  7017. }
  7018. function normalizeChildren(vnode, children) {
  7019. let type = 0;
  7020. const { shapeFlag } = vnode;
  7021. if (children == null) {
  7022. children = null;
  7023. }
  7024. else if (isArray(children)) {
  7025. type = 16 /* ARRAY_CHILDREN */;
  7026. }
  7027. else if (typeof children === 'object') {
  7028. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  7029. // Normalize slot to plain children for plain element and Teleport
  7030. const slot = children.default;
  7031. if (slot) {
  7032. // _c marker is added by withCtx() indicating this is a compiled slot
  7033. slot._c && (slot._d = false);
  7034. normalizeChildren(vnode, slot());
  7035. slot._c && (slot._d = true);
  7036. }
  7037. return;
  7038. }
  7039. else {
  7040. type = 32 /* SLOTS_CHILDREN */;
  7041. const slotFlag = children._;
  7042. if (!slotFlag && !(InternalObjectKey in children)) {
  7043. children._ctx = currentRenderingInstance;
  7044. }
  7045. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  7046. // a child component receives forwarded slots from the parent.
  7047. // its slot type is determined by its parent's slot type.
  7048. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  7049. children._ = 1 /* STABLE */;
  7050. }
  7051. else {
  7052. children._ = 2 /* DYNAMIC */;
  7053. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  7054. }
  7055. }
  7056. }
  7057. }
  7058. else if (isFunction(children)) {
  7059. children = { default: children, _ctx: currentRenderingInstance };
  7060. type = 32 /* SLOTS_CHILDREN */;
  7061. }
  7062. else {
  7063. children = String(children);
  7064. // force teleport children to array so it can be moved around
  7065. if (shapeFlag & 64 /* TELEPORT */) {
  7066. type = 16 /* ARRAY_CHILDREN */;
  7067. children = [createTextVNode(children)];
  7068. }
  7069. else {
  7070. type = 8 /* TEXT_CHILDREN */;
  7071. }
  7072. }
  7073. vnode.children = children;
  7074. vnode.shapeFlag |= type;
  7075. }
  7076. function mergeProps(...args) {
  7077. const ret = {};
  7078. for (let i = 0; i < args.length; i++) {
  7079. const toMerge = args[i];
  7080. for (const key in toMerge) {
  7081. if (key === 'class') {
  7082. if (ret.class !== toMerge.class) {
  7083. ret.class = normalizeClass([ret.class, toMerge.class]);
  7084. }
  7085. }
  7086. else if (key === 'style') {
  7087. ret.style = normalizeStyle([ret.style, toMerge.style]);
  7088. }
  7089. else if (isOn(key)) {
  7090. const existing = ret[key];
  7091. const incoming = toMerge[key];
  7092. if (existing !== incoming &&
  7093. !(isArray(existing) && existing.includes(incoming))) {
  7094. ret[key] = existing
  7095. ? [].concat(existing, incoming)
  7096. : incoming;
  7097. }
  7098. }
  7099. else if (key !== '') {
  7100. ret[key] = toMerge[key];
  7101. }
  7102. }
  7103. }
  7104. return ret;
  7105. }
  7106. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  7107. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  7108. vnode,
  7109. prevVNode
  7110. ]);
  7111. }
  7112. /**
  7113. * Actual implementation
  7114. */
  7115. function renderList(source, renderItem, cache, index) {
  7116. let ret;
  7117. const cached = (cache && cache[index]);
  7118. if (isArray(source) || isString(source)) {
  7119. ret = new Array(source.length);
  7120. for (let i = 0, l = source.length; i < l; i++) {
  7121. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  7122. }
  7123. }
  7124. else if (typeof source === 'number') {
  7125. if (!Number.isInteger(source)) {
  7126. warn$1(`The v-for range expect an integer value but got ${source}.`);
  7127. return [];
  7128. }
  7129. ret = new Array(source);
  7130. for (let i = 0; i < source; i++) {
  7131. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  7132. }
  7133. }
  7134. else if (isObject(source)) {
  7135. if (source[Symbol.iterator]) {
  7136. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  7137. }
  7138. else {
  7139. const keys = Object.keys(source);
  7140. ret = new Array(keys.length);
  7141. for (let i = 0, l = keys.length; i < l; i++) {
  7142. const key = keys[i];
  7143. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  7144. }
  7145. }
  7146. }
  7147. else {
  7148. ret = [];
  7149. }
  7150. if (cache) {
  7151. cache[index] = ret;
  7152. }
  7153. return ret;
  7154. }
  7155. /**
  7156. * Compiler runtime helper for creating dynamic slots object
  7157. * @private
  7158. */
  7159. function createSlots(slots, dynamicSlots) {
  7160. for (let i = 0; i < dynamicSlots.length; i++) {
  7161. const slot = dynamicSlots[i];
  7162. // array of dynamic slot generated by <template v-for="..." #[...]>
  7163. if (isArray(slot)) {
  7164. for (let j = 0; j < slot.length; j++) {
  7165. slots[slot[j].name] = slot[j].fn;
  7166. }
  7167. }
  7168. else if (slot) {
  7169. // conditional single slot generated by <template v-if="..." #foo>
  7170. slots[slot.name] = slot.fn;
  7171. }
  7172. }
  7173. return slots;
  7174. }
  7175. /**
  7176. * Compiler runtime helper for rendering `<slot/>`
  7177. * @private
  7178. */
  7179. function renderSlot(slots, name, props = {},
  7180. // this is not a user-facing function, so the fallback is always generated by
  7181. // the compiler and guaranteed to be a function returning an array
  7182. fallback, noSlotted) {
  7183. if (currentRenderingInstance.isCE) {
  7184. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  7185. }
  7186. let slot = slots[name];
  7187. if (slot && slot.length > 1) {
  7188. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  7189. `function. You need to mark this component with $dynamic-slots in the ` +
  7190. `parent template.`);
  7191. slot = () => [];
  7192. }
  7193. // a compiled slot disables block tracking by default to avoid manual
  7194. // invocation interfering with template-based block tracking, but in
  7195. // `renderSlot` we can be sure that it's template-based so we can force
  7196. // enable it.
  7197. if (slot && slot._c) {
  7198. slot._d = false;
  7199. }
  7200. openBlock();
  7201. const validSlotContent = slot && ensureValidVNode(slot(props));
  7202. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  7203. ? 64 /* STABLE_FRAGMENT */
  7204. : -2 /* BAIL */);
  7205. if (!noSlotted && rendered.scopeId) {
  7206. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  7207. }
  7208. if (slot && slot._c) {
  7209. slot._d = true;
  7210. }
  7211. return rendered;
  7212. }
  7213. function ensureValidVNode(vnodes) {
  7214. return vnodes.some(child => {
  7215. if (!isVNode(child))
  7216. return true;
  7217. if (child.type === Comment)
  7218. return false;
  7219. if (child.type === Fragment &&
  7220. !ensureValidVNode(child.children))
  7221. return false;
  7222. return true;
  7223. })
  7224. ? vnodes
  7225. : null;
  7226. }
  7227. /**
  7228. * For prefixing keys in v-on="obj" with "on"
  7229. * @private
  7230. */
  7231. function toHandlers(obj) {
  7232. const ret = {};
  7233. if (!isObject(obj)) {
  7234. warn$1(`v-on with no argument expects an object value.`);
  7235. return ret;
  7236. }
  7237. for (const key in obj) {
  7238. ret[toHandlerKey(key)] = obj[key];
  7239. }
  7240. return ret;
  7241. }
  7242. /**
  7243. * #2437 In Vue 3, functional components do not have a public instance proxy but
  7244. * they exist in the internal parent chain. For code that relies on traversing
  7245. * public $parent chains, skip functional ones and go to the parent instead.
  7246. */
  7247. const getPublicInstance = (i) => {
  7248. if (!i)
  7249. return null;
  7250. if (isStatefulComponent(i))
  7251. return getExposeProxy(i) || i.proxy;
  7252. return getPublicInstance(i.parent);
  7253. };
  7254. const publicPropertiesMap = extend(Object.create(null), {
  7255. $: i => i,
  7256. $el: i => i.vnode.el,
  7257. $data: i => i.data,
  7258. $props: i => (shallowReadonly(i.props) ),
  7259. $attrs: i => (shallowReadonly(i.attrs) ),
  7260. $slots: i => (shallowReadonly(i.slots) ),
  7261. $refs: i => (shallowReadonly(i.refs) ),
  7262. $parent: i => getPublicInstance(i.parent),
  7263. $root: i => getPublicInstance(i.root),
  7264. $emit: i => i.emit,
  7265. $options: i => (resolveMergedOptions(i) ),
  7266. $forceUpdate: i => () => queueJob(i.update),
  7267. $nextTick: i => nextTick.bind(i.proxy),
  7268. $watch: i => (instanceWatch.bind(i) )
  7269. });
  7270. const PublicInstanceProxyHandlers = {
  7271. get({ _: instance }, key) {
  7272. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  7273. // for internal formatters to know that this is a Vue instance
  7274. if (key === '__isVue') {
  7275. return true;
  7276. }
  7277. // prioritize <script setup> bindings during dev.
  7278. // this allows even properties that start with _ or $ to be used - so that
  7279. // it aligns with the production behavior where the render fn is inlined and
  7280. // indeed has access to all declared variables.
  7281. if (setupState !== EMPTY_OBJ &&
  7282. setupState.__isScriptSetup &&
  7283. hasOwn(setupState, key)) {
  7284. return setupState[key];
  7285. }
  7286. // data / props / ctx
  7287. // This getter gets called for every property access on the render context
  7288. // during render and is a major hotspot. The most expensive part of this
  7289. // is the multiple hasOwn() calls. It's much faster to do a simple property
  7290. // access on a plain object, so we use an accessCache object (with null
  7291. // prototype) to memoize what access type a key corresponds to.
  7292. let normalizedProps;
  7293. if (key[0] !== '$') {
  7294. const n = accessCache[key];
  7295. if (n !== undefined) {
  7296. switch (n) {
  7297. case 1 /* SETUP */:
  7298. return setupState[key];
  7299. case 2 /* DATA */:
  7300. return data[key];
  7301. case 4 /* CONTEXT */:
  7302. return ctx[key];
  7303. case 3 /* PROPS */:
  7304. return props[key];
  7305. // default: just fallthrough
  7306. }
  7307. }
  7308. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7309. accessCache[key] = 1 /* SETUP */;
  7310. return setupState[key];
  7311. }
  7312. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7313. accessCache[key] = 2 /* DATA */;
  7314. return data[key];
  7315. }
  7316. else if (
  7317. // only cache other properties when instance has declared (thus stable)
  7318. // props
  7319. (normalizedProps = instance.propsOptions[0]) &&
  7320. hasOwn(normalizedProps, key)) {
  7321. accessCache[key] = 3 /* PROPS */;
  7322. return props[key];
  7323. }
  7324. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  7325. accessCache[key] = 4 /* CONTEXT */;
  7326. return ctx[key];
  7327. }
  7328. else if (shouldCacheAccess) {
  7329. accessCache[key] = 0 /* OTHER */;
  7330. }
  7331. }
  7332. const publicGetter = publicPropertiesMap[key];
  7333. let cssModule, globalProperties;
  7334. // public $xxx properties
  7335. if (publicGetter) {
  7336. if (key === '$attrs') {
  7337. track(instance, "get" /* GET */, key);
  7338. markAttrsAccessed();
  7339. }
  7340. return publicGetter(instance);
  7341. }
  7342. else if (
  7343. // css module (injected by vue-loader)
  7344. (cssModule = type.__cssModules) &&
  7345. (cssModule = cssModule[key])) {
  7346. return cssModule;
  7347. }
  7348. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  7349. // user may set custom properties to `this` that start with `$`
  7350. accessCache[key] = 4 /* CONTEXT */;
  7351. return ctx[key];
  7352. }
  7353. else if (
  7354. // global properties
  7355. ((globalProperties = appContext.config.globalProperties),
  7356. hasOwn(globalProperties, key))) {
  7357. {
  7358. return globalProperties[key];
  7359. }
  7360. }
  7361. else if (currentRenderingInstance &&
  7362. (!isString(key) ||
  7363. // #1091 avoid internal isRef/isVNode checks on component instance leading
  7364. // to infinite warning loop
  7365. key.indexOf('__v') !== 0)) {
  7366. if (data !== EMPTY_OBJ &&
  7367. (key[0] === '$' || key[0] === '_') &&
  7368. hasOwn(data, key)) {
  7369. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  7370. `character ("$" or "_") and is not proxied on the render context.`);
  7371. }
  7372. else if (instance === currentRenderingInstance) {
  7373. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  7374. `but is not defined on instance.`);
  7375. }
  7376. }
  7377. },
  7378. set({ _: instance }, key, value) {
  7379. const { data, setupState, ctx } = instance;
  7380. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7381. setupState[key] = value;
  7382. }
  7383. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7384. data[key] = value;
  7385. }
  7386. else if (hasOwn(instance.props, key)) {
  7387. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  7388. return false;
  7389. }
  7390. if (key[0] === '$' && key.slice(1) in instance) {
  7391. warn$1(`Attempting to mutate public property "${key}". ` +
  7392. `Properties starting with $ are reserved and readonly.`, instance);
  7393. return false;
  7394. }
  7395. else {
  7396. if (key in instance.appContext.config.globalProperties) {
  7397. Object.defineProperty(ctx, key, {
  7398. enumerable: true,
  7399. configurable: true,
  7400. value
  7401. });
  7402. }
  7403. else {
  7404. ctx[key] = value;
  7405. }
  7406. }
  7407. return true;
  7408. },
  7409. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  7410. let normalizedProps;
  7411. return (!!accessCache[key] ||
  7412. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  7413. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  7414. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  7415. hasOwn(ctx, key) ||
  7416. hasOwn(publicPropertiesMap, key) ||
  7417. hasOwn(appContext.config.globalProperties, key));
  7418. }
  7419. };
  7420. {
  7421. PublicInstanceProxyHandlers.ownKeys = (target) => {
  7422. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  7423. `The keys will be empty in production mode to avoid performance overhead.`);
  7424. return Reflect.ownKeys(target);
  7425. };
  7426. }
  7427. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  7428. get(target, key) {
  7429. // fast path for unscopables when using `with` block
  7430. if (key === Symbol.unscopables) {
  7431. return;
  7432. }
  7433. return PublicInstanceProxyHandlers.get(target, key, target);
  7434. },
  7435. has(_, key) {
  7436. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  7437. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  7438. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  7439. }
  7440. return has;
  7441. }
  7442. });
  7443. // dev only
  7444. // In dev mode, the proxy target exposes the same properties as seen on `this`
  7445. // for easier console inspection. In prod mode it will be an empty object so
  7446. // these properties definitions can be skipped.
  7447. function createDevRenderContext(instance) {
  7448. const target = {};
  7449. // expose internal instance for proxy handlers
  7450. Object.defineProperty(target, `_`, {
  7451. configurable: true,
  7452. enumerable: false,
  7453. get: () => instance
  7454. });
  7455. // expose public properties
  7456. Object.keys(publicPropertiesMap).forEach(key => {
  7457. Object.defineProperty(target, key, {
  7458. configurable: true,
  7459. enumerable: false,
  7460. get: () => publicPropertiesMap[key](instance),
  7461. // intercepted by the proxy so no need for implementation,
  7462. // but needed to prevent set errors
  7463. set: NOOP
  7464. });
  7465. });
  7466. return target;
  7467. }
  7468. // dev only
  7469. function exposePropsOnRenderContext(instance) {
  7470. const { ctx, propsOptions: [propsOptions] } = instance;
  7471. if (propsOptions) {
  7472. Object.keys(propsOptions).forEach(key => {
  7473. Object.defineProperty(ctx, key, {
  7474. enumerable: true,
  7475. configurable: true,
  7476. get: () => instance.props[key],
  7477. set: NOOP
  7478. });
  7479. });
  7480. }
  7481. }
  7482. // dev only
  7483. function exposeSetupStateOnRenderContext(instance) {
  7484. const { ctx, setupState } = instance;
  7485. Object.keys(toRaw(setupState)).forEach(key => {
  7486. if (!setupState.__isScriptSetup) {
  7487. if (key[0] === '$' || key[0] === '_') {
  7488. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  7489. `which are reserved prefixes for Vue internals.`);
  7490. return;
  7491. }
  7492. Object.defineProperty(ctx, key, {
  7493. enumerable: true,
  7494. configurable: true,
  7495. get: () => setupState[key],
  7496. set: NOOP
  7497. });
  7498. }
  7499. });
  7500. }
  7501. const emptyAppContext = createAppContext();
  7502. let uid$1 = 0;
  7503. function createComponentInstance(vnode, parent, suspense) {
  7504. const type = vnode.type;
  7505. // inherit parent app context - or - if root, adopt from root vnode
  7506. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  7507. const instance = {
  7508. uid: uid$1++,
  7509. vnode,
  7510. type,
  7511. parent,
  7512. appContext,
  7513. root: null,
  7514. next: null,
  7515. subTree: null,
  7516. effect: null,
  7517. update: null,
  7518. scope: new EffectScope(true /* detached */),
  7519. render: null,
  7520. proxy: null,
  7521. exposed: null,
  7522. exposeProxy: null,
  7523. withProxy: null,
  7524. provides: parent ? parent.provides : Object.create(appContext.provides),
  7525. accessCache: null,
  7526. renderCache: [],
  7527. // local resovled assets
  7528. components: null,
  7529. directives: null,
  7530. // resolved props and emits options
  7531. propsOptions: normalizePropsOptions(type, appContext),
  7532. emitsOptions: normalizeEmitsOptions(type, appContext),
  7533. // emit
  7534. emit: null,
  7535. emitted: null,
  7536. // props default value
  7537. propsDefaults: EMPTY_OBJ,
  7538. // inheritAttrs
  7539. inheritAttrs: type.inheritAttrs,
  7540. // state
  7541. ctx: EMPTY_OBJ,
  7542. data: EMPTY_OBJ,
  7543. props: EMPTY_OBJ,
  7544. attrs: EMPTY_OBJ,
  7545. slots: EMPTY_OBJ,
  7546. refs: EMPTY_OBJ,
  7547. setupState: EMPTY_OBJ,
  7548. setupContext: null,
  7549. // suspense related
  7550. suspense,
  7551. suspenseId: suspense ? suspense.pendingId : 0,
  7552. asyncDep: null,
  7553. asyncResolved: false,
  7554. // lifecycle hooks
  7555. // not using enums here because it results in computed properties
  7556. isMounted: false,
  7557. isUnmounted: false,
  7558. isDeactivated: false,
  7559. bc: null,
  7560. c: null,
  7561. bm: null,
  7562. m: null,
  7563. bu: null,
  7564. u: null,
  7565. um: null,
  7566. bum: null,
  7567. da: null,
  7568. a: null,
  7569. rtg: null,
  7570. rtc: null,
  7571. ec: null,
  7572. sp: null
  7573. };
  7574. {
  7575. instance.ctx = createDevRenderContext(instance);
  7576. }
  7577. instance.root = parent ? parent.root : instance;
  7578. instance.emit = emit$1.bind(null, instance);
  7579. // apply custom element special handling
  7580. if (vnode.ce) {
  7581. vnode.ce(instance);
  7582. }
  7583. return instance;
  7584. }
  7585. let currentInstance = null;
  7586. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  7587. const setCurrentInstance = (instance) => {
  7588. currentInstance = instance;
  7589. instance.scope.on();
  7590. };
  7591. const unsetCurrentInstance = () => {
  7592. currentInstance && currentInstance.scope.off();
  7593. currentInstance = null;
  7594. };
  7595. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  7596. function validateComponentName(name, config) {
  7597. const appIsNativeTag = config.isNativeTag || NO;
  7598. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  7599. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  7600. }
  7601. }
  7602. function isStatefulComponent(instance) {
  7603. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  7604. }
  7605. let isInSSRComponentSetup = false;
  7606. function setupComponent(instance, isSSR = false) {
  7607. isInSSRComponentSetup = isSSR;
  7608. const { props, children } = instance.vnode;
  7609. const isStateful = isStatefulComponent(instance);
  7610. initProps(instance, props, isStateful, isSSR);
  7611. initSlots(instance, children);
  7612. const setupResult = isStateful
  7613. ? setupStatefulComponent(instance, isSSR)
  7614. : undefined;
  7615. isInSSRComponentSetup = false;
  7616. return setupResult;
  7617. }
  7618. function setupStatefulComponent(instance, isSSR) {
  7619. const Component = instance.type;
  7620. {
  7621. if (Component.name) {
  7622. validateComponentName(Component.name, instance.appContext.config);
  7623. }
  7624. if (Component.components) {
  7625. const names = Object.keys(Component.components);
  7626. for (let i = 0; i < names.length; i++) {
  7627. validateComponentName(names[i], instance.appContext.config);
  7628. }
  7629. }
  7630. if (Component.directives) {
  7631. const names = Object.keys(Component.directives);
  7632. for (let i = 0; i < names.length; i++) {
  7633. validateDirectiveName(names[i]);
  7634. }
  7635. }
  7636. if (Component.compilerOptions && isRuntimeOnly()) {
  7637. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  7638. `includes the runtime compiler. Since you are using a runtime-only ` +
  7639. `build, the options should be passed via your build tool config instead.`);
  7640. }
  7641. }
  7642. // 0. create render proxy property access cache
  7643. instance.accessCache = Object.create(null);
  7644. // 1. create public instance / render proxy
  7645. // also mark it raw so it's never observed
  7646. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  7647. {
  7648. exposePropsOnRenderContext(instance);
  7649. }
  7650. // 2. call setup()
  7651. const { setup } = Component;
  7652. if (setup) {
  7653. const setupContext = (instance.setupContext =
  7654. setup.length > 1 ? createSetupContext(instance) : null);
  7655. setCurrentInstance(instance);
  7656. pauseTracking();
  7657. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  7658. resetTracking();
  7659. unsetCurrentInstance();
  7660. if (isPromise(setupResult)) {
  7661. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  7662. if (isSSR) {
  7663. // return the promise so server-renderer can wait on it
  7664. return setupResult
  7665. .then((resolvedResult) => {
  7666. handleSetupResult(instance, resolvedResult, isSSR);
  7667. })
  7668. .catch(e => {
  7669. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  7670. });
  7671. }
  7672. else {
  7673. // async setup returned Promise.
  7674. // bail here and wait for re-entry.
  7675. instance.asyncDep = setupResult;
  7676. }
  7677. }
  7678. else {
  7679. handleSetupResult(instance, setupResult, isSSR);
  7680. }
  7681. }
  7682. else {
  7683. finishComponentSetup(instance, isSSR);
  7684. }
  7685. }
  7686. function handleSetupResult(instance, setupResult, isSSR) {
  7687. if (isFunction(setupResult)) {
  7688. // setup returned an inline render function
  7689. {
  7690. instance.render = setupResult;
  7691. }
  7692. }
  7693. else if (isObject(setupResult)) {
  7694. if (isVNode(setupResult)) {
  7695. warn$1(`setup() should not return VNodes directly - ` +
  7696. `return a render function instead.`);
  7697. }
  7698. // setup returned bindings.
  7699. // assuming a render function compiled from template is present.
  7700. {
  7701. instance.devtoolsRawSetupState = setupResult;
  7702. }
  7703. instance.setupState = proxyRefs(setupResult);
  7704. {
  7705. exposeSetupStateOnRenderContext(instance);
  7706. }
  7707. }
  7708. else if (setupResult !== undefined) {
  7709. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  7710. }
  7711. finishComponentSetup(instance, isSSR);
  7712. }
  7713. let compile;
  7714. let installWithProxy;
  7715. /**
  7716. * For runtime-dom to register the compiler.
  7717. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  7718. */
  7719. function registerRuntimeCompiler(_compile) {
  7720. compile = _compile;
  7721. installWithProxy = i => {
  7722. if (i.render._rc) {
  7723. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  7724. }
  7725. };
  7726. }
  7727. // dev only
  7728. const isRuntimeOnly = () => !compile;
  7729. function finishComponentSetup(instance, isSSR, skipOptions) {
  7730. const Component = instance.type;
  7731. // template / render function normalization
  7732. // could be already set when returned from setup()
  7733. if (!instance.render) {
  7734. // only do on-the-fly compile if not in SSR - SSR on-the-fly compliation
  7735. // is done by server-renderer
  7736. if (!isSSR && compile && !Component.render) {
  7737. const template = Component.template;
  7738. if (template) {
  7739. {
  7740. startMeasure(instance, `compile`);
  7741. }
  7742. const { isCustomElement, compilerOptions } = instance.appContext.config;
  7743. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  7744. const finalCompilerOptions = extend(extend({
  7745. isCustomElement,
  7746. delimiters
  7747. }, compilerOptions), componentCompilerOptions);
  7748. Component.render = compile(template, finalCompilerOptions);
  7749. {
  7750. endMeasure(instance, `compile`);
  7751. }
  7752. }
  7753. }
  7754. instance.render = (Component.render || NOOP);
  7755. // for runtime-compiled render functions using `with` blocks, the render
  7756. // proxy used needs a different `has` handler which is more performant and
  7757. // also only allows a whitelist of globals to fallthrough.
  7758. if (installWithProxy) {
  7759. installWithProxy(instance);
  7760. }
  7761. }
  7762. // support for 2.x options
  7763. {
  7764. setCurrentInstance(instance);
  7765. pauseTracking();
  7766. applyOptions(instance);
  7767. resetTracking();
  7768. unsetCurrentInstance();
  7769. }
  7770. // warn missing template/render
  7771. // the runtime compilation of template in SSR is done by server-render
  7772. if (!Component.render && instance.render === NOOP && !isSSR) {
  7773. /* istanbul ignore if */
  7774. if (!compile && Component.template) {
  7775. warn$1(`Component provided template option but ` +
  7776. `runtime compilation is not supported in this build of Vue.` +
  7777. (` Use "vue.esm-browser.js" instead.`
  7778. ) /* should not happen */);
  7779. }
  7780. else {
  7781. warn$1(`Component is missing template or render function.`);
  7782. }
  7783. }
  7784. }
  7785. function createAttrsProxy(instance) {
  7786. return new Proxy(instance.attrs, {
  7787. get(target, key) {
  7788. markAttrsAccessed();
  7789. track(instance, "get" /* GET */, '$attrs');
  7790. return target[key];
  7791. },
  7792. set() {
  7793. warn$1(`setupContext.attrs is readonly.`);
  7794. return false;
  7795. },
  7796. deleteProperty() {
  7797. warn$1(`setupContext.attrs is readonly.`);
  7798. return false;
  7799. }
  7800. }
  7801. );
  7802. }
  7803. function createSetupContext(instance) {
  7804. const expose = exposed => {
  7805. if (instance.exposed) {
  7806. warn$1(`expose() should be called only once per setup().`);
  7807. }
  7808. instance.exposed = exposed || {};
  7809. };
  7810. let attrs;
  7811. {
  7812. // We use getters in dev in case libs like test-utils overwrite instance
  7813. // properties (overwrites should not be done in prod)
  7814. return Object.freeze({
  7815. get attrs() {
  7816. return attrs || (attrs = createAttrsProxy(instance));
  7817. },
  7818. get slots() {
  7819. return shallowReadonly(instance.slots);
  7820. },
  7821. get emit() {
  7822. return (event, ...args) => instance.emit(event, ...args);
  7823. },
  7824. expose
  7825. });
  7826. }
  7827. }
  7828. function getExposeProxy(instance) {
  7829. if (instance.exposed) {
  7830. return (instance.exposeProxy ||
  7831. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  7832. get(target, key) {
  7833. if (key in target) {
  7834. return target[key];
  7835. }
  7836. else if (key in publicPropertiesMap) {
  7837. return publicPropertiesMap[key](instance);
  7838. }
  7839. }
  7840. })));
  7841. }
  7842. }
  7843. const classifyRE = /(?:^|[-_])(\w)/g;
  7844. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  7845. function getComponentName(Component) {
  7846. return isFunction(Component)
  7847. ? Component.displayName || Component.name
  7848. : Component.name;
  7849. }
  7850. /* istanbul ignore next */
  7851. function formatComponentName(instance, Component, isRoot = false) {
  7852. let name = getComponentName(Component);
  7853. if (!name && Component.__file) {
  7854. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  7855. if (match) {
  7856. name = match[1];
  7857. }
  7858. }
  7859. if (!name && instance && instance.parent) {
  7860. // try to infer the name based on reverse resolution
  7861. const inferFromRegistry = (registry) => {
  7862. for (const key in registry) {
  7863. if (registry[key] === Component) {
  7864. return key;
  7865. }
  7866. }
  7867. };
  7868. name =
  7869. inferFromRegistry(instance.components ||
  7870. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  7871. }
  7872. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  7873. }
  7874. function isClassComponent(value) {
  7875. return isFunction(value) && '__vccOpts' in value;
  7876. }
  7877. const stack = [];
  7878. function pushWarningContext(vnode) {
  7879. stack.push(vnode);
  7880. }
  7881. function popWarningContext() {
  7882. stack.pop();
  7883. }
  7884. function warn$1(msg, ...args) {
  7885. // avoid props formatting or warn handler tracking deps that might be mutated
  7886. // during patch, leading to infinite recursion.
  7887. pauseTracking();
  7888. const instance = stack.length ? stack[stack.length - 1].component : null;
  7889. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  7890. const trace = getComponentTrace();
  7891. if (appWarnHandler) {
  7892. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  7893. msg + args.join(''),
  7894. instance && instance.proxy,
  7895. trace
  7896. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  7897. .join('\n'),
  7898. trace
  7899. ]);
  7900. }
  7901. else {
  7902. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  7903. /* istanbul ignore if */
  7904. if (trace.length &&
  7905. // avoid spamming console during tests
  7906. !false) {
  7907. warnArgs.push(`\n`, ...formatTrace(trace));
  7908. }
  7909. console.warn(...warnArgs);
  7910. }
  7911. resetTracking();
  7912. }
  7913. function getComponentTrace() {
  7914. let currentVNode = stack[stack.length - 1];
  7915. if (!currentVNode) {
  7916. return [];
  7917. }
  7918. // we can't just use the stack because it will be incomplete during updates
  7919. // that did not start from the root. Re-construct the parent chain using
  7920. // instance parent pointers.
  7921. const normalizedStack = [];
  7922. while (currentVNode) {
  7923. const last = normalizedStack[0];
  7924. if (last && last.vnode === currentVNode) {
  7925. last.recurseCount++;
  7926. }
  7927. else {
  7928. normalizedStack.push({
  7929. vnode: currentVNode,
  7930. recurseCount: 0
  7931. });
  7932. }
  7933. const parentInstance = currentVNode.component && currentVNode.component.parent;
  7934. currentVNode = parentInstance && parentInstance.vnode;
  7935. }
  7936. return normalizedStack;
  7937. }
  7938. /* istanbul ignore next */
  7939. function formatTrace(trace) {
  7940. const logs = [];
  7941. trace.forEach((entry, i) => {
  7942. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  7943. });
  7944. return logs;
  7945. }
  7946. function formatTraceEntry({ vnode, recurseCount }) {
  7947. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  7948. const isRoot = vnode.component ? vnode.component.parent == null : false;
  7949. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  7950. const close = `>` + postfix;
  7951. return vnode.props
  7952. ? [open, ...formatProps(vnode.props), close]
  7953. : [open + close];
  7954. }
  7955. /* istanbul ignore next */
  7956. function formatProps(props) {
  7957. const res = [];
  7958. const keys = Object.keys(props);
  7959. keys.slice(0, 3).forEach(key => {
  7960. res.push(...formatProp(key, props[key]));
  7961. });
  7962. if (keys.length > 3) {
  7963. res.push(` ...`);
  7964. }
  7965. return res;
  7966. }
  7967. /* istanbul ignore next */
  7968. function formatProp(key, value, raw) {
  7969. if (isString(value)) {
  7970. value = JSON.stringify(value);
  7971. return raw ? value : [`${key}=${value}`];
  7972. }
  7973. else if (typeof value === 'number' ||
  7974. typeof value === 'boolean' ||
  7975. value == null) {
  7976. return raw ? value : [`${key}=${value}`];
  7977. }
  7978. else if (isRef(value)) {
  7979. value = formatProp(key, toRaw(value.value), true);
  7980. return raw ? value : [`${key}=Ref<`, value, `>`];
  7981. }
  7982. else if (isFunction(value)) {
  7983. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  7984. }
  7985. else {
  7986. value = toRaw(value);
  7987. return raw ? value : [`${key}=`, value];
  7988. }
  7989. }
  7990. const ErrorTypeStrings = {
  7991. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  7992. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  7993. ["c" /* CREATED */]: 'created hook',
  7994. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  7995. ["m" /* MOUNTED */]: 'mounted hook',
  7996. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  7997. ["u" /* UPDATED */]: 'updated',
  7998. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  7999. ["um" /* UNMOUNTED */]: 'unmounted hook',
  8000. ["a" /* ACTIVATED */]: 'activated hook',
  8001. ["da" /* DEACTIVATED */]: 'deactivated hook',
  8002. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  8003. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  8004. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  8005. [0 /* SETUP_FUNCTION */]: 'setup function',
  8006. [1 /* RENDER_FUNCTION */]: 'render function',
  8007. [2 /* WATCH_GETTER */]: 'watcher getter',
  8008. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  8009. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  8010. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  8011. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  8012. [7 /* VNODE_HOOK */]: 'vnode hook',
  8013. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  8014. [9 /* TRANSITION_HOOK */]: 'transition hook',
  8015. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  8016. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  8017. [12 /* FUNCTION_REF */]: 'ref function',
  8018. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  8019. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  8020. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next'
  8021. };
  8022. function callWithErrorHandling(fn, instance, type, args) {
  8023. let res;
  8024. try {
  8025. res = args ? fn(...args) : fn();
  8026. }
  8027. catch (err) {
  8028. handleError(err, instance, type);
  8029. }
  8030. return res;
  8031. }
  8032. function callWithAsyncErrorHandling(fn, instance, type, args) {
  8033. if (isFunction(fn)) {
  8034. const res = callWithErrorHandling(fn, instance, type, args);
  8035. if (res && isPromise(res)) {
  8036. res.catch(err => {
  8037. handleError(err, instance, type);
  8038. });
  8039. }
  8040. return res;
  8041. }
  8042. const values = [];
  8043. for (let i = 0; i < fn.length; i++) {
  8044. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  8045. }
  8046. return values;
  8047. }
  8048. function handleError(err, instance, type, throwInDev = true) {
  8049. const contextVNode = instance ? instance.vnode : null;
  8050. if (instance) {
  8051. let cur = instance.parent;
  8052. // the exposed instance is the render proxy to keep it consistent with 2.x
  8053. const exposedInstance = instance.proxy;
  8054. // in production the hook receives only the error code
  8055. const errorInfo = ErrorTypeStrings[type] ;
  8056. while (cur) {
  8057. const errorCapturedHooks = cur.ec;
  8058. if (errorCapturedHooks) {
  8059. for (let i = 0; i < errorCapturedHooks.length; i++) {
  8060. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  8061. return;
  8062. }
  8063. }
  8064. }
  8065. cur = cur.parent;
  8066. }
  8067. // app-level handling
  8068. const appErrorHandler = instance.appContext.config.errorHandler;
  8069. if (appErrorHandler) {
  8070. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  8071. return;
  8072. }
  8073. }
  8074. logError(err, type, contextVNode, throwInDev);
  8075. }
  8076. function logError(err, type, contextVNode, throwInDev = true) {
  8077. {
  8078. const info = ErrorTypeStrings[type];
  8079. if (contextVNode) {
  8080. pushWarningContext(contextVNode);
  8081. }
  8082. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  8083. if (contextVNode) {
  8084. popWarningContext();
  8085. }
  8086. // crash in dev by default so it's more noticeable
  8087. if (throwInDev) {
  8088. throw err;
  8089. }
  8090. else {
  8091. console.error(err);
  8092. }
  8093. }
  8094. }
  8095. let isFlushing = false;
  8096. let isFlushPending = false;
  8097. const queue = [];
  8098. let flushIndex = 0;
  8099. const pendingPreFlushCbs = [];
  8100. let activePreFlushCbs = null;
  8101. let preFlushIndex = 0;
  8102. const pendingPostFlushCbs = [];
  8103. let activePostFlushCbs = null;
  8104. let postFlushIndex = 0;
  8105. const resolvedPromise = Promise.resolve();
  8106. let currentFlushPromise = null;
  8107. let currentPreFlushParentJob = null;
  8108. const RECURSION_LIMIT = 100;
  8109. function nextTick(fn) {
  8110. const p = currentFlushPromise || resolvedPromise;
  8111. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  8112. }
  8113. // #2768
  8114. // Use binary-search to find a suitable position in the queue,
  8115. // so that the queue maintains the increasing order of job's id,
  8116. // which can prevent the job from being skipped and also can avoid repeated patching.
  8117. function findInsertionIndex(id) {
  8118. // the start index should be `flushIndex + 1`
  8119. let start = flushIndex + 1;
  8120. let end = queue.length;
  8121. while (start < end) {
  8122. const middle = (start + end) >>> 1;
  8123. const middleJobId = getId(queue[middle]);
  8124. middleJobId < id ? (start = middle + 1) : (end = middle);
  8125. }
  8126. return start;
  8127. }
  8128. function queueJob(job) {
  8129. // the dedupe search uses the startIndex argument of Array.includes()
  8130. // by default the search index includes the current job that is being run
  8131. // so it cannot recursively trigger itself again.
  8132. // if the job is a watch() callback, the search will start with a +1 index to
  8133. // allow it recursively trigger itself - it is the user's responsibility to
  8134. // ensure it doesn't end up in an infinite loop.
  8135. if ((!queue.length ||
  8136. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  8137. job !== currentPreFlushParentJob) {
  8138. if (job.id == null) {
  8139. queue.push(job);
  8140. }
  8141. else {
  8142. queue.splice(findInsertionIndex(job.id), 0, job);
  8143. }
  8144. queueFlush();
  8145. }
  8146. }
  8147. function queueFlush() {
  8148. if (!isFlushing && !isFlushPending) {
  8149. isFlushPending = true;
  8150. currentFlushPromise = resolvedPromise.then(flushJobs);
  8151. }
  8152. }
  8153. function invalidateJob(job) {
  8154. const i = queue.indexOf(job);
  8155. if (i > flushIndex) {
  8156. queue.splice(i, 1);
  8157. }
  8158. }
  8159. function queueCb(cb, activeQueue, pendingQueue, index) {
  8160. if (!isArray(cb)) {
  8161. if (!activeQueue ||
  8162. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  8163. pendingQueue.push(cb);
  8164. }
  8165. }
  8166. else {
  8167. // if cb is an array, it is a component lifecycle hook which can only be
  8168. // triggered by a job, which is already deduped in the main queue, so
  8169. // we can skip duplicate check here to improve perf
  8170. pendingQueue.push(...cb);
  8171. }
  8172. queueFlush();
  8173. }
  8174. function queuePreFlushCb(cb) {
  8175. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  8176. }
  8177. function queuePostFlushCb(cb) {
  8178. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  8179. }
  8180. function flushPreFlushCbs(seen, parentJob = null) {
  8181. if (pendingPreFlushCbs.length) {
  8182. currentPreFlushParentJob = parentJob;
  8183. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  8184. pendingPreFlushCbs.length = 0;
  8185. {
  8186. seen = seen || new Map();
  8187. }
  8188. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  8189. if (checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  8190. continue;
  8191. }
  8192. activePreFlushCbs[preFlushIndex]();
  8193. }
  8194. activePreFlushCbs = null;
  8195. preFlushIndex = 0;
  8196. currentPreFlushParentJob = null;
  8197. // recursively flush until it drains
  8198. flushPreFlushCbs(seen, parentJob);
  8199. }
  8200. }
  8201. function flushPostFlushCbs(seen) {
  8202. if (pendingPostFlushCbs.length) {
  8203. const deduped = [...new Set(pendingPostFlushCbs)];
  8204. pendingPostFlushCbs.length = 0;
  8205. // #1947 already has active queue, nested flushPostFlushCbs call
  8206. if (activePostFlushCbs) {
  8207. activePostFlushCbs.push(...deduped);
  8208. return;
  8209. }
  8210. activePostFlushCbs = deduped;
  8211. {
  8212. seen = seen || new Map();
  8213. }
  8214. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  8215. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  8216. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  8217. continue;
  8218. }
  8219. activePostFlushCbs[postFlushIndex]();
  8220. }
  8221. activePostFlushCbs = null;
  8222. postFlushIndex = 0;
  8223. }
  8224. }
  8225. const getId = (job) => job.id == null ? Infinity : job.id;
  8226. function flushJobs(seen) {
  8227. isFlushPending = false;
  8228. isFlushing = true;
  8229. {
  8230. seen = seen || new Map();
  8231. }
  8232. flushPreFlushCbs(seen);
  8233. // Sort queue before flush.
  8234. // This ensures that:
  8235. // 1. Components are updated from parent to child. (because parent is always
  8236. // created before the child so its render effect will have smaller
  8237. // priority number)
  8238. // 2. If a component is unmounted during a parent component's update,
  8239. // its update can be skipped.
  8240. queue.sort((a, b) => getId(a) - getId(b));
  8241. // conditional usage of checkRecursiveUpdate must be determined out of
  8242. // try ... catch block since Rollup by default de-optimizes treeshaking
  8243. // inside try-catch. This can leave all warning code unshaked. Although
  8244. // they would get eventually shaken by a minifier like terser, some minifiers
  8245. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  8246. const check = (job) => checkRecursiveUpdates(seen, job)
  8247. ;
  8248. try {
  8249. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  8250. const job = queue[flushIndex];
  8251. if (job && job.active !== false) {
  8252. if (true && check(job)) {
  8253. continue;
  8254. }
  8255. // console.log(`running:`, job.id)
  8256. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  8257. }
  8258. }
  8259. }
  8260. finally {
  8261. flushIndex = 0;
  8262. queue.length = 0;
  8263. flushPostFlushCbs(seen);
  8264. isFlushing = false;
  8265. currentFlushPromise = null;
  8266. // some postFlushCb queued jobs!
  8267. // keep flushing until it drains.
  8268. if (queue.length ||
  8269. pendingPreFlushCbs.length ||
  8270. pendingPostFlushCbs.length) {
  8271. flushJobs(seen);
  8272. }
  8273. }
  8274. }
  8275. function checkRecursiveUpdates(seen, fn) {
  8276. if (!seen.has(fn)) {
  8277. seen.set(fn, 1);
  8278. }
  8279. else {
  8280. const count = seen.get(fn);
  8281. if (count > RECURSION_LIMIT) {
  8282. const instance = fn.ownerInstance;
  8283. const componentName = instance && getComponentName(instance.type);
  8284. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  8285. `This means you have a reactive effect that is mutating its own ` +
  8286. `dependencies and thus recursively triggering itself. Possible sources ` +
  8287. `include component template, render function, updated hook or ` +
  8288. `watcher source function.`);
  8289. return true;
  8290. }
  8291. else {
  8292. seen.set(fn, count + 1);
  8293. }
  8294. }
  8295. }
  8296. // Simple effect.
  8297. function watchEffect(effect, options) {
  8298. return doWatch(effect, null, options);
  8299. }
  8300. function watchPostEffect(effect, options) {
  8301. return doWatch(effect, null, (Object.assign(options || {}, { flush: 'post' })
  8302. ));
  8303. }
  8304. function watchSyncEffect(effect, options) {
  8305. return doWatch(effect, null, (Object.assign(options || {}, { flush: 'sync' })
  8306. ));
  8307. }
  8308. // initial value for watchers to trigger on undefined initial values
  8309. const INITIAL_WATCHER_VALUE = {};
  8310. // implementation
  8311. function watch(source, cb, options) {
  8312. if (!isFunction(cb)) {
  8313. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  8314. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  8315. `supports \`watch(source, cb, options?) signature.`);
  8316. }
  8317. return doWatch(source, cb, options);
  8318. }
  8319. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  8320. if (!cb) {
  8321. if (immediate !== undefined) {
  8322. warn$1(`watch() "immediate" option is only respected when using the ` +
  8323. `watch(source, callback, options?) signature.`);
  8324. }
  8325. if (deep !== undefined) {
  8326. warn$1(`watch() "deep" option is only respected when using the ` +
  8327. `watch(source, callback, options?) signature.`);
  8328. }
  8329. }
  8330. const warnInvalidSource = (s) => {
  8331. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  8332. `a reactive object, or an array of these types.`);
  8333. };
  8334. const instance = currentInstance;
  8335. let getter;
  8336. let forceTrigger = false;
  8337. let isMultiSource = false;
  8338. if (isRef(source)) {
  8339. getter = () => source.value;
  8340. forceTrigger = !!source._shallow;
  8341. }
  8342. else if (isReactive(source)) {
  8343. getter = () => source;
  8344. deep = true;
  8345. }
  8346. else if (isArray(source)) {
  8347. isMultiSource = true;
  8348. forceTrigger = source.some(isReactive);
  8349. getter = () => source.map(s => {
  8350. if (isRef(s)) {
  8351. return s.value;
  8352. }
  8353. else if (isReactive(s)) {
  8354. return traverse(s);
  8355. }
  8356. else if (isFunction(s)) {
  8357. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  8358. }
  8359. else {
  8360. warnInvalidSource(s);
  8361. }
  8362. });
  8363. }
  8364. else if (isFunction(source)) {
  8365. if (cb) {
  8366. // getter with cb
  8367. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  8368. }
  8369. else {
  8370. // no cb -> simple effect
  8371. getter = () => {
  8372. if (instance && instance.isUnmounted) {
  8373. return;
  8374. }
  8375. if (cleanup) {
  8376. cleanup();
  8377. }
  8378. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
  8379. };
  8380. }
  8381. }
  8382. else {
  8383. getter = NOOP;
  8384. warnInvalidSource(source);
  8385. }
  8386. if (cb && deep) {
  8387. const baseGetter = getter;
  8388. getter = () => traverse(baseGetter());
  8389. }
  8390. let cleanup;
  8391. let onInvalidate = (fn) => {
  8392. cleanup = effect.onStop = () => {
  8393. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  8394. };
  8395. };
  8396. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  8397. const job = () => {
  8398. if (!effect.active) {
  8399. return;
  8400. }
  8401. if (cb) {
  8402. // watch(source, cb)
  8403. const newValue = effect.run();
  8404. if (deep ||
  8405. forceTrigger ||
  8406. (isMultiSource
  8407. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  8408. : hasChanged(newValue, oldValue)) ||
  8409. (false )) {
  8410. // cleanup before running cb again
  8411. if (cleanup) {
  8412. cleanup();
  8413. }
  8414. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  8415. newValue,
  8416. // pass undefined as the old value when it's changed for the first time
  8417. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  8418. onInvalidate
  8419. ]);
  8420. oldValue = newValue;
  8421. }
  8422. }
  8423. else {
  8424. // watchEffect
  8425. effect.run();
  8426. }
  8427. };
  8428. // important: mark the job as a watcher callback so that scheduler knows
  8429. // it is allowed to self-trigger (#1727)
  8430. job.allowRecurse = !!cb;
  8431. let scheduler;
  8432. if (flush === 'sync') {
  8433. scheduler = job; // the scheduler function gets called directly
  8434. }
  8435. else if (flush === 'post') {
  8436. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  8437. }
  8438. else {
  8439. // default: 'pre'
  8440. scheduler = () => {
  8441. if (!instance || instance.isMounted) {
  8442. queuePreFlushCb(job);
  8443. }
  8444. else {
  8445. // with 'pre' option, the first call must happen before
  8446. // the component is mounted so it is called synchronously.
  8447. job();
  8448. }
  8449. };
  8450. }
  8451. const effect = new ReactiveEffect(getter, scheduler);
  8452. {
  8453. effect.onTrack = onTrack;
  8454. effect.onTrigger = onTrigger;
  8455. }
  8456. // initial run
  8457. if (cb) {
  8458. if (immediate) {
  8459. job();
  8460. }
  8461. else {
  8462. oldValue = effect.run();
  8463. }
  8464. }
  8465. else if (flush === 'post') {
  8466. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  8467. }
  8468. else {
  8469. effect.run();
  8470. }
  8471. return () => {
  8472. effect.stop();
  8473. if (instance && instance.scope) {
  8474. remove(instance.scope.effects, effect);
  8475. }
  8476. };
  8477. }
  8478. // this.$watch
  8479. function instanceWatch(source, value, options) {
  8480. const publicThis = this.proxy;
  8481. const getter = isString(source)
  8482. ? source.includes('.')
  8483. ? createPathGetter(publicThis, source)
  8484. : () => publicThis[source]
  8485. : source.bind(publicThis, publicThis);
  8486. let cb;
  8487. if (isFunction(value)) {
  8488. cb = value;
  8489. }
  8490. else {
  8491. cb = value.handler;
  8492. options = value;
  8493. }
  8494. const cur = currentInstance;
  8495. setCurrentInstance(this);
  8496. const res = doWatch(getter, cb.bind(publicThis), options);
  8497. if (cur) {
  8498. setCurrentInstance(cur);
  8499. }
  8500. else {
  8501. unsetCurrentInstance();
  8502. }
  8503. return res;
  8504. }
  8505. function createPathGetter(ctx, path) {
  8506. const segments = path.split('.');
  8507. return () => {
  8508. let cur = ctx;
  8509. for (let i = 0; i < segments.length && cur; i++) {
  8510. cur = cur[segments[i]];
  8511. }
  8512. return cur;
  8513. };
  8514. }
  8515. function traverse(value, seen) {
  8516. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  8517. return value;
  8518. }
  8519. seen = seen || new Set();
  8520. if (seen.has(value)) {
  8521. return value;
  8522. }
  8523. seen.add(value);
  8524. if (isRef(value)) {
  8525. traverse(value.value, seen);
  8526. }
  8527. else if (isArray(value)) {
  8528. for (let i = 0; i < value.length; i++) {
  8529. traverse(value[i], seen);
  8530. }
  8531. }
  8532. else if (isSet(value) || isMap(value)) {
  8533. value.forEach((v) => {
  8534. traverse(v, seen);
  8535. });
  8536. }
  8537. else if (isPlainObject(value)) {
  8538. for (const key in value) {
  8539. traverse(value[key], seen);
  8540. }
  8541. }
  8542. return value;
  8543. }
  8544. // dev only
  8545. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8546. `<script setup> of a single file component. Its arguments should be ` +
  8547. `compiled away and passing it at runtime has no effect.`);
  8548. // implementation
  8549. function defineProps() {
  8550. {
  8551. warnRuntimeUsage(`defineProps`);
  8552. }
  8553. return null;
  8554. }
  8555. // implementation
  8556. function defineEmits() {
  8557. {
  8558. warnRuntimeUsage(`defineEmits`);
  8559. }
  8560. return null;
  8561. }
  8562. /**
  8563. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8564. * instance properties when it is accessed by a parent component via template
  8565. * refs.
  8566. *
  8567. * `<script setup>` components are closed by default - i.e. varaibles inside
  8568. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8569. * via `defineExpose`.
  8570. *
  8571. * This is only usable inside `<script setup>`, is compiled away in the
  8572. * output and should **not** be actually called at runtime.
  8573. */
  8574. function defineExpose(exposed) {
  8575. {
  8576. warnRuntimeUsage(`defineExpose`);
  8577. }
  8578. }
  8579. /**
  8580. * Vue `<script setup>` compiler macro for providing props default values when
  8581. * using type-based `defineProps` declaration.
  8582. *
  8583. * Example usage:
  8584. * ```ts
  8585. * withDefaults(defineProps<{
  8586. * size?: number
  8587. * labels?: string[]
  8588. * }>(), {
  8589. * size: 3,
  8590. * labels: () => ['default label']
  8591. * })
  8592. * ```
  8593. *
  8594. * This is only usable inside `<script setup>`, is compiled away in the output
  8595. * and should **not** be actually called at runtime.
  8596. */
  8597. function withDefaults(props, defaults) {
  8598. {
  8599. warnRuntimeUsage(`withDefaults`);
  8600. }
  8601. return null;
  8602. }
  8603. function useSlots() {
  8604. return getContext().slots;
  8605. }
  8606. function useAttrs() {
  8607. return getContext().attrs;
  8608. }
  8609. function getContext() {
  8610. const i = getCurrentInstance();
  8611. if (!i) {
  8612. warn$1(`useContext() called without active instance.`);
  8613. }
  8614. return i.setupContext || (i.setupContext = createSetupContext(i));
  8615. }
  8616. /**
  8617. * Runtime helper for merging default declarations. Imported by compiled code
  8618. * only.
  8619. * @internal
  8620. */
  8621. function mergeDefaults(raw, defaults) {
  8622. const props = isArray(raw)
  8623. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8624. : raw;
  8625. for (const key in defaults) {
  8626. const opt = props[key];
  8627. if (opt) {
  8628. if (isArray(opt) || isFunction(opt)) {
  8629. props[key] = { type: opt, default: defaults[key] };
  8630. }
  8631. else {
  8632. opt.default = defaults[key];
  8633. }
  8634. }
  8635. else if (opt === null) {
  8636. props[key] = { default: defaults[key] };
  8637. }
  8638. else {
  8639. warn$1(`props default key "${key}" has no corresponding declaration.`);
  8640. }
  8641. }
  8642. return props;
  8643. }
  8644. /**
  8645. * Used to create a proxy for the rest element when destructuring props with
  8646. * defineProps().
  8647. * @internal
  8648. */
  8649. function createPropsRestProxy(props, excludedKeys) {
  8650. const ret = {};
  8651. for (const key in props) {
  8652. if (!excludedKeys.includes(key)) {
  8653. Object.defineProperty(ret, key, {
  8654. enumerable: true,
  8655. get: () => props[key]
  8656. });
  8657. }
  8658. }
  8659. return ret;
  8660. }
  8661. /**
  8662. * `<script setup>` helper for persisting the current instance context over
  8663. * async/await flows.
  8664. *
  8665. * `@vue/compiler-sfc` converts the following:
  8666. *
  8667. * ```ts
  8668. * const x = await foo()
  8669. * ```
  8670. *
  8671. * into:
  8672. *
  8673. * ```ts
  8674. * let __temp, __restore
  8675. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8676. * ```
  8677. * @internal
  8678. */
  8679. function withAsyncContext(getAwaitable) {
  8680. const ctx = getCurrentInstance();
  8681. if (!ctx) {
  8682. warn$1(`withAsyncContext called without active current instance. ` +
  8683. `This is likely a bug.`);
  8684. }
  8685. let awaitable = getAwaitable();
  8686. unsetCurrentInstance();
  8687. if (isPromise(awaitable)) {
  8688. awaitable = awaitable.catch(e => {
  8689. setCurrentInstance(ctx);
  8690. throw e;
  8691. });
  8692. }
  8693. return [awaitable, () => setCurrentInstance(ctx)];
  8694. }
  8695. // Actual implementation
  8696. function h(type, propsOrChildren, children) {
  8697. const l = arguments.length;
  8698. if (l === 2) {
  8699. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  8700. // single vnode without props
  8701. if (isVNode(propsOrChildren)) {
  8702. return createVNode(type, null, [propsOrChildren]);
  8703. }
  8704. // props without children
  8705. return createVNode(type, propsOrChildren);
  8706. }
  8707. else {
  8708. // omit props
  8709. return createVNode(type, null, propsOrChildren);
  8710. }
  8711. }
  8712. else {
  8713. if (l > 3) {
  8714. children = Array.prototype.slice.call(arguments, 2);
  8715. }
  8716. else if (l === 3 && isVNode(children)) {
  8717. children = [children];
  8718. }
  8719. return createVNode(type, propsOrChildren, children);
  8720. }
  8721. }
  8722. const ssrContextKey = Symbol(`ssrContext` );
  8723. const useSSRContext = () => {
  8724. {
  8725. const ctx = inject(ssrContextKey);
  8726. if (!ctx) {
  8727. warn$1(`Server rendering context not provided. Make sure to only call ` +
  8728. `useSSRContext() conditionally in the server build.`);
  8729. }
  8730. return ctx;
  8731. }
  8732. };
  8733. function initCustomFormatter() {
  8734. /* eslint-disable no-restricted-globals */
  8735. if (typeof window === 'undefined') {
  8736. return;
  8737. }
  8738. const vueStyle = { style: 'color:#3ba776' };
  8739. const numberStyle = { style: 'color:#0b1bc9' };
  8740. const stringStyle = { style: 'color:#b62e24' };
  8741. const keywordStyle = { style: 'color:#9d288c' };
  8742. // custom formatter for Chrome
  8743. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  8744. const formatter = {
  8745. header(obj) {
  8746. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  8747. if (!isObject(obj)) {
  8748. return null;
  8749. }
  8750. if (obj.__isVue) {
  8751. return ['div', vueStyle, `VueInstance`];
  8752. }
  8753. else if (isRef(obj)) {
  8754. return [
  8755. 'div',
  8756. {},
  8757. ['span', vueStyle, genRefFlag(obj)],
  8758. '<',
  8759. formatValue(obj.value),
  8760. `>`
  8761. ];
  8762. }
  8763. else if (isReactive(obj)) {
  8764. return [
  8765. 'div',
  8766. {},
  8767. ['span', vueStyle, 'Reactive'],
  8768. '<',
  8769. formatValue(obj),
  8770. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  8771. ];
  8772. }
  8773. else if (isReadonly(obj)) {
  8774. return [
  8775. 'div',
  8776. {},
  8777. ['span', vueStyle, 'Readonly'],
  8778. '<',
  8779. formatValue(obj),
  8780. '>'
  8781. ];
  8782. }
  8783. return null;
  8784. },
  8785. hasBody(obj) {
  8786. return obj && obj.__isVue;
  8787. },
  8788. body(obj) {
  8789. if (obj && obj.__isVue) {
  8790. return [
  8791. 'div',
  8792. {},
  8793. ...formatInstance(obj.$)
  8794. ];
  8795. }
  8796. }
  8797. };
  8798. function formatInstance(instance) {
  8799. const blocks = [];
  8800. if (instance.type.props && instance.props) {
  8801. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  8802. }
  8803. if (instance.setupState !== EMPTY_OBJ) {
  8804. blocks.push(createInstanceBlock('setup', instance.setupState));
  8805. }
  8806. if (instance.data !== EMPTY_OBJ) {
  8807. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  8808. }
  8809. const computed = extractKeys(instance, 'computed');
  8810. if (computed) {
  8811. blocks.push(createInstanceBlock('computed', computed));
  8812. }
  8813. const injected = extractKeys(instance, 'inject');
  8814. if (injected) {
  8815. blocks.push(createInstanceBlock('injected', injected));
  8816. }
  8817. blocks.push([
  8818. 'div',
  8819. {},
  8820. [
  8821. 'span',
  8822. {
  8823. style: keywordStyle.style + ';opacity:0.66'
  8824. },
  8825. '$ (internal): '
  8826. ],
  8827. ['object', { object: instance }]
  8828. ]);
  8829. return blocks;
  8830. }
  8831. function createInstanceBlock(type, target) {
  8832. target = extend({}, target);
  8833. if (!Object.keys(target).length) {
  8834. return ['span', {}];
  8835. }
  8836. return [
  8837. 'div',
  8838. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  8839. [
  8840. 'div',
  8841. {
  8842. style: 'color:#476582'
  8843. },
  8844. type
  8845. ],
  8846. [
  8847. 'div',
  8848. {
  8849. style: 'padding-left:1.25em'
  8850. },
  8851. ...Object.keys(target).map(key => {
  8852. return [
  8853. 'div',
  8854. {},
  8855. ['span', keywordStyle, key + ': '],
  8856. formatValue(target[key], false)
  8857. ];
  8858. })
  8859. ]
  8860. ];
  8861. }
  8862. function formatValue(v, asRaw = true) {
  8863. if (typeof v === 'number') {
  8864. return ['span', numberStyle, v];
  8865. }
  8866. else if (typeof v === 'string') {
  8867. return ['span', stringStyle, JSON.stringify(v)];
  8868. }
  8869. else if (typeof v === 'boolean') {
  8870. return ['span', keywordStyle, v];
  8871. }
  8872. else if (isObject(v)) {
  8873. return ['object', { object: asRaw ? toRaw(v) : v }];
  8874. }
  8875. else {
  8876. return ['span', stringStyle, String(v)];
  8877. }
  8878. }
  8879. function extractKeys(instance, type) {
  8880. const Comp = instance.type;
  8881. if (isFunction(Comp)) {
  8882. return;
  8883. }
  8884. const extracted = {};
  8885. for (const key in instance.ctx) {
  8886. if (isKeyOfType(Comp, key, type)) {
  8887. extracted[key] = instance.ctx[key];
  8888. }
  8889. }
  8890. return extracted;
  8891. }
  8892. function isKeyOfType(Comp, key, type) {
  8893. const opts = Comp[type];
  8894. if ((isArray(opts) && opts.includes(key)) ||
  8895. (isObject(opts) && key in opts)) {
  8896. return true;
  8897. }
  8898. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  8899. return true;
  8900. }
  8901. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  8902. return true;
  8903. }
  8904. }
  8905. function genRefFlag(v) {
  8906. if (v._shallow) {
  8907. return `ShallowRef`;
  8908. }
  8909. if (v.effect) {
  8910. return `ComputedRef`;
  8911. }
  8912. return `Ref`;
  8913. }
  8914. if (window.devtoolsFormatters) {
  8915. window.devtoolsFormatters.push(formatter);
  8916. }
  8917. else {
  8918. window.devtoolsFormatters = [formatter];
  8919. }
  8920. }
  8921. function withMemo(memo, render, cache, index) {
  8922. const cached = cache[index];
  8923. if (cached && isMemoSame(cached, memo)) {
  8924. return cached;
  8925. }
  8926. const ret = render();
  8927. // shallow clone
  8928. ret.memo = memo.slice();
  8929. return (cache[index] = ret);
  8930. }
  8931. function isMemoSame(cached, memo) {
  8932. const prev = cached.memo;
  8933. if (prev.length != memo.length) {
  8934. return false;
  8935. }
  8936. for (let i = 0; i < prev.length; i++) {
  8937. if (prev[i] !== memo[i]) {
  8938. return false;
  8939. }
  8940. }
  8941. // make sure to let parent block track it when returning cached
  8942. if (isBlockTreeEnabled > 0 && currentBlock) {
  8943. currentBlock.push(cached);
  8944. }
  8945. return true;
  8946. }
  8947. // Core API ------------------------------------------------------------------
  8948. const version = "3.2.25";
  8949. /**
  8950. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  8951. * @internal
  8952. */
  8953. const ssrUtils = (null);
  8954. /**
  8955. * @internal only exposed in compat builds
  8956. */
  8957. const resolveFilter = null;
  8958. /**
  8959. * @internal only exposed in compat builds.
  8960. */
  8961. const compatUtils = (null);
  8962. const svgNS = 'http://www.w3.org/2000/svg';
  8963. const doc = (typeof document !== 'undefined' ? document : null);
  8964. const staticTemplateCache = new Map();
  8965. const nodeOps = {
  8966. insert: (child, parent, anchor) => {
  8967. parent.insertBefore(child, anchor || null);
  8968. },
  8969. remove: child => {
  8970. const parent = child.parentNode;
  8971. if (parent) {
  8972. parent.removeChild(child);
  8973. }
  8974. },
  8975. createElement: (tag, isSVG, is, props) => {
  8976. const el = isSVG
  8977. ? doc.createElementNS(svgNS, tag)
  8978. : doc.createElement(tag, is ? { is } : undefined);
  8979. if (tag === 'select' && props && props.multiple != null) {
  8980. el.setAttribute('multiple', props.multiple);
  8981. }
  8982. return el;
  8983. },
  8984. createText: text => doc.createTextNode(text),
  8985. createComment: text => doc.createComment(text),
  8986. setText: (node, text) => {
  8987. node.nodeValue = text;
  8988. },
  8989. setElementText: (el, text) => {
  8990. el.textContent = text;
  8991. },
  8992. parentNode: node => node.parentNode,
  8993. nextSibling: node => node.nextSibling,
  8994. querySelector: selector => doc.querySelector(selector),
  8995. setScopeId(el, id) {
  8996. el.setAttribute(id, '');
  8997. },
  8998. cloneNode(el) {
  8999. const cloned = el.cloneNode(true);
  9000. // #3072
  9001. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  9002. // - normally, elements using `:value` bindings will not be hoisted, but if
  9003. // the bound value is a constant, e.g. `:value="true"` - they do get
  9004. // hoisted.
  9005. // - in production, hoisted nodes are cloned when subsequent inserts, but
  9006. // cloneNode() does not copy the custom property we attached.
  9007. // - This may need to account for other custom DOM properties we attach to
  9008. // elements in addition to `_value` in the future.
  9009. if (`_value` in el) {
  9010. cloned._value = el._value;
  9011. }
  9012. return cloned;
  9013. },
  9014. // __UNSAFE__
  9015. // Reason: innerHTML.
  9016. // Static content here can only come from compiled templates.
  9017. // As long as the user only uses trusted templates, this is safe.
  9018. insertStaticContent(content, parent, anchor, isSVG) {
  9019. // <parent> before | first ... last | anchor </parent>
  9020. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9021. let template = staticTemplateCache.get(content);
  9022. if (!template) {
  9023. const t = doc.createElement('template');
  9024. t.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9025. template = t.content;
  9026. if (isSVG) {
  9027. // remove outer svg wrapper
  9028. const wrapper = template.firstChild;
  9029. while (wrapper.firstChild) {
  9030. template.appendChild(wrapper.firstChild);
  9031. }
  9032. template.removeChild(wrapper);
  9033. }
  9034. staticTemplateCache.set(content, template);
  9035. }
  9036. parent.insertBefore(template.cloneNode(true), anchor);
  9037. return [
  9038. // first
  9039. before ? before.nextSibling : parent.firstChild,
  9040. // last
  9041. anchor ? anchor.previousSibling : parent.lastChild
  9042. ];
  9043. }
  9044. };
  9045. // compiler should normalize class + :class bindings on the same element
  9046. // into a single binding ['staticClass', dynamic]
  9047. function patchClass(el, value, isSVG) {
  9048. // directly setting className should be faster than setAttribute in theory
  9049. // if this is an element during a transition, take the temporary transition
  9050. // classes into account.
  9051. const transitionClasses = el._vtc;
  9052. if (transitionClasses) {
  9053. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9054. }
  9055. if (value == null) {
  9056. el.removeAttribute('class');
  9057. }
  9058. else if (isSVG) {
  9059. el.setAttribute('class', value);
  9060. }
  9061. else {
  9062. el.className = value;
  9063. }
  9064. }
  9065. function patchStyle(el, prev, next) {
  9066. const style = el.style;
  9067. const isCssString = isString(next);
  9068. if (next && !isCssString) {
  9069. for (const key in next) {
  9070. setStyle(style, key, next[key]);
  9071. }
  9072. if (prev && !isString(prev)) {
  9073. for (const key in prev) {
  9074. if (next[key] == null) {
  9075. setStyle(style, key, '');
  9076. }
  9077. }
  9078. }
  9079. }
  9080. else {
  9081. const currentDisplay = style.display;
  9082. if (isCssString) {
  9083. if (prev !== next) {
  9084. style.cssText = next;
  9085. }
  9086. }
  9087. else if (prev) {
  9088. el.removeAttribute('style');
  9089. }
  9090. // indicates that the `display` of the element is controlled by `v-show`,
  9091. // so we always keep the current `display` value regardless of the `style`
  9092. // value, thus handing over control to `v-show`.
  9093. if ('_vod' in el) {
  9094. style.display = currentDisplay;
  9095. }
  9096. }
  9097. }
  9098. const importantRE = /\s*!important$/;
  9099. function setStyle(style, name, val) {
  9100. if (isArray(val)) {
  9101. val.forEach(v => setStyle(style, name, v));
  9102. }
  9103. else {
  9104. if (name.startsWith('--')) {
  9105. // custom property definition
  9106. style.setProperty(name, val);
  9107. }
  9108. else {
  9109. const prefixed = autoPrefix(style, name);
  9110. if (importantRE.test(val)) {
  9111. // !important
  9112. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9113. }
  9114. else {
  9115. style[prefixed] = val;
  9116. }
  9117. }
  9118. }
  9119. }
  9120. const prefixes = ['Webkit', 'Moz', 'ms'];
  9121. const prefixCache = {};
  9122. function autoPrefix(style, rawName) {
  9123. const cached = prefixCache[rawName];
  9124. if (cached) {
  9125. return cached;
  9126. }
  9127. let name = camelize(rawName);
  9128. if (name !== 'filter' && name in style) {
  9129. return (prefixCache[rawName] = name);
  9130. }
  9131. name = capitalize(name);
  9132. for (let i = 0; i < prefixes.length; i++) {
  9133. const prefixed = prefixes[i] + name;
  9134. if (prefixed in style) {
  9135. return (prefixCache[rawName] = prefixed);
  9136. }
  9137. }
  9138. return rawName;
  9139. }
  9140. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9141. function patchAttr(el, key, value, isSVG, instance) {
  9142. if (isSVG && key.startsWith('xlink:')) {
  9143. if (value == null) {
  9144. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9145. }
  9146. else {
  9147. el.setAttributeNS(xlinkNS, key, value);
  9148. }
  9149. }
  9150. else {
  9151. // note we are only checking boolean attributes that don't have a
  9152. // corresponding dom prop of the same name here.
  9153. const isBoolean = isSpecialBooleanAttr(key);
  9154. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9155. el.removeAttribute(key);
  9156. }
  9157. else {
  9158. el.setAttribute(key, isBoolean ? '' : value);
  9159. }
  9160. }
  9161. }
  9162. // __UNSAFE__
  9163. // functions. The user is responsible for using them with only trusted content.
  9164. function patchDOMProp(el, key, value,
  9165. // the following args are passed only due to potential innerHTML/textContent
  9166. // overriding existing VNodes, in which case the old tree must be properly
  9167. // unmounted.
  9168. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9169. if (key === 'innerHTML' || key === 'textContent') {
  9170. if (prevChildren) {
  9171. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9172. }
  9173. el[key] = value == null ? '' : value;
  9174. return;
  9175. }
  9176. if (key === 'value' &&
  9177. el.tagName !== 'PROGRESS' &&
  9178. // custom elements may use _value internally
  9179. !el.tagName.includes('-')) {
  9180. // store value as _value as well since
  9181. // non-string values will be stringified.
  9182. el._value = value;
  9183. const newValue = value == null ? '' : value;
  9184. if (el.value !== newValue ||
  9185. // #4956: always set for OPTION elements because its value falls back to
  9186. // textContent if no value attribute is present. And setting .value for
  9187. // OPTION has no side effect
  9188. el.tagName === 'OPTION') {
  9189. el.value = newValue;
  9190. }
  9191. if (value == null) {
  9192. el.removeAttribute(key);
  9193. }
  9194. return;
  9195. }
  9196. if (value === '' || value == null) {
  9197. const type = typeof el[key];
  9198. if (type === 'boolean') {
  9199. // e.g. <select multiple> compiles to { multiple: '' }
  9200. el[key] = includeBooleanAttr(value);
  9201. return;
  9202. }
  9203. else if (value == null && type === 'string') {
  9204. // e.g. <div :id="null">
  9205. el[key] = '';
  9206. el.removeAttribute(key);
  9207. return;
  9208. }
  9209. else if (type === 'number') {
  9210. // e.g. <img :width="null">
  9211. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  9212. try {
  9213. el[key] = 0;
  9214. }
  9215. catch (_a) { }
  9216. el.removeAttribute(key);
  9217. return;
  9218. }
  9219. }
  9220. // some properties perform value validation and throw
  9221. try {
  9222. el[key] = value;
  9223. }
  9224. catch (e) {
  9225. {
  9226. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9227. `value ${value} is invalid.`, e);
  9228. }
  9229. }
  9230. }
  9231. // Async edge case fix requires storing an event listener's attach timestamp.
  9232. let _getNow = Date.now;
  9233. let skipTimestampCheck = false;
  9234. if (typeof window !== 'undefined') {
  9235. // Determine what event timestamp the browser is using. Annoyingly, the
  9236. // timestamp can either be hi-res (relative to page load) or low-res
  9237. // (relative to UNIX epoch), so in order to compare time we have to use the
  9238. // same timestamp type when saving the flush timestamp.
  9239. if (_getNow() > document.createEvent('Event').timeStamp) {
  9240. // if the low-res timestamp which is bigger than the event timestamp
  9241. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  9242. // and we need to use the hi-res version for event listeners as well.
  9243. _getNow = () => performance.now();
  9244. }
  9245. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  9246. // and does not fire microtasks in between event propagation, so safe to exclude.
  9247. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  9248. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  9249. }
  9250. // To avoid the overhead of repeatedly calling performance.now(), we cache
  9251. // and use the same timestamp for all event listeners attached in the same tick.
  9252. let cachedNow = 0;
  9253. const p = Promise.resolve();
  9254. const reset = () => {
  9255. cachedNow = 0;
  9256. };
  9257. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  9258. function addEventListener(el, event, handler, options) {
  9259. el.addEventListener(event, handler, options);
  9260. }
  9261. function removeEventListener(el, event, handler, options) {
  9262. el.removeEventListener(event, handler, options);
  9263. }
  9264. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9265. // vei = vue event invokers
  9266. const invokers = el._vei || (el._vei = {});
  9267. const existingInvoker = invokers[rawName];
  9268. if (nextValue && existingInvoker) {
  9269. // patch
  9270. existingInvoker.value = nextValue;
  9271. }
  9272. else {
  9273. const [name, options] = parseName(rawName);
  9274. if (nextValue) {
  9275. // add
  9276. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9277. addEventListener(el, name, invoker, options);
  9278. }
  9279. else if (existingInvoker) {
  9280. // remove
  9281. removeEventListener(el, name, existingInvoker, options);
  9282. invokers[rawName] = undefined;
  9283. }
  9284. }
  9285. }
  9286. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9287. function parseName(name) {
  9288. let options;
  9289. if (optionsModifierRE.test(name)) {
  9290. options = {};
  9291. let m;
  9292. while ((m = name.match(optionsModifierRE))) {
  9293. name = name.slice(0, name.length - m[0].length);
  9294. options[m[0].toLowerCase()] = true;
  9295. }
  9296. }
  9297. return [hyphenate(name.slice(2)), options];
  9298. }
  9299. function createInvoker(initialValue, instance) {
  9300. const invoker = (e) => {
  9301. // async edge case #6566: inner click event triggers patch, event handler
  9302. // attached to outer element during patch, and triggered again. This
  9303. // happens because browsers fire microtask ticks between event propagation.
  9304. // the solution is simple: we save the timestamp when a handler is attached,
  9305. // and the handler would only fire if the event passed to it was fired
  9306. // AFTER it was attached.
  9307. const timeStamp = e.timeStamp || _getNow();
  9308. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  9309. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  9310. }
  9311. };
  9312. invoker.value = initialValue;
  9313. invoker.attached = getNow();
  9314. return invoker;
  9315. }
  9316. function patchStopImmediatePropagation(e, value) {
  9317. if (isArray(value)) {
  9318. const originalStop = e.stopImmediatePropagation;
  9319. e.stopImmediatePropagation = () => {
  9320. originalStop.call(e);
  9321. e._stopped = true;
  9322. };
  9323. return value.map(fn => (e) => !e._stopped && fn(e));
  9324. }
  9325. else {
  9326. return value;
  9327. }
  9328. }
  9329. const nativeOnRE = /^on[a-z]/;
  9330. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9331. if (key === 'class') {
  9332. patchClass(el, nextValue, isSVG);
  9333. }
  9334. else if (key === 'style') {
  9335. patchStyle(el, prevValue, nextValue);
  9336. }
  9337. else if (isOn(key)) {
  9338. // ignore v-model listeners
  9339. if (!isModelListener(key)) {
  9340. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9341. }
  9342. }
  9343. else if (key[0] === '.'
  9344. ? ((key = key.slice(1)), true)
  9345. : key[0] === '^'
  9346. ? ((key = key.slice(1)), false)
  9347. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9348. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9349. }
  9350. else {
  9351. // special case for <input v-model type="checkbox"> with
  9352. // :true-value & :false-value
  9353. // store value as dom properties since non-string values will be
  9354. // stringified.
  9355. if (key === 'true-value') {
  9356. el._trueValue = nextValue;
  9357. }
  9358. else if (key === 'false-value') {
  9359. el._falseValue = nextValue;
  9360. }
  9361. patchAttr(el, key, nextValue, isSVG);
  9362. }
  9363. };
  9364. function shouldSetAsProp(el, key, value, isSVG) {
  9365. if (isSVG) {
  9366. // most keys must be set as attribute on svg elements to work
  9367. // ...except innerHTML & textContent
  9368. if (key === 'innerHTML' || key === 'textContent') {
  9369. return true;
  9370. }
  9371. // or native onclick with function values
  9372. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9373. return true;
  9374. }
  9375. return false;
  9376. }
  9377. // spellcheck and draggable are numerated attrs, however their
  9378. // corresponding DOM properties are actually booleans - this leads to
  9379. // setting it with a string "false" value leading it to be coerced to
  9380. // `true`, so we need to always treat them as attributes.
  9381. // Note that `contentEditable` doesn't have this problem: its DOM
  9382. // property is also enumerated string values.
  9383. if (key === 'spellcheck' || key === 'draggable') {
  9384. return false;
  9385. }
  9386. // #1787, #2840 form property on form elements is readonly and must be set as
  9387. // attribute.
  9388. if (key === 'form') {
  9389. return false;
  9390. }
  9391. // #1526 <input list> must be set as attribute
  9392. if (key === 'list' && el.tagName === 'INPUT') {
  9393. return false;
  9394. }
  9395. // #2766 <textarea type> must be set as attribute
  9396. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9397. return false;
  9398. }
  9399. // native onclick with string value, must be set as attribute
  9400. if (nativeOnRE.test(key) && isString(value)) {
  9401. return false;
  9402. }
  9403. return key in el;
  9404. }
  9405. function defineCustomElement(options, hydate) {
  9406. const Comp = defineComponent(options);
  9407. class VueCustomElement extends VueElement {
  9408. constructor(initialProps) {
  9409. super(Comp, initialProps, hydate);
  9410. }
  9411. }
  9412. VueCustomElement.def = Comp;
  9413. return VueCustomElement;
  9414. }
  9415. const defineSSRCustomElement = ((options) => {
  9416. // @ts-ignore
  9417. return defineCustomElement(options, hydrate);
  9418. });
  9419. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9420. });
  9421. class VueElement extends BaseClass {
  9422. constructor(_def, _props = {}, hydrate) {
  9423. super();
  9424. this._def = _def;
  9425. this._props = _props;
  9426. /**
  9427. * @internal
  9428. */
  9429. this._instance = null;
  9430. this._connected = false;
  9431. this._resolved = false;
  9432. this._numberProps = null;
  9433. if (this.shadowRoot && hydrate) {
  9434. hydrate(this._createVNode(), this.shadowRoot);
  9435. }
  9436. else {
  9437. if (this.shadowRoot) {
  9438. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9439. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9440. }
  9441. this.attachShadow({ mode: 'open' });
  9442. }
  9443. }
  9444. connectedCallback() {
  9445. this._connected = true;
  9446. if (!this._instance) {
  9447. this._resolveDef();
  9448. }
  9449. }
  9450. disconnectedCallback() {
  9451. this._connected = false;
  9452. nextTick(() => {
  9453. if (!this._connected) {
  9454. render(null, this.shadowRoot);
  9455. this._instance = null;
  9456. }
  9457. });
  9458. }
  9459. /**
  9460. * resolve inner component definition (handle possible async component)
  9461. */
  9462. _resolveDef() {
  9463. if (this._resolved) {
  9464. return;
  9465. }
  9466. this._resolved = true;
  9467. // set initial attrs
  9468. for (let i = 0; i < this.attributes.length; i++) {
  9469. this._setAttr(this.attributes[i].name);
  9470. }
  9471. // watch future attr changes
  9472. new MutationObserver(mutations => {
  9473. for (const m of mutations) {
  9474. this._setAttr(m.attributeName);
  9475. }
  9476. }).observe(this, { attributes: true });
  9477. const resolve = (def) => {
  9478. const { props, styles } = def;
  9479. const hasOptions = !isArray(props);
  9480. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  9481. // cast Number-type props set before resolve
  9482. let numberProps;
  9483. if (hasOptions) {
  9484. for (const key in this._props) {
  9485. const opt = props[key];
  9486. if (opt === Number || (opt && opt.type === Number)) {
  9487. this._props[key] = toNumber(this._props[key]);
  9488. (numberProps || (numberProps = Object.create(null)))[key] = true;
  9489. }
  9490. }
  9491. }
  9492. this._numberProps = numberProps;
  9493. // check if there are props set pre-upgrade or connect
  9494. for (const key of Object.keys(this)) {
  9495. if (key[0] !== '_') {
  9496. this._setProp(key, this[key], true, false);
  9497. }
  9498. }
  9499. // defining getter/setters on prototype
  9500. for (const key of rawKeys.map(camelize)) {
  9501. Object.defineProperty(this, key, {
  9502. get() {
  9503. return this._getProp(key);
  9504. },
  9505. set(val) {
  9506. this._setProp(key, val);
  9507. }
  9508. });
  9509. }
  9510. // apply CSS
  9511. this._applyStyles(styles);
  9512. // initial render
  9513. this._update();
  9514. };
  9515. const asyncDef = this._def.__asyncLoader;
  9516. if (asyncDef) {
  9517. asyncDef().then(resolve);
  9518. }
  9519. else {
  9520. resolve(this._def);
  9521. }
  9522. }
  9523. _setAttr(key) {
  9524. let value = this.getAttribute(key);
  9525. if (this._numberProps && this._numberProps[key]) {
  9526. value = toNumber(value);
  9527. }
  9528. this._setProp(camelize(key), value, false);
  9529. }
  9530. /**
  9531. * @internal
  9532. */
  9533. _getProp(key) {
  9534. return this._props[key];
  9535. }
  9536. /**
  9537. * @internal
  9538. */
  9539. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9540. if (val !== this._props[key]) {
  9541. this._props[key] = val;
  9542. if (shouldUpdate && this._instance) {
  9543. this._update();
  9544. }
  9545. // reflect
  9546. if (shouldReflect) {
  9547. if (val === true) {
  9548. this.setAttribute(hyphenate(key), '');
  9549. }
  9550. else if (typeof val === 'string' || typeof val === 'number') {
  9551. this.setAttribute(hyphenate(key), val + '');
  9552. }
  9553. else if (!val) {
  9554. this.removeAttribute(hyphenate(key));
  9555. }
  9556. }
  9557. }
  9558. }
  9559. _update() {
  9560. render(this._createVNode(), this.shadowRoot);
  9561. }
  9562. _createVNode() {
  9563. const vnode = createVNode(this._def, extend({}, this._props));
  9564. if (!this._instance) {
  9565. vnode.ce = instance => {
  9566. this._instance = instance;
  9567. instance.isCE = true;
  9568. // HMR
  9569. {
  9570. instance.ceReload = newStyles => {
  9571. // always reset styles
  9572. if (this._styles) {
  9573. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9574. this._styles.length = 0;
  9575. }
  9576. this._applyStyles(newStyles);
  9577. // if this is an async component, ceReload is called from the inner
  9578. // component so no need to reload the async wrapper
  9579. if (!this._def.__asyncLoader) {
  9580. // reload
  9581. this._instance = null;
  9582. this._update();
  9583. }
  9584. };
  9585. }
  9586. // intercept emit
  9587. instance.emit = (event, ...args) => {
  9588. this.dispatchEvent(new CustomEvent(event, {
  9589. detail: args
  9590. }));
  9591. };
  9592. // locate nearest Vue custom element parent for provide/inject
  9593. let parent = this;
  9594. while ((parent =
  9595. parent && (parent.parentNode || parent.host))) {
  9596. if (parent instanceof VueElement) {
  9597. instance.parent = parent._instance;
  9598. break;
  9599. }
  9600. }
  9601. };
  9602. }
  9603. return vnode;
  9604. }
  9605. _applyStyles(styles) {
  9606. if (styles) {
  9607. styles.forEach(css => {
  9608. const s = document.createElement('style');
  9609. s.textContent = css;
  9610. this.shadowRoot.appendChild(s);
  9611. // record for HMR
  9612. {
  9613. (this._styles || (this._styles = [])).push(s);
  9614. }
  9615. });
  9616. }
  9617. }
  9618. }
  9619. function useCssModule(name = '$style') {
  9620. /* istanbul ignore else */
  9621. {
  9622. const instance = getCurrentInstance();
  9623. if (!instance) {
  9624. warn$1(`useCssModule must be called inside setup()`);
  9625. return EMPTY_OBJ;
  9626. }
  9627. const modules = instance.type.__cssModules;
  9628. if (!modules) {
  9629. warn$1(`Current instance does not have CSS modules injected.`);
  9630. return EMPTY_OBJ;
  9631. }
  9632. const mod = modules[name];
  9633. if (!mod) {
  9634. warn$1(`Current instance does not have CSS module named "${name}".`);
  9635. return EMPTY_OBJ;
  9636. }
  9637. return mod;
  9638. }
  9639. }
  9640. /**
  9641. * Runtime helper for SFC's CSS variable injection feature.
  9642. * @private
  9643. */
  9644. function useCssVars(getter) {
  9645. const instance = getCurrentInstance();
  9646. /* istanbul ignore next */
  9647. if (!instance) {
  9648. warn$1(`useCssVars is called without current active component instance.`);
  9649. return;
  9650. }
  9651. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  9652. watchPostEffect(setVars);
  9653. onMounted(() => {
  9654. const ob = new MutationObserver(setVars);
  9655. ob.observe(instance.subTree.el.parentNode, { childList: true });
  9656. onUnmounted(() => ob.disconnect());
  9657. });
  9658. }
  9659. function setVarsOnVNode(vnode, vars) {
  9660. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  9661. const suspense = vnode.suspense;
  9662. vnode = suspense.activeBranch;
  9663. if (suspense.pendingBranch && !suspense.isHydrating) {
  9664. suspense.effects.push(() => {
  9665. setVarsOnVNode(suspense.activeBranch, vars);
  9666. });
  9667. }
  9668. }
  9669. // drill down HOCs until it's a non-component vnode
  9670. while (vnode.component) {
  9671. vnode = vnode.component.subTree;
  9672. }
  9673. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  9674. setVarsOnNode(vnode.el, vars);
  9675. }
  9676. else if (vnode.type === Fragment) {
  9677. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  9678. }
  9679. else if (vnode.type === Static) {
  9680. let { el, anchor } = vnode;
  9681. while (el) {
  9682. setVarsOnNode(el, vars);
  9683. if (el === anchor)
  9684. break;
  9685. el = el.nextSibling;
  9686. }
  9687. }
  9688. }
  9689. function setVarsOnNode(el, vars) {
  9690. if (el.nodeType === 1) {
  9691. const style = el.style;
  9692. for (const key in vars) {
  9693. style.setProperty(`--${key}`, vars[key]);
  9694. }
  9695. }
  9696. }
  9697. const TRANSITION = 'transition';
  9698. const ANIMATION = 'animation';
  9699. // DOM Transition is a higher-order-component based on the platform-agnostic
  9700. // base Transition component, with DOM-specific logic.
  9701. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  9702. Transition.displayName = 'Transition';
  9703. const DOMTransitionPropsValidators = {
  9704. name: String,
  9705. type: String,
  9706. css: {
  9707. type: Boolean,
  9708. default: true
  9709. },
  9710. duration: [String, Number, Object],
  9711. enterFromClass: String,
  9712. enterActiveClass: String,
  9713. enterToClass: String,
  9714. appearFromClass: String,
  9715. appearActiveClass: String,
  9716. appearToClass: String,
  9717. leaveFromClass: String,
  9718. leaveActiveClass: String,
  9719. leaveToClass: String
  9720. };
  9721. const TransitionPropsValidators = (Transition.props =
  9722. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  9723. /**
  9724. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  9725. * with custom HOCs.
  9726. */
  9727. const callHook$1 = (hook, args = []) => {
  9728. if (isArray(hook)) {
  9729. hook.forEach(h => h(...args));
  9730. }
  9731. else if (hook) {
  9732. hook(...args);
  9733. }
  9734. };
  9735. /**
  9736. * Check if a hook expects a callback (2nd arg), which means the user
  9737. * intends to explicitly control the end of the transition.
  9738. */
  9739. const hasExplicitCallback = (hook) => {
  9740. return hook
  9741. ? isArray(hook)
  9742. ? hook.some(h => h.length > 1)
  9743. : hook.length > 1
  9744. : false;
  9745. };
  9746. function resolveTransitionProps(rawProps) {
  9747. const baseProps = {};
  9748. for (const key in rawProps) {
  9749. if (!(key in DOMTransitionPropsValidators)) {
  9750. baseProps[key] = rawProps[key];
  9751. }
  9752. }
  9753. if (rawProps.css === false) {
  9754. return baseProps;
  9755. }
  9756. const { name = 'v', type, duration, enterFromClass = `${name}-enter-from`, enterActiveClass = `${name}-enter-active`, enterToClass = `${name}-enter-to`, appearFromClass = enterFromClass, appearActiveClass = enterActiveClass, appearToClass = enterToClass, leaveFromClass = `${name}-leave-from`, leaveActiveClass = `${name}-leave-active`, leaveToClass = `${name}-leave-to` } = rawProps;
  9757. const durations = normalizeDuration(duration);
  9758. const enterDuration = durations && durations[0];
  9759. const leaveDuration = durations && durations[1];
  9760. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  9761. const finishEnter = (el, isAppear, done) => {
  9762. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9763. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  9764. done && done();
  9765. };
  9766. const finishLeave = (el, done) => {
  9767. removeTransitionClass(el, leaveToClass);
  9768. removeTransitionClass(el, leaveActiveClass);
  9769. done && done();
  9770. };
  9771. const makeEnterHook = (isAppear) => {
  9772. return (el, done) => {
  9773. const hook = isAppear ? onAppear : onEnter;
  9774. const resolve = () => finishEnter(el, isAppear, done);
  9775. callHook$1(hook, [el, resolve]);
  9776. nextFrame(() => {
  9777. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  9778. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9779. if (!hasExplicitCallback(hook)) {
  9780. whenTransitionEnds(el, type, enterDuration, resolve);
  9781. }
  9782. });
  9783. };
  9784. };
  9785. return extend(baseProps, {
  9786. onBeforeEnter(el) {
  9787. callHook$1(onBeforeEnter, [el]);
  9788. addTransitionClass(el, enterFromClass);
  9789. addTransitionClass(el, enterActiveClass);
  9790. },
  9791. onBeforeAppear(el) {
  9792. callHook$1(onBeforeAppear, [el]);
  9793. addTransitionClass(el, appearFromClass);
  9794. addTransitionClass(el, appearActiveClass);
  9795. },
  9796. onEnter: makeEnterHook(false),
  9797. onAppear: makeEnterHook(true),
  9798. onLeave(el, done) {
  9799. const resolve = () => finishLeave(el, done);
  9800. addTransitionClass(el, leaveFromClass);
  9801. // force reflow so *-leave-from classes immediately take effect (#2593)
  9802. forceReflow();
  9803. addTransitionClass(el, leaveActiveClass);
  9804. nextFrame(() => {
  9805. removeTransitionClass(el, leaveFromClass);
  9806. addTransitionClass(el, leaveToClass);
  9807. if (!hasExplicitCallback(onLeave)) {
  9808. whenTransitionEnds(el, type, leaveDuration, resolve);
  9809. }
  9810. });
  9811. callHook$1(onLeave, [el, resolve]);
  9812. },
  9813. onEnterCancelled(el) {
  9814. finishEnter(el, false);
  9815. callHook$1(onEnterCancelled, [el]);
  9816. },
  9817. onAppearCancelled(el) {
  9818. finishEnter(el, true);
  9819. callHook$1(onAppearCancelled, [el]);
  9820. },
  9821. onLeaveCancelled(el) {
  9822. finishLeave(el);
  9823. callHook$1(onLeaveCancelled, [el]);
  9824. }
  9825. });
  9826. }
  9827. function normalizeDuration(duration) {
  9828. if (duration == null) {
  9829. return null;
  9830. }
  9831. else if (isObject(duration)) {
  9832. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  9833. }
  9834. else {
  9835. const n = NumberOf(duration);
  9836. return [n, n];
  9837. }
  9838. }
  9839. function NumberOf(val) {
  9840. const res = toNumber(val);
  9841. validateDuration(res);
  9842. return res;
  9843. }
  9844. function validateDuration(val) {
  9845. if (typeof val !== 'number') {
  9846. warn$1(`<transition> explicit duration is not a valid number - ` +
  9847. `got ${JSON.stringify(val)}.`);
  9848. }
  9849. else if (isNaN(val)) {
  9850. warn$1(`<transition> explicit duration is NaN - ` +
  9851. 'the duration expression might be incorrect.');
  9852. }
  9853. }
  9854. function addTransitionClass(el, cls) {
  9855. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  9856. (el._vtc ||
  9857. (el._vtc = new Set())).add(cls);
  9858. }
  9859. function removeTransitionClass(el, cls) {
  9860. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  9861. const { _vtc } = el;
  9862. if (_vtc) {
  9863. _vtc.delete(cls);
  9864. if (!_vtc.size) {
  9865. el._vtc = undefined;
  9866. }
  9867. }
  9868. }
  9869. function nextFrame(cb) {
  9870. requestAnimationFrame(() => {
  9871. requestAnimationFrame(cb);
  9872. });
  9873. }
  9874. let endId = 0;
  9875. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  9876. const id = (el._endId = ++endId);
  9877. const resolveIfNotStale = () => {
  9878. if (id === el._endId) {
  9879. resolve();
  9880. }
  9881. };
  9882. if (explicitTimeout) {
  9883. return setTimeout(resolveIfNotStale, explicitTimeout);
  9884. }
  9885. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  9886. if (!type) {
  9887. return resolve();
  9888. }
  9889. const endEvent = type + 'end';
  9890. let ended = 0;
  9891. const end = () => {
  9892. el.removeEventListener(endEvent, onEnd);
  9893. resolveIfNotStale();
  9894. };
  9895. const onEnd = (e) => {
  9896. if (e.target === el && ++ended >= propCount) {
  9897. end();
  9898. }
  9899. };
  9900. setTimeout(() => {
  9901. if (ended < propCount) {
  9902. end();
  9903. }
  9904. }, timeout + 1);
  9905. el.addEventListener(endEvent, onEnd);
  9906. }
  9907. function getTransitionInfo(el, expectedType) {
  9908. const styles = window.getComputedStyle(el);
  9909. // JSDOM may return undefined for transition properties
  9910. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  9911. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  9912. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  9913. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  9914. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  9915. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  9916. const animationTimeout = getTimeout(animationDelays, animationDurations);
  9917. let type = null;
  9918. let timeout = 0;
  9919. let propCount = 0;
  9920. /* istanbul ignore if */
  9921. if (expectedType === TRANSITION) {
  9922. if (transitionTimeout > 0) {
  9923. type = TRANSITION;
  9924. timeout = transitionTimeout;
  9925. propCount = transitionDurations.length;
  9926. }
  9927. }
  9928. else if (expectedType === ANIMATION) {
  9929. if (animationTimeout > 0) {
  9930. type = ANIMATION;
  9931. timeout = animationTimeout;
  9932. propCount = animationDurations.length;
  9933. }
  9934. }
  9935. else {
  9936. timeout = Math.max(transitionTimeout, animationTimeout);
  9937. type =
  9938. timeout > 0
  9939. ? transitionTimeout > animationTimeout
  9940. ? TRANSITION
  9941. : ANIMATION
  9942. : null;
  9943. propCount = type
  9944. ? type === TRANSITION
  9945. ? transitionDurations.length
  9946. : animationDurations.length
  9947. : 0;
  9948. }
  9949. const hasTransform = type === TRANSITION &&
  9950. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  9951. return {
  9952. type,
  9953. timeout,
  9954. propCount,
  9955. hasTransform
  9956. };
  9957. }
  9958. function getTimeout(delays, durations) {
  9959. while (delays.length < durations.length) {
  9960. delays = delays.concat(delays);
  9961. }
  9962. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  9963. }
  9964. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  9965. // numbers in a locale-dependent way, using a comma instead of a dot.
  9966. // If comma is not replaced with a dot, the input will be rounded down
  9967. // (i.e. acting as a floor function) causing unexpected behaviors
  9968. function toMs(s) {
  9969. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  9970. }
  9971. // synchronously force layout to put elements into a certain state
  9972. function forceReflow() {
  9973. return document.body.offsetHeight;
  9974. }
  9975. const positionMap = new WeakMap();
  9976. const newPositionMap = new WeakMap();
  9977. const TransitionGroupImpl = {
  9978. name: 'TransitionGroup',
  9979. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  9980. tag: String,
  9981. moveClass: String
  9982. }),
  9983. setup(props, { slots }) {
  9984. const instance = getCurrentInstance();
  9985. const state = useTransitionState();
  9986. let prevChildren;
  9987. let children;
  9988. onUpdated(() => {
  9989. // children is guaranteed to exist after initial render
  9990. if (!prevChildren.length) {
  9991. return;
  9992. }
  9993. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  9994. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  9995. return;
  9996. }
  9997. // we divide the work into three loops to avoid mixing DOM reads and writes
  9998. // in each iteration - which helps prevent layout thrashing.
  9999. prevChildren.forEach(callPendingCbs);
  10000. prevChildren.forEach(recordPosition);
  10001. const movedChildren = prevChildren.filter(applyTranslation);
  10002. // force reflow to put everything in position
  10003. forceReflow();
  10004. movedChildren.forEach(c => {
  10005. const el = c.el;
  10006. const style = el.style;
  10007. addTransitionClass(el, moveClass);
  10008. style.transform = style.webkitTransform = style.transitionDuration = '';
  10009. const cb = (el._moveCb = (e) => {
  10010. if (e && e.target !== el) {
  10011. return;
  10012. }
  10013. if (!e || /transform$/.test(e.propertyName)) {
  10014. el.removeEventListener('transitionend', cb);
  10015. el._moveCb = null;
  10016. removeTransitionClass(el, moveClass);
  10017. }
  10018. });
  10019. el.addEventListener('transitionend', cb);
  10020. });
  10021. });
  10022. return () => {
  10023. const rawProps = toRaw(props);
  10024. const cssTransitionProps = resolveTransitionProps(rawProps);
  10025. let tag = rawProps.tag || Fragment;
  10026. prevChildren = children;
  10027. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10028. for (let i = 0; i < children.length; i++) {
  10029. const child = children[i];
  10030. if (child.key != null) {
  10031. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10032. }
  10033. else {
  10034. warn$1(`<TransitionGroup> children must be keyed.`);
  10035. }
  10036. }
  10037. if (prevChildren) {
  10038. for (let i = 0; i < prevChildren.length; i++) {
  10039. const child = prevChildren[i];
  10040. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10041. positionMap.set(child, child.el.getBoundingClientRect());
  10042. }
  10043. }
  10044. return createVNode(tag, null, children);
  10045. };
  10046. }
  10047. };
  10048. const TransitionGroup = TransitionGroupImpl;
  10049. function callPendingCbs(c) {
  10050. const el = c.el;
  10051. if (el._moveCb) {
  10052. el._moveCb();
  10053. }
  10054. if (el._enterCb) {
  10055. el._enterCb();
  10056. }
  10057. }
  10058. function recordPosition(c) {
  10059. newPositionMap.set(c, c.el.getBoundingClientRect());
  10060. }
  10061. function applyTranslation(c) {
  10062. const oldPos = positionMap.get(c);
  10063. const newPos = newPositionMap.get(c);
  10064. const dx = oldPos.left - newPos.left;
  10065. const dy = oldPos.top - newPos.top;
  10066. if (dx || dy) {
  10067. const s = c.el.style;
  10068. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10069. s.transitionDuration = '0s';
  10070. return c;
  10071. }
  10072. }
  10073. function hasCSSTransform(el, root, moveClass) {
  10074. // Detect whether an element with the move class applied has
  10075. // CSS transitions. Since the element may be inside an entering
  10076. // transition at this very moment, we make a clone of it and remove
  10077. // all other transition classes applied to ensure only the move class
  10078. // is applied.
  10079. const clone = el.cloneNode();
  10080. if (el._vtc) {
  10081. el._vtc.forEach(cls => {
  10082. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10083. });
  10084. }
  10085. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10086. clone.style.display = 'none';
  10087. const container = (root.nodeType === 1 ? root : root.parentNode);
  10088. container.appendChild(clone);
  10089. const { hasTransform } = getTransitionInfo(clone);
  10090. container.removeChild(clone);
  10091. return hasTransform;
  10092. }
  10093. const getModelAssigner = (vnode) => {
  10094. const fn = vnode.props['onUpdate:modelValue'];
  10095. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10096. };
  10097. function onCompositionStart(e) {
  10098. e.target.composing = true;
  10099. }
  10100. function onCompositionEnd(e) {
  10101. const target = e.target;
  10102. if (target.composing) {
  10103. target.composing = false;
  10104. trigger$1(target, 'input');
  10105. }
  10106. }
  10107. function trigger$1(el, type) {
  10108. const e = document.createEvent('HTMLEvents');
  10109. e.initEvent(type, true, true);
  10110. el.dispatchEvent(e);
  10111. }
  10112. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10113. // be tree-shaken in case v-model is never used.
  10114. const vModelText = {
  10115. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10116. el._assign = getModelAssigner(vnode);
  10117. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10118. addEventListener(el, lazy ? 'change' : 'input', e => {
  10119. if (e.target.composing)
  10120. return;
  10121. let domValue = el.value;
  10122. if (trim) {
  10123. domValue = domValue.trim();
  10124. }
  10125. else if (castToNumber) {
  10126. domValue = toNumber(domValue);
  10127. }
  10128. el._assign(domValue);
  10129. });
  10130. if (trim) {
  10131. addEventListener(el, 'change', () => {
  10132. el.value = el.value.trim();
  10133. });
  10134. }
  10135. if (!lazy) {
  10136. addEventListener(el, 'compositionstart', onCompositionStart);
  10137. addEventListener(el, 'compositionend', onCompositionEnd);
  10138. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10139. // switching focus before confirming composition choice
  10140. // this also fixes the issue where some browsers e.g. iOS Chrome
  10141. // fires "change" instead of "input" on autocomplete.
  10142. addEventListener(el, 'change', onCompositionEnd);
  10143. }
  10144. },
  10145. // set value on mounted so it's after min/max for type="range"
  10146. mounted(el, { value }) {
  10147. el.value = value == null ? '' : value;
  10148. },
  10149. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10150. el._assign = getModelAssigner(vnode);
  10151. // avoid clearing unresolved text. #2302
  10152. if (el.composing)
  10153. return;
  10154. if (document.activeElement === el) {
  10155. if (lazy) {
  10156. return;
  10157. }
  10158. if (trim && el.value.trim() === value) {
  10159. return;
  10160. }
  10161. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10162. return;
  10163. }
  10164. }
  10165. const newValue = value == null ? '' : value;
  10166. if (el.value !== newValue) {
  10167. el.value = newValue;
  10168. }
  10169. }
  10170. };
  10171. const vModelCheckbox = {
  10172. // #4096 array checkboxes need to be deep traversed
  10173. deep: true,
  10174. created(el, _, vnode) {
  10175. el._assign = getModelAssigner(vnode);
  10176. addEventListener(el, 'change', () => {
  10177. const modelValue = el._modelValue;
  10178. const elementValue = getValue(el);
  10179. const checked = el.checked;
  10180. const assign = el._assign;
  10181. if (isArray(modelValue)) {
  10182. const index = looseIndexOf(modelValue, elementValue);
  10183. const found = index !== -1;
  10184. if (checked && !found) {
  10185. assign(modelValue.concat(elementValue));
  10186. }
  10187. else if (!checked && found) {
  10188. const filtered = [...modelValue];
  10189. filtered.splice(index, 1);
  10190. assign(filtered);
  10191. }
  10192. }
  10193. else if (isSet(modelValue)) {
  10194. const cloned = new Set(modelValue);
  10195. if (checked) {
  10196. cloned.add(elementValue);
  10197. }
  10198. else {
  10199. cloned.delete(elementValue);
  10200. }
  10201. assign(cloned);
  10202. }
  10203. else {
  10204. assign(getCheckboxValue(el, checked));
  10205. }
  10206. });
  10207. },
  10208. // set initial checked on mount to wait for true-value/false-value
  10209. mounted: setChecked,
  10210. beforeUpdate(el, binding, vnode) {
  10211. el._assign = getModelAssigner(vnode);
  10212. setChecked(el, binding, vnode);
  10213. }
  10214. };
  10215. function setChecked(el, { value, oldValue }, vnode) {
  10216. el._modelValue = value;
  10217. if (isArray(value)) {
  10218. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10219. }
  10220. else if (isSet(value)) {
  10221. el.checked = value.has(vnode.props.value);
  10222. }
  10223. else if (value !== oldValue) {
  10224. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10225. }
  10226. }
  10227. const vModelRadio = {
  10228. created(el, { value }, vnode) {
  10229. el.checked = looseEqual(value, vnode.props.value);
  10230. el._assign = getModelAssigner(vnode);
  10231. addEventListener(el, 'change', () => {
  10232. el._assign(getValue(el));
  10233. });
  10234. },
  10235. beforeUpdate(el, { value, oldValue }, vnode) {
  10236. el._assign = getModelAssigner(vnode);
  10237. if (value !== oldValue) {
  10238. el.checked = looseEqual(value, vnode.props.value);
  10239. }
  10240. }
  10241. };
  10242. const vModelSelect = {
  10243. // <select multiple> value need to be deep traversed
  10244. deep: true,
  10245. created(el, { value, modifiers: { number } }, vnode) {
  10246. const isSetModel = isSet(value);
  10247. addEventListener(el, 'change', () => {
  10248. const selectedVal = Array.prototype.filter
  10249. .call(el.options, (o) => o.selected)
  10250. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10251. el._assign(el.multiple
  10252. ? isSetModel
  10253. ? new Set(selectedVal)
  10254. : selectedVal
  10255. : selectedVal[0]);
  10256. });
  10257. el._assign = getModelAssigner(vnode);
  10258. },
  10259. // set value in mounted & updated because <select> relies on its children
  10260. // <option>s.
  10261. mounted(el, { value }) {
  10262. setSelected(el, value);
  10263. },
  10264. beforeUpdate(el, _binding, vnode) {
  10265. el._assign = getModelAssigner(vnode);
  10266. },
  10267. updated(el, { value }) {
  10268. setSelected(el, value);
  10269. }
  10270. };
  10271. function setSelected(el, value) {
  10272. const isMultiple = el.multiple;
  10273. if (isMultiple && !isArray(value) && !isSet(value)) {
  10274. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10275. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10276. return;
  10277. }
  10278. for (let i = 0, l = el.options.length; i < l; i++) {
  10279. const option = el.options[i];
  10280. const optionValue = getValue(option);
  10281. if (isMultiple) {
  10282. if (isArray(value)) {
  10283. option.selected = looseIndexOf(value, optionValue) > -1;
  10284. }
  10285. else {
  10286. option.selected = value.has(optionValue);
  10287. }
  10288. }
  10289. else {
  10290. if (looseEqual(getValue(option), value)) {
  10291. if (el.selectedIndex !== i)
  10292. el.selectedIndex = i;
  10293. return;
  10294. }
  10295. }
  10296. }
  10297. if (!isMultiple && el.selectedIndex !== -1) {
  10298. el.selectedIndex = -1;
  10299. }
  10300. }
  10301. // retrieve raw value set via :value bindings
  10302. function getValue(el) {
  10303. return '_value' in el ? el._value : el.value;
  10304. }
  10305. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10306. function getCheckboxValue(el, checked) {
  10307. const key = checked ? '_trueValue' : '_falseValue';
  10308. return key in el ? el[key] : checked;
  10309. }
  10310. const vModelDynamic = {
  10311. created(el, binding, vnode) {
  10312. callModelHook(el, binding, vnode, null, 'created');
  10313. },
  10314. mounted(el, binding, vnode) {
  10315. callModelHook(el, binding, vnode, null, 'mounted');
  10316. },
  10317. beforeUpdate(el, binding, vnode, prevVNode) {
  10318. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10319. },
  10320. updated(el, binding, vnode, prevVNode) {
  10321. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10322. }
  10323. };
  10324. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10325. let modelToUse;
  10326. switch (el.tagName) {
  10327. case 'SELECT':
  10328. modelToUse = vModelSelect;
  10329. break;
  10330. case 'TEXTAREA':
  10331. modelToUse = vModelText;
  10332. break;
  10333. default:
  10334. switch (vnode.props && vnode.props.type) {
  10335. case 'checkbox':
  10336. modelToUse = vModelCheckbox;
  10337. break;
  10338. case 'radio':
  10339. modelToUse = vModelRadio;
  10340. break;
  10341. default:
  10342. modelToUse = vModelText;
  10343. }
  10344. }
  10345. const fn = modelToUse[hook];
  10346. fn && fn(el, binding, vnode, prevVNode);
  10347. }
  10348. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10349. const modifierGuards = {
  10350. stop: e => e.stopPropagation(),
  10351. prevent: e => e.preventDefault(),
  10352. self: e => e.target !== e.currentTarget,
  10353. ctrl: e => !e.ctrlKey,
  10354. shift: e => !e.shiftKey,
  10355. alt: e => !e.altKey,
  10356. meta: e => !e.metaKey,
  10357. left: e => 'button' in e && e.button !== 0,
  10358. middle: e => 'button' in e && e.button !== 1,
  10359. right: e => 'button' in e && e.button !== 2,
  10360. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10361. };
  10362. /**
  10363. * @private
  10364. */
  10365. const withModifiers = (fn, modifiers) => {
  10366. return (event, ...args) => {
  10367. for (let i = 0; i < modifiers.length; i++) {
  10368. const guard = modifierGuards[modifiers[i]];
  10369. if (guard && guard(event, modifiers))
  10370. return;
  10371. }
  10372. return fn(event, ...args);
  10373. };
  10374. };
  10375. // Kept for 2.x compat.
  10376. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10377. const keyNames = {
  10378. esc: 'escape',
  10379. space: ' ',
  10380. up: 'arrow-up',
  10381. left: 'arrow-left',
  10382. right: 'arrow-right',
  10383. down: 'arrow-down',
  10384. delete: 'backspace'
  10385. };
  10386. /**
  10387. * @private
  10388. */
  10389. const withKeys = (fn, modifiers) => {
  10390. return (event) => {
  10391. if (!('key' in event)) {
  10392. return;
  10393. }
  10394. const eventKey = hyphenate(event.key);
  10395. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10396. return fn(event);
  10397. }
  10398. };
  10399. };
  10400. const vShow = {
  10401. beforeMount(el, { value }, { transition }) {
  10402. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10403. if (transition && value) {
  10404. transition.beforeEnter(el);
  10405. }
  10406. else {
  10407. setDisplay(el, value);
  10408. }
  10409. },
  10410. mounted(el, { value }, { transition }) {
  10411. if (transition && value) {
  10412. transition.enter(el);
  10413. }
  10414. },
  10415. updated(el, { value, oldValue }, { transition }) {
  10416. if (!value === !oldValue)
  10417. return;
  10418. if (transition) {
  10419. if (value) {
  10420. transition.beforeEnter(el);
  10421. setDisplay(el, true);
  10422. transition.enter(el);
  10423. }
  10424. else {
  10425. transition.leave(el, () => {
  10426. setDisplay(el, false);
  10427. });
  10428. }
  10429. }
  10430. else {
  10431. setDisplay(el, value);
  10432. }
  10433. },
  10434. beforeUnmount(el, { value }) {
  10435. setDisplay(el, value);
  10436. }
  10437. };
  10438. function setDisplay(el, value) {
  10439. el.style.display = value ? el._vod : 'none';
  10440. }
  10441. const rendererOptions = extend({ patchProp }, nodeOps);
  10442. // lazy create the renderer - this makes core renderer logic tree-shakable
  10443. // in case the user only imports reactivity utilities from Vue.
  10444. let renderer;
  10445. let enabledHydration = false;
  10446. function ensureRenderer() {
  10447. return (renderer ||
  10448. (renderer = createRenderer(rendererOptions)));
  10449. }
  10450. function ensureHydrationRenderer() {
  10451. renderer = enabledHydration
  10452. ? renderer
  10453. : createHydrationRenderer(rendererOptions);
  10454. enabledHydration = true;
  10455. return renderer;
  10456. }
  10457. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10458. const render = ((...args) => {
  10459. ensureRenderer().render(...args);
  10460. });
  10461. const hydrate = ((...args) => {
  10462. ensureHydrationRenderer().hydrate(...args);
  10463. });
  10464. const createApp = ((...args) => {
  10465. const app = ensureRenderer().createApp(...args);
  10466. {
  10467. injectNativeTagCheck(app);
  10468. injectCompilerOptionsCheck(app);
  10469. }
  10470. const { mount } = app;
  10471. app.mount = (containerOrSelector) => {
  10472. const container = normalizeContainer(containerOrSelector);
  10473. if (!container)
  10474. return;
  10475. const component = app._component;
  10476. if (!isFunction(component) && !component.render && !component.template) {
  10477. // __UNSAFE__
  10478. // Reason: potential execution of JS expressions in in-DOM template.
  10479. // The user must make sure the in-DOM template is trusted. If it's
  10480. // rendered by the server, the template should not contain any user data.
  10481. component.template = container.innerHTML;
  10482. }
  10483. // clear content before mounting
  10484. container.innerHTML = '';
  10485. const proxy = mount(container, false, container instanceof SVGElement);
  10486. if (container instanceof Element) {
  10487. container.removeAttribute('v-cloak');
  10488. container.setAttribute('data-v-app', '');
  10489. }
  10490. return proxy;
  10491. };
  10492. return app;
  10493. });
  10494. const createSSRApp = ((...args) => {
  10495. const app = ensureHydrationRenderer().createApp(...args);
  10496. {
  10497. injectNativeTagCheck(app);
  10498. injectCompilerOptionsCheck(app);
  10499. }
  10500. const { mount } = app;
  10501. app.mount = (containerOrSelector) => {
  10502. const container = normalizeContainer(containerOrSelector);
  10503. if (container) {
  10504. return mount(container, true, container instanceof SVGElement);
  10505. }
  10506. };
  10507. return app;
  10508. });
  10509. function injectNativeTagCheck(app) {
  10510. // Inject `isNativeTag`
  10511. // this is used for component name validation (dev only)
  10512. Object.defineProperty(app.config, 'isNativeTag', {
  10513. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10514. writable: false
  10515. });
  10516. }
  10517. // dev only
  10518. function injectCompilerOptionsCheck(app) {
  10519. if (isRuntimeOnly()) {
  10520. const isCustomElement = app.config.isCustomElement;
  10521. Object.defineProperty(app.config, 'isCustomElement', {
  10522. get() {
  10523. return isCustomElement;
  10524. },
  10525. set() {
  10526. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10527. `\`compilerOptions.isCustomElement\` instead.`);
  10528. }
  10529. });
  10530. const compilerOptions = app.config.compilerOptions;
  10531. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10532. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10533. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10534. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10535. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10536. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10537. `- 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`;
  10538. Object.defineProperty(app.config, 'compilerOptions', {
  10539. get() {
  10540. warn$1(msg);
  10541. return compilerOptions;
  10542. },
  10543. set() {
  10544. warn$1(msg);
  10545. }
  10546. });
  10547. }
  10548. }
  10549. function normalizeContainer(container) {
  10550. if (isString(container)) {
  10551. const res = document.querySelector(container);
  10552. if (!res) {
  10553. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10554. }
  10555. return res;
  10556. }
  10557. if (window.ShadowRoot &&
  10558. container instanceof window.ShadowRoot &&
  10559. container.mode === 'closed') {
  10560. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10561. }
  10562. return container;
  10563. }
  10564. /**
  10565. * @internal
  10566. */
  10567. const initDirectivesForSSR = NOOP;
  10568. function initDev() {
  10569. {
  10570. {
  10571. console.info(`You are running a development build of Vue.\n` +
  10572. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10573. }
  10574. initCustomFormatter();
  10575. }
  10576. }
  10577. // This entry exports the runtime only, and is built as
  10578. {
  10579. initDev();
  10580. }
  10581. const compile$1 = () => {
  10582. {
  10583. warn$1(`Runtime compilation is not supported in this build of Vue.` +
  10584. (` Use "vue.esm-browser.js" instead.`
  10585. ) /* should not happen */);
  10586. }
  10587. };
  10588. export { BaseTransition, Comment, EffectScope, Fragment, KeepAlive, ReactiveEffect, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VueElement, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compatUtils, compile$1 as compile, computed, createApp, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineCustomElement, defineEmits, defineExpose, defineProps, defineSSRCustomElement, devtools, effect, effectScope, getCurrentInstance, getCurrentScope, getTransitionRawChildren, guardReactiveProps, h, handleError, hydrate, initCustomFormatter, initDirectivesForSSR, inject, isMemoSame, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeDefaults, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, stop, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withKeys, withMemo, withModifiers, withScopeId };