vue.global.js 606 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839
  1. var Vue = (function (exports) {
  2. 'use strict';
  3. /**
  4. * Make a map and return a function for checking if a key
  5. * is in that map.
  6. * IMPORTANT: all calls of this function must be prefixed with
  7. * \/\*#\_\_PURE\_\_\*\/
  8. * So that rollup can tree-shake them if necessary.
  9. */
  10. function makeMap(str, expectsLowerCase) {
  11. const map = Object.create(null);
  12. const list = str.split(',');
  13. for (let i = 0; i < list.length; i++) {
  14. map[list[i]] = true;
  15. }
  16. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  17. }
  18. /**
  19. * dev only flag -> name mapping
  20. */
  21. const PatchFlagNames = {
  22. [1 /* TEXT */]: `TEXT`,
  23. [2 /* CLASS */]: `CLASS`,
  24. [4 /* STYLE */]: `STYLE`,
  25. [8 /* PROPS */]: `PROPS`,
  26. [16 /* FULL_PROPS */]: `FULL_PROPS`,
  27. [32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  28. [64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  29. [128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  30. [256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  31. [512 /* NEED_PATCH */]: `NEED_PATCH`,
  32. [1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  33. [2048 /* DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  34. [-1 /* HOISTED */]: `HOISTED`,
  35. [-2 /* BAIL */]: `BAIL`
  36. };
  37. /**
  38. * Dev only
  39. */
  40. const slotFlagsText = {
  41. [1 /* STABLE */]: 'STABLE',
  42. [2 /* DYNAMIC */]: 'DYNAMIC',
  43. [3 /* FORWARDED */]: 'FORWARDED'
  44. };
  45. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  46. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  47. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  48. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  49. const range = 2;
  50. function generateCodeFrame(source, start = 0, end = source.length) {
  51. // Split the content into individual lines but capture the newline sequence
  52. // that separated each line. This is important because the actual sequence is
  53. // needed to properly take into account the full line length for offset
  54. // comparison
  55. let lines = source.split(/(\r?\n)/);
  56. // Separate the lines and newline sequences into separate arrays for easier referencing
  57. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  58. lines = lines.filter((_, idx) => idx % 2 === 0);
  59. let count = 0;
  60. const res = [];
  61. for (let i = 0; i < lines.length; i++) {
  62. count +=
  63. lines[i].length +
  64. ((newlineSequences[i] && newlineSequences[i].length) || 0);
  65. if (count >= start) {
  66. for (let j = i - range; j <= i + range || end > count; j++) {
  67. if (j < 0 || j >= lines.length)
  68. continue;
  69. const line = j + 1;
  70. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  71. const lineLength = lines[j].length;
  72. const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
  73. if (j === i) {
  74. // push underline
  75. const pad = start - (count - (lineLength + newLineSeqLength));
  76. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  77. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  78. }
  79. else if (j > i) {
  80. if (end > count) {
  81. const length = Math.max(Math.min(end - count, lineLength), 1);
  82. res.push(` | ` + '^'.repeat(length));
  83. }
  84. count += lineLength + newLineSeqLength;
  85. }
  86. }
  87. break;
  88. }
  89. }
  90. return res.join('\n');
  91. }
  92. /**
  93. * On the client we only need to offer special cases for boolean attributes that
  94. * have different names from their corresponding dom properties:
  95. * - itemscope -> N/A
  96. * - allowfullscreen -> allowFullscreen
  97. * - formnovalidate -> formNoValidate
  98. * - ismap -> isMap
  99. * - nomodule -> noModule
  100. * - novalidate -> noValidate
  101. * - readonly -> readOnly
  102. */
  103. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  104. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  105. /**
  106. * Boolean attributes should be included if the value is truthy or ''.
  107. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  108. */
  109. function includeBooleanAttr(value) {
  110. return !!value || value === '';
  111. }
  112. function normalizeStyle(value) {
  113. if (isArray(value)) {
  114. const res = {};
  115. for (let i = 0; i < value.length; i++) {
  116. const item = value[i];
  117. const normalized = isString(item)
  118. ? parseStringStyle(item)
  119. : normalizeStyle(item);
  120. if (normalized) {
  121. for (const key in normalized) {
  122. res[key] = normalized[key];
  123. }
  124. }
  125. }
  126. return res;
  127. }
  128. else if (isString(value)) {
  129. return value;
  130. }
  131. else if (isObject(value)) {
  132. return value;
  133. }
  134. }
  135. const listDelimiterRE = /;(?![^(]*\))/g;
  136. const propertyDelimiterRE = /:(.+)/;
  137. function parseStringStyle(cssText) {
  138. const ret = {};
  139. cssText.split(listDelimiterRE).forEach(item => {
  140. if (item) {
  141. const tmp = item.split(propertyDelimiterRE);
  142. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  143. }
  144. });
  145. return ret;
  146. }
  147. function normalizeClass(value) {
  148. let res = '';
  149. if (isString(value)) {
  150. res = value;
  151. }
  152. else if (isArray(value)) {
  153. for (let i = 0; i < value.length; i++) {
  154. const normalized = normalizeClass(value[i]);
  155. if (normalized) {
  156. res += normalized + ' ';
  157. }
  158. }
  159. }
  160. else if (isObject(value)) {
  161. for (const name in value) {
  162. if (value[name]) {
  163. res += name + ' ';
  164. }
  165. }
  166. }
  167. return res.trim();
  168. }
  169. function normalizeProps(props) {
  170. if (!props)
  171. return null;
  172. let { class: klass, style } = props;
  173. if (klass && !isString(klass)) {
  174. props.class = normalizeClass(klass);
  175. }
  176. if (style) {
  177. props.style = normalizeStyle(style);
  178. }
  179. return props;
  180. }
  181. // These tag configs are shared between compiler-dom and runtime-dom, so they
  182. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  183. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  184. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  185. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  186. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  187. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  188. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  189. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  190. 'option,output,progress,select,textarea,details,dialog,menu,' +
  191. 'summary,template,blockquote,iframe,tfoot';
  192. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  193. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  194. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  195. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  196. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  197. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  198. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  199. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  200. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  201. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  202. 'text,textPath,title,tspan,unknown,use,view';
  203. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  204. /**
  205. * Compiler only.
  206. * Do NOT use in runtime code paths unless behind `true` flag.
  207. */
  208. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  209. /**
  210. * Compiler only.
  211. * Do NOT use in runtime code paths unless behind `true` flag.
  212. */
  213. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  214. /**
  215. * Compiler only.
  216. * Do NOT use in runtime code paths unless behind `true` flag.
  217. */
  218. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  219. function looseCompareArrays(a, b) {
  220. if (a.length !== b.length)
  221. return false;
  222. let equal = true;
  223. for (let i = 0; equal && i < a.length; i++) {
  224. equal = looseEqual(a[i], b[i]);
  225. }
  226. return equal;
  227. }
  228. function looseEqual(a, b) {
  229. if (a === b)
  230. return true;
  231. let aValidType = isDate(a);
  232. let bValidType = isDate(b);
  233. if (aValidType || bValidType) {
  234. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  235. }
  236. aValidType = isArray(a);
  237. bValidType = isArray(b);
  238. if (aValidType || bValidType) {
  239. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  240. }
  241. aValidType = isObject(a);
  242. bValidType = isObject(b);
  243. if (aValidType || bValidType) {
  244. /* istanbul ignore if: this if will probably never be called */
  245. if (!aValidType || !bValidType) {
  246. return false;
  247. }
  248. const aKeysCount = Object.keys(a).length;
  249. const bKeysCount = Object.keys(b).length;
  250. if (aKeysCount !== bKeysCount) {
  251. return false;
  252. }
  253. for (const key in a) {
  254. const aHasKey = a.hasOwnProperty(key);
  255. const bHasKey = b.hasOwnProperty(key);
  256. if ((aHasKey && !bHasKey) ||
  257. (!aHasKey && bHasKey) ||
  258. !looseEqual(a[key], b[key])) {
  259. return false;
  260. }
  261. }
  262. }
  263. return String(a) === String(b);
  264. }
  265. function looseIndexOf(arr, val) {
  266. return arr.findIndex(item => looseEqual(item, val));
  267. }
  268. /**
  269. * For converting {{ interpolation }} values to displayed strings.
  270. * @private
  271. */
  272. const toDisplayString = (val) => {
  273. return isString(val)
  274. ? val
  275. : val == null
  276. ? ''
  277. : isArray(val) ||
  278. (isObject(val) &&
  279. (val.toString === objectToString || !isFunction(val.toString)))
  280. ? JSON.stringify(val, replacer, 2)
  281. : String(val);
  282. };
  283. const replacer = (_key, val) => {
  284. // can't use isRef here since @vue/shared has no deps
  285. if (val && val.__v_isRef) {
  286. return replacer(_key, val.value);
  287. }
  288. else if (isMap(val)) {
  289. return {
  290. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  291. entries[`${key} =>`] = val;
  292. return entries;
  293. }, {})
  294. };
  295. }
  296. else if (isSet(val)) {
  297. return {
  298. [`Set(${val.size})`]: [...val.values()]
  299. };
  300. }
  301. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  302. return String(val);
  303. }
  304. return val;
  305. };
  306. const EMPTY_OBJ = Object.freeze({})
  307. ;
  308. const EMPTY_ARR = Object.freeze([]) ;
  309. const NOOP = () => { };
  310. /**
  311. * Always return false.
  312. */
  313. const NO = () => false;
  314. const onRE = /^on[^a-z]/;
  315. const isOn = (key) => onRE.test(key);
  316. const isModelListener = (key) => key.startsWith('onUpdate:');
  317. const extend = Object.assign;
  318. const remove = (arr, el) => {
  319. const i = arr.indexOf(el);
  320. if (i > -1) {
  321. arr.splice(i, 1);
  322. }
  323. };
  324. const hasOwnProperty = Object.prototype.hasOwnProperty;
  325. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  326. const isArray = Array.isArray;
  327. const isMap = (val) => toTypeString(val) === '[object Map]';
  328. const isSet = (val) => toTypeString(val) === '[object Set]';
  329. const isDate = (val) => val instanceof Date;
  330. const isFunction = (val) => typeof val === 'function';
  331. const isString = (val) => typeof val === 'string';
  332. const isSymbol = (val) => typeof val === 'symbol';
  333. const isObject = (val) => val !== null && typeof val === 'object';
  334. const isPromise = (val) => {
  335. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  336. };
  337. const objectToString = Object.prototype.toString;
  338. const toTypeString = (value) => objectToString.call(value);
  339. const toRawType = (value) => {
  340. // extract "RawType" from strings like "[object RawType]"
  341. return toTypeString(value).slice(8, -1);
  342. };
  343. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  344. const isIntegerKey = (key) => isString(key) &&
  345. key !== 'NaN' &&
  346. key[0] !== '-' &&
  347. '' + parseInt(key, 10) === key;
  348. const isReservedProp = /*#__PURE__*/ makeMap(
  349. // the leading comma is intentional so empty string "" is also included
  350. ',key,ref,ref_for,ref_key,' +
  351. 'onVnodeBeforeMount,onVnodeMounted,' +
  352. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  353. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  354. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  355. const cacheStringFunction = (fn) => {
  356. const cache = Object.create(null);
  357. return ((str) => {
  358. const hit = cache[str];
  359. return hit || (cache[str] = fn(str));
  360. });
  361. };
  362. const camelizeRE = /-(\w)/g;
  363. /**
  364. * @private
  365. */
  366. const camelize = cacheStringFunction((str) => {
  367. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  368. });
  369. const hyphenateRE = /\B([A-Z])/g;
  370. /**
  371. * @private
  372. */
  373. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  374. /**
  375. * @private
  376. */
  377. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  378. /**
  379. * @private
  380. */
  381. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  382. // compare whether a value has changed, accounting for NaN.
  383. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  384. const invokeArrayFns = (fns, arg) => {
  385. for (let i = 0; i < fns.length; i++) {
  386. fns[i](arg);
  387. }
  388. };
  389. const def = (obj, key, value) => {
  390. Object.defineProperty(obj, key, {
  391. configurable: true,
  392. enumerable: false,
  393. value
  394. });
  395. };
  396. const toNumber = (val) => {
  397. const n = parseFloat(val);
  398. return isNaN(n) ? val : n;
  399. };
  400. let _globalThis;
  401. const getGlobalThis = () => {
  402. return (_globalThis ||
  403. (_globalThis =
  404. typeof globalThis !== 'undefined'
  405. ? globalThis
  406. : typeof self !== 'undefined'
  407. ? self
  408. : typeof window !== 'undefined'
  409. ? window
  410. : typeof global !== 'undefined'
  411. ? global
  412. : {}));
  413. };
  414. function warn(msg, ...args) {
  415. console.warn(`[Vue warn] ${msg}`, ...args);
  416. }
  417. let activeEffectScope;
  418. class EffectScope {
  419. constructor(detached = false) {
  420. /**
  421. * @internal
  422. */
  423. this.active = true;
  424. /**
  425. * @internal
  426. */
  427. this.effects = [];
  428. /**
  429. * @internal
  430. */
  431. this.cleanups = [];
  432. if (!detached && activeEffectScope) {
  433. this.parent = activeEffectScope;
  434. this.index =
  435. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  436. }
  437. }
  438. run(fn) {
  439. if (this.active) {
  440. const currentEffectScope = activeEffectScope;
  441. try {
  442. activeEffectScope = this;
  443. return fn();
  444. }
  445. finally {
  446. activeEffectScope = currentEffectScope;
  447. }
  448. }
  449. else {
  450. warn(`cannot run an inactive effect scope.`);
  451. }
  452. }
  453. /**
  454. * This should only be called on non-detached scopes
  455. * @internal
  456. */
  457. on() {
  458. activeEffectScope = this;
  459. }
  460. /**
  461. * This should only be called on non-detached scopes
  462. * @internal
  463. */
  464. off() {
  465. activeEffectScope = this.parent;
  466. }
  467. stop(fromParent) {
  468. if (this.active) {
  469. let i, l;
  470. for (i = 0, l = this.effects.length; i < l; i++) {
  471. this.effects[i].stop();
  472. }
  473. for (i = 0, l = this.cleanups.length; i < l; i++) {
  474. this.cleanups[i]();
  475. }
  476. if (this.scopes) {
  477. for (i = 0, l = this.scopes.length; i < l; i++) {
  478. this.scopes[i].stop(true);
  479. }
  480. }
  481. // nested scope, dereference from parent to avoid memory leaks
  482. if (this.parent && !fromParent) {
  483. // optimized O(1) removal
  484. const last = this.parent.scopes.pop();
  485. if (last && last !== this) {
  486. this.parent.scopes[this.index] = last;
  487. last.index = this.index;
  488. }
  489. }
  490. this.active = false;
  491. }
  492. }
  493. }
  494. function effectScope(detached) {
  495. return new EffectScope(detached);
  496. }
  497. function recordEffectScope(effect, scope = activeEffectScope) {
  498. if (scope && scope.active) {
  499. scope.effects.push(effect);
  500. }
  501. }
  502. function getCurrentScope() {
  503. return activeEffectScope;
  504. }
  505. function onScopeDispose(fn) {
  506. if (activeEffectScope) {
  507. activeEffectScope.cleanups.push(fn);
  508. }
  509. else {
  510. warn(`onScopeDispose() is called when there is no active effect scope` +
  511. ` to be associated with.`);
  512. }
  513. }
  514. const createDep = (effects) => {
  515. const dep = new Set(effects);
  516. dep.w = 0;
  517. dep.n = 0;
  518. return dep;
  519. };
  520. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  521. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  522. const initDepMarkers = ({ deps }) => {
  523. if (deps.length) {
  524. for (let i = 0; i < deps.length; i++) {
  525. deps[i].w |= trackOpBit; // set was tracked
  526. }
  527. }
  528. };
  529. const finalizeDepMarkers = (effect) => {
  530. const { deps } = effect;
  531. if (deps.length) {
  532. let ptr = 0;
  533. for (let i = 0; i < deps.length; i++) {
  534. const dep = deps[i];
  535. if (wasTracked(dep) && !newTracked(dep)) {
  536. dep.delete(effect);
  537. }
  538. else {
  539. deps[ptr++] = dep;
  540. }
  541. // clear bits
  542. dep.w &= ~trackOpBit;
  543. dep.n &= ~trackOpBit;
  544. }
  545. deps.length = ptr;
  546. }
  547. };
  548. const targetMap = new WeakMap();
  549. // The number of effects currently being tracked recursively.
  550. let effectTrackDepth = 0;
  551. let trackOpBit = 1;
  552. /**
  553. * The bitwise track markers support at most 30 levels of recursion.
  554. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  555. * When recursion depth is greater, fall back to using a full cleanup.
  556. */
  557. const maxMarkerBits = 30;
  558. let activeEffect;
  559. const ITERATE_KEY = Symbol('iterate' );
  560. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  561. class ReactiveEffect {
  562. constructor(fn, scheduler = null, scope) {
  563. this.fn = fn;
  564. this.scheduler = scheduler;
  565. this.active = true;
  566. this.deps = [];
  567. this.parent = undefined;
  568. recordEffectScope(this, scope);
  569. }
  570. run() {
  571. if (!this.active) {
  572. return this.fn();
  573. }
  574. let parent = activeEffect;
  575. let lastShouldTrack = shouldTrack;
  576. while (parent) {
  577. if (parent === this) {
  578. return;
  579. }
  580. parent = parent.parent;
  581. }
  582. try {
  583. this.parent = activeEffect;
  584. activeEffect = this;
  585. shouldTrack = true;
  586. trackOpBit = 1 << ++effectTrackDepth;
  587. if (effectTrackDepth <= maxMarkerBits) {
  588. initDepMarkers(this);
  589. }
  590. else {
  591. cleanupEffect(this);
  592. }
  593. return this.fn();
  594. }
  595. finally {
  596. if (effectTrackDepth <= maxMarkerBits) {
  597. finalizeDepMarkers(this);
  598. }
  599. trackOpBit = 1 << --effectTrackDepth;
  600. activeEffect = this.parent;
  601. shouldTrack = lastShouldTrack;
  602. this.parent = undefined;
  603. if (this.deferStop) {
  604. this.stop();
  605. }
  606. }
  607. }
  608. stop() {
  609. // stopped while running itself - defer the cleanup
  610. if (activeEffect === this) {
  611. this.deferStop = true;
  612. }
  613. else if (this.active) {
  614. cleanupEffect(this);
  615. if (this.onStop) {
  616. this.onStop();
  617. }
  618. this.active = false;
  619. }
  620. }
  621. }
  622. function cleanupEffect(effect) {
  623. const { deps } = effect;
  624. if (deps.length) {
  625. for (let i = 0; i < deps.length; i++) {
  626. deps[i].delete(effect);
  627. }
  628. deps.length = 0;
  629. }
  630. }
  631. function effect(fn, options) {
  632. if (fn.effect) {
  633. fn = fn.effect.fn;
  634. }
  635. const _effect = new ReactiveEffect(fn);
  636. if (options) {
  637. extend(_effect, options);
  638. if (options.scope)
  639. recordEffectScope(_effect, options.scope);
  640. }
  641. if (!options || !options.lazy) {
  642. _effect.run();
  643. }
  644. const runner = _effect.run.bind(_effect);
  645. runner.effect = _effect;
  646. return runner;
  647. }
  648. function stop(runner) {
  649. runner.effect.stop();
  650. }
  651. let shouldTrack = true;
  652. const trackStack = [];
  653. function pauseTracking() {
  654. trackStack.push(shouldTrack);
  655. shouldTrack = false;
  656. }
  657. function resetTracking() {
  658. const last = trackStack.pop();
  659. shouldTrack = last === undefined ? true : last;
  660. }
  661. function track(target, type, key) {
  662. if (shouldTrack && activeEffect) {
  663. let depsMap = targetMap.get(target);
  664. if (!depsMap) {
  665. targetMap.set(target, (depsMap = new Map()));
  666. }
  667. let dep = depsMap.get(key);
  668. if (!dep) {
  669. depsMap.set(key, (dep = createDep()));
  670. }
  671. const eventInfo = { effect: activeEffect, target, type, key }
  672. ;
  673. trackEffects(dep, eventInfo);
  674. }
  675. }
  676. function trackEffects(dep, debuggerEventExtraInfo) {
  677. let shouldTrack = false;
  678. if (effectTrackDepth <= maxMarkerBits) {
  679. if (!newTracked(dep)) {
  680. dep.n |= trackOpBit; // set newly tracked
  681. shouldTrack = !wasTracked(dep);
  682. }
  683. }
  684. else {
  685. // Full cleanup mode.
  686. shouldTrack = !dep.has(activeEffect);
  687. }
  688. if (shouldTrack) {
  689. dep.add(activeEffect);
  690. activeEffect.deps.push(dep);
  691. if (activeEffect.onTrack) {
  692. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  693. }
  694. }
  695. }
  696. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  697. const depsMap = targetMap.get(target);
  698. if (!depsMap) {
  699. // never been tracked
  700. return;
  701. }
  702. let deps = [];
  703. if (type === "clear" /* CLEAR */) {
  704. // collection being cleared
  705. // trigger all effects for target
  706. deps = [...depsMap.values()];
  707. }
  708. else if (key === 'length' && isArray(target)) {
  709. depsMap.forEach((dep, key) => {
  710. if (key === 'length' || key >= newValue) {
  711. deps.push(dep);
  712. }
  713. });
  714. }
  715. else {
  716. // schedule runs for SET | ADD | DELETE
  717. if (key !== void 0) {
  718. deps.push(depsMap.get(key));
  719. }
  720. // also run for iteration key on ADD | DELETE | Map.SET
  721. switch (type) {
  722. case "add" /* ADD */:
  723. if (!isArray(target)) {
  724. deps.push(depsMap.get(ITERATE_KEY));
  725. if (isMap(target)) {
  726. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  727. }
  728. }
  729. else if (isIntegerKey(key)) {
  730. // new index added to array -> length changes
  731. deps.push(depsMap.get('length'));
  732. }
  733. break;
  734. case "delete" /* DELETE */:
  735. if (!isArray(target)) {
  736. deps.push(depsMap.get(ITERATE_KEY));
  737. if (isMap(target)) {
  738. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  739. }
  740. }
  741. break;
  742. case "set" /* SET */:
  743. if (isMap(target)) {
  744. deps.push(depsMap.get(ITERATE_KEY));
  745. }
  746. break;
  747. }
  748. }
  749. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  750. ;
  751. if (deps.length === 1) {
  752. if (deps[0]) {
  753. {
  754. triggerEffects(deps[0], eventInfo);
  755. }
  756. }
  757. }
  758. else {
  759. const effects = [];
  760. for (const dep of deps) {
  761. if (dep) {
  762. effects.push(...dep);
  763. }
  764. }
  765. {
  766. triggerEffects(createDep(effects), eventInfo);
  767. }
  768. }
  769. }
  770. function triggerEffects(dep, debuggerEventExtraInfo) {
  771. // spread into array for stabilization
  772. for (const effect of isArray(dep) ? dep : [...dep]) {
  773. if (effect !== activeEffect || effect.allowRecurse) {
  774. if (effect.onTrigger) {
  775. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  776. }
  777. if (effect.scheduler) {
  778. effect.scheduler();
  779. }
  780. else {
  781. effect.run();
  782. }
  783. }
  784. }
  785. }
  786. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  787. const builtInSymbols = new Set(
  788. /*#__PURE__*/
  789. Object.getOwnPropertyNames(Symbol)
  790. .map(key => Symbol[key])
  791. .filter(isSymbol));
  792. const get = /*#__PURE__*/ createGetter();
  793. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  794. const readonlyGet = /*#__PURE__*/ createGetter(true);
  795. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  796. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  797. function createArrayInstrumentations() {
  798. const instrumentations = {};
  799. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  800. instrumentations[key] = function (...args) {
  801. const arr = toRaw(this);
  802. for (let i = 0, l = this.length; i < l; i++) {
  803. track(arr, "get" /* GET */, i + '');
  804. }
  805. // we run the method using the original args first (which may be reactive)
  806. const res = arr[key](...args);
  807. if (res === -1 || res === false) {
  808. // if that didn't work, run it again using raw values.
  809. return arr[key](...args.map(toRaw));
  810. }
  811. else {
  812. return res;
  813. }
  814. };
  815. });
  816. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  817. instrumentations[key] = function (...args) {
  818. pauseTracking();
  819. const res = toRaw(this)[key].apply(this, args);
  820. resetTracking();
  821. return res;
  822. };
  823. });
  824. return instrumentations;
  825. }
  826. function createGetter(isReadonly = false, shallow = false) {
  827. return function get(target, key, receiver) {
  828. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  829. return !isReadonly;
  830. }
  831. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  832. return isReadonly;
  833. }
  834. else if (key === "__v_isShallow" /* IS_SHALLOW */) {
  835. return shallow;
  836. }
  837. else if (key === "__v_raw" /* RAW */ &&
  838. receiver ===
  839. (isReadonly
  840. ? shallow
  841. ? shallowReadonlyMap
  842. : readonlyMap
  843. : shallow
  844. ? shallowReactiveMap
  845. : reactiveMap).get(target)) {
  846. return target;
  847. }
  848. const targetIsArray = isArray(target);
  849. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  850. return Reflect.get(arrayInstrumentations, key, receiver);
  851. }
  852. const res = Reflect.get(target, key, receiver);
  853. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  854. return res;
  855. }
  856. if (!isReadonly) {
  857. track(target, "get" /* GET */, key);
  858. }
  859. if (shallow) {
  860. return res;
  861. }
  862. if (isRef(res)) {
  863. // ref unwrapping - does not apply for Array + integer key.
  864. const shouldUnwrap = !targetIsArray || !isIntegerKey(key);
  865. return shouldUnwrap ? res.value : res;
  866. }
  867. if (isObject(res)) {
  868. // Convert returned value into a proxy as well. we do the isObject check
  869. // here to avoid invalid value warning. Also need to lazy access readonly
  870. // and reactive here to avoid circular dependency.
  871. return isReadonly ? readonly(res) : reactive(res);
  872. }
  873. return res;
  874. };
  875. }
  876. const set = /*#__PURE__*/ createSetter();
  877. const shallowSet = /*#__PURE__*/ createSetter(true);
  878. function createSetter(shallow = false) {
  879. return function set(target, key, value, receiver) {
  880. let oldValue = target[key];
  881. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  882. return false;
  883. }
  884. if (!shallow && !isReadonly(value)) {
  885. if (!isShallow(value)) {
  886. value = toRaw(value);
  887. oldValue = toRaw(oldValue);
  888. }
  889. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  890. oldValue.value = value;
  891. return true;
  892. }
  893. }
  894. const hadKey = isArray(target) && isIntegerKey(key)
  895. ? Number(key) < target.length
  896. : hasOwn(target, key);
  897. const result = Reflect.set(target, key, value, receiver);
  898. // don't trigger if target is something up in the prototype chain of original
  899. if (target === toRaw(receiver)) {
  900. if (!hadKey) {
  901. trigger(target, "add" /* ADD */, key, value);
  902. }
  903. else if (hasChanged(value, oldValue)) {
  904. trigger(target, "set" /* SET */, key, value, oldValue);
  905. }
  906. }
  907. return result;
  908. };
  909. }
  910. function deleteProperty(target, key) {
  911. const hadKey = hasOwn(target, key);
  912. const oldValue = target[key];
  913. const result = Reflect.deleteProperty(target, key);
  914. if (result && hadKey) {
  915. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  916. }
  917. return result;
  918. }
  919. function has(target, key) {
  920. const result = Reflect.has(target, key);
  921. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  922. track(target, "has" /* HAS */, key);
  923. }
  924. return result;
  925. }
  926. function ownKeys(target) {
  927. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  928. return Reflect.ownKeys(target);
  929. }
  930. const mutableHandlers = {
  931. get,
  932. set,
  933. deleteProperty,
  934. has,
  935. ownKeys
  936. };
  937. const readonlyHandlers = {
  938. get: readonlyGet,
  939. set(target, key) {
  940. {
  941. warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  942. }
  943. return true;
  944. },
  945. deleteProperty(target, key) {
  946. {
  947. warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  948. }
  949. return true;
  950. }
  951. };
  952. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  953. get: shallowGet,
  954. set: shallowSet
  955. });
  956. // Props handlers are special in the sense that it should not unwrap top-level
  957. // refs (in order to allow refs to be explicitly passed down), but should
  958. // retain the reactivity of the normal readonly object.
  959. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  960. get: shallowReadonlyGet
  961. });
  962. const toShallow = (value) => value;
  963. const getProto = (v) => Reflect.getPrototypeOf(v);
  964. function get$1(target, key, isReadonly = false, isShallow = false) {
  965. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  966. // of the value
  967. target = target["__v_raw" /* RAW */];
  968. const rawTarget = toRaw(target);
  969. const rawKey = toRaw(key);
  970. if (key !== rawKey) {
  971. !isReadonly && track(rawTarget, "get" /* GET */, key);
  972. }
  973. !isReadonly && track(rawTarget, "get" /* GET */, rawKey);
  974. const { has } = getProto(rawTarget);
  975. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  976. if (has.call(rawTarget, key)) {
  977. return wrap(target.get(key));
  978. }
  979. else if (has.call(rawTarget, rawKey)) {
  980. return wrap(target.get(rawKey));
  981. }
  982. else if (target !== rawTarget) {
  983. // #3602 readonly(reactive(Map))
  984. // ensure that the nested reactive `Map` can do tracking for itself
  985. target.get(key);
  986. }
  987. }
  988. function has$1(key, isReadonly = false) {
  989. const target = this["__v_raw" /* RAW */];
  990. const rawTarget = toRaw(target);
  991. const rawKey = toRaw(key);
  992. if (key !== rawKey) {
  993. !isReadonly && track(rawTarget, "has" /* HAS */, key);
  994. }
  995. !isReadonly && track(rawTarget, "has" /* HAS */, rawKey);
  996. return key === rawKey
  997. ? target.has(key)
  998. : target.has(key) || target.has(rawKey);
  999. }
  1000. function size(target, isReadonly = false) {
  1001. target = target["__v_raw" /* RAW */];
  1002. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  1003. return Reflect.get(target, 'size', target);
  1004. }
  1005. function add(value) {
  1006. value = toRaw(value);
  1007. const target = toRaw(this);
  1008. const proto = getProto(target);
  1009. const hadKey = proto.has.call(target, value);
  1010. if (!hadKey) {
  1011. target.add(value);
  1012. trigger(target, "add" /* ADD */, value, value);
  1013. }
  1014. return this;
  1015. }
  1016. function set$1(key, value) {
  1017. value = toRaw(value);
  1018. const target = toRaw(this);
  1019. const { has, get } = getProto(target);
  1020. let hadKey = has.call(target, key);
  1021. if (!hadKey) {
  1022. key = toRaw(key);
  1023. hadKey = has.call(target, key);
  1024. }
  1025. else {
  1026. checkIdentityKeys(target, has, key);
  1027. }
  1028. const oldValue = get.call(target, key);
  1029. target.set(key, value);
  1030. if (!hadKey) {
  1031. trigger(target, "add" /* ADD */, key, value);
  1032. }
  1033. else if (hasChanged(value, oldValue)) {
  1034. trigger(target, "set" /* SET */, key, value, oldValue);
  1035. }
  1036. return this;
  1037. }
  1038. function deleteEntry(key) {
  1039. const target = toRaw(this);
  1040. const { has, get } = getProto(target);
  1041. let hadKey = has.call(target, key);
  1042. if (!hadKey) {
  1043. key = toRaw(key);
  1044. hadKey = has.call(target, key);
  1045. }
  1046. else {
  1047. checkIdentityKeys(target, has, key);
  1048. }
  1049. const oldValue = get ? get.call(target, key) : undefined;
  1050. // forward the operation before queueing reactions
  1051. const result = target.delete(key);
  1052. if (hadKey) {
  1053. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  1054. }
  1055. return result;
  1056. }
  1057. function clear() {
  1058. const target = toRaw(this);
  1059. const hadItems = target.size !== 0;
  1060. const oldTarget = isMap(target)
  1061. ? new Map(target)
  1062. : new Set(target)
  1063. ;
  1064. // forward the operation before queueing reactions
  1065. const result = target.clear();
  1066. if (hadItems) {
  1067. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  1068. }
  1069. return result;
  1070. }
  1071. function createForEach(isReadonly, isShallow) {
  1072. return function forEach(callback, thisArg) {
  1073. const observed = this;
  1074. const target = observed["__v_raw" /* RAW */];
  1075. const rawTarget = toRaw(target);
  1076. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1077. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  1078. return target.forEach((value, key) => {
  1079. // important: make sure the callback is
  1080. // 1. invoked with the reactive map as `this` and 3rd arg
  1081. // 2. the value received should be a corresponding reactive/readonly.
  1082. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1083. });
  1084. };
  1085. }
  1086. function createIterableMethod(method, isReadonly, isShallow) {
  1087. return function (...args) {
  1088. const target = this["__v_raw" /* RAW */];
  1089. const rawTarget = toRaw(target);
  1090. const targetIsMap = isMap(rawTarget);
  1091. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1092. const isKeyOnly = method === 'keys' && targetIsMap;
  1093. const innerIterator = target[method](...args);
  1094. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1095. !isReadonly &&
  1096. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1097. // return a wrapped iterator which returns observed versions of the
  1098. // values emitted from the real iterator
  1099. return {
  1100. // iterator protocol
  1101. next() {
  1102. const { value, done } = innerIterator.next();
  1103. return done
  1104. ? { value, done }
  1105. : {
  1106. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1107. done
  1108. };
  1109. },
  1110. // iterable protocol
  1111. [Symbol.iterator]() {
  1112. return this;
  1113. }
  1114. };
  1115. };
  1116. }
  1117. function createReadonlyMethod(type) {
  1118. return function (...args) {
  1119. {
  1120. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1121. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1122. }
  1123. return type === "delete" /* DELETE */ ? false : this;
  1124. };
  1125. }
  1126. function createInstrumentations() {
  1127. const mutableInstrumentations = {
  1128. get(key) {
  1129. return get$1(this, key);
  1130. },
  1131. get size() {
  1132. return size(this);
  1133. },
  1134. has: has$1,
  1135. add,
  1136. set: set$1,
  1137. delete: deleteEntry,
  1138. clear,
  1139. forEach: createForEach(false, false)
  1140. };
  1141. const shallowInstrumentations = {
  1142. get(key) {
  1143. return get$1(this, key, false, true);
  1144. },
  1145. get size() {
  1146. return size(this);
  1147. },
  1148. has: has$1,
  1149. add,
  1150. set: set$1,
  1151. delete: deleteEntry,
  1152. clear,
  1153. forEach: createForEach(false, true)
  1154. };
  1155. const readonlyInstrumentations = {
  1156. get(key) {
  1157. return get$1(this, key, true);
  1158. },
  1159. get size() {
  1160. return size(this, true);
  1161. },
  1162. has(key) {
  1163. return has$1.call(this, key, true);
  1164. },
  1165. add: createReadonlyMethod("add" /* ADD */),
  1166. set: createReadonlyMethod("set" /* SET */),
  1167. delete: createReadonlyMethod("delete" /* DELETE */),
  1168. clear: createReadonlyMethod("clear" /* CLEAR */),
  1169. forEach: createForEach(true, false)
  1170. };
  1171. const shallowReadonlyInstrumentations = {
  1172. get(key) {
  1173. return get$1(this, key, true, true);
  1174. },
  1175. get size() {
  1176. return size(this, true);
  1177. },
  1178. has(key) {
  1179. return has$1.call(this, key, true);
  1180. },
  1181. add: createReadonlyMethod("add" /* ADD */),
  1182. set: createReadonlyMethod("set" /* SET */),
  1183. delete: createReadonlyMethod("delete" /* DELETE */),
  1184. clear: createReadonlyMethod("clear" /* CLEAR */),
  1185. forEach: createForEach(true, true)
  1186. };
  1187. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1188. iteratorMethods.forEach(method => {
  1189. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1190. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1191. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1192. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1193. });
  1194. return [
  1195. mutableInstrumentations,
  1196. readonlyInstrumentations,
  1197. shallowInstrumentations,
  1198. shallowReadonlyInstrumentations
  1199. ];
  1200. }
  1201. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1202. function createInstrumentationGetter(isReadonly, shallow) {
  1203. const instrumentations = shallow
  1204. ? isReadonly
  1205. ? shallowReadonlyInstrumentations
  1206. : shallowInstrumentations
  1207. : isReadonly
  1208. ? readonlyInstrumentations
  1209. : mutableInstrumentations;
  1210. return (target, key, receiver) => {
  1211. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  1212. return !isReadonly;
  1213. }
  1214. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  1215. return isReadonly;
  1216. }
  1217. else if (key === "__v_raw" /* RAW */) {
  1218. return target;
  1219. }
  1220. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1221. ? instrumentations
  1222. : target, key, receiver);
  1223. };
  1224. }
  1225. const mutableCollectionHandlers = {
  1226. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1227. };
  1228. const shallowCollectionHandlers = {
  1229. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1230. };
  1231. const readonlyCollectionHandlers = {
  1232. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1233. };
  1234. const shallowReadonlyCollectionHandlers = {
  1235. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1236. };
  1237. function checkIdentityKeys(target, has, key) {
  1238. const rawKey = toRaw(key);
  1239. if (rawKey !== key && has.call(target, rawKey)) {
  1240. const type = toRawType(target);
  1241. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1242. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1243. `which can lead to inconsistencies. ` +
  1244. `Avoid differentiating between the raw and reactive versions ` +
  1245. `of an object and only use the reactive version if possible.`);
  1246. }
  1247. }
  1248. const reactiveMap = new WeakMap();
  1249. const shallowReactiveMap = new WeakMap();
  1250. const readonlyMap = new WeakMap();
  1251. const shallowReadonlyMap = new WeakMap();
  1252. function targetTypeMap(rawType) {
  1253. switch (rawType) {
  1254. case 'Object':
  1255. case 'Array':
  1256. return 1 /* COMMON */;
  1257. case 'Map':
  1258. case 'Set':
  1259. case 'WeakMap':
  1260. case 'WeakSet':
  1261. return 2 /* COLLECTION */;
  1262. default:
  1263. return 0 /* INVALID */;
  1264. }
  1265. }
  1266. function getTargetType(value) {
  1267. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  1268. ? 0 /* INVALID */
  1269. : targetTypeMap(toRawType(value));
  1270. }
  1271. function reactive(target) {
  1272. // if trying to observe a readonly proxy, return the readonly version.
  1273. if (isReadonly(target)) {
  1274. return target;
  1275. }
  1276. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1277. }
  1278. /**
  1279. * Return a shallowly-reactive copy of the original object, where only the root
  1280. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1281. * root level).
  1282. */
  1283. function shallowReactive(target) {
  1284. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1285. }
  1286. /**
  1287. * Creates a readonly copy of the original object. Note the returned copy is not
  1288. * made reactive, but `readonly` can be called on an already reactive object.
  1289. */
  1290. function readonly(target) {
  1291. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1292. }
  1293. /**
  1294. * Returns a reactive-copy of the original object, where only the root level
  1295. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1296. * returned properties.
  1297. * This is used for creating the props proxy object for stateful components.
  1298. */
  1299. function shallowReadonly(target) {
  1300. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1301. }
  1302. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1303. if (!isObject(target)) {
  1304. {
  1305. console.warn(`value cannot be made reactive: ${String(target)}`);
  1306. }
  1307. return target;
  1308. }
  1309. // target is already a Proxy, return it.
  1310. // exception: calling readonly() on a reactive object
  1311. if (target["__v_raw" /* RAW */] &&
  1312. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1313. return target;
  1314. }
  1315. // target already has corresponding Proxy
  1316. const existingProxy = proxyMap.get(target);
  1317. if (existingProxy) {
  1318. return existingProxy;
  1319. }
  1320. // only a whitelist of value types can be observed.
  1321. const targetType = getTargetType(target);
  1322. if (targetType === 0 /* INVALID */) {
  1323. return target;
  1324. }
  1325. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1326. proxyMap.set(target, proxy);
  1327. return proxy;
  1328. }
  1329. function isReactive(value) {
  1330. if (isReadonly(value)) {
  1331. return isReactive(value["__v_raw" /* RAW */]);
  1332. }
  1333. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1334. }
  1335. function isReadonly(value) {
  1336. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1337. }
  1338. function isShallow(value) {
  1339. return !!(value && value["__v_isShallow" /* IS_SHALLOW */]);
  1340. }
  1341. function isProxy(value) {
  1342. return isReactive(value) || isReadonly(value);
  1343. }
  1344. function toRaw(observed) {
  1345. const raw = observed && observed["__v_raw" /* RAW */];
  1346. return raw ? toRaw(raw) : observed;
  1347. }
  1348. function markRaw(value) {
  1349. def(value, "__v_skip" /* SKIP */, true);
  1350. return value;
  1351. }
  1352. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1353. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1354. function trackRefValue(ref) {
  1355. if (shouldTrack && activeEffect) {
  1356. ref = toRaw(ref);
  1357. {
  1358. trackEffects(ref.dep || (ref.dep = createDep()), {
  1359. target: ref,
  1360. type: "get" /* GET */,
  1361. key: 'value'
  1362. });
  1363. }
  1364. }
  1365. }
  1366. function triggerRefValue(ref, newVal) {
  1367. ref = toRaw(ref);
  1368. if (ref.dep) {
  1369. {
  1370. triggerEffects(ref.dep, {
  1371. target: ref,
  1372. type: "set" /* SET */,
  1373. key: 'value',
  1374. newValue: newVal
  1375. });
  1376. }
  1377. }
  1378. }
  1379. function isRef(r) {
  1380. return !!(r && r.__v_isRef === true);
  1381. }
  1382. function ref(value) {
  1383. return createRef(value, false);
  1384. }
  1385. function shallowRef(value) {
  1386. return createRef(value, true);
  1387. }
  1388. function createRef(rawValue, shallow) {
  1389. if (isRef(rawValue)) {
  1390. return rawValue;
  1391. }
  1392. return new RefImpl(rawValue, shallow);
  1393. }
  1394. class RefImpl {
  1395. constructor(value, __v_isShallow) {
  1396. this.__v_isShallow = __v_isShallow;
  1397. this.dep = undefined;
  1398. this.__v_isRef = true;
  1399. this._rawValue = __v_isShallow ? value : toRaw(value);
  1400. this._value = __v_isShallow ? value : toReactive(value);
  1401. }
  1402. get value() {
  1403. trackRefValue(this);
  1404. return this._value;
  1405. }
  1406. set value(newVal) {
  1407. newVal = this.__v_isShallow ? newVal : toRaw(newVal);
  1408. if (hasChanged(newVal, this._rawValue)) {
  1409. this._rawValue = newVal;
  1410. this._value = this.__v_isShallow ? newVal : toReactive(newVal);
  1411. triggerRefValue(this, newVal);
  1412. }
  1413. }
  1414. }
  1415. function triggerRef(ref) {
  1416. triggerRefValue(ref, ref.value );
  1417. }
  1418. function unref(ref) {
  1419. return isRef(ref) ? ref.value : ref;
  1420. }
  1421. const shallowUnwrapHandlers = {
  1422. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1423. set: (target, key, value, receiver) => {
  1424. const oldValue = target[key];
  1425. if (isRef(oldValue) && !isRef(value)) {
  1426. oldValue.value = value;
  1427. return true;
  1428. }
  1429. else {
  1430. return Reflect.set(target, key, value, receiver);
  1431. }
  1432. }
  1433. };
  1434. function proxyRefs(objectWithRefs) {
  1435. return isReactive(objectWithRefs)
  1436. ? objectWithRefs
  1437. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1438. }
  1439. class CustomRefImpl {
  1440. constructor(factory) {
  1441. this.dep = undefined;
  1442. this.__v_isRef = true;
  1443. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1444. this._get = get;
  1445. this._set = set;
  1446. }
  1447. get value() {
  1448. return this._get();
  1449. }
  1450. set value(newVal) {
  1451. this._set(newVal);
  1452. }
  1453. }
  1454. function customRef(factory) {
  1455. return new CustomRefImpl(factory);
  1456. }
  1457. function toRefs(object) {
  1458. if (!isProxy(object)) {
  1459. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1460. }
  1461. const ret = isArray(object) ? new Array(object.length) : {};
  1462. for (const key in object) {
  1463. ret[key] = toRef(object, key);
  1464. }
  1465. return ret;
  1466. }
  1467. class ObjectRefImpl {
  1468. constructor(_object, _key, _defaultValue) {
  1469. this._object = _object;
  1470. this._key = _key;
  1471. this._defaultValue = _defaultValue;
  1472. this.__v_isRef = true;
  1473. }
  1474. get value() {
  1475. const val = this._object[this._key];
  1476. return val === undefined ? this._defaultValue : val;
  1477. }
  1478. set value(newVal) {
  1479. this._object[this._key] = newVal;
  1480. }
  1481. }
  1482. function toRef(object, key, defaultValue) {
  1483. const val = object[key];
  1484. return isRef(val)
  1485. ? val
  1486. : new ObjectRefImpl(object, key, defaultValue);
  1487. }
  1488. class ComputedRefImpl {
  1489. constructor(getter, _setter, isReadonly, isSSR) {
  1490. this._setter = _setter;
  1491. this.dep = undefined;
  1492. this.__v_isRef = true;
  1493. this._dirty = true;
  1494. this.effect = new ReactiveEffect(getter, () => {
  1495. if (!this._dirty) {
  1496. this._dirty = true;
  1497. triggerRefValue(this);
  1498. }
  1499. });
  1500. this.effect.computed = this;
  1501. this.effect.active = this._cacheable = !isSSR;
  1502. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1503. }
  1504. get value() {
  1505. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1506. const self = toRaw(this);
  1507. trackRefValue(self);
  1508. if (self._dirty || !self._cacheable) {
  1509. self._dirty = false;
  1510. self._value = self.effect.run();
  1511. }
  1512. return self._value;
  1513. }
  1514. set value(newValue) {
  1515. this._setter(newValue);
  1516. }
  1517. }
  1518. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1519. let getter;
  1520. let setter;
  1521. const onlyGetter = isFunction(getterOrOptions);
  1522. if (onlyGetter) {
  1523. getter = getterOrOptions;
  1524. setter = () => {
  1525. console.warn('Write operation failed: computed value is readonly');
  1526. }
  1527. ;
  1528. }
  1529. else {
  1530. getter = getterOrOptions.get;
  1531. setter = getterOrOptions.set;
  1532. }
  1533. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1534. if (debugOptions && !isSSR) {
  1535. cRef.effect.onTrack = debugOptions.onTrack;
  1536. cRef.effect.onTrigger = debugOptions.onTrigger;
  1537. }
  1538. return cRef;
  1539. }
  1540. const stack = [];
  1541. function pushWarningContext(vnode) {
  1542. stack.push(vnode);
  1543. }
  1544. function popWarningContext() {
  1545. stack.pop();
  1546. }
  1547. function warn$1(msg, ...args) {
  1548. // avoid props formatting or warn handler tracking deps that might be mutated
  1549. // during patch, leading to infinite recursion.
  1550. pauseTracking();
  1551. const instance = stack.length ? stack[stack.length - 1].component : null;
  1552. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1553. const trace = getComponentTrace();
  1554. if (appWarnHandler) {
  1555. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1556. msg + args.join(''),
  1557. instance && instance.proxy,
  1558. trace
  1559. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1560. .join('\n'),
  1561. trace
  1562. ]);
  1563. }
  1564. else {
  1565. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1566. /* istanbul ignore if */
  1567. if (trace.length &&
  1568. // avoid spamming console during tests
  1569. !false) {
  1570. warnArgs.push(`\n`, ...formatTrace(trace));
  1571. }
  1572. console.warn(...warnArgs);
  1573. }
  1574. resetTracking();
  1575. }
  1576. function getComponentTrace() {
  1577. let currentVNode = stack[stack.length - 1];
  1578. if (!currentVNode) {
  1579. return [];
  1580. }
  1581. // we can't just use the stack because it will be incomplete during updates
  1582. // that did not start from the root. Re-construct the parent chain using
  1583. // instance parent pointers.
  1584. const normalizedStack = [];
  1585. while (currentVNode) {
  1586. const last = normalizedStack[0];
  1587. if (last && last.vnode === currentVNode) {
  1588. last.recurseCount++;
  1589. }
  1590. else {
  1591. normalizedStack.push({
  1592. vnode: currentVNode,
  1593. recurseCount: 0
  1594. });
  1595. }
  1596. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1597. currentVNode = parentInstance && parentInstance.vnode;
  1598. }
  1599. return normalizedStack;
  1600. }
  1601. /* istanbul ignore next */
  1602. function formatTrace(trace) {
  1603. const logs = [];
  1604. trace.forEach((entry, i) => {
  1605. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1606. });
  1607. return logs;
  1608. }
  1609. function formatTraceEntry({ vnode, recurseCount }) {
  1610. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1611. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1612. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1613. const close = `>` + postfix;
  1614. return vnode.props
  1615. ? [open, ...formatProps(vnode.props), close]
  1616. : [open + close];
  1617. }
  1618. /* istanbul ignore next */
  1619. function formatProps(props) {
  1620. const res = [];
  1621. const keys = Object.keys(props);
  1622. keys.slice(0, 3).forEach(key => {
  1623. res.push(...formatProp(key, props[key]));
  1624. });
  1625. if (keys.length > 3) {
  1626. res.push(` ...`);
  1627. }
  1628. return res;
  1629. }
  1630. /* istanbul ignore next */
  1631. function formatProp(key, value, raw) {
  1632. if (isString(value)) {
  1633. value = JSON.stringify(value);
  1634. return raw ? value : [`${key}=${value}`];
  1635. }
  1636. else if (typeof value === 'number' ||
  1637. typeof value === 'boolean' ||
  1638. value == null) {
  1639. return raw ? value : [`${key}=${value}`];
  1640. }
  1641. else if (isRef(value)) {
  1642. value = formatProp(key, toRaw(value.value), true);
  1643. return raw ? value : [`${key}=Ref<`, value, `>`];
  1644. }
  1645. else if (isFunction(value)) {
  1646. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1647. }
  1648. else {
  1649. value = toRaw(value);
  1650. return raw ? value : [`${key}=`, value];
  1651. }
  1652. }
  1653. const ErrorTypeStrings = {
  1654. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  1655. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1656. ["c" /* CREATED */]: 'created hook',
  1657. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1658. ["m" /* MOUNTED */]: 'mounted hook',
  1659. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1660. ["u" /* UPDATED */]: 'updated',
  1661. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1662. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1663. ["a" /* ACTIVATED */]: 'activated hook',
  1664. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1665. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1666. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1667. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1668. [0 /* SETUP_FUNCTION */]: 'setup function',
  1669. [1 /* RENDER_FUNCTION */]: 'render function',
  1670. [2 /* WATCH_GETTER */]: 'watcher getter',
  1671. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1672. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1673. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1674. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1675. [7 /* VNODE_HOOK */]: 'vnode hook',
  1676. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1677. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1678. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1679. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1680. [12 /* FUNCTION_REF */]: 'ref function',
  1681. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1682. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1683. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1684. };
  1685. function callWithErrorHandling(fn, instance, type, args) {
  1686. let res;
  1687. try {
  1688. res = args ? fn(...args) : fn();
  1689. }
  1690. catch (err) {
  1691. handleError(err, instance, type);
  1692. }
  1693. return res;
  1694. }
  1695. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1696. if (isFunction(fn)) {
  1697. const res = callWithErrorHandling(fn, instance, type, args);
  1698. if (res && isPromise(res)) {
  1699. res.catch(err => {
  1700. handleError(err, instance, type);
  1701. });
  1702. }
  1703. return res;
  1704. }
  1705. const values = [];
  1706. for (let i = 0; i < fn.length; i++) {
  1707. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1708. }
  1709. return values;
  1710. }
  1711. function handleError(err, instance, type, throwInDev = true) {
  1712. const contextVNode = instance ? instance.vnode : null;
  1713. if (instance) {
  1714. let cur = instance.parent;
  1715. // the exposed instance is the render proxy to keep it consistent with 2.x
  1716. const exposedInstance = instance.proxy;
  1717. // in production the hook receives only the error code
  1718. const errorInfo = ErrorTypeStrings[type] ;
  1719. while (cur) {
  1720. const errorCapturedHooks = cur.ec;
  1721. if (errorCapturedHooks) {
  1722. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1723. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1724. return;
  1725. }
  1726. }
  1727. }
  1728. cur = cur.parent;
  1729. }
  1730. // app-level handling
  1731. const appErrorHandler = instance.appContext.config.errorHandler;
  1732. if (appErrorHandler) {
  1733. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1734. return;
  1735. }
  1736. }
  1737. logError(err, type, contextVNode, throwInDev);
  1738. }
  1739. function logError(err, type, contextVNode, throwInDev = true) {
  1740. {
  1741. const info = ErrorTypeStrings[type];
  1742. if (contextVNode) {
  1743. pushWarningContext(contextVNode);
  1744. }
  1745. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1746. if (contextVNode) {
  1747. popWarningContext();
  1748. }
  1749. // crash in dev by default so it's more noticeable
  1750. if (throwInDev) {
  1751. throw err;
  1752. }
  1753. else {
  1754. console.error(err);
  1755. }
  1756. }
  1757. }
  1758. let isFlushing = false;
  1759. let isFlushPending = false;
  1760. const queue = [];
  1761. let flushIndex = 0;
  1762. const pendingPreFlushCbs = [];
  1763. let activePreFlushCbs = null;
  1764. let preFlushIndex = 0;
  1765. const pendingPostFlushCbs = [];
  1766. let activePostFlushCbs = null;
  1767. let postFlushIndex = 0;
  1768. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1769. let currentFlushPromise = null;
  1770. let currentPreFlushParentJob = null;
  1771. const RECURSION_LIMIT = 100;
  1772. function nextTick(fn) {
  1773. const p = currentFlushPromise || resolvedPromise;
  1774. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1775. }
  1776. // #2768
  1777. // Use binary-search to find a suitable position in the queue,
  1778. // so that the queue maintains the increasing order of job's id,
  1779. // which can prevent the job from being skipped and also can avoid repeated patching.
  1780. function findInsertionIndex(id) {
  1781. // the start index should be `flushIndex + 1`
  1782. let start = flushIndex + 1;
  1783. let end = queue.length;
  1784. while (start < end) {
  1785. const middle = (start + end) >>> 1;
  1786. const middleJobId = getId(queue[middle]);
  1787. middleJobId < id ? (start = middle + 1) : (end = middle);
  1788. }
  1789. return start;
  1790. }
  1791. function queueJob(job) {
  1792. // the dedupe search uses the startIndex argument of Array.includes()
  1793. // by default the search index includes the current job that is being run
  1794. // so it cannot recursively trigger itself again.
  1795. // if the job is a watch() callback, the search will start with a +1 index to
  1796. // allow it recursively trigger itself - it is the user's responsibility to
  1797. // ensure it doesn't end up in an infinite loop.
  1798. if ((!queue.length ||
  1799. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1800. job !== currentPreFlushParentJob) {
  1801. if (job.id == null) {
  1802. queue.push(job);
  1803. }
  1804. else {
  1805. queue.splice(findInsertionIndex(job.id), 0, job);
  1806. }
  1807. queueFlush();
  1808. }
  1809. }
  1810. function queueFlush() {
  1811. if (!isFlushing && !isFlushPending) {
  1812. isFlushPending = true;
  1813. currentFlushPromise = resolvedPromise.then(flushJobs);
  1814. }
  1815. }
  1816. function invalidateJob(job) {
  1817. const i = queue.indexOf(job);
  1818. if (i > flushIndex) {
  1819. queue.splice(i, 1);
  1820. }
  1821. }
  1822. function queueCb(cb, activeQueue, pendingQueue, index) {
  1823. if (!isArray(cb)) {
  1824. if (!activeQueue ||
  1825. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1826. pendingQueue.push(cb);
  1827. }
  1828. }
  1829. else {
  1830. // if cb is an array, it is a component lifecycle hook which can only be
  1831. // triggered by a job, which is already deduped in the main queue, so
  1832. // we can skip duplicate check here to improve perf
  1833. pendingQueue.push(...cb);
  1834. }
  1835. queueFlush();
  1836. }
  1837. function queuePreFlushCb(cb) {
  1838. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1839. }
  1840. function queuePostFlushCb(cb) {
  1841. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1842. }
  1843. function flushPreFlushCbs(seen, parentJob = null) {
  1844. if (pendingPreFlushCbs.length) {
  1845. currentPreFlushParentJob = parentJob;
  1846. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1847. pendingPreFlushCbs.length = 0;
  1848. {
  1849. seen = seen || new Map();
  1850. }
  1851. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1852. if (checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  1853. continue;
  1854. }
  1855. activePreFlushCbs[preFlushIndex]();
  1856. }
  1857. activePreFlushCbs = null;
  1858. preFlushIndex = 0;
  1859. currentPreFlushParentJob = null;
  1860. // recursively flush until it drains
  1861. flushPreFlushCbs(seen, parentJob);
  1862. }
  1863. }
  1864. function flushPostFlushCbs(seen) {
  1865. if (pendingPostFlushCbs.length) {
  1866. const deduped = [...new Set(pendingPostFlushCbs)];
  1867. pendingPostFlushCbs.length = 0;
  1868. // #1947 already has active queue, nested flushPostFlushCbs call
  1869. if (activePostFlushCbs) {
  1870. activePostFlushCbs.push(...deduped);
  1871. return;
  1872. }
  1873. activePostFlushCbs = deduped;
  1874. {
  1875. seen = seen || new Map();
  1876. }
  1877. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1878. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1879. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1880. continue;
  1881. }
  1882. activePostFlushCbs[postFlushIndex]();
  1883. }
  1884. activePostFlushCbs = null;
  1885. postFlushIndex = 0;
  1886. }
  1887. }
  1888. const getId = (job) => job.id == null ? Infinity : job.id;
  1889. function flushJobs(seen) {
  1890. isFlushPending = false;
  1891. isFlushing = true;
  1892. {
  1893. seen = seen || new Map();
  1894. }
  1895. flushPreFlushCbs(seen);
  1896. // Sort queue before flush.
  1897. // This ensures that:
  1898. // 1. Components are updated from parent to child. (because parent is always
  1899. // created before the child so its render effect will have smaller
  1900. // priority number)
  1901. // 2. If a component is unmounted during a parent component's update,
  1902. // its update can be skipped.
  1903. queue.sort((a, b) => getId(a) - getId(b));
  1904. // conditional usage of checkRecursiveUpdate must be determined out of
  1905. // try ... catch block since Rollup by default de-optimizes treeshaking
  1906. // inside try-catch. This can leave all warning code unshaked. Although
  1907. // they would get eventually shaken by a minifier like terser, some minifiers
  1908. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1909. const check = (job) => checkRecursiveUpdates(seen, job)
  1910. ;
  1911. try {
  1912. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1913. const job = queue[flushIndex];
  1914. if (job && job.active !== false) {
  1915. if (true && check(job)) {
  1916. continue;
  1917. }
  1918. // console.log(`running:`, job.id)
  1919. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1920. }
  1921. }
  1922. }
  1923. finally {
  1924. flushIndex = 0;
  1925. queue.length = 0;
  1926. flushPostFlushCbs(seen);
  1927. isFlushing = false;
  1928. currentFlushPromise = null;
  1929. // some postFlushCb queued jobs!
  1930. // keep flushing until it drains.
  1931. if (queue.length ||
  1932. pendingPreFlushCbs.length ||
  1933. pendingPostFlushCbs.length) {
  1934. flushJobs(seen);
  1935. }
  1936. }
  1937. }
  1938. function checkRecursiveUpdates(seen, fn) {
  1939. if (!seen.has(fn)) {
  1940. seen.set(fn, 1);
  1941. }
  1942. else {
  1943. const count = seen.get(fn);
  1944. if (count > RECURSION_LIMIT) {
  1945. const instance = fn.ownerInstance;
  1946. const componentName = instance && getComponentName(instance.type);
  1947. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1948. `This means you have a reactive effect that is mutating its own ` +
  1949. `dependencies and thus recursively triggering itself. Possible sources ` +
  1950. `include component template, render function, updated hook or ` +
  1951. `watcher source function.`);
  1952. return true;
  1953. }
  1954. else {
  1955. seen.set(fn, count + 1);
  1956. }
  1957. }
  1958. }
  1959. /* eslint-disable no-restricted-globals */
  1960. let isHmrUpdating = false;
  1961. const hmrDirtyComponents = new Set();
  1962. // Expose the HMR runtime on the global object
  1963. // This makes it entirely tree-shakable without polluting the exports and makes
  1964. // it easier to be used in toolings like vue-loader
  1965. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1966. // to be set so that its instances can be registered / removed.
  1967. {
  1968. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1969. createRecord: tryWrap(createRecord),
  1970. rerender: tryWrap(rerender),
  1971. reload: tryWrap(reload)
  1972. };
  1973. }
  1974. const map = new Map();
  1975. function registerHMR(instance) {
  1976. const id = instance.type.__hmrId;
  1977. let record = map.get(id);
  1978. if (!record) {
  1979. createRecord(id, instance.type);
  1980. record = map.get(id);
  1981. }
  1982. record.instances.add(instance);
  1983. }
  1984. function unregisterHMR(instance) {
  1985. map.get(instance.type.__hmrId).instances.delete(instance);
  1986. }
  1987. function createRecord(id, initialDef) {
  1988. if (map.has(id)) {
  1989. return false;
  1990. }
  1991. map.set(id, {
  1992. initialDef: normalizeClassComponent(initialDef),
  1993. instances: new Set()
  1994. });
  1995. return true;
  1996. }
  1997. function normalizeClassComponent(component) {
  1998. return isClassComponent(component) ? component.__vccOpts : component;
  1999. }
  2000. function rerender(id, newRender) {
  2001. const record = map.get(id);
  2002. if (!record) {
  2003. return;
  2004. }
  2005. // update initial record (for not-yet-rendered component)
  2006. record.initialDef.render = newRender;
  2007. [...record.instances].forEach(instance => {
  2008. if (newRender) {
  2009. instance.render = newRender;
  2010. normalizeClassComponent(instance.type).render = newRender;
  2011. }
  2012. instance.renderCache = [];
  2013. // this flag forces child components with slot content to update
  2014. isHmrUpdating = true;
  2015. instance.update();
  2016. isHmrUpdating = false;
  2017. });
  2018. }
  2019. function reload(id, newComp) {
  2020. const record = map.get(id);
  2021. if (!record)
  2022. return;
  2023. newComp = normalizeClassComponent(newComp);
  2024. // update initial def (for not-yet-rendered components)
  2025. updateComponentDef(record.initialDef, newComp);
  2026. // create a snapshot which avoids the set being mutated during updates
  2027. const instances = [...record.instances];
  2028. for (const instance of instances) {
  2029. const oldComp = normalizeClassComponent(instance.type);
  2030. if (!hmrDirtyComponents.has(oldComp)) {
  2031. // 1. Update existing comp definition to match new one
  2032. if (oldComp !== record.initialDef) {
  2033. updateComponentDef(oldComp, newComp);
  2034. }
  2035. // 2. mark definition dirty. This forces the renderer to replace the
  2036. // component on patch.
  2037. hmrDirtyComponents.add(oldComp);
  2038. }
  2039. // 3. invalidate options resolution cache
  2040. instance.appContext.optionsCache.delete(instance.type);
  2041. // 4. actually update
  2042. if (instance.ceReload) {
  2043. // custom element
  2044. hmrDirtyComponents.add(oldComp);
  2045. instance.ceReload(newComp.styles);
  2046. hmrDirtyComponents.delete(oldComp);
  2047. }
  2048. else if (instance.parent) {
  2049. // 4. Force the parent instance to re-render. This will cause all updated
  2050. // components to be unmounted and re-mounted. Queue the update so that we
  2051. // don't end up forcing the same parent to re-render multiple times.
  2052. queueJob(instance.parent.update);
  2053. // instance is the inner component of an async custom element
  2054. // invoke to reset styles
  2055. if (instance.parent.type.__asyncLoader &&
  2056. instance.parent.ceReload) {
  2057. instance.parent.ceReload(newComp.styles);
  2058. }
  2059. }
  2060. else if (instance.appContext.reload) {
  2061. // root instance mounted via createApp() has a reload method
  2062. instance.appContext.reload();
  2063. }
  2064. else if (typeof window !== 'undefined') {
  2065. // root instance inside tree created via raw render(). Force reload.
  2066. window.location.reload();
  2067. }
  2068. else {
  2069. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  2070. }
  2071. }
  2072. // 5. make sure to cleanup dirty hmr components after update
  2073. queuePostFlushCb(() => {
  2074. for (const instance of instances) {
  2075. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  2076. }
  2077. });
  2078. }
  2079. function updateComponentDef(oldComp, newComp) {
  2080. extend(oldComp, newComp);
  2081. for (const key in oldComp) {
  2082. if (key !== '__file' && !(key in newComp)) {
  2083. delete oldComp[key];
  2084. }
  2085. }
  2086. }
  2087. function tryWrap(fn) {
  2088. return (id, arg) => {
  2089. try {
  2090. return fn(id, arg);
  2091. }
  2092. catch (e) {
  2093. console.error(e);
  2094. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2095. `Full reload required.`);
  2096. }
  2097. };
  2098. }
  2099. let buffer = [];
  2100. let devtoolsNotInstalled = false;
  2101. function emit(event, ...args) {
  2102. if (exports.devtools) {
  2103. exports.devtools.emit(event, ...args);
  2104. }
  2105. else if (!devtoolsNotInstalled) {
  2106. buffer.push({ event, args });
  2107. }
  2108. }
  2109. function setDevtoolsHook(hook, target) {
  2110. var _a, _b;
  2111. exports.devtools = hook;
  2112. if (exports.devtools) {
  2113. exports.devtools.enabled = true;
  2114. buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
  2115. buffer = [];
  2116. }
  2117. else if (
  2118. // handle late devtools injection - only do this if we are in an actual
  2119. // browser environment to avoid the timer handle stalling test runner exit
  2120. // (#4815)
  2121. // eslint-disable-next-line no-restricted-globals
  2122. typeof window !== 'undefined' &&
  2123. // some envs mock window but not fully
  2124. window.HTMLElement &&
  2125. // also exclude jsdom
  2126. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2127. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2128. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2129. replay.push((newHook) => {
  2130. setDevtoolsHook(newHook, target);
  2131. });
  2132. // clear buffer after 3s - the user probably doesn't have devtools installed
  2133. // at all, and keeping the buffer will cause memory leaks (#4738)
  2134. setTimeout(() => {
  2135. if (!exports.devtools) {
  2136. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2137. devtoolsNotInstalled = true;
  2138. buffer = [];
  2139. }
  2140. }, 3000);
  2141. }
  2142. else {
  2143. // non-browser env, assume not installed
  2144. devtoolsNotInstalled = true;
  2145. buffer = [];
  2146. }
  2147. }
  2148. function devtoolsInitApp(app, version) {
  2149. emit("app:init" /* APP_INIT */, app, version, {
  2150. Fragment,
  2151. Text,
  2152. Comment,
  2153. Static
  2154. });
  2155. }
  2156. function devtoolsUnmountApp(app) {
  2157. emit("app:unmount" /* APP_UNMOUNT */, app);
  2158. }
  2159. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  2160. const devtoolsComponentUpdated =
  2161. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  2162. const devtoolsComponentRemoved =
  2163. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  2164. function createDevtoolsComponentHook(hook) {
  2165. return (component) => {
  2166. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2167. };
  2168. }
  2169. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  2170. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  2171. function createDevtoolsPerformanceHook(hook) {
  2172. return (component, type, time) => {
  2173. emit(hook, component.appContext.app, component.uid, component, type, time);
  2174. };
  2175. }
  2176. function devtoolsComponentEmit(component, event, params) {
  2177. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2178. }
  2179. function emit$1(instance, event, ...rawArgs) {
  2180. if (instance.isUnmounted)
  2181. return;
  2182. const props = instance.vnode.props || EMPTY_OBJ;
  2183. {
  2184. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2185. if (emitsOptions) {
  2186. if (!(event in emitsOptions) &&
  2187. !(false )) {
  2188. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2189. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  2190. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2191. }
  2192. }
  2193. else {
  2194. const validator = emitsOptions[event];
  2195. if (isFunction(validator)) {
  2196. const isValid = validator(...rawArgs);
  2197. if (!isValid) {
  2198. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. let args = rawArgs;
  2205. const isModelListener = event.startsWith('update:');
  2206. // for v-model update:xxx events, apply modifiers on args
  2207. const modelArg = isModelListener && event.slice(7);
  2208. if (modelArg && modelArg in props) {
  2209. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2210. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2211. if (trim) {
  2212. args = rawArgs.map(a => a.trim());
  2213. }
  2214. else if (number) {
  2215. args = rawArgs.map(toNumber);
  2216. }
  2217. }
  2218. {
  2219. devtoolsComponentEmit(instance, event, args);
  2220. }
  2221. {
  2222. const lowerCaseEvent = event.toLowerCase();
  2223. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2224. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  2225. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2226. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2227. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2228. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2229. }
  2230. }
  2231. let handlerName;
  2232. let handler = props[(handlerName = toHandlerKey(event))] ||
  2233. // also try camelCase event handler (#2249)
  2234. props[(handlerName = toHandlerKey(camelize(event)))];
  2235. // for v-model update:xxx events, also trigger kebab-case equivalent
  2236. // for props passed via kebab-case
  2237. if (!handler && isModelListener) {
  2238. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2239. }
  2240. if (handler) {
  2241. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2242. }
  2243. const onceHandler = props[handlerName + `Once`];
  2244. if (onceHandler) {
  2245. if (!instance.emitted) {
  2246. instance.emitted = {};
  2247. }
  2248. else if (instance.emitted[handlerName]) {
  2249. return;
  2250. }
  2251. instance.emitted[handlerName] = true;
  2252. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2253. }
  2254. }
  2255. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2256. const cache = appContext.emitsCache;
  2257. const cached = cache.get(comp);
  2258. if (cached !== undefined) {
  2259. return cached;
  2260. }
  2261. const raw = comp.emits;
  2262. let normalized = {};
  2263. // apply mixin/extends props
  2264. let hasExtends = false;
  2265. if (!isFunction(comp)) {
  2266. const extendEmits = (raw) => {
  2267. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2268. if (normalizedFromExtend) {
  2269. hasExtends = true;
  2270. extend(normalized, normalizedFromExtend);
  2271. }
  2272. };
  2273. if (!asMixin && appContext.mixins.length) {
  2274. appContext.mixins.forEach(extendEmits);
  2275. }
  2276. if (comp.extends) {
  2277. extendEmits(comp.extends);
  2278. }
  2279. if (comp.mixins) {
  2280. comp.mixins.forEach(extendEmits);
  2281. }
  2282. }
  2283. if (!raw && !hasExtends) {
  2284. cache.set(comp, null);
  2285. return null;
  2286. }
  2287. if (isArray(raw)) {
  2288. raw.forEach(key => (normalized[key] = null));
  2289. }
  2290. else {
  2291. extend(normalized, raw);
  2292. }
  2293. cache.set(comp, normalized);
  2294. return normalized;
  2295. }
  2296. // Check if an incoming prop key is a declared emit event listener.
  2297. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2298. // both considered matched listeners.
  2299. function isEmitListener(options, key) {
  2300. if (!options || !isOn(key)) {
  2301. return false;
  2302. }
  2303. key = key.slice(2).replace(/Once$/, '');
  2304. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2305. hasOwn(options, hyphenate(key)) ||
  2306. hasOwn(options, key));
  2307. }
  2308. /**
  2309. * mark the current rendering instance for asset resolution (e.g.
  2310. * resolveComponent, resolveDirective) during render
  2311. */
  2312. let currentRenderingInstance = null;
  2313. let currentScopeId = null;
  2314. /**
  2315. * Note: rendering calls maybe nested. The function returns the parent rendering
  2316. * instance if present, which should be restored after the render is done:
  2317. *
  2318. * ```js
  2319. * const prev = setCurrentRenderingInstance(i)
  2320. * // ...render
  2321. * setCurrentRenderingInstance(prev)
  2322. * ```
  2323. */
  2324. function setCurrentRenderingInstance(instance) {
  2325. const prev = currentRenderingInstance;
  2326. currentRenderingInstance = instance;
  2327. currentScopeId = (instance && instance.type.__scopeId) || null;
  2328. return prev;
  2329. }
  2330. /**
  2331. * Set scope id when creating hoisted vnodes.
  2332. * @private compiler helper
  2333. */
  2334. function pushScopeId(id) {
  2335. currentScopeId = id;
  2336. }
  2337. /**
  2338. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2339. * API for backwards compat w/ code generated by compilers.
  2340. * @private
  2341. */
  2342. function popScopeId() {
  2343. currentScopeId = null;
  2344. }
  2345. /**
  2346. * Only for backwards compat
  2347. * @private
  2348. */
  2349. const withScopeId = (_id) => withCtx;
  2350. /**
  2351. * Wrap a slot function to memoize current rendering instance
  2352. * @private compiler helper
  2353. */
  2354. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2355. ) {
  2356. if (!ctx)
  2357. return fn;
  2358. // already normalized
  2359. if (fn._n) {
  2360. return fn;
  2361. }
  2362. const renderFnWithContext = (...args) => {
  2363. // If a user calls a compiled slot inside a template expression (#1745), it
  2364. // can mess up block tracking, so by default we disable block tracking and
  2365. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2366. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2367. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2368. if (renderFnWithContext._d) {
  2369. setBlockTracking(-1);
  2370. }
  2371. const prevInstance = setCurrentRenderingInstance(ctx);
  2372. const res = fn(...args);
  2373. setCurrentRenderingInstance(prevInstance);
  2374. if (renderFnWithContext._d) {
  2375. setBlockTracking(1);
  2376. }
  2377. {
  2378. devtoolsComponentUpdated(ctx);
  2379. }
  2380. return res;
  2381. };
  2382. // mark normalized to avoid duplicated wrapping
  2383. renderFnWithContext._n = true;
  2384. // mark this as compiled by default
  2385. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2386. // rendering flag.
  2387. renderFnWithContext._c = true;
  2388. // disable block tracking by default
  2389. renderFnWithContext._d = true;
  2390. return renderFnWithContext;
  2391. }
  2392. /**
  2393. * dev only flag to track whether $attrs was used during render.
  2394. * If $attrs was used during render then the warning for failed attrs
  2395. * fallthrough can be suppressed.
  2396. */
  2397. let accessedAttrs = false;
  2398. function markAttrsAccessed() {
  2399. accessedAttrs = true;
  2400. }
  2401. function renderComponentRoot(instance) {
  2402. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2403. let result;
  2404. let fallthroughAttrs;
  2405. const prev = setCurrentRenderingInstance(instance);
  2406. {
  2407. accessedAttrs = false;
  2408. }
  2409. try {
  2410. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  2411. // withProxy is a proxy with a different `has` trap only for
  2412. // runtime-compiled render functions using `with` block.
  2413. const proxyToUse = withProxy || proxy;
  2414. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2415. fallthroughAttrs = attrs;
  2416. }
  2417. else {
  2418. // functional
  2419. const render = Component;
  2420. // in dev, mark attrs accessed if optional props (attrs === props)
  2421. if (true && attrs === props) {
  2422. markAttrsAccessed();
  2423. }
  2424. result = normalizeVNode(render.length > 1
  2425. ? render(props, true
  2426. ? {
  2427. get attrs() {
  2428. markAttrsAccessed();
  2429. return attrs;
  2430. },
  2431. slots,
  2432. emit
  2433. }
  2434. : { attrs, slots, emit })
  2435. : render(props, null /* we know it doesn't need it */));
  2436. fallthroughAttrs = Component.props
  2437. ? attrs
  2438. : getFunctionalFallthrough(attrs);
  2439. }
  2440. }
  2441. catch (err) {
  2442. blockStack.length = 0;
  2443. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  2444. result = createVNode(Comment);
  2445. }
  2446. // attr merging
  2447. // in dev mode, comments are preserved, and it's possible for a template
  2448. // to have comments along side the root element which makes it a fragment
  2449. let root = result;
  2450. let setRoot = undefined;
  2451. if (result.patchFlag > 0 &&
  2452. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  2453. [root, setRoot] = getChildRoot(result);
  2454. }
  2455. if (fallthroughAttrs && inheritAttrs !== false) {
  2456. const keys = Object.keys(fallthroughAttrs);
  2457. const { shapeFlag } = root;
  2458. if (keys.length) {
  2459. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  2460. if (propsOptions && keys.some(isModelListener)) {
  2461. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2462. // prop, it indicates this component expects to handle v-model and
  2463. // it should not fallthrough.
  2464. // related: #1543, #1643, #1989
  2465. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2466. }
  2467. root = cloneVNode(root, fallthroughAttrs);
  2468. }
  2469. else if (!accessedAttrs && root.type !== Comment) {
  2470. const allAttrs = Object.keys(attrs);
  2471. const eventAttrs = [];
  2472. const extraAttrs = [];
  2473. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2474. const key = allAttrs[i];
  2475. if (isOn(key)) {
  2476. // ignore v-model handlers when they fail to fallthrough
  2477. if (!isModelListener(key)) {
  2478. // remove `on`, lowercase first letter to reflect event casing
  2479. // accurately
  2480. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2481. }
  2482. }
  2483. else {
  2484. extraAttrs.push(key);
  2485. }
  2486. }
  2487. if (extraAttrs.length) {
  2488. warn$1(`Extraneous non-props attributes (` +
  2489. `${extraAttrs.join(', ')}) ` +
  2490. `were passed to component but could not be automatically inherited ` +
  2491. `because component renders fragment or text root nodes.`);
  2492. }
  2493. if (eventAttrs.length) {
  2494. warn$1(`Extraneous non-emits event listeners (` +
  2495. `${eventAttrs.join(', ')}) ` +
  2496. `were passed to component but could not be automatically inherited ` +
  2497. `because component renders fragment or text root nodes. ` +
  2498. `If the listener is intended to be a component custom event listener only, ` +
  2499. `declare it using the "emits" option.`);
  2500. }
  2501. }
  2502. }
  2503. }
  2504. // inherit directives
  2505. if (vnode.dirs) {
  2506. if (!isElementRoot(root)) {
  2507. warn$1(`Runtime directive used on component with non-element root node. ` +
  2508. `The directives will not function as intended.`);
  2509. }
  2510. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2511. }
  2512. // inherit transition data
  2513. if (vnode.transition) {
  2514. if (!isElementRoot(root)) {
  2515. warn$1(`Component inside <Transition> renders non-element root node ` +
  2516. `that cannot be animated.`);
  2517. }
  2518. root.transition = vnode.transition;
  2519. }
  2520. if (setRoot) {
  2521. setRoot(root);
  2522. }
  2523. else {
  2524. result = root;
  2525. }
  2526. setCurrentRenderingInstance(prev);
  2527. return result;
  2528. }
  2529. /**
  2530. * dev only
  2531. * In dev mode, template root level comments are rendered, which turns the
  2532. * template into a fragment root, but we need to locate the single element
  2533. * root for attrs and scope id processing.
  2534. */
  2535. const getChildRoot = (vnode) => {
  2536. const rawChildren = vnode.children;
  2537. const dynamicChildren = vnode.dynamicChildren;
  2538. const childRoot = filterSingleRoot(rawChildren);
  2539. if (!childRoot) {
  2540. return [vnode, undefined];
  2541. }
  2542. const index = rawChildren.indexOf(childRoot);
  2543. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2544. const setRoot = (updatedRoot) => {
  2545. rawChildren[index] = updatedRoot;
  2546. if (dynamicChildren) {
  2547. if (dynamicIndex > -1) {
  2548. dynamicChildren[dynamicIndex] = updatedRoot;
  2549. }
  2550. else if (updatedRoot.patchFlag > 0) {
  2551. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2552. }
  2553. }
  2554. };
  2555. return [normalizeVNode(childRoot), setRoot];
  2556. };
  2557. function filterSingleRoot(children) {
  2558. let singleRoot;
  2559. for (let i = 0; i < children.length; i++) {
  2560. const child = children[i];
  2561. if (isVNode(child)) {
  2562. // ignore user comment
  2563. if (child.type !== Comment || child.children === 'v-if') {
  2564. if (singleRoot) {
  2565. // has more than 1 non-comment child, return now
  2566. return;
  2567. }
  2568. else {
  2569. singleRoot = child;
  2570. }
  2571. }
  2572. }
  2573. else {
  2574. return;
  2575. }
  2576. }
  2577. return singleRoot;
  2578. }
  2579. const getFunctionalFallthrough = (attrs) => {
  2580. let res;
  2581. for (const key in attrs) {
  2582. if (key === 'class' || key === 'style' || isOn(key)) {
  2583. (res || (res = {}))[key] = attrs[key];
  2584. }
  2585. }
  2586. return res;
  2587. };
  2588. const filterModelListeners = (attrs, props) => {
  2589. const res = {};
  2590. for (const key in attrs) {
  2591. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2592. res[key] = attrs[key];
  2593. }
  2594. }
  2595. return res;
  2596. };
  2597. const isElementRoot = (vnode) => {
  2598. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  2599. vnode.type === Comment // potential v-if branch switch
  2600. );
  2601. };
  2602. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2603. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2604. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2605. const emits = component.emitsOptions;
  2606. // Parent component's render function was hot-updated. Since this may have
  2607. // caused the child component's slots content to have changed, we need to
  2608. // force the child to update as well.
  2609. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2610. return true;
  2611. }
  2612. // force child update for runtime directive or transition on component vnode.
  2613. if (nextVNode.dirs || nextVNode.transition) {
  2614. return true;
  2615. }
  2616. if (optimized && patchFlag >= 0) {
  2617. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2618. // slot content that references values that might have changed,
  2619. // e.g. in a v-for
  2620. return true;
  2621. }
  2622. if (patchFlag & 16 /* FULL_PROPS */) {
  2623. if (!prevProps) {
  2624. return !!nextProps;
  2625. }
  2626. // presence of this flag indicates props are always non-null
  2627. return hasPropsChanged(prevProps, nextProps, emits);
  2628. }
  2629. else if (patchFlag & 8 /* PROPS */) {
  2630. const dynamicProps = nextVNode.dynamicProps;
  2631. for (let i = 0; i < dynamicProps.length; i++) {
  2632. const key = dynamicProps[i];
  2633. if (nextProps[key] !== prevProps[key] &&
  2634. !isEmitListener(emits, key)) {
  2635. return true;
  2636. }
  2637. }
  2638. }
  2639. }
  2640. else {
  2641. // this path is only taken by manually written render functions
  2642. // so presence of any children leads to a forced update
  2643. if (prevChildren || nextChildren) {
  2644. if (!nextChildren || !nextChildren.$stable) {
  2645. return true;
  2646. }
  2647. }
  2648. if (prevProps === nextProps) {
  2649. return false;
  2650. }
  2651. if (!prevProps) {
  2652. return !!nextProps;
  2653. }
  2654. if (!nextProps) {
  2655. return true;
  2656. }
  2657. return hasPropsChanged(prevProps, nextProps, emits);
  2658. }
  2659. return false;
  2660. }
  2661. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2662. const nextKeys = Object.keys(nextProps);
  2663. if (nextKeys.length !== Object.keys(prevProps).length) {
  2664. return true;
  2665. }
  2666. for (let i = 0; i < nextKeys.length; i++) {
  2667. const key = nextKeys[i];
  2668. if (nextProps[key] !== prevProps[key] &&
  2669. !isEmitListener(emitsOptions, key)) {
  2670. return true;
  2671. }
  2672. }
  2673. return false;
  2674. }
  2675. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2676. ) {
  2677. while (parent && parent.subTree === vnode) {
  2678. (vnode = parent.vnode).el = el;
  2679. parent = parent.parent;
  2680. }
  2681. }
  2682. const isSuspense = (type) => type.__isSuspense;
  2683. // Suspense exposes a component-like API, and is treated like a component
  2684. // in the compiler, but internally it's a special built-in type that hooks
  2685. // directly into the renderer.
  2686. const SuspenseImpl = {
  2687. name: 'Suspense',
  2688. // In order to make Suspense tree-shakable, we need to avoid importing it
  2689. // directly in the renderer. The renderer checks for the __isSuspense flag
  2690. // on a vnode's type and calls the `process` method, passing in renderer
  2691. // internals.
  2692. __isSuspense: true,
  2693. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2694. // platform-specific impl passed from renderer
  2695. rendererInternals) {
  2696. if (n1 == null) {
  2697. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2698. }
  2699. else {
  2700. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2701. }
  2702. },
  2703. hydrate: hydrateSuspense,
  2704. create: createSuspenseBoundary,
  2705. normalize: normalizeSuspenseChildren
  2706. };
  2707. // Force-casted public typing for h and TSX props inference
  2708. const Suspense = (SuspenseImpl );
  2709. function triggerEvent(vnode, name) {
  2710. const eventListener = vnode.props && vnode.props[name];
  2711. if (isFunction(eventListener)) {
  2712. eventListener();
  2713. }
  2714. }
  2715. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2716. const { p: patch, o: { createElement } } = rendererInternals;
  2717. const hiddenContainer = createElement('div');
  2718. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2719. // start mounting the content subtree in an off-dom container
  2720. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2721. // now check if we have encountered any async deps
  2722. if (suspense.deps > 0) {
  2723. // has async
  2724. // invoke @fallback event
  2725. triggerEvent(vnode, 'onPending');
  2726. triggerEvent(vnode, 'onFallback');
  2727. // mount the fallback tree
  2728. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2729. isSVG, slotScopeIds);
  2730. setActiveBranch(suspense, vnode.ssFallback);
  2731. }
  2732. else {
  2733. // Suspense has no async deps. Just resolve.
  2734. suspense.resolve();
  2735. }
  2736. }
  2737. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2738. const suspense = (n2.suspense = n1.suspense);
  2739. suspense.vnode = n2;
  2740. n2.el = n1.el;
  2741. const newBranch = n2.ssContent;
  2742. const newFallback = n2.ssFallback;
  2743. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2744. if (pendingBranch) {
  2745. suspense.pendingBranch = newBranch;
  2746. if (isSameVNodeType(newBranch, pendingBranch)) {
  2747. // same root type but content may have changed.
  2748. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2749. if (suspense.deps <= 0) {
  2750. suspense.resolve();
  2751. }
  2752. else if (isInFallback) {
  2753. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2754. isSVG, slotScopeIds, optimized);
  2755. setActiveBranch(suspense, newFallback);
  2756. }
  2757. }
  2758. else {
  2759. // toggled before pending tree is resolved
  2760. suspense.pendingId++;
  2761. if (isHydrating) {
  2762. // if toggled before hydration is finished, the current DOM tree is
  2763. // no longer valid. set it as the active branch so it will be unmounted
  2764. // when resolved
  2765. suspense.isHydrating = false;
  2766. suspense.activeBranch = pendingBranch;
  2767. }
  2768. else {
  2769. unmount(pendingBranch, parentComponent, suspense);
  2770. }
  2771. // increment pending ID. this is used to invalidate async callbacks
  2772. // reset suspense state
  2773. suspense.deps = 0;
  2774. // discard effects from pending branch
  2775. suspense.effects.length = 0;
  2776. // discard previous container
  2777. suspense.hiddenContainer = createElement('div');
  2778. if (isInFallback) {
  2779. // already in fallback state
  2780. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2781. if (suspense.deps <= 0) {
  2782. suspense.resolve();
  2783. }
  2784. else {
  2785. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2786. isSVG, slotScopeIds, optimized);
  2787. setActiveBranch(suspense, newFallback);
  2788. }
  2789. }
  2790. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2791. // toggled "back" to current active branch
  2792. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2793. // force resolve
  2794. suspense.resolve(true);
  2795. }
  2796. else {
  2797. // switched to a 3rd branch
  2798. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2799. if (suspense.deps <= 0) {
  2800. suspense.resolve();
  2801. }
  2802. }
  2803. }
  2804. }
  2805. else {
  2806. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2807. // root did not change, just normal patch
  2808. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2809. setActiveBranch(suspense, newBranch);
  2810. }
  2811. else {
  2812. // root node toggled
  2813. // invoke @pending event
  2814. triggerEvent(n2, 'onPending');
  2815. // mount pending branch in off-dom container
  2816. suspense.pendingBranch = newBranch;
  2817. suspense.pendingId++;
  2818. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2819. if (suspense.deps <= 0) {
  2820. // incoming branch has no async deps, resolve now.
  2821. suspense.resolve();
  2822. }
  2823. else {
  2824. const { timeout, pendingId } = suspense;
  2825. if (timeout > 0) {
  2826. setTimeout(() => {
  2827. if (suspense.pendingId === pendingId) {
  2828. suspense.fallback(newFallback);
  2829. }
  2830. }, timeout);
  2831. }
  2832. else if (timeout === 0) {
  2833. suspense.fallback(newFallback);
  2834. }
  2835. }
  2836. }
  2837. }
  2838. }
  2839. let hasWarned = false;
  2840. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2841. /* istanbul ignore if */
  2842. if (!hasWarned) {
  2843. hasWarned = true;
  2844. // @ts-ignore `console.info` cannot be null error
  2845. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2846. }
  2847. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2848. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2849. const suspense = {
  2850. vnode,
  2851. parent,
  2852. parentComponent,
  2853. isSVG,
  2854. container,
  2855. hiddenContainer,
  2856. anchor,
  2857. deps: 0,
  2858. pendingId: 0,
  2859. timeout: typeof timeout === 'number' ? timeout : -1,
  2860. activeBranch: null,
  2861. pendingBranch: null,
  2862. isInFallback: true,
  2863. isHydrating,
  2864. isUnmounted: false,
  2865. effects: [],
  2866. resolve(resume = false) {
  2867. {
  2868. if (!resume && !suspense.pendingBranch) {
  2869. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2870. }
  2871. if (suspense.isUnmounted) {
  2872. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2873. }
  2874. }
  2875. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2876. if (suspense.isHydrating) {
  2877. suspense.isHydrating = false;
  2878. }
  2879. else if (!resume) {
  2880. const delayEnter = activeBranch &&
  2881. pendingBranch.transition &&
  2882. pendingBranch.transition.mode === 'out-in';
  2883. if (delayEnter) {
  2884. activeBranch.transition.afterLeave = () => {
  2885. if (pendingId === suspense.pendingId) {
  2886. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2887. }
  2888. };
  2889. }
  2890. // this is initial anchor on mount
  2891. let { anchor } = suspense;
  2892. // unmount current active tree
  2893. if (activeBranch) {
  2894. // if the fallback tree was mounted, it may have been moved
  2895. // as part of a parent suspense. get the latest anchor for insertion
  2896. anchor = next(activeBranch);
  2897. unmount(activeBranch, parentComponent, suspense, true);
  2898. }
  2899. if (!delayEnter) {
  2900. // move content from off-dom container to actual container
  2901. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2902. }
  2903. }
  2904. setActiveBranch(suspense, pendingBranch);
  2905. suspense.pendingBranch = null;
  2906. suspense.isInFallback = false;
  2907. // flush buffered effects
  2908. // check if there is a pending parent suspense
  2909. let parent = suspense.parent;
  2910. let hasUnresolvedAncestor = false;
  2911. while (parent) {
  2912. if (parent.pendingBranch) {
  2913. // found a pending parent suspense, merge buffered post jobs
  2914. // into that parent
  2915. parent.effects.push(...effects);
  2916. hasUnresolvedAncestor = true;
  2917. break;
  2918. }
  2919. parent = parent.parent;
  2920. }
  2921. // no pending parent suspense, flush all jobs
  2922. if (!hasUnresolvedAncestor) {
  2923. queuePostFlushCb(effects);
  2924. }
  2925. suspense.effects = [];
  2926. // invoke @resolve event
  2927. triggerEvent(vnode, 'onResolve');
  2928. },
  2929. fallback(fallbackVNode) {
  2930. if (!suspense.pendingBranch) {
  2931. return;
  2932. }
  2933. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2934. // invoke @fallback event
  2935. triggerEvent(vnode, 'onFallback');
  2936. const anchor = next(activeBranch);
  2937. const mountFallback = () => {
  2938. if (!suspense.isInFallback) {
  2939. return;
  2940. }
  2941. // mount the fallback tree
  2942. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2943. isSVG, slotScopeIds, optimized);
  2944. setActiveBranch(suspense, fallbackVNode);
  2945. };
  2946. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2947. if (delayEnter) {
  2948. activeBranch.transition.afterLeave = mountFallback;
  2949. }
  2950. suspense.isInFallback = true;
  2951. // unmount current active branch
  2952. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2953. true // shouldRemove
  2954. );
  2955. if (!delayEnter) {
  2956. mountFallback();
  2957. }
  2958. },
  2959. move(container, anchor, type) {
  2960. suspense.activeBranch &&
  2961. move(suspense.activeBranch, container, anchor, type);
  2962. suspense.container = container;
  2963. },
  2964. next() {
  2965. return suspense.activeBranch && next(suspense.activeBranch);
  2966. },
  2967. registerDep(instance, setupRenderEffect) {
  2968. const isInPendingSuspense = !!suspense.pendingBranch;
  2969. if (isInPendingSuspense) {
  2970. suspense.deps++;
  2971. }
  2972. const hydratedEl = instance.vnode.el;
  2973. instance
  2974. .asyncDep.catch(err => {
  2975. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  2976. })
  2977. .then(asyncSetupResult => {
  2978. // retry when the setup() promise resolves.
  2979. // component may have been unmounted before resolve.
  2980. if (instance.isUnmounted ||
  2981. suspense.isUnmounted ||
  2982. suspense.pendingId !== instance.suspenseId) {
  2983. return;
  2984. }
  2985. // retry from this component
  2986. instance.asyncResolved = true;
  2987. const { vnode } = instance;
  2988. {
  2989. pushWarningContext(vnode);
  2990. }
  2991. handleSetupResult(instance, asyncSetupResult, false);
  2992. if (hydratedEl) {
  2993. // vnode may have been replaced if an update happened before the
  2994. // async dep is resolved.
  2995. vnode.el = hydratedEl;
  2996. }
  2997. const placeholder = !hydratedEl && instance.subTree.el;
  2998. setupRenderEffect(instance, vnode,
  2999. // component may have been moved before resolve.
  3000. // if this is not a hydration, instance.subTree will be the comment
  3001. // placeholder.
  3002. parentNode(hydratedEl || instance.subTree.el),
  3003. // anchor will not be used if this is hydration, so only need to
  3004. // consider the comment placeholder case.
  3005. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  3006. if (placeholder) {
  3007. remove(placeholder);
  3008. }
  3009. updateHOCHostEl(instance, vnode.el);
  3010. {
  3011. popWarningContext();
  3012. }
  3013. // only decrease deps count if suspense is not already resolved
  3014. if (isInPendingSuspense && --suspense.deps === 0) {
  3015. suspense.resolve();
  3016. }
  3017. });
  3018. },
  3019. unmount(parentSuspense, doRemove) {
  3020. suspense.isUnmounted = true;
  3021. if (suspense.activeBranch) {
  3022. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  3023. }
  3024. if (suspense.pendingBranch) {
  3025. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  3026. }
  3027. }
  3028. };
  3029. return suspense;
  3030. }
  3031. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  3032. /* eslint-disable no-restricted-globals */
  3033. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  3034. // there are two possible scenarios for server-rendered suspense:
  3035. // - success: ssr content should be fully resolved
  3036. // - failure: ssr content should be the fallback branch.
  3037. // however, on the client we don't really know if it has failed or not
  3038. // attempt to hydrate the DOM assuming it has succeeded, but we still
  3039. // need to construct a suspense boundary first
  3040. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  3041. if (suspense.deps === 0) {
  3042. suspense.resolve();
  3043. }
  3044. return result;
  3045. /* eslint-enable no-restricted-globals */
  3046. }
  3047. function normalizeSuspenseChildren(vnode) {
  3048. const { shapeFlag, children } = vnode;
  3049. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  3050. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  3051. vnode.ssFallback = isSlotChildren
  3052. ? normalizeSuspenseSlot(children.fallback)
  3053. : createVNode(Comment);
  3054. }
  3055. function normalizeSuspenseSlot(s) {
  3056. let block;
  3057. if (isFunction(s)) {
  3058. const trackBlock = isBlockTreeEnabled && s._c;
  3059. if (trackBlock) {
  3060. // disableTracking: false
  3061. // allow block tracking for compiled slots
  3062. // (see ./componentRenderContext.ts)
  3063. s._d = false;
  3064. openBlock();
  3065. }
  3066. s = s();
  3067. if (trackBlock) {
  3068. s._d = true;
  3069. block = currentBlock;
  3070. closeBlock();
  3071. }
  3072. }
  3073. if (isArray(s)) {
  3074. const singleChild = filterSingleRoot(s);
  3075. if (!singleChild) {
  3076. warn$1(`<Suspense> slots expect a single root node.`);
  3077. }
  3078. s = singleChild;
  3079. }
  3080. s = normalizeVNode(s);
  3081. if (block && !s.dynamicChildren) {
  3082. s.dynamicChildren = block.filter(c => c !== s);
  3083. }
  3084. return s;
  3085. }
  3086. function queueEffectWithSuspense(fn, suspense) {
  3087. if (suspense && suspense.pendingBranch) {
  3088. if (isArray(fn)) {
  3089. suspense.effects.push(...fn);
  3090. }
  3091. else {
  3092. suspense.effects.push(fn);
  3093. }
  3094. }
  3095. else {
  3096. queuePostFlushCb(fn);
  3097. }
  3098. }
  3099. function setActiveBranch(suspense, branch) {
  3100. suspense.activeBranch = branch;
  3101. const { vnode, parentComponent } = suspense;
  3102. const el = (vnode.el = branch.el);
  3103. // in case suspense is the root node of a component,
  3104. // recursively update the HOC el
  3105. if (parentComponent && parentComponent.subTree === vnode) {
  3106. parentComponent.vnode.el = el;
  3107. updateHOCHostEl(parentComponent, el);
  3108. }
  3109. }
  3110. function provide(key, value) {
  3111. if (!currentInstance) {
  3112. {
  3113. warn$1(`provide() can only be used inside setup().`);
  3114. }
  3115. }
  3116. else {
  3117. let provides = currentInstance.provides;
  3118. // by default an instance inherits its parent's provides object
  3119. // but when it needs to provide values of its own, it creates its
  3120. // own provides object using parent provides object as prototype.
  3121. // this way in `inject` we can simply look up injections from direct
  3122. // parent and let the prototype chain do the work.
  3123. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3124. if (parentProvides === provides) {
  3125. provides = currentInstance.provides = Object.create(parentProvides);
  3126. }
  3127. // TS doesn't allow symbol as index type
  3128. provides[key] = value;
  3129. }
  3130. }
  3131. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3132. // fallback to `currentRenderingInstance` so that this can be called in
  3133. // a functional component
  3134. const instance = currentInstance || currentRenderingInstance;
  3135. if (instance) {
  3136. // #2400
  3137. // to support `app.use` plugins,
  3138. // fallback to appContext's `provides` if the instance is at root
  3139. const provides = instance.parent == null
  3140. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3141. : instance.parent.provides;
  3142. if (provides && key in provides) {
  3143. // TS doesn't allow symbol as index type
  3144. return provides[key];
  3145. }
  3146. else if (arguments.length > 1) {
  3147. return treatDefaultAsFactory && isFunction(defaultValue)
  3148. ? defaultValue.call(instance.proxy)
  3149. : defaultValue;
  3150. }
  3151. else {
  3152. warn$1(`injection "${String(key)}" not found.`);
  3153. }
  3154. }
  3155. else {
  3156. warn$1(`inject() can only be used inside setup() or functional components.`);
  3157. }
  3158. }
  3159. // Simple effect.
  3160. function watchEffect(effect, options) {
  3161. return doWatch(effect, null, options);
  3162. }
  3163. function watchPostEffect(effect, options) {
  3164. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'post' }) ));
  3165. }
  3166. function watchSyncEffect(effect, options) {
  3167. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'sync' }) ));
  3168. }
  3169. // initial value for watchers to trigger on undefined initial values
  3170. const INITIAL_WATCHER_VALUE = {};
  3171. // implementation
  3172. function watch(source, cb, options) {
  3173. if (!isFunction(cb)) {
  3174. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3175. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3176. `supports \`watch(source, cb, options?) signature.`);
  3177. }
  3178. return doWatch(source, cb, options);
  3179. }
  3180. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3181. if (!cb) {
  3182. if (immediate !== undefined) {
  3183. warn$1(`watch() "immediate" option is only respected when using the ` +
  3184. `watch(source, callback, options?) signature.`);
  3185. }
  3186. if (deep !== undefined) {
  3187. warn$1(`watch() "deep" option is only respected when using the ` +
  3188. `watch(source, callback, options?) signature.`);
  3189. }
  3190. }
  3191. const warnInvalidSource = (s) => {
  3192. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3193. `a reactive object, or an array of these types.`);
  3194. };
  3195. const instance = currentInstance;
  3196. let getter;
  3197. let forceTrigger = false;
  3198. let isMultiSource = false;
  3199. if (isRef(source)) {
  3200. getter = () => source.value;
  3201. forceTrigger = isShallow(source);
  3202. }
  3203. else if (isReactive(source)) {
  3204. getter = () => source;
  3205. deep = true;
  3206. }
  3207. else if (isArray(source)) {
  3208. isMultiSource = true;
  3209. forceTrigger = source.some(isReactive);
  3210. getter = () => source.map(s => {
  3211. if (isRef(s)) {
  3212. return s.value;
  3213. }
  3214. else if (isReactive(s)) {
  3215. return traverse(s);
  3216. }
  3217. else if (isFunction(s)) {
  3218. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  3219. }
  3220. else {
  3221. warnInvalidSource(s);
  3222. }
  3223. });
  3224. }
  3225. else if (isFunction(source)) {
  3226. if (cb) {
  3227. // getter with cb
  3228. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  3229. }
  3230. else {
  3231. // no cb -> simple effect
  3232. getter = () => {
  3233. if (instance && instance.isUnmounted) {
  3234. return;
  3235. }
  3236. if (cleanup) {
  3237. cleanup();
  3238. }
  3239. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onCleanup]);
  3240. };
  3241. }
  3242. }
  3243. else {
  3244. getter = NOOP;
  3245. warnInvalidSource(source);
  3246. }
  3247. if (cb && deep) {
  3248. const baseGetter = getter;
  3249. getter = () => traverse(baseGetter());
  3250. }
  3251. let cleanup;
  3252. let onCleanup = (fn) => {
  3253. cleanup = effect.onStop = () => {
  3254. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  3255. };
  3256. };
  3257. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  3258. const job = () => {
  3259. if (!effect.active) {
  3260. return;
  3261. }
  3262. if (cb) {
  3263. // watch(source, cb)
  3264. const newValue = effect.run();
  3265. if (deep ||
  3266. forceTrigger ||
  3267. (isMultiSource
  3268. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3269. : hasChanged(newValue, oldValue)) ||
  3270. (false )) {
  3271. // cleanup before running cb again
  3272. if (cleanup) {
  3273. cleanup();
  3274. }
  3275. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  3276. newValue,
  3277. // pass undefined as the old value when it's changed for the first time
  3278. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  3279. onCleanup
  3280. ]);
  3281. oldValue = newValue;
  3282. }
  3283. }
  3284. else {
  3285. // watchEffect
  3286. effect.run();
  3287. }
  3288. };
  3289. // important: mark the job as a watcher callback so that scheduler knows
  3290. // it is allowed to self-trigger (#1727)
  3291. job.allowRecurse = !!cb;
  3292. let scheduler;
  3293. if (flush === 'sync') {
  3294. scheduler = job; // the scheduler function gets called directly
  3295. }
  3296. else if (flush === 'post') {
  3297. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3298. }
  3299. else {
  3300. // default: 'pre'
  3301. scheduler = () => {
  3302. if (!instance || instance.isMounted) {
  3303. queuePreFlushCb(job);
  3304. }
  3305. else {
  3306. // with 'pre' option, the first call must happen before
  3307. // the component is mounted so it is called synchronously.
  3308. job();
  3309. }
  3310. };
  3311. }
  3312. const effect = new ReactiveEffect(getter, scheduler);
  3313. {
  3314. effect.onTrack = onTrack;
  3315. effect.onTrigger = onTrigger;
  3316. }
  3317. // initial run
  3318. if (cb) {
  3319. if (immediate) {
  3320. job();
  3321. }
  3322. else {
  3323. oldValue = effect.run();
  3324. }
  3325. }
  3326. else if (flush === 'post') {
  3327. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3328. }
  3329. else {
  3330. effect.run();
  3331. }
  3332. return () => {
  3333. effect.stop();
  3334. if (instance && instance.scope) {
  3335. remove(instance.scope.effects, effect);
  3336. }
  3337. };
  3338. }
  3339. // this.$watch
  3340. function instanceWatch(source, value, options) {
  3341. const publicThis = this.proxy;
  3342. const getter = isString(source)
  3343. ? source.includes('.')
  3344. ? createPathGetter(publicThis, source)
  3345. : () => publicThis[source]
  3346. : source.bind(publicThis, publicThis);
  3347. let cb;
  3348. if (isFunction(value)) {
  3349. cb = value;
  3350. }
  3351. else {
  3352. cb = value.handler;
  3353. options = value;
  3354. }
  3355. const cur = currentInstance;
  3356. setCurrentInstance(this);
  3357. const res = doWatch(getter, cb.bind(publicThis), options);
  3358. if (cur) {
  3359. setCurrentInstance(cur);
  3360. }
  3361. else {
  3362. unsetCurrentInstance();
  3363. }
  3364. return res;
  3365. }
  3366. function createPathGetter(ctx, path) {
  3367. const segments = path.split('.');
  3368. return () => {
  3369. let cur = ctx;
  3370. for (let i = 0; i < segments.length && cur; i++) {
  3371. cur = cur[segments[i]];
  3372. }
  3373. return cur;
  3374. };
  3375. }
  3376. function traverse(value, seen) {
  3377. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  3378. return value;
  3379. }
  3380. seen = seen || new Set();
  3381. if (seen.has(value)) {
  3382. return value;
  3383. }
  3384. seen.add(value);
  3385. if (isRef(value)) {
  3386. traverse(value.value, seen);
  3387. }
  3388. else if (isArray(value)) {
  3389. for (let i = 0; i < value.length; i++) {
  3390. traverse(value[i], seen);
  3391. }
  3392. }
  3393. else if (isSet(value) || isMap(value)) {
  3394. value.forEach((v) => {
  3395. traverse(v, seen);
  3396. });
  3397. }
  3398. else if (isPlainObject(value)) {
  3399. for (const key in value) {
  3400. traverse(value[key], seen);
  3401. }
  3402. }
  3403. return value;
  3404. }
  3405. function useTransitionState() {
  3406. const state = {
  3407. isMounted: false,
  3408. isLeaving: false,
  3409. isUnmounting: false,
  3410. leavingVNodes: new Map()
  3411. };
  3412. onMounted(() => {
  3413. state.isMounted = true;
  3414. });
  3415. onBeforeUnmount(() => {
  3416. state.isUnmounting = true;
  3417. });
  3418. return state;
  3419. }
  3420. const TransitionHookValidator = [Function, Array];
  3421. const BaseTransitionImpl = {
  3422. name: `BaseTransition`,
  3423. props: {
  3424. mode: String,
  3425. appear: Boolean,
  3426. persisted: Boolean,
  3427. // enter
  3428. onBeforeEnter: TransitionHookValidator,
  3429. onEnter: TransitionHookValidator,
  3430. onAfterEnter: TransitionHookValidator,
  3431. onEnterCancelled: TransitionHookValidator,
  3432. // leave
  3433. onBeforeLeave: TransitionHookValidator,
  3434. onLeave: TransitionHookValidator,
  3435. onAfterLeave: TransitionHookValidator,
  3436. onLeaveCancelled: TransitionHookValidator,
  3437. // appear
  3438. onBeforeAppear: TransitionHookValidator,
  3439. onAppear: TransitionHookValidator,
  3440. onAfterAppear: TransitionHookValidator,
  3441. onAppearCancelled: TransitionHookValidator
  3442. },
  3443. setup(props, { slots }) {
  3444. const instance = getCurrentInstance();
  3445. const state = useTransitionState();
  3446. let prevTransitionKey;
  3447. return () => {
  3448. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3449. if (!children || !children.length) {
  3450. return;
  3451. }
  3452. let child = children[0];
  3453. if (children.length > 1) {
  3454. let hasFound = false;
  3455. // locate first non-comment child
  3456. for (const c of children) {
  3457. if (c.type !== Comment) {
  3458. if (hasFound) {
  3459. // warn more than one non-comment child
  3460. warn$1('<transition> can only be used on a single element or component. ' +
  3461. 'Use <transition-group> for lists.');
  3462. break;
  3463. }
  3464. child = c;
  3465. hasFound = true;
  3466. }
  3467. }
  3468. }
  3469. // there's no need to track reactivity for these props so use the raw
  3470. // props for a bit better perf
  3471. const rawProps = toRaw(props);
  3472. const { mode } = rawProps;
  3473. // check mode
  3474. if (mode &&
  3475. mode !== 'in-out' &&
  3476. mode !== 'out-in' &&
  3477. mode !== 'default') {
  3478. warn$1(`invalid <transition> mode: ${mode}`);
  3479. }
  3480. if (state.isLeaving) {
  3481. return emptyPlaceholder(child);
  3482. }
  3483. // in the case of <transition><keep-alive/></transition>, we need to
  3484. // compare the type of the kept-alive children.
  3485. const innerChild = getKeepAliveChild(child);
  3486. if (!innerChild) {
  3487. return emptyPlaceholder(child);
  3488. }
  3489. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3490. setTransitionHooks(innerChild, enterHooks);
  3491. const oldChild = instance.subTree;
  3492. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3493. let transitionKeyChanged = false;
  3494. const { getTransitionKey } = innerChild.type;
  3495. if (getTransitionKey) {
  3496. const key = getTransitionKey();
  3497. if (prevTransitionKey === undefined) {
  3498. prevTransitionKey = key;
  3499. }
  3500. else if (key !== prevTransitionKey) {
  3501. prevTransitionKey = key;
  3502. transitionKeyChanged = true;
  3503. }
  3504. }
  3505. // handle mode
  3506. if (oldInnerChild &&
  3507. oldInnerChild.type !== Comment &&
  3508. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3509. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3510. // update old tree's hooks in case of dynamic transition
  3511. setTransitionHooks(oldInnerChild, leavingHooks);
  3512. // switching between different views
  3513. if (mode === 'out-in') {
  3514. state.isLeaving = true;
  3515. // return placeholder node and queue update when leave finishes
  3516. leavingHooks.afterLeave = () => {
  3517. state.isLeaving = false;
  3518. instance.update();
  3519. };
  3520. return emptyPlaceholder(child);
  3521. }
  3522. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3523. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3524. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3525. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3526. // early removal callback
  3527. el._leaveCb = () => {
  3528. earlyRemove();
  3529. el._leaveCb = undefined;
  3530. delete enterHooks.delayedLeave;
  3531. };
  3532. enterHooks.delayedLeave = delayedLeave;
  3533. };
  3534. }
  3535. }
  3536. return child;
  3537. };
  3538. }
  3539. };
  3540. // export the public type for h/tsx inference
  3541. // also to avoid inline import() in generated d.ts files
  3542. const BaseTransition = BaseTransitionImpl;
  3543. function getLeavingNodesForType(state, vnode) {
  3544. const { leavingVNodes } = state;
  3545. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3546. if (!leavingVNodesCache) {
  3547. leavingVNodesCache = Object.create(null);
  3548. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3549. }
  3550. return leavingVNodesCache;
  3551. }
  3552. // The transition hooks are attached to the vnode as vnode.transition
  3553. // and will be called at appropriate timing in the renderer.
  3554. function resolveTransitionHooks(vnode, props, state, instance) {
  3555. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3556. const key = String(vnode.key);
  3557. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3558. const callHook = (hook, args) => {
  3559. hook &&
  3560. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3561. };
  3562. const hooks = {
  3563. mode,
  3564. persisted,
  3565. beforeEnter(el) {
  3566. let hook = onBeforeEnter;
  3567. if (!state.isMounted) {
  3568. if (appear) {
  3569. hook = onBeforeAppear || onBeforeEnter;
  3570. }
  3571. else {
  3572. return;
  3573. }
  3574. }
  3575. // for same element (v-show)
  3576. if (el._leaveCb) {
  3577. el._leaveCb(true /* cancelled */);
  3578. }
  3579. // for toggled element with same key (v-if)
  3580. const leavingVNode = leavingVNodesCache[key];
  3581. if (leavingVNode &&
  3582. isSameVNodeType(vnode, leavingVNode) &&
  3583. leavingVNode.el._leaveCb) {
  3584. // force early removal (not cancelled)
  3585. leavingVNode.el._leaveCb();
  3586. }
  3587. callHook(hook, [el]);
  3588. },
  3589. enter(el) {
  3590. let hook = onEnter;
  3591. let afterHook = onAfterEnter;
  3592. let cancelHook = onEnterCancelled;
  3593. if (!state.isMounted) {
  3594. if (appear) {
  3595. hook = onAppear || onEnter;
  3596. afterHook = onAfterAppear || onAfterEnter;
  3597. cancelHook = onAppearCancelled || onEnterCancelled;
  3598. }
  3599. else {
  3600. return;
  3601. }
  3602. }
  3603. let called = false;
  3604. const done = (el._enterCb = (cancelled) => {
  3605. if (called)
  3606. return;
  3607. called = true;
  3608. if (cancelled) {
  3609. callHook(cancelHook, [el]);
  3610. }
  3611. else {
  3612. callHook(afterHook, [el]);
  3613. }
  3614. if (hooks.delayedLeave) {
  3615. hooks.delayedLeave();
  3616. }
  3617. el._enterCb = undefined;
  3618. });
  3619. if (hook) {
  3620. hook(el, done);
  3621. if (hook.length <= 1) {
  3622. done();
  3623. }
  3624. }
  3625. else {
  3626. done();
  3627. }
  3628. },
  3629. leave(el, remove) {
  3630. const key = String(vnode.key);
  3631. if (el._enterCb) {
  3632. el._enterCb(true /* cancelled */);
  3633. }
  3634. if (state.isUnmounting) {
  3635. return remove();
  3636. }
  3637. callHook(onBeforeLeave, [el]);
  3638. let called = false;
  3639. const done = (el._leaveCb = (cancelled) => {
  3640. if (called)
  3641. return;
  3642. called = true;
  3643. remove();
  3644. if (cancelled) {
  3645. callHook(onLeaveCancelled, [el]);
  3646. }
  3647. else {
  3648. callHook(onAfterLeave, [el]);
  3649. }
  3650. el._leaveCb = undefined;
  3651. if (leavingVNodesCache[key] === vnode) {
  3652. delete leavingVNodesCache[key];
  3653. }
  3654. });
  3655. leavingVNodesCache[key] = vnode;
  3656. if (onLeave) {
  3657. onLeave(el, done);
  3658. if (onLeave.length <= 1) {
  3659. done();
  3660. }
  3661. }
  3662. else {
  3663. done();
  3664. }
  3665. },
  3666. clone(vnode) {
  3667. return resolveTransitionHooks(vnode, props, state, instance);
  3668. }
  3669. };
  3670. return hooks;
  3671. }
  3672. // the placeholder really only handles one special case: KeepAlive
  3673. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3674. // placeholder with empty content to avoid the KeepAlive instance from being
  3675. // unmounted.
  3676. function emptyPlaceholder(vnode) {
  3677. if (isKeepAlive(vnode)) {
  3678. vnode = cloneVNode(vnode);
  3679. vnode.children = null;
  3680. return vnode;
  3681. }
  3682. }
  3683. function getKeepAliveChild(vnode) {
  3684. return isKeepAlive(vnode)
  3685. ? vnode.children
  3686. ? vnode.children[0]
  3687. : undefined
  3688. : vnode;
  3689. }
  3690. function setTransitionHooks(vnode, hooks) {
  3691. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3692. setTransitionHooks(vnode.component.subTree, hooks);
  3693. }
  3694. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3695. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3696. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3697. }
  3698. else {
  3699. vnode.transition = hooks;
  3700. }
  3701. }
  3702. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3703. let ret = [];
  3704. let keyedFragmentCount = 0;
  3705. for (let i = 0; i < children.length; i++) {
  3706. let child = children[i];
  3707. // #5360 inherit parent key in case of <template v-for>
  3708. const key = parentKey == null
  3709. ? child.key
  3710. : String(parentKey) + String(child.key != null ? child.key : i);
  3711. // handle fragment children case, e.g. v-for
  3712. if (child.type === Fragment) {
  3713. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  3714. keyedFragmentCount++;
  3715. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3716. }
  3717. // comment placeholders should be skipped, e.g. v-if
  3718. else if (keepComment || child.type !== Comment) {
  3719. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3720. }
  3721. }
  3722. // #1126 if a transition children list contains multiple sub fragments, these
  3723. // fragments will be merged into a flat children array. Since each v-for
  3724. // fragment may contain different static bindings inside, we need to de-op
  3725. // these children to force full diffs to ensure correct behavior.
  3726. if (keyedFragmentCount > 1) {
  3727. for (let i = 0; i < ret.length; i++) {
  3728. ret[i].patchFlag = -2 /* BAIL */;
  3729. }
  3730. }
  3731. return ret;
  3732. }
  3733. // implementation, close to no-op
  3734. function defineComponent(options) {
  3735. return isFunction(options) ? { setup: options, name: options.name } : options;
  3736. }
  3737. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3738. function defineAsyncComponent(source) {
  3739. if (isFunction(source)) {
  3740. source = { loader: source };
  3741. }
  3742. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3743. suspensible = true, onError: userOnError } = source;
  3744. let pendingRequest = null;
  3745. let resolvedComp;
  3746. let retries = 0;
  3747. const retry = () => {
  3748. retries++;
  3749. pendingRequest = null;
  3750. return load();
  3751. };
  3752. const load = () => {
  3753. let thisRequest;
  3754. return (pendingRequest ||
  3755. (thisRequest = pendingRequest =
  3756. loader()
  3757. .catch(err => {
  3758. err = err instanceof Error ? err : new Error(String(err));
  3759. if (userOnError) {
  3760. return new Promise((resolve, reject) => {
  3761. const userRetry = () => resolve(retry());
  3762. const userFail = () => reject(err);
  3763. userOnError(err, userRetry, userFail, retries + 1);
  3764. });
  3765. }
  3766. else {
  3767. throw err;
  3768. }
  3769. })
  3770. .then((comp) => {
  3771. if (thisRequest !== pendingRequest && pendingRequest) {
  3772. return pendingRequest;
  3773. }
  3774. if (!comp) {
  3775. warn$1(`Async component loader resolved to undefined. ` +
  3776. `If you are using retry(), make sure to return its return value.`);
  3777. }
  3778. // interop module default
  3779. if (comp &&
  3780. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3781. comp = comp.default;
  3782. }
  3783. if (comp && !isObject(comp) && !isFunction(comp)) {
  3784. throw new Error(`Invalid async component load result: ${comp}`);
  3785. }
  3786. resolvedComp = comp;
  3787. return comp;
  3788. })));
  3789. };
  3790. return defineComponent({
  3791. name: 'AsyncComponentWrapper',
  3792. __asyncLoader: load,
  3793. get __asyncResolved() {
  3794. return resolvedComp;
  3795. },
  3796. setup() {
  3797. const instance = currentInstance;
  3798. // already resolved
  3799. if (resolvedComp) {
  3800. return () => createInnerComp(resolvedComp, instance);
  3801. }
  3802. const onError = (err) => {
  3803. pendingRequest = null;
  3804. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3805. };
  3806. // suspense-controlled or SSR.
  3807. if ((suspensible && instance.suspense) ||
  3808. (false )) {
  3809. return load()
  3810. .then(comp => {
  3811. return () => createInnerComp(comp, instance);
  3812. })
  3813. .catch(err => {
  3814. onError(err);
  3815. return () => errorComponent
  3816. ? createVNode(errorComponent, {
  3817. error: err
  3818. })
  3819. : null;
  3820. });
  3821. }
  3822. const loaded = ref(false);
  3823. const error = ref();
  3824. const delayed = ref(!!delay);
  3825. if (delay) {
  3826. setTimeout(() => {
  3827. delayed.value = false;
  3828. }, delay);
  3829. }
  3830. if (timeout != null) {
  3831. setTimeout(() => {
  3832. if (!loaded.value && !error.value) {
  3833. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3834. onError(err);
  3835. error.value = err;
  3836. }
  3837. }, timeout);
  3838. }
  3839. load()
  3840. .then(() => {
  3841. loaded.value = true;
  3842. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3843. // parent is keep-alive, force update so the loaded component's
  3844. // name is taken into account
  3845. queueJob(instance.parent.update);
  3846. }
  3847. })
  3848. .catch(err => {
  3849. onError(err);
  3850. error.value = err;
  3851. });
  3852. return () => {
  3853. if (loaded.value && resolvedComp) {
  3854. return createInnerComp(resolvedComp, instance);
  3855. }
  3856. else if (error.value && errorComponent) {
  3857. return createVNode(errorComponent, {
  3858. error: error.value
  3859. });
  3860. }
  3861. else if (loadingComponent && !delayed.value) {
  3862. return createVNode(loadingComponent);
  3863. }
  3864. };
  3865. }
  3866. });
  3867. }
  3868. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  3869. const vnode = createVNode(comp, props, children);
  3870. // ensure inner component inherits the async wrapper's ref owner
  3871. vnode.ref = ref;
  3872. return vnode;
  3873. }
  3874. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3875. const KeepAliveImpl = {
  3876. name: `KeepAlive`,
  3877. // Marker for special handling inside the renderer. We are not using a ===
  3878. // check directly on KeepAlive in the renderer, because importing it directly
  3879. // would prevent it from being tree-shaken.
  3880. __isKeepAlive: true,
  3881. props: {
  3882. include: [String, RegExp, Array],
  3883. exclude: [String, RegExp, Array],
  3884. max: [String, Number]
  3885. },
  3886. setup(props, { slots }) {
  3887. const instance = getCurrentInstance();
  3888. // KeepAlive communicates with the instantiated renderer via the
  3889. // ctx where the renderer passes in its internals,
  3890. // and the KeepAlive instance exposes activate/deactivate implementations.
  3891. // The whole point of this is to avoid importing KeepAlive directly in the
  3892. // renderer to facilitate tree-shaking.
  3893. const sharedContext = instance.ctx;
  3894. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  3895. // for KeepAlive, we just need to render its children
  3896. if (!sharedContext.renderer) {
  3897. return slots.default;
  3898. }
  3899. const cache = new Map();
  3900. const keys = new Set();
  3901. let current = null;
  3902. {
  3903. instance.__v_cache = cache;
  3904. }
  3905. const parentSuspense = instance.suspense;
  3906. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3907. const storageContainer = createElement('div');
  3908. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3909. const instance = vnode.component;
  3910. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3911. // in case props have changed
  3912. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3913. queuePostRenderEffect(() => {
  3914. instance.isDeactivated = false;
  3915. if (instance.a) {
  3916. invokeArrayFns(instance.a);
  3917. }
  3918. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3919. if (vnodeHook) {
  3920. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3921. }
  3922. }, parentSuspense);
  3923. {
  3924. // Update components tree
  3925. devtoolsComponentAdded(instance);
  3926. }
  3927. };
  3928. sharedContext.deactivate = (vnode) => {
  3929. const instance = vnode.component;
  3930. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3931. queuePostRenderEffect(() => {
  3932. if (instance.da) {
  3933. invokeArrayFns(instance.da);
  3934. }
  3935. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3936. if (vnodeHook) {
  3937. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3938. }
  3939. instance.isDeactivated = true;
  3940. }, parentSuspense);
  3941. {
  3942. // Update components tree
  3943. devtoolsComponentAdded(instance);
  3944. }
  3945. };
  3946. function unmount(vnode) {
  3947. // reset the shapeFlag so it can be properly unmounted
  3948. resetShapeFlag(vnode);
  3949. _unmount(vnode, instance, parentSuspense, true);
  3950. }
  3951. function pruneCache(filter) {
  3952. cache.forEach((vnode, key) => {
  3953. const name = getComponentName(vnode.type);
  3954. if (name && (!filter || !filter(name))) {
  3955. pruneCacheEntry(key);
  3956. }
  3957. });
  3958. }
  3959. function pruneCacheEntry(key) {
  3960. const cached = cache.get(key);
  3961. if (!current || cached.type !== current.type) {
  3962. unmount(cached);
  3963. }
  3964. else if (current) {
  3965. // current active instance should no longer be kept-alive.
  3966. // we can't unmount it now but it might be later, so reset its flag now.
  3967. resetShapeFlag(current);
  3968. }
  3969. cache.delete(key);
  3970. keys.delete(key);
  3971. }
  3972. // prune cache on include/exclude prop change
  3973. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3974. include && pruneCache(name => matches(include, name));
  3975. exclude && pruneCache(name => !matches(exclude, name));
  3976. },
  3977. // prune post-render after `current` has been updated
  3978. { flush: 'post', deep: true });
  3979. // cache sub tree after render
  3980. let pendingCacheKey = null;
  3981. const cacheSubtree = () => {
  3982. // fix #1621, the pendingCacheKey could be 0
  3983. if (pendingCacheKey != null) {
  3984. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3985. }
  3986. };
  3987. onMounted(cacheSubtree);
  3988. onUpdated(cacheSubtree);
  3989. onBeforeUnmount(() => {
  3990. cache.forEach(cached => {
  3991. const { subTree, suspense } = instance;
  3992. const vnode = getInnerChild(subTree);
  3993. if (cached.type === vnode.type) {
  3994. // current instance will be unmounted as part of keep-alive's unmount
  3995. resetShapeFlag(vnode);
  3996. // but invoke its deactivated hook here
  3997. const da = vnode.component.da;
  3998. da && queuePostRenderEffect(da, suspense);
  3999. return;
  4000. }
  4001. unmount(cached);
  4002. });
  4003. });
  4004. return () => {
  4005. pendingCacheKey = null;
  4006. if (!slots.default) {
  4007. return null;
  4008. }
  4009. const children = slots.default();
  4010. const rawVNode = children[0];
  4011. if (children.length > 1) {
  4012. {
  4013. warn$1(`KeepAlive should contain exactly one component child.`);
  4014. }
  4015. current = null;
  4016. return children;
  4017. }
  4018. else if (!isVNode(rawVNode) ||
  4019. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  4020. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  4021. current = null;
  4022. return rawVNode;
  4023. }
  4024. let vnode = getInnerChild(rawVNode);
  4025. const comp = vnode.type;
  4026. // for async components, name check should be based in its loaded
  4027. // inner component if available
  4028. const name = getComponentName(isAsyncWrapper(vnode)
  4029. ? vnode.type.__asyncResolved || {}
  4030. : comp);
  4031. const { include, exclude, max } = props;
  4032. if ((include && (!name || !matches(include, name))) ||
  4033. (exclude && name && matches(exclude, name))) {
  4034. current = vnode;
  4035. return rawVNode;
  4036. }
  4037. const key = vnode.key == null ? comp : vnode.key;
  4038. const cachedVNode = cache.get(key);
  4039. // clone vnode if it's reused because we are going to mutate it
  4040. if (vnode.el) {
  4041. vnode = cloneVNode(vnode);
  4042. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  4043. rawVNode.ssContent = vnode;
  4044. }
  4045. }
  4046. // #1513 it's possible for the returned vnode to be cloned due to attr
  4047. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4048. // that is mounted. Instead of caching it directly, we store the pending
  4049. // key and cache `instance.subTree` (the normalized vnode) in
  4050. // beforeMount/beforeUpdate hooks.
  4051. pendingCacheKey = key;
  4052. if (cachedVNode) {
  4053. // copy over mounted state
  4054. vnode.el = cachedVNode.el;
  4055. vnode.component = cachedVNode.component;
  4056. if (vnode.transition) {
  4057. // recursively update transition hooks on subTree
  4058. setTransitionHooks(vnode, vnode.transition);
  4059. }
  4060. // avoid vnode being mounted as fresh
  4061. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  4062. // make this key the freshest
  4063. keys.delete(key);
  4064. keys.add(key);
  4065. }
  4066. else {
  4067. keys.add(key);
  4068. // prune oldest entry
  4069. if (max && keys.size > parseInt(max, 10)) {
  4070. pruneCacheEntry(keys.values().next().value);
  4071. }
  4072. }
  4073. // avoid vnode being unmounted
  4074. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4075. current = vnode;
  4076. return rawVNode;
  4077. };
  4078. }
  4079. };
  4080. // export the public type for h/tsx inference
  4081. // also to avoid inline import() in generated d.ts files
  4082. const KeepAlive = KeepAliveImpl;
  4083. function matches(pattern, name) {
  4084. if (isArray(pattern)) {
  4085. return pattern.some((p) => matches(p, name));
  4086. }
  4087. else if (isString(pattern)) {
  4088. return pattern.split(',').includes(name);
  4089. }
  4090. else if (pattern.test) {
  4091. return pattern.test(name);
  4092. }
  4093. /* istanbul ignore next */
  4094. return false;
  4095. }
  4096. function onActivated(hook, target) {
  4097. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  4098. }
  4099. function onDeactivated(hook, target) {
  4100. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  4101. }
  4102. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4103. // cache the deactivate branch check wrapper for injected hooks so the same
  4104. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4105. // deactivation check".
  4106. const wrappedHook = hook.__wdc ||
  4107. (hook.__wdc = () => {
  4108. // only fire the hook if the target instance is NOT in a deactivated branch.
  4109. let current = target;
  4110. while (current) {
  4111. if (current.isDeactivated) {
  4112. return;
  4113. }
  4114. current = current.parent;
  4115. }
  4116. return hook();
  4117. });
  4118. injectHook(type, wrappedHook, target);
  4119. // In addition to registering it on the target instance, we walk up the parent
  4120. // chain and register it on all ancestor instances that are keep-alive roots.
  4121. // This avoids the need to walk the entire component tree when invoking these
  4122. // hooks, and more importantly, avoids the need to track child components in
  4123. // arrays.
  4124. if (target) {
  4125. let current = target.parent;
  4126. while (current && current.parent) {
  4127. if (isKeepAlive(current.parent.vnode)) {
  4128. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4129. }
  4130. current = current.parent;
  4131. }
  4132. }
  4133. }
  4134. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4135. // injectHook wraps the original for error handling, so make sure to remove
  4136. // the wrapped version.
  4137. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4138. onUnmounted(() => {
  4139. remove(keepAliveRoot[type], injected);
  4140. }, target);
  4141. }
  4142. function resetShapeFlag(vnode) {
  4143. let shapeFlag = vnode.shapeFlag;
  4144. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4145. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4146. }
  4147. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  4148. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  4149. }
  4150. vnode.shapeFlag = shapeFlag;
  4151. }
  4152. function getInnerChild(vnode) {
  4153. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  4154. }
  4155. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4156. if (target) {
  4157. const hooks = target[type] || (target[type] = []);
  4158. // cache the error handling wrapper for injected hooks so the same hook
  4159. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4160. // handling".
  4161. const wrappedHook = hook.__weh ||
  4162. (hook.__weh = (...args) => {
  4163. if (target.isUnmounted) {
  4164. return;
  4165. }
  4166. // disable tracking inside all lifecycle hooks
  4167. // since they can potentially be called inside effects.
  4168. pauseTracking();
  4169. // Set currentInstance during hook invocation.
  4170. // This assumes the hook does not synchronously trigger other hooks, which
  4171. // can only be false when the user does something really funky.
  4172. setCurrentInstance(target);
  4173. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4174. unsetCurrentInstance();
  4175. resetTracking();
  4176. return res;
  4177. });
  4178. if (prepend) {
  4179. hooks.unshift(wrappedHook);
  4180. }
  4181. else {
  4182. hooks.push(wrappedHook);
  4183. }
  4184. return wrappedHook;
  4185. }
  4186. else {
  4187. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4188. warn$1(`${apiName} is called when there is no active component instance to be ` +
  4189. `associated with. ` +
  4190. `Lifecycle injection APIs can only be used during execution of setup().` +
  4191. (` If you are using async setup(), make sure to register lifecycle ` +
  4192. `hooks before the first await statement.`
  4193. ));
  4194. }
  4195. }
  4196. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4197. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4198. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  4199. injectHook(lifecycle, hook, target);
  4200. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  4201. const onMounted = createHook("m" /* MOUNTED */);
  4202. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  4203. const onUpdated = createHook("u" /* UPDATED */);
  4204. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  4205. const onUnmounted = createHook("um" /* UNMOUNTED */);
  4206. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  4207. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  4208. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  4209. function onErrorCaptured(hook, target = currentInstance) {
  4210. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  4211. }
  4212. function createDuplicateChecker() {
  4213. const cache = Object.create(null);
  4214. return (type, key) => {
  4215. if (cache[key]) {
  4216. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4217. }
  4218. else {
  4219. cache[key] = type;
  4220. }
  4221. };
  4222. }
  4223. let shouldCacheAccess = true;
  4224. function applyOptions(instance) {
  4225. const options = resolveMergedOptions(instance);
  4226. const publicThis = instance.proxy;
  4227. const ctx = instance.ctx;
  4228. // do not cache property access on public proxy during state initialization
  4229. shouldCacheAccess = false;
  4230. // call beforeCreate first before accessing other options since
  4231. // the hook may mutate resolved options (#2791)
  4232. if (options.beforeCreate) {
  4233. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  4234. }
  4235. const {
  4236. // state
  4237. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4238. // lifecycle
  4239. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4240. // public API
  4241. expose, inheritAttrs,
  4242. // assets
  4243. components, directives, filters } = options;
  4244. const checkDuplicateProperties = createDuplicateChecker() ;
  4245. {
  4246. const [propsOptions] = instance.propsOptions;
  4247. if (propsOptions) {
  4248. for (const key in propsOptions) {
  4249. checkDuplicateProperties("Props" /* PROPS */, key);
  4250. }
  4251. }
  4252. }
  4253. // options initialization order (to be consistent with Vue 2):
  4254. // - props (already done outside of this function)
  4255. // - inject
  4256. // - methods
  4257. // - data (deferred since it relies on `this` access)
  4258. // - computed
  4259. // - watch (deferred since it relies on `this` access)
  4260. if (injectOptions) {
  4261. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4262. }
  4263. if (methods) {
  4264. for (const key in methods) {
  4265. const methodHandler = methods[key];
  4266. if (isFunction(methodHandler)) {
  4267. // In dev mode, we use the `createRenderContext` function to define
  4268. // methods to the proxy target, and those are read-only but
  4269. // reconfigurable, so it needs to be redefined here
  4270. {
  4271. Object.defineProperty(ctx, key, {
  4272. value: methodHandler.bind(publicThis),
  4273. configurable: true,
  4274. enumerable: true,
  4275. writable: true
  4276. });
  4277. }
  4278. {
  4279. checkDuplicateProperties("Methods" /* METHODS */, key);
  4280. }
  4281. }
  4282. else {
  4283. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4284. `Did you reference the function correctly?`);
  4285. }
  4286. }
  4287. }
  4288. if (dataOptions) {
  4289. if (!isFunction(dataOptions)) {
  4290. warn$1(`The data option must be a function. ` +
  4291. `Plain object usage is no longer supported.`);
  4292. }
  4293. const data = dataOptions.call(publicThis, publicThis);
  4294. if (isPromise(data)) {
  4295. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  4296. `intend to perform data fetching before component renders, use ` +
  4297. `async setup() + <Suspense>.`);
  4298. }
  4299. if (!isObject(data)) {
  4300. warn$1(`data() should return an object.`);
  4301. }
  4302. else {
  4303. instance.data = reactive(data);
  4304. {
  4305. for (const key in data) {
  4306. checkDuplicateProperties("Data" /* DATA */, key);
  4307. // expose data on ctx during dev
  4308. if (key[0] !== '$' && key[0] !== '_') {
  4309. Object.defineProperty(ctx, key, {
  4310. configurable: true,
  4311. enumerable: true,
  4312. get: () => data[key],
  4313. set: NOOP
  4314. });
  4315. }
  4316. }
  4317. }
  4318. }
  4319. }
  4320. // state initialization complete at this point - start caching access
  4321. shouldCacheAccess = true;
  4322. if (computedOptions) {
  4323. for (const key in computedOptions) {
  4324. const opt = computedOptions[key];
  4325. const get = isFunction(opt)
  4326. ? opt.bind(publicThis, publicThis)
  4327. : isFunction(opt.get)
  4328. ? opt.get.bind(publicThis, publicThis)
  4329. : NOOP;
  4330. if (get === NOOP) {
  4331. warn$1(`Computed property "${key}" has no getter.`);
  4332. }
  4333. const set = !isFunction(opt) && isFunction(opt.set)
  4334. ? opt.set.bind(publicThis)
  4335. : () => {
  4336. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  4337. }
  4338. ;
  4339. const c = computed$1({
  4340. get,
  4341. set
  4342. });
  4343. Object.defineProperty(ctx, key, {
  4344. enumerable: true,
  4345. configurable: true,
  4346. get: () => c.value,
  4347. set: v => (c.value = v)
  4348. });
  4349. {
  4350. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  4351. }
  4352. }
  4353. }
  4354. if (watchOptions) {
  4355. for (const key in watchOptions) {
  4356. createWatcher(watchOptions[key], ctx, publicThis, key);
  4357. }
  4358. }
  4359. if (provideOptions) {
  4360. const provides = isFunction(provideOptions)
  4361. ? provideOptions.call(publicThis)
  4362. : provideOptions;
  4363. Reflect.ownKeys(provides).forEach(key => {
  4364. provide(key, provides[key]);
  4365. });
  4366. }
  4367. if (created) {
  4368. callHook(created, instance, "c" /* CREATED */);
  4369. }
  4370. function registerLifecycleHook(register, hook) {
  4371. if (isArray(hook)) {
  4372. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4373. }
  4374. else if (hook) {
  4375. register(hook.bind(publicThis));
  4376. }
  4377. }
  4378. registerLifecycleHook(onBeforeMount, beforeMount);
  4379. registerLifecycleHook(onMounted, mounted);
  4380. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4381. registerLifecycleHook(onUpdated, updated);
  4382. registerLifecycleHook(onActivated, activated);
  4383. registerLifecycleHook(onDeactivated, deactivated);
  4384. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4385. registerLifecycleHook(onRenderTracked, renderTracked);
  4386. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4387. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4388. registerLifecycleHook(onUnmounted, unmounted);
  4389. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4390. if (isArray(expose)) {
  4391. if (expose.length) {
  4392. const exposed = instance.exposed || (instance.exposed = {});
  4393. expose.forEach(key => {
  4394. Object.defineProperty(exposed, key, {
  4395. get: () => publicThis[key],
  4396. set: val => (publicThis[key] = val)
  4397. });
  4398. });
  4399. }
  4400. else if (!instance.exposed) {
  4401. instance.exposed = {};
  4402. }
  4403. }
  4404. // options that are handled when creating the instance but also need to be
  4405. // applied from mixins
  4406. if (render && instance.render === NOOP) {
  4407. instance.render = render;
  4408. }
  4409. if (inheritAttrs != null) {
  4410. instance.inheritAttrs = inheritAttrs;
  4411. }
  4412. // asset options.
  4413. if (components)
  4414. instance.components = components;
  4415. if (directives)
  4416. instance.directives = directives;
  4417. }
  4418. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  4419. if (isArray(injectOptions)) {
  4420. injectOptions = normalizeInject(injectOptions);
  4421. }
  4422. for (const key in injectOptions) {
  4423. const opt = injectOptions[key];
  4424. let injected;
  4425. if (isObject(opt)) {
  4426. if ('default' in opt) {
  4427. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4428. }
  4429. else {
  4430. injected = inject(opt.from || key);
  4431. }
  4432. }
  4433. else {
  4434. injected = inject(opt);
  4435. }
  4436. if (isRef(injected)) {
  4437. // TODO remove the check in 3.3
  4438. if (unwrapRef) {
  4439. Object.defineProperty(ctx, key, {
  4440. enumerable: true,
  4441. configurable: true,
  4442. get: () => injected.value,
  4443. set: v => (injected.value = v)
  4444. });
  4445. }
  4446. else {
  4447. {
  4448. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  4449. `and no longer needs \`.value\` in the next minor release. ` +
  4450. `To opt-in to the new behavior now, ` +
  4451. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  4452. `temporary and will not be needed in the future.)`);
  4453. }
  4454. ctx[key] = injected;
  4455. }
  4456. }
  4457. else {
  4458. ctx[key] = injected;
  4459. }
  4460. {
  4461. checkDuplicateProperties("Inject" /* INJECT */, key);
  4462. }
  4463. }
  4464. }
  4465. function callHook(hook, instance, type) {
  4466. callWithAsyncErrorHandling(isArray(hook)
  4467. ? hook.map(h => h.bind(instance.proxy))
  4468. : hook.bind(instance.proxy), instance, type);
  4469. }
  4470. function createWatcher(raw, ctx, publicThis, key) {
  4471. const getter = key.includes('.')
  4472. ? createPathGetter(publicThis, key)
  4473. : () => publicThis[key];
  4474. if (isString(raw)) {
  4475. const handler = ctx[raw];
  4476. if (isFunction(handler)) {
  4477. watch(getter, handler);
  4478. }
  4479. else {
  4480. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  4481. }
  4482. }
  4483. else if (isFunction(raw)) {
  4484. watch(getter, raw.bind(publicThis));
  4485. }
  4486. else if (isObject(raw)) {
  4487. if (isArray(raw)) {
  4488. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  4489. }
  4490. else {
  4491. const handler = isFunction(raw.handler)
  4492. ? raw.handler.bind(publicThis)
  4493. : ctx[raw.handler];
  4494. if (isFunction(handler)) {
  4495. watch(getter, handler, raw);
  4496. }
  4497. else {
  4498. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  4499. }
  4500. }
  4501. }
  4502. else {
  4503. warn$1(`Invalid watch option: "${key}"`, raw);
  4504. }
  4505. }
  4506. /**
  4507. * Resolve merged options and cache it on the component.
  4508. * This is done only once per-component since the merging does not involve
  4509. * instances.
  4510. */
  4511. function resolveMergedOptions(instance) {
  4512. const base = instance.type;
  4513. const { mixins, extends: extendsOptions } = base;
  4514. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  4515. const cached = cache.get(base);
  4516. let resolved;
  4517. if (cached) {
  4518. resolved = cached;
  4519. }
  4520. else if (!globalMixins.length && !mixins && !extendsOptions) {
  4521. {
  4522. resolved = base;
  4523. }
  4524. }
  4525. else {
  4526. resolved = {};
  4527. if (globalMixins.length) {
  4528. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  4529. }
  4530. mergeOptions(resolved, base, optionMergeStrategies);
  4531. }
  4532. cache.set(base, resolved);
  4533. return resolved;
  4534. }
  4535. function mergeOptions(to, from, strats, asMixin = false) {
  4536. const { mixins, extends: extendsOptions } = from;
  4537. if (extendsOptions) {
  4538. mergeOptions(to, extendsOptions, strats, true);
  4539. }
  4540. if (mixins) {
  4541. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  4542. }
  4543. for (const key in from) {
  4544. if (asMixin && key === 'expose') {
  4545. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  4546. `It should only be declared in the base component itself.`);
  4547. }
  4548. else {
  4549. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  4550. to[key] = strat ? strat(to[key], from[key]) : from[key];
  4551. }
  4552. }
  4553. return to;
  4554. }
  4555. const internalOptionMergeStrats = {
  4556. data: mergeDataFn,
  4557. props: mergeObjectOptions,
  4558. emits: mergeObjectOptions,
  4559. // objects
  4560. methods: mergeObjectOptions,
  4561. computed: mergeObjectOptions,
  4562. // lifecycle
  4563. beforeCreate: mergeAsArray,
  4564. created: mergeAsArray,
  4565. beforeMount: mergeAsArray,
  4566. mounted: mergeAsArray,
  4567. beforeUpdate: mergeAsArray,
  4568. updated: mergeAsArray,
  4569. beforeDestroy: mergeAsArray,
  4570. beforeUnmount: mergeAsArray,
  4571. destroyed: mergeAsArray,
  4572. unmounted: mergeAsArray,
  4573. activated: mergeAsArray,
  4574. deactivated: mergeAsArray,
  4575. errorCaptured: mergeAsArray,
  4576. serverPrefetch: mergeAsArray,
  4577. // assets
  4578. components: mergeObjectOptions,
  4579. directives: mergeObjectOptions,
  4580. // watch
  4581. watch: mergeWatchOptions,
  4582. // provide / inject
  4583. provide: mergeDataFn,
  4584. inject: mergeInject
  4585. };
  4586. function mergeDataFn(to, from) {
  4587. if (!from) {
  4588. return to;
  4589. }
  4590. if (!to) {
  4591. return from;
  4592. }
  4593. return function mergedDataFn() {
  4594. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  4595. };
  4596. }
  4597. function mergeInject(to, from) {
  4598. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  4599. }
  4600. function normalizeInject(raw) {
  4601. if (isArray(raw)) {
  4602. const res = {};
  4603. for (let i = 0; i < raw.length; i++) {
  4604. res[raw[i]] = raw[i];
  4605. }
  4606. return res;
  4607. }
  4608. return raw;
  4609. }
  4610. function mergeAsArray(to, from) {
  4611. return to ? [...new Set([].concat(to, from))] : from;
  4612. }
  4613. function mergeObjectOptions(to, from) {
  4614. return to ? extend(extend(Object.create(null), to), from) : from;
  4615. }
  4616. function mergeWatchOptions(to, from) {
  4617. if (!to)
  4618. return from;
  4619. if (!from)
  4620. return to;
  4621. const merged = extend(Object.create(null), to);
  4622. for (const key in from) {
  4623. merged[key] = mergeAsArray(to[key], from[key]);
  4624. }
  4625. return merged;
  4626. }
  4627. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  4628. isSSR = false) {
  4629. const props = {};
  4630. const attrs = {};
  4631. def(attrs, InternalObjectKey, 1);
  4632. instance.propsDefaults = Object.create(null);
  4633. setFullProps(instance, rawProps, props, attrs);
  4634. // ensure all declared prop keys are present
  4635. for (const key in instance.propsOptions[0]) {
  4636. if (!(key in props)) {
  4637. props[key] = undefined;
  4638. }
  4639. }
  4640. // validation
  4641. {
  4642. validateProps(rawProps || {}, props, instance);
  4643. }
  4644. if (isStateful) {
  4645. // stateful
  4646. instance.props = isSSR ? props : shallowReactive(props);
  4647. }
  4648. else {
  4649. if (!instance.type.props) {
  4650. // functional w/ optional props, props === attrs
  4651. instance.props = attrs;
  4652. }
  4653. else {
  4654. // functional w/ declared props
  4655. instance.props = props;
  4656. }
  4657. }
  4658. instance.attrs = attrs;
  4659. }
  4660. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  4661. const { props, attrs, vnode: { patchFlag } } = instance;
  4662. const rawCurrentProps = toRaw(props);
  4663. const [options] = instance.propsOptions;
  4664. let hasAttrsChanged = false;
  4665. if (
  4666. // always force full diff in dev
  4667. // - #1942 if hmr is enabled with sfc component
  4668. // - vite#872 non-sfc component used by sfc component
  4669. !((instance.type.__hmrId ||
  4670. (instance.parent && instance.parent.type.__hmrId))) &&
  4671. (optimized || patchFlag > 0) &&
  4672. !(patchFlag & 16 /* FULL_PROPS */)) {
  4673. if (patchFlag & 8 /* PROPS */) {
  4674. // Compiler-generated props & no keys change, just set the updated
  4675. // the props.
  4676. const propsToUpdate = instance.vnode.dynamicProps;
  4677. for (let i = 0; i < propsToUpdate.length; i++) {
  4678. let key = propsToUpdate[i];
  4679. // skip if the prop key is a declared emit event listener
  4680. if (isEmitListener(instance.emitsOptions, key)) {
  4681. continue;
  4682. }
  4683. // PROPS flag guarantees rawProps to be non-null
  4684. const value = rawProps[key];
  4685. if (options) {
  4686. // attr / props separation was done on init and will be consistent
  4687. // in this code path, so just check if attrs have it.
  4688. if (hasOwn(attrs, key)) {
  4689. if (value !== attrs[key]) {
  4690. attrs[key] = value;
  4691. hasAttrsChanged = true;
  4692. }
  4693. }
  4694. else {
  4695. const camelizedKey = camelize(key);
  4696. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  4697. }
  4698. }
  4699. else {
  4700. if (value !== attrs[key]) {
  4701. attrs[key] = value;
  4702. hasAttrsChanged = true;
  4703. }
  4704. }
  4705. }
  4706. }
  4707. }
  4708. else {
  4709. // full props update.
  4710. if (setFullProps(instance, rawProps, props, attrs)) {
  4711. hasAttrsChanged = true;
  4712. }
  4713. // in case of dynamic props, check if we need to delete keys from
  4714. // the props object
  4715. let kebabKey;
  4716. for (const key in rawCurrentProps) {
  4717. if (!rawProps ||
  4718. // for camelCase
  4719. (!hasOwn(rawProps, key) &&
  4720. // it's possible the original props was passed in as kebab-case
  4721. // and converted to camelCase (#955)
  4722. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  4723. if (options) {
  4724. if (rawPrevProps &&
  4725. // for camelCase
  4726. (rawPrevProps[key] !== undefined ||
  4727. // for kebab-case
  4728. rawPrevProps[kebabKey] !== undefined)) {
  4729. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  4730. }
  4731. }
  4732. else {
  4733. delete props[key];
  4734. }
  4735. }
  4736. }
  4737. // in the case of functional component w/o props declaration, props and
  4738. // attrs point to the same object so it should already have been updated.
  4739. if (attrs !== rawCurrentProps) {
  4740. for (const key in attrs) {
  4741. if (!rawProps ||
  4742. (!hasOwn(rawProps, key) &&
  4743. (!false ))) {
  4744. delete attrs[key];
  4745. hasAttrsChanged = true;
  4746. }
  4747. }
  4748. }
  4749. }
  4750. // trigger updates for $attrs in case it's used in component slots
  4751. if (hasAttrsChanged) {
  4752. trigger(instance, "set" /* SET */, '$attrs');
  4753. }
  4754. {
  4755. validateProps(rawProps || {}, props, instance);
  4756. }
  4757. }
  4758. function setFullProps(instance, rawProps, props, attrs) {
  4759. const [options, needCastKeys] = instance.propsOptions;
  4760. let hasAttrsChanged = false;
  4761. let rawCastValues;
  4762. if (rawProps) {
  4763. for (let key in rawProps) {
  4764. // key, ref are reserved and never passed down
  4765. if (isReservedProp(key)) {
  4766. continue;
  4767. }
  4768. const value = rawProps[key];
  4769. // prop option names are camelized during normalization, so to support
  4770. // kebab -> camel conversion here we need to camelize the key.
  4771. let camelKey;
  4772. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  4773. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  4774. props[camelKey] = value;
  4775. }
  4776. else {
  4777. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  4778. }
  4779. }
  4780. else if (!isEmitListener(instance.emitsOptions, key)) {
  4781. if (!(key in attrs) || value !== attrs[key]) {
  4782. attrs[key] = value;
  4783. hasAttrsChanged = true;
  4784. }
  4785. }
  4786. }
  4787. }
  4788. if (needCastKeys) {
  4789. const rawCurrentProps = toRaw(props);
  4790. const castValues = rawCastValues || EMPTY_OBJ;
  4791. for (let i = 0; i < needCastKeys.length; i++) {
  4792. const key = needCastKeys[i];
  4793. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  4794. }
  4795. }
  4796. return hasAttrsChanged;
  4797. }
  4798. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  4799. const opt = options[key];
  4800. if (opt != null) {
  4801. const hasDefault = hasOwn(opt, 'default');
  4802. // default values
  4803. if (hasDefault && value === undefined) {
  4804. const defaultValue = opt.default;
  4805. if (opt.type !== Function && isFunction(defaultValue)) {
  4806. const { propsDefaults } = instance;
  4807. if (key in propsDefaults) {
  4808. value = propsDefaults[key];
  4809. }
  4810. else {
  4811. setCurrentInstance(instance);
  4812. value = propsDefaults[key] = defaultValue.call(null, props);
  4813. unsetCurrentInstance();
  4814. }
  4815. }
  4816. else {
  4817. value = defaultValue;
  4818. }
  4819. }
  4820. // boolean casting
  4821. if (opt[0 /* shouldCast */]) {
  4822. if (isAbsent && !hasDefault) {
  4823. value = false;
  4824. }
  4825. else if (opt[1 /* shouldCastTrue */] &&
  4826. (value === '' || value === hyphenate(key))) {
  4827. value = true;
  4828. }
  4829. }
  4830. }
  4831. return value;
  4832. }
  4833. function normalizePropsOptions(comp, appContext, asMixin = false) {
  4834. const cache = appContext.propsCache;
  4835. const cached = cache.get(comp);
  4836. if (cached) {
  4837. return cached;
  4838. }
  4839. const raw = comp.props;
  4840. const normalized = {};
  4841. const needCastKeys = [];
  4842. // apply mixin/extends props
  4843. let hasExtends = false;
  4844. if (!isFunction(comp)) {
  4845. const extendProps = (raw) => {
  4846. hasExtends = true;
  4847. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  4848. extend(normalized, props);
  4849. if (keys)
  4850. needCastKeys.push(...keys);
  4851. };
  4852. if (!asMixin && appContext.mixins.length) {
  4853. appContext.mixins.forEach(extendProps);
  4854. }
  4855. if (comp.extends) {
  4856. extendProps(comp.extends);
  4857. }
  4858. if (comp.mixins) {
  4859. comp.mixins.forEach(extendProps);
  4860. }
  4861. }
  4862. if (!raw && !hasExtends) {
  4863. cache.set(comp, EMPTY_ARR);
  4864. return EMPTY_ARR;
  4865. }
  4866. if (isArray(raw)) {
  4867. for (let i = 0; i < raw.length; i++) {
  4868. if (!isString(raw[i])) {
  4869. warn$1(`props must be strings when using array syntax.`, raw[i]);
  4870. }
  4871. const normalizedKey = camelize(raw[i]);
  4872. if (validatePropName(normalizedKey)) {
  4873. normalized[normalizedKey] = EMPTY_OBJ;
  4874. }
  4875. }
  4876. }
  4877. else if (raw) {
  4878. if (!isObject(raw)) {
  4879. warn$1(`invalid props options`, raw);
  4880. }
  4881. for (const key in raw) {
  4882. const normalizedKey = camelize(key);
  4883. if (validatePropName(normalizedKey)) {
  4884. const opt = raw[key];
  4885. const prop = (normalized[normalizedKey] =
  4886. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  4887. if (prop) {
  4888. const booleanIndex = getTypeIndex(Boolean, prop.type);
  4889. const stringIndex = getTypeIndex(String, prop.type);
  4890. prop[0 /* shouldCast */] = booleanIndex > -1;
  4891. prop[1 /* shouldCastTrue */] =
  4892. stringIndex < 0 || booleanIndex < stringIndex;
  4893. // if the prop needs boolean casting or default value
  4894. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  4895. needCastKeys.push(normalizedKey);
  4896. }
  4897. }
  4898. }
  4899. }
  4900. }
  4901. const res = [normalized, needCastKeys];
  4902. cache.set(comp, res);
  4903. return res;
  4904. }
  4905. function validatePropName(key) {
  4906. if (key[0] !== '$') {
  4907. return true;
  4908. }
  4909. else {
  4910. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  4911. }
  4912. return false;
  4913. }
  4914. // use function string name to check type constructors
  4915. // so that it works across vms / iframes.
  4916. function getType(ctor) {
  4917. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  4918. return match ? match[1] : ctor === null ? 'null' : '';
  4919. }
  4920. function isSameType(a, b) {
  4921. return getType(a) === getType(b);
  4922. }
  4923. function getTypeIndex(type, expectedTypes) {
  4924. if (isArray(expectedTypes)) {
  4925. return expectedTypes.findIndex(t => isSameType(t, type));
  4926. }
  4927. else if (isFunction(expectedTypes)) {
  4928. return isSameType(expectedTypes, type) ? 0 : -1;
  4929. }
  4930. return -1;
  4931. }
  4932. /**
  4933. * dev only
  4934. */
  4935. function validateProps(rawProps, props, instance) {
  4936. const resolvedValues = toRaw(props);
  4937. const options = instance.propsOptions[0];
  4938. for (const key in options) {
  4939. let opt = options[key];
  4940. if (opt == null)
  4941. continue;
  4942. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  4943. }
  4944. }
  4945. /**
  4946. * dev only
  4947. */
  4948. function validateProp(name, value, prop, isAbsent) {
  4949. const { type, required, validator } = prop;
  4950. // required!
  4951. if (required && isAbsent) {
  4952. warn$1('Missing required prop: "' + name + '"');
  4953. return;
  4954. }
  4955. // missing but optional
  4956. if (value == null && !prop.required) {
  4957. return;
  4958. }
  4959. // type check
  4960. if (type != null && type !== true) {
  4961. let isValid = false;
  4962. const types = isArray(type) ? type : [type];
  4963. const expectedTypes = [];
  4964. // value is valid as long as one of the specified types match
  4965. for (let i = 0; i < types.length && !isValid; i++) {
  4966. const { valid, expectedType } = assertType(value, types[i]);
  4967. expectedTypes.push(expectedType || '');
  4968. isValid = valid;
  4969. }
  4970. if (!isValid) {
  4971. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  4972. return;
  4973. }
  4974. }
  4975. // custom validator
  4976. if (validator && !validator(value)) {
  4977. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  4978. }
  4979. }
  4980. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  4981. /**
  4982. * dev only
  4983. */
  4984. function assertType(value, type) {
  4985. let valid;
  4986. const expectedType = getType(type);
  4987. if (isSimpleType(expectedType)) {
  4988. const t = typeof value;
  4989. valid = t === expectedType.toLowerCase();
  4990. // for primitive wrapper objects
  4991. if (!valid && t === 'object') {
  4992. valid = value instanceof type;
  4993. }
  4994. }
  4995. else if (expectedType === 'Object') {
  4996. valid = isObject(value);
  4997. }
  4998. else if (expectedType === 'Array') {
  4999. valid = isArray(value);
  5000. }
  5001. else if (expectedType === 'null') {
  5002. valid = value === null;
  5003. }
  5004. else {
  5005. valid = value instanceof type;
  5006. }
  5007. return {
  5008. valid,
  5009. expectedType
  5010. };
  5011. }
  5012. /**
  5013. * dev only
  5014. */
  5015. function getInvalidTypeMessage(name, value, expectedTypes) {
  5016. let message = `Invalid prop: type check failed for prop "${name}".` +
  5017. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  5018. const expectedType = expectedTypes[0];
  5019. const receivedType = toRawType(value);
  5020. const expectedValue = styleValue(value, expectedType);
  5021. const receivedValue = styleValue(value, receivedType);
  5022. // check if we need to specify expected value
  5023. if (expectedTypes.length === 1 &&
  5024. isExplicable(expectedType) &&
  5025. !isBoolean(expectedType, receivedType)) {
  5026. message += ` with value ${expectedValue}`;
  5027. }
  5028. message += `, got ${receivedType} `;
  5029. // check if we need to specify received value
  5030. if (isExplicable(receivedType)) {
  5031. message += `with value ${receivedValue}.`;
  5032. }
  5033. return message;
  5034. }
  5035. /**
  5036. * dev only
  5037. */
  5038. function styleValue(value, type) {
  5039. if (type === 'String') {
  5040. return `"${value}"`;
  5041. }
  5042. else if (type === 'Number') {
  5043. return `${Number(value)}`;
  5044. }
  5045. else {
  5046. return `${value}`;
  5047. }
  5048. }
  5049. /**
  5050. * dev only
  5051. */
  5052. function isExplicable(type) {
  5053. const explicitTypes = ['string', 'number', 'boolean'];
  5054. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5055. }
  5056. /**
  5057. * dev only
  5058. */
  5059. function isBoolean(...args) {
  5060. return args.some(elem => elem.toLowerCase() === 'boolean');
  5061. }
  5062. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5063. const normalizeSlotValue = (value) => isArray(value)
  5064. ? value.map(normalizeVNode)
  5065. : [normalizeVNode(value)];
  5066. const normalizeSlot = (key, rawSlot, ctx) => {
  5067. const normalized = withCtx((...args) => {
  5068. if (currentInstance) {
  5069. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  5070. `this will not track dependencies used in the slot. ` +
  5071. `Invoke the slot function inside the render function instead.`);
  5072. }
  5073. return normalizeSlotValue(rawSlot(...args));
  5074. }, ctx);
  5075. normalized._c = false;
  5076. return normalized;
  5077. };
  5078. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5079. const ctx = rawSlots._ctx;
  5080. for (const key in rawSlots) {
  5081. if (isInternalKey(key))
  5082. continue;
  5083. const value = rawSlots[key];
  5084. if (isFunction(value)) {
  5085. slots[key] = normalizeSlot(key, value, ctx);
  5086. }
  5087. else if (value != null) {
  5088. {
  5089. warn$1(`Non-function value encountered for slot "${key}". ` +
  5090. `Prefer function slots for better performance.`);
  5091. }
  5092. const normalized = normalizeSlotValue(value);
  5093. slots[key] = () => normalized;
  5094. }
  5095. }
  5096. };
  5097. const normalizeVNodeSlots = (instance, children) => {
  5098. if (!isKeepAlive(instance.vnode) &&
  5099. !(false )) {
  5100. warn$1(`Non-function value encountered for default slot. ` +
  5101. `Prefer function slots for better performance.`);
  5102. }
  5103. const normalized = normalizeSlotValue(children);
  5104. instance.slots.default = () => normalized;
  5105. };
  5106. const initSlots = (instance, children) => {
  5107. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5108. const type = children._;
  5109. if (type) {
  5110. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5111. // we should avoid the proxy object polluting the slots of the internal instance
  5112. instance.slots = toRaw(children);
  5113. // make compiler marker non-enumerable
  5114. def(children, '_', type);
  5115. }
  5116. else {
  5117. normalizeObjectSlots(children, (instance.slots = {}));
  5118. }
  5119. }
  5120. else {
  5121. instance.slots = {};
  5122. if (children) {
  5123. normalizeVNodeSlots(instance, children);
  5124. }
  5125. }
  5126. def(instance.slots, InternalObjectKey, 1);
  5127. };
  5128. const updateSlots = (instance, children, optimized) => {
  5129. const { vnode, slots } = instance;
  5130. let needDeletionCheck = true;
  5131. let deletionComparisonTarget = EMPTY_OBJ;
  5132. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5133. const type = children._;
  5134. if (type) {
  5135. // compiled slots.
  5136. if (isHmrUpdating) {
  5137. // Parent was HMR updated so slot content may have changed.
  5138. // force update slots and mark instance for hmr as well
  5139. extend(slots, children);
  5140. }
  5141. else if (optimized && type === 1 /* STABLE */) {
  5142. // compiled AND stable.
  5143. // no need to update, and skip stale slots removal.
  5144. needDeletionCheck = false;
  5145. }
  5146. else {
  5147. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5148. // normalization.
  5149. extend(slots, children);
  5150. // #2893
  5151. // when rendering the optimized slots by manually written render function,
  5152. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5153. // i.e. let the `renderSlot` create the bailed Fragment
  5154. if (!optimized && type === 1 /* STABLE */) {
  5155. delete slots._;
  5156. }
  5157. }
  5158. }
  5159. else {
  5160. needDeletionCheck = !children.$stable;
  5161. normalizeObjectSlots(children, slots);
  5162. }
  5163. deletionComparisonTarget = children;
  5164. }
  5165. else if (children) {
  5166. // non slot object children (direct value) passed to a component
  5167. normalizeVNodeSlots(instance, children);
  5168. deletionComparisonTarget = { default: 1 };
  5169. }
  5170. // delete stale slots
  5171. if (needDeletionCheck) {
  5172. for (const key in slots) {
  5173. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5174. delete slots[key];
  5175. }
  5176. }
  5177. }
  5178. };
  5179. /**
  5180. Runtime helper for applying directives to a vnode. Example usage:
  5181. const comp = resolveComponent('comp')
  5182. const foo = resolveDirective('foo')
  5183. const bar = resolveDirective('bar')
  5184. return withDirectives(h(comp), [
  5185. [foo, this.x],
  5186. [bar, this.y]
  5187. ])
  5188. */
  5189. function validateDirectiveName(name) {
  5190. if (isBuiltInDirective(name)) {
  5191. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  5192. }
  5193. }
  5194. /**
  5195. * Adds directives to a VNode.
  5196. */
  5197. function withDirectives(vnode, directives) {
  5198. const internalInstance = currentRenderingInstance;
  5199. if (internalInstance === null) {
  5200. warn$1(`withDirectives can only be used inside render functions.`);
  5201. return vnode;
  5202. }
  5203. const instance = getExposeProxy(internalInstance) ||
  5204. internalInstance.proxy;
  5205. const bindings = vnode.dirs || (vnode.dirs = []);
  5206. for (let i = 0; i < directives.length; i++) {
  5207. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  5208. if (isFunction(dir)) {
  5209. dir = {
  5210. mounted: dir,
  5211. updated: dir
  5212. };
  5213. }
  5214. if (dir.deep) {
  5215. traverse(value);
  5216. }
  5217. bindings.push({
  5218. dir,
  5219. instance,
  5220. value,
  5221. oldValue: void 0,
  5222. arg,
  5223. modifiers
  5224. });
  5225. }
  5226. return vnode;
  5227. }
  5228. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  5229. const bindings = vnode.dirs;
  5230. const oldBindings = prevVNode && prevVNode.dirs;
  5231. for (let i = 0; i < bindings.length; i++) {
  5232. const binding = bindings[i];
  5233. if (oldBindings) {
  5234. binding.oldValue = oldBindings[i].value;
  5235. }
  5236. let hook = binding.dir[name];
  5237. if (hook) {
  5238. // disable tracking inside all lifecycle hooks
  5239. // since they can potentially be called inside effects.
  5240. pauseTracking();
  5241. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  5242. vnode.el,
  5243. binding,
  5244. vnode,
  5245. prevVNode
  5246. ]);
  5247. resetTracking();
  5248. }
  5249. }
  5250. }
  5251. function createAppContext() {
  5252. return {
  5253. app: null,
  5254. config: {
  5255. isNativeTag: NO,
  5256. performance: false,
  5257. globalProperties: {},
  5258. optionMergeStrategies: {},
  5259. errorHandler: undefined,
  5260. warnHandler: undefined,
  5261. compilerOptions: {}
  5262. },
  5263. mixins: [],
  5264. components: {},
  5265. directives: {},
  5266. provides: Object.create(null),
  5267. optionsCache: new WeakMap(),
  5268. propsCache: new WeakMap(),
  5269. emitsCache: new WeakMap()
  5270. };
  5271. }
  5272. let uid = 0;
  5273. function createAppAPI(render, hydrate) {
  5274. return function createApp(rootComponent, rootProps = null) {
  5275. if (!isFunction(rootComponent)) {
  5276. rootComponent = Object.assign({}, rootComponent);
  5277. }
  5278. if (rootProps != null && !isObject(rootProps)) {
  5279. warn$1(`root props passed to app.mount() must be an object.`);
  5280. rootProps = null;
  5281. }
  5282. const context = createAppContext();
  5283. const installedPlugins = new Set();
  5284. let isMounted = false;
  5285. const app = (context.app = {
  5286. _uid: uid++,
  5287. _component: rootComponent,
  5288. _props: rootProps,
  5289. _container: null,
  5290. _context: context,
  5291. _instance: null,
  5292. version,
  5293. get config() {
  5294. return context.config;
  5295. },
  5296. set config(v) {
  5297. {
  5298. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  5299. }
  5300. },
  5301. use(plugin, ...options) {
  5302. if (installedPlugins.has(plugin)) {
  5303. warn$1(`Plugin has already been applied to target app.`);
  5304. }
  5305. else if (plugin && isFunction(plugin.install)) {
  5306. installedPlugins.add(plugin);
  5307. plugin.install(app, ...options);
  5308. }
  5309. else if (isFunction(plugin)) {
  5310. installedPlugins.add(plugin);
  5311. plugin(app, ...options);
  5312. }
  5313. else {
  5314. warn$1(`A plugin must either be a function or an object with an "install" ` +
  5315. `function.`);
  5316. }
  5317. return app;
  5318. },
  5319. mixin(mixin) {
  5320. {
  5321. if (!context.mixins.includes(mixin)) {
  5322. context.mixins.push(mixin);
  5323. }
  5324. else {
  5325. warn$1('Mixin has already been applied to target app' +
  5326. (mixin.name ? `: ${mixin.name}` : ''));
  5327. }
  5328. }
  5329. return app;
  5330. },
  5331. component(name, component) {
  5332. {
  5333. validateComponentName(name, context.config);
  5334. }
  5335. if (!component) {
  5336. return context.components[name];
  5337. }
  5338. if (context.components[name]) {
  5339. warn$1(`Component "${name}" has already been registered in target app.`);
  5340. }
  5341. context.components[name] = component;
  5342. return app;
  5343. },
  5344. directive(name, directive) {
  5345. {
  5346. validateDirectiveName(name);
  5347. }
  5348. if (!directive) {
  5349. return context.directives[name];
  5350. }
  5351. if (context.directives[name]) {
  5352. warn$1(`Directive "${name}" has already been registered in target app.`);
  5353. }
  5354. context.directives[name] = directive;
  5355. return app;
  5356. },
  5357. mount(rootContainer, isHydrate, isSVG) {
  5358. if (!isMounted) {
  5359. const vnode = createVNode(rootComponent, rootProps);
  5360. // store app context on the root VNode.
  5361. // this will be set on the root instance on initial mount.
  5362. vnode.appContext = context;
  5363. // HMR root reload
  5364. {
  5365. context.reload = () => {
  5366. render(cloneVNode(vnode), rootContainer, isSVG);
  5367. };
  5368. }
  5369. if (isHydrate && hydrate) {
  5370. hydrate(vnode, rootContainer);
  5371. }
  5372. else {
  5373. render(vnode, rootContainer, isSVG);
  5374. }
  5375. isMounted = true;
  5376. app._container = rootContainer;
  5377. rootContainer.__vue_app__ = app;
  5378. {
  5379. app._instance = vnode.component;
  5380. devtoolsInitApp(app, version);
  5381. }
  5382. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5383. }
  5384. else {
  5385. warn$1(`App has already been mounted.\n` +
  5386. `If you want to remount the same app, move your app creation logic ` +
  5387. `into a factory function and create fresh app instances for each ` +
  5388. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5389. }
  5390. },
  5391. unmount() {
  5392. if (isMounted) {
  5393. render(null, app._container);
  5394. {
  5395. app._instance = null;
  5396. devtoolsUnmountApp(app);
  5397. }
  5398. delete app._container.__vue_app__;
  5399. }
  5400. else {
  5401. warn$1(`Cannot unmount an app that is not mounted.`);
  5402. }
  5403. },
  5404. provide(key, value) {
  5405. if (key in context.provides) {
  5406. warn$1(`App already provides property with key "${String(key)}". ` +
  5407. `It will be overwritten with the new value.`);
  5408. }
  5409. // TypeScript doesn't allow symbols as index type
  5410. // https://github.com/Microsoft/TypeScript/issues/24587
  5411. context.provides[key] = value;
  5412. return app;
  5413. }
  5414. });
  5415. return app;
  5416. };
  5417. }
  5418. /**
  5419. * Function for handling a template ref
  5420. */
  5421. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5422. if (isArray(rawRef)) {
  5423. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5424. return;
  5425. }
  5426. if (isAsyncWrapper(vnode) && !isUnmount) {
  5427. // when mounting async components, nothing needs to be done,
  5428. // because the template ref is forwarded to inner component
  5429. return;
  5430. }
  5431. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  5432. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5433. : vnode.el;
  5434. const value = isUnmount ? null : refValue;
  5435. const { i: owner, r: ref } = rawRef;
  5436. if (!owner) {
  5437. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5438. `A vnode with ref must be created inside the render function.`);
  5439. return;
  5440. }
  5441. const oldRef = oldRawRef && oldRawRef.r;
  5442. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5443. const setupState = owner.setupState;
  5444. // dynamic ref changed. unset old ref
  5445. if (oldRef != null && oldRef !== ref) {
  5446. if (isString(oldRef)) {
  5447. refs[oldRef] = null;
  5448. if (hasOwn(setupState, oldRef)) {
  5449. setupState[oldRef] = null;
  5450. }
  5451. }
  5452. else if (isRef(oldRef)) {
  5453. oldRef.value = null;
  5454. }
  5455. }
  5456. if (isFunction(ref)) {
  5457. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  5458. }
  5459. else {
  5460. const _isString = isString(ref);
  5461. const _isRef = isRef(ref);
  5462. if (_isString || _isRef) {
  5463. const doSet = () => {
  5464. if (rawRef.f) {
  5465. const existing = _isString ? refs[ref] : ref.value;
  5466. if (isUnmount) {
  5467. isArray(existing) && remove(existing, refValue);
  5468. }
  5469. else {
  5470. if (!isArray(existing)) {
  5471. if (_isString) {
  5472. refs[ref] = [refValue];
  5473. if (hasOwn(setupState, ref)) {
  5474. setupState[ref] = refs[ref];
  5475. }
  5476. }
  5477. else {
  5478. ref.value = [refValue];
  5479. if (rawRef.k)
  5480. refs[rawRef.k] = ref.value;
  5481. }
  5482. }
  5483. else if (!existing.includes(refValue)) {
  5484. existing.push(refValue);
  5485. }
  5486. }
  5487. }
  5488. else if (_isString) {
  5489. refs[ref] = value;
  5490. if (hasOwn(setupState, ref)) {
  5491. setupState[ref] = value;
  5492. }
  5493. }
  5494. else if (isRef(ref)) {
  5495. ref.value = value;
  5496. if (rawRef.k)
  5497. refs[rawRef.k] = value;
  5498. }
  5499. else {
  5500. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  5501. }
  5502. };
  5503. if (value) {
  5504. doSet.id = -1;
  5505. queuePostRenderEffect(doSet, parentSuspense);
  5506. }
  5507. else {
  5508. doSet();
  5509. }
  5510. }
  5511. else {
  5512. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  5513. }
  5514. }
  5515. }
  5516. let hasMismatch = false;
  5517. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  5518. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  5519. // Note: hydration is DOM-specific
  5520. // But we have to place it in core due to tight coupling with core - splitting
  5521. // it out creates a ton of unnecessary complexity.
  5522. // Hydration also depends on some renderer internal logic which needs to be
  5523. // passed in via arguments.
  5524. function createHydrationFunctions(rendererInternals) {
  5525. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  5526. const hydrate = (vnode, container) => {
  5527. if (!container.hasChildNodes()) {
  5528. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  5529. `Performing full mount instead.`);
  5530. patch(null, vnode, container);
  5531. flushPostFlushCbs();
  5532. return;
  5533. }
  5534. hasMismatch = false;
  5535. hydrateNode(container.firstChild, vnode, null, null, null);
  5536. flushPostFlushCbs();
  5537. if (hasMismatch && !false) {
  5538. // this error should show up in production
  5539. console.error(`Hydration completed but contains mismatches.`);
  5540. }
  5541. };
  5542. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  5543. const isFragmentStart = isComment(node) && node.data === '[';
  5544. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  5545. const { type, ref, shapeFlag } = vnode;
  5546. const domType = node.nodeType;
  5547. vnode.el = node;
  5548. let nextNode = null;
  5549. switch (type) {
  5550. case Text:
  5551. if (domType !== 3 /* TEXT */) {
  5552. nextNode = onMismatch();
  5553. }
  5554. else {
  5555. if (node.data !== vnode.children) {
  5556. hasMismatch = true;
  5557. warn$1(`Hydration text mismatch:` +
  5558. `\n- Client: ${JSON.stringify(node.data)}` +
  5559. `\n- Server: ${JSON.stringify(vnode.children)}`);
  5560. node.data = vnode.children;
  5561. }
  5562. nextNode = nextSibling(node);
  5563. }
  5564. break;
  5565. case Comment:
  5566. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  5567. nextNode = onMismatch();
  5568. }
  5569. else {
  5570. nextNode = nextSibling(node);
  5571. }
  5572. break;
  5573. case Static:
  5574. if (domType !== 1 /* ELEMENT */) {
  5575. nextNode = onMismatch();
  5576. }
  5577. else {
  5578. // determine anchor, adopt content
  5579. nextNode = node;
  5580. // if the static vnode has its content stripped during build,
  5581. // adopt it from the server-rendered HTML.
  5582. const needToAdoptContent = !vnode.children.length;
  5583. for (let i = 0; i < vnode.staticCount; i++) {
  5584. if (needToAdoptContent)
  5585. vnode.children += nextNode.outerHTML;
  5586. if (i === vnode.staticCount - 1) {
  5587. vnode.anchor = nextNode;
  5588. }
  5589. nextNode = nextSibling(nextNode);
  5590. }
  5591. return nextNode;
  5592. }
  5593. break;
  5594. case Fragment:
  5595. if (!isFragmentStart) {
  5596. nextNode = onMismatch();
  5597. }
  5598. else {
  5599. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5600. }
  5601. break;
  5602. default:
  5603. if (shapeFlag & 1 /* ELEMENT */) {
  5604. if (domType !== 1 /* ELEMENT */ ||
  5605. vnode.type.toLowerCase() !==
  5606. node.tagName.toLowerCase()) {
  5607. nextNode = onMismatch();
  5608. }
  5609. else {
  5610. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5611. }
  5612. }
  5613. else if (shapeFlag & 6 /* COMPONENT */) {
  5614. // when setting up the render effect, if the initial vnode already
  5615. // has .el set, the component will perform hydration instead of mount
  5616. // on its sub-tree.
  5617. vnode.slotScopeIds = slotScopeIds;
  5618. const container = parentNode(node);
  5619. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  5620. // component may be async, so in the case of fragments we cannot rely
  5621. // on component's rendered output to determine the end of the fragment
  5622. // instead, we do a lookahead to find the end anchor node.
  5623. nextNode = isFragmentStart
  5624. ? locateClosingAsyncAnchor(node)
  5625. : nextSibling(node);
  5626. // #3787
  5627. // if component is async, it may get moved / unmounted before its
  5628. // inner component is loaded, so we need to give it a placeholder
  5629. // vnode that matches its adopted DOM.
  5630. if (isAsyncWrapper(vnode)) {
  5631. let subTree;
  5632. if (isFragmentStart) {
  5633. subTree = createVNode(Fragment);
  5634. subTree.anchor = nextNode
  5635. ? nextNode.previousSibling
  5636. : container.lastChild;
  5637. }
  5638. else {
  5639. subTree =
  5640. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  5641. }
  5642. subTree.el = node;
  5643. vnode.component.subTree = subTree;
  5644. }
  5645. }
  5646. else if (shapeFlag & 64 /* TELEPORT */) {
  5647. if (domType !== 8 /* COMMENT */) {
  5648. nextNode = onMismatch();
  5649. }
  5650. else {
  5651. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  5652. }
  5653. }
  5654. else if (shapeFlag & 128 /* SUSPENSE */) {
  5655. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  5656. }
  5657. else {
  5658. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  5659. }
  5660. }
  5661. if (ref != null) {
  5662. setRef(ref, null, parentSuspense, vnode);
  5663. }
  5664. return nextNode;
  5665. };
  5666. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5667. optimized = optimized || !!vnode.dynamicChildren;
  5668. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  5669. // #4006 for form elements with non-string v-model value bindings
  5670. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  5671. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  5672. // skip props & children if this is hoisted static nodes
  5673. // #5405 in dev, always hydrate children for HMR
  5674. {
  5675. if (dirs) {
  5676. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5677. }
  5678. // props
  5679. if (props) {
  5680. if (forcePatchValue ||
  5681. !optimized ||
  5682. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  5683. for (const key in props) {
  5684. if ((forcePatchValue && key.endsWith('value')) ||
  5685. (isOn(key) && !isReservedProp(key))) {
  5686. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  5687. }
  5688. }
  5689. }
  5690. else if (props.onClick) {
  5691. // Fast path for click listeners (which is most often) to avoid
  5692. // iterating through props.
  5693. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  5694. }
  5695. }
  5696. // vnode / directive hooks
  5697. let vnodeHooks;
  5698. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  5699. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  5700. }
  5701. if (dirs) {
  5702. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  5703. }
  5704. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  5705. queueEffectWithSuspense(() => {
  5706. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  5707. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  5708. }, parentSuspense);
  5709. }
  5710. // children
  5711. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  5712. // skip if element has innerHTML / textContent
  5713. !(props && (props.innerHTML || props.textContent))) {
  5714. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  5715. let hasWarned = false;
  5716. while (next) {
  5717. hasMismatch = true;
  5718. if (!hasWarned) {
  5719. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  5720. `server rendered element contains more child nodes than client vdom.`);
  5721. hasWarned = true;
  5722. }
  5723. // The SSRed DOM contains more nodes than it should. Remove them.
  5724. const cur = next;
  5725. next = next.nextSibling;
  5726. remove(cur);
  5727. }
  5728. }
  5729. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5730. if (el.textContent !== vnode.children) {
  5731. hasMismatch = true;
  5732. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  5733. `- Client: ${el.textContent}\n` +
  5734. `- Server: ${vnode.children}`);
  5735. el.textContent = vnode.children;
  5736. }
  5737. }
  5738. }
  5739. return el.nextSibling;
  5740. };
  5741. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5742. optimized = optimized || !!parentVNode.dynamicChildren;
  5743. const children = parentVNode.children;
  5744. const l = children.length;
  5745. let hasWarned = false;
  5746. for (let i = 0; i < l; i++) {
  5747. const vnode = optimized
  5748. ? children[i]
  5749. : (children[i] = normalizeVNode(children[i]));
  5750. if (node) {
  5751. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5752. }
  5753. else if (vnode.type === Text && !vnode.children) {
  5754. continue;
  5755. }
  5756. else {
  5757. hasMismatch = true;
  5758. if (!hasWarned) {
  5759. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  5760. `server rendered element contains fewer child nodes than client vdom.`);
  5761. hasWarned = true;
  5762. }
  5763. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  5764. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  5765. }
  5766. }
  5767. return node;
  5768. };
  5769. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5770. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  5771. if (fragmentSlotScopeIds) {
  5772. slotScopeIds = slotScopeIds
  5773. ? slotScopeIds.concat(fragmentSlotScopeIds)
  5774. : fragmentSlotScopeIds;
  5775. }
  5776. const container = parentNode(node);
  5777. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  5778. if (next && isComment(next) && next.data === ']') {
  5779. return nextSibling((vnode.anchor = next));
  5780. }
  5781. else {
  5782. // fragment didn't hydrate successfully, since we didn't get a end anchor
  5783. // back. This should have led to node/children mismatch warnings.
  5784. hasMismatch = true;
  5785. // since the anchor is missing, we need to create one and insert it
  5786. insert((vnode.anchor = createComment(`]`)), container, next);
  5787. return next;
  5788. }
  5789. };
  5790. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  5791. hasMismatch = true;
  5792. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  5793. ? `(text)`
  5794. : isComment(node) && node.data === '['
  5795. ? `(start of fragment)`
  5796. : ``);
  5797. vnode.el = null;
  5798. if (isFragment) {
  5799. // remove excessive fragment nodes
  5800. const end = locateClosingAsyncAnchor(node);
  5801. while (true) {
  5802. const next = nextSibling(node);
  5803. if (next && next !== end) {
  5804. remove(next);
  5805. }
  5806. else {
  5807. break;
  5808. }
  5809. }
  5810. }
  5811. const next = nextSibling(node);
  5812. const container = parentNode(node);
  5813. remove(node);
  5814. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  5815. return next;
  5816. };
  5817. const locateClosingAsyncAnchor = (node) => {
  5818. let match = 0;
  5819. while (node) {
  5820. node = nextSibling(node);
  5821. if (node && isComment(node)) {
  5822. if (node.data === '[')
  5823. match++;
  5824. if (node.data === ']') {
  5825. if (match === 0) {
  5826. return nextSibling(node);
  5827. }
  5828. else {
  5829. match--;
  5830. }
  5831. }
  5832. }
  5833. }
  5834. return node;
  5835. };
  5836. return [hydrate, hydrateNode];
  5837. }
  5838. /* eslint-disable no-restricted-globals */
  5839. let supported;
  5840. let perf;
  5841. function startMeasure(instance, type) {
  5842. if (instance.appContext.config.performance && isSupported()) {
  5843. perf.mark(`vue-${type}-${instance.uid}`);
  5844. }
  5845. {
  5846. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  5847. }
  5848. }
  5849. function endMeasure(instance, type) {
  5850. if (instance.appContext.config.performance && isSupported()) {
  5851. const startTag = `vue-${type}-${instance.uid}`;
  5852. const endTag = startTag + `:end`;
  5853. perf.mark(endTag);
  5854. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  5855. perf.clearMarks(startTag);
  5856. perf.clearMarks(endTag);
  5857. }
  5858. {
  5859. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  5860. }
  5861. }
  5862. function isSupported() {
  5863. if (supported !== undefined) {
  5864. return supported;
  5865. }
  5866. if (typeof window !== 'undefined' && window.performance) {
  5867. supported = true;
  5868. perf = window.performance;
  5869. }
  5870. else {
  5871. supported = false;
  5872. }
  5873. return supported;
  5874. }
  5875. const queuePostRenderEffect = queueEffectWithSuspense
  5876. ;
  5877. /**
  5878. * The createRenderer function accepts two generic arguments:
  5879. * HostNode and HostElement, corresponding to Node and Element types in the
  5880. * host environment. For example, for runtime-dom, HostNode would be the DOM
  5881. * `Node` interface and HostElement would be the DOM `Element` interface.
  5882. *
  5883. * Custom renderers can pass in the platform specific types like this:
  5884. *
  5885. * ``` js
  5886. * const { render, createApp } = createRenderer<Node, Element>({
  5887. * patchProp,
  5888. * ...nodeOps
  5889. * })
  5890. * ```
  5891. */
  5892. function createRenderer(options) {
  5893. return baseCreateRenderer(options);
  5894. }
  5895. // Separate API for creating hydration-enabled renderer.
  5896. // Hydration logic is only used when calling this function, making it
  5897. // tree-shakable.
  5898. function createHydrationRenderer(options) {
  5899. return baseCreateRenderer(options, createHydrationFunctions);
  5900. }
  5901. // implementation
  5902. function baseCreateRenderer(options, createHydrationFns) {
  5903. const target = getGlobalThis();
  5904. target.__VUE__ = true;
  5905. {
  5906. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  5907. }
  5908. 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;
  5909. // Note: functions inside this closure should use `const xxx = () => {}`
  5910. // style in order to prevent being inlined by minifiers.
  5911. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  5912. if (n1 === n2) {
  5913. return;
  5914. }
  5915. // patching & not same type, unmount old tree
  5916. if (n1 && !isSameVNodeType(n1, n2)) {
  5917. anchor = getNextHostNode(n1);
  5918. unmount(n1, parentComponent, parentSuspense, true);
  5919. n1 = null;
  5920. }
  5921. if (n2.patchFlag === -2 /* BAIL */) {
  5922. optimized = false;
  5923. n2.dynamicChildren = null;
  5924. }
  5925. const { type, ref, shapeFlag } = n2;
  5926. switch (type) {
  5927. case Text:
  5928. processText(n1, n2, container, anchor);
  5929. break;
  5930. case Comment:
  5931. processCommentNode(n1, n2, container, anchor);
  5932. break;
  5933. case Static:
  5934. if (n1 == null) {
  5935. mountStaticNode(n2, container, anchor, isSVG);
  5936. }
  5937. else {
  5938. patchStaticNode(n1, n2, container, isSVG);
  5939. }
  5940. break;
  5941. case Fragment:
  5942. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5943. break;
  5944. default:
  5945. if (shapeFlag & 1 /* ELEMENT */) {
  5946. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5947. }
  5948. else if (shapeFlag & 6 /* COMPONENT */) {
  5949. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5950. }
  5951. else if (shapeFlag & 64 /* TELEPORT */) {
  5952. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5953. }
  5954. else if (shapeFlag & 128 /* SUSPENSE */) {
  5955. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5956. }
  5957. else {
  5958. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  5959. }
  5960. }
  5961. // set ref
  5962. if (ref != null && parentComponent) {
  5963. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  5964. }
  5965. };
  5966. const processText = (n1, n2, container, anchor) => {
  5967. if (n1 == null) {
  5968. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  5969. }
  5970. else {
  5971. const el = (n2.el = n1.el);
  5972. if (n2.children !== n1.children) {
  5973. hostSetText(el, n2.children);
  5974. }
  5975. }
  5976. };
  5977. const processCommentNode = (n1, n2, container, anchor) => {
  5978. if (n1 == null) {
  5979. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  5980. }
  5981. else {
  5982. // there's no support for dynamic comments
  5983. n2.el = n1.el;
  5984. }
  5985. };
  5986. const mountStaticNode = (n2, container, anchor, isSVG) => {
  5987. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  5988. };
  5989. /**
  5990. * Dev / HMR only
  5991. */
  5992. const patchStaticNode = (n1, n2, container, isSVG) => {
  5993. // static nodes are only patched during dev for HMR
  5994. if (n2.children !== n1.children) {
  5995. const anchor = hostNextSibling(n1.anchor);
  5996. // remove existing
  5997. removeStaticNode(n1);
  5998. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5999. }
  6000. else {
  6001. n2.el = n1.el;
  6002. n2.anchor = n1.anchor;
  6003. }
  6004. };
  6005. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6006. let next;
  6007. while (el && el !== anchor) {
  6008. next = hostNextSibling(el);
  6009. hostInsert(el, container, nextSibling);
  6010. el = next;
  6011. }
  6012. hostInsert(anchor, container, nextSibling);
  6013. };
  6014. const removeStaticNode = ({ el, anchor }) => {
  6015. let next;
  6016. while (el && el !== anchor) {
  6017. next = hostNextSibling(el);
  6018. hostRemove(el);
  6019. el = next;
  6020. }
  6021. hostRemove(anchor);
  6022. };
  6023. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6024. isSVG = isSVG || n2.type === 'svg';
  6025. if (n1 == null) {
  6026. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6027. }
  6028. else {
  6029. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6030. }
  6031. };
  6032. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6033. let el;
  6034. let vnodeHook;
  6035. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  6036. {
  6037. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6038. // mount children first, since some props may rely on child content
  6039. // being already rendered, e.g. `<select value>`
  6040. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6041. hostSetElementText(el, vnode.children);
  6042. }
  6043. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6044. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6045. }
  6046. if (dirs) {
  6047. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6048. }
  6049. // props
  6050. if (props) {
  6051. for (const key in props) {
  6052. if (key !== 'value' && !isReservedProp(key)) {
  6053. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6054. }
  6055. }
  6056. /**
  6057. * Special case for setting value on DOM elements:
  6058. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6059. * - it needs to be forced (#1471)
  6060. * #2353 proposes adding another renderer option to configure this, but
  6061. * the properties affects are so finite it is worth special casing it
  6062. * here to reduce the complexity. (Special casing it also should not
  6063. * affect non-DOM renderers)
  6064. */
  6065. if ('value' in props) {
  6066. hostPatchProp(el, 'value', null, props.value);
  6067. }
  6068. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6069. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6070. }
  6071. }
  6072. // scopeId
  6073. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6074. }
  6075. {
  6076. Object.defineProperty(el, '__vnode', {
  6077. value: vnode,
  6078. enumerable: false
  6079. });
  6080. Object.defineProperty(el, '__vueParentComponent', {
  6081. value: parentComponent,
  6082. enumerable: false
  6083. });
  6084. }
  6085. if (dirs) {
  6086. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6087. }
  6088. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6089. // #1689 For inside suspense + suspense resolved case, just call it
  6090. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6091. transition &&
  6092. !transition.persisted;
  6093. if (needCallTransitionHooks) {
  6094. transition.beforeEnter(el);
  6095. }
  6096. hostInsert(el, container, anchor);
  6097. if ((vnodeHook = props && props.onVnodeMounted) ||
  6098. needCallTransitionHooks ||
  6099. dirs) {
  6100. queuePostRenderEffect(() => {
  6101. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6102. needCallTransitionHooks && transition.enter(el);
  6103. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6104. }, parentSuspense);
  6105. }
  6106. };
  6107. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6108. if (scopeId) {
  6109. hostSetScopeId(el, scopeId);
  6110. }
  6111. if (slotScopeIds) {
  6112. for (let i = 0; i < slotScopeIds.length; i++) {
  6113. hostSetScopeId(el, slotScopeIds[i]);
  6114. }
  6115. }
  6116. if (parentComponent) {
  6117. let subTree = parentComponent.subTree;
  6118. if (subTree.patchFlag > 0 &&
  6119. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  6120. subTree =
  6121. filterSingleRoot(subTree.children) || subTree;
  6122. }
  6123. if (vnode === subTree) {
  6124. const parentVNode = parentComponent.vnode;
  6125. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6126. }
  6127. }
  6128. };
  6129. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6130. for (let i = start; i < children.length; i++) {
  6131. const child = (children[i] = optimized
  6132. ? cloneIfMounted(children[i])
  6133. : normalizeVNode(children[i]));
  6134. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6135. }
  6136. };
  6137. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6138. const el = (n2.el = n1.el);
  6139. let { patchFlag, dynamicChildren, dirs } = n2;
  6140. // #1426 take the old vnode's patch flag into account since user may clone a
  6141. // compiler-generated vnode, which de-opts to FULL_PROPS
  6142. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  6143. const oldProps = n1.props || EMPTY_OBJ;
  6144. const newProps = n2.props || EMPTY_OBJ;
  6145. let vnodeHook;
  6146. // disable recurse in beforeUpdate hooks
  6147. parentComponent && toggleRecurse(parentComponent, false);
  6148. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6149. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6150. }
  6151. if (dirs) {
  6152. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6153. }
  6154. parentComponent && toggleRecurse(parentComponent, true);
  6155. if (isHmrUpdating) {
  6156. // HMR updated, force full diff
  6157. patchFlag = 0;
  6158. optimized = false;
  6159. dynamicChildren = null;
  6160. }
  6161. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6162. if (dynamicChildren) {
  6163. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6164. if (parentComponent && parentComponent.type.__hmrId) {
  6165. traverseStaticChildren(n1, n2);
  6166. }
  6167. }
  6168. else if (!optimized) {
  6169. // full diff
  6170. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6171. }
  6172. if (patchFlag > 0) {
  6173. // the presence of a patchFlag means this element's render code was
  6174. // generated by the compiler and can take the fast path.
  6175. // in this path old node and new node are guaranteed to have the same shape
  6176. // (i.e. at the exact same position in the source template)
  6177. if (patchFlag & 16 /* FULL_PROPS */) {
  6178. // element props contain dynamic keys, full diff needed
  6179. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6180. }
  6181. else {
  6182. // class
  6183. // this flag is matched when the element has dynamic class bindings.
  6184. if (patchFlag & 2 /* CLASS */) {
  6185. if (oldProps.class !== newProps.class) {
  6186. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6187. }
  6188. }
  6189. // style
  6190. // this flag is matched when the element has dynamic style bindings
  6191. if (patchFlag & 4 /* STYLE */) {
  6192. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6193. }
  6194. // props
  6195. // This flag is matched when the element has dynamic prop/attr bindings
  6196. // other than class and style. The keys of dynamic prop/attrs are saved for
  6197. // faster iteration.
  6198. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6199. // bail out and go through a full diff because we need to unset the old key
  6200. if (patchFlag & 8 /* PROPS */) {
  6201. // if the flag is present then dynamicProps must be non-null
  6202. const propsToUpdate = n2.dynamicProps;
  6203. for (let i = 0; i < propsToUpdate.length; i++) {
  6204. const key = propsToUpdate[i];
  6205. const prev = oldProps[key];
  6206. const next = newProps[key];
  6207. // #1471 force patch value
  6208. if (next !== prev || key === 'value') {
  6209. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6210. }
  6211. }
  6212. }
  6213. }
  6214. // text
  6215. // This flag is matched when the element has only dynamic text children.
  6216. if (patchFlag & 1 /* TEXT */) {
  6217. if (n1.children !== n2.children) {
  6218. hostSetElementText(el, n2.children);
  6219. }
  6220. }
  6221. }
  6222. else if (!optimized && dynamicChildren == null) {
  6223. // unoptimized, full diff
  6224. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6225. }
  6226. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6227. queuePostRenderEffect(() => {
  6228. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6229. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6230. }, parentSuspense);
  6231. }
  6232. };
  6233. // The fast path for blocks.
  6234. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6235. for (let i = 0; i < newChildren.length; i++) {
  6236. const oldVNode = oldChildren[i];
  6237. const newVNode = newChildren[i];
  6238. // Determine the container (parent element) for the patch.
  6239. const container =
  6240. // oldVNode may be an errored async setup() component inside Suspense
  6241. // which will not have a mounted element
  6242. oldVNode.el &&
  6243. // - In the case of a Fragment, we need to provide the actual parent
  6244. // of the Fragment itself so it can move its children.
  6245. (oldVNode.type === Fragment ||
  6246. // - In the case of different nodes, there is going to be a replacement
  6247. // which also requires the correct parent container
  6248. !isSameVNodeType(oldVNode, newVNode) ||
  6249. // - In the case of a component, it could contain anything.
  6250. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  6251. ? hostParentNode(oldVNode.el)
  6252. : // In other cases, the parent container is not actually used so we
  6253. // just pass the block element here to avoid a DOM parentNode call.
  6254. fallbackContainer;
  6255. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6256. }
  6257. };
  6258. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6259. if (oldProps !== newProps) {
  6260. for (const key in newProps) {
  6261. // empty string is not valid prop
  6262. if (isReservedProp(key))
  6263. continue;
  6264. const next = newProps[key];
  6265. const prev = oldProps[key];
  6266. // defer patching value
  6267. if (next !== prev && key !== 'value') {
  6268. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6269. }
  6270. }
  6271. if (oldProps !== EMPTY_OBJ) {
  6272. for (const key in oldProps) {
  6273. if (!isReservedProp(key) && !(key in newProps)) {
  6274. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6275. }
  6276. }
  6277. }
  6278. if ('value' in newProps) {
  6279. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6280. }
  6281. }
  6282. };
  6283. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6284. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6285. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6286. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6287. if (isHmrUpdating) {
  6288. // HMR updated, force full diff
  6289. patchFlag = 0;
  6290. optimized = false;
  6291. dynamicChildren = null;
  6292. }
  6293. // check if this is a slot fragment with :slotted scope ids
  6294. if (fragmentSlotScopeIds) {
  6295. slotScopeIds = slotScopeIds
  6296. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6297. : fragmentSlotScopeIds;
  6298. }
  6299. if (n1 == null) {
  6300. hostInsert(fragmentStartAnchor, container, anchor);
  6301. hostInsert(fragmentEndAnchor, container, anchor);
  6302. // a fragment can only have array children
  6303. // since they are either generated by the compiler, or implicitly created
  6304. // from arrays.
  6305. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6306. }
  6307. else {
  6308. if (patchFlag > 0 &&
  6309. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  6310. dynamicChildren &&
  6311. // #2715 the previous fragment could've been a BAILed one as a result
  6312. // of renderSlot() with no valid children
  6313. n1.dynamicChildren) {
  6314. // a stable fragment (template root or <template v-for>) doesn't need to
  6315. // patch children order, but it may contain dynamicChildren.
  6316. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6317. if (parentComponent && parentComponent.type.__hmrId) {
  6318. traverseStaticChildren(n1, n2);
  6319. }
  6320. else if (
  6321. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6322. // get moved around. Make sure all root level vnodes inherit el.
  6323. // #2134 or if it's a component root, it may also get moved around
  6324. // as the component is being moved.
  6325. n2.key != null ||
  6326. (parentComponent && n2 === parentComponent.subTree)) {
  6327. traverseStaticChildren(n1, n2, true /* shallow */);
  6328. }
  6329. }
  6330. else {
  6331. // keyed / unkeyed, or manual fragments.
  6332. // for keyed & unkeyed, since they are compiler generated from v-for,
  6333. // each child is guaranteed to be a block so the fragment will never
  6334. // have dynamicChildren.
  6335. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6336. }
  6337. }
  6338. };
  6339. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6340. n2.slotScopeIds = slotScopeIds;
  6341. if (n1 == null) {
  6342. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  6343. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6344. }
  6345. else {
  6346. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6347. }
  6348. }
  6349. else {
  6350. updateComponent(n1, n2, optimized);
  6351. }
  6352. };
  6353. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6354. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6355. if (instance.type.__hmrId) {
  6356. registerHMR(instance);
  6357. }
  6358. {
  6359. pushWarningContext(initialVNode);
  6360. startMeasure(instance, `mount`);
  6361. }
  6362. // inject renderer internals for keepAlive
  6363. if (isKeepAlive(initialVNode)) {
  6364. instance.ctx.renderer = internals;
  6365. }
  6366. // resolve props and slots for setup context
  6367. {
  6368. {
  6369. startMeasure(instance, `init`);
  6370. }
  6371. setupComponent(instance);
  6372. {
  6373. endMeasure(instance, `init`);
  6374. }
  6375. }
  6376. // setup() is async. This component relies on async logic to be resolved
  6377. // before proceeding
  6378. if (instance.asyncDep) {
  6379. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6380. // Give it a placeholder if this is not hydration
  6381. // TODO handle self-defined fallback
  6382. if (!initialVNode.el) {
  6383. const placeholder = (instance.subTree = createVNode(Comment));
  6384. processCommentNode(null, placeholder, container, anchor);
  6385. }
  6386. return;
  6387. }
  6388. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6389. {
  6390. popWarningContext();
  6391. endMeasure(instance, `mount`);
  6392. }
  6393. };
  6394. const updateComponent = (n1, n2, optimized) => {
  6395. const instance = (n2.component = n1.component);
  6396. if (shouldUpdateComponent(n1, n2, optimized)) {
  6397. if (instance.asyncDep &&
  6398. !instance.asyncResolved) {
  6399. // async & still pending - just update props and slots
  6400. // since the component's reactive effect for render isn't set-up yet
  6401. {
  6402. pushWarningContext(n2);
  6403. }
  6404. updateComponentPreRender(instance, n2, optimized);
  6405. {
  6406. popWarningContext();
  6407. }
  6408. return;
  6409. }
  6410. else {
  6411. // normal update
  6412. instance.next = n2;
  6413. // in case the child component is also queued, remove it to avoid
  6414. // double updating the same child component in the same flush.
  6415. invalidateJob(instance.update);
  6416. // instance.update is the reactive effect.
  6417. instance.update();
  6418. }
  6419. }
  6420. else {
  6421. // no update needed. just copy over properties
  6422. n2.component = n1.component;
  6423. n2.el = n1.el;
  6424. instance.vnode = n2;
  6425. }
  6426. };
  6427. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6428. const componentUpdateFn = () => {
  6429. if (!instance.isMounted) {
  6430. let vnodeHook;
  6431. const { el, props } = initialVNode;
  6432. const { bm, m, parent } = instance;
  6433. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6434. toggleRecurse(instance, false);
  6435. // beforeMount hook
  6436. if (bm) {
  6437. invokeArrayFns(bm);
  6438. }
  6439. // onVnodeBeforeMount
  6440. if (!isAsyncWrapperVNode &&
  6441. (vnodeHook = props && props.onVnodeBeforeMount)) {
  6442. invokeVNodeHook(vnodeHook, parent, initialVNode);
  6443. }
  6444. toggleRecurse(instance, true);
  6445. if (el && hydrateNode) {
  6446. // vnode has adopted host node - perform hydration instead of mount.
  6447. const hydrateSubTree = () => {
  6448. {
  6449. startMeasure(instance, `render`);
  6450. }
  6451. instance.subTree = renderComponentRoot(instance);
  6452. {
  6453. endMeasure(instance, `render`);
  6454. }
  6455. {
  6456. startMeasure(instance, `hydrate`);
  6457. }
  6458. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  6459. {
  6460. endMeasure(instance, `hydrate`);
  6461. }
  6462. };
  6463. if (isAsyncWrapperVNode) {
  6464. initialVNode.type.__asyncLoader().then(
  6465. // note: we are moving the render call into an async callback,
  6466. // which means it won't track dependencies - but it's ok because
  6467. // a server-rendered async wrapper is already in resolved state
  6468. // and it will never need to change.
  6469. () => !instance.isUnmounted && hydrateSubTree());
  6470. }
  6471. else {
  6472. hydrateSubTree();
  6473. }
  6474. }
  6475. else {
  6476. {
  6477. startMeasure(instance, `render`);
  6478. }
  6479. const subTree = (instance.subTree = renderComponentRoot(instance));
  6480. {
  6481. endMeasure(instance, `render`);
  6482. }
  6483. {
  6484. startMeasure(instance, `patch`);
  6485. }
  6486. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  6487. {
  6488. endMeasure(instance, `patch`);
  6489. }
  6490. initialVNode.el = subTree.el;
  6491. }
  6492. // mounted hook
  6493. if (m) {
  6494. queuePostRenderEffect(m, parentSuspense);
  6495. }
  6496. // onVnodeMounted
  6497. if (!isAsyncWrapperVNode &&
  6498. (vnodeHook = props && props.onVnodeMounted)) {
  6499. const scopedInitialVNode = initialVNode;
  6500. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  6501. }
  6502. // activated hook for keep-alive roots.
  6503. // #1742 activated hook must be accessed after first render
  6504. // since the hook may be injected by a child keep-alive
  6505. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6506. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  6507. }
  6508. instance.isMounted = true;
  6509. {
  6510. devtoolsComponentAdded(instance);
  6511. }
  6512. // #2458: deference mount-only object parameters to prevent memleaks
  6513. initialVNode = container = anchor = null;
  6514. }
  6515. else {
  6516. // updateComponent
  6517. // This is triggered by mutation of component's own state (next: null)
  6518. // OR parent calling processComponent (next: VNode)
  6519. let { next, bu, u, parent, vnode } = instance;
  6520. let originNext = next;
  6521. let vnodeHook;
  6522. {
  6523. pushWarningContext(next || instance.vnode);
  6524. }
  6525. // Disallow component effect recursion during pre-lifecycle hooks.
  6526. toggleRecurse(instance, false);
  6527. if (next) {
  6528. next.el = vnode.el;
  6529. updateComponentPreRender(instance, next, optimized);
  6530. }
  6531. else {
  6532. next = vnode;
  6533. }
  6534. // beforeUpdate hook
  6535. if (bu) {
  6536. invokeArrayFns(bu);
  6537. }
  6538. // onVnodeBeforeUpdate
  6539. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  6540. invokeVNodeHook(vnodeHook, parent, next, vnode);
  6541. }
  6542. toggleRecurse(instance, true);
  6543. // render
  6544. {
  6545. startMeasure(instance, `render`);
  6546. }
  6547. const nextTree = renderComponentRoot(instance);
  6548. {
  6549. endMeasure(instance, `render`);
  6550. }
  6551. const prevTree = instance.subTree;
  6552. instance.subTree = nextTree;
  6553. {
  6554. startMeasure(instance, `patch`);
  6555. }
  6556. patch(prevTree, nextTree,
  6557. // parent may have changed if it's in a teleport
  6558. hostParentNode(prevTree.el),
  6559. // anchor may have changed if it's in a fragment
  6560. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  6561. {
  6562. endMeasure(instance, `patch`);
  6563. }
  6564. next.el = nextTree.el;
  6565. if (originNext === null) {
  6566. // self-triggered update. In case of HOC, update parent component
  6567. // vnode el. HOC is indicated by parent instance's subTree pointing
  6568. // to child component's vnode
  6569. updateHOCHostEl(instance, nextTree.el);
  6570. }
  6571. // updated hook
  6572. if (u) {
  6573. queuePostRenderEffect(u, parentSuspense);
  6574. }
  6575. // onVnodeUpdated
  6576. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  6577. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  6578. }
  6579. {
  6580. devtoolsComponentUpdated(instance);
  6581. }
  6582. {
  6583. popWarningContext();
  6584. }
  6585. }
  6586. };
  6587. // create reactive effect for rendering
  6588. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
  6589. ));
  6590. const update = (instance.update = effect.run.bind(effect));
  6591. update.id = instance.uid;
  6592. // allowRecurse
  6593. // #1801, #2043 component render effects should allow recursive updates
  6594. toggleRecurse(instance, true);
  6595. {
  6596. effect.onTrack = instance.rtc
  6597. ? e => invokeArrayFns(instance.rtc, e)
  6598. : void 0;
  6599. effect.onTrigger = instance.rtg
  6600. ? e => invokeArrayFns(instance.rtg, e)
  6601. : void 0;
  6602. // @ts-ignore (for scheduler)
  6603. update.ownerInstance = instance;
  6604. }
  6605. update();
  6606. };
  6607. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  6608. nextVNode.component = instance;
  6609. const prevProps = instance.vnode.props;
  6610. instance.vnode = nextVNode;
  6611. instance.next = null;
  6612. updateProps(instance, nextVNode.props, prevProps, optimized);
  6613. updateSlots(instance, nextVNode.children, optimized);
  6614. pauseTracking();
  6615. // props update may have triggered pre-flush watchers.
  6616. // flush them before the render update.
  6617. flushPreFlushCbs(undefined, instance.update);
  6618. resetTracking();
  6619. };
  6620. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  6621. const c1 = n1 && n1.children;
  6622. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  6623. const c2 = n2.children;
  6624. const { patchFlag, shapeFlag } = n2;
  6625. // fast path
  6626. if (patchFlag > 0) {
  6627. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  6628. // this could be either fully-keyed or mixed (some keyed some not)
  6629. // presence of patchFlag means children are guaranteed to be arrays
  6630. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6631. return;
  6632. }
  6633. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  6634. // unkeyed
  6635. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6636. return;
  6637. }
  6638. }
  6639. // children has 3 possibilities: text, array or no children.
  6640. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6641. // text children fast path
  6642. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  6643. unmountChildren(c1, parentComponent, parentSuspense);
  6644. }
  6645. if (c2 !== c1) {
  6646. hostSetElementText(container, c2);
  6647. }
  6648. }
  6649. else {
  6650. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  6651. // prev children was array
  6652. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6653. // two arrays, cannot assume anything, do full diff
  6654. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6655. }
  6656. else {
  6657. // no new children, just unmount old
  6658. unmountChildren(c1, parentComponent, parentSuspense, true);
  6659. }
  6660. }
  6661. else {
  6662. // prev children was text OR null
  6663. // new children is array OR null
  6664. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  6665. hostSetElementText(container, '');
  6666. }
  6667. // mount new if array
  6668. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6669. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6670. }
  6671. }
  6672. }
  6673. };
  6674. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6675. c1 = c1 || EMPTY_ARR;
  6676. c2 = c2 || EMPTY_ARR;
  6677. const oldLength = c1.length;
  6678. const newLength = c2.length;
  6679. const commonLength = Math.min(oldLength, newLength);
  6680. let i;
  6681. for (i = 0; i < commonLength; i++) {
  6682. const nextChild = (c2[i] = optimized
  6683. ? cloneIfMounted(c2[i])
  6684. : normalizeVNode(c2[i]));
  6685. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6686. }
  6687. if (oldLength > newLength) {
  6688. // remove old
  6689. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  6690. }
  6691. else {
  6692. // mount new
  6693. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  6694. }
  6695. };
  6696. // can be all-keyed or mixed
  6697. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6698. let i = 0;
  6699. const l2 = c2.length;
  6700. let e1 = c1.length - 1; // prev ending index
  6701. let e2 = l2 - 1; // next ending index
  6702. // 1. sync from start
  6703. // (a b) c
  6704. // (a b) d e
  6705. while (i <= e1 && i <= e2) {
  6706. const n1 = c1[i];
  6707. const n2 = (c2[i] = optimized
  6708. ? cloneIfMounted(c2[i])
  6709. : normalizeVNode(c2[i]));
  6710. if (isSameVNodeType(n1, n2)) {
  6711. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6712. }
  6713. else {
  6714. break;
  6715. }
  6716. i++;
  6717. }
  6718. // 2. sync from end
  6719. // a (b c)
  6720. // d e (b c)
  6721. while (i <= e1 && i <= e2) {
  6722. const n1 = c1[e1];
  6723. const n2 = (c2[e2] = optimized
  6724. ? cloneIfMounted(c2[e2])
  6725. : normalizeVNode(c2[e2]));
  6726. if (isSameVNodeType(n1, n2)) {
  6727. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6728. }
  6729. else {
  6730. break;
  6731. }
  6732. e1--;
  6733. e2--;
  6734. }
  6735. // 3. common sequence + mount
  6736. // (a b)
  6737. // (a b) c
  6738. // i = 2, e1 = 1, e2 = 2
  6739. // (a b)
  6740. // c (a b)
  6741. // i = 0, e1 = -1, e2 = 0
  6742. if (i > e1) {
  6743. if (i <= e2) {
  6744. const nextPos = e2 + 1;
  6745. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  6746. while (i <= e2) {
  6747. patch(null, (c2[i] = optimized
  6748. ? cloneIfMounted(c2[i])
  6749. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6750. i++;
  6751. }
  6752. }
  6753. }
  6754. // 4. common sequence + unmount
  6755. // (a b) c
  6756. // (a b)
  6757. // i = 2, e1 = 2, e2 = 1
  6758. // a (b c)
  6759. // (b c)
  6760. // i = 0, e1 = 0, e2 = -1
  6761. else if (i > e2) {
  6762. while (i <= e1) {
  6763. unmount(c1[i], parentComponent, parentSuspense, true);
  6764. i++;
  6765. }
  6766. }
  6767. // 5. unknown sequence
  6768. // [i ... e1 + 1]: a b [c d e] f g
  6769. // [i ... e2 + 1]: a b [e d c h] f g
  6770. // i = 2, e1 = 4, e2 = 5
  6771. else {
  6772. const s1 = i; // prev starting index
  6773. const s2 = i; // next starting index
  6774. // 5.1 build key:index map for newChildren
  6775. const keyToNewIndexMap = new Map();
  6776. for (i = s2; i <= e2; i++) {
  6777. const nextChild = (c2[i] = optimized
  6778. ? cloneIfMounted(c2[i])
  6779. : normalizeVNode(c2[i]));
  6780. if (nextChild.key != null) {
  6781. if (keyToNewIndexMap.has(nextChild.key)) {
  6782. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  6783. }
  6784. keyToNewIndexMap.set(nextChild.key, i);
  6785. }
  6786. }
  6787. // 5.2 loop through old children left to be patched and try to patch
  6788. // matching nodes & remove nodes that are no longer present
  6789. let j;
  6790. let patched = 0;
  6791. const toBePatched = e2 - s2 + 1;
  6792. let moved = false;
  6793. // used to track whether any node has moved
  6794. let maxNewIndexSoFar = 0;
  6795. // works as Map<newIndex, oldIndex>
  6796. // Note that oldIndex is offset by +1
  6797. // and oldIndex = 0 is a special value indicating the new node has
  6798. // no corresponding old node.
  6799. // used for determining longest stable subsequence
  6800. const newIndexToOldIndexMap = new Array(toBePatched);
  6801. for (i = 0; i < toBePatched; i++)
  6802. newIndexToOldIndexMap[i] = 0;
  6803. for (i = s1; i <= e1; i++) {
  6804. const prevChild = c1[i];
  6805. if (patched >= toBePatched) {
  6806. // all new children have been patched so this can only be a removal
  6807. unmount(prevChild, parentComponent, parentSuspense, true);
  6808. continue;
  6809. }
  6810. let newIndex;
  6811. if (prevChild.key != null) {
  6812. newIndex = keyToNewIndexMap.get(prevChild.key);
  6813. }
  6814. else {
  6815. // key-less node, try to locate a key-less node of the same type
  6816. for (j = s2; j <= e2; j++) {
  6817. if (newIndexToOldIndexMap[j - s2] === 0 &&
  6818. isSameVNodeType(prevChild, c2[j])) {
  6819. newIndex = j;
  6820. break;
  6821. }
  6822. }
  6823. }
  6824. if (newIndex === undefined) {
  6825. unmount(prevChild, parentComponent, parentSuspense, true);
  6826. }
  6827. else {
  6828. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  6829. if (newIndex >= maxNewIndexSoFar) {
  6830. maxNewIndexSoFar = newIndex;
  6831. }
  6832. else {
  6833. moved = true;
  6834. }
  6835. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6836. patched++;
  6837. }
  6838. }
  6839. // 5.3 move and mount
  6840. // generate longest stable subsequence only when nodes have moved
  6841. const increasingNewIndexSequence = moved
  6842. ? getSequence(newIndexToOldIndexMap)
  6843. : EMPTY_ARR;
  6844. j = increasingNewIndexSequence.length - 1;
  6845. // looping backwards so that we can use last patched node as anchor
  6846. for (i = toBePatched - 1; i >= 0; i--) {
  6847. const nextIndex = s2 + i;
  6848. const nextChild = c2[nextIndex];
  6849. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  6850. if (newIndexToOldIndexMap[i] === 0) {
  6851. // mount new
  6852. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6853. }
  6854. else if (moved) {
  6855. // move if:
  6856. // There is no stable subsequence (e.g. a reverse)
  6857. // OR current node is not among the stable sequence
  6858. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  6859. move(nextChild, container, anchor, 2 /* REORDER */);
  6860. }
  6861. else {
  6862. j--;
  6863. }
  6864. }
  6865. }
  6866. }
  6867. };
  6868. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  6869. const { el, type, transition, children, shapeFlag } = vnode;
  6870. if (shapeFlag & 6 /* COMPONENT */) {
  6871. move(vnode.component.subTree, container, anchor, moveType);
  6872. return;
  6873. }
  6874. if (shapeFlag & 128 /* SUSPENSE */) {
  6875. vnode.suspense.move(container, anchor, moveType);
  6876. return;
  6877. }
  6878. if (shapeFlag & 64 /* TELEPORT */) {
  6879. type.move(vnode, container, anchor, internals);
  6880. return;
  6881. }
  6882. if (type === Fragment) {
  6883. hostInsert(el, container, anchor);
  6884. for (let i = 0; i < children.length; i++) {
  6885. move(children[i], container, anchor, moveType);
  6886. }
  6887. hostInsert(vnode.anchor, container, anchor);
  6888. return;
  6889. }
  6890. if (type === Static) {
  6891. moveStaticNode(vnode, container, anchor);
  6892. return;
  6893. }
  6894. // single nodes
  6895. const needTransition = moveType !== 2 /* REORDER */ &&
  6896. shapeFlag & 1 /* ELEMENT */ &&
  6897. transition;
  6898. if (needTransition) {
  6899. if (moveType === 0 /* ENTER */) {
  6900. transition.beforeEnter(el);
  6901. hostInsert(el, container, anchor);
  6902. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  6903. }
  6904. else {
  6905. const { leave, delayLeave, afterLeave } = transition;
  6906. const remove = () => hostInsert(el, container, anchor);
  6907. const performLeave = () => {
  6908. leave(el, () => {
  6909. remove();
  6910. afterLeave && afterLeave();
  6911. });
  6912. };
  6913. if (delayLeave) {
  6914. delayLeave(el, remove, performLeave);
  6915. }
  6916. else {
  6917. performLeave();
  6918. }
  6919. }
  6920. }
  6921. else {
  6922. hostInsert(el, container, anchor);
  6923. }
  6924. };
  6925. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  6926. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  6927. // unset ref
  6928. if (ref != null) {
  6929. setRef(ref, null, parentSuspense, vnode, true);
  6930. }
  6931. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6932. parentComponent.ctx.deactivate(vnode);
  6933. return;
  6934. }
  6935. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  6936. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  6937. let vnodeHook;
  6938. if (shouldInvokeVnodeHook &&
  6939. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  6940. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6941. }
  6942. if (shapeFlag & 6 /* COMPONENT */) {
  6943. unmountComponent(vnode.component, parentSuspense, doRemove);
  6944. }
  6945. else {
  6946. if (shapeFlag & 128 /* SUSPENSE */) {
  6947. vnode.suspense.unmount(parentSuspense, doRemove);
  6948. return;
  6949. }
  6950. if (shouldInvokeDirs) {
  6951. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  6952. }
  6953. if (shapeFlag & 64 /* TELEPORT */) {
  6954. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  6955. }
  6956. else if (dynamicChildren &&
  6957. // #1153: fast path should not be taken for non-stable (v-for) fragments
  6958. (type !== Fragment ||
  6959. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  6960. // fast path for block nodes: only need to unmount dynamic children.
  6961. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  6962. }
  6963. else if ((type === Fragment &&
  6964. patchFlag &
  6965. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  6966. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  6967. unmountChildren(children, parentComponent, parentSuspense);
  6968. }
  6969. if (doRemove) {
  6970. remove(vnode);
  6971. }
  6972. }
  6973. if ((shouldInvokeVnodeHook &&
  6974. (vnodeHook = props && props.onVnodeUnmounted)) ||
  6975. shouldInvokeDirs) {
  6976. queuePostRenderEffect(() => {
  6977. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6978. shouldInvokeDirs &&
  6979. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  6980. }, parentSuspense);
  6981. }
  6982. };
  6983. const remove = vnode => {
  6984. const { type, el, anchor, transition } = vnode;
  6985. if (type === Fragment) {
  6986. if (vnode.patchFlag > 0 &&
  6987. vnode.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */ &&
  6988. transition &&
  6989. !transition.persisted) {
  6990. vnode.children.forEach(child => {
  6991. if (child.type === Comment) {
  6992. hostRemove(child.el);
  6993. }
  6994. else {
  6995. remove(child);
  6996. }
  6997. });
  6998. }
  6999. else {
  7000. removeFragment(el, anchor);
  7001. }
  7002. return;
  7003. }
  7004. if (type === Static) {
  7005. removeStaticNode(vnode);
  7006. return;
  7007. }
  7008. const performRemove = () => {
  7009. hostRemove(el);
  7010. if (transition && !transition.persisted && transition.afterLeave) {
  7011. transition.afterLeave();
  7012. }
  7013. };
  7014. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  7015. transition &&
  7016. !transition.persisted) {
  7017. const { leave, delayLeave } = transition;
  7018. const performLeave = () => leave(el, performRemove);
  7019. if (delayLeave) {
  7020. delayLeave(vnode.el, performRemove, performLeave);
  7021. }
  7022. else {
  7023. performLeave();
  7024. }
  7025. }
  7026. else {
  7027. performRemove();
  7028. }
  7029. };
  7030. const removeFragment = (cur, end) => {
  7031. // For fragments, directly remove all contained DOM nodes.
  7032. // (fragment child nodes cannot have transition)
  7033. let next;
  7034. while (cur !== end) {
  7035. next = hostNextSibling(cur);
  7036. hostRemove(cur);
  7037. cur = next;
  7038. }
  7039. hostRemove(end);
  7040. };
  7041. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7042. if (instance.type.__hmrId) {
  7043. unregisterHMR(instance);
  7044. }
  7045. const { bum, scope, update, subTree, um } = instance;
  7046. // beforeUnmount hook
  7047. if (bum) {
  7048. invokeArrayFns(bum);
  7049. }
  7050. // stop effects in component scope
  7051. scope.stop();
  7052. // update may be null if a component is unmounted before its async
  7053. // setup has resolved.
  7054. if (update) {
  7055. // so that scheduler will no longer invoke it
  7056. update.active = false;
  7057. unmount(subTree, instance, parentSuspense, doRemove);
  7058. }
  7059. // unmounted hook
  7060. if (um) {
  7061. queuePostRenderEffect(um, parentSuspense);
  7062. }
  7063. queuePostRenderEffect(() => {
  7064. instance.isUnmounted = true;
  7065. }, parentSuspense);
  7066. // A component with async dep inside a pending suspense is unmounted before
  7067. // its async dep resolves. This should remove the dep from the suspense, and
  7068. // cause the suspense to resolve immediately if that was the last dep.
  7069. if (parentSuspense &&
  7070. parentSuspense.pendingBranch &&
  7071. !parentSuspense.isUnmounted &&
  7072. instance.asyncDep &&
  7073. !instance.asyncResolved &&
  7074. instance.suspenseId === parentSuspense.pendingId) {
  7075. parentSuspense.deps--;
  7076. if (parentSuspense.deps === 0) {
  7077. parentSuspense.resolve();
  7078. }
  7079. }
  7080. {
  7081. devtoolsComponentRemoved(instance);
  7082. }
  7083. };
  7084. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7085. for (let i = start; i < children.length; i++) {
  7086. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7087. }
  7088. };
  7089. const getNextHostNode = vnode => {
  7090. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  7091. return getNextHostNode(vnode.component.subTree);
  7092. }
  7093. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  7094. return vnode.suspense.next();
  7095. }
  7096. return hostNextSibling((vnode.anchor || vnode.el));
  7097. };
  7098. const render = (vnode, container, isSVG) => {
  7099. if (vnode == null) {
  7100. if (container._vnode) {
  7101. unmount(container._vnode, null, null, true);
  7102. }
  7103. }
  7104. else {
  7105. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7106. }
  7107. flushPostFlushCbs();
  7108. container._vnode = vnode;
  7109. };
  7110. const internals = {
  7111. p: patch,
  7112. um: unmount,
  7113. m: move,
  7114. r: remove,
  7115. mt: mountComponent,
  7116. mc: mountChildren,
  7117. pc: patchChildren,
  7118. pbc: patchBlockChildren,
  7119. n: getNextHostNode,
  7120. o: options
  7121. };
  7122. let hydrate;
  7123. let hydrateNode;
  7124. if (createHydrationFns) {
  7125. [hydrate, hydrateNode] = createHydrationFns(internals);
  7126. }
  7127. return {
  7128. render,
  7129. hydrate,
  7130. createApp: createAppAPI(render, hydrate)
  7131. };
  7132. }
  7133. function toggleRecurse({ effect, update }, allowed) {
  7134. effect.allowRecurse = update.allowRecurse = allowed;
  7135. }
  7136. /**
  7137. * #1156
  7138. * When a component is HMR-enabled, we need to make sure that all static nodes
  7139. * inside a block also inherit the DOM element from the previous tree so that
  7140. * HMR updates (which are full updates) can retrieve the element for patching.
  7141. *
  7142. * #2080
  7143. * Inside keyed `template` fragment static children, if a fragment is moved,
  7144. * the children will always be moved. Therefore, in order to ensure correct move
  7145. * position, el should be inherited from previous nodes.
  7146. */
  7147. function traverseStaticChildren(n1, n2, shallow = false) {
  7148. const ch1 = n1.children;
  7149. const ch2 = n2.children;
  7150. if (isArray(ch1) && isArray(ch2)) {
  7151. for (let i = 0; i < ch1.length; i++) {
  7152. // this is only called in the optimized path so array children are
  7153. // guaranteed to be vnodes
  7154. const c1 = ch1[i];
  7155. let c2 = ch2[i];
  7156. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  7157. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  7158. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7159. c2.el = c1.el;
  7160. }
  7161. if (!shallow)
  7162. traverseStaticChildren(c1, c2);
  7163. }
  7164. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7165. // would have received .el during block patch)
  7166. if (c2.type === Comment && !c2.el) {
  7167. c2.el = c1.el;
  7168. }
  7169. }
  7170. }
  7171. }
  7172. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7173. function getSequence(arr) {
  7174. const p = arr.slice();
  7175. const result = [0];
  7176. let i, j, u, v, c;
  7177. const len = arr.length;
  7178. for (i = 0; i < len; i++) {
  7179. const arrI = arr[i];
  7180. if (arrI !== 0) {
  7181. j = result[result.length - 1];
  7182. if (arr[j] < arrI) {
  7183. p[i] = j;
  7184. result.push(i);
  7185. continue;
  7186. }
  7187. u = 0;
  7188. v = result.length - 1;
  7189. while (u < v) {
  7190. c = (u + v) >> 1;
  7191. if (arr[result[c]] < arrI) {
  7192. u = c + 1;
  7193. }
  7194. else {
  7195. v = c;
  7196. }
  7197. }
  7198. if (arrI < arr[result[u]]) {
  7199. if (u > 0) {
  7200. p[i] = result[u - 1];
  7201. }
  7202. result[u] = i;
  7203. }
  7204. }
  7205. }
  7206. u = result.length;
  7207. v = result[u - 1];
  7208. while (u-- > 0) {
  7209. result[u] = v;
  7210. v = p[v];
  7211. }
  7212. return result;
  7213. }
  7214. const isTeleport = (type) => type.__isTeleport;
  7215. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7216. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7217. const resolveTarget = (props, select) => {
  7218. const targetSelector = props && props.to;
  7219. if (isString(targetSelector)) {
  7220. if (!select) {
  7221. warn$1(`Current renderer does not support string target for Teleports. ` +
  7222. `(missing querySelector renderer option)`);
  7223. return null;
  7224. }
  7225. else {
  7226. const target = select(targetSelector);
  7227. if (!target) {
  7228. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7229. `Note the target element must exist before the component is mounted - ` +
  7230. `i.e. the target cannot be rendered by the component itself, and ` +
  7231. `ideally should be outside of the entire Vue component tree.`);
  7232. }
  7233. return target;
  7234. }
  7235. }
  7236. else {
  7237. if (!targetSelector && !isTeleportDisabled(props)) {
  7238. warn$1(`Invalid Teleport target: ${targetSelector}`);
  7239. }
  7240. return targetSelector;
  7241. }
  7242. };
  7243. const TeleportImpl = {
  7244. __isTeleport: true,
  7245. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7246. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7247. const disabled = isTeleportDisabled(n2.props);
  7248. let { shapeFlag, children, dynamicChildren } = n2;
  7249. // #3302
  7250. // HMR updated, force full diff
  7251. if (isHmrUpdating) {
  7252. optimized = false;
  7253. dynamicChildren = null;
  7254. }
  7255. if (n1 == null) {
  7256. // insert anchors in the main view
  7257. const placeholder = (n2.el = createComment('teleport start')
  7258. );
  7259. const mainAnchor = (n2.anchor = createComment('teleport end')
  7260. );
  7261. insert(placeholder, container, anchor);
  7262. insert(mainAnchor, container, anchor);
  7263. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7264. const targetAnchor = (n2.targetAnchor = createText(''));
  7265. if (target) {
  7266. insert(targetAnchor, target);
  7267. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7268. isSVG = isSVG || isTargetSVG(target);
  7269. }
  7270. else if (!disabled) {
  7271. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7272. }
  7273. const mount = (container, anchor) => {
  7274. // Teleport *always* has Array children. This is enforced in both the
  7275. // compiler and vnode children normalization.
  7276. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7277. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7278. }
  7279. };
  7280. if (disabled) {
  7281. mount(container, mainAnchor);
  7282. }
  7283. else if (target) {
  7284. mount(target, targetAnchor);
  7285. }
  7286. }
  7287. else {
  7288. // update content
  7289. n2.el = n1.el;
  7290. const mainAnchor = (n2.anchor = n1.anchor);
  7291. const target = (n2.target = n1.target);
  7292. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7293. const wasDisabled = isTeleportDisabled(n1.props);
  7294. const currentContainer = wasDisabled ? container : target;
  7295. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7296. isSVG = isSVG || isTargetSVG(target);
  7297. if (dynamicChildren) {
  7298. // fast path when the teleport happens to be a block root
  7299. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7300. // even in block tree mode we need to make sure all root-level nodes
  7301. // in the teleport inherit previous DOM references so that they can
  7302. // be moved in future patches.
  7303. traverseStaticChildren(n1, n2, true);
  7304. }
  7305. else if (!optimized) {
  7306. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7307. }
  7308. if (disabled) {
  7309. if (!wasDisabled) {
  7310. // enabled -> disabled
  7311. // move into main container
  7312. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  7313. }
  7314. }
  7315. else {
  7316. // target changed
  7317. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7318. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7319. if (nextTarget) {
  7320. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  7321. }
  7322. else {
  7323. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  7324. }
  7325. }
  7326. else if (wasDisabled) {
  7327. // disabled -> enabled
  7328. // move into teleport target
  7329. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  7330. }
  7331. }
  7332. }
  7333. },
  7334. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7335. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7336. if (target) {
  7337. hostRemove(targetAnchor);
  7338. }
  7339. // an unmounted teleport should always remove its children if not disabled
  7340. if (doRemove || !isTeleportDisabled(props)) {
  7341. hostRemove(anchor);
  7342. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7343. for (let i = 0; i < children.length; i++) {
  7344. const child = children[i];
  7345. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7346. }
  7347. }
  7348. }
  7349. },
  7350. move: moveTeleport,
  7351. hydrate: hydrateTeleport
  7352. };
  7353. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  7354. // move target anchor if this is a target change.
  7355. if (moveType === 0 /* TARGET_CHANGE */) {
  7356. insert(vnode.targetAnchor, container, parentAnchor);
  7357. }
  7358. const { el, anchor, shapeFlag, children, props } = vnode;
  7359. const isReorder = moveType === 2 /* REORDER */;
  7360. // move main view anchor if this is a re-order.
  7361. if (isReorder) {
  7362. insert(el, container, parentAnchor);
  7363. }
  7364. // if this is a re-order and teleport is enabled (content is in target)
  7365. // do not move children. So the opposite is: only move children if this
  7366. // is not a reorder, or the teleport is disabled
  7367. if (!isReorder || isTeleportDisabled(props)) {
  7368. // Teleport has either Array children or no children.
  7369. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7370. for (let i = 0; i < children.length; i++) {
  7371. move(children[i], container, parentAnchor, 2 /* REORDER */);
  7372. }
  7373. }
  7374. }
  7375. // move main view anchor if this is a re-order.
  7376. if (isReorder) {
  7377. insert(anchor, container, parentAnchor);
  7378. }
  7379. }
  7380. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7381. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7382. if (target) {
  7383. // if multiple teleports rendered to the same target element, we need to
  7384. // pick up from where the last teleport finished instead of the first node
  7385. const targetNode = target._lpa || target.firstChild;
  7386. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7387. if (isTeleportDisabled(vnode.props)) {
  7388. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7389. vnode.targetAnchor = targetNode;
  7390. }
  7391. else {
  7392. vnode.anchor = nextSibling(node);
  7393. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7394. }
  7395. target._lpa =
  7396. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7397. }
  7398. }
  7399. return vnode.anchor && nextSibling(vnode.anchor);
  7400. }
  7401. // Force-casted public typing for h and TSX props inference
  7402. const Teleport = TeleportImpl;
  7403. const COMPONENTS = 'components';
  7404. const DIRECTIVES = 'directives';
  7405. /**
  7406. * @private
  7407. */
  7408. function resolveComponent(name, maybeSelfReference) {
  7409. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  7410. }
  7411. const NULL_DYNAMIC_COMPONENT = Symbol();
  7412. /**
  7413. * @private
  7414. */
  7415. function resolveDynamicComponent(component) {
  7416. if (isString(component)) {
  7417. return resolveAsset(COMPONENTS, component, false) || component;
  7418. }
  7419. else {
  7420. // invalid types will fallthrough to createVNode and raise warning
  7421. return (component || NULL_DYNAMIC_COMPONENT);
  7422. }
  7423. }
  7424. /**
  7425. * @private
  7426. */
  7427. function resolveDirective(name) {
  7428. return resolveAsset(DIRECTIVES, name);
  7429. }
  7430. // implementation
  7431. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  7432. const instance = currentRenderingInstance || currentInstance;
  7433. if (instance) {
  7434. const Component = instance.type;
  7435. // explicit self name has highest priority
  7436. if (type === COMPONENTS) {
  7437. const selfName = getComponentName(Component);
  7438. if (selfName &&
  7439. (selfName === name ||
  7440. selfName === camelize(name) ||
  7441. selfName === capitalize(camelize(name)))) {
  7442. return Component;
  7443. }
  7444. }
  7445. const res =
  7446. // local registration
  7447. // check instance[type] first which is resolved for options API
  7448. resolve(instance[type] || Component[type], name) ||
  7449. // global registration
  7450. resolve(instance.appContext[type], name);
  7451. if (!res && maybeSelfReference) {
  7452. // fallback to implicit self-reference
  7453. return Component;
  7454. }
  7455. if (warnMissing && !res) {
  7456. const extra = type === COMPONENTS
  7457. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  7458. `component resolution via compilerOptions.isCustomElement.`
  7459. : ``;
  7460. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  7461. }
  7462. return res;
  7463. }
  7464. else {
  7465. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  7466. `can only be used in render() or setup().`);
  7467. }
  7468. }
  7469. function resolve(registry, name) {
  7470. return (registry &&
  7471. (registry[name] ||
  7472. registry[camelize(name)] ||
  7473. registry[capitalize(camelize(name))]));
  7474. }
  7475. const Fragment = Symbol('Fragment' );
  7476. const Text = Symbol('Text' );
  7477. const Comment = Symbol('Comment' );
  7478. const Static = Symbol('Static' );
  7479. // Since v-if and v-for are the two possible ways node structure can dynamically
  7480. // change, once we consider v-if branches and each v-for fragment a block, we
  7481. // can divide a template into nested blocks, and within each block the node
  7482. // structure would be stable. This allows us to skip most children diffing
  7483. // and only worry about the dynamic nodes (indicated by patch flags).
  7484. const blockStack = [];
  7485. let currentBlock = null;
  7486. /**
  7487. * Open a block.
  7488. * This must be called before `createBlock`. It cannot be part of `createBlock`
  7489. * because the children of the block are evaluated before `createBlock` itself
  7490. * is called. The generated code typically looks like this:
  7491. *
  7492. * ```js
  7493. * function render() {
  7494. * return (openBlock(),createBlock('div', null, [...]))
  7495. * }
  7496. * ```
  7497. * disableTracking is true when creating a v-for fragment block, since a v-for
  7498. * fragment always diffs its children.
  7499. *
  7500. * @private
  7501. */
  7502. function openBlock(disableTracking = false) {
  7503. blockStack.push((currentBlock = disableTracking ? null : []));
  7504. }
  7505. function closeBlock() {
  7506. blockStack.pop();
  7507. currentBlock = blockStack[blockStack.length - 1] || null;
  7508. }
  7509. // Whether we should be tracking dynamic child nodes inside a block.
  7510. // Only tracks when this value is > 0
  7511. // We are not using a simple boolean because this value may need to be
  7512. // incremented/decremented by nested usage of v-once (see below)
  7513. let isBlockTreeEnabled = 1;
  7514. /**
  7515. * Block tracking sometimes needs to be disabled, for example during the
  7516. * creation of a tree that needs to be cached by v-once. The compiler generates
  7517. * code like this:
  7518. *
  7519. * ``` js
  7520. * _cache[1] || (
  7521. * setBlockTracking(-1),
  7522. * _cache[1] = createVNode(...),
  7523. * setBlockTracking(1),
  7524. * _cache[1]
  7525. * )
  7526. * ```
  7527. *
  7528. * @private
  7529. */
  7530. function setBlockTracking(value) {
  7531. isBlockTreeEnabled += value;
  7532. }
  7533. function setupBlock(vnode) {
  7534. // save current block children on the block vnode
  7535. vnode.dynamicChildren =
  7536. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  7537. // close block
  7538. closeBlock();
  7539. // a block is always going to be patched, so track it as a child of its
  7540. // parent block
  7541. if (isBlockTreeEnabled > 0 && currentBlock) {
  7542. currentBlock.push(vnode);
  7543. }
  7544. return vnode;
  7545. }
  7546. /**
  7547. * @private
  7548. */
  7549. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  7550. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  7551. }
  7552. /**
  7553. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  7554. * A block root keeps track of dynamic nodes within the block in the
  7555. * `dynamicChildren` array.
  7556. *
  7557. * @private
  7558. */
  7559. function createBlock(type, props, children, patchFlag, dynamicProps) {
  7560. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  7561. }
  7562. function isVNode(value) {
  7563. return value ? value.__v_isVNode === true : false;
  7564. }
  7565. function isSameVNodeType(n1, n2) {
  7566. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  7567. hmrDirtyComponents.has(n2.type)) {
  7568. // HMR only: if the component has been hot-updated, force a reload.
  7569. return false;
  7570. }
  7571. return n1.type === n2.type && n1.key === n2.key;
  7572. }
  7573. let vnodeArgsTransformer;
  7574. /**
  7575. * Internal API for registering an arguments transform for createVNode
  7576. * used for creating stubs in the test-utils
  7577. * It is *internal* but needs to be exposed for test-utils to pick up proper
  7578. * typings
  7579. */
  7580. function transformVNodeArgs(transformer) {
  7581. vnodeArgsTransformer = transformer;
  7582. }
  7583. const createVNodeWithArgsTransform = (...args) => {
  7584. return _createVNode(...(vnodeArgsTransformer
  7585. ? vnodeArgsTransformer(args, currentRenderingInstance)
  7586. : args));
  7587. };
  7588. const InternalObjectKey = `__vInternal`;
  7589. const normalizeKey = ({ key }) => key != null ? key : null;
  7590. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  7591. return (ref != null
  7592. ? isString(ref) || isRef(ref) || isFunction(ref)
  7593. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  7594. : ref
  7595. : null);
  7596. };
  7597. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  7598. const vnode = {
  7599. __v_isVNode: true,
  7600. __v_skip: true,
  7601. type,
  7602. props,
  7603. key: props && normalizeKey(props),
  7604. ref: props && normalizeRef(props),
  7605. scopeId: currentScopeId,
  7606. slotScopeIds: null,
  7607. children,
  7608. component: null,
  7609. suspense: null,
  7610. ssContent: null,
  7611. ssFallback: null,
  7612. dirs: null,
  7613. transition: null,
  7614. el: null,
  7615. anchor: null,
  7616. target: null,
  7617. targetAnchor: null,
  7618. staticCount: 0,
  7619. shapeFlag,
  7620. patchFlag,
  7621. dynamicProps,
  7622. dynamicChildren: null,
  7623. appContext: null
  7624. };
  7625. if (needFullChildrenNormalization) {
  7626. normalizeChildren(vnode, children);
  7627. // normalize suspense children
  7628. if (shapeFlag & 128 /* SUSPENSE */) {
  7629. type.normalize(vnode);
  7630. }
  7631. }
  7632. else if (children) {
  7633. // compiled element vnode - if children is passed, only possible types are
  7634. // string or Array.
  7635. vnode.shapeFlag |= isString(children)
  7636. ? 8 /* TEXT_CHILDREN */
  7637. : 16 /* ARRAY_CHILDREN */;
  7638. }
  7639. // validate key
  7640. if (vnode.key !== vnode.key) {
  7641. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  7642. }
  7643. // track vnode for block tree
  7644. if (isBlockTreeEnabled > 0 &&
  7645. // avoid a block node from tracking itself
  7646. !isBlockNode &&
  7647. // has current parent block
  7648. currentBlock &&
  7649. // presence of a patch flag indicates this node needs patching on updates.
  7650. // component nodes also should always be patched, because even if the
  7651. // component doesn't need to update, it needs to persist the instance on to
  7652. // the next vnode so that it can be properly unmounted later.
  7653. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  7654. // the EVENTS flag is only for hydration and if it is the only flag, the
  7655. // vnode should not be considered dynamic due to handler caching.
  7656. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  7657. currentBlock.push(vnode);
  7658. }
  7659. return vnode;
  7660. }
  7661. const createVNode = (createVNodeWithArgsTransform );
  7662. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  7663. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  7664. if (!type) {
  7665. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  7666. }
  7667. type = Comment;
  7668. }
  7669. if (isVNode(type)) {
  7670. // createVNode receiving an existing vnode. This happens in cases like
  7671. // <component :is="vnode"/>
  7672. // #2078 make sure to merge refs during the clone instead of overwriting it
  7673. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  7674. if (children) {
  7675. normalizeChildren(cloned, children);
  7676. }
  7677. return cloned;
  7678. }
  7679. // class component normalization.
  7680. if (isClassComponent(type)) {
  7681. type = type.__vccOpts;
  7682. }
  7683. // class & style normalization.
  7684. if (props) {
  7685. // for reactive or proxy objects, we need to clone it to enable mutation.
  7686. props = guardReactiveProps(props);
  7687. let { class: klass, style } = props;
  7688. if (klass && !isString(klass)) {
  7689. props.class = normalizeClass(klass);
  7690. }
  7691. if (isObject(style)) {
  7692. // reactive state objects need to be cloned since they are likely to be
  7693. // mutated
  7694. if (isProxy(style) && !isArray(style)) {
  7695. style = extend({}, style);
  7696. }
  7697. props.style = normalizeStyle(style);
  7698. }
  7699. }
  7700. // encode the vnode type information into a bitmap
  7701. const shapeFlag = isString(type)
  7702. ? 1 /* ELEMENT */
  7703. : isSuspense(type)
  7704. ? 128 /* SUSPENSE */
  7705. : isTeleport(type)
  7706. ? 64 /* TELEPORT */
  7707. : isObject(type)
  7708. ? 4 /* STATEFUL_COMPONENT */
  7709. : isFunction(type)
  7710. ? 2 /* FUNCTIONAL_COMPONENT */
  7711. : 0;
  7712. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  7713. type = toRaw(type);
  7714. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  7715. `lead to unnecessary performance overhead, and should be avoided by ` +
  7716. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  7717. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  7718. }
  7719. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  7720. }
  7721. function guardReactiveProps(props) {
  7722. if (!props)
  7723. return null;
  7724. return isProxy(props) || InternalObjectKey in props
  7725. ? extend({}, props)
  7726. : props;
  7727. }
  7728. function cloneVNode(vnode, extraProps, mergeRef = false) {
  7729. // This is intentionally NOT using spread or extend to avoid the runtime
  7730. // key enumeration cost.
  7731. const { props, ref, patchFlag, children } = vnode;
  7732. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  7733. const cloned = {
  7734. __v_isVNode: true,
  7735. __v_skip: true,
  7736. type: vnode.type,
  7737. props: mergedProps,
  7738. key: mergedProps && normalizeKey(mergedProps),
  7739. ref: extraProps && extraProps.ref
  7740. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  7741. // if the vnode itself already has a ref, cloneVNode will need to merge
  7742. // the refs so the single vnode can be set on multiple refs
  7743. mergeRef && ref
  7744. ? isArray(ref)
  7745. ? ref.concat(normalizeRef(extraProps))
  7746. : [ref, normalizeRef(extraProps)]
  7747. : normalizeRef(extraProps)
  7748. : ref,
  7749. scopeId: vnode.scopeId,
  7750. slotScopeIds: vnode.slotScopeIds,
  7751. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  7752. ? children.map(deepCloneVNode)
  7753. : children,
  7754. target: vnode.target,
  7755. targetAnchor: vnode.targetAnchor,
  7756. staticCount: vnode.staticCount,
  7757. shapeFlag: vnode.shapeFlag,
  7758. // if the vnode is cloned with extra props, we can no longer assume its
  7759. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  7760. // note: preserve flag for fragments since they use the flag for children
  7761. // fast paths only.
  7762. patchFlag: extraProps && vnode.type !== Fragment
  7763. ? patchFlag === -1 // hoisted node
  7764. ? 16 /* FULL_PROPS */
  7765. : patchFlag | 16 /* FULL_PROPS */
  7766. : patchFlag,
  7767. dynamicProps: vnode.dynamicProps,
  7768. dynamicChildren: vnode.dynamicChildren,
  7769. appContext: vnode.appContext,
  7770. dirs: vnode.dirs,
  7771. transition: vnode.transition,
  7772. // These should technically only be non-null on mounted VNodes. However,
  7773. // they *should* be copied for kept-alive vnodes. So we just always copy
  7774. // them since them being non-null during a mount doesn't affect the logic as
  7775. // they will simply be overwritten.
  7776. component: vnode.component,
  7777. suspense: vnode.suspense,
  7778. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  7779. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  7780. el: vnode.el,
  7781. anchor: vnode.anchor
  7782. };
  7783. return cloned;
  7784. }
  7785. /**
  7786. * Dev only, for HMR of hoisted vnodes reused in v-for
  7787. * https://github.com/vitejs/vite/issues/2022
  7788. */
  7789. function deepCloneVNode(vnode) {
  7790. const cloned = cloneVNode(vnode);
  7791. if (isArray(vnode.children)) {
  7792. cloned.children = vnode.children.map(deepCloneVNode);
  7793. }
  7794. return cloned;
  7795. }
  7796. /**
  7797. * @private
  7798. */
  7799. function createTextVNode(text = ' ', flag = 0) {
  7800. return createVNode(Text, null, text, flag);
  7801. }
  7802. /**
  7803. * @private
  7804. */
  7805. function createStaticVNode(content, numberOfNodes) {
  7806. // A static vnode can contain multiple stringified elements, and the number
  7807. // of elements is necessary for hydration.
  7808. const vnode = createVNode(Static, null, content);
  7809. vnode.staticCount = numberOfNodes;
  7810. return vnode;
  7811. }
  7812. /**
  7813. * @private
  7814. */
  7815. function createCommentVNode(text = '',
  7816. // when used as the v-else branch, the comment node must be created as a
  7817. // block to ensure correct updates.
  7818. asBlock = false) {
  7819. return asBlock
  7820. ? (openBlock(), createBlock(Comment, null, text))
  7821. : createVNode(Comment, null, text);
  7822. }
  7823. function normalizeVNode(child) {
  7824. if (child == null || typeof child === 'boolean') {
  7825. // empty placeholder
  7826. return createVNode(Comment);
  7827. }
  7828. else if (isArray(child)) {
  7829. // fragment
  7830. return createVNode(Fragment, null,
  7831. // #3666, avoid reference pollution when reusing vnode
  7832. child.slice());
  7833. }
  7834. else if (typeof child === 'object') {
  7835. // already vnode, this should be the most common since compiled templates
  7836. // always produce all-vnode children arrays
  7837. return cloneIfMounted(child);
  7838. }
  7839. else {
  7840. // strings and numbers
  7841. return createVNode(Text, null, String(child));
  7842. }
  7843. }
  7844. // optimized normalization for template-compiled render fns
  7845. function cloneIfMounted(child) {
  7846. return child.el === null || child.memo ? child : cloneVNode(child);
  7847. }
  7848. function normalizeChildren(vnode, children) {
  7849. let type = 0;
  7850. const { shapeFlag } = vnode;
  7851. if (children == null) {
  7852. children = null;
  7853. }
  7854. else if (isArray(children)) {
  7855. type = 16 /* ARRAY_CHILDREN */;
  7856. }
  7857. else if (typeof children === 'object') {
  7858. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  7859. // Normalize slot to plain children for plain element and Teleport
  7860. const slot = children.default;
  7861. if (slot) {
  7862. // _c marker is added by withCtx() indicating this is a compiled slot
  7863. slot._c && (slot._d = false);
  7864. normalizeChildren(vnode, slot());
  7865. slot._c && (slot._d = true);
  7866. }
  7867. return;
  7868. }
  7869. else {
  7870. type = 32 /* SLOTS_CHILDREN */;
  7871. const slotFlag = children._;
  7872. if (!slotFlag && !(InternalObjectKey in children)) {
  7873. children._ctx = currentRenderingInstance;
  7874. }
  7875. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  7876. // a child component receives forwarded slots from the parent.
  7877. // its slot type is determined by its parent's slot type.
  7878. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  7879. children._ = 1 /* STABLE */;
  7880. }
  7881. else {
  7882. children._ = 2 /* DYNAMIC */;
  7883. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  7884. }
  7885. }
  7886. }
  7887. }
  7888. else if (isFunction(children)) {
  7889. children = { default: children, _ctx: currentRenderingInstance };
  7890. type = 32 /* SLOTS_CHILDREN */;
  7891. }
  7892. else {
  7893. children = String(children);
  7894. // force teleport children to array so it can be moved around
  7895. if (shapeFlag & 64 /* TELEPORT */) {
  7896. type = 16 /* ARRAY_CHILDREN */;
  7897. children = [createTextVNode(children)];
  7898. }
  7899. else {
  7900. type = 8 /* TEXT_CHILDREN */;
  7901. }
  7902. }
  7903. vnode.children = children;
  7904. vnode.shapeFlag |= type;
  7905. }
  7906. function mergeProps(...args) {
  7907. const ret = {};
  7908. for (let i = 0; i < args.length; i++) {
  7909. const toMerge = args[i];
  7910. for (const key in toMerge) {
  7911. if (key === 'class') {
  7912. if (ret.class !== toMerge.class) {
  7913. ret.class = normalizeClass([ret.class, toMerge.class]);
  7914. }
  7915. }
  7916. else if (key === 'style') {
  7917. ret.style = normalizeStyle([ret.style, toMerge.style]);
  7918. }
  7919. else if (isOn(key)) {
  7920. const existing = ret[key];
  7921. const incoming = toMerge[key];
  7922. if (incoming &&
  7923. existing !== incoming &&
  7924. !(isArray(existing) && existing.includes(incoming))) {
  7925. ret[key] = existing
  7926. ? [].concat(existing, incoming)
  7927. : incoming;
  7928. }
  7929. }
  7930. else if (key !== '') {
  7931. ret[key] = toMerge[key];
  7932. }
  7933. }
  7934. }
  7935. return ret;
  7936. }
  7937. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  7938. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  7939. vnode,
  7940. prevVNode
  7941. ]);
  7942. }
  7943. /**
  7944. * Actual implementation
  7945. */
  7946. function renderList(source, renderItem, cache, index) {
  7947. let ret;
  7948. const cached = (cache && cache[index]);
  7949. if (isArray(source) || isString(source)) {
  7950. ret = new Array(source.length);
  7951. for (let i = 0, l = source.length; i < l; i++) {
  7952. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  7953. }
  7954. }
  7955. else if (typeof source === 'number') {
  7956. if (!Number.isInteger(source)) {
  7957. warn$1(`The v-for range expect an integer value but got ${source}.`);
  7958. return [];
  7959. }
  7960. ret = new Array(source);
  7961. for (let i = 0; i < source; i++) {
  7962. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  7963. }
  7964. }
  7965. else if (isObject(source)) {
  7966. if (source[Symbol.iterator]) {
  7967. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  7968. }
  7969. else {
  7970. const keys = Object.keys(source);
  7971. ret = new Array(keys.length);
  7972. for (let i = 0, l = keys.length; i < l; i++) {
  7973. const key = keys[i];
  7974. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  7975. }
  7976. }
  7977. }
  7978. else {
  7979. ret = [];
  7980. }
  7981. if (cache) {
  7982. cache[index] = ret;
  7983. }
  7984. return ret;
  7985. }
  7986. /**
  7987. * Compiler runtime helper for creating dynamic slots object
  7988. * @private
  7989. */
  7990. function createSlots(slots, dynamicSlots) {
  7991. for (let i = 0; i < dynamicSlots.length; i++) {
  7992. const slot = dynamicSlots[i];
  7993. // array of dynamic slot generated by <template v-for="..." #[...]>
  7994. if (isArray(slot)) {
  7995. for (let j = 0; j < slot.length; j++) {
  7996. slots[slot[j].name] = slot[j].fn;
  7997. }
  7998. }
  7999. else if (slot) {
  8000. // conditional single slot generated by <template v-if="..." #foo>
  8001. slots[slot.name] = slot.fn;
  8002. }
  8003. }
  8004. return slots;
  8005. }
  8006. /**
  8007. * Compiler runtime helper for rendering `<slot/>`
  8008. * @private
  8009. */
  8010. function renderSlot(slots, name, props = {},
  8011. // this is not a user-facing function, so the fallback is always generated by
  8012. // the compiler and guaranteed to be a function returning an array
  8013. fallback, noSlotted) {
  8014. if (currentRenderingInstance.isCE ||
  8015. (currentRenderingInstance.parent &&
  8016. isAsyncWrapper(currentRenderingInstance.parent) &&
  8017. currentRenderingInstance.parent.isCE)) {
  8018. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  8019. }
  8020. let slot = slots[name];
  8021. if (slot && slot.length > 1) {
  8022. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  8023. `function. You need to mark this component with $dynamic-slots in the ` +
  8024. `parent template.`);
  8025. slot = () => [];
  8026. }
  8027. // a compiled slot disables block tracking by default to avoid manual
  8028. // invocation interfering with template-based block tracking, but in
  8029. // `renderSlot` we can be sure that it's template-based so we can force
  8030. // enable it.
  8031. if (slot && slot._c) {
  8032. slot._d = false;
  8033. }
  8034. openBlock();
  8035. const validSlotContent = slot && ensureValidVNode(slot(props));
  8036. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  8037. ? 64 /* STABLE_FRAGMENT */
  8038. : -2 /* BAIL */);
  8039. if (!noSlotted && rendered.scopeId) {
  8040. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  8041. }
  8042. if (slot && slot._c) {
  8043. slot._d = true;
  8044. }
  8045. return rendered;
  8046. }
  8047. function ensureValidVNode(vnodes) {
  8048. return vnodes.some(child => {
  8049. if (!isVNode(child))
  8050. return true;
  8051. if (child.type === Comment)
  8052. return false;
  8053. if (child.type === Fragment &&
  8054. !ensureValidVNode(child.children))
  8055. return false;
  8056. return true;
  8057. })
  8058. ? vnodes
  8059. : null;
  8060. }
  8061. /**
  8062. * For prefixing keys in v-on="obj" with "on"
  8063. * @private
  8064. */
  8065. function toHandlers(obj) {
  8066. const ret = {};
  8067. if (!isObject(obj)) {
  8068. warn$1(`v-on with no argument expects an object value.`);
  8069. return ret;
  8070. }
  8071. for (const key in obj) {
  8072. ret[toHandlerKey(key)] = obj[key];
  8073. }
  8074. return ret;
  8075. }
  8076. /**
  8077. * #2437 In Vue 3, functional components do not have a public instance proxy but
  8078. * they exist in the internal parent chain. For code that relies on traversing
  8079. * public $parent chains, skip functional ones and go to the parent instead.
  8080. */
  8081. const getPublicInstance = (i) => {
  8082. if (!i)
  8083. return null;
  8084. if (isStatefulComponent(i))
  8085. return getExposeProxy(i) || i.proxy;
  8086. return getPublicInstance(i.parent);
  8087. };
  8088. const publicPropertiesMap =
  8089. // Move PURE marker to new line to workaround compiler discarding it
  8090. // due to type annotation
  8091. /*#__PURE__*/ extend(Object.create(null), {
  8092. $: i => i,
  8093. $el: i => i.vnode.el,
  8094. $data: i => i.data,
  8095. $props: i => (shallowReadonly(i.props) ),
  8096. $attrs: i => (shallowReadonly(i.attrs) ),
  8097. $slots: i => (shallowReadonly(i.slots) ),
  8098. $refs: i => (shallowReadonly(i.refs) ),
  8099. $parent: i => getPublicInstance(i.parent),
  8100. $root: i => getPublicInstance(i.root),
  8101. $emit: i => i.emit,
  8102. $options: i => (resolveMergedOptions(i) ),
  8103. $forceUpdate: i => () => queueJob(i.update),
  8104. $nextTick: i => nextTick.bind(i.proxy),
  8105. $watch: i => (instanceWatch.bind(i) )
  8106. });
  8107. const PublicInstanceProxyHandlers = {
  8108. get({ _: instance }, key) {
  8109. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  8110. // for internal formatters to know that this is a Vue instance
  8111. if (key === '__isVue') {
  8112. return true;
  8113. }
  8114. // prioritize <script setup> bindings during dev.
  8115. // this allows even properties that start with _ or $ to be used - so that
  8116. // it aligns with the production behavior where the render fn is inlined and
  8117. // indeed has access to all declared variables.
  8118. if (setupState !== EMPTY_OBJ &&
  8119. setupState.__isScriptSetup &&
  8120. hasOwn(setupState, key)) {
  8121. return setupState[key];
  8122. }
  8123. // data / props / ctx
  8124. // This getter gets called for every property access on the render context
  8125. // during render and is a major hotspot. The most expensive part of this
  8126. // is the multiple hasOwn() calls. It's much faster to do a simple property
  8127. // access on a plain object, so we use an accessCache object (with null
  8128. // prototype) to memoize what access type a key corresponds to.
  8129. let normalizedProps;
  8130. if (key[0] !== '$') {
  8131. const n = accessCache[key];
  8132. if (n !== undefined) {
  8133. switch (n) {
  8134. case 1 /* SETUP */:
  8135. return setupState[key];
  8136. case 2 /* DATA */:
  8137. return data[key];
  8138. case 4 /* CONTEXT */:
  8139. return ctx[key];
  8140. case 3 /* PROPS */:
  8141. return props[key];
  8142. // default: just fallthrough
  8143. }
  8144. }
  8145. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  8146. accessCache[key] = 1 /* SETUP */;
  8147. return setupState[key];
  8148. }
  8149. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  8150. accessCache[key] = 2 /* DATA */;
  8151. return data[key];
  8152. }
  8153. else if (
  8154. // only cache other properties when instance has declared (thus stable)
  8155. // props
  8156. (normalizedProps = instance.propsOptions[0]) &&
  8157. hasOwn(normalizedProps, key)) {
  8158. accessCache[key] = 3 /* PROPS */;
  8159. return props[key];
  8160. }
  8161. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  8162. accessCache[key] = 4 /* CONTEXT */;
  8163. return ctx[key];
  8164. }
  8165. else if (shouldCacheAccess) {
  8166. accessCache[key] = 0 /* OTHER */;
  8167. }
  8168. }
  8169. const publicGetter = publicPropertiesMap[key];
  8170. let cssModule, globalProperties;
  8171. // public $xxx properties
  8172. if (publicGetter) {
  8173. if (key === '$attrs') {
  8174. track(instance, "get" /* GET */, key);
  8175. markAttrsAccessed();
  8176. }
  8177. return publicGetter(instance);
  8178. }
  8179. else if (
  8180. // css module (injected by vue-loader)
  8181. (cssModule = type.__cssModules) &&
  8182. (cssModule = cssModule[key])) {
  8183. return cssModule;
  8184. }
  8185. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  8186. // user may set custom properties to `this` that start with `$`
  8187. accessCache[key] = 4 /* CONTEXT */;
  8188. return ctx[key];
  8189. }
  8190. else if (
  8191. // global properties
  8192. ((globalProperties = appContext.config.globalProperties),
  8193. hasOwn(globalProperties, key))) {
  8194. {
  8195. return globalProperties[key];
  8196. }
  8197. }
  8198. else if (currentRenderingInstance &&
  8199. (!isString(key) ||
  8200. // #1091 avoid internal isRef/isVNode checks on component instance leading
  8201. // to infinite warning loop
  8202. key.indexOf('__v') !== 0)) {
  8203. if (data !== EMPTY_OBJ &&
  8204. (key[0] === '$' || key[0] === '_') &&
  8205. hasOwn(data, key)) {
  8206. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  8207. `character ("$" or "_") and is not proxied on the render context.`);
  8208. }
  8209. else if (instance === currentRenderingInstance) {
  8210. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  8211. `but is not defined on instance.`);
  8212. }
  8213. }
  8214. },
  8215. set({ _: instance }, key, value) {
  8216. const { data, setupState, ctx } = instance;
  8217. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  8218. setupState[key] = value;
  8219. return true;
  8220. }
  8221. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  8222. data[key] = value;
  8223. return true;
  8224. }
  8225. else if (hasOwn(instance.props, key)) {
  8226. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  8227. return false;
  8228. }
  8229. if (key[0] === '$' && key.slice(1) in instance) {
  8230. warn$1(`Attempting to mutate public property "${key}". ` +
  8231. `Properties starting with $ are reserved and readonly.`, instance);
  8232. return false;
  8233. }
  8234. else {
  8235. if (key in instance.appContext.config.globalProperties) {
  8236. Object.defineProperty(ctx, key, {
  8237. enumerable: true,
  8238. configurable: true,
  8239. value
  8240. });
  8241. }
  8242. else {
  8243. ctx[key] = value;
  8244. }
  8245. }
  8246. return true;
  8247. },
  8248. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  8249. let normalizedProps;
  8250. return (!!accessCache[key] ||
  8251. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  8252. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  8253. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  8254. hasOwn(ctx, key) ||
  8255. hasOwn(publicPropertiesMap, key) ||
  8256. hasOwn(appContext.config.globalProperties, key));
  8257. },
  8258. defineProperty(target, key, descriptor) {
  8259. if (descriptor.get != null) {
  8260. // invalidate key cache of a getter based property #5417
  8261. target._.accessCache[key] = 0;
  8262. }
  8263. else if (hasOwn(descriptor, 'value')) {
  8264. this.set(target, key, descriptor.value, null);
  8265. }
  8266. return Reflect.defineProperty(target, key, descriptor);
  8267. }
  8268. };
  8269. {
  8270. PublicInstanceProxyHandlers.ownKeys = (target) => {
  8271. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  8272. `The keys will be empty in production mode to avoid performance overhead.`);
  8273. return Reflect.ownKeys(target);
  8274. };
  8275. }
  8276. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  8277. get(target, key) {
  8278. // fast path for unscopables when using `with` block
  8279. if (key === Symbol.unscopables) {
  8280. return;
  8281. }
  8282. return PublicInstanceProxyHandlers.get(target, key, target);
  8283. },
  8284. has(_, key) {
  8285. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  8286. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  8287. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  8288. }
  8289. return has;
  8290. }
  8291. });
  8292. // dev only
  8293. // In dev mode, the proxy target exposes the same properties as seen on `this`
  8294. // for easier console inspection. In prod mode it will be an empty object so
  8295. // these properties definitions can be skipped.
  8296. function createDevRenderContext(instance) {
  8297. const target = {};
  8298. // expose internal instance for proxy handlers
  8299. Object.defineProperty(target, `_`, {
  8300. configurable: true,
  8301. enumerable: false,
  8302. get: () => instance
  8303. });
  8304. // expose public properties
  8305. Object.keys(publicPropertiesMap).forEach(key => {
  8306. Object.defineProperty(target, key, {
  8307. configurable: true,
  8308. enumerable: false,
  8309. get: () => publicPropertiesMap[key](instance),
  8310. // intercepted by the proxy so no need for implementation,
  8311. // but needed to prevent set errors
  8312. set: NOOP
  8313. });
  8314. });
  8315. return target;
  8316. }
  8317. // dev only
  8318. function exposePropsOnRenderContext(instance) {
  8319. const { ctx, propsOptions: [propsOptions] } = instance;
  8320. if (propsOptions) {
  8321. Object.keys(propsOptions).forEach(key => {
  8322. Object.defineProperty(ctx, key, {
  8323. enumerable: true,
  8324. configurable: true,
  8325. get: () => instance.props[key],
  8326. set: NOOP
  8327. });
  8328. });
  8329. }
  8330. }
  8331. // dev only
  8332. function exposeSetupStateOnRenderContext(instance) {
  8333. const { ctx, setupState } = instance;
  8334. Object.keys(toRaw(setupState)).forEach(key => {
  8335. if (!setupState.__isScriptSetup) {
  8336. if (key[0] === '$' || key[0] === '_') {
  8337. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  8338. `which are reserved prefixes for Vue internals.`);
  8339. return;
  8340. }
  8341. Object.defineProperty(ctx, key, {
  8342. enumerable: true,
  8343. configurable: true,
  8344. get: () => setupState[key],
  8345. set: NOOP
  8346. });
  8347. }
  8348. });
  8349. }
  8350. const emptyAppContext = createAppContext();
  8351. let uid$1 = 0;
  8352. function createComponentInstance(vnode, parent, suspense) {
  8353. const type = vnode.type;
  8354. // inherit parent app context - or - if root, adopt from root vnode
  8355. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8356. const instance = {
  8357. uid: uid$1++,
  8358. vnode,
  8359. type,
  8360. parent,
  8361. appContext,
  8362. root: null,
  8363. next: null,
  8364. subTree: null,
  8365. effect: null,
  8366. update: null,
  8367. scope: new EffectScope(true /* detached */),
  8368. render: null,
  8369. proxy: null,
  8370. exposed: null,
  8371. exposeProxy: null,
  8372. withProxy: null,
  8373. provides: parent ? parent.provides : Object.create(appContext.provides),
  8374. accessCache: null,
  8375. renderCache: [],
  8376. // local resovled assets
  8377. components: null,
  8378. directives: null,
  8379. // resolved props and emits options
  8380. propsOptions: normalizePropsOptions(type, appContext),
  8381. emitsOptions: normalizeEmitsOptions(type, appContext),
  8382. // emit
  8383. emit: null,
  8384. emitted: null,
  8385. // props default value
  8386. propsDefaults: EMPTY_OBJ,
  8387. // inheritAttrs
  8388. inheritAttrs: type.inheritAttrs,
  8389. // state
  8390. ctx: EMPTY_OBJ,
  8391. data: EMPTY_OBJ,
  8392. props: EMPTY_OBJ,
  8393. attrs: EMPTY_OBJ,
  8394. slots: EMPTY_OBJ,
  8395. refs: EMPTY_OBJ,
  8396. setupState: EMPTY_OBJ,
  8397. setupContext: null,
  8398. // suspense related
  8399. suspense,
  8400. suspenseId: suspense ? suspense.pendingId : 0,
  8401. asyncDep: null,
  8402. asyncResolved: false,
  8403. // lifecycle hooks
  8404. // not using enums here because it results in computed properties
  8405. isMounted: false,
  8406. isUnmounted: false,
  8407. isDeactivated: false,
  8408. bc: null,
  8409. c: null,
  8410. bm: null,
  8411. m: null,
  8412. bu: null,
  8413. u: null,
  8414. um: null,
  8415. bum: null,
  8416. da: null,
  8417. a: null,
  8418. rtg: null,
  8419. rtc: null,
  8420. ec: null,
  8421. sp: null
  8422. };
  8423. {
  8424. instance.ctx = createDevRenderContext(instance);
  8425. }
  8426. instance.root = parent ? parent.root : instance;
  8427. instance.emit = emit$1.bind(null, instance);
  8428. // apply custom element special handling
  8429. if (vnode.ce) {
  8430. vnode.ce(instance);
  8431. }
  8432. return instance;
  8433. }
  8434. let currentInstance = null;
  8435. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8436. const setCurrentInstance = (instance) => {
  8437. currentInstance = instance;
  8438. instance.scope.on();
  8439. };
  8440. const unsetCurrentInstance = () => {
  8441. currentInstance && currentInstance.scope.off();
  8442. currentInstance = null;
  8443. };
  8444. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8445. function validateComponentName(name, config) {
  8446. const appIsNativeTag = config.isNativeTag || NO;
  8447. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8448. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  8449. }
  8450. }
  8451. function isStatefulComponent(instance) {
  8452. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  8453. }
  8454. let isInSSRComponentSetup = false;
  8455. function setupComponent(instance, isSSR = false) {
  8456. isInSSRComponentSetup = isSSR;
  8457. const { props, children } = instance.vnode;
  8458. const isStateful = isStatefulComponent(instance);
  8459. initProps(instance, props, isStateful, isSSR);
  8460. initSlots(instance, children);
  8461. const setupResult = isStateful
  8462. ? setupStatefulComponent(instance, isSSR)
  8463. : undefined;
  8464. isInSSRComponentSetup = false;
  8465. return setupResult;
  8466. }
  8467. function setupStatefulComponent(instance, isSSR) {
  8468. var _a;
  8469. const Component = instance.type;
  8470. {
  8471. if (Component.name) {
  8472. validateComponentName(Component.name, instance.appContext.config);
  8473. }
  8474. if (Component.components) {
  8475. const names = Object.keys(Component.components);
  8476. for (let i = 0; i < names.length; i++) {
  8477. validateComponentName(names[i], instance.appContext.config);
  8478. }
  8479. }
  8480. if (Component.directives) {
  8481. const names = Object.keys(Component.directives);
  8482. for (let i = 0; i < names.length; i++) {
  8483. validateDirectiveName(names[i]);
  8484. }
  8485. }
  8486. if (Component.compilerOptions && isRuntimeOnly()) {
  8487. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  8488. `includes the runtime compiler. Since you are using a runtime-only ` +
  8489. `build, the options should be passed via your build tool config instead.`);
  8490. }
  8491. }
  8492. // 0. create render proxy property access cache
  8493. instance.accessCache = Object.create(null);
  8494. // 1. create public instance / render proxy
  8495. // also mark it raw so it's never observed
  8496. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8497. {
  8498. exposePropsOnRenderContext(instance);
  8499. }
  8500. // 2. call setup()
  8501. const { setup } = Component;
  8502. if (setup) {
  8503. const setupContext = (instance.setupContext =
  8504. setup.length > 1 ? createSetupContext(instance) : null);
  8505. setCurrentInstance(instance);
  8506. pauseTracking();
  8507. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8508. resetTracking();
  8509. unsetCurrentInstance();
  8510. if (isPromise(setupResult)) {
  8511. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8512. if (isSSR) {
  8513. // return the promise so server-renderer can wait on it
  8514. return setupResult
  8515. .then((resolvedResult) => {
  8516. handleSetupResult(instance, resolvedResult, isSSR);
  8517. })
  8518. .catch(e => {
  8519. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  8520. });
  8521. }
  8522. else {
  8523. // async setup returned Promise.
  8524. // bail here and wait for re-entry.
  8525. instance.asyncDep = setupResult;
  8526. if (!instance.suspense) {
  8527. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8528. warn$1(`Component <${name}>: setup function returned a promise, but no ` +
  8529. `<Suspense> boundary was found in the parent component tree. ` +
  8530. `A component with async setup() must be nested in a <Suspense> ` +
  8531. `in order to be rendered.`);
  8532. }
  8533. }
  8534. }
  8535. else {
  8536. handleSetupResult(instance, setupResult, isSSR);
  8537. }
  8538. }
  8539. else {
  8540. finishComponentSetup(instance, isSSR);
  8541. }
  8542. }
  8543. function handleSetupResult(instance, setupResult, isSSR) {
  8544. if (isFunction(setupResult)) {
  8545. // setup returned an inline render function
  8546. {
  8547. instance.render = setupResult;
  8548. }
  8549. }
  8550. else if (isObject(setupResult)) {
  8551. if (isVNode(setupResult)) {
  8552. warn$1(`setup() should not return VNodes directly - ` +
  8553. `return a render function instead.`);
  8554. }
  8555. // setup returned bindings.
  8556. // assuming a render function compiled from template is present.
  8557. {
  8558. instance.devtoolsRawSetupState = setupResult;
  8559. }
  8560. instance.setupState = proxyRefs(setupResult);
  8561. {
  8562. exposeSetupStateOnRenderContext(instance);
  8563. }
  8564. }
  8565. else if (setupResult !== undefined) {
  8566. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8567. }
  8568. finishComponentSetup(instance, isSSR);
  8569. }
  8570. let compile;
  8571. let installWithProxy;
  8572. /**
  8573. * For runtime-dom to register the compiler.
  8574. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8575. */
  8576. function registerRuntimeCompiler(_compile) {
  8577. compile = _compile;
  8578. installWithProxy = i => {
  8579. if (i.render._rc) {
  8580. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8581. }
  8582. };
  8583. }
  8584. // dev only
  8585. const isRuntimeOnly = () => !compile;
  8586. function finishComponentSetup(instance, isSSR, skipOptions) {
  8587. const Component = instance.type;
  8588. // template / render function normalization
  8589. // could be already set when returned from setup()
  8590. if (!instance.render) {
  8591. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8592. // is done by server-renderer
  8593. if (!isSSR && compile && !Component.render) {
  8594. const template = Component.template;
  8595. if (template) {
  8596. {
  8597. startMeasure(instance, `compile`);
  8598. }
  8599. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8600. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8601. const finalCompilerOptions = extend(extend({
  8602. isCustomElement,
  8603. delimiters
  8604. }, compilerOptions), componentCompilerOptions);
  8605. Component.render = compile(template, finalCompilerOptions);
  8606. {
  8607. endMeasure(instance, `compile`);
  8608. }
  8609. }
  8610. }
  8611. instance.render = (Component.render || NOOP);
  8612. // for runtime-compiled render functions using `with` blocks, the render
  8613. // proxy used needs a different `has` handler which is more performant and
  8614. // also only allows a whitelist of globals to fallthrough.
  8615. if (installWithProxy) {
  8616. installWithProxy(instance);
  8617. }
  8618. }
  8619. // support for 2.x options
  8620. {
  8621. setCurrentInstance(instance);
  8622. pauseTracking();
  8623. applyOptions(instance);
  8624. resetTracking();
  8625. unsetCurrentInstance();
  8626. }
  8627. // warn missing template/render
  8628. // the runtime compilation of template in SSR is done by server-render
  8629. if (!Component.render && instance.render === NOOP && !isSSR) {
  8630. /* istanbul ignore if */
  8631. if (!compile && Component.template) {
  8632. warn$1(`Component provided template option but ` +
  8633. `runtime compilation is not supported in this build of Vue.` +
  8634. (` Use "vue.global.js" instead.`
  8635. ) /* should not happen */);
  8636. }
  8637. else {
  8638. warn$1(`Component is missing template or render function.`);
  8639. }
  8640. }
  8641. }
  8642. function createAttrsProxy(instance) {
  8643. return new Proxy(instance.attrs, {
  8644. get(target, key) {
  8645. markAttrsAccessed();
  8646. track(instance, "get" /* GET */, '$attrs');
  8647. return target[key];
  8648. },
  8649. set() {
  8650. warn$1(`setupContext.attrs is readonly.`);
  8651. return false;
  8652. },
  8653. deleteProperty() {
  8654. warn$1(`setupContext.attrs is readonly.`);
  8655. return false;
  8656. }
  8657. }
  8658. );
  8659. }
  8660. function createSetupContext(instance) {
  8661. const expose = exposed => {
  8662. if (instance.exposed) {
  8663. warn$1(`expose() should be called only once per setup().`);
  8664. }
  8665. instance.exposed = exposed || {};
  8666. };
  8667. let attrs;
  8668. {
  8669. // We use getters in dev in case libs like test-utils overwrite instance
  8670. // properties (overwrites should not be done in prod)
  8671. return Object.freeze({
  8672. get attrs() {
  8673. return attrs || (attrs = createAttrsProxy(instance));
  8674. },
  8675. get slots() {
  8676. return shallowReadonly(instance.slots);
  8677. },
  8678. get emit() {
  8679. return (event, ...args) => instance.emit(event, ...args);
  8680. },
  8681. expose
  8682. });
  8683. }
  8684. }
  8685. function getExposeProxy(instance) {
  8686. if (instance.exposed) {
  8687. return (instance.exposeProxy ||
  8688. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8689. get(target, key) {
  8690. if (key in target) {
  8691. return target[key];
  8692. }
  8693. else if (key in publicPropertiesMap) {
  8694. return publicPropertiesMap[key](instance);
  8695. }
  8696. }
  8697. })));
  8698. }
  8699. }
  8700. const classifyRE = /(?:^|[-_])(\w)/g;
  8701. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8702. function getComponentName(Component) {
  8703. return isFunction(Component)
  8704. ? Component.displayName || Component.name
  8705. : Component.name;
  8706. }
  8707. /* istanbul ignore next */
  8708. function formatComponentName(instance, Component, isRoot = false) {
  8709. let name = getComponentName(Component);
  8710. if (!name && Component.__file) {
  8711. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8712. if (match) {
  8713. name = match[1];
  8714. }
  8715. }
  8716. if (!name && instance && instance.parent) {
  8717. // try to infer the name based on reverse resolution
  8718. const inferFromRegistry = (registry) => {
  8719. for (const key in registry) {
  8720. if (registry[key] === Component) {
  8721. return key;
  8722. }
  8723. }
  8724. };
  8725. name =
  8726. inferFromRegistry(instance.components ||
  8727. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8728. }
  8729. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8730. }
  8731. function isClassComponent(value) {
  8732. return isFunction(value) && '__vccOpts' in value;
  8733. }
  8734. const computed$1 = ((getterOrOptions, debugOptions) => {
  8735. // @ts-ignore
  8736. return computed(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8737. });
  8738. // dev only
  8739. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8740. `<script setup> of a single file component. Its arguments should be ` +
  8741. `compiled away and passing it at runtime has no effect.`);
  8742. // implementation
  8743. function defineProps() {
  8744. {
  8745. warnRuntimeUsage(`defineProps`);
  8746. }
  8747. return null;
  8748. }
  8749. // implementation
  8750. function defineEmits() {
  8751. {
  8752. warnRuntimeUsage(`defineEmits`);
  8753. }
  8754. return null;
  8755. }
  8756. /**
  8757. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8758. * instance properties when it is accessed by a parent component via template
  8759. * refs.
  8760. *
  8761. * `<script setup>` components are closed by default - i.e. variables inside
  8762. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8763. * via `defineExpose`.
  8764. *
  8765. * This is only usable inside `<script setup>`, is compiled away in the
  8766. * output and should **not** be actually called at runtime.
  8767. */
  8768. function defineExpose(exposed) {
  8769. {
  8770. warnRuntimeUsage(`defineExpose`);
  8771. }
  8772. }
  8773. /**
  8774. * Vue `<script setup>` compiler macro for providing props default values when
  8775. * using type-based `defineProps` declaration.
  8776. *
  8777. * Example usage:
  8778. * ```ts
  8779. * withDefaults(defineProps<{
  8780. * size?: number
  8781. * labels?: string[]
  8782. * }>(), {
  8783. * size: 3,
  8784. * labels: () => ['default label']
  8785. * })
  8786. * ```
  8787. *
  8788. * This is only usable inside `<script setup>`, is compiled away in the output
  8789. * and should **not** be actually called at runtime.
  8790. */
  8791. function withDefaults(props, defaults) {
  8792. {
  8793. warnRuntimeUsage(`withDefaults`);
  8794. }
  8795. return null;
  8796. }
  8797. function useSlots() {
  8798. return getContext().slots;
  8799. }
  8800. function useAttrs() {
  8801. return getContext().attrs;
  8802. }
  8803. function getContext() {
  8804. const i = getCurrentInstance();
  8805. if (!i) {
  8806. warn$1(`useContext() called without active instance.`);
  8807. }
  8808. return i.setupContext || (i.setupContext = createSetupContext(i));
  8809. }
  8810. /**
  8811. * Runtime helper for merging default declarations. Imported by compiled code
  8812. * only.
  8813. * @internal
  8814. */
  8815. function mergeDefaults(raw, defaults) {
  8816. const props = isArray(raw)
  8817. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8818. : raw;
  8819. for (const key in defaults) {
  8820. const opt = props[key];
  8821. if (opt) {
  8822. if (isArray(opt) || isFunction(opt)) {
  8823. props[key] = { type: opt, default: defaults[key] };
  8824. }
  8825. else {
  8826. opt.default = defaults[key];
  8827. }
  8828. }
  8829. else if (opt === null) {
  8830. props[key] = { default: defaults[key] };
  8831. }
  8832. else {
  8833. warn$1(`props default key "${key}" has no corresponding declaration.`);
  8834. }
  8835. }
  8836. return props;
  8837. }
  8838. /**
  8839. * Used to create a proxy for the rest element when destructuring props with
  8840. * defineProps().
  8841. * @internal
  8842. */
  8843. function createPropsRestProxy(props, excludedKeys) {
  8844. const ret = {};
  8845. for (const key in props) {
  8846. if (!excludedKeys.includes(key)) {
  8847. Object.defineProperty(ret, key, {
  8848. enumerable: true,
  8849. get: () => props[key]
  8850. });
  8851. }
  8852. }
  8853. return ret;
  8854. }
  8855. /**
  8856. * `<script setup>` helper for persisting the current instance context over
  8857. * async/await flows.
  8858. *
  8859. * `@vue/compiler-sfc` converts the following:
  8860. *
  8861. * ```ts
  8862. * const x = await foo()
  8863. * ```
  8864. *
  8865. * into:
  8866. *
  8867. * ```ts
  8868. * let __temp, __restore
  8869. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8870. * ```
  8871. * @internal
  8872. */
  8873. function withAsyncContext(getAwaitable) {
  8874. const ctx = getCurrentInstance();
  8875. if (!ctx) {
  8876. warn$1(`withAsyncContext called without active current instance. ` +
  8877. `This is likely a bug.`);
  8878. }
  8879. let awaitable = getAwaitable();
  8880. unsetCurrentInstance();
  8881. if (isPromise(awaitable)) {
  8882. awaitable = awaitable.catch(e => {
  8883. setCurrentInstance(ctx);
  8884. throw e;
  8885. });
  8886. }
  8887. return [awaitable, () => setCurrentInstance(ctx)];
  8888. }
  8889. // Actual implementation
  8890. function h(type, propsOrChildren, children) {
  8891. const l = arguments.length;
  8892. if (l === 2) {
  8893. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  8894. // single vnode without props
  8895. if (isVNode(propsOrChildren)) {
  8896. return createVNode(type, null, [propsOrChildren]);
  8897. }
  8898. // props without children
  8899. return createVNode(type, propsOrChildren);
  8900. }
  8901. else {
  8902. // omit props
  8903. return createVNode(type, null, propsOrChildren);
  8904. }
  8905. }
  8906. else {
  8907. if (l > 3) {
  8908. children = Array.prototype.slice.call(arguments, 2);
  8909. }
  8910. else if (l === 3 && isVNode(children)) {
  8911. children = [children];
  8912. }
  8913. return createVNode(type, propsOrChildren, children);
  8914. }
  8915. }
  8916. const ssrContextKey = Symbol(`ssrContext` );
  8917. const useSSRContext = () => {
  8918. {
  8919. warn$1(`useSSRContext() is not supported in the global build.`);
  8920. }
  8921. };
  8922. function initCustomFormatter() {
  8923. /* eslint-disable no-restricted-globals */
  8924. if (typeof window === 'undefined') {
  8925. return;
  8926. }
  8927. const vueStyle = { style: 'color:#3ba776' };
  8928. const numberStyle = { style: 'color:#0b1bc9' };
  8929. const stringStyle = { style: 'color:#b62e24' };
  8930. const keywordStyle = { style: 'color:#9d288c' };
  8931. // custom formatter for Chrome
  8932. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  8933. const formatter = {
  8934. header(obj) {
  8935. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  8936. if (!isObject(obj)) {
  8937. return null;
  8938. }
  8939. if (obj.__isVue) {
  8940. return ['div', vueStyle, `VueInstance`];
  8941. }
  8942. else if (isRef(obj)) {
  8943. return [
  8944. 'div',
  8945. {},
  8946. ['span', vueStyle, genRefFlag(obj)],
  8947. '<',
  8948. formatValue(obj.value),
  8949. `>`
  8950. ];
  8951. }
  8952. else if (isReactive(obj)) {
  8953. return [
  8954. 'div',
  8955. {},
  8956. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  8957. '<',
  8958. formatValue(obj),
  8959. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  8960. ];
  8961. }
  8962. else if (isReadonly(obj)) {
  8963. return [
  8964. 'div',
  8965. {},
  8966. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  8967. '<',
  8968. formatValue(obj),
  8969. '>'
  8970. ];
  8971. }
  8972. return null;
  8973. },
  8974. hasBody(obj) {
  8975. return obj && obj.__isVue;
  8976. },
  8977. body(obj) {
  8978. if (obj && obj.__isVue) {
  8979. return [
  8980. 'div',
  8981. {},
  8982. ...formatInstance(obj.$)
  8983. ];
  8984. }
  8985. }
  8986. };
  8987. function formatInstance(instance) {
  8988. const blocks = [];
  8989. if (instance.type.props && instance.props) {
  8990. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  8991. }
  8992. if (instance.setupState !== EMPTY_OBJ) {
  8993. blocks.push(createInstanceBlock('setup', instance.setupState));
  8994. }
  8995. if (instance.data !== EMPTY_OBJ) {
  8996. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  8997. }
  8998. const computed = extractKeys(instance, 'computed');
  8999. if (computed) {
  9000. blocks.push(createInstanceBlock('computed', computed));
  9001. }
  9002. const injected = extractKeys(instance, 'inject');
  9003. if (injected) {
  9004. blocks.push(createInstanceBlock('injected', injected));
  9005. }
  9006. blocks.push([
  9007. 'div',
  9008. {},
  9009. [
  9010. 'span',
  9011. {
  9012. style: keywordStyle.style + ';opacity:0.66'
  9013. },
  9014. '$ (internal): '
  9015. ],
  9016. ['object', { object: instance }]
  9017. ]);
  9018. return blocks;
  9019. }
  9020. function createInstanceBlock(type, target) {
  9021. target = extend({}, target);
  9022. if (!Object.keys(target).length) {
  9023. return ['span', {}];
  9024. }
  9025. return [
  9026. 'div',
  9027. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9028. [
  9029. 'div',
  9030. {
  9031. style: 'color:#476582'
  9032. },
  9033. type
  9034. ],
  9035. [
  9036. 'div',
  9037. {
  9038. style: 'padding-left:1.25em'
  9039. },
  9040. ...Object.keys(target).map(key => {
  9041. return [
  9042. 'div',
  9043. {},
  9044. ['span', keywordStyle, key + ': '],
  9045. formatValue(target[key], false)
  9046. ];
  9047. })
  9048. ]
  9049. ];
  9050. }
  9051. function formatValue(v, asRaw = true) {
  9052. if (typeof v === 'number') {
  9053. return ['span', numberStyle, v];
  9054. }
  9055. else if (typeof v === 'string') {
  9056. return ['span', stringStyle, JSON.stringify(v)];
  9057. }
  9058. else if (typeof v === 'boolean') {
  9059. return ['span', keywordStyle, v];
  9060. }
  9061. else if (isObject(v)) {
  9062. return ['object', { object: asRaw ? toRaw(v) : v }];
  9063. }
  9064. else {
  9065. return ['span', stringStyle, String(v)];
  9066. }
  9067. }
  9068. function extractKeys(instance, type) {
  9069. const Comp = instance.type;
  9070. if (isFunction(Comp)) {
  9071. return;
  9072. }
  9073. const extracted = {};
  9074. for (const key in instance.ctx) {
  9075. if (isKeyOfType(Comp, key, type)) {
  9076. extracted[key] = instance.ctx[key];
  9077. }
  9078. }
  9079. return extracted;
  9080. }
  9081. function isKeyOfType(Comp, key, type) {
  9082. const opts = Comp[type];
  9083. if ((isArray(opts) && opts.includes(key)) ||
  9084. (isObject(opts) && key in opts)) {
  9085. return true;
  9086. }
  9087. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9088. return true;
  9089. }
  9090. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9091. return true;
  9092. }
  9093. }
  9094. function genRefFlag(v) {
  9095. if (isShallow(v)) {
  9096. return `ShallowRef`;
  9097. }
  9098. if (v.effect) {
  9099. return `ComputedRef`;
  9100. }
  9101. return `Ref`;
  9102. }
  9103. if (window.devtoolsFormatters) {
  9104. window.devtoolsFormatters.push(formatter);
  9105. }
  9106. else {
  9107. window.devtoolsFormatters = [formatter];
  9108. }
  9109. }
  9110. function withMemo(memo, render, cache, index) {
  9111. const cached = cache[index];
  9112. if (cached && isMemoSame(cached, memo)) {
  9113. return cached;
  9114. }
  9115. const ret = render();
  9116. // shallow clone
  9117. ret.memo = memo.slice();
  9118. return (cache[index] = ret);
  9119. }
  9120. function isMemoSame(cached, memo) {
  9121. const prev = cached.memo;
  9122. if (prev.length != memo.length) {
  9123. return false;
  9124. }
  9125. for (let i = 0; i < prev.length; i++) {
  9126. if (prev[i] !== memo[i]) {
  9127. return false;
  9128. }
  9129. }
  9130. // make sure to let parent block track it when returning cached
  9131. if (isBlockTreeEnabled > 0 && currentBlock) {
  9132. currentBlock.push(cached);
  9133. }
  9134. return true;
  9135. }
  9136. // Core API ------------------------------------------------------------------
  9137. const version = "3.2.33";
  9138. /**
  9139. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  9140. * @internal
  9141. */
  9142. const ssrUtils = (null);
  9143. /**
  9144. * @internal only exposed in compat builds
  9145. */
  9146. const resolveFilter = null;
  9147. /**
  9148. * @internal only exposed in compat builds.
  9149. */
  9150. const compatUtils = (null);
  9151. const svgNS = 'http://www.w3.org/2000/svg';
  9152. const doc = (typeof document !== 'undefined' ? document : null);
  9153. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9154. const nodeOps = {
  9155. insert: (child, parent, anchor) => {
  9156. parent.insertBefore(child, anchor || null);
  9157. },
  9158. remove: child => {
  9159. const parent = child.parentNode;
  9160. if (parent) {
  9161. parent.removeChild(child);
  9162. }
  9163. },
  9164. createElement: (tag, isSVG, is, props) => {
  9165. const el = isSVG
  9166. ? doc.createElementNS(svgNS, tag)
  9167. : doc.createElement(tag, is ? { is } : undefined);
  9168. if (tag === 'select' && props && props.multiple != null) {
  9169. el.setAttribute('multiple', props.multiple);
  9170. }
  9171. return el;
  9172. },
  9173. createText: text => doc.createTextNode(text),
  9174. createComment: text => doc.createComment(text),
  9175. setText: (node, text) => {
  9176. node.nodeValue = text;
  9177. },
  9178. setElementText: (el, text) => {
  9179. el.textContent = text;
  9180. },
  9181. parentNode: node => node.parentNode,
  9182. nextSibling: node => node.nextSibling,
  9183. querySelector: selector => doc.querySelector(selector),
  9184. setScopeId(el, id) {
  9185. el.setAttribute(id, '');
  9186. },
  9187. cloneNode(el) {
  9188. const cloned = el.cloneNode(true);
  9189. // #3072
  9190. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  9191. // - normally, elements using `:value` bindings will not be hoisted, but if
  9192. // the bound value is a constant, e.g. `:value="true"` - they do get
  9193. // hoisted.
  9194. // - in production, hoisted nodes are cloned when subsequent inserts, but
  9195. // cloneNode() does not copy the custom property we attached.
  9196. // - This may need to account for other custom DOM properties we attach to
  9197. // elements in addition to `_value` in the future.
  9198. if (`_value` in el) {
  9199. cloned._value = el._value;
  9200. }
  9201. return cloned;
  9202. },
  9203. // __UNSAFE__
  9204. // Reason: innerHTML.
  9205. // Static content here can only come from compiled templates.
  9206. // As long as the user only uses trusted templates, this is safe.
  9207. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9208. // <parent> before | first ... last | anchor </parent>
  9209. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9210. // #5308 can only take cached path if:
  9211. // - has a single root node
  9212. // - nextSibling info is still available
  9213. if (start && (start === end || start.nextSibling)) {
  9214. // cached
  9215. while (true) {
  9216. parent.insertBefore(start.cloneNode(true), anchor);
  9217. if (start === end || !(start = start.nextSibling))
  9218. break;
  9219. }
  9220. }
  9221. else {
  9222. // fresh insert
  9223. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9224. const template = templateContainer.content;
  9225. if (isSVG) {
  9226. // remove outer svg wrapper
  9227. const wrapper = template.firstChild;
  9228. while (wrapper.firstChild) {
  9229. template.appendChild(wrapper.firstChild);
  9230. }
  9231. template.removeChild(wrapper);
  9232. }
  9233. parent.insertBefore(template, anchor);
  9234. }
  9235. return [
  9236. // first
  9237. before ? before.nextSibling : parent.firstChild,
  9238. // last
  9239. anchor ? anchor.previousSibling : parent.lastChild
  9240. ];
  9241. }
  9242. };
  9243. // compiler should normalize class + :class bindings on the same element
  9244. // into a single binding ['staticClass', dynamic]
  9245. function patchClass(el, value, isSVG) {
  9246. // directly setting className should be faster than setAttribute in theory
  9247. // if this is an element during a transition, take the temporary transition
  9248. // classes into account.
  9249. const transitionClasses = el._vtc;
  9250. if (transitionClasses) {
  9251. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9252. }
  9253. if (value == null) {
  9254. el.removeAttribute('class');
  9255. }
  9256. else if (isSVG) {
  9257. el.setAttribute('class', value);
  9258. }
  9259. else {
  9260. el.className = value;
  9261. }
  9262. }
  9263. function patchStyle(el, prev, next) {
  9264. const style = el.style;
  9265. const isCssString = isString(next);
  9266. if (next && !isCssString) {
  9267. for (const key in next) {
  9268. setStyle(style, key, next[key]);
  9269. }
  9270. if (prev && !isString(prev)) {
  9271. for (const key in prev) {
  9272. if (next[key] == null) {
  9273. setStyle(style, key, '');
  9274. }
  9275. }
  9276. }
  9277. }
  9278. else {
  9279. const currentDisplay = style.display;
  9280. if (isCssString) {
  9281. if (prev !== next) {
  9282. style.cssText = next;
  9283. }
  9284. }
  9285. else if (prev) {
  9286. el.removeAttribute('style');
  9287. }
  9288. // indicates that the `display` of the element is controlled by `v-show`,
  9289. // so we always keep the current `display` value regardless of the `style`
  9290. // value, thus handing over control to `v-show`.
  9291. if ('_vod' in el) {
  9292. style.display = currentDisplay;
  9293. }
  9294. }
  9295. }
  9296. const importantRE = /\s*!important$/;
  9297. function setStyle(style, name, val) {
  9298. if (isArray(val)) {
  9299. val.forEach(v => setStyle(style, name, v));
  9300. }
  9301. else {
  9302. if (val == null)
  9303. val = '';
  9304. if (name.startsWith('--')) {
  9305. // custom property definition
  9306. style.setProperty(name, val);
  9307. }
  9308. else {
  9309. const prefixed = autoPrefix(style, name);
  9310. if (importantRE.test(val)) {
  9311. // !important
  9312. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9313. }
  9314. else {
  9315. style[prefixed] = val;
  9316. }
  9317. }
  9318. }
  9319. }
  9320. const prefixes = ['Webkit', 'Moz', 'ms'];
  9321. const prefixCache = {};
  9322. function autoPrefix(style, rawName) {
  9323. const cached = prefixCache[rawName];
  9324. if (cached) {
  9325. return cached;
  9326. }
  9327. let name = camelize(rawName);
  9328. if (name !== 'filter' && name in style) {
  9329. return (prefixCache[rawName] = name);
  9330. }
  9331. name = capitalize(name);
  9332. for (let i = 0; i < prefixes.length; i++) {
  9333. const prefixed = prefixes[i] + name;
  9334. if (prefixed in style) {
  9335. return (prefixCache[rawName] = prefixed);
  9336. }
  9337. }
  9338. return rawName;
  9339. }
  9340. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9341. function patchAttr(el, key, value, isSVG, instance) {
  9342. if (isSVG && key.startsWith('xlink:')) {
  9343. if (value == null) {
  9344. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9345. }
  9346. else {
  9347. el.setAttributeNS(xlinkNS, key, value);
  9348. }
  9349. }
  9350. else {
  9351. // note we are only checking boolean attributes that don't have a
  9352. // corresponding dom prop of the same name here.
  9353. const isBoolean = isSpecialBooleanAttr(key);
  9354. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9355. el.removeAttribute(key);
  9356. }
  9357. else {
  9358. el.setAttribute(key, isBoolean ? '' : value);
  9359. }
  9360. }
  9361. }
  9362. // __UNSAFE__
  9363. // functions. The user is responsible for using them with only trusted content.
  9364. function patchDOMProp(el, key, value,
  9365. // the following args are passed only due to potential innerHTML/textContent
  9366. // overriding existing VNodes, in which case the old tree must be properly
  9367. // unmounted.
  9368. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9369. if (key === 'innerHTML' || key === 'textContent') {
  9370. if (prevChildren) {
  9371. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9372. }
  9373. el[key] = value == null ? '' : value;
  9374. return;
  9375. }
  9376. if (key === 'value' &&
  9377. el.tagName !== 'PROGRESS' &&
  9378. // custom elements may use _value internally
  9379. !el.tagName.includes('-')) {
  9380. // store value as _value as well since
  9381. // non-string values will be stringified.
  9382. el._value = value;
  9383. const newValue = value == null ? '' : value;
  9384. if (el.value !== newValue ||
  9385. // #4956: always set for OPTION elements because its value falls back to
  9386. // textContent if no value attribute is present. And setting .value for
  9387. // OPTION has no side effect
  9388. el.tagName === 'OPTION') {
  9389. el.value = newValue;
  9390. }
  9391. if (value == null) {
  9392. el.removeAttribute(key);
  9393. }
  9394. return;
  9395. }
  9396. let needRemove = false;
  9397. if (value === '' || value == null) {
  9398. const type = typeof el[key];
  9399. if (type === 'boolean') {
  9400. // e.g. <select multiple> compiles to { multiple: '' }
  9401. value = includeBooleanAttr(value);
  9402. }
  9403. else if (value == null && type === 'string') {
  9404. // e.g. <div :id="null">
  9405. value = '';
  9406. needRemove = true;
  9407. }
  9408. else if (type === 'number') {
  9409. // e.g. <img :width="null">
  9410. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  9411. value = 0;
  9412. needRemove = true;
  9413. }
  9414. }
  9415. // some properties perform value validation and throw,
  9416. // some properties has getter, no setter, will error in 'use strict'
  9417. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9418. try {
  9419. el[key] = value;
  9420. }
  9421. catch (e) {
  9422. {
  9423. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9424. `value ${value} is invalid.`, e);
  9425. }
  9426. }
  9427. needRemove && el.removeAttribute(key);
  9428. }
  9429. // Async edge case fix requires storing an event listener's attach timestamp.
  9430. const [_getNow, skipTimestampCheck] = /*#__PURE__*/ (() => {
  9431. let _getNow = Date.now;
  9432. let skipTimestampCheck = false;
  9433. if (typeof window !== 'undefined') {
  9434. // Determine what event timestamp the browser is using. Annoyingly, the
  9435. // timestamp can either be hi-res (relative to page load) or low-res
  9436. // (relative to UNIX epoch), so in order to compare time we have to use the
  9437. // same timestamp type when saving the flush timestamp.
  9438. if (Date.now() > document.createEvent('Event').timeStamp) {
  9439. // if the low-res timestamp which is bigger than the event timestamp
  9440. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  9441. // and we need to use the hi-res version for event listeners as well.
  9442. _getNow = () => performance.now();
  9443. }
  9444. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  9445. // and does not fire microtasks in between event propagation, so safe to exclude.
  9446. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  9447. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  9448. }
  9449. return [_getNow, skipTimestampCheck];
  9450. })();
  9451. // To avoid the overhead of repeatedly calling performance.now(), we cache
  9452. // and use the same timestamp for all event listeners attached in the same tick.
  9453. let cachedNow = 0;
  9454. const p = /*#__PURE__*/ Promise.resolve();
  9455. const reset = () => {
  9456. cachedNow = 0;
  9457. };
  9458. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  9459. function addEventListener(el, event, handler, options) {
  9460. el.addEventListener(event, handler, options);
  9461. }
  9462. function removeEventListener(el, event, handler, options) {
  9463. el.removeEventListener(event, handler, options);
  9464. }
  9465. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9466. // vei = vue event invokers
  9467. const invokers = el._vei || (el._vei = {});
  9468. const existingInvoker = invokers[rawName];
  9469. if (nextValue && existingInvoker) {
  9470. // patch
  9471. existingInvoker.value = nextValue;
  9472. }
  9473. else {
  9474. const [name, options] = parseName(rawName);
  9475. if (nextValue) {
  9476. // add
  9477. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9478. addEventListener(el, name, invoker, options);
  9479. }
  9480. else if (existingInvoker) {
  9481. // remove
  9482. removeEventListener(el, name, existingInvoker, options);
  9483. invokers[rawName] = undefined;
  9484. }
  9485. }
  9486. }
  9487. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9488. function parseName(name) {
  9489. let options;
  9490. if (optionsModifierRE.test(name)) {
  9491. options = {};
  9492. let m;
  9493. while ((m = name.match(optionsModifierRE))) {
  9494. name = name.slice(0, name.length - m[0].length);
  9495. options[m[0].toLowerCase()] = true;
  9496. }
  9497. }
  9498. return [hyphenate(name.slice(2)), options];
  9499. }
  9500. function createInvoker(initialValue, instance) {
  9501. const invoker = (e) => {
  9502. // async edge case #6566: inner click event triggers patch, event handler
  9503. // attached to outer element during patch, and triggered again. This
  9504. // happens because browsers fire microtask ticks between event propagation.
  9505. // the solution is simple: we save the timestamp when a handler is attached,
  9506. // and the handler would only fire if the event passed to it was fired
  9507. // AFTER it was attached.
  9508. const timeStamp = e.timeStamp || _getNow();
  9509. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  9510. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  9511. }
  9512. };
  9513. invoker.value = initialValue;
  9514. invoker.attached = getNow();
  9515. return invoker;
  9516. }
  9517. function patchStopImmediatePropagation(e, value) {
  9518. if (isArray(value)) {
  9519. const originalStop = e.stopImmediatePropagation;
  9520. e.stopImmediatePropagation = () => {
  9521. originalStop.call(e);
  9522. e._stopped = true;
  9523. };
  9524. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9525. }
  9526. else {
  9527. return value;
  9528. }
  9529. }
  9530. const nativeOnRE = /^on[a-z]/;
  9531. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9532. if (key === 'class') {
  9533. patchClass(el, nextValue, isSVG);
  9534. }
  9535. else if (key === 'style') {
  9536. patchStyle(el, prevValue, nextValue);
  9537. }
  9538. else if (isOn(key)) {
  9539. // ignore v-model listeners
  9540. if (!isModelListener(key)) {
  9541. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9542. }
  9543. }
  9544. else if (key[0] === '.'
  9545. ? ((key = key.slice(1)), true)
  9546. : key[0] === '^'
  9547. ? ((key = key.slice(1)), false)
  9548. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9549. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9550. }
  9551. else {
  9552. // special case for <input v-model type="checkbox"> with
  9553. // :true-value & :false-value
  9554. // store value as dom properties since non-string values will be
  9555. // stringified.
  9556. if (key === 'true-value') {
  9557. el._trueValue = nextValue;
  9558. }
  9559. else if (key === 'false-value') {
  9560. el._falseValue = nextValue;
  9561. }
  9562. patchAttr(el, key, nextValue, isSVG);
  9563. }
  9564. };
  9565. function shouldSetAsProp(el, key, value, isSVG) {
  9566. if (isSVG) {
  9567. // most keys must be set as attribute on svg elements to work
  9568. // ...except innerHTML & textContent
  9569. if (key === 'innerHTML' || key === 'textContent') {
  9570. return true;
  9571. }
  9572. // or native onclick with function values
  9573. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9574. return true;
  9575. }
  9576. return false;
  9577. }
  9578. // these are enumerated attrs, however their corresponding DOM properties
  9579. // are actually booleans - this leads to setting it with a string "false"
  9580. // value leading it to be coerced to `true`, so we need to always treat
  9581. // them as attributes.
  9582. // Note that `contentEditable` doesn't have this problem: its DOM
  9583. // property is also enumerated string values.
  9584. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9585. return false;
  9586. }
  9587. // #1787, #2840 form property on form elements is readonly and must be set as
  9588. // attribute.
  9589. if (key === 'form') {
  9590. return false;
  9591. }
  9592. // #1526 <input list> must be set as attribute
  9593. if (key === 'list' && el.tagName === 'INPUT') {
  9594. return false;
  9595. }
  9596. // #2766 <textarea type> must be set as attribute
  9597. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9598. return false;
  9599. }
  9600. // native onclick with string value, must be set as attribute
  9601. if (nativeOnRE.test(key) && isString(value)) {
  9602. return false;
  9603. }
  9604. return key in el;
  9605. }
  9606. function defineCustomElement(options, hydate) {
  9607. const Comp = defineComponent(options);
  9608. class VueCustomElement extends VueElement {
  9609. constructor(initialProps) {
  9610. super(Comp, initialProps, hydate);
  9611. }
  9612. }
  9613. VueCustomElement.def = Comp;
  9614. return VueCustomElement;
  9615. }
  9616. const defineSSRCustomElement = ((options) => {
  9617. // @ts-ignore
  9618. return defineCustomElement(options, hydrate);
  9619. });
  9620. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9621. });
  9622. class VueElement extends BaseClass {
  9623. constructor(_def, _props = {}, hydrate) {
  9624. super();
  9625. this._def = _def;
  9626. this._props = _props;
  9627. /**
  9628. * @internal
  9629. */
  9630. this._instance = null;
  9631. this._connected = false;
  9632. this._resolved = false;
  9633. this._numberProps = null;
  9634. if (this.shadowRoot && hydrate) {
  9635. hydrate(this._createVNode(), this.shadowRoot);
  9636. }
  9637. else {
  9638. if (this.shadowRoot) {
  9639. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9640. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9641. }
  9642. this.attachShadow({ mode: 'open' });
  9643. }
  9644. }
  9645. connectedCallback() {
  9646. this._connected = true;
  9647. if (!this._instance) {
  9648. this._resolveDef();
  9649. }
  9650. }
  9651. disconnectedCallback() {
  9652. this._connected = false;
  9653. nextTick(() => {
  9654. if (!this._connected) {
  9655. render(null, this.shadowRoot);
  9656. this._instance = null;
  9657. }
  9658. });
  9659. }
  9660. /**
  9661. * resolve inner component definition (handle possible async component)
  9662. */
  9663. _resolveDef() {
  9664. if (this._resolved) {
  9665. return;
  9666. }
  9667. this._resolved = true;
  9668. // set initial attrs
  9669. for (let i = 0; i < this.attributes.length; i++) {
  9670. this._setAttr(this.attributes[i].name);
  9671. }
  9672. // watch future attr changes
  9673. new MutationObserver(mutations => {
  9674. for (const m of mutations) {
  9675. this._setAttr(m.attributeName);
  9676. }
  9677. }).observe(this, { attributes: true });
  9678. const resolve = (def) => {
  9679. const { props, styles } = def;
  9680. const hasOptions = !isArray(props);
  9681. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  9682. // cast Number-type props set before resolve
  9683. let numberProps;
  9684. if (hasOptions) {
  9685. for (const key in this._props) {
  9686. const opt = props[key];
  9687. if (opt === Number || (opt && opt.type === Number)) {
  9688. this._props[key] = toNumber(this._props[key]);
  9689. (numberProps || (numberProps = Object.create(null)))[key] = true;
  9690. }
  9691. }
  9692. }
  9693. this._numberProps = numberProps;
  9694. // check if there are props set pre-upgrade or connect
  9695. for (const key of Object.keys(this)) {
  9696. if (key[0] !== '_') {
  9697. this._setProp(key, this[key], true, false);
  9698. }
  9699. }
  9700. // defining getter/setters on prototype
  9701. for (const key of rawKeys.map(camelize)) {
  9702. Object.defineProperty(this, key, {
  9703. get() {
  9704. return this._getProp(key);
  9705. },
  9706. set(val) {
  9707. this._setProp(key, val);
  9708. }
  9709. });
  9710. }
  9711. // apply CSS
  9712. this._applyStyles(styles);
  9713. // initial render
  9714. this._update();
  9715. };
  9716. const asyncDef = this._def.__asyncLoader;
  9717. if (asyncDef) {
  9718. asyncDef().then(resolve);
  9719. }
  9720. else {
  9721. resolve(this._def);
  9722. }
  9723. }
  9724. _setAttr(key) {
  9725. let value = this.getAttribute(key);
  9726. if (this._numberProps && this._numberProps[key]) {
  9727. value = toNumber(value);
  9728. }
  9729. this._setProp(camelize(key), value, false);
  9730. }
  9731. /**
  9732. * @internal
  9733. */
  9734. _getProp(key) {
  9735. return this._props[key];
  9736. }
  9737. /**
  9738. * @internal
  9739. */
  9740. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9741. if (val !== this._props[key]) {
  9742. this._props[key] = val;
  9743. if (shouldUpdate && this._instance) {
  9744. this._update();
  9745. }
  9746. // reflect
  9747. if (shouldReflect) {
  9748. if (val === true) {
  9749. this.setAttribute(hyphenate(key), '');
  9750. }
  9751. else if (typeof val === 'string' || typeof val === 'number') {
  9752. this.setAttribute(hyphenate(key), val + '');
  9753. }
  9754. else if (!val) {
  9755. this.removeAttribute(hyphenate(key));
  9756. }
  9757. }
  9758. }
  9759. }
  9760. _update() {
  9761. render(this._createVNode(), this.shadowRoot);
  9762. }
  9763. _createVNode() {
  9764. const vnode = createVNode(this._def, extend({}, this._props));
  9765. if (!this._instance) {
  9766. vnode.ce = instance => {
  9767. this._instance = instance;
  9768. instance.isCE = true;
  9769. // HMR
  9770. {
  9771. instance.ceReload = newStyles => {
  9772. // always reset styles
  9773. if (this._styles) {
  9774. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9775. this._styles.length = 0;
  9776. }
  9777. this._applyStyles(newStyles);
  9778. // if this is an async component, ceReload is called from the inner
  9779. // component so no need to reload the async wrapper
  9780. if (!this._def.__asyncLoader) {
  9781. // reload
  9782. this._instance = null;
  9783. this._update();
  9784. }
  9785. };
  9786. }
  9787. // intercept emit
  9788. instance.emit = (event, ...args) => {
  9789. this.dispatchEvent(new CustomEvent(event, {
  9790. detail: args
  9791. }));
  9792. };
  9793. // locate nearest Vue custom element parent for provide/inject
  9794. let parent = this;
  9795. while ((parent =
  9796. parent && (parent.parentNode || parent.host))) {
  9797. if (parent instanceof VueElement) {
  9798. instance.parent = parent._instance;
  9799. break;
  9800. }
  9801. }
  9802. };
  9803. }
  9804. return vnode;
  9805. }
  9806. _applyStyles(styles) {
  9807. if (styles) {
  9808. styles.forEach(css => {
  9809. const s = document.createElement('style');
  9810. s.textContent = css;
  9811. this.shadowRoot.appendChild(s);
  9812. // record for HMR
  9813. {
  9814. (this._styles || (this._styles = [])).push(s);
  9815. }
  9816. });
  9817. }
  9818. }
  9819. }
  9820. function useCssModule(name = '$style') {
  9821. /* istanbul ignore else */
  9822. {
  9823. {
  9824. warn$1(`useCssModule() is not supported in the global build.`);
  9825. }
  9826. return EMPTY_OBJ;
  9827. }
  9828. }
  9829. /**
  9830. * Runtime helper for SFC's CSS variable injection feature.
  9831. * @private
  9832. */
  9833. function useCssVars(getter) {
  9834. const instance = getCurrentInstance();
  9835. /* istanbul ignore next */
  9836. if (!instance) {
  9837. warn$1(`useCssVars is called without current active component instance.`);
  9838. return;
  9839. }
  9840. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  9841. watchPostEffect(setVars);
  9842. onMounted(() => {
  9843. const ob = new MutationObserver(setVars);
  9844. ob.observe(instance.subTree.el.parentNode, { childList: true });
  9845. onUnmounted(() => ob.disconnect());
  9846. });
  9847. }
  9848. function setVarsOnVNode(vnode, vars) {
  9849. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  9850. const suspense = vnode.suspense;
  9851. vnode = suspense.activeBranch;
  9852. if (suspense.pendingBranch && !suspense.isHydrating) {
  9853. suspense.effects.push(() => {
  9854. setVarsOnVNode(suspense.activeBranch, vars);
  9855. });
  9856. }
  9857. }
  9858. // drill down HOCs until it's a non-component vnode
  9859. while (vnode.component) {
  9860. vnode = vnode.component.subTree;
  9861. }
  9862. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  9863. setVarsOnNode(vnode.el, vars);
  9864. }
  9865. else if (vnode.type === Fragment) {
  9866. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  9867. }
  9868. else if (vnode.type === Static) {
  9869. let { el, anchor } = vnode;
  9870. while (el) {
  9871. setVarsOnNode(el, vars);
  9872. if (el === anchor)
  9873. break;
  9874. el = el.nextSibling;
  9875. }
  9876. }
  9877. }
  9878. function setVarsOnNode(el, vars) {
  9879. if (el.nodeType === 1) {
  9880. const style = el.style;
  9881. for (const key in vars) {
  9882. style.setProperty(`--${key}`, vars[key]);
  9883. }
  9884. }
  9885. }
  9886. const TRANSITION = 'transition';
  9887. const ANIMATION = 'animation';
  9888. // DOM Transition is a higher-order-component based on the platform-agnostic
  9889. // base Transition component, with DOM-specific logic.
  9890. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  9891. Transition.displayName = 'Transition';
  9892. const DOMTransitionPropsValidators = {
  9893. name: String,
  9894. type: String,
  9895. css: {
  9896. type: Boolean,
  9897. default: true
  9898. },
  9899. duration: [String, Number, Object],
  9900. enterFromClass: String,
  9901. enterActiveClass: String,
  9902. enterToClass: String,
  9903. appearFromClass: String,
  9904. appearActiveClass: String,
  9905. appearToClass: String,
  9906. leaveFromClass: String,
  9907. leaveActiveClass: String,
  9908. leaveToClass: String
  9909. };
  9910. const TransitionPropsValidators = (Transition.props =
  9911. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  9912. /**
  9913. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  9914. * with custom HOCs.
  9915. */
  9916. const callHook$1 = (hook, args = []) => {
  9917. if (isArray(hook)) {
  9918. hook.forEach(h => h(...args));
  9919. }
  9920. else if (hook) {
  9921. hook(...args);
  9922. }
  9923. };
  9924. /**
  9925. * Check if a hook expects a callback (2nd arg), which means the user
  9926. * intends to explicitly control the end of the transition.
  9927. */
  9928. const hasExplicitCallback = (hook) => {
  9929. return hook
  9930. ? isArray(hook)
  9931. ? hook.some(h => h.length > 1)
  9932. : hook.length > 1
  9933. : false;
  9934. };
  9935. function resolveTransitionProps(rawProps) {
  9936. const baseProps = {};
  9937. for (const key in rawProps) {
  9938. if (!(key in DOMTransitionPropsValidators)) {
  9939. baseProps[key] = rawProps[key];
  9940. }
  9941. }
  9942. if (rawProps.css === false) {
  9943. return baseProps;
  9944. }
  9945. 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;
  9946. const durations = normalizeDuration(duration);
  9947. const enterDuration = durations && durations[0];
  9948. const leaveDuration = durations && durations[1];
  9949. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  9950. const finishEnter = (el, isAppear, done) => {
  9951. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9952. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  9953. done && done();
  9954. };
  9955. const finishLeave = (el, done) => {
  9956. removeTransitionClass(el, leaveToClass);
  9957. removeTransitionClass(el, leaveActiveClass);
  9958. done && done();
  9959. };
  9960. const makeEnterHook = (isAppear) => {
  9961. return (el, done) => {
  9962. const hook = isAppear ? onAppear : onEnter;
  9963. const resolve = () => finishEnter(el, isAppear, done);
  9964. callHook$1(hook, [el, resolve]);
  9965. nextFrame(() => {
  9966. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  9967. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9968. if (!hasExplicitCallback(hook)) {
  9969. whenTransitionEnds(el, type, enterDuration, resolve);
  9970. }
  9971. });
  9972. };
  9973. };
  9974. return extend(baseProps, {
  9975. onBeforeEnter(el) {
  9976. callHook$1(onBeforeEnter, [el]);
  9977. addTransitionClass(el, enterFromClass);
  9978. addTransitionClass(el, enterActiveClass);
  9979. },
  9980. onBeforeAppear(el) {
  9981. callHook$1(onBeforeAppear, [el]);
  9982. addTransitionClass(el, appearFromClass);
  9983. addTransitionClass(el, appearActiveClass);
  9984. },
  9985. onEnter: makeEnterHook(false),
  9986. onAppear: makeEnterHook(true),
  9987. onLeave(el, done) {
  9988. const resolve = () => finishLeave(el, done);
  9989. addTransitionClass(el, leaveFromClass);
  9990. // force reflow so *-leave-from classes immediately take effect (#2593)
  9991. forceReflow();
  9992. addTransitionClass(el, leaveActiveClass);
  9993. nextFrame(() => {
  9994. removeTransitionClass(el, leaveFromClass);
  9995. addTransitionClass(el, leaveToClass);
  9996. if (!hasExplicitCallback(onLeave)) {
  9997. whenTransitionEnds(el, type, leaveDuration, resolve);
  9998. }
  9999. });
  10000. callHook$1(onLeave, [el, resolve]);
  10001. },
  10002. onEnterCancelled(el) {
  10003. finishEnter(el, false);
  10004. callHook$1(onEnterCancelled, [el]);
  10005. },
  10006. onAppearCancelled(el) {
  10007. finishEnter(el, true);
  10008. callHook$1(onAppearCancelled, [el]);
  10009. },
  10010. onLeaveCancelled(el) {
  10011. finishLeave(el);
  10012. callHook$1(onLeaveCancelled, [el]);
  10013. }
  10014. });
  10015. }
  10016. function normalizeDuration(duration) {
  10017. if (duration == null) {
  10018. return null;
  10019. }
  10020. else if (isObject(duration)) {
  10021. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10022. }
  10023. else {
  10024. const n = NumberOf(duration);
  10025. return [n, n];
  10026. }
  10027. }
  10028. function NumberOf(val) {
  10029. const res = toNumber(val);
  10030. validateDuration(res);
  10031. return res;
  10032. }
  10033. function validateDuration(val) {
  10034. if (typeof val !== 'number') {
  10035. warn$1(`<transition> explicit duration is not a valid number - ` +
  10036. `got ${JSON.stringify(val)}.`);
  10037. }
  10038. else if (isNaN(val)) {
  10039. warn$1(`<transition> explicit duration is NaN - ` +
  10040. 'the duration expression might be incorrect.');
  10041. }
  10042. }
  10043. function addTransitionClass(el, cls) {
  10044. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10045. (el._vtc ||
  10046. (el._vtc = new Set())).add(cls);
  10047. }
  10048. function removeTransitionClass(el, cls) {
  10049. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10050. const { _vtc } = el;
  10051. if (_vtc) {
  10052. _vtc.delete(cls);
  10053. if (!_vtc.size) {
  10054. el._vtc = undefined;
  10055. }
  10056. }
  10057. }
  10058. function nextFrame(cb) {
  10059. requestAnimationFrame(() => {
  10060. requestAnimationFrame(cb);
  10061. });
  10062. }
  10063. let endId = 0;
  10064. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10065. const id = (el._endId = ++endId);
  10066. const resolveIfNotStale = () => {
  10067. if (id === el._endId) {
  10068. resolve();
  10069. }
  10070. };
  10071. if (explicitTimeout) {
  10072. return setTimeout(resolveIfNotStale, explicitTimeout);
  10073. }
  10074. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10075. if (!type) {
  10076. return resolve();
  10077. }
  10078. const endEvent = type + 'end';
  10079. let ended = 0;
  10080. const end = () => {
  10081. el.removeEventListener(endEvent, onEnd);
  10082. resolveIfNotStale();
  10083. };
  10084. const onEnd = (e) => {
  10085. if (e.target === el && ++ended >= propCount) {
  10086. end();
  10087. }
  10088. };
  10089. setTimeout(() => {
  10090. if (ended < propCount) {
  10091. end();
  10092. }
  10093. }, timeout + 1);
  10094. el.addEventListener(endEvent, onEnd);
  10095. }
  10096. function getTransitionInfo(el, expectedType) {
  10097. const styles = window.getComputedStyle(el);
  10098. // JSDOM may return undefined for transition properties
  10099. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10100. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  10101. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  10102. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10103. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  10104. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  10105. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10106. let type = null;
  10107. let timeout = 0;
  10108. let propCount = 0;
  10109. /* istanbul ignore if */
  10110. if (expectedType === TRANSITION) {
  10111. if (transitionTimeout > 0) {
  10112. type = TRANSITION;
  10113. timeout = transitionTimeout;
  10114. propCount = transitionDurations.length;
  10115. }
  10116. }
  10117. else if (expectedType === ANIMATION) {
  10118. if (animationTimeout > 0) {
  10119. type = ANIMATION;
  10120. timeout = animationTimeout;
  10121. propCount = animationDurations.length;
  10122. }
  10123. }
  10124. else {
  10125. timeout = Math.max(transitionTimeout, animationTimeout);
  10126. type =
  10127. timeout > 0
  10128. ? transitionTimeout > animationTimeout
  10129. ? TRANSITION
  10130. : ANIMATION
  10131. : null;
  10132. propCount = type
  10133. ? type === TRANSITION
  10134. ? transitionDurations.length
  10135. : animationDurations.length
  10136. : 0;
  10137. }
  10138. const hasTransform = type === TRANSITION &&
  10139. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  10140. return {
  10141. type,
  10142. timeout,
  10143. propCount,
  10144. hasTransform
  10145. };
  10146. }
  10147. function getTimeout(delays, durations) {
  10148. while (delays.length < durations.length) {
  10149. delays = delays.concat(delays);
  10150. }
  10151. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10152. }
  10153. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10154. // numbers in a locale-dependent way, using a comma instead of a dot.
  10155. // If comma is not replaced with a dot, the input will be rounded down
  10156. // (i.e. acting as a floor function) causing unexpected behaviors
  10157. function toMs(s) {
  10158. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10159. }
  10160. // synchronously force layout to put elements into a certain state
  10161. function forceReflow() {
  10162. return document.body.offsetHeight;
  10163. }
  10164. const positionMap = new WeakMap();
  10165. const newPositionMap = new WeakMap();
  10166. const TransitionGroupImpl = {
  10167. name: 'TransitionGroup',
  10168. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10169. tag: String,
  10170. moveClass: String
  10171. }),
  10172. setup(props, { slots }) {
  10173. const instance = getCurrentInstance();
  10174. const state = useTransitionState();
  10175. let prevChildren;
  10176. let children;
  10177. onUpdated(() => {
  10178. // children is guaranteed to exist after initial render
  10179. if (!prevChildren.length) {
  10180. return;
  10181. }
  10182. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10183. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10184. return;
  10185. }
  10186. // we divide the work into three loops to avoid mixing DOM reads and writes
  10187. // in each iteration - which helps prevent layout thrashing.
  10188. prevChildren.forEach(callPendingCbs);
  10189. prevChildren.forEach(recordPosition);
  10190. const movedChildren = prevChildren.filter(applyTranslation);
  10191. // force reflow to put everything in position
  10192. forceReflow();
  10193. movedChildren.forEach(c => {
  10194. const el = c.el;
  10195. const style = el.style;
  10196. addTransitionClass(el, moveClass);
  10197. style.transform = style.webkitTransform = style.transitionDuration = '';
  10198. const cb = (el._moveCb = (e) => {
  10199. if (e && e.target !== el) {
  10200. return;
  10201. }
  10202. if (!e || /transform$/.test(e.propertyName)) {
  10203. el.removeEventListener('transitionend', cb);
  10204. el._moveCb = null;
  10205. removeTransitionClass(el, moveClass);
  10206. }
  10207. });
  10208. el.addEventListener('transitionend', cb);
  10209. });
  10210. });
  10211. return () => {
  10212. const rawProps = toRaw(props);
  10213. const cssTransitionProps = resolveTransitionProps(rawProps);
  10214. let tag = rawProps.tag || Fragment;
  10215. prevChildren = children;
  10216. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10217. for (let i = 0; i < children.length; i++) {
  10218. const child = children[i];
  10219. if (child.key != null) {
  10220. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10221. }
  10222. else {
  10223. warn$1(`<TransitionGroup> children must be keyed.`);
  10224. }
  10225. }
  10226. if (prevChildren) {
  10227. for (let i = 0; i < prevChildren.length; i++) {
  10228. const child = prevChildren[i];
  10229. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10230. positionMap.set(child, child.el.getBoundingClientRect());
  10231. }
  10232. }
  10233. return createVNode(tag, null, children);
  10234. };
  10235. }
  10236. };
  10237. const TransitionGroup = TransitionGroupImpl;
  10238. function callPendingCbs(c) {
  10239. const el = c.el;
  10240. if (el._moveCb) {
  10241. el._moveCb();
  10242. }
  10243. if (el._enterCb) {
  10244. el._enterCb();
  10245. }
  10246. }
  10247. function recordPosition(c) {
  10248. newPositionMap.set(c, c.el.getBoundingClientRect());
  10249. }
  10250. function applyTranslation(c) {
  10251. const oldPos = positionMap.get(c);
  10252. const newPos = newPositionMap.get(c);
  10253. const dx = oldPos.left - newPos.left;
  10254. const dy = oldPos.top - newPos.top;
  10255. if (dx || dy) {
  10256. const s = c.el.style;
  10257. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10258. s.transitionDuration = '0s';
  10259. return c;
  10260. }
  10261. }
  10262. function hasCSSTransform(el, root, moveClass) {
  10263. // Detect whether an element with the move class applied has
  10264. // CSS transitions. Since the element may be inside an entering
  10265. // transition at this very moment, we make a clone of it and remove
  10266. // all other transition classes applied to ensure only the move class
  10267. // is applied.
  10268. const clone = el.cloneNode();
  10269. if (el._vtc) {
  10270. el._vtc.forEach(cls => {
  10271. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10272. });
  10273. }
  10274. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10275. clone.style.display = 'none';
  10276. const container = (root.nodeType === 1 ? root : root.parentNode);
  10277. container.appendChild(clone);
  10278. const { hasTransform } = getTransitionInfo(clone);
  10279. container.removeChild(clone);
  10280. return hasTransform;
  10281. }
  10282. const getModelAssigner = (vnode) => {
  10283. const fn = vnode.props['onUpdate:modelValue'];
  10284. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10285. };
  10286. function onCompositionStart(e) {
  10287. e.target.composing = true;
  10288. }
  10289. function onCompositionEnd(e) {
  10290. const target = e.target;
  10291. if (target.composing) {
  10292. target.composing = false;
  10293. trigger$1(target, 'input');
  10294. }
  10295. }
  10296. function trigger$1(el, type) {
  10297. const e = document.createEvent('HTMLEvents');
  10298. e.initEvent(type, true, true);
  10299. el.dispatchEvent(e);
  10300. }
  10301. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10302. // be tree-shaken in case v-model is never used.
  10303. const vModelText = {
  10304. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10305. el._assign = getModelAssigner(vnode);
  10306. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10307. addEventListener(el, lazy ? 'change' : 'input', e => {
  10308. if (e.target.composing)
  10309. return;
  10310. let domValue = el.value;
  10311. if (trim) {
  10312. domValue = domValue.trim();
  10313. }
  10314. else if (castToNumber) {
  10315. domValue = toNumber(domValue);
  10316. }
  10317. el._assign(domValue);
  10318. });
  10319. if (trim) {
  10320. addEventListener(el, 'change', () => {
  10321. el.value = el.value.trim();
  10322. });
  10323. }
  10324. if (!lazy) {
  10325. addEventListener(el, 'compositionstart', onCompositionStart);
  10326. addEventListener(el, 'compositionend', onCompositionEnd);
  10327. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10328. // switching focus before confirming composition choice
  10329. // this also fixes the issue where some browsers e.g. iOS Chrome
  10330. // fires "change" instead of "input" on autocomplete.
  10331. addEventListener(el, 'change', onCompositionEnd);
  10332. }
  10333. },
  10334. // set value on mounted so it's after min/max for type="range"
  10335. mounted(el, { value }) {
  10336. el.value = value == null ? '' : value;
  10337. },
  10338. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10339. el._assign = getModelAssigner(vnode);
  10340. // avoid clearing unresolved text. #2302
  10341. if (el.composing)
  10342. return;
  10343. if (document.activeElement === el) {
  10344. if (lazy) {
  10345. return;
  10346. }
  10347. if (trim && el.value.trim() === value) {
  10348. return;
  10349. }
  10350. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10351. return;
  10352. }
  10353. }
  10354. const newValue = value == null ? '' : value;
  10355. if (el.value !== newValue) {
  10356. el.value = newValue;
  10357. }
  10358. }
  10359. };
  10360. const vModelCheckbox = {
  10361. // #4096 array checkboxes need to be deep traversed
  10362. deep: true,
  10363. created(el, _, vnode) {
  10364. el._assign = getModelAssigner(vnode);
  10365. addEventListener(el, 'change', () => {
  10366. const modelValue = el._modelValue;
  10367. const elementValue = getValue(el);
  10368. const checked = el.checked;
  10369. const assign = el._assign;
  10370. if (isArray(modelValue)) {
  10371. const index = looseIndexOf(modelValue, elementValue);
  10372. const found = index !== -1;
  10373. if (checked && !found) {
  10374. assign(modelValue.concat(elementValue));
  10375. }
  10376. else if (!checked && found) {
  10377. const filtered = [...modelValue];
  10378. filtered.splice(index, 1);
  10379. assign(filtered);
  10380. }
  10381. }
  10382. else if (isSet(modelValue)) {
  10383. const cloned = new Set(modelValue);
  10384. if (checked) {
  10385. cloned.add(elementValue);
  10386. }
  10387. else {
  10388. cloned.delete(elementValue);
  10389. }
  10390. assign(cloned);
  10391. }
  10392. else {
  10393. assign(getCheckboxValue(el, checked));
  10394. }
  10395. });
  10396. },
  10397. // set initial checked on mount to wait for true-value/false-value
  10398. mounted: setChecked,
  10399. beforeUpdate(el, binding, vnode) {
  10400. el._assign = getModelAssigner(vnode);
  10401. setChecked(el, binding, vnode);
  10402. }
  10403. };
  10404. function setChecked(el, { value, oldValue }, vnode) {
  10405. el._modelValue = value;
  10406. if (isArray(value)) {
  10407. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10408. }
  10409. else if (isSet(value)) {
  10410. el.checked = value.has(vnode.props.value);
  10411. }
  10412. else if (value !== oldValue) {
  10413. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10414. }
  10415. }
  10416. const vModelRadio = {
  10417. created(el, { value }, vnode) {
  10418. el.checked = looseEqual(value, vnode.props.value);
  10419. el._assign = getModelAssigner(vnode);
  10420. addEventListener(el, 'change', () => {
  10421. el._assign(getValue(el));
  10422. });
  10423. },
  10424. beforeUpdate(el, { value, oldValue }, vnode) {
  10425. el._assign = getModelAssigner(vnode);
  10426. if (value !== oldValue) {
  10427. el.checked = looseEqual(value, vnode.props.value);
  10428. }
  10429. }
  10430. };
  10431. const vModelSelect = {
  10432. // <select multiple> value need to be deep traversed
  10433. deep: true,
  10434. created(el, { value, modifiers: { number } }, vnode) {
  10435. const isSetModel = isSet(value);
  10436. addEventListener(el, 'change', () => {
  10437. const selectedVal = Array.prototype.filter
  10438. .call(el.options, (o) => o.selected)
  10439. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10440. el._assign(el.multiple
  10441. ? isSetModel
  10442. ? new Set(selectedVal)
  10443. : selectedVal
  10444. : selectedVal[0]);
  10445. });
  10446. el._assign = getModelAssigner(vnode);
  10447. },
  10448. // set value in mounted & updated because <select> relies on its children
  10449. // <option>s.
  10450. mounted(el, { value }) {
  10451. setSelected(el, value);
  10452. },
  10453. beforeUpdate(el, _binding, vnode) {
  10454. el._assign = getModelAssigner(vnode);
  10455. },
  10456. updated(el, { value }) {
  10457. setSelected(el, value);
  10458. }
  10459. };
  10460. function setSelected(el, value) {
  10461. const isMultiple = el.multiple;
  10462. if (isMultiple && !isArray(value) && !isSet(value)) {
  10463. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10464. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10465. return;
  10466. }
  10467. for (let i = 0, l = el.options.length; i < l; i++) {
  10468. const option = el.options[i];
  10469. const optionValue = getValue(option);
  10470. if (isMultiple) {
  10471. if (isArray(value)) {
  10472. option.selected = looseIndexOf(value, optionValue) > -1;
  10473. }
  10474. else {
  10475. option.selected = value.has(optionValue);
  10476. }
  10477. }
  10478. else {
  10479. if (looseEqual(getValue(option), value)) {
  10480. if (el.selectedIndex !== i)
  10481. el.selectedIndex = i;
  10482. return;
  10483. }
  10484. }
  10485. }
  10486. if (!isMultiple && el.selectedIndex !== -1) {
  10487. el.selectedIndex = -1;
  10488. }
  10489. }
  10490. // retrieve raw value set via :value bindings
  10491. function getValue(el) {
  10492. return '_value' in el ? el._value : el.value;
  10493. }
  10494. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10495. function getCheckboxValue(el, checked) {
  10496. const key = checked ? '_trueValue' : '_falseValue';
  10497. return key in el ? el[key] : checked;
  10498. }
  10499. const vModelDynamic = {
  10500. created(el, binding, vnode) {
  10501. callModelHook(el, binding, vnode, null, 'created');
  10502. },
  10503. mounted(el, binding, vnode) {
  10504. callModelHook(el, binding, vnode, null, 'mounted');
  10505. },
  10506. beforeUpdate(el, binding, vnode, prevVNode) {
  10507. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10508. },
  10509. updated(el, binding, vnode, prevVNode) {
  10510. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10511. }
  10512. };
  10513. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10514. let modelToUse;
  10515. switch (el.tagName) {
  10516. case 'SELECT':
  10517. modelToUse = vModelSelect;
  10518. break;
  10519. case 'TEXTAREA':
  10520. modelToUse = vModelText;
  10521. break;
  10522. default:
  10523. switch (vnode.props && vnode.props.type) {
  10524. case 'checkbox':
  10525. modelToUse = vModelCheckbox;
  10526. break;
  10527. case 'radio':
  10528. modelToUse = vModelRadio;
  10529. break;
  10530. default:
  10531. modelToUse = vModelText;
  10532. }
  10533. }
  10534. const fn = modelToUse[hook];
  10535. fn && fn(el, binding, vnode, prevVNode);
  10536. }
  10537. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10538. const modifierGuards = {
  10539. stop: e => e.stopPropagation(),
  10540. prevent: e => e.preventDefault(),
  10541. self: e => e.target !== e.currentTarget,
  10542. ctrl: e => !e.ctrlKey,
  10543. shift: e => !e.shiftKey,
  10544. alt: e => !e.altKey,
  10545. meta: e => !e.metaKey,
  10546. left: e => 'button' in e && e.button !== 0,
  10547. middle: e => 'button' in e && e.button !== 1,
  10548. right: e => 'button' in e && e.button !== 2,
  10549. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10550. };
  10551. /**
  10552. * @private
  10553. */
  10554. const withModifiers = (fn, modifiers) => {
  10555. return (event, ...args) => {
  10556. for (let i = 0; i < modifiers.length; i++) {
  10557. const guard = modifierGuards[modifiers[i]];
  10558. if (guard && guard(event, modifiers))
  10559. return;
  10560. }
  10561. return fn(event, ...args);
  10562. };
  10563. };
  10564. // Kept for 2.x compat.
  10565. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10566. const keyNames = {
  10567. esc: 'escape',
  10568. space: ' ',
  10569. up: 'arrow-up',
  10570. left: 'arrow-left',
  10571. right: 'arrow-right',
  10572. down: 'arrow-down',
  10573. delete: 'backspace'
  10574. };
  10575. /**
  10576. * @private
  10577. */
  10578. const withKeys = (fn, modifiers) => {
  10579. return (event) => {
  10580. if (!('key' in event)) {
  10581. return;
  10582. }
  10583. const eventKey = hyphenate(event.key);
  10584. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10585. return fn(event);
  10586. }
  10587. };
  10588. };
  10589. const vShow = {
  10590. beforeMount(el, { value }, { transition }) {
  10591. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10592. if (transition && value) {
  10593. transition.beforeEnter(el);
  10594. }
  10595. else {
  10596. setDisplay(el, value);
  10597. }
  10598. },
  10599. mounted(el, { value }, { transition }) {
  10600. if (transition && value) {
  10601. transition.enter(el);
  10602. }
  10603. },
  10604. updated(el, { value, oldValue }, { transition }) {
  10605. if (!value === !oldValue)
  10606. return;
  10607. if (transition) {
  10608. if (value) {
  10609. transition.beforeEnter(el);
  10610. setDisplay(el, true);
  10611. transition.enter(el);
  10612. }
  10613. else {
  10614. transition.leave(el, () => {
  10615. setDisplay(el, false);
  10616. });
  10617. }
  10618. }
  10619. else {
  10620. setDisplay(el, value);
  10621. }
  10622. },
  10623. beforeUnmount(el, { value }) {
  10624. setDisplay(el, value);
  10625. }
  10626. };
  10627. function setDisplay(el, value) {
  10628. el.style.display = value ? el._vod : 'none';
  10629. }
  10630. const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
  10631. // lazy create the renderer - this makes core renderer logic tree-shakable
  10632. // in case the user only imports reactivity utilities from Vue.
  10633. let renderer;
  10634. let enabledHydration = false;
  10635. function ensureRenderer() {
  10636. return (renderer ||
  10637. (renderer = createRenderer(rendererOptions)));
  10638. }
  10639. function ensureHydrationRenderer() {
  10640. renderer = enabledHydration
  10641. ? renderer
  10642. : createHydrationRenderer(rendererOptions);
  10643. enabledHydration = true;
  10644. return renderer;
  10645. }
  10646. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10647. const render = ((...args) => {
  10648. ensureRenderer().render(...args);
  10649. });
  10650. const hydrate = ((...args) => {
  10651. ensureHydrationRenderer().hydrate(...args);
  10652. });
  10653. const createApp = ((...args) => {
  10654. const app = ensureRenderer().createApp(...args);
  10655. {
  10656. injectNativeTagCheck(app);
  10657. injectCompilerOptionsCheck(app);
  10658. }
  10659. const { mount } = app;
  10660. app.mount = (containerOrSelector) => {
  10661. const container = normalizeContainer(containerOrSelector);
  10662. if (!container)
  10663. return;
  10664. const component = app._component;
  10665. if (!isFunction(component) && !component.render && !component.template) {
  10666. // __UNSAFE__
  10667. // Reason: potential execution of JS expressions in in-DOM template.
  10668. // The user must make sure the in-DOM template is trusted. If it's
  10669. // rendered by the server, the template should not contain any user data.
  10670. component.template = container.innerHTML;
  10671. }
  10672. // clear content before mounting
  10673. container.innerHTML = '';
  10674. const proxy = mount(container, false, container instanceof SVGElement);
  10675. if (container instanceof Element) {
  10676. container.removeAttribute('v-cloak');
  10677. container.setAttribute('data-v-app', '');
  10678. }
  10679. return proxy;
  10680. };
  10681. return app;
  10682. });
  10683. const createSSRApp = ((...args) => {
  10684. const app = ensureHydrationRenderer().createApp(...args);
  10685. {
  10686. injectNativeTagCheck(app);
  10687. injectCompilerOptionsCheck(app);
  10688. }
  10689. const { mount } = app;
  10690. app.mount = (containerOrSelector) => {
  10691. const container = normalizeContainer(containerOrSelector);
  10692. if (container) {
  10693. return mount(container, true, container instanceof SVGElement);
  10694. }
  10695. };
  10696. return app;
  10697. });
  10698. function injectNativeTagCheck(app) {
  10699. // Inject `isNativeTag`
  10700. // this is used for component name validation (dev only)
  10701. Object.defineProperty(app.config, 'isNativeTag', {
  10702. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10703. writable: false
  10704. });
  10705. }
  10706. // dev only
  10707. function injectCompilerOptionsCheck(app) {
  10708. if (isRuntimeOnly()) {
  10709. const isCustomElement = app.config.isCustomElement;
  10710. Object.defineProperty(app.config, 'isCustomElement', {
  10711. get() {
  10712. return isCustomElement;
  10713. },
  10714. set() {
  10715. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10716. `\`compilerOptions.isCustomElement\` instead.`);
  10717. }
  10718. });
  10719. const compilerOptions = app.config.compilerOptions;
  10720. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10721. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10722. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10723. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10724. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10725. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10726. `- 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`;
  10727. Object.defineProperty(app.config, 'compilerOptions', {
  10728. get() {
  10729. warn$1(msg);
  10730. return compilerOptions;
  10731. },
  10732. set() {
  10733. warn$1(msg);
  10734. }
  10735. });
  10736. }
  10737. }
  10738. function normalizeContainer(container) {
  10739. if (isString(container)) {
  10740. const res = document.querySelector(container);
  10741. if (!res) {
  10742. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10743. }
  10744. return res;
  10745. }
  10746. if (window.ShadowRoot &&
  10747. container instanceof window.ShadowRoot &&
  10748. container.mode === 'closed') {
  10749. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10750. }
  10751. return container;
  10752. }
  10753. /**
  10754. * @internal
  10755. */
  10756. const initDirectivesForSSR = NOOP;
  10757. function initDev() {
  10758. {
  10759. {
  10760. console.info(`You are running a development build of Vue.\n` +
  10761. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10762. }
  10763. initCustomFormatter();
  10764. }
  10765. }
  10766. function defaultOnError(error) {
  10767. throw error;
  10768. }
  10769. function defaultOnWarn(msg) {
  10770. console.warn(`[Vue warn] ${msg.message}`);
  10771. }
  10772. function createCompilerError(code, loc, messages, additionalMessage) {
  10773. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  10774. ;
  10775. const error = new SyntaxError(String(msg));
  10776. error.code = code;
  10777. error.loc = loc;
  10778. return error;
  10779. }
  10780. const errorMessages = {
  10781. // parse errors
  10782. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  10783. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  10784. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  10785. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  10786. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  10787. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  10788. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  10789. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  10790. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  10791. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  10792. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  10793. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  10794. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  10795. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  10796. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  10797. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  10798. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  10799. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  10800. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  10801. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  10802. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  10803. [20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  10804. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  10805. // Vue-specific parse errors
  10806. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  10807. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  10808. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  10809. [27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  10810. 'Note that dynamic directive argument cannot contain spaces.',
  10811. [26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  10812. // transform errors
  10813. [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  10814. [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  10815. [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  10816. [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  10817. [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  10818. [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  10819. [34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  10820. [35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  10821. [36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  10822. [37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  10823. `When there are multiple named slots, all slots should use <template> ` +
  10824. `syntax to avoid scope ambiguity.`,
  10825. [38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  10826. [39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  10827. `default slot. These children will be ignored.`,
  10828. [40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  10829. [41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  10830. [42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  10831. [43 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  10832. [44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  10833. [45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  10834. // generic errors
  10835. [46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  10836. [47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  10837. [48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  10838. [49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  10839. // just to fulfill types
  10840. [50 /* __EXTEND_POINT__ */]: ``
  10841. };
  10842. const FRAGMENT = Symbol(`Fragment` );
  10843. const TELEPORT = Symbol(`Teleport` );
  10844. const SUSPENSE = Symbol(`Suspense` );
  10845. const KEEP_ALIVE = Symbol(`KeepAlive` );
  10846. const BASE_TRANSITION = Symbol(`BaseTransition` );
  10847. const OPEN_BLOCK = Symbol(`openBlock` );
  10848. const CREATE_BLOCK = Symbol(`createBlock` );
  10849. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  10850. const CREATE_VNODE = Symbol(`createVNode` );
  10851. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  10852. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  10853. const CREATE_TEXT = Symbol(`createTextVNode` );
  10854. const CREATE_STATIC = Symbol(`createStaticVNode` );
  10855. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  10856. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  10857. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  10858. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  10859. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  10860. const RENDER_LIST = Symbol(`renderList` );
  10861. const RENDER_SLOT = Symbol(`renderSlot` );
  10862. const CREATE_SLOTS = Symbol(`createSlots` );
  10863. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  10864. const MERGE_PROPS = Symbol(`mergeProps` );
  10865. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  10866. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  10867. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  10868. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  10869. const TO_HANDLERS = Symbol(`toHandlers` );
  10870. const CAMELIZE = Symbol(`camelize` );
  10871. const CAPITALIZE = Symbol(`capitalize` );
  10872. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  10873. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  10874. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  10875. const POP_SCOPE_ID = Symbol(`popScopeId` );
  10876. const WITH_CTX = Symbol(`withCtx` );
  10877. const UNREF = Symbol(`unref` );
  10878. const IS_REF = Symbol(`isRef` );
  10879. const WITH_MEMO = Symbol(`withMemo` );
  10880. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  10881. // Name mapping for runtime helpers that need to be imported from 'vue' in
  10882. // generated code. Make sure these are correctly exported in the runtime!
  10883. // Using `any` here because TS doesn't allow symbols as index type.
  10884. const helperNameMap = {
  10885. [FRAGMENT]: `Fragment`,
  10886. [TELEPORT]: `Teleport`,
  10887. [SUSPENSE]: `Suspense`,
  10888. [KEEP_ALIVE]: `KeepAlive`,
  10889. [BASE_TRANSITION]: `BaseTransition`,
  10890. [OPEN_BLOCK]: `openBlock`,
  10891. [CREATE_BLOCK]: `createBlock`,
  10892. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  10893. [CREATE_VNODE]: `createVNode`,
  10894. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  10895. [CREATE_COMMENT]: `createCommentVNode`,
  10896. [CREATE_TEXT]: `createTextVNode`,
  10897. [CREATE_STATIC]: `createStaticVNode`,
  10898. [RESOLVE_COMPONENT]: `resolveComponent`,
  10899. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  10900. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  10901. [RESOLVE_FILTER]: `resolveFilter`,
  10902. [WITH_DIRECTIVES]: `withDirectives`,
  10903. [RENDER_LIST]: `renderList`,
  10904. [RENDER_SLOT]: `renderSlot`,
  10905. [CREATE_SLOTS]: `createSlots`,
  10906. [TO_DISPLAY_STRING]: `toDisplayString`,
  10907. [MERGE_PROPS]: `mergeProps`,
  10908. [NORMALIZE_CLASS]: `normalizeClass`,
  10909. [NORMALIZE_STYLE]: `normalizeStyle`,
  10910. [NORMALIZE_PROPS]: `normalizeProps`,
  10911. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  10912. [TO_HANDLERS]: `toHandlers`,
  10913. [CAMELIZE]: `camelize`,
  10914. [CAPITALIZE]: `capitalize`,
  10915. [TO_HANDLER_KEY]: `toHandlerKey`,
  10916. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  10917. [PUSH_SCOPE_ID]: `pushScopeId`,
  10918. [POP_SCOPE_ID]: `popScopeId`,
  10919. [WITH_CTX]: `withCtx`,
  10920. [UNREF]: `unref`,
  10921. [IS_REF]: `isRef`,
  10922. [WITH_MEMO]: `withMemo`,
  10923. [IS_MEMO_SAME]: `isMemoSame`
  10924. };
  10925. function registerRuntimeHelpers(helpers) {
  10926. Object.getOwnPropertySymbols(helpers).forEach(s => {
  10927. helperNameMap[s] = helpers[s];
  10928. });
  10929. }
  10930. // AST Utilities ---------------------------------------------------------------
  10931. // Some expressions, e.g. sequence and conditional expressions, are never
  10932. // associated with template nodes, so their source locations are just a stub.
  10933. // Container types like CompoundExpression also don't need a real location.
  10934. const locStub = {
  10935. source: '',
  10936. start: { line: 1, column: 1, offset: 0 },
  10937. end: { line: 1, column: 1, offset: 0 }
  10938. };
  10939. function createRoot(children, loc = locStub) {
  10940. return {
  10941. type: 0 /* ROOT */,
  10942. children,
  10943. helpers: [],
  10944. components: [],
  10945. directives: [],
  10946. hoists: [],
  10947. imports: [],
  10948. cached: 0,
  10949. temps: 0,
  10950. codegenNode: undefined,
  10951. loc
  10952. };
  10953. }
  10954. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  10955. if (context) {
  10956. if (isBlock) {
  10957. context.helper(OPEN_BLOCK);
  10958. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  10959. }
  10960. else {
  10961. context.helper(getVNodeHelper(context.inSSR, isComponent));
  10962. }
  10963. if (directives) {
  10964. context.helper(WITH_DIRECTIVES);
  10965. }
  10966. }
  10967. return {
  10968. type: 13 /* VNODE_CALL */,
  10969. tag,
  10970. props,
  10971. children,
  10972. patchFlag,
  10973. dynamicProps,
  10974. directives,
  10975. isBlock,
  10976. disableTracking,
  10977. isComponent,
  10978. loc
  10979. };
  10980. }
  10981. function createArrayExpression(elements, loc = locStub) {
  10982. return {
  10983. type: 17 /* JS_ARRAY_EXPRESSION */,
  10984. loc,
  10985. elements
  10986. };
  10987. }
  10988. function createObjectExpression(properties, loc = locStub) {
  10989. return {
  10990. type: 15 /* JS_OBJECT_EXPRESSION */,
  10991. loc,
  10992. properties
  10993. };
  10994. }
  10995. function createObjectProperty(key, value) {
  10996. return {
  10997. type: 16 /* JS_PROPERTY */,
  10998. loc: locStub,
  10999. key: isString(key) ? createSimpleExpression(key, true) : key,
  11000. value
  11001. };
  11002. }
  11003. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  11004. return {
  11005. type: 4 /* SIMPLE_EXPRESSION */,
  11006. loc,
  11007. content,
  11008. isStatic,
  11009. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  11010. };
  11011. }
  11012. function createCompoundExpression(children, loc = locStub) {
  11013. return {
  11014. type: 8 /* COMPOUND_EXPRESSION */,
  11015. loc,
  11016. children
  11017. };
  11018. }
  11019. function createCallExpression(callee, args = [], loc = locStub) {
  11020. return {
  11021. type: 14 /* JS_CALL_EXPRESSION */,
  11022. loc,
  11023. callee,
  11024. arguments: args
  11025. };
  11026. }
  11027. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  11028. return {
  11029. type: 18 /* JS_FUNCTION_EXPRESSION */,
  11030. params,
  11031. returns,
  11032. newline,
  11033. isSlot,
  11034. loc
  11035. };
  11036. }
  11037. function createConditionalExpression(test, consequent, alternate, newline = true) {
  11038. return {
  11039. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  11040. test,
  11041. consequent,
  11042. alternate,
  11043. newline,
  11044. loc: locStub
  11045. };
  11046. }
  11047. function createCacheExpression(index, value, isVNode = false) {
  11048. return {
  11049. type: 20 /* JS_CACHE_EXPRESSION */,
  11050. index,
  11051. value,
  11052. isVNode,
  11053. loc: locStub
  11054. };
  11055. }
  11056. function createBlockStatement(body) {
  11057. return {
  11058. type: 21 /* JS_BLOCK_STATEMENT */,
  11059. body,
  11060. loc: locStub
  11061. };
  11062. }
  11063. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  11064. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  11065. function isCoreComponent(tag) {
  11066. if (isBuiltInType(tag, 'Teleport')) {
  11067. return TELEPORT;
  11068. }
  11069. else if (isBuiltInType(tag, 'Suspense')) {
  11070. return SUSPENSE;
  11071. }
  11072. else if (isBuiltInType(tag, 'KeepAlive')) {
  11073. return KEEP_ALIVE;
  11074. }
  11075. else if (isBuiltInType(tag, 'BaseTransition')) {
  11076. return BASE_TRANSITION;
  11077. }
  11078. }
  11079. const nonIdentifierRE = /^\d|[^\$\w]/;
  11080. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  11081. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  11082. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  11083. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  11084. /**
  11085. * Simple lexer to check if an expression is a member expression. This is
  11086. * lax and only checks validity at the root level (i.e. does not validate exps
  11087. * inside square brackets), but it's ok since these are only used on template
  11088. * expressions and false positives are invalid expressions in the first place.
  11089. */
  11090. const isMemberExpressionBrowser = (path) => {
  11091. // remove whitespaces around . or [ first
  11092. path = path.trim().replace(whitespaceRE, s => s.trim());
  11093. let state = 0 /* inMemberExp */;
  11094. let stateStack = [];
  11095. let currentOpenBracketCount = 0;
  11096. let currentOpenParensCount = 0;
  11097. let currentStringType = null;
  11098. for (let i = 0; i < path.length; i++) {
  11099. const char = path.charAt(i);
  11100. switch (state) {
  11101. case 0 /* inMemberExp */:
  11102. if (char === '[') {
  11103. stateStack.push(state);
  11104. state = 1 /* inBrackets */;
  11105. currentOpenBracketCount++;
  11106. }
  11107. else if (char === '(') {
  11108. stateStack.push(state);
  11109. state = 2 /* inParens */;
  11110. currentOpenParensCount++;
  11111. }
  11112. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  11113. return false;
  11114. }
  11115. break;
  11116. case 1 /* inBrackets */:
  11117. if (char === `'` || char === `"` || char === '`') {
  11118. stateStack.push(state);
  11119. state = 3 /* inString */;
  11120. currentStringType = char;
  11121. }
  11122. else if (char === `[`) {
  11123. currentOpenBracketCount++;
  11124. }
  11125. else if (char === `]`) {
  11126. if (!--currentOpenBracketCount) {
  11127. state = stateStack.pop();
  11128. }
  11129. }
  11130. break;
  11131. case 2 /* inParens */:
  11132. if (char === `'` || char === `"` || char === '`') {
  11133. stateStack.push(state);
  11134. state = 3 /* inString */;
  11135. currentStringType = char;
  11136. }
  11137. else if (char === `(`) {
  11138. currentOpenParensCount++;
  11139. }
  11140. else if (char === `)`) {
  11141. // if the exp ends as a call then it should not be considered valid
  11142. if (i === path.length - 1) {
  11143. return false;
  11144. }
  11145. if (!--currentOpenParensCount) {
  11146. state = stateStack.pop();
  11147. }
  11148. }
  11149. break;
  11150. case 3 /* inString */:
  11151. if (char === currentStringType) {
  11152. state = stateStack.pop();
  11153. currentStringType = null;
  11154. }
  11155. break;
  11156. }
  11157. }
  11158. return !currentOpenBracketCount && !currentOpenParensCount;
  11159. };
  11160. const isMemberExpression = isMemberExpressionBrowser
  11161. ;
  11162. function getInnerRange(loc, offset, length) {
  11163. const source = loc.source.slice(offset, offset + length);
  11164. const newLoc = {
  11165. source,
  11166. start: advancePositionWithClone(loc.start, loc.source, offset),
  11167. end: loc.end
  11168. };
  11169. if (length != null) {
  11170. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  11171. }
  11172. return newLoc;
  11173. }
  11174. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  11175. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  11176. }
  11177. // advance by mutation without cloning (for performance reasons), since this
  11178. // gets called a lot in the parser
  11179. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  11180. let linesCount = 0;
  11181. let lastNewLinePos = -1;
  11182. for (let i = 0; i < numberOfCharacters; i++) {
  11183. if (source.charCodeAt(i) === 10 /* newline char code */) {
  11184. linesCount++;
  11185. lastNewLinePos = i;
  11186. }
  11187. }
  11188. pos.offset += numberOfCharacters;
  11189. pos.line += linesCount;
  11190. pos.column =
  11191. lastNewLinePos === -1
  11192. ? pos.column + numberOfCharacters
  11193. : numberOfCharacters - lastNewLinePos;
  11194. return pos;
  11195. }
  11196. function assert(condition, msg) {
  11197. /* istanbul ignore if */
  11198. if (!condition) {
  11199. throw new Error(msg || `unexpected compiler condition`);
  11200. }
  11201. }
  11202. function findDir(node, name, allowEmpty = false) {
  11203. for (let i = 0; i < node.props.length; i++) {
  11204. const p = node.props[i];
  11205. if (p.type === 7 /* DIRECTIVE */ &&
  11206. (allowEmpty || p.exp) &&
  11207. (isString(name) ? p.name === name : name.test(p.name))) {
  11208. return p;
  11209. }
  11210. }
  11211. }
  11212. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  11213. for (let i = 0; i < node.props.length; i++) {
  11214. const p = node.props[i];
  11215. if (p.type === 6 /* ATTRIBUTE */) {
  11216. if (dynamicOnly)
  11217. continue;
  11218. if (p.name === name && (p.value || allowEmpty)) {
  11219. return p;
  11220. }
  11221. }
  11222. else if (p.name === 'bind' &&
  11223. (p.exp || allowEmpty) &&
  11224. isStaticArgOf(p.arg, name)) {
  11225. return p;
  11226. }
  11227. }
  11228. }
  11229. function isStaticArgOf(arg, name) {
  11230. return !!(arg && isStaticExp(arg) && arg.content === name);
  11231. }
  11232. function hasDynamicKeyVBind(node) {
  11233. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  11234. p.name === 'bind' &&
  11235. (!p.arg || // v-bind="obj"
  11236. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  11237. !p.arg.isStatic) // v-bind:[foo]
  11238. );
  11239. }
  11240. function isText(node) {
  11241. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  11242. }
  11243. function isVSlot(p) {
  11244. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  11245. }
  11246. function isTemplateNode(node) {
  11247. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  11248. }
  11249. function isSlotOutlet(node) {
  11250. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  11251. }
  11252. function getVNodeHelper(ssr, isComponent) {
  11253. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  11254. }
  11255. function getVNodeBlockHelper(ssr, isComponent) {
  11256. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  11257. }
  11258. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  11259. function getUnnormalizedProps(props, callPath = []) {
  11260. if (props &&
  11261. !isString(props) &&
  11262. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11263. const callee = props.callee;
  11264. if (!isString(callee) && propsHelperSet.has(callee)) {
  11265. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  11266. }
  11267. }
  11268. return [props, callPath];
  11269. }
  11270. function injectProp(node, prop, context) {
  11271. let propsWithInjection;
  11272. /**
  11273. * 1. mergeProps(...)
  11274. * 2. toHandlers(...)
  11275. * 3. normalizeProps(...)
  11276. * 4. normalizeProps(guardReactiveProps(...))
  11277. *
  11278. * we need to get the real props before normalization
  11279. */
  11280. let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  11281. let callPath = [];
  11282. let parentCall;
  11283. if (props &&
  11284. !isString(props) &&
  11285. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11286. const ret = getUnnormalizedProps(props);
  11287. props = ret[0];
  11288. callPath = ret[1];
  11289. parentCall = callPath[callPath.length - 1];
  11290. }
  11291. if (props == null || isString(props)) {
  11292. propsWithInjection = createObjectExpression([prop]);
  11293. }
  11294. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  11295. // merged props... add ours
  11296. // only inject key to object literal if it's the first argument so that
  11297. // if doesn't override user provided keys
  11298. const first = props.arguments[0];
  11299. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11300. first.properties.unshift(prop);
  11301. }
  11302. else {
  11303. if (props.callee === TO_HANDLERS) {
  11304. // #2366
  11305. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11306. createObjectExpression([prop]),
  11307. props
  11308. ]);
  11309. }
  11310. else {
  11311. props.arguments.unshift(createObjectExpression([prop]));
  11312. }
  11313. }
  11314. !propsWithInjection && (propsWithInjection = props);
  11315. }
  11316. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11317. let alreadyExists = false;
  11318. // check existing key to avoid overriding user provided keys
  11319. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  11320. const propKeyName = prop.key.content;
  11321. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  11322. p.key.content === propKeyName);
  11323. }
  11324. if (!alreadyExists) {
  11325. props.properties.unshift(prop);
  11326. }
  11327. propsWithInjection = props;
  11328. }
  11329. else {
  11330. // single v-bind with expression, return a merged replacement
  11331. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11332. createObjectExpression([prop]),
  11333. props
  11334. ]);
  11335. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  11336. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  11337. // the `guardReactiveProps` will no longer be needed
  11338. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  11339. parentCall = callPath[callPath.length - 2];
  11340. }
  11341. }
  11342. if (node.type === 13 /* VNODE_CALL */) {
  11343. if (parentCall) {
  11344. parentCall.arguments[0] = propsWithInjection;
  11345. }
  11346. else {
  11347. node.props = propsWithInjection;
  11348. }
  11349. }
  11350. else {
  11351. if (parentCall) {
  11352. parentCall.arguments[0] = propsWithInjection;
  11353. }
  11354. else {
  11355. node.arguments[2] = propsWithInjection;
  11356. }
  11357. }
  11358. }
  11359. function toValidAssetId(name, type) {
  11360. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  11361. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  11362. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  11363. })}`;
  11364. }
  11365. function getMemoedVNodeCall(node) {
  11366. if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  11367. return node.arguments[1].returns;
  11368. }
  11369. else {
  11370. return node;
  11371. }
  11372. }
  11373. function makeBlock(node, { helper, removeHelper, inSSR }) {
  11374. if (!node.isBlock) {
  11375. node.isBlock = true;
  11376. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  11377. helper(OPEN_BLOCK);
  11378. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  11379. }
  11380. }
  11381. const deprecationData = {
  11382. ["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
  11383. message: `Platform-native elements with "is" prop will no longer be ` +
  11384. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  11385. `prefixed with "vue:".`,
  11386. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  11387. },
  11388. ["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
  11389. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  11390. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  11391. `\`v-model:${key}\`.`,
  11392. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  11393. },
  11394. ["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
  11395. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  11396. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  11397. },
  11398. ["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
  11399. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  11400. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  11401. `that appears before v-bind in the case of conflict. ` +
  11402. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  11403. `You can also suppress this warning if the usage is intended.`,
  11404. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  11405. },
  11406. ["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
  11407. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  11408. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  11409. },
  11410. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  11411. message: `v-if / v-for precedence when used on the same element has changed ` +
  11412. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  11413. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  11414. `with <template> tags or use a computed property that filters v-for ` +
  11415. `data source.`,
  11416. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  11417. },
  11418. ["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
  11419. message: `<template> with no special directives will render as a native template ` +
  11420. `element instead of its inner content in Vue 3.`
  11421. },
  11422. ["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
  11423. message: `"inline-template" has been removed in Vue 3.`,
  11424. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  11425. },
  11426. ["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
  11427. message: `filters have been removed in Vue 3. ` +
  11428. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  11429. `Use method calls or computed properties instead.`,
  11430. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  11431. }
  11432. };
  11433. function getCompatValue(key, context) {
  11434. const config = context.options
  11435. ? context.options.compatConfig
  11436. : context.compatConfig;
  11437. const value = config && config[key];
  11438. if (key === 'MODE') {
  11439. return value || 3; // compiler defaults to v3 behavior
  11440. }
  11441. else {
  11442. return value;
  11443. }
  11444. }
  11445. function isCompatEnabled(key, context) {
  11446. const mode = getCompatValue('MODE', context);
  11447. const value = getCompatValue(key, context);
  11448. // in v3 mode, only enable if explicitly set to true
  11449. // otherwise enable for any non-false value
  11450. return mode === 3 ? value === true : value !== false;
  11451. }
  11452. function checkCompatEnabled(key, context, loc, ...args) {
  11453. const enabled = isCompatEnabled(key, context);
  11454. if (enabled) {
  11455. warnDeprecation(key, context, loc, ...args);
  11456. }
  11457. return enabled;
  11458. }
  11459. function warnDeprecation(key, context, loc, ...args) {
  11460. const val = getCompatValue(key, context);
  11461. if (val === 'suppress-warning') {
  11462. return;
  11463. }
  11464. const { message, link } = deprecationData[key];
  11465. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  11466. const err = new SyntaxError(msg);
  11467. err.code = key;
  11468. if (loc)
  11469. err.loc = loc;
  11470. context.onWarn(err);
  11471. }
  11472. // The default decoder only provides escapes for characters reserved as part of
  11473. // the template syntax, and is only used if the custom renderer did not provide
  11474. // a platform-specific decoder.
  11475. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  11476. const decodeMap = {
  11477. gt: '>',
  11478. lt: '<',
  11479. amp: '&',
  11480. apos: "'",
  11481. quot: '"'
  11482. };
  11483. const defaultParserOptions = {
  11484. delimiters: [`{{`, `}}`],
  11485. getNamespace: () => 0 /* HTML */,
  11486. getTextMode: () => 0 /* DATA */,
  11487. isVoidTag: NO,
  11488. isPreTag: NO,
  11489. isCustomElement: NO,
  11490. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  11491. onError: defaultOnError,
  11492. onWarn: defaultOnWarn,
  11493. comments: true
  11494. };
  11495. function baseParse(content, options = {}) {
  11496. const context = createParserContext(content, options);
  11497. const start = getCursor(context);
  11498. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  11499. }
  11500. function createParserContext(content, rawOptions) {
  11501. const options = extend({}, defaultParserOptions);
  11502. let key;
  11503. for (key in rawOptions) {
  11504. // @ts-ignore
  11505. options[key] =
  11506. rawOptions[key] === undefined
  11507. ? defaultParserOptions[key]
  11508. : rawOptions[key];
  11509. }
  11510. return {
  11511. options,
  11512. column: 1,
  11513. line: 1,
  11514. offset: 0,
  11515. originalSource: content,
  11516. source: content,
  11517. inPre: false,
  11518. inVPre: false,
  11519. onWarn: options.onWarn
  11520. };
  11521. }
  11522. function parseChildren(context, mode, ancestors) {
  11523. const parent = last(ancestors);
  11524. const ns = parent ? parent.ns : 0 /* HTML */;
  11525. const nodes = [];
  11526. while (!isEnd(context, mode, ancestors)) {
  11527. const s = context.source;
  11528. let node = undefined;
  11529. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  11530. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  11531. // '{{'
  11532. node = parseInterpolation(context, mode);
  11533. }
  11534. else if (mode === 0 /* DATA */ && s[0] === '<') {
  11535. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  11536. if (s.length === 1) {
  11537. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  11538. }
  11539. else if (s[1] === '!') {
  11540. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  11541. if (startsWith(s, '<!--')) {
  11542. node = parseComment(context);
  11543. }
  11544. else if (startsWith(s, '<!DOCTYPE')) {
  11545. // Ignore DOCTYPE by a limitation.
  11546. node = parseBogusComment(context);
  11547. }
  11548. else if (startsWith(s, '<![CDATA[')) {
  11549. if (ns !== 0 /* HTML */) {
  11550. node = parseCDATA(context, ancestors);
  11551. }
  11552. else {
  11553. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  11554. node = parseBogusComment(context);
  11555. }
  11556. }
  11557. else {
  11558. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  11559. node = parseBogusComment(context);
  11560. }
  11561. }
  11562. else if (s[1] === '/') {
  11563. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  11564. if (s.length === 2) {
  11565. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  11566. }
  11567. else if (s[2] === '>') {
  11568. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  11569. advanceBy(context, 3);
  11570. continue;
  11571. }
  11572. else if (/[a-z]/i.test(s[2])) {
  11573. emitError(context, 23 /* X_INVALID_END_TAG */);
  11574. parseTag(context, 1 /* End */, parent);
  11575. continue;
  11576. }
  11577. else {
  11578. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  11579. node = parseBogusComment(context);
  11580. }
  11581. }
  11582. else if (/[a-z]/i.test(s[1])) {
  11583. node = parseElement(context, ancestors);
  11584. }
  11585. else if (s[1] === '?') {
  11586. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  11587. node = parseBogusComment(context);
  11588. }
  11589. else {
  11590. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  11591. }
  11592. }
  11593. }
  11594. if (!node) {
  11595. node = parseText(context, mode);
  11596. }
  11597. if (isArray(node)) {
  11598. for (let i = 0; i < node.length; i++) {
  11599. pushNode(nodes, node[i]);
  11600. }
  11601. }
  11602. else {
  11603. pushNode(nodes, node);
  11604. }
  11605. }
  11606. // Whitespace handling strategy like v2
  11607. let removedWhitespace = false;
  11608. if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
  11609. const shouldCondense = context.options.whitespace !== 'preserve';
  11610. for (let i = 0; i < nodes.length; i++) {
  11611. const node = nodes[i];
  11612. if (!context.inPre && node.type === 2 /* TEXT */) {
  11613. if (!/[^\t\r\n\f ]/.test(node.content)) {
  11614. const prev = nodes[i - 1];
  11615. const next = nodes[i + 1];
  11616. // Remove if:
  11617. // - the whitespace is the first or last node, or:
  11618. // - (condense mode) the whitespace is adjacent to a comment, or:
  11619. // - (condense mode) the whitespace is between two elements AND contains newline
  11620. if (!prev ||
  11621. !next ||
  11622. (shouldCondense &&
  11623. (prev.type === 3 /* COMMENT */ ||
  11624. next.type === 3 /* COMMENT */ ||
  11625. (prev.type === 1 /* ELEMENT */ &&
  11626. next.type === 1 /* ELEMENT */ &&
  11627. /[\r\n]/.test(node.content))))) {
  11628. removedWhitespace = true;
  11629. nodes[i] = null;
  11630. }
  11631. else {
  11632. // Otherwise, the whitespace is condensed into a single space
  11633. node.content = ' ';
  11634. }
  11635. }
  11636. else if (shouldCondense) {
  11637. // in condense mode, consecutive whitespaces in text are condensed
  11638. // down to a single space.
  11639. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  11640. }
  11641. }
  11642. // Remove comment nodes if desired by configuration.
  11643. else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
  11644. removedWhitespace = true;
  11645. nodes[i] = null;
  11646. }
  11647. }
  11648. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  11649. // remove leading newline per html spec
  11650. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  11651. const first = nodes[0];
  11652. if (first && first.type === 2 /* TEXT */) {
  11653. first.content = first.content.replace(/^\r?\n/, '');
  11654. }
  11655. }
  11656. }
  11657. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  11658. }
  11659. function pushNode(nodes, node) {
  11660. if (node.type === 2 /* TEXT */) {
  11661. const prev = last(nodes);
  11662. // Merge if both this and the previous node are text and those are
  11663. // consecutive. This happens for cases like "a < b".
  11664. if (prev &&
  11665. prev.type === 2 /* TEXT */ &&
  11666. prev.loc.end.offset === node.loc.start.offset) {
  11667. prev.content += node.content;
  11668. prev.loc.end = node.loc.end;
  11669. prev.loc.source += node.loc.source;
  11670. return;
  11671. }
  11672. }
  11673. nodes.push(node);
  11674. }
  11675. function parseCDATA(context, ancestors) {
  11676. advanceBy(context, 9);
  11677. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  11678. if (context.source.length === 0) {
  11679. emitError(context, 6 /* EOF_IN_CDATA */);
  11680. }
  11681. else {
  11682. advanceBy(context, 3);
  11683. }
  11684. return nodes;
  11685. }
  11686. function parseComment(context) {
  11687. const start = getCursor(context);
  11688. let content;
  11689. // Regular comment.
  11690. const match = /--(\!)?>/.exec(context.source);
  11691. if (!match) {
  11692. content = context.source.slice(4);
  11693. advanceBy(context, context.source.length);
  11694. emitError(context, 7 /* EOF_IN_COMMENT */);
  11695. }
  11696. else {
  11697. if (match.index <= 3) {
  11698. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  11699. }
  11700. if (match[1]) {
  11701. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  11702. }
  11703. content = context.source.slice(4, match.index);
  11704. // Advancing with reporting nested comments.
  11705. const s = context.source.slice(0, match.index);
  11706. let prevIndex = 1, nestedIndex = 0;
  11707. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  11708. advanceBy(context, nestedIndex - prevIndex + 1);
  11709. if (nestedIndex + 4 < s.length) {
  11710. emitError(context, 16 /* NESTED_COMMENT */);
  11711. }
  11712. prevIndex = nestedIndex + 1;
  11713. }
  11714. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  11715. }
  11716. return {
  11717. type: 3 /* COMMENT */,
  11718. content,
  11719. loc: getSelection(context, start)
  11720. };
  11721. }
  11722. function parseBogusComment(context) {
  11723. const start = getCursor(context);
  11724. const contentStart = context.source[1] === '?' ? 1 : 2;
  11725. let content;
  11726. const closeIndex = context.source.indexOf('>');
  11727. if (closeIndex === -1) {
  11728. content = context.source.slice(contentStart);
  11729. advanceBy(context, context.source.length);
  11730. }
  11731. else {
  11732. content = context.source.slice(contentStart, closeIndex);
  11733. advanceBy(context, closeIndex + 1);
  11734. }
  11735. return {
  11736. type: 3 /* COMMENT */,
  11737. content,
  11738. loc: getSelection(context, start)
  11739. };
  11740. }
  11741. function parseElement(context, ancestors) {
  11742. // Start tag.
  11743. const wasInPre = context.inPre;
  11744. const wasInVPre = context.inVPre;
  11745. const parent = last(ancestors);
  11746. const element = parseTag(context, 0 /* Start */, parent);
  11747. const isPreBoundary = context.inPre && !wasInPre;
  11748. const isVPreBoundary = context.inVPre && !wasInVPre;
  11749. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  11750. // #4030 self-closing <pre> tag
  11751. if (isPreBoundary) {
  11752. context.inPre = false;
  11753. }
  11754. if (isVPreBoundary) {
  11755. context.inVPre = false;
  11756. }
  11757. return element;
  11758. }
  11759. // Children.
  11760. ancestors.push(element);
  11761. const mode = context.options.getTextMode(element, parent);
  11762. const children = parseChildren(context, mode, ancestors);
  11763. ancestors.pop();
  11764. element.children = children;
  11765. // End tag.
  11766. if (startsWithEndTagOpen(context.source, element.tag)) {
  11767. parseTag(context, 1 /* End */, parent);
  11768. }
  11769. else {
  11770. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  11771. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  11772. const first = children[0];
  11773. if (first && startsWith(first.loc.source, '<!--')) {
  11774. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  11775. }
  11776. }
  11777. }
  11778. element.loc = getSelection(context, element.loc.start);
  11779. if (isPreBoundary) {
  11780. context.inPre = false;
  11781. }
  11782. if (isVPreBoundary) {
  11783. context.inVPre = false;
  11784. }
  11785. return element;
  11786. }
  11787. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  11788. function parseTag(context, type, parent) {
  11789. // Tag open.
  11790. const start = getCursor(context);
  11791. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  11792. const tag = match[1];
  11793. const ns = context.options.getNamespace(tag, parent);
  11794. advanceBy(context, match[0].length);
  11795. advanceSpaces(context);
  11796. // save current state in case we need to re-parse attributes with v-pre
  11797. const cursor = getCursor(context);
  11798. const currentSource = context.source;
  11799. // check <pre> tag
  11800. if (context.options.isPreTag(tag)) {
  11801. context.inPre = true;
  11802. }
  11803. // Attributes.
  11804. let props = parseAttributes(context, type);
  11805. // check v-pre
  11806. if (type === 0 /* Start */ &&
  11807. !context.inVPre &&
  11808. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  11809. context.inVPre = true;
  11810. // reset context
  11811. extend(context, cursor);
  11812. context.source = currentSource;
  11813. // re-parse attrs and filter out v-pre itself
  11814. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  11815. }
  11816. // Tag close.
  11817. let isSelfClosing = false;
  11818. if (context.source.length === 0) {
  11819. emitError(context, 9 /* EOF_IN_TAG */);
  11820. }
  11821. else {
  11822. isSelfClosing = startsWith(context.source, '/>');
  11823. if (type === 1 /* End */ && isSelfClosing) {
  11824. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  11825. }
  11826. advanceBy(context, isSelfClosing ? 2 : 1);
  11827. }
  11828. if (type === 1 /* End */) {
  11829. return;
  11830. }
  11831. let tagType = 0 /* ELEMENT */;
  11832. if (!context.inVPre) {
  11833. if (tag === 'slot') {
  11834. tagType = 2 /* SLOT */;
  11835. }
  11836. else if (tag === 'template') {
  11837. if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  11838. tagType = 3 /* TEMPLATE */;
  11839. }
  11840. }
  11841. else if (isComponent(tag, props, context)) {
  11842. tagType = 1 /* COMPONENT */;
  11843. }
  11844. }
  11845. return {
  11846. type: 1 /* ELEMENT */,
  11847. ns,
  11848. tag,
  11849. tagType,
  11850. props,
  11851. isSelfClosing,
  11852. children: [],
  11853. loc: getSelection(context, start),
  11854. codegenNode: undefined // to be created during transform phase
  11855. };
  11856. }
  11857. function isComponent(tag, props, context) {
  11858. const options = context.options;
  11859. if (options.isCustomElement(tag)) {
  11860. return false;
  11861. }
  11862. if (tag === 'component' ||
  11863. /^[A-Z]/.test(tag) ||
  11864. isCoreComponent(tag) ||
  11865. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  11866. (options.isNativeTag && !options.isNativeTag(tag))) {
  11867. return true;
  11868. }
  11869. // at this point the tag should be a native tag, but check for potential "is"
  11870. // casting
  11871. for (let i = 0; i < props.length; i++) {
  11872. const p = props[i];
  11873. if (p.type === 6 /* ATTRIBUTE */) {
  11874. if (p.name === 'is' && p.value) {
  11875. if (p.value.content.startsWith('vue:')) {
  11876. return true;
  11877. }
  11878. }
  11879. }
  11880. else {
  11881. // directive
  11882. // v-is (TODO Deprecate)
  11883. if (p.name === 'is') {
  11884. return true;
  11885. }
  11886. else if (
  11887. // :is on plain element - only treat as component in compat mode
  11888. p.name === 'bind' &&
  11889. isStaticArgOf(p.arg, 'is') &&
  11890. false &&
  11891. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  11892. return true;
  11893. }
  11894. }
  11895. }
  11896. }
  11897. function parseAttributes(context, type) {
  11898. const props = [];
  11899. const attributeNames = new Set();
  11900. while (context.source.length > 0 &&
  11901. !startsWith(context.source, '>') &&
  11902. !startsWith(context.source, '/>')) {
  11903. if (startsWith(context.source, '/')) {
  11904. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  11905. advanceBy(context, 1);
  11906. advanceSpaces(context);
  11907. continue;
  11908. }
  11909. if (type === 1 /* End */) {
  11910. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  11911. }
  11912. const attr = parseAttribute(context, attributeNames);
  11913. // Trim whitespace between class
  11914. // https://github.com/vuejs/core/issues/4251
  11915. if (attr.type === 6 /* ATTRIBUTE */ &&
  11916. attr.value &&
  11917. attr.name === 'class') {
  11918. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  11919. }
  11920. if (type === 0 /* Start */) {
  11921. props.push(attr);
  11922. }
  11923. if (/^[^\t\r\n\f />]/.test(context.source)) {
  11924. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  11925. }
  11926. advanceSpaces(context);
  11927. }
  11928. return props;
  11929. }
  11930. function parseAttribute(context, nameSet) {
  11931. // Name.
  11932. const start = getCursor(context);
  11933. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  11934. const name = match[0];
  11935. if (nameSet.has(name)) {
  11936. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  11937. }
  11938. nameSet.add(name);
  11939. if (name[0] === '=') {
  11940. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  11941. }
  11942. {
  11943. const pattern = /["'<]/g;
  11944. let m;
  11945. while ((m = pattern.exec(name))) {
  11946. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  11947. }
  11948. }
  11949. advanceBy(context, name.length);
  11950. // Value
  11951. let value = undefined;
  11952. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  11953. advanceSpaces(context);
  11954. advanceBy(context, 1);
  11955. advanceSpaces(context);
  11956. value = parseAttributeValue(context);
  11957. if (!value) {
  11958. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  11959. }
  11960. }
  11961. const loc = getSelection(context, start);
  11962. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  11963. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  11964. let isPropShorthand = startsWith(name, '.');
  11965. let dirName = match[1] ||
  11966. (isPropShorthand || startsWith(name, ':')
  11967. ? 'bind'
  11968. : startsWith(name, '@')
  11969. ? 'on'
  11970. : 'slot');
  11971. let arg;
  11972. if (match[2]) {
  11973. const isSlot = dirName === 'slot';
  11974. const startOffset = name.lastIndexOf(match[2]);
  11975. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  11976. let content = match[2];
  11977. let isStatic = true;
  11978. if (content.startsWith('[')) {
  11979. isStatic = false;
  11980. if (!content.endsWith(']')) {
  11981. emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  11982. content = content.slice(1);
  11983. }
  11984. else {
  11985. content = content.slice(1, content.length - 1);
  11986. }
  11987. }
  11988. else if (isSlot) {
  11989. // #1241 special case for v-slot: vuetify relies extensively on slot
  11990. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  11991. // supports such usage so we are keeping it consistent with 2.x.
  11992. content += match[3] || '';
  11993. }
  11994. arg = {
  11995. type: 4 /* SIMPLE_EXPRESSION */,
  11996. content,
  11997. isStatic,
  11998. constType: isStatic
  11999. ? 3 /* CAN_STRINGIFY */
  12000. : 0 /* NOT_CONSTANT */,
  12001. loc
  12002. };
  12003. }
  12004. if (value && value.isQuoted) {
  12005. const valueLoc = value.loc;
  12006. valueLoc.start.offset++;
  12007. valueLoc.start.column++;
  12008. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  12009. valueLoc.source = valueLoc.source.slice(1, -1);
  12010. }
  12011. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  12012. if (isPropShorthand)
  12013. modifiers.push('prop');
  12014. return {
  12015. type: 7 /* DIRECTIVE */,
  12016. name: dirName,
  12017. exp: value && {
  12018. type: 4 /* SIMPLE_EXPRESSION */,
  12019. content: value.content,
  12020. isStatic: false,
  12021. // Treat as non-constant by default. This can be potentially set to
  12022. // other values by `transformExpression` to make it eligible for hoisting.
  12023. constType: 0 /* NOT_CONSTANT */,
  12024. loc: value.loc
  12025. },
  12026. arg,
  12027. modifiers,
  12028. loc
  12029. };
  12030. }
  12031. // missing directive name or illegal directive name
  12032. if (!context.inVPre && startsWith(name, 'v-')) {
  12033. emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
  12034. }
  12035. return {
  12036. type: 6 /* ATTRIBUTE */,
  12037. name,
  12038. value: value && {
  12039. type: 2 /* TEXT */,
  12040. content: value.content,
  12041. loc: value.loc
  12042. },
  12043. loc
  12044. };
  12045. }
  12046. function parseAttributeValue(context) {
  12047. const start = getCursor(context);
  12048. let content;
  12049. const quote = context.source[0];
  12050. const isQuoted = quote === `"` || quote === `'`;
  12051. if (isQuoted) {
  12052. // Quoted value.
  12053. advanceBy(context, 1);
  12054. const endIndex = context.source.indexOf(quote);
  12055. if (endIndex === -1) {
  12056. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  12057. }
  12058. else {
  12059. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  12060. advanceBy(context, 1);
  12061. }
  12062. }
  12063. else {
  12064. // Unquoted
  12065. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  12066. if (!match) {
  12067. return undefined;
  12068. }
  12069. const unexpectedChars = /["'<=`]/g;
  12070. let m;
  12071. while ((m = unexpectedChars.exec(match[0]))) {
  12072. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  12073. }
  12074. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  12075. }
  12076. return { content, isQuoted, loc: getSelection(context, start) };
  12077. }
  12078. function parseInterpolation(context, mode) {
  12079. const [open, close] = context.options.delimiters;
  12080. const closeIndex = context.source.indexOf(close, open.length);
  12081. if (closeIndex === -1) {
  12082. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  12083. return undefined;
  12084. }
  12085. const start = getCursor(context);
  12086. advanceBy(context, open.length);
  12087. const innerStart = getCursor(context);
  12088. const innerEnd = getCursor(context);
  12089. const rawContentLength = closeIndex - open.length;
  12090. const rawContent = context.source.slice(0, rawContentLength);
  12091. const preTrimContent = parseTextData(context, rawContentLength, mode);
  12092. const content = preTrimContent.trim();
  12093. const startOffset = preTrimContent.indexOf(content);
  12094. if (startOffset > 0) {
  12095. advancePositionWithMutation(innerStart, rawContent, startOffset);
  12096. }
  12097. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  12098. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  12099. advanceBy(context, close.length);
  12100. return {
  12101. type: 5 /* INTERPOLATION */,
  12102. content: {
  12103. type: 4 /* SIMPLE_EXPRESSION */,
  12104. isStatic: false,
  12105. // Set `isConstant` to false by default and will decide in transformExpression
  12106. constType: 0 /* NOT_CONSTANT */,
  12107. content,
  12108. loc: getSelection(context, innerStart, innerEnd)
  12109. },
  12110. loc: getSelection(context, start)
  12111. };
  12112. }
  12113. function parseText(context, mode) {
  12114. const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  12115. let endIndex = context.source.length;
  12116. for (let i = 0; i < endTokens.length; i++) {
  12117. const index = context.source.indexOf(endTokens[i], 1);
  12118. if (index !== -1 && endIndex > index) {
  12119. endIndex = index;
  12120. }
  12121. }
  12122. const start = getCursor(context);
  12123. const content = parseTextData(context, endIndex, mode);
  12124. return {
  12125. type: 2 /* TEXT */,
  12126. content,
  12127. loc: getSelection(context, start)
  12128. };
  12129. }
  12130. /**
  12131. * Get text data with a given length from the current location.
  12132. * This translates HTML entities in the text data.
  12133. */
  12134. function parseTextData(context, length, mode) {
  12135. const rawText = context.source.slice(0, length);
  12136. advanceBy(context, length);
  12137. if (mode === 2 /* RAWTEXT */ ||
  12138. mode === 3 /* CDATA */ ||
  12139. !rawText.includes('&')) {
  12140. return rawText;
  12141. }
  12142. else {
  12143. // DATA or RCDATA containing "&"". Entity decoding required.
  12144. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  12145. }
  12146. }
  12147. function getCursor(context) {
  12148. const { column, line, offset } = context;
  12149. return { column, line, offset };
  12150. }
  12151. function getSelection(context, start, end) {
  12152. end = end || getCursor(context);
  12153. return {
  12154. start,
  12155. end,
  12156. source: context.originalSource.slice(start.offset, end.offset)
  12157. };
  12158. }
  12159. function last(xs) {
  12160. return xs[xs.length - 1];
  12161. }
  12162. function startsWith(source, searchString) {
  12163. return source.startsWith(searchString);
  12164. }
  12165. function advanceBy(context, numberOfCharacters) {
  12166. const { source } = context;
  12167. advancePositionWithMutation(context, source, numberOfCharacters);
  12168. context.source = source.slice(numberOfCharacters);
  12169. }
  12170. function advanceSpaces(context) {
  12171. const match = /^[\t\r\n\f ]+/.exec(context.source);
  12172. if (match) {
  12173. advanceBy(context, match[0].length);
  12174. }
  12175. }
  12176. function getNewPosition(context, start, numberOfCharacters) {
  12177. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  12178. }
  12179. function emitError(context, code, offset, loc = getCursor(context)) {
  12180. if (offset) {
  12181. loc.offset += offset;
  12182. loc.column += offset;
  12183. }
  12184. context.options.onError(createCompilerError(code, {
  12185. start: loc,
  12186. end: loc,
  12187. source: ''
  12188. }));
  12189. }
  12190. function isEnd(context, mode, ancestors) {
  12191. const s = context.source;
  12192. switch (mode) {
  12193. case 0 /* DATA */:
  12194. if (startsWith(s, '</')) {
  12195. // TODO: probably bad performance
  12196. for (let i = ancestors.length - 1; i >= 0; --i) {
  12197. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  12198. return true;
  12199. }
  12200. }
  12201. }
  12202. break;
  12203. case 1 /* RCDATA */:
  12204. case 2 /* RAWTEXT */: {
  12205. const parent = last(ancestors);
  12206. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  12207. return true;
  12208. }
  12209. break;
  12210. }
  12211. case 3 /* CDATA */:
  12212. if (startsWith(s, ']]>')) {
  12213. return true;
  12214. }
  12215. break;
  12216. }
  12217. return !s;
  12218. }
  12219. function startsWithEndTagOpen(source, tag) {
  12220. return (startsWith(source, '</') &&
  12221. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  12222. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  12223. }
  12224. function hoistStatic(root, context) {
  12225. walk(root, context,
  12226. // Root node is unfortunately non-hoistable due to potential parent
  12227. // fallthrough attributes.
  12228. isSingleElementRoot(root, root.children[0]));
  12229. }
  12230. function isSingleElementRoot(root, child) {
  12231. const { children } = root;
  12232. return (children.length === 1 &&
  12233. child.type === 1 /* ELEMENT */ &&
  12234. !isSlotOutlet(child));
  12235. }
  12236. function walk(node, context, doNotHoistNode = false) {
  12237. const { children } = node;
  12238. const originalCount = children.length;
  12239. let hoistedCount = 0;
  12240. for (let i = 0; i < children.length; i++) {
  12241. const child = children[i];
  12242. // only plain elements & text calls are eligible for hoisting.
  12243. if (child.type === 1 /* ELEMENT */ &&
  12244. child.tagType === 0 /* ELEMENT */) {
  12245. const constantType = doNotHoistNode
  12246. ? 0 /* NOT_CONSTANT */
  12247. : getConstantType(child, context);
  12248. if (constantType > 0 /* NOT_CONSTANT */) {
  12249. if (constantType >= 2 /* CAN_HOIST */) {
  12250. child.codegenNode.patchFlag =
  12251. -1 /* HOISTED */ + (` /* HOISTED */` );
  12252. child.codegenNode = context.hoist(child.codegenNode);
  12253. hoistedCount++;
  12254. continue;
  12255. }
  12256. }
  12257. else {
  12258. // node may contain dynamic children, but its props may be eligible for
  12259. // hoisting.
  12260. const codegenNode = child.codegenNode;
  12261. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12262. const flag = getPatchFlag(codegenNode);
  12263. if ((!flag ||
  12264. flag === 512 /* NEED_PATCH */ ||
  12265. flag === 1 /* TEXT */) &&
  12266. getGeneratedPropsConstantType(child, context) >=
  12267. 2 /* CAN_HOIST */) {
  12268. const props = getNodeProps(child);
  12269. if (props) {
  12270. codegenNode.props = context.hoist(props);
  12271. }
  12272. }
  12273. if (codegenNode.dynamicProps) {
  12274. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  12275. }
  12276. }
  12277. }
  12278. }
  12279. else if (child.type === 12 /* TEXT_CALL */ &&
  12280. getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
  12281. child.codegenNode = context.hoist(child.codegenNode);
  12282. hoistedCount++;
  12283. }
  12284. // walk further
  12285. if (child.type === 1 /* ELEMENT */) {
  12286. const isComponent = child.tagType === 1 /* COMPONENT */;
  12287. if (isComponent) {
  12288. context.scopes.vSlot++;
  12289. }
  12290. walk(child, context);
  12291. if (isComponent) {
  12292. context.scopes.vSlot--;
  12293. }
  12294. }
  12295. else if (child.type === 11 /* FOR */) {
  12296. // Do not hoist v-for single child because it has to be a block
  12297. walk(child, context, child.children.length === 1);
  12298. }
  12299. else if (child.type === 9 /* IF */) {
  12300. for (let i = 0; i < child.branches.length; i++) {
  12301. // Do not hoist v-if single child because it has to be a block
  12302. walk(child.branches[i], context, child.branches[i].children.length === 1);
  12303. }
  12304. }
  12305. }
  12306. if (hoistedCount && context.transformHoist) {
  12307. context.transformHoist(children, context, node);
  12308. }
  12309. // all children were hoisted - the entire children array is hoistable.
  12310. if (hoistedCount &&
  12311. hoistedCount === originalCount &&
  12312. node.type === 1 /* ELEMENT */ &&
  12313. node.tagType === 0 /* ELEMENT */ &&
  12314. node.codegenNode &&
  12315. node.codegenNode.type === 13 /* VNODE_CALL */ &&
  12316. isArray(node.codegenNode.children)) {
  12317. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  12318. }
  12319. }
  12320. function getConstantType(node, context) {
  12321. const { constantCache } = context;
  12322. switch (node.type) {
  12323. case 1 /* ELEMENT */:
  12324. if (node.tagType !== 0 /* ELEMENT */) {
  12325. return 0 /* NOT_CONSTANT */;
  12326. }
  12327. const cached = constantCache.get(node);
  12328. if (cached !== undefined) {
  12329. return cached;
  12330. }
  12331. const codegenNode = node.codegenNode;
  12332. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  12333. return 0 /* NOT_CONSTANT */;
  12334. }
  12335. if (codegenNode.isBlock &&
  12336. node.tag !== 'svg' &&
  12337. node.tag !== 'foreignObject') {
  12338. return 0 /* NOT_CONSTANT */;
  12339. }
  12340. const flag = getPatchFlag(codegenNode);
  12341. if (!flag) {
  12342. let returnType = 3 /* CAN_STRINGIFY */;
  12343. // Element itself has no patch flag. However we still need to check:
  12344. // 1. Even for a node with no patch flag, it is possible for it to contain
  12345. // non-hoistable expressions that refers to scope variables, e.g. compiler
  12346. // injected keys or cached event handlers. Therefore we need to always
  12347. // check the codegenNode's props to be sure.
  12348. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  12349. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  12350. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12351. return 0 /* NOT_CONSTANT */;
  12352. }
  12353. if (generatedPropsType < returnType) {
  12354. returnType = generatedPropsType;
  12355. }
  12356. // 2. its children.
  12357. for (let i = 0; i < node.children.length; i++) {
  12358. const childType = getConstantType(node.children[i], context);
  12359. if (childType === 0 /* NOT_CONSTANT */) {
  12360. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12361. return 0 /* NOT_CONSTANT */;
  12362. }
  12363. if (childType < returnType) {
  12364. returnType = childType;
  12365. }
  12366. }
  12367. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  12368. // type, check if any of the props can cause the type to be lowered
  12369. // we can skip can_patch because it's guaranteed by the absence of a
  12370. // patchFlag.
  12371. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  12372. for (let i = 0; i < node.props.length; i++) {
  12373. const p = node.props[i];
  12374. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  12375. const expType = getConstantType(p.exp, context);
  12376. if (expType === 0 /* NOT_CONSTANT */) {
  12377. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12378. return 0 /* NOT_CONSTANT */;
  12379. }
  12380. if (expType < returnType) {
  12381. returnType = expType;
  12382. }
  12383. }
  12384. }
  12385. }
  12386. // only svg/foreignObject could be block here, however if they are
  12387. // static then they don't need to be blocks since there will be no
  12388. // nested updates.
  12389. if (codegenNode.isBlock) {
  12390. context.removeHelper(OPEN_BLOCK);
  12391. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  12392. codegenNode.isBlock = false;
  12393. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  12394. }
  12395. constantCache.set(node, returnType);
  12396. return returnType;
  12397. }
  12398. else {
  12399. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12400. return 0 /* NOT_CONSTANT */;
  12401. }
  12402. case 2 /* TEXT */:
  12403. case 3 /* COMMENT */:
  12404. return 3 /* CAN_STRINGIFY */;
  12405. case 9 /* IF */:
  12406. case 11 /* FOR */:
  12407. case 10 /* IF_BRANCH */:
  12408. return 0 /* NOT_CONSTANT */;
  12409. case 5 /* INTERPOLATION */:
  12410. case 12 /* TEXT_CALL */:
  12411. return getConstantType(node.content, context);
  12412. case 4 /* SIMPLE_EXPRESSION */:
  12413. return node.constType;
  12414. case 8 /* COMPOUND_EXPRESSION */:
  12415. let returnType = 3 /* CAN_STRINGIFY */;
  12416. for (let i = 0; i < node.children.length; i++) {
  12417. const child = node.children[i];
  12418. if (isString(child) || isSymbol(child)) {
  12419. continue;
  12420. }
  12421. const childType = getConstantType(child, context);
  12422. if (childType === 0 /* NOT_CONSTANT */) {
  12423. return 0 /* NOT_CONSTANT */;
  12424. }
  12425. else if (childType < returnType) {
  12426. returnType = childType;
  12427. }
  12428. }
  12429. return returnType;
  12430. default:
  12431. return 0 /* NOT_CONSTANT */;
  12432. }
  12433. }
  12434. const allowHoistedHelperSet = new Set([
  12435. NORMALIZE_CLASS,
  12436. NORMALIZE_STYLE,
  12437. NORMALIZE_PROPS,
  12438. GUARD_REACTIVE_PROPS
  12439. ]);
  12440. function getConstantTypeOfHelperCall(value, context) {
  12441. if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
  12442. !isString(value.callee) &&
  12443. allowHoistedHelperSet.has(value.callee)) {
  12444. const arg = value.arguments[0];
  12445. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12446. return getConstantType(arg, context);
  12447. }
  12448. else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
  12449. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  12450. return getConstantTypeOfHelperCall(arg, context);
  12451. }
  12452. }
  12453. return 0 /* NOT_CONSTANT */;
  12454. }
  12455. function getGeneratedPropsConstantType(node, context) {
  12456. let returnType = 3 /* CAN_STRINGIFY */;
  12457. const props = getNodeProps(node);
  12458. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  12459. const { properties } = props;
  12460. for (let i = 0; i < properties.length; i++) {
  12461. const { key, value } = properties[i];
  12462. const keyType = getConstantType(key, context);
  12463. if (keyType === 0 /* NOT_CONSTANT */) {
  12464. return keyType;
  12465. }
  12466. if (keyType < returnType) {
  12467. returnType = keyType;
  12468. }
  12469. let valueType;
  12470. if (value.type === 4 /* SIMPLE_EXPRESSION */) {
  12471. valueType = getConstantType(value, context);
  12472. }
  12473. else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
  12474. // some helper calls can be hoisted,
  12475. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  12476. // in this case we need to respect the ConstantType of the helper's arguments
  12477. valueType = getConstantTypeOfHelperCall(value, context);
  12478. }
  12479. else {
  12480. valueType = 0 /* NOT_CONSTANT */;
  12481. }
  12482. if (valueType === 0 /* NOT_CONSTANT */) {
  12483. return valueType;
  12484. }
  12485. if (valueType < returnType) {
  12486. returnType = valueType;
  12487. }
  12488. }
  12489. }
  12490. return returnType;
  12491. }
  12492. function getNodeProps(node) {
  12493. const codegenNode = node.codegenNode;
  12494. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12495. return codegenNode.props;
  12496. }
  12497. }
  12498. function getPatchFlag(node) {
  12499. const flag = node.patchFlag;
  12500. return flag ? parseInt(flag, 10) : undefined;
  12501. }
  12502. function createTransformContext(root, { filename = '', prefixIdentifiers = false, hoistStatic = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, isCustomElement = NOOP, expressionPlugins = [], scopeId = null, slotted = true, ssr = false, inSSR = false, ssrCssVars = ``, bindingMetadata = EMPTY_OBJ, inline = false, isTS = false, onError = defaultOnError, onWarn = defaultOnWarn, compatConfig }) {
  12503. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  12504. const context = {
  12505. // options
  12506. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  12507. prefixIdentifiers,
  12508. hoistStatic,
  12509. cacheHandlers,
  12510. nodeTransforms,
  12511. directiveTransforms,
  12512. transformHoist,
  12513. isBuiltInComponent,
  12514. isCustomElement,
  12515. expressionPlugins,
  12516. scopeId,
  12517. slotted,
  12518. ssr,
  12519. inSSR,
  12520. ssrCssVars,
  12521. bindingMetadata,
  12522. inline,
  12523. isTS,
  12524. onError,
  12525. onWarn,
  12526. compatConfig,
  12527. // state
  12528. root,
  12529. helpers: new Map(),
  12530. components: new Set(),
  12531. directives: new Set(),
  12532. hoists: [],
  12533. imports: [],
  12534. constantCache: new Map(),
  12535. temps: 0,
  12536. cached: 0,
  12537. identifiers: Object.create(null),
  12538. scopes: {
  12539. vFor: 0,
  12540. vSlot: 0,
  12541. vPre: 0,
  12542. vOnce: 0
  12543. },
  12544. parent: null,
  12545. currentNode: root,
  12546. childIndex: 0,
  12547. inVOnce: false,
  12548. // methods
  12549. helper(name) {
  12550. const count = context.helpers.get(name) || 0;
  12551. context.helpers.set(name, count + 1);
  12552. return name;
  12553. },
  12554. removeHelper(name) {
  12555. const count = context.helpers.get(name);
  12556. if (count) {
  12557. const currentCount = count - 1;
  12558. if (!currentCount) {
  12559. context.helpers.delete(name);
  12560. }
  12561. else {
  12562. context.helpers.set(name, currentCount);
  12563. }
  12564. }
  12565. },
  12566. helperString(name) {
  12567. return `_${helperNameMap[context.helper(name)]}`;
  12568. },
  12569. replaceNode(node) {
  12570. /* istanbul ignore if */
  12571. {
  12572. if (!context.currentNode) {
  12573. throw new Error(`Node being replaced is already removed.`);
  12574. }
  12575. if (!context.parent) {
  12576. throw new Error(`Cannot replace root node.`);
  12577. }
  12578. }
  12579. context.parent.children[context.childIndex] = context.currentNode = node;
  12580. },
  12581. removeNode(node) {
  12582. if (!context.parent) {
  12583. throw new Error(`Cannot remove root node.`);
  12584. }
  12585. const list = context.parent.children;
  12586. const removalIndex = node
  12587. ? list.indexOf(node)
  12588. : context.currentNode
  12589. ? context.childIndex
  12590. : -1;
  12591. /* istanbul ignore if */
  12592. if (removalIndex < 0) {
  12593. throw new Error(`node being removed is not a child of current parent`);
  12594. }
  12595. if (!node || node === context.currentNode) {
  12596. // current node removed
  12597. context.currentNode = null;
  12598. context.onNodeRemoved();
  12599. }
  12600. else {
  12601. // sibling node removed
  12602. if (context.childIndex > removalIndex) {
  12603. context.childIndex--;
  12604. context.onNodeRemoved();
  12605. }
  12606. }
  12607. context.parent.children.splice(removalIndex, 1);
  12608. },
  12609. onNodeRemoved: () => { },
  12610. addIdentifiers(exp) {
  12611. },
  12612. removeIdentifiers(exp) {
  12613. },
  12614. hoist(exp) {
  12615. if (isString(exp))
  12616. exp = createSimpleExpression(exp);
  12617. context.hoists.push(exp);
  12618. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  12619. identifier.hoisted = exp;
  12620. return identifier;
  12621. },
  12622. cache(exp, isVNode = false) {
  12623. return createCacheExpression(context.cached++, exp, isVNode);
  12624. }
  12625. };
  12626. return context;
  12627. }
  12628. function transform(root, options) {
  12629. const context = createTransformContext(root, options);
  12630. traverseNode(root, context);
  12631. if (options.hoistStatic) {
  12632. hoistStatic(root, context);
  12633. }
  12634. if (!options.ssr) {
  12635. createRootCodegen(root, context);
  12636. }
  12637. // finalize meta information
  12638. root.helpers = [...context.helpers.keys()];
  12639. root.components = [...context.components];
  12640. root.directives = [...context.directives];
  12641. root.imports = context.imports;
  12642. root.hoists = context.hoists;
  12643. root.temps = context.temps;
  12644. root.cached = context.cached;
  12645. }
  12646. function createRootCodegen(root, context) {
  12647. const { helper } = context;
  12648. const { children } = root;
  12649. if (children.length === 1) {
  12650. const child = children[0];
  12651. // if the single child is an element, turn it into a block.
  12652. if (isSingleElementRoot(root, child) && child.codegenNode) {
  12653. // single element root is never hoisted so codegenNode will never be
  12654. // SimpleExpressionNode
  12655. const codegenNode = child.codegenNode;
  12656. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12657. makeBlock(codegenNode, context);
  12658. }
  12659. root.codegenNode = codegenNode;
  12660. }
  12661. else {
  12662. // - single <slot/>, IfNode, ForNode: already blocks.
  12663. // - single text node: always patched.
  12664. // root codegen falls through via genNode()
  12665. root.codegenNode = child;
  12666. }
  12667. }
  12668. else if (children.length > 1) {
  12669. // root has multiple nodes - return a fragment block.
  12670. let patchFlag = 64 /* STABLE_FRAGMENT */;
  12671. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  12672. // check if the fragment actually contains a single valid child with
  12673. // the rest being comments
  12674. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  12675. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  12676. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  12677. }
  12678. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
  12679. }
  12680. else ;
  12681. }
  12682. function traverseChildren(parent, context) {
  12683. let i = 0;
  12684. const nodeRemoved = () => {
  12685. i--;
  12686. };
  12687. for (; i < parent.children.length; i++) {
  12688. const child = parent.children[i];
  12689. if (isString(child))
  12690. continue;
  12691. context.parent = parent;
  12692. context.childIndex = i;
  12693. context.onNodeRemoved = nodeRemoved;
  12694. traverseNode(child, context);
  12695. }
  12696. }
  12697. function traverseNode(node, context) {
  12698. context.currentNode = node;
  12699. // apply transform plugins
  12700. const { nodeTransforms } = context;
  12701. const exitFns = [];
  12702. for (let i = 0; i < nodeTransforms.length; i++) {
  12703. const onExit = nodeTransforms[i](node, context);
  12704. if (onExit) {
  12705. if (isArray(onExit)) {
  12706. exitFns.push(...onExit);
  12707. }
  12708. else {
  12709. exitFns.push(onExit);
  12710. }
  12711. }
  12712. if (!context.currentNode) {
  12713. // node was removed
  12714. return;
  12715. }
  12716. else {
  12717. // node may have been replaced
  12718. node = context.currentNode;
  12719. }
  12720. }
  12721. switch (node.type) {
  12722. case 3 /* COMMENT */:
  12723. if (!context.ssr) {
  12724. // inject import for the Comment symbol, which is needed for creating
  12725. // comment nodes with `createVNode`
  12726. context.helper(CREATE_COMMENT);
  12727. }
  12728. break;
  12729. case 5 /* INTERPOLATION */:
  12730. // no need to traverse, but we need to inject toString helper
  12731. if (!context.ssr) {
  12732. context.helper(TO_DISPLAY_STRING);
  12733. }
  12734. break;
  12735. // for container types, further traverse downwards
  12736. case 9 /* IF */:
  12737. for (let i = 0; i < node.branches.length; i++) {
  12738. traverseNode(node.branches[i], context);
  12739. }
  12740. break;
  12741. case 10 /* IF_BRANCH */:
  12742. case 11 /* FOR */:
  12743. case 1 /* ELEMENT */:
  12744. case 0 /* ROOT */:
  12745. traverseChildren(node, context);
  12746. break;
  12747. }
  12748. // exit transforms
  12749. context.currentNode = node;
  12750. let i = exitFns.length;
  12751. while (i--) {
  12752. exitFns[i]();
  12753. }
  12754. }
  12755. function createStructuralDirectiveTransform(name, fn) {
  12756. const matches = isString(name)
  12757. ? (n) => n === name
  12758. : (n) => name.test(n);
  12759. return (node, context) => {
  12760. if (node.type === 1 /* ELEMENT */) {
  12761. const { props } = node;
  12762. // structural directive transforms are not concerned with slots
  12763. // as they are handled separately in vSlot.ts
  12764. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  12765. return;
  12766. }
  12767. const exitFns = [];
  12768. for (let i = 0; i < props.length; i++) {
  12769. const prop = props[i];
  12770. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  12771. // structural directives are removed to avoid infinite recursion
  12772. // also we remove them *before* applying so that it can further
  12773. // traverse itself in case it moves the node around
  12774. props.splice(i, 1);
  12775. i--;
  12776. const onExit = fn(node, prop, context);
  12777. if (onExit)
  12778. exitFns.push(onExit);
  12779. }
  12780. }
  12781. return exitFns;
  12782. }
  12783. };
  12784. }
  12785. const PURE_ANNOTATION = `/*#__PURE__*/`;
  12786. function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssrRuntimeModuleName = 'vue/server-renderer', ssr = false, isTS = false, inSSR = false }) {
  12787. const context = {
  12788. mode,
  12789. prefixIdentifiers,
  12790. sourceMap,
  12791. filename,
  12792. scopeId,
  12793. optimizeImports,
  12794. runtimeGlobalName,
  12795. runtimeModuleName,
  12796. ssrRuntimeModuleName,
  12797. ssr,
  12798. isTS,
  12799. inSSR,
  12800. source: ast.loc.source,
  12801. code: ``,
  12802. column: 1,
  12803. line: 1,
  12804. offset: 0,
  12805. indentLevel: 0,
  12806. pure: false,
  12807. map: undefined,
  12808. helper(key) {
  12809. return `_${helperNameMap[key]}`;
  12810. },
  12811. push(code, node) {
  12812. context.code += code;
  12813. },
  12814. indent() {
  12815. newline(++context.indentLevel);
  12816. },
  12817. deindent(withoutNewLine = false) {
  12818. if (withoutNewLine) {
  12819. --context.indentLevel;
  12820. }
  12821. else {
  12822. newline(--context.indentLevel);
  12823. }
  12824. },
  12825. newline() {
  12826. newline(context.indentLevel);
  12827. }
  12828. };
  12829. function newline(n) {
  12830. context.push('\n' + ` `.repeat(n));
  12831. }
  12832. return context;
  12833. }
  12834. function generate(ast, options = {}) {
  12835. const context = createCodegenContext(ast, options);
  12836. if (options.onContextCreated)
  12837. options.onContextCreated(context);
  12838. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  12839. const hasHelpers = ast.helpers.length > 0;
  12840. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  12841. // preambles
  12842. // in setup() inline mode, the preamble is generated in a sub context
  12843. // and returned separately.
  12844. const preambleContext = context;
  12845. {
  12846. genFunctionPreamble(ast, preambleContext);
  12847. }
  12848. // enter render function
  12849. const functionName = ssr ? `ssrRender` : `render`;
  12850. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  12851. const signature = args.join(', ');
  12852. {
  12853. push(`function ${functionName}(${signature}) {`);
  12854. }
  12855. indent();
  12856. if (useWithBlock) {
  12857. push(`with (_ctx) {`);
  12858. indent();
  12859. // function mode const declarations should be inside with block
  12860. // also they should be renamed to avoid collision with user properties
  12861. if (hasHelpers) {
  12862. push(`const { ${ast.helpers
  12863. .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
  12864. .join(', ')} } = _Vue`);
  12865. push(`\n`);
  12866. newline();
  12867. }
  12868. }
  12869. // generate asset resolution statements
  12870. if (ast.components.length) {
  12871. genAssets(ast.components, 'component', context);
  12872. if (ast.directives.length || ast.temps > 0) {
  12873. newline();
  12874. }
  12875. }
  12876. if (ast.directives.length) {
  12877. genAssets(ast.directives, 'directive', context);
  12878. if (ast.temps > 0) {
  12879. newline();
  12880. }
  12881. }
  12882. if (ast.temps > 0) {
  12883. push(`let `);
  12884. for (let i = 0; i < ast.temps; i++) {
  12885. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  12886. }
  12887. }
  12888. if (ast.components.length || ast.directives.length || ast.temps) {
  12889. push(`\n`);
  12890. newline();
  12891. }
  12892. // generate the VNode tree expression
  12893. if (!ssr) {
  12894. push(`return `);
  12895. }
  12896. if (ast.codegenNode) {
  12897. genNode(ast.codegenNode, context);
  12898. }
  12899. else {
  12900. push(`null`);
  12901. }
  12902. if (useWithBlock) {
  12903. deindent();
  12904. push(`}`);
  12905. }
  12906. deindent();
  12907. push(`}`);
  12908. return {
  12909. ast,
  12910. code: context.code,
  12911. preamble: ``,
  12912. // SourceMapGenerator does have toJSON() method but it's not in the types
  12913. map: context.map ? context.map.toJSON() : undefined
  12914. };
  12915. }
  12916. function genFunctionPreamble(ast, context) {
  12917. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  12918. const VueBinding = runtimeGlobalName;
  12919. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  12920. // Generate const declaration for helpers
  12921. // In prefix mode, we place the const declaration at top so it's done
  12922. // only once; But if we not prefixing, we place the declaration inside the
  12923. // with block so it doesn't incur the `in` check cost for every helper access.
  12924. if (ast.helpers.length > 0) {
  12925. {
  12926. // "with" mode.
  12927. // save Vue in a separate variable to avoid collision
  12928. push(`const _Vue = ${VueBinding}\n`);
  12929. // in "with" mode, helpers are declared inside the with block to avoid
  12930. // has check cost, but hoists are lifted out of the function - we need
  12931. // to provide the helper here.
  12932. if (ast.hoists.length) {
  12933. const staticHelpers = [
  12934. CREATE_VNODE,
  12935. CREATE_ELEMENT_VNODE,
  12936. CREATE_COMMENT,
  12937. CREATE_TEXT,
  12938. CREATE_STATIC
  12939. ]
  12940. .filter(helper => ast.helpers.includes(helper))
  12941. .map(aliasHelper)
  12942. .join(', ');
  12943. push(`const { ${staticHelpers} } = _Vue\n`);
  12944. }
  12945. }
  12946. }
  12947. genHoists(ast.hoists, context);
  12948. newline();
  12949. push(`return `);
  12950. }
  12951. function genAssets(assets, type, { helper, push, newline, isTS }) {
  12952. const resolver = helper(type === 'component'
  12953. ? RESOLVE_COMPONENT
  12954. : RESOLVE_DIRECTIVE);
  12955. for (let i = 0; i < assets.length; i++) {
  12956. let id = assets[i];
  12957. // potential component implicit self-reference inferred from SFC filename
  12958. const maybeSelfReference = id.endsWith('__self');
  12959. if (maybeSelfReference) {
  12960. id = id.slice(0, -6);
  12961. }
  12962. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  12963. if (i < assets.length - 1) {
  12964. newline();
  12965. }
  12966. }
  12967. }
  12968. function genHoists(hoists, context) {
  12969. if (!hoists.length) {
  12970. return;
  12971. }
  12972. context.pure = true;
  12973. const { push, newline, helper, scopeId, mode } = context;
  12974. newline();
  12975. for (let i = 0; i < hoists.length; i++) {
  12976. const exp = hoists[i];
  12977. if (exp) {
  12978. push(`const _hoisted_${i + 1} = ${``}`);
  12979. genNode(exp, context);
  12980. newline();
  12981. }
  12982. }
  12983. context.pure = false;
  12984. }
  12985. function isText$1(n) {
  12986. return (isString(n) ||
  12987. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  12988. n.type === 2 /* TEXT */ ||
  12989. n.type === 5 /* INTERPOLATION */ ||
  12990. n.type === 8 /* COMPOUND_EXPRESSION */);
  12991. }
  12992. function genNodeListAsArray(nodes, context) {
  12993. const multilines = nodes.length > 3 ||
  12994. (nodes.some(n => isArray(n) || !isText$1(n)));
  12995. context.push(`[`);
  12996. multilines && context.indent();
  12997. genNodeList(nodes, context, multilines);
  12998. multilines && context.deindent();
  12999. context.push(`]`);
  13000. }
  13001. function genNodeList(nodes, context, multilines = false, comma = true) {
  13002. const { push, newline } = context;
  13003. for (let i = 0; i < nodes.length; i++) {
  13004. const node = nodes[i];
  13005. if (isString(node)) {
  13006. push(node);
  13007. }
  13008. else if (isArray(node)) {
  13009. genNodeListAsArray(node, context);
  13010. }
  13011. else {
  13012. genNode(node, context);
  13013. }
  13014. if (i < nodes.length - 1) {
  13015. if (multilines) {
  13016. comma && push(',');
  13017. newline();
  13018. }
  13019. else {
  13020. comma && push(', ');
  13021. }
  13022. }
  13023. }
  13024. }
  13025. function genNode(node, context) {
  13026. if (isString(node)) {
  13027. context.push(node);
  13028. return;
  13029. }
  13030. if (isSymbol(node)) {
  13031. context.push(context.helper(node));
  13032. return;
  13033. }
  13034. switch (node.type) {
  13035. case 1 /* ELEMENT */:
  13036. case 9 /* IF */:
  13037. case 11 /* FOR */:
  13038. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  13039. `Apply appropriate transforms first.`);
  13040. genNode(node.codegenNode, context);
  13041. break;
  13042. case 2 /* TEXT */:
  13043. genText(node, context);
  13044. break;
  13045. case 4 /* SIMPLE_EXPRESSION */:
  13046. genExpression(node, context);
  13047. break;
  13048. case 5 /* INTERPOLATION */:
  13049. genInterpolation(node, context);
  13050. break;
  13051. case 12 /* TEXT_CALL */:
  13052. genNode(node.codegenNode, context);
  13053. break;
  13054. case 8 /* COMPOUND_EXPRESSION */:
  13055. genCompoundExpression(node, context);
  13056. break;
  13057. case 3 /* COMMENT */:
  13058. genComment(node, context);
  13059. break;
  13060. case 13 /* VNODE_CALL */:
  13061. genVNodeCall(node, context);
  13062. break;
  13063. case 14 /* JS_CALL_EXPRESSION */:
  13064. genCallExpression(node, context);
  13065. break;
  13066. case 15 /* JS_OBJECT_EXPRESSION */:
  13067. genObjectExpression(node, context);
  13068. break;
  13069. case 17 /* JS_ARRAY_EXPRESSION */:
  13070. genArrayExpression(node, context);
  13071. break;
  13072. case 18 /* JS_FUNCTION_EXPRESSION */:
  13073. genFunctionExpression(node, context);
  13074. break;
  13075. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  13076. genConditionalExpression(node, context);
  13077. break;
  13078. case 20 /* JS_CACHE_EXPRESSION */:
  13079. genCacheExpression(node, context);
  13080. break;
  13081. case 21 /* JS_BLOCK_STATEMENT */:
  13082. genNodeList(node.body, context, true, false);
  13083. break;
  13084. // SSR only types
  13085. case 22 /* JS_TEMPLATE_LITERAL */:
  13086. break;
  13087. case 23 /* JS_IF_STATEMENT */:
  13088. break;
  13089. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  13090. break;
  13091. case 25 /* JS_SEQUENCE_EXPRESSION */:
  13092. break;
  13093. case 26 /* JS_RETURN_STATEMENT */:
  13094. break;
  13095. /* istanbul ignore next */
  13096. case 10 /* IF_BRANCH */:
  13097. // noop
  13098. break;
  13099. default:
  13100. {
  13101. assert(false, `unhandled codegen node type: ${node.type}`);
  13102. // make sure we exhaust all possible types
  13103. const exhaustiveCheck = node;
  13104. return exhaustiveCheck;
  13105. }
  13106. }
  13107. }
  13108. function genText(node, context) {
  13109. context.push(JSON.stringify(node.content), node);
  13110. }
  13111. function genExpression(node, context) {
  13112. const { content, isStatic } = node;
  13113. context.push(isStatic ? JSON.stringify(content) : content, node);
  13114. }
  13115. function genInterpolation(node, context) {
  13116. const { push, helper, pure } = context;
  13117. if (pure)
  13118. push(PURE_ANNOTATION);
  13119. push(`${helper(TO_DISPLAY_STRING)}(`);
  13120. genNode(node.content, context);
  13121. push(`)`);
  13122. }
  13123. function genCompoundExpression(node, context) {
  13124. for (let i = 0; i < node.children.length; i++) {
  13125. const child = node.children[i];
  13126. if (isString(child)) {
  13127. context.push(child);
  13128. }
  13129. else {
  13130. genNode(child, context);
  13131. }
  13132. }
  13133. }
  13134. function genExpressionAsPropertyKey(node, context) {
  13135. const { push } = context;
  13136. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  13137. push(`[`);
  13138. genCompoundExpression(node, context);
  13139. push(`]`);
  13140. }
  13141. else if (node.isStatic) {
  13142. // only quote keys if necessary
  13143. const text = isSimpleIdentifier(node.content)
  13144. ? node.content
  13145. : JSON.stringify(node.content);
  13146. push(text, node);
  13147. }
  13148. else {
  13149. push(`[${node.content}]`, node);
  13150. }
  13151. }
  13152. function genComment(node, context) {
  13153. const { push, helper, pure } = context;
  13154. if (pure) {
  13155. push(PURE_ANNOTATION);
  13156. }
  13157. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  13158. }
  13159. function genVNodeCall(node, context) {
  13160. const { push, helper, pure } = context;
  13161. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  13162. if (directives) {
  13163. push(helper(WITH_DIRECTIVES) + `(`);
  13164. }
  13165. if (isBlock) {
  13166. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  13167. }
  13168. if (pure) {
  13169. push(PURE_ANNOTATION);
  13170. }
  13171. const callHelper = isBlock
  13172. ? getVNodeBlockHelper(context.inSSR, isComponent)
  13173. : getVNodeHelper(context.inSSR, isComponent);
  13174. push(helper(callHelper) + `(`, node);
  13175. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  13176. push(`)`);
  13177. if (isBlock) {
  13178. push(`)`);
  13179. }
  13180. if (directives) {
  13181. push(`, `);
  13182. genNode(directives, context);
  13183. push(`)`);
  13184. }
  13185. }
  13186. function genNullableArgs(args) {
  13187. let i = args.length;
  13188. while (i--) {
  13189. if (args[i] != null)
  13190. break;
  13191. }
  13192. return args.slice(0, i + 1).map(arg => arg || `null`);
  13193. }
  13194. // JavaScript
  13195. function genCallExpression(node, context) {
  13196. const { push, helper, pure } = context;
  13197. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  13198. if (pure) {
  13199. push(PURE_ANNOTATION);
  13200. }
  13201. push(callee + `(`, node);
  13202. genNodeList(node.arguments, context);
  13203. push(`)`);
  13204. }
  13205. function genObjectExpression(node, context) {
  13206. const { push, indent, deindent, newline } = context;
  13207. const { properties } = node;
  13208. if (!properties.length) {
  13209. push(`{}`, node);
  13210. return;
  13211. }
  13212. const multilines = properties.length > 1 ||
  13213. (properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  13214. push(multilines ? `{` : `{ `);
  13215. multilines && indent();
  13216. for (let i = 0; i < properties.length; i++) {
  13217. const { key, value } = properties[i];
  13218. // key
  13219. genExpressionAsPropertyKey(key, context);
  13220. push(`: `);
  13221. // value
  13222. genNode(value, context);
  13223. if (i < properties.length - 1) {
  13224. // will only reach this if it's multilines
  13225. push(`,`);
  13226. newline();
  13227. }
  13228. }
  13229. multilines && deindent();
  13230. push(multilines ? `}` : ` }`);
  13231. }
  13232. function genArrayExpression(node, context) {
  13233. genNodeListAsArray(node.elements, context);
  13234. }
  13235. function genFunctionExpression(node, context) {
  13236. const { push, indent, deindent } = context;
  13237. const { params, returns, body, newline, isSlot } = node;
  13238. if (isSlot) {
  13239. // wrap slot functions with owner context
  13240. push(`_${helperNameMap[WITH_CTX]}(`);
  13241. }
  13242. push(`(`, node);
  13243. if (isArray(params)) {
  13244. genNodeList(params, context);
  13245. }
  13246. else if (params) {
  13247. genNode(params, context);
  13248. }
  13249. push(`) => `);
  13250. if (newline || body) {
  13251. push(`{`);
  13252. indent();
  13253. }
  13254. if (returns) {
  13255. if (newline) {
  13256. push(`return `);
  13257. }
  13258. if (isArray(returns)) {
  13259. genNodeListAsArray(returns, context);
  13260. }
  13261. else {
  13262. genNode(returns, context);
  13263. }
  13264. }
  13265. else if (body) {
  13266. genNode(body, context);
  13267. }
  13268. if (newline || body) {
  13269. deindent();
  13270. push(`}`);
  13271. }
  13272. if (isSlot) {
  13273. push(`)`);
  13274. }
  13275. }
  13276. function genConditionalExpression(node, context) {
  13277. const { test, consequent, alternate, newline: needNewline } = node;
  13278. const { push, indent, deindent, newline } = context;
  13279. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  13280. const needsParens = !isSimpleIdentifier(test.content);
  13281. needsParens && push(`(`);
  13282. genExpression(test, context);
  13283. needsParens && push(`)`);
  13284. }
  13285. else {
  13286. push(`(`);
  13287. genNode(test, context);
  13288. push(`)`);
  13289. }
  13290. needNewline && indent();
  13291. context.indentLevel++;
  13292. needNewline || push(` `);
  13293. push(`? `);
  13294. genNode(consequent, context);
  13295. context.indentLevel--;
  13296. needNewline && newline();
  13297. needNewline || push(` `);
  13298. push(`: `);
  13299. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  13300. if (!isNested) {
  13301. context.indentLevel++;
  13302. }
  13303. genNode(alternate, context);
  13304. if (!isNested) {
  13305. context.indentLevel--;
  13306. }
  13307. needNewline && deindent(true /* without newline */);
  13308. }
  13309. function genCacheExpression(node, context) {
  13310. const { push, helper, indent, deindent, newline } = context;
  13311. push(`_cache[${node.index}] || (`);
  13312. if (node.isVNode) {
  13313. indent();
  13314. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  13315. newline();
  13316. }
  13317. push(`_cache[${node.index}] = `);
  13318. genNode(node.value, context);
  13319. if (node.isVNode) {
  13320. push(`,`);
  13321. newline();
  13322. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  13323. newline();
  13324. push(`_cache[${node.index}]`);
  13325. deindent();
  13326. }
  13327. push(`)`);
  13328. }
  13329. // these keywords should not appear inside expressions, but operators like
  13330. // typeof, instanceof and in are allowed
  13331. const prohibitedKeywordRE = new RegExp('\\b' +
  13332. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  13333. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  13334. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  13335. .split(',')
  13336. .join('\\b|\\b') +
  13337. '\\b');
  13338. // strip strings in expressions
  13339. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  13340. /**
  13341. * Validate a non-prefixed expression.
  13342. * This is only called when using the in-browser runtime compiler since it
  13343. * doesn't prefix expressions.
  13344. */
  13345. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  13346. const exp = node.content;
  13347. // empty expressions are validated per-directive since some directives
  13348. // do allow empty expressions.
  13349. if (!exp.trim()) {
  13350. return;
  13351. }
  13352. try {
  13353. new Function(asRawStatements
  13354. ? ` ${exp} `
  13355. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  13356. }
  13357. catch (e) {
  13358. let message = e.message;
  13359. const keywordMatch = exp
  13360. .replace(stripStringRE, '')
  13361. .match(prohibitedKeywordRE);
  13362. if (keywordMatch) {
  13363. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  13364. }
  13365. context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  13366. }
  13367. }
  13368. const transformExpression = (node, context) => {
  13369. if (node.type === 5 /* INTERPOLATION */) {
  13370. node.content = processExpression(node.content, context);
  13371. }
  13372. else if (node.type === 1 /* ELEMENT */) {
  13373. // handle directives on element
  13374. for (let i = 0; i < node.props.length; i++) {
  13375. const dir = node.props[i];
  13376. // do not process for v-on & v-for since they are special handled
  13377. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  13378. const exp = dir.exp;
  13379. const arg = dir.arg;
  13380. // do not process exp if this is v-on:arg - we need special handling
  13381. // for wrapping inline statements.
  13382. if (exp &&
  13383. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  13384. !(dir.name === 'on' && arg)) {
  13385. dir.exp = processExpression(exp, context,
  13386. // slot args must be processed as function params
  13387. dir.name === 'slot');
  13388. }
  13389. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  13390. dir.arg = processExpression(arg, context);
  13391. }
  13392. }
  13393. }
  13394. }
  13395. };
  13396. // Important: since this function uses Node.js only dependencies, it should
  13397. // always be used with a leading !true check so that it can be
  13398. // tree-shaken from the browser build.
  13399. function processExpression(node, context,
  13400. // some expressions like v-slot props & v-for aliases should be parsed as
  13401. // function params
  13402. asParams = false,
  13403. // v-on handler values may contain multiple statements
  13404. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  13405. {
  13406. {
  13407. // simple in-browser validation (same logic in 2.x)
  13408. validateBrowserExpression(node, context, asParams, asRawStatements);
  13409. }
  13410. return node;
  13411. }
  13412. }
  13413. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  13414. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  13415. // #1587: We need to dynamically increment the key based on the current
  13416. // node's sibling nodes, since chained v-if/else branches are
  13417. // rendered at the same depth
  13418. const siblings = context.parent.children;
  13419. let i = siblings.indexOf(ifNode);
  13420. let key = 0;
  13421. while (i-- >= 0) {
  13422. const sibling = siblings[i];
  13423. if (sibling && sibling.type === 9 /* IF */) {
  13424. key += sibling.branches.length;
  13425. }
  13426. }
  13427. // Exit callback. Complete the codegenNode when all children have been
  13428. // transformed.
  13429. return () => {
  13430. if (isRoot) {
  13431. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  13432. }
  13433. else {
  13434. // attach this branch's codegen node to the v-if root.
  13435. const parentCondition = getParentCondition(ifNode.codegenNode);
  13436. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  13437. }
  13438. };
  13439. });
  13440. });
  13441. // target-agnostic transform used for both Client and SSR
  13442. function processIf(node, dir, context, processCodegen) {
  13443. if (dir.name !== 'else' &&
  13444. (!dir.exp || !dir.exp.content.trim())) {
  13445. const loc = dir.exp ? dir.exp.loc : node.loc;
  13446. context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  13447. dir.exp = createSimpleExpression(`true`, false, loc);
  13448. }
  13449. if (dir.exp) {
  13450. validateBrowserExpression(dir.exp, context);
  13451. }
  13452. if (dir.name === 'if') {
  13453. const branch = createIfBranch(node, dir);
  13454. const ifNode = {
  13455. type: 9 /* IF */,
  13456. loc: node.loc,
  13457. branches: [branch]
  13458. };
  13459. context.replaceNode(ifNode);
  13460. if (processCodegen) {
  13461. return processCodegen(ifNode, branch, true);
  13462. }
  13463. }
  13464. else {
  13465. // locate the adjacent v-if
  13466. const siblings = context.parent.children;
  13467. const comments = [];
  13468. let i = siblings.indexOf(node);
  13469. while (i-- >= -1) {
  13470. const sibling = siblings[i];
  13471. if (sibling && sibling.type === 3 /* COMMENT */) {
  13472. context.removeNode(sibling);
  13473. comments.unshift(sibling);
  13474. continue;
  13475. }
  13476. if (sibling &&
  13477. sibling.type === 2 /* TEXT */ &&
  13478. !sibling.content.trim().length) {
  13479. context.removeNode(sibling);
  13480. continue;
  13481. }
  13482. if (sibling && sibling.type === 9 /* IF */) {
  13483. // Check if v-else was followed by v-else-if
  13484. if (dir.name === 'else-if' &&
  13485. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  13486. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13487. }
  13488. // move the node to the if node's branches
  13489. context.removeNode();
  13490. const branch = createIfBranch(node, dir);
  13491. if (comments.length &&
  13492. // #3619 ignore comments if the v-if is direct child of <transition>
  13493. !(context.parent &&
  13494. context.parent.type === 1 /* ELEMENT */ &&
  13495. isBuiltInType(context.parent.tag, 'transition'))) {
  13496. branch.children = [...comments, ...branch.children];
  13497. }
  13498. // check if user is forcing same key on different branches
  13499. {
  13500. const key = branch.userKey;
  13501. if (key) {
  13502. sibling.branches.forEach(({ userKey }) => {
  13503. if (isSameKey(userKey, key)) {
  13504. context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  13505. }
  13506. });
  13507. }
  13508. }
  13509. sibling.branches.push(branch);
  13510. const onExit = processCodegen && processCodegen(sibling, branch, false);
  13511. // since the branch was removed, it will not be traversed.
  13512. // make sure to traverse here.
  13513. traverseNode(branch, context);
  13514. // call on exit
  13515. if (onExit)
  13516. onExit();
  13517. // make sure to reset currentNode after traversal to indicate this
  13518. // node has been removed.
  13519. context.currentNode = null;
  13520. }
  13521. else {
  13522. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13523. }
  13524. break;
  13525. }
  13526. }
  13527. }
  13528. function createIfBranch(node, dir) {
  13529. return {
  13530. type: 10 /* IF_BRANCH */,
  13531. loc: node.loc,
  13532. condition: dir.name === 'else' ? undefined : dir.exp,
  13533. children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
  13534. ? node.children
  13535. : [node],
  13536. userKey: findProp(node, `key`)
  13537. };
  13538. }
  13539. function createCodegenNodeForBranch(branch, keyIndex, context) {
  13540. if (branch.condition) {
  13541. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  13542. // make sure to pass in asBlock: true so that the comment node call
  13543. // closes the current block.
  13544. createCallExpression(context.helper(CREATE_COMMENT), [
  13545. '"v-if"' ,
  13546. 'true'
  13547. ]));
  13548. }
  13549. else {
  13550. return createChildrenCodegenNode(branch, keyIndex, context);
  13551. }
  13552. }
  13553. function createChildrenCodegenNode(branch, keyIndex, context) {
  13554. const { helper } = context;
  13555. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  13556. const { children } = branch;
  13557. const firstChild = children[0];
  13558. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  13559. if (needFragmentWrapper) {
  13560. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  13561. // optimize away nested fragments when child is a ForNode
  13562. const vnodeCall = firstChild.codegenNode;
  13563. injectProp(vnodeCall, keyProperty, context);
  13564. return vnodeCall;
  13565. }
  13566. else {
  13567. let patchFlag = 64 /* STABLE_FRAGMENT */;
  13568. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  13569. // check if the fragment actually contains a single valid child with
  13570. // the rest being comments
  13571. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  13572. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  13573. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  13574. }
  13575. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  13576. }
  13577. }
  13578. else {
  13579. const ret = firstChild.codegenNode;
  13580. const vnodeCall = getMemoedVNodeCall(ret);
  13581. // Change createVNode to createBlock.
  13582. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  13583. makeBlock(vnodeCall, context);
  13584. }
  13585. // inject branch key
  13586. injectProp(vnodeCall, keyProperty, context);
  13587. return ret;
  13588. }
  13589. }
  13590. function isSameKey(a, b) {
  13591. if (!a || a.type !== b.type) {
  13592. return false;
  13593. }
  13594. if (a.type === 6 /* ATTRIBUTE */) {
  13595. if (a.value.content !== b.value.content) {
  13596. return false;
  13597. }
  13598. }
  13599. else {
  13600. // directive
  13601. const exp = a.exp;
  13602. const branchExp = b.exp;
  13603. if (exp.type !== branchExp.type) {
  13604. return false;
  13605. }
  13606. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  13607. exp.isStatic !== branchExp.isStatic ||
  13608. exp.content !== branchExp.content) {
  13609. return false;
  13610. }
  13611. }
  13612. return true;
  13613. }
  13614. function getParentCondition(node) {
  13615. while (true) {
  13616. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13617. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13618. node = node.alternate;
  13619. }
  13620. else {
  13621. return node;
  13622. }
  13623. }
  13624. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  13625. node = node.value;
  13626. }
  13627. }
  13628. }
  13629. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  13630. const { helper, removeHelper } = context;
  13631. return processFor(node, dir, context, forNode => {
  13632. // create the loop render function expression now, and add the
  13633. // iterator on exit after all children have been traversed
  13634. const renderExp = createCallExpression(helper(RENDER_LIST), [
  13635. forNode.source
  13636. ]);
  13637. const isTemplate = isTemplateNode(node);
  13638. const memo = findDir(node, 'memo');
  13639. const keyProp = findProp(node, `key`);
  13640. const keyExp = keyProp &&
  13641. (keyProp.type === 6 /* ATTRIBUTE */
  13642. ? createSimpleExpression(keyProp.value.content, true)
  13643. : keyProp.exp);
  13644. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  13645. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  13646. forNode.source.constType > 0 /* NOT_CONSTANT */;
  13647. const fragmentFlag = isStableFragment
  13648. ? 64 /* STABLE_FRAGMENT */
  13649. : keyProp
  13650. ? 128 /* KEYED_FRAGMENT */
  13651. : 256 /* UNKEYED_FRAGMENT */;
  13652. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  13653. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  13654. return () => {
  13655. // finish the codegen now that all children have been traversed
  13656. let childBlock;
  13657. const { children } = forNode;
  13658. // check <template v-for> key placement
  13659. if (isTemplate) {
  13660. node.children.some(c => {
  13661. if (c.type === 1 /* ELEMENT */) {
  13662. const key = findProp(c, 'key');
  13663. if (key) {
  13664. context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  13665. return true;
  13666. }
  13667. }
  13668. });
  13669. }
  13670. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  13671. const slotOutlet = isSlotOutlet(node)
  13672. ? node
  13673. : isTemplate &&
  13674. node.children.length === 1 &&
  13675. isSlotOutlet(node.children[0])
  13676. ? node.children[0] // api-extractor somehow fails to infer this
  13677. : null;
  13678. if (slotOutlet) {
  13679. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  13680. childBlock = slotOutlet.codegenNode;
  13681. if (isTemplate && keyProperty) {
  13682. // <template v-for="..." :key="..."><slot/></template>
  13683. // we need to inject the key to the renderSlot() call.
  13684. // the props for renderSlot is passed as the 3rd argument.
  13685. injectProp(childBlock, keyProperty, context);
  13686. }
  13687. }
  13688. else if (needFragmentWrapper) {
  13689. // <template v-for="..."> with text or multi-elements
  13690. // should generate a fragment block for each loop
  13691. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  13692. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  13693. ), undefined, undefined, true, undefined, false /* isComponent */);
  13694. }
  13695. else {
  13696. // Normal element v-for. Directly use the child's codegenNode
  13697. // but mark it as a block.
  13698. childBlock = children[0]
  13699. .codegenNode;
  13700. if (isTemplate && keyProperty) {
  13701. injectProp(childBlock, keyProperty, context);
  13702. }
  13703. if (childBlock.isBlock !== !isStableFragment) {
  13704. if (childBlock.isBlock) {
  13705. // switch from block to vnode
  13706. removeHelper(OPEN_BLOCK);
  13707. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13708. }
  13709. else {
  13710. // switch from vnode to block
  13711. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13712. }
  13713. }
  13714. childBlock.isBlock = !isStableFragment;
  13715. if (childBlock.isBlock) {
  13716. helper(OPEN_BLOCK);
  13717. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13718. }
  13719. else {
  13720. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13721. }
  13722. }
  13723. if (memo) {
  13724. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  13725. createSimpleExpression(`_cached`)
  13726. ]));
  13727. loop.body = createBlockStatement([
  13728. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  13729. createCompoundExpression([
  13730. `if (_cached`,
  13731. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  13732. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  13733. ]),
  13734. createCompoundExpression([`const _item = `, childBlock]),
  13735. createSimpleExpression(`_item.memo = _memo`),
  13736. createSimpleExpression(`return _item`)
  13737. ]);
  13738. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  13739. }
  13740. else {
  13741. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  13742. }
  13743. };
  13744. });
  13745. });
  13746. // target-agnostic transform used for both Client and SSR
  13747. function processFor(node, dir, context, processCodegen) {
  13748. if (!dir.exp) {
  13749. context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  13750. return;
  13751. }
  13752. const parseResult = parseForExpression(
  13753. // can only be simple expression because vFor transform is applied
  13754. // before expression transform.
  13755. dir.exp, context);
  13756. if (!parseResult) {
  13757. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  13758. return;
  13759. }
  13760. const { addIdentifiers, removeIdentifiers, scopes } = context;
  13761. const { source, value, key, index } = parseResult;
  13762. const forNode = {
  13763. type: 11 /* FOR */,
  13764. loc: dir.loc,
  13765. source,
  13766. valueAlias: value,
  13767. keyAlias: key,
  13768. objectIndexAlias: index,
  13769. parseResult,
  13770. children: isTemplateNode(node) ? node.children : [node]
  13771. };
  13772. context.replaceNode(forNode);
  13773. // bookkeeping
  13774. scopes.vFor++;
  13775. const onExit = processCodegen && processCodegen(forNode);
  13776. return () => {
  13777. scopes.vFor--;
  13778. if (onExit)
  13779. onExit();
  13780. };
  13781. }
  13782. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  13783. // This regex doesn't cover the case if key or index aliases have destructuring,
  13784. // but those do not make sense in the first place, so this works in practice.
  13785. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  13786. const stripParensRE = /^\(|\)$/g;
  13787. function parseForExpression(input, context) {
  13788. const loc = input.loc;
  13789. const exp = input.content;
  13790. const inMatch = exp.match(forAliasRE);
  13791. if (!inMatch)
  13792. return;
  13793. const [, LHS, RHS] = inMatch;
  13794. const result = {
  13795. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  13796. value: undefined,
  13797. key: undefined,
  13798. index: undefined
  13799. };
  13800. {
  13801. validateBrowserExpression(result.source, context);
  13802. }
  13803. let valueContent = LHS.trim().replace(stripParensRE, '').trim();
  13804. const trimmedOffset = LHS.indexOf(valueContent);
  13805. const iteratorMatch = valueContent.match(forIteratorRE);
  13806. if (iteratorMatch) {
  13807. valueContent = valueContent.replace(forIteratorRE, '').trim();
  13808. const keyContent = iteratorMatch[1].trim();
  13809. let keyOffset;
  13810. if (keyContent) {
  13811. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  13812. result.key = createAliasExpression(loc, keyContent, keyOffset);
  13813. {
  13814. validateBrowserExpression(result.key, context, true);
  13815. }
  13816. }
  13817. if (iteratorMatch[2]) {
  13818. const indexContent = iteratorMatch[2].trim();
  13819. if (indexContent) {
  13820. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  13821. ? keyOffset + keyContent.length
  13822. : trimmedOffset + valueContent.length));
  13823. {
  13824. validateBrowserExpression(result.index, context, true);
  13825. }
  13826. }
  13827. }
  13828. }
  13829. if (valueContent) {
  13830. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  13831. {
  13832. validateBrowserExpression(result.value, context, true);
  13833. }
  13834. }
  13835. return result;
  13836. }
  13837. function createAliasExpression(range, content, offset) {
  13838. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  13839. }
  13840. function createForLoopParams({ value, key, index }, memoArgs = []) {
  13841. return createParamsList([value, key, index, ...memoArgs]);
  13842. }
  13843. function createParamsList(args) {
  13844. let i = args.length;
  13845. while (i--) {
  13846. if (args[i])
  13847. break;
  13848. }
  13849. return args
  13850. .slice(0, i + 1)
  13851. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  13852. }
  13853. const defaultFallback = createSimpleExpression(`undefined`, false);
  13854. // A NodeTransform that:
  13855. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  13856. // by transformExpression. This is only applied in non-browser builds with
  13857. // { prefixIdentifiers: true }.
  13858. // 2. Track v-slot depths so that we know a slot is inside another slot.
  13859. // Note the exit callback is executed before buildSlots() on the same node,
  13860. // so only nested slots see positive numbers.
  13861. const trackSlotScopes = (node, context) => {
  13862. if (node.type === 1 /* ELEMENT */ &&
  13863. (node.tagType === 1 /* COMPONENT */ ||
  13864. node.tagType === 3 /* TEMPLATE */)) {
  13865. // We are only checking non-empty v-slot here
  13866. // since we only care about slots that introduce scope variables.
  13867. const vSlot = findDir(node, 'slot');
  13868. if (vSlot) {
  13869. vSlot.exp;
  13870. context.scopes.vSlot++;
  13871. return () => {
  13872. context.scopes.vSlot--;
  13873. };
  13874. }
  13875. }
  13876. };
  13877. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  13878. // Instead of being a DirectiveTransform, v-slot processing is called during
  13879. // transformElement to build the slots object for a component.
  13880. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  13881. context.helper(WITH_CTX);
  13882. const { children, loc } = node;
  13883. const slotsProperties = [];
  13884. const dynamicSlots = [];
  13885. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  13886. // since it likely uses a scope variable.
  13887. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  13888. // 1. Check for slot with slotProps on component itself.
  13889. // <Comp v-slot="{ prop }"/>
  13890. const onComponentSlot = findDir(node, 'slot', true);
  13891. if (onComponentSlot) {
  13892. const { arg, exp } = onComponentSlot;
  13893. if (arg && !isStaticExp(arg)) {
  13894. hasDynamicSlots = true;
  13895. }
  13896. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  13897. }
  13898. // 2. Iterate through children and check for template slots
  13899. // <template v-slot:foo="{ prop }">
  13900. let hasTemplateSlots = false;
  13901. let hasNamedDefaultSlot = false;
  13902. const implicitDefaultChildren = [];
  13903. const seenSlotNames = new Set();
  13904. for (let i = 0; i < children.length; i++) {
  13905. const slotElement = children[i];
  13906. let slotDir;
  13907. if (!isTemplateNode(slotElement) ||
  13908. !(slotDir = findDir(slotElement, 'slot', true))) {
  13909. // not a <template v-slot>, skip.
  13910. if (slotElement.type !== 3 /* COMMENT */) {
  13911. implicitDefaultChildren.push(slotElement);
  13912. }
  13913. continue;
  13914. }
  13915. if (onComponentSlot) {
  13916. // already has on-component slot - this is incorrect usage.
  13917. context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  13918. break;
  13919. }
  13920. hasTemplateSlots = true;
  13921. const { children: slotChildren, loc: slotLoc } = slotElement;
  13922. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  13923. // check if name is dynamic.
  13924. let staticSlotName;
  13925. if (isStaticExp(slotName)) {
  13926. staticSlotName = slotName ? slotName.content : `default`;
  13927. }
  13928. else {
  13929. hasDynamicSlots = true;
  13930. }
  13931. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  13932. // check if this slot is conditional (v-if/v-for)
  13933. let vIf;
  13934. let vElse;
  13935. let vFor;
  13936. if ((vIf = findDir(slotElement, 'if'))) {
  13937. hasDynamicSlots = true;
  13938. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  13939. }
  13940. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  13941. // find adjacent v-if
  13942. let j = i;
  13943. let prev;
  13944. while (j--) {
  13945. prev = children[j];
  13946. if (prev.type !== 3 /* COMMENT */) {
  13947. break;
  13948. }
  13949. }
  13950. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  13951. // remove node
  13952. children.splice(i, 1);
  13953. i--;
  13954. // attach this slot to previous conditional
  13955. let conditional = dynamicSlots[dynamicSlots.length - 1];
  13956. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13957. conditional = conditional.alternate;
  13958. }
  13959. conditional.alternate = vElse.exp
  13960. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  13961. : buildDynamicSlot(slotName, slotFunction);
  13962. }
  13963. else {
  13964. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  13965. }
  13966. }
  13967. else if ((vFor = findDir(slotElement, 'for'))) {
  13968. hasDynamicSlots = true;
  13969. const parseResult = vFor.parseResult ||
  13970. parseForExpression(vFor.exp, context);
  13971. if (parseResult) {
  13972. // Render the dynamic slots as an array and add it to the createSlot()
  13973. // args. The runtime knows how to handle it appropriately.
  13974. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  13975. parseResult.source,
  13976. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  13977. ]));
  13978. }
  13979. else {
  13980. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  13981. }
  13982. }
  13983. else {
  13984. // check duplicate static names
  13985. if (staticSlotName) {
  13986. if (seenSlotNames.has(staticSlotName)) {
  13987. context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  13988. continue;
  13989. }
  13990. seenSlotNames.add(staticSlotName);
  13991. if (staticSlotName === 'default') {
  13992. hasNamedDefaultSlot = true;
  13993. }
  13994. }
  13995. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  13996. }
  13997. }
  13998. if (!onComponentSlot) {
  13999. const buildDefaultSlotProperty = (props, children) => {
  14000. const fn = buildSlotFn(props, children, loc);
  14001. return createObjectProperty(`default`, fn);
  14002. };
  14003. if (!hasTemplateSlots) {
  14004. // implicit default slot (on component)
  14005. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  14006. }
  14007. else if (implicitDefaultChildren.length &&
  14008. // #3766
  14009. // with whitespace: 'preserve', whitespaces between slots will end up in
  14010. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  14011. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  14012. // implicit default slot (mixed with named slots)
  14013. if (hasNamedDefaultSlot) {
  14014. context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  14015. }
  14016. else {
  14017. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  14018. }
  14019. }
  14020. }
  14021. const slotFlag = hasDynamicSlots
  14022. ? 2 /* DYNAMIC */
  14023. : hasForwardedSlots(node.children)
  14024. ? 3 /* FORWARDED */
  14025. : 1 /* STABLE */;
  14026. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  14027. // 2 = compiled but dynamic = can skip normalization, but must run diff
  14028. // 1 = compiled and static = can skip normalization AND diff as optimized
  14029. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  14030. if (dynamicSlots.length) {
  14031. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  14032. slots,
  14033. createArrayExpression(dynamicSlots)
  14034. ]);
  14035. }
  14036. return {
  14037. slots,
  14038. hasDynamicSlots
  14039. };
  14040. }
  14041. function buildDynamicSlot(name, fn) {
  14042. return createObjectExpression([
  14043. createObjectProperty(`name`, name),
  14044. createObjectProperty(`fn`, fn)
  14045. ]);
  14046. }
  14047. function hasForwardedSlots(children) {
  14048. for (let i = 0; i < children.length; i++) {
  14049. const child = children[i];
  14050. switch (child.type) {
  14051. case 1 /* ELEMENT */:
  14052. if (child.tagType === 2 /* SLOT */ ||
  14053. hasForwardedSlots(child.children)) {
  14054. return true;
  14055. }
  14056. break;
  14057. case 9 /* IF */:
  14058. if (hasForwardedSlots(child.branches))
  14059. return true;
  14060. break;
  14061. case 10 /* IF_BRANCH */:
  14062. case 11 /* FOR */:
  14063. if (hasForwardedSlots(child.children))
  14064. return true;
  14065. break;
  14066. }
  14067. }
  14068. return false;
  14069. }
  14070. function isNonWhitespaceContent(node) {
  14071. if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
  14072. return true;
  14073. return node.type === 2 /* TEXT */
  14074. ? !!node.content.trim()
  14075. : isNonWhitespaceContent(node.content);
  14076. }
  14077. // some directive transforms (e.g. v-model) may return a symbol for runtime
  14078. // import, which should be used instead of a resolveDirective call.
  14079. const directiveImportMap = new WeakMap();
  14080. // generate a JavaScript AST for this element's codegen
  14081. const transformElement = (node, context) => {
  14082. // perform the work on exit, after all child expressions have been
  14083. // processed and merged.
  14084. return function postTransformElement() {
  14085. node = context.currentNode;
  14086. if (!(node.type === 1 /* ELEMENT */ &&
  14087. (node.tagType === 0 /* ELEMENT */ ||
  14088. node.tagType === 1 /* COMPONENT */))) {
  14089. return;
  14090. }
  14091. const { tag, props } = node;
  14092. const isComponent = node.tagType === 1 /* COMPONENT */;
  14093. // The goal of the transform is to create a codegenNode implementing the
  14094. // VNodeCall interface.
  14095. let vnodeTag = isComponent
  14096. ? resolveComponentType(node, context)
  14097. : `"${tag}"`;
  14098. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  14099. let vnodeProps;
  14100. let vnodeChildren;
  14101. let vnodePatchFlag;
  14102. let patchFlag = 0;
  14103. let vnodeDynamicProps;
  14104. let dynamicPropNames;
  14105. let vnodeDirectives;
  14106. let shouldUseBlock =
  14107. // dynamic component may resolve to plain elements
  14108. isDynamicComponent ||
  14109. vnodeTag === TELEPORT ||
  14110. vnodeTag === SUSPENSE ||
  14111. (!isComponent &&
  14112. // <svg> and <foreignObject> must be forced into blocks so that block
  14113. // updates inside get proper isSVG flag at runtime. (#639, #643)
  14114. // This is technically web-specific, but splitting the logic out of core
  14115. // leads to too much unnecessary complexity.
  14116. (tag === 'svg' || tag === 'foreignObject'));
  14117. // props
  14118. if (props.length > 0) {
  14119. const propsBuildResult = buildProps(node, context);
  14120. vnodeProps = propsBuildResult.props;
  14121. patchFlag = propsBuildResult.patchFlag;
  14122. dynamicPropNames = propsBuildResult.dynamicPropNames;
  14123. const directives = propsBuildResult.directives;
  14124. vnodeDirectives =
  14125. directives && directives.length
  14126. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  14127. : undefined;
  14128. if (propsBuildResult.shouldUseBlock) {
  14129. shouldUseBlock = true;
  14130. }
  14131. }
  14132. // children
  14133. if (node.children.length > 0) {
  14134. if (vnodeTag === KEEP_ALIVE) {
  14135. // Although a built-in component, we compile KeepAlive with raw children
  14136. // instead of slot functions so that it can be used inside Transition
  14137. // or other Transition-wrapping HOCs.
  14138. // To ensure correct updates with block optimizations, we need to:
  14139. // 1. Force keep-alive into a block. This avoids its children being
  14140. // collected by a parent block.
  14141. shouldUseBlock = true;
  14142. // 2. Force keep-alive to always be updated, since it uses raw children.
  14143. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14144. if (node.children.length > 1) {
  14145. context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  14146. start: node.children[0].loc.start,
  14147. end: node.children[node.children.length - 1].loc.end,
  14148. source: ''
  14149. }));
  14150. }
  14151. }
  14152. const shouldBuildAsSlots = isComponent &&
  14153. // Teleport is not a real component and has dedicated runtime handling
  14154. vnodeTag !== TELEPORT &&
  14155. // explained above.
  14156. vnodeTag !== KEEP_ALIVE;
  14157. if (shouldBuildAsSlots) {
  14158. const { slots, hasDynamicSlots } = buildSlots(node, context);
  14159. vnodeChildren = slots;
  14160. if (hasDynamicSlots) {
  14161. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14162. }
  14163. }
  14164. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  14165. const child = node.children[0];
  14166. const type = child.type;
  14167. // check for dynamic text children
  14168. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  14169. type === 8 /* COMPOUND_EXPRESSION */;
  14170. if (hasDynamicTextChild &&
  14171. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14172. patchFlag |= 1 /* TEXT */;
  14173. }
  14174. // pass directly if the only child is a text node
  14175. // (plain / interpolation / expression)
  14176. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  14177. vnodeChildren = child;
  14178. }
  14179. else {
  14180. vnodeChildren = node.children;
  14181. }
  14182. }
  14183. else {
  14184. vnodeChildren = node.children;
  14185. }
  14186. }
  14187. // patchFlag & dynamicPropNames
  14188. if (patchFlag !== 0) {
  14189. {
  14190. if (patchFlag < 0) {
  14191. // special flags (negative and mutually exclusive)
  14192. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  14193. }
  14194. else {
  14195. // bitwise flags
  14196. const flagNames = Object.keys(PatchFlagNames)
  14197. .map(Number)
  14198. .filter(n => n > 0 && patchFlag & n)
  14199. .map(n => PatchFlagNames[n])
  14200. .join(`, `);
  14201. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  14202. }
  14203. }
  14204. if (dynamicPropNames && dynamicPropNames.length) {
  14205. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  14206. }
  14207. }
  14208. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  14209. };
  14210. };
  14211. function resolveComponentType(node, context, ssr = false) {
  14212. let { tag } = node;
  14213. // 1. dynamic component
  14214. const isExplicitDynamic = isComponentTag(tag);
  14215. const isProp = findProp(node, 'is');
  14216. if (isProp) {
  14217. if (isExplicitDynamic ||
  14218. (false )) {
  14219. const exp = isProp.type === 6 /* ATTRIBUTE */
  14220. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  14221. : isProp.exp;
  14222. if (exp) {
  14223. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14224. exp
  14225. ]);
  14226. }
  14227. }
  14228. else if (isProp.type === 6 /* ATTRIBUTE */ &&
  14229. isProp.value.content.startsWith('vue:')) {
  14230. // <button is="vue:xxx">
  14231. // if not <component>, only is value that starts with "vue:" will be
  14232. // treated as component by the parse phase and reach here, unless it's
  14233. // compat mode where all is values are considered components
  14234. tag = isProp.value.content.slice(4);
  14235. }
  14236. }
  14237. // 1.5 v-is (TODO: Deprecate)
  14238. const isDir = !isExplicitDynamic && findDir(node, 'is');
  14239. if (isDir && isDir.exp) {
  14240. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14241. isDir.exp
  14242. ]);
  14243. }
  14244. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  14245. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  14246. if (builtIn) {
  14247. // built-ins are simply fallthroughs / have special handling during ssr
  14248. // so we don't need to import their runtime equivalents
  14249. if (!ssr)
  14250. context.helper(builtIn);
  14251. return builtIn;
  14252. }
  14253. // 5. user component (resolve)
  14254. context.helper(RESOLVE_COMPONENT);
  14255. context.components.add(tag);
  14256. return toValidAssetId(tag, `component`);
  14257. }
  14258. function buildProps(node, context, props = node.props, ssr = false) {
  14259. const { tag, loc: elementLoc, children } = node;
  14260. const isComponent = node.tagType === 1 /* COMPONENT */;
  14261. let properties = [];
  14262. const mergeArgs = [];
  14263. const runtimeDirectives = [];
  14264. const hasChildren = children.length > 0;
  14265. let shouldUseBlock = false;
  14266. // patchFlag analysis
  14267. let patchFlag = 0;
  14268. let hasRef = false;
  14269. let hasClassBinding = false;
  14270. let hasStyleBinding = false;
  14271. let hasHydrationEventBinding = false;
  14272. let hasDynamicKeys = false;
  14273. let hasVnodeHook = false;
  14274. const dynamicPropNames = [];
  14275. const analyzePatchFlag = ({ key, value }) => {
  14276. if (isStaticExp(key)) {
  14277. const name = key.content;
  14278. const isEventHandler = isOn(name);
  14279. if (!isComponent &&
  14280. isEventHandler &&
  14281. // omit the flag for click handlers because hydration gives click
  14282. // dedicated fast path.
  14283. name.toLowerCase() !== 'onclick' &&
  14284. // omit v-model handlers
  14285. name !== 'onUpdate:modelValue' &&
  14286. // omit onVnodeXXX hooks
  14287. !isReservedProp(name)) {
  14288. hasHydrationEventBinding = true;
  14289. }
  14290. if (isEventHandler && isReservedProp(name)) {
  14291. hasVnodeHook = true;
  14292. }
  14293. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  14294. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  14295. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  14296. getConstantType(value, context) > 0)) {
  14297. // skip if the prop is a cached handler or has constant value
  14298. return;
  14299. }
  14300. if (name === 'ref') {
  14301. hasRef = true;
  14302. }
  14303. else if (name === 'class') {
  14304. hasClassBinding = true;
  14305. }
  14306. else if (name === 'style') {
  14307. hasStyleBinding = true;
  14308. }
  14309. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  14310. dynamicPropNames.push(name);
  14311. }
  14312. // treat the dynamic class and style binding of the component as dynamic props
  14313. if (isComponent &&
  14314. (name === 'class' || name === 'style') &&
  14315. !dynamicPropNames.includes(name)) {
  14316. dynamicPropNames.push(name);
  14317. }
  14318. }
  14319. else {
  14320. hasDynamicKeys = true;
  14321. }
  14322. };
  14323. for (let i = 0; i < props.length; i++) {
  14324. // static attribute
  14325. const prop = props[i];
  14326. if (prop.type === 6 /* ATTRIBUTE */) {
  14327. const { loc, name, value } = prop;
  14328. let isStatic = true;
  14329. if (name === 'ref') {
  14330. hasRef = true;
  14331. if (context.scopes.vFor > 0) {
  14332. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14333. }
  14334. }
  14335. // skip is on <component>, or is="vue:xxx"
  14336. if (name === 'is' &&
  14337. (isComponentTag(tag) ||
  14338. (value && value.content.startsWith('vue:')) ||
  14339. (false ))) {
  14340. continue;
  14341. }
  14342. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  14343. }
  14344. else {
  14345. // directives
  14346. const { name, arg, exp, loc } = prop;
  14347. const isVBind = name === 'bind';
  14348. const isVOn = name === 'on';
  14349. // skip v-slot - it is handled by its dedicated transform.
  14350. if (name === 'slot') {
  14351. if (!isComponent) {
  14352. context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
  14353. }
  14354. continue;
  14355. }
  14356. // skip v-once/v-memo - they are handled by dedicated transforms.
  14357. if (name === 'once' || name === 'memo') {
  14358. continue;
  14359. }
  14360. // skip v-is and :is on <component>
  14361. if (name === 'is' ||
  14362. (isVBind &&
  14363. isStaticArgOf(arg, 'is') &&
  14364. (isComponentTag(tag) ||
  14365. (false )))) {
  14366. continue;
  14367. }
  14368. // skip v-on in SSR compilation
  14369. if (isVOn && ssr) {
  14370. continue;
  14371. }
  14372. if (
  14373. // #938: elements with dynamic keys should be forced into blocks
  14374. (isVBind && isStaticArgOf(arg, 'key')) ||
  14375. // inline before-update hooks need to force block so that it is invoked
  14376. // before children
  14377. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  14378. shouldUseBlock = true;
  14379. }
  14380. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  14381. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14382. }
  14383. // special case for v-bind and v-on with no argument
  14384. if (!arg && (isVBind || isVOn)) {
  14385. hasDynamicKeys = true;
  14386. if (exp) {
  14387. if (properties.length) {
  14388. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14389. properties = [];
  14390. }
  14391. if (isVBind) {
  14392. mergeArgs.push(exp);
  14393. }
  14394. else {
  14395. // v-on="obj" -> toHandlers(obj)
  14396. mergeArgs.push({
  14397. type: 14 /* JS_CALL_EXPRESSION */,
  14398. loc,
  14399. callee: context.helper(TO_HANDLERS),
  14400. arguments: [exp]
  14401. });
  14402. }
  14403. }
  14404. else {
  14405. context.onError(createCompilerError(isVBind
  14406. ? 34 /* X_V_BIND_NO_EXPRESSION */
  14407. : 35 /* X_V_ON_NO_EXPRESSION */, loc));
  14408. }
  14409. continue;
  14410. }
  14411. const directiveTransform = context.directiveTransforms[name];
  14412. if (directiveTransform) {
  14413. // has built-in directive transform.
  14414. const { props, needRuntime } = directiveTransform(prop, node, context);
  14415. !ssr && props.forEach(analyzePatchFlag);
  14416. properties.push(...props);
  14417. if (needRuntime) {
  14418. runtimeDirectives.push(prop);
  14419. if (isSymbol(needRuntime)) {
  14420. directiveImportMap.set(prop, needRuntime);
  14421. }
  14422. }
  14423. }
  14424. else if (!isBuiltInDirective(name)) {
  14425. // no built-in transform, this is a user custom directive.
  14426. runtimeDirectives.push(prop);
  14427. // custom dirs may use beforeUpdate so they need to force blocks
  14428. // to ensure before-update gets called before children update
  14429. if (hasChildren) {
  14430. shouldUseBlock = true;
  14431. }
  14432. }
  14433. }
  14434. }
  14435. let propsExpression = undefined;
  14436. // has v-bind="object" or v-on="object", wrap with mergeProps
  14437. if (mergeArgs.length) {
  14438. if (properties.length) {
  14439. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14440. }
  14441. if (mergeArgs.length > 1) {
  14442. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  14443. }
  14444. else {
  14445. // single v-bind with nothing else - no need for a mergeProps call
  14446. propsExpression = mergeArgs[0];
  14447. }
  14448. }
  14449. else if (properties.length) {
  14450. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  14451. }
  14452. // patchFlag analysis
  14453. if (hasDynamicKeys) {
  14454. patchFlag |= 16 /* FULL_PROPS */;
  14455. }
  14456. else {
  14457. if (hasClassBinding && !isComponent) {
  14458. patchFlag |= 2 /* CLASS */;
  14459. }
  14460. if (hasStyleBinding && !isComponent) {
  14461. patchFlag |= 4 /* STYLE */;
  14462. }
  14463. if (dynamicPropNames.length) {
  14464. patchFlag |= 8 /* PROPS */;
  14465. }
  14466. if (hasHydrationEventBinding) {
  14467. patchFlag |= 32 /* HYDRATE_EVENTS */;
  14468. }
  14469. }
  14470. if (!shouldUseBlock &&
  14471. (patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  14472. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  14473. patchFlag |= 512 /* NEED_PATCH */;
  14474. }
  14475. // pre-normalize props, SSR is skipped for now
  14476. if (!context.inSSR && propsExpression) {
  14477. switch (propsExpression.type) {
  14478. case 15 /* JS_OBJECT_EXPRESSION */:
  14479. // means that there is no v-bind,
  14480. // but still need to deal with dynamic key binding
  14481. let classKeyIndex = -1;
  14482. let styleKeyIndex = -1;
  14483. let hasDynamicKey = false;
  14484. for (let i = 0; i < propsExpression.properties.length; i++) {
  14485. const key = propsExpression.properties[i].key;
  14486. if (isStaticExp(key)) {
  14487. if (key.content === 'class') {
  14488. classKeyIndex = i;
  14489. }
  14490. else if (key.content === 'style') {
  14491. styleKeyIndex = i;
  14492. }
  14493. }
  14494. else if (!key.isHandlerKey) {
  14495. hasDynamicKey = true;
  14496. }
  14497. }
  14498. const classProp = propsExpression.properties[classKeyIndex];
  14499. const styleProp = propsExpression.properties[styleKeyIndex];
  14500. // no dynamic key
  14501. if (!hasDynamicKey) {
  14502. if (classProp && !isStaticExp(classProp.value)) {
  14503. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  14504. }
  14505. if (styleProp &&
  14506. !isStaticExp(styleProp.value) &&
  14507. // the static style is compiled into an object,
  14508. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  14509. (hasStyleBinding ||
  14510. // v-bind:style and style both exist,
  14511. // v-bind:style with static literal object
  14512. styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
  14513. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  14514. }
  14515. }
  14516. else {
  14517. // dynamic key binding, wrap with `normalizeProps`
  14518. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  14519. }
  14520. break;
  14521. case 14 /* JS_CALL_EXPRESSION */:
  14522. // mergeProps call, do nothing
  14523. break;
  14524. default:
  14525. // single v-bind
  14526. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  14527. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  14528. propsExpression
  14529. ])
  14530. ]);
  14531. break;
  14532. }
  14533. }
  14534. return {
  14535. props: propsExpression,
  14536. directives: runtimeDirectives,
  14537. patchFlag,
  14538. dynamicPropNames,
  14539. shouldUseBlock
  14540. };
  14541. }
  14542. // Dedupe props in an object literal.
  14543. // Literal duplicated attributes would have been warned during the parse phase,
  14544. // however, it's possible to encounter duplicated `onXXX` handlers with different
  14545. // modifiers. We also need to merge static and dynamic class / style attributes.
  14546. // - onXXX handlers / style: merge into array
  14547. // - class: merge into single expression with concatenation
  14548. function dedupeProperties(properties) {
  14549. const knownProps = new Map();
  14550. const deduped = [];
  14551. for (let i = 0; i < properties.length; i++) {
  14552. const prop = properties[i];
  14553. // dynamic keys are always allowed
  14554. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  14555. deduped.push(prop);
  14556. continue;
  14557. }
  14558. const name = prop.key.content;
  14559. const existing = knownProps.get(name);
  14560. if (existing) {
  14561. if (name === 'style' || name === 'class' || isOn(name)) {
  14562. mergeAsArray$1(existing, prop);
  14563. }
  14564. // unexpected duplicate, should have emitted error during parse
  14565. }
  14566. else {
  14567. knownProps.set(name, prop);
  14568. deduped.push(prop);
  14569. }
  14570. }
  14571. return deduped;
  14572. }
  14573. function mergeAsArray$1(existing, incoming) {
  14574. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  14575. existing.value.elements.push(incoming.value);
  14576. }
  14577. else {
  14578. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  14579. }
  14580. }
  14581. function buildDirectiveArgs(dir, context) {
  14582. const dirArgs = [];
  14583. const runtime = directiveImportMap.get(dir);
  14584. if (runtime) {
  14585. // built-in directive with runtime
  14586. dirArgs.push(context.helperString(runtime));
  14587. }
  14588. else {
  14589. {
  14590. // inject statement for resolving directive
  14591. context.helper(RESOLVE_DIRECTIVE);
  14592. context.directives.add(dir.name);
  14593. dirArgs.push(toValidAssetId(dir.name, `directive`));
  14594. }
  14595. }
  14596. const { loc } = dir;
  14597. if (dir.exp)
  14598. dirArgs.push(dir.exp);
  14599. if (dir.arg) {
  14600. if (!dir.exp) {
  14601. dirArgs.push(`void 0`);
  14602. }
  14603. dirArgs.push(dir.arg);
  14604. }
  14605. if (Object.keys(dir.modifiers).length) {
  14606. if (!dir.arg) {
  14607. if (!dir.exp) {
  14608. dirArgs.push(`void 0`);
  14609. }
  14610. dirArgs.push(`void 0`);
  14611. }
  14612. const trueExpression = createSimpleExpression(`true`, false, loc);
  14613. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  14614. }
  14615. return createArrayExpression(dirArgs, dir.loc);
  14616. }
  14617. function stringifyDynamicPropNames(props) {
  14618. let propsNamesString = `[`;
  14619. for (let i = 0, l = props.length; i < l; i++) {
  14620. propsNamesString += JSON.stringify(props[i]);
  14621. if (i < l - 1)
  14622. propsNamesString += ', ';
  14623. }
  14624. return propsNamesString + `]`;
  14625. }
  14626. function isComponentTag(tag) {
  14627. return tag === 'component' || tag === 'Component';
  14628. }
  14629. const transformSlotOutlet = (node, context) => {
  14630. if (isSlotOutlet(node)) {
  14631. const { children, loc } = node;
  14632. const { slotName, slotProps } = processSlotOutlet(node, context);
  14633. const slotArgs = [
  14634. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  14635. slotName,
  14636. '{}',
  14637. 'undefined',
  14638. 'true'
  14639. ];
  14640. let expectedLen = 2;
  14641. if (slotProps) {
  14642. slotArgs[2] = slotProps;
  14643. expectedLen = 3;
  14644. }
  14645. if (children.length) {
  14646. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  14647. expectedLen = 4;
  14648. }
  14649. if (context.scopeId && !context.slotted) {
  14650. expectedLen = 5;
  14651. }
  14652. slotArgs.splice(expectedLen); // remove unused arguments
  14653. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  14654. }
  14655. };
  14656. function processSlotOutlet(node, context) {
  14657. let slotName = `"default"`;
  14658. let slotProps = undefined;
  14659. const nonNameProps = [];
  14660. for (let i = 0; i < node.props.length; i++) {
  14661. const p = node.props[i];
  14662. if (p.type === 6 /* ATTRIBUTE */) {
  14663. if (p.value) {
  14664. if (p.name === 'name') {
  14665. slotName = JSON.stringify(p.value.content);
  14666. }
  14667. else {
  14668. p.name = camelize(p.name);
  14669. nonNameProps.push(p);
  14670. }
  14671. }
  14672. }
  14673. else {
  14674. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  14675. if (p.exp)
  14676. slotName = p.exp;
  14677. }
  14678. else {
  14679. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  14680. p.arg.content = camelize(p.arg.content);
  14681. }
  14682. nonNameProps.push(p);
  14683. }
  14684. }
  14685. }
  14686. if (nonNameProps.length > 0) {
  14687. const { props, directives } = buildProps(node, context, nonNameProps);
  14688. slotProps = props;
  14689. if (directives.length) {
  14690. context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  14691. }
  14692. }
  14693. return {
  14694. slotName,
  14695. slotProps
  14696. };
  14697. }
  14698. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  14699. const transformOn = (dir, node, context, augmentor) => {
  14700. const { loc, modifiers, arg } = dir;
  14701. if (!dir.exp && !modifiers.length) {
  14702. context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
  14703. }
  14704. let eventName;
  14705. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14706. if (arg.isStatic) {
  14707. let rawName = arg.content;
  14708. // TODO deprecate @vnodeXXX usage
  14709. if (rawName.startsWith('vue:')) {
  14710. rawName = `vnode-${rawName.slice(4)}`;
  14711. }
  14712. // for all event listeners, auto convert it to camelCase. See issue #2249
  14713. eventName = createSimpleExpression(toHandlerKey(camelize(rawName)), true, arg.loc);
  14714. }
  14715. else {
  14716. // #2388
  14717. eventName = createCompoundExpression([
  14718. `${context.helperString(TO_HANDLER_KEY)}(`,
  14719. arg,
  14720. `)`
  14721. ]);
  14722. }
  14723. }
  14724. else {
  14725. // already a compound expression.
  14726. eventName = arg;
  14727. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  14728. eventName.children.push(`)`);
  14729. }
  14730. // handler processing
  14731. let exp = dir.exp;
  14732. if (exp && !exp.content.trim()) {
  14733. exp = undefined;
  14734. }
  14735. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  14736. if (exp) {
  14737. const isMemberExp = isMemberExpression(exp.content);
  14738. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  14739. const hasMultipleStatements = exp.content.includes(`;`);
  14740. {
  14741. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  14742. }
  14743. if (isInlineStatement || (shouldCache && isMemberExp)) {
  14744. // wrap inline statement in a function expression
  14745. exp = createCompoundExpression([
  14746. `${isInlineStatement
  14747. ? `$event`
  14748. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  14749. exp,
  14750. hasMultipleStatements ? `}` : `)`
  14751. ]);
  14752. }
  14753. }
  14754. let ret = {
  14755. props: [
  14756. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  14757. ]
  14758. };
  14759. // apply extended compiler augmentor
  14760. if (augmentor) {
  14761. ret = augmentor(ret);
  14762. }
  14763. if (shouldCache) {
  14764. // cache handlers so that it's always the same handler being passed down.
  14765. // this avoids unnecessary re-renders when users use inline handlers on
  14766. // components.
  14767. ret.props[0].value = context.cache(ret.props[0].value);
  14768. }
  14769. // mark the key as handler for props normalization check
  14770. ret.props.forEach(p => (p.key.isHandlerKey = true));
  14771. return ret;
  14772. };
  14773. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  14774. // codegen for the entire props object. This transform here is only for v-bind
  14775. // *with* args.
  14776. const transformBind = (dir, _node, context) => {
  14777. const { exp, modifiers, loc } = dir;
  14778. const arg = dir.arg;
  14779. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  14780. arg.children.unshift(`(`);
  14781. arg.children.push(`) || ""`);
  14782. }
  14783. else if (!arg.isStatic) {
  14784. arg.content = `${arg.content} || ""`;
  14785. }
  14786. // .sync is replaced by v-model:arg
  14787. if (modifiers.includes('camel')) {
  14788. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14789. if (arg.isStatic) {
  14790. arg.content = camelize(arg.content);
  14791. }
  14792. else {
  14793. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  14794. }
  14795. }
  14796. else {
  14797. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  14798. arg.children.push(`)`);
  14799. }
  14800. }
  14801. if (!context.inSSR) {
  14802. if (modifiers.includes('prop')) {
  14803. injectPrefix(arg, '.');
  14804. }
  14805. if (modifiers.includes('attr')) {
  14806. injectPrefix(arg, '^');
  14807. }
  14808. }
  14809. if (!exp ||
  14810. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  14811. context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
  14812. return {
  14813. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  14814. };
  14815. }
  14816. return {
  14817. props: [createObjectProperty(arg, exp)]
  14818. };
  14819. };
  14820. const injectPrefix = (arg, prefix) => {
  14821. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14822. if (arg.isStatic) {
  14823. arg.content = prefix + arg.content;
  14824. }
  14825. else {
  14826. arg.content = `\`${prefix}\${${arg.content}}\``;
  14827. }
  14828. }
  14829. else {
  14830. arg.children.unshift(`'${prefix}' + (`);
  14831. arg.children.push(`)`);
  14832. }
  14833. };
  14834. // Merge adjacent text nodes and expressions into a single expression
  14835. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  14836. const transformText = (node, context) => {
  14837. if (node.type === 0 /* ROOT */ ||
  14838. node.type === 1 /* ELEMENT */ ||
  14839. node.type === 11 /* FOR */ ||
  14840. node.type === 10 /* IF_BRANCH */) {
  14841. // perform the transform on node exit so that all expressions have already
  14842. // been processed.
  14843. return () => {
  14844. const children = node.children;
  14845. let currentContainer = undefined;
  14846. let hasText = false;
  14847. for (let i = 0; i < children.length; i++) {
  14848. const child = children[i];
  14849. if (isText(child)) {
  14850. hasText = true;
  14851. for (let j = i + 1; j < children.length; j++) {
  14852. const next = children[j];
  14853. if (isText(next)) {
  14854. if (!currentContainer) {
  14855. currentContainer = children[i] = {
  14856. type: 8 /* COMPOUND_EXPRESSION */,
  14857. loc: child.loc,
  14858. children: [child]
  14859. };
  14860. }
  14861. // merge adjacent text node into current
  14862. currentContainer.children.push(` + `, next);
  14863. children.splice(j, 1);
  14864. j--;
  14865. }
  14866. else {
  14867. currentContainer = undefined;
  14868. break;
  14869. }
  14870. }
  14871. }
  14872. }
  14873. if (!hasText ||
  14874. // if this is a plain element with a single text child, leave it
  14875. // as-is since the runtime has dedicated fast path for this by directly
  14876. // setting textContent of the element.
  14877. // for component root it's always normalized anyway.
  14878. (children.length === 1 &&
  14879. (node.type === 0 /* ROOT */ ||
  14880. (node.type === 1 /* ELEMENT */ &&
  14881. node.tagType === 0 /* ELEMENT */ &&
  14882. // #3756
  14883. // custom directives can potentially add DOM elements arbitrarily,
  14884. // we need to avoid setting textContent of the element at runtime
  14885. // to avoid accidentally overwriting the DOM elements added
  14886. // by the user through custom directives.
  14887. !node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
  14888. !context.directiveTransforms[p.name]) &&
  14889. // in compat mode, <template> tags with no special directives
  14890. // will be rendered as a fragment so its children must be
  14891. // converted into vnodes.
  14892. !(false ))))) {
  14893. return;
  14894. }
  14895. // pre-convert text nodes into createTextVNode(text) calls to avoid
  14896. // runtime normalization.
  14897. for (let i = 0; i < children.length; i++) {
  14898. const child = children[i];
  14899. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  14900. const callArgs = [];
  14901. // createTextVNode defaults to single whitespace, so if it is a
  14902. // single space the code could be an empty call to save bytes.
  14903. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  14904. callArgs.push(child);
  14905. }
  14906. // mark dynamic text with flag so it gets patched inside a block
  14907. if (!context.ssr &&
  14908. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14909. callArgs.push(1 /* TEXT */ +
  14910. (` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
  14911. }
  14912. children[i] = {
  14913. type: 12 /* TEXT_CALL */,
  14914. content: child,
  14915. loc: child.loc,
  14916. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  14917. };
  14918. }
  14919. }
  14920. };
  14921. }
  14922. };
  14923. const seen = new WeakSet();
  14924. const transformOnce = (node, context) => {
  14925. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  14926. if (seen.has(node) || context.inVOnce) {
  14927. return;
  14928. }
  14929. seen.add(node);
  14930. context.inVOnce = true;
  14931. context.helper(SET_BLOCK_TRACKING);
  14932. return () => {
  14933. context.inVOnce = false;
  14934. const cur = context.currentNode;
  14935. if (cur.codegenNode) {
  14936. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  14937. }
  14938. };
  14939. }
  14940. };
  14941. const transformModel = (dir, node, context) => {
  14942. const { exp, arg } = dir;
  14943. if (!exp) {
  14944. context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  14945. return createTransformProps();
  14946. }
  14947. const rawExp = exp.loc.source;
  14948. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  14949. // im SFC <script setup> inline mode, the exp may have been transformed into
  14950. // _unref(exp)
  14951. context.bindingMetadata[rawExp];
  14952. const maybeRef = !true /* SETUP_CONST */;
  14953. if (!expString.trim() ||
  14954. (!isMemberExpression(expString) && !maybeRef)) {
  14955. context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  14956. return createTransformProps();
  14957. }
  14958. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  14959. const eventName = arg
  14960. ? isStaticExp(arg)
  14961. ? `onUpdate:${arg.content}`
  14962. : createCompoundExpression(['"onUpdate:" + ', arg])
  14963. : `onUpdate:modelValue`;
  14964. let assignmentExp;
  14965. const eventArg = context.isTS ? `($event: any)` : `$event`;
  14966. {
  14967. assignmentExp = createCompoundExpression([
  14968. `${eventArg} => ((`,
  14969. exp,
  14970. `) = $event)`
  14971. ]);
  14972. }
  14973. const props = [
  14974. // modelValue: foo
  14975. createObjectProperty(propName, dir.exp),
  14976. // "onUpdate:modelValue": $event => (foo = $event)
  14977. createObjectProperty(eventName, assignmentExp)
  14978. ];
  14979. // modelModifiers: { foo: true, "bar-baz": true }
  14980. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  14981. const modifiers = dir.modifiers
  14982. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  14983. .join(`, `);
  14984. const modifiersKey = arg
  14985. ? isStaticExp(arg)
  14986. ? `${arg.content}Modifiers`
  14987. : createCompoundExpression([arg, ' + "Modifiers"'])
  14988. : `modelModifiers`;
  14989. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  14990. }
  14991. return createTransformProps(props);
  14992. };
  14993. function createTransformProps(props = []) {
  14994. return { props };
  14995. }
  14996. const seen$1 = new WeakSet();
  14997. const transformMemo = (node, context) => {
  14998. if (node.type === 1 /* ELEMENT */) {
  14999. const dir = findDir(node, 'memo');
  15000. if (!dir || seen$1.has(node)) {
  15001. return;
  15002. }
  15003. seen$1.add(node);
  15004. return () => {
  15005. const codegenNode = node.codegenNode ||
  15006. context.currentNode.codegenNode;
  15007. if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
  15008. // non-component sub tree should be turned into a block
  15009. if (node.tagType !== 1 /* COMPONENT */) {
  15010. makeBlock(codegenNode, context);
  15011. }
  15012. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  15013. dir.exp,
  15014. createFunctionExpression(undefined, codegenNode),
  15015. `_cache`,
  15016. String(context.cached++)
  15017. ]);
  15018. }
  15019. };
  15020. }
  15021. };
  15022. function getBaseTransformPreset(prefixIdentifiers) {
  15023. return [
  15024. [
  15025. transformOnce,
  15026. transformIf,
  15027. transformMemo,
  15028. transformFor,
  15029. ...([]),
  15030. ...([transformExpression]
  15031. ),
  15032. transformSlotOutlet,
  15033. transformElement,
  15034. trackSlotScopes,
  15035. transformText
  15036. ],
  15037. {
  15038. on: transformOn,
  15039. bind: transformBind,
  15040. model: transformModel
  15041. }
  15042. ];
  15043. }
  15044. // we name it `baseCompile` so that higher order compilers like
  15045. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  15046. function baseCompile(template, options = {}) {
  15047. const onError = options.onError || defaultOnError;
  15048. const isModuleMode = options.mode === 'module';
  15049. /* istanbul ignore if */
  15050. {
  15051. if (options.prefixIdentifiers === true) {
  15052. onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
  15053. }
  15054. else if (isModuleMode) {
  15055. onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
  15056. }
  15057. }
  15058. const prefixIdentifiers = !true ;
  15059. if (options.cacheHandlers) {
  15060. onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  15061. }
  15062. if (options.scopeId && !isModuleMode) {
  15063. onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
  15064. }
  15065. const ast = isString(template) ? baseParse(template, options) : template;
  15066. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  15067. transform(ast, extend({}, options, {
  15068. prefixIdentifiers,
  15069. nodeTransforms: [
  15070. ...nodeTransforms,
  15071. ...(options.nodeTransforms || []) // user transforms
  15072. ],
  15073. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  15074. )
  15075. }));
  15076. return generate(ast, extend({}, options, {
  15077. prefixIdentifiers
  15078. }));
  15079. }
  15080. const noopDirectiveTransform = () => ({ props: [] });
  15081. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  15082. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  15083. const V_MODEL_TEXT = Symbol(`vModelText` );
  15084. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  15085. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  15086. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  15087. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  15088. const V_SHOW = Symbol(`vShow` );
  15089. const TRANSITION$1 = Symbol(`Transition` );
  15090. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  15091. registerRuntimeHelpers({
  15092. [V_MODEL_RADIO]: `vModelRadio`,
  15093. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  15094. [V_MODEL_TEXT]: `vModelText`,
  15095. [V_MODEL_SELECT]: `vModelSelect`,
  15096. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  15097. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  15098. [V_ON_WITH_KEYS]: `withKeys`,
  15099. [V_SHOW]: `vShow`,
  15100. [TRANSITION$1]: `Transition`,
  15101. [TRANSITION_GROUP]: `TransitionGroup`
  15102. });
  15103. /* eslint-disable no-restricted-globals */
  15104. let decoder;
  15105. function decodeHtmlBrowser(raw, asAttr = false) {
  15106. if (!decoder) {
  15107. decoder = document.createElement('div');
  15108. }
  15109. if (asAttr) {
  15110. decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
  15111. return decoder.children[0].getAttribute('foo');
  15112. }
  15113. else {
  15114. decoder.innerHTML = raw;
  15115. return decoder.textContent;
  15116. }
  15117. }
  15118. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  15119. const parserOptions = {
  15120. isVoidTag,
  15121. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  15122. isPreTag: tag => tag === 'pre',
  15123. decodeEntities: decodeHtmlBrowser ,
  15124. isBuiltInComponent: (tag) => {
  15125. if (isBuiltInType(tag, `Transition`)) {
  15126. return TRANSITION$1;
  15127. }
  15128. else if (isBuiltInType(tag, `TransitionGroup`)) {
  15129. return TRANSITION_GROUP;
  15130. }
  15131. },
  15132. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  15133. getNamespace(tag, parent) {
  15134. let ns = parent ? parent.ns : 0 /* HTML */;
  15135. if (parent && ns === 2 /* MATH_ML */) {
  15136. if (parent.tag === 'annotation-xml') {
  15137. if (tag === 'svg') {
  15138. return 1 /* SVG */;
  15139. }
  15140. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  15141. a.name === 'encoding' &&
  15142. a.value != null &&
  15143. (a.value.content === 'text/html' ||
  15144. a.value.content === 'application/xhtml+xml'))) {
  15145. ns = 0 /* HTML */;
  15146. }
  15147. }
  15148. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  15149. tag !== 'mglyph' &&
  15150. tag !== 'malignmark') {
  15151. ns = 0 /* HTML */;
  15152. }
  15153. }
  15154. else if (parent && ns === 1 /* SVG */) {
  15155. if (parent.tag === 'foreignObject' ||
  15156. parent.tag === 'desc' ||
  15157. parent.tag === 'title') {
  15158. ns = 0 /* HTML */;
  15159. }
  15160. }
  15161. if (ns === 0 /* HTML */) {
  15162. if (tag === 'svg') {
  15163. return 1 /* SVG */;
  15164. }
  15165. if (tag === 'math') {
  15166. return 2 /* MATH_ML */;
  15167. }
  15168. }
  15169. return ns;
  15170. },
  15171. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  15172. getTextMode({ tag, ns }) {
  15173. if (ns === 0 /* HTML */) {
  15174. if (tag === 'textarea' || tag === 'title') {
  15175. return 1 /* RCDATA */;
  15176. }
  15177. if (isRawTextContainer(tag)) {
  15178. return 2 /* RAWTEXT */;
  15179. }
  15180. }
  15181. return 0 /* DATA */;
  15182. }
  15183. };
  15184. // Parse inline CSS strings for static style attributes into an object.
  15185. // This is a NodeTransform since it works on the static `style` attribute and
  15186. // converts it into a dynamic equivalent:
  15187. // style="color: red" -> :style='{ "color": "red" }'
  15188. // It is then processed by `transformElement` and included in the generated
  15189. // props.
  15190. const transformStyle = node => {
  15191. if (node.type === 1 /* ELEMENT */) {
  15192. node.props.forEach((p, i) => {
  15193. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  15194. // replace p with an expression node
  15195. node.props[i] = {
  15196. type: 7 /* DIRECTIVE */,
  15197. name: `bind`,
  15198. arg: createSimpleExpression(`style`, true, p.loc),
  15199. exp: parseInlineCSS(p.value.content, p.loc),
  15200. modifiers: [],
  15201. loc: p.loc
  15202. };
  15203. }
  15204. });
  15205. }
  15206. };
  15207. const parseInlineCSS = (cssText, loc) => {
  15208. const normalized = parseStringStyle(cssText);
  15209. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
  15210. };
  15211. function createDOMCompilerError(code, loc) {
  15212. return createCompilerError(code, loc, DOMErrorMessages );
  15213. }
  15214. const DOMErrorMessages = {
  15215. [50 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  15216. [51 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  15217. [52 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  15218. [53 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  15219. [54 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  15220. [55 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  15221. [56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  15222. [57 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  15223. [58 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  15224. [59 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  15225. [60 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  15226. };
  15227. const transformVHtml = (dir, node, context) => {
  15228. const { exp, loc } = dir;
  15229. if (!exp) {
  15230. context.onError(createDOMCompilerError(50 /* X_V_HTML_NO_EXPRESSION */, loc));
  15231. }
  15232. if (node.children.length) {
  15233. context.onError(createDOMCompilerError(51 /* X_V_HTML_WITH_CHILDREN */, loc));
  15234. node.children.length = 0;
  15235. }
  15236. return {
  15237. props: [
  15238. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  15239. ]
  15240. };
  15241. };
  15242. const transformVText = (dir, node, context) => {
  15243. const { exp, loc } = dir;
  15244. if (!exp) {
  15245. context.onError(createDOMCompilerError(52 /* X_V_TEXT_NO_EXPRESSION */, loc));
  15246. }
  15247. if (node.children.length) {
  15248. context.onError(createDOMCompilerError(53 /* X_V_TEXT_WITH_CHILDREN */, loc));
  15249. node.children.length = 0;
  15250. }
  15251. return {
  15252. props: [
  15253. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  15254. ? createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  15255. : createSimpleExpression('', true))
  15256. ]
  15257. };
  15258. };
  15259. const transformModel$1 = (dir, node, context) => {
  15260. const baseResult = transformModel(dir, node, context);
  15261. // base transform has errors OR component v-model (only need props)
  15262. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  15263. return baseResult;
  15264. }
  15265. if (dir.arg) {
  15266. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  15267. }
  15268. function checkDuplicatedValue() {
  15269. const value = findProp(node, 'value');
  15270. if (value) {
  15271. context.onError(createDOMCompilerError(57 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  15272. }
  15273. }
  15274. const { tag } = node;
  15275. const isCustomElement = context.isCustomElement(tag);
  15276. if (tag === 'input' ||
  15277. tag === 'textarea' ||
  15278. tag === 'select' ||
  15279. isCustomElement) {
  15280. let directiveToUse = V_MODEL_TEXT;
  15281. let isInvalidType = false;
  15282. if (tag === 'input' || isCustomElement) {
  15283. const type = findProp(node, `type`);
  15284. if (type) {
  15285. if (type.type === 7 /* DIRECTIVE */) {
  15286. // :type="foo"
  15287. directiveToUse = V_MODEL_DYNAMIC;
  15288. }
  15289. else if (type.value) {
  15290. switch (type.value.content) {
  15291. case 'radio':
  15292. directiveToUse = V_MODEL_RADIO;
  15293. break;
  15294. case 'checkbox':
  15295. directiveToUse = V_MODEL_CHECKBOX;
  15296. break;
  15297. case 'file':
  15298. isInvalidType = true;
  15299. context.onError(createDOMCompilerError(56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  15300. break;
  15301. default:
  15302. // text type
  15303. checkDuplicatedValue();
  15304. break;
  15305. }
  15306. }
  15307. }
  15308. else if (hasDynamicKeyVBind(node)) {
  15309. // element has bindings with dynamic keys, which can possibly contain
  15310. // "type".
  15311. directiveToUse = V_MODEL_DYNAMIC;
  15312. }
  15313. else {
  15314. // text type
  15315. checkDuplicatedValue();
  15316. }
  15317. }
  15318. else if (tag === 'select') {
  15319. directiveToUse = V_MODEL_SELECT;
  15320. }
  15321. else {
  15322. // textarea
  15323. checkDuplicatedValue();
  15324. }
  15325. // inject runtime directive
  15326. // by returning the helper symbol via needRuntime
  15327. // the import will replaced a resolveDirective call.
  15328. if (!isInvalidType) {
  15329. baseResult.needRuntime = context.helper(directiveToUse);
  15330. }
  15331. }
  15332. else {
  15333. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  15334. }
  15335. // native vmodel doesn't need the `modelValue` props since they are also
  15336. // passed to the runtime as `binding.value`. removing it reduces code size.
  15337. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  15338. p.key.content === 'modelValue'));
  15339. return baseResult;
  15340. };
  15341. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  15342. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  15343. // event propagation management
  15344. `stop,prevent,self,` +
  15345. // system modifiers + exact
  15346. `ctrl,shift,alt,meta,exact,` +
  15347. // mouse
  15348. `middle`);
  15349. // left & right could be mouse or key modifiers based on event type
  15350. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  15351. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  15352. const resolveModifiers = (key, modifiers, context, loc) => {
  15353. const keyModifiers = [];
  15354. const nonKeyModifiers = [];
  15355. const eventOptionModifiers = [];
  15356. for (let i = 0; i < modifiers.length; i++) {
  15357. const modifier = modifiers[i];
  15358. if (isEventOptionModifier(modifier)) {
  15359. // eventOptionModifiers: modifiers for addEventListener() options,
  15360. // e.g. .passive & .capture
  15361. eventOptionModifiers.push(modifier);
  15362. }
  15363. else {
  15364. // runtimeModifiers: modifiers that needs runtime guards
  15365. if (maybeKeyModifier(modifier)) {
  15366. if (isStaticExp(key)) {
  15367. if (isKeyboardEvent(key.content)) {
  15368. keyModifiers.push(modifier);
  15369. }
  15370. else {
  15371. nonKeyModifiers.push(modifier);
  15372. }
  15373. }
  15374. else {
  15375. keyModifiers.push(modifier);
  15376. nonKeyModifiers.push(modifier);
  15377. }
  15378. }
  15379. else {
  15380. if (isNonKeyModifier(modifier)) {
  15381. nonKeyModifiers.push(modifier);
  15382. }
  15383. else {
  15384. keyModifiers.push(modifier);
  15385. }
  15386. }
  15387. }
  15388. }
  15389. return {
  15390. keyModifiers,
  15391. nonKeyModifiers,
  15392. eventOptionModifiers
  15393. };
  15394. };
  15395. const transformClick = (key, event) => {
  15396. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  15397. return isStaticClick
  15398. ? createSimpleExpression(event, true)
  15399. : key.type !== 4 /* SIMPLE_EXPRESSION */
  15400. ? createCompoundExpression([
  15401. `(`,
  15402. key,
  15403. `) === "onClick" ? "${event}" : (`,
  15404. key,
  15405. `)`
  15406. ])
  15407. : key;
  15408. };
  15409. const transformOn$1 = (dir, node, context) => {
  15410. return transformOn(dir, node, context, baseResult => {
  15411. const { modifiers } = dir;
  15412. if (!modifiers.length)
  15413. return baseResult;
  15414. let { key, value: handlerExp } = baseResult.props[0];
  15415. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  15416. // normalize click.right and click.middle since they don't actually fire
  15417. if (nonKeyModifiers.includes('right')) {
  15418. key = transformClick(key, `onContextmenu`);
  15419. }
  15420. if (nonKeyModifiers.includes('middle')) {
  15421. key = transformClick(key, `onMouseup`);
  15422. }
  15423. if (nonKeyModifiers.length) {
  15424. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  15425. handlerExp,
  15426. JSON.stringify(nonKeyModifiers)
  15427. ]);
  15428. }
  15429. if (keyModifiers.length &&
  15430. // if event name is dynamic, always wrap with keys guard
  15431. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  15432. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  15433. handlerExp,
  15434. JSON.stringify(keyModifiers)
  15435. ]);
  15436. }
  15437. if (eventOptionModifiers.length) {
  15438. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  15439. key = isStaticExp(key)
  15440. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  15441. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  15442. }
  15443. return {
  15444. props: [createObjectProperty(key, handlerExp)]
  15445. };
  15446. });
  15447. };
  15448. const transformShow = (dir, node, context) => {
  15449. const { exp, loc } = dir;
  15450. if (!exp) {
  15451. context.onError(createDOMCompilerError(58 /* X_V_SHOW_NO_EXPRESSION */, loc));
  15452. }
  15453. return {
  15454. props: [],
  15455. needRuntime: context.helper(V_SHOW)
  15456. };
  15457. };
  15458. const warnTransitionChildren = (node, context) => {
  15459. if (node.type === 1 /* ELEMENT */ &&
  15460. node.tagType === 1 /* COMPONENT */) {
  15461. const component = context.isBuiltInComponent(node.tag);
  15462. if (component === TRANSITION$1) {
  15463. return () => {
  15464. if (node.children.length && hasMultipleChildren(node)) {
  15465. context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
  15466. start: node.children[0].loc.start,
  15467. end: node.children[node.children.length - 1].loc.end,
  15468. source: ''
  15469. }));
  15470. }
  15471. };
  15472. }
  15473. }
  15474. };
  15475. function hasMultipleChildren(node) {
  15476. // #1352 filter out potential comment nodes.
  15477. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */ &&
  15478. !(c.type === 2 /* TEXT */ && !c.content.trim())));
  15479. const child = children[0];
  15480. return (children.length !== 1 ||
  15481. child.type === 11 /* FOR */ ||
  15482. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  15483. }
  15484. const ignoreSideEffectTags = (node, context) => {
  15485. if (node.type === 1 /* ELEMENT */ &&
  15486. node.tagType === 0 /* ELEMENT */ &&
  15487. (node.tag === 'script' || node.tag === 'style')) {
  15488. context.onError(createDOMCompilerError(60 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  15489. context.removeNode();
  15490. }
  15491. };
  15492. const DOMNodeTransforms = [
  15493. transformStyle,
  15494. ...([warnTransitionChildren] )
  15495. ];
  15496. const DOMDirectiveTransforms = {
  15497. cloak: noopDirectiveTransform,
  15498. html: transformVHtml,
  15499. text: transformVText,
  15500. model: transformModel$1,
  15501. on: transformOn$1,
  15502. show: transformShow
  15503. };
  15504. function compile$1(template, options = {}) {
  15505. return baseCompile(template, extend({}, parserOptions, options, {
  15506. nodeTransforms: [
  15507. // ignore <script> and <tag>
  15508. // this is not put inside DOMNodeTransforms because that list is used
  15509. // by compiler-ssr to generate vnode fallback branches
  15510. ignoreSideEffectTags,
  15511. ...DOMNodeTransforms,
  15512. ...(options.nodeTransforms || [])
  15513. ],
  15514. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  15515. transformHoist: null
  15516. }));
  15517. }
  15518. // This entry is the "full-build" that includes both the runtime
  15519. {
  15520. initDev();
  15521. }
  15522. const compileCache = Object.create(null);
  15523. function compileToFunction(template, options) {
  15524. if (!isString(template)) {
  15525. if (template.nodeType) {
  15526. template = template.innerHTML;
  15527. }
  15528. else {
  15529. warn$1(`invalid template option: `, template);
  15530. return NOOP;
  15531. }
  15532. }
  15533. const key = template;
  15534. const cached = compileCache[key];
  15535. if (cached) {
  15536. return cached;
  15537. }
  15538. if (template[0] === '#') {
  15539. const el = document.querySelector(template);
  15540. if (!el) {
  15541. warn$1(`Template element not found or is empty: ${template}`);
  15542. }
  15543. // __UNSAFE__
  15544. // Reason: potential execution of JS expressions in in-DOM template.
  15545. // The user must make sure the in-DOM template is trusted. If it's rendered
  15546. // by the server, the template should not contain any user data.
  15547. template = el ? el.innerHTML : ``;
  15548. }
  15549. const { code } = compile$1(template, extend({
  15550. hoistStatic: true,
  15551. onError: onError ,
  15552. onWarn: e => onError(e, true)
  15553. }, options));
  15554. function onError(err, asWarning = false) {
  15555. const message = asWarning
  15556. ? err.message
  15557. : `Template compilation error: ${err.message}`;
  15558. const codeFrame = err.loc &&
  15559. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  15560. warn$1(codeFrame ? `${message}\n${codeFrame}` : message);
  15561. }
  15562. // The wildcard import results in a huge object with every export
  15563. // with keys that cannot be mangled, and can be quite heavy size-wise.
  15564. // In the global build we know `Vue` is available globally so we can avoid
  15565. // the wildcard object.
  15566. const render = (new Function(code)() );
  15567. render._rc = true;
  15568. return (compileCache[key] = render);
  15569. }
  15570. registerRuntimeCompiler(compileToFunction);
  15571. exports.BaseTransition = BaseTransition;
  15572. exports.Comment = Comment;
  15573. exports.EffectScope = EffectScope;
  15574. exports.Fragment = Fragment;
  15575. exports.KeepAlive = KeepAlive;
  15576. exports.ReactiveEffect = ReactiveEffect;
  15577. exports.Static = Static;
  15578. exports.Suspense = Suspense;
  15579. exports.Teleport = Teleport;
  15580. exports.Text = Text;
  15581. exports.Transition = Transition;
  15582. exports.TransitionGroup = TransitionGroup;
  15583. exports.VueElement = VueElement;
  15584. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  15585. exports.callWithErrorHandling = callWithErrorHandling;
  15586. exports.camelize = camelize;
  15587. exports.capitalize = capitalize;
  15588. exports.cloneVNode = cloneVNode;
  15589. exports.compatUtils = compatUtils;
  15590. exports.compile = compileToFunction;
  15591. exports.computed = computed$1;
  15592. exports.createApp = createApp;
  15593. exports.createBlock = createBlock;
  15594. exports.createCommentVNode = createCommentVNode;
  15595. exports.createElementBlock = createElementBlock;
  15596. exports.createElementVNode = createBaseVNode;
  15597. exports.createHydrationRenderer = createHydrationRenderer;
  15598. exports.createPropsRestProxy = createPropsRestProxy;
  15599. exports.createRenderer = createRenderer;
  15600. exports.createSSRApp = createSSRApp;
  15601. exports.createSlots = createSlots;
  15602. exports.createStaticVNode = createStaticVNode;
  15603. exports.createTextVNode = createTextVNode;
  15604. exports.createVNode = createVNode;
  15605. exports.customRef = customRef;
  15606. exports.defineAsyncComponent = defineAsyncComponent;
  15607. exports.defineComponent = defineComponent;
  15608. exports.defineCustomElement = defineCustomElement;
  15609. exports.defineEmits = defineEmits;
  15610. exports.defineExpose = defineExpose;
  15611. exports.defineProps = defineProps;
  15612. exports.defineSSRCustomElement = defineSSRCustomElement;
  15613. exports.effect = effect;
  15614. exports.effectScope = effectScope;
  15615. exports.getCurrentInstance = getCurrentInstance;
  15616. exports.getCurrentScope = getCurrentScope;
  15617. exports.getTransitionRawChildren = getTransitionRawChildren;
  15618. exports.guardReactiveProps = guardReactiveProps;
  15619. exports.h = h;
  15620. exports.handleError = handleError;
  15621. exports.hydrate = hydrate;
  15622. exports.initCustomFormatter = initCustomFormatter;
  15623. exports.initDirectivesForSSR = initDirectivesForSSR;
  15624. exports.inject = inject;
  15625. exports.isMemoSame = isMemoSame;
  15626. exports.isProxy = isProxy;
  15627. exports.isReactive = isReactive;
  15628. exports.isReadonly = isReadonly;
  15629. exports.isRef = isRef;
  15630. exports.isRuntimeOnly = isRuntimeOnly;
  15631. exports.isShallow = isShallow;
  15632. exports.isVNode = isVNode;
  15633. exports.markRaw = markRaw;
  15634. exports.mergeDefaults = mergeDefaults;
  15635. exports.mergeProps = mergeProps;
  15636. exports.nextTick = nextTick;
  15637. exports.normalizeClass = normalizeClass;
  15638. exports.normalizeProps = normalizeProps;
  15639. exports.normalizeStyle = normalizeStyle;
  15640. exports.onActivated = onActivated;
  15641. exports.onBeforeMount = onBeforeMount;
  15642. exports.onBeforeUnmount = onBeforeUnmount;
  15643. exports.onBeforeUpdate = onBeforeUpdate;
  15644. exports.onDeactivated = onDeactivated;
  15645. exports.onErrorCaptured = onErrorCaptured;
  15646. exports.onMounted = onMounted;
  15647. exports.onRenderTracked = onRenderTracked;
  15648. exports.onRenderTriggered = onRenderTriggered;
  15649. exports.onScopeDispose = onScopeDispose;
  15650. exports.onServerPrefetch = onServerPrefetch;
  15651. exports.onUnmounted = onUnmounted;
  15652. exports.onUpdated = onUpdated;
  15653. exports.openBlock = openBlock;
  15654. exports.popScopeId = popScopeId;
  15655. exports.provide = provide;
  15656. exports.proxyRefs = proxyRefs;
  15657. exports.pushScopeId = pushScopeId;
  15658. exports.queuePostFlushCb = queuePostFlushCb;
  15659. exports.reactive = reactive;
  15660. exports.readonly = readonly;
  15661. exports.ref = ref;
  15662. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  15663. exports.render = render;
  15664. exports.renderList = renderList;
  15665. exports.renderSlot = renderSlot;
  15666. exports.resolveComponent = resolveComponent;
  15667. exports.resolveDirective = resolveDirective;
  15668. exports.resolveDynamicComponent = resolveDynamicComponent;
  15669. exports.resolveFilter = resolveFilter;
  15670. exports.resolveTransitionHooks = resolveTransitionHooks;
  15671. exports.setBlockTracking = setBlockTracking;
  15672. exports.setDevtoolsHook = setDevtoolsHook;
  15673. exports.setTransitionHooks = setTransitionHooks;
  15674. exports.shallowReactive = shallowReactive;
  15675. exports.shallowReadonly = shallowReadonly;
  15676. exports.shallowRef = shallowRef;
  15677. exports.ssrContextKey = ssrContextKey;
  15678. exports.ssrUtils = ssrUtils;
  15679. exports.stop = stop;
  15680. exports.toDisplayString = toDisplayString;
  15681. exports.toHandlerKey = toHandlerKey;
  15682. exports.toHandlers = toHandlers;
  15683. exports.toRaw = toRaw;
  15684. exports.toRef = toRef;
  15685. exports.toRefs = toRefs;
  15686. exports.transformVNodeArgs = transformVNodeArgs;
  15687. exports.triggerRef = triggerRef;
  15688. exports.unref = unref;
  15689. exports.useAttrs = useAttrs;
  15690. exports.useCssModule = useCssModule;
  15691. exports.useCssVars = useCssVars;
  15692. exports.useSSRContext = useSSRContext;
  15693. exports.useSlots = useSlots;
  15694. exports.useTransitionState = useTransitionState;
  15695. exports.vModelCheckbox = vModelCheckbox;
  15696. exports.vModelDynamic = vModelDynamic;
  15697. exports.vModelRadio = vModelRadio;
  15698. exports.vModelSelect = vModelSelect;
  15699. exports.vModelText = vModelText;
  15700. exports.vShow = vShow;
  15701. exports.version = version;
  15702. exports.warn = warn$1;
  15703. exports.watch = watch;
  15704. exports.watchEffect = watchEffect;
  15705. exports.watchPostEffect = watchPostEffect;
  15706. exports.watchSyncEffect = watchSyncEffect;
  15707. exports.withAsyncContext = withAsyncContext;
  15708. exports.withCtx = withCtx;
  15709. exports.withDefaults = withDefaults;
  15710. exports.withDirectives = withDirectives;
  15711. exports.withKeys = withKeys;
  15712. exports.withMemo = withMemo;
  15713. exports.withModifiers = withModifiers;
  15714. exports.withScopeId = withScopeId;
  15715. Object.defineProperty(exports, '__esModule', { value: true });
  15716. return exports;
  15717. }({}));