vue.global.js 628 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160
  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 /* PatchFlags.TEXT */]: `TEXT`,
  23. [2 /* PatchFlags.CLASS */]: `CLASS`,
  24. [4 /* PatchFlags.STYLE */]: `STYLE`,
  25. [8 /* PatchFlags.PROPS */]: `PROPS`,
  26. [16 /* PatchFlags.FULL_PROPS */]: `FULL_PROPS`,
  27. [32 /* PatchFlags.HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  28. [64 /* PatchFlags.STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  29. [128 /* PatchFlags.KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  30. [256 /* PatchFlags.UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  31. [512 /* PatchFlags.NEED_PATCH */]: `NEED_PATCH`,
  32. [1024 /* PatchFlags.DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  33. [2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  34. [-1 /* PatchFlags.HOISTED */]: `HOISTED`,
  35. [-2 /* PatchFlags.BAIL */]: `BAIL`
  36. };
  37. /**
  38. * Dev only
  39. */
  40. const slotFlagsText = {
  41. [1 /* SlotFlags.STABLE */]: 'STABLE',
  42. [2 /* SlotFlags.DYNAMIC */]: 'DYNAMIC',
  43. [3 /* SlotFlags.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. function normalizeStyle(value) {
  93. if (isArray(value)) {
  94. const res = {};
  95. for (let i = 0; i < value.length; i++) {
  96. const item = value[i];
  97. const normalized = isString(item)
  98. ? parseStringStyle(item)
  99. : normalizeStyle(item);
  100. if (normalized) {
  101. for (const key in normalized) {
  102. res[key] = normalized[key];
  103. }
  104. }
  105. }
  106. return res;
  107. }
  108. else if (isString(value)) {
  109. return value;
  110. }
  111. else if (isObject(value)) {
  112. return value;
  113. }
  114. }
  115. const listDelimiterRE = /;(?![^(]*\))/g;
  116. const propertyDelimiterRE = /:([^]+)/;
  117. const styleCommentRE = /\/\*.*?\*\//gs;
  118. function parseStringStyle(cssText) {
  119. const ret = {};
  120. cssText
  121. .replace(styleCommentRE, '')
  122. .split(listDelimiterRE)
  123. .forEach(item => {
  124. if (item) {
  125. const tmp = item.split(propertyDelimiterRE);
  126. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  127. }
  128. });
  129. return ret;
  130. }
  131. function normalizeClass(value) {
  132. let res = '';
  133. if (isString(value)) {
  134. res = value;
  135. }
  136. else if (isArray(value)) {
  137. for (let i = 0; i < value.length; i++) {
  138. const normalized = normalizeClass(value[i]);
  139. if (normalized) {
  140. res += normalized + ' ';
  141. }
  142. }
  143. }
  144. else if (isObject(value)) {
  145. for (const name in value) {
  146. if (value[name]) {
  147. res += name + ' ';
  148. }
  149. }
  150. }
  151. return res.trim();
  152. }
  153. function normalizeProps(props) {
  154. if (!props)
  155. return null;
  156. let { class: klass, style } = props;
  157. if (klass && !isString(klass)) {
  158. props.class = normalizeClass(klass);
  159. }
  160. if (style) {
  161. props.style = normalizeStyle(style);
  162. }
  163. return props;
  164. }
  165. // These tag configs are shared between compiler-dom and runtime-dom, so they
  166. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  167. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  168. 'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  169. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  170. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  171. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  172. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  173. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  174. 'option,output,progress,select,textarea,details,dialog,menu,' +
  175. 'summary,template,blockquote,iframe,tfoot';
  176. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  177. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  178. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  179. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  180. 'feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  181. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  182. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  183. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  184. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  185. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  186. 'text,textPath,title,tspan,unknown,use,view';
  187. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  188. /**
  189. * Compiler only.
  190. * Do NOT use in runtime code paths unless behind `true` flag.
  191. */
  192. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  193. /**
  194. * Compiler only.
  195. * Do NOT use in runtime code paths unless behind `true` flag.
  196. */
  197. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  198. /**
  199. * Compiler only.
  200. * Do NOT use in runtime code paths unless behind `true` flag.
  201. */
  202. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  203. /**
  204. * On the client we only need to offer special cases for boolean attributes that
  205. * have different names from their corresponding dom properties:
  206. * - itemscope -> N/A
  207. * - allowfullscreen -> allowFullscreen
  208. * - formnovalidate -> formNoValidate
  209. * - ismap -> isMap
  210. * - nomodule -> noModule
  211. * - novalidate -> noValidate
  212. * - readonly -> readOnly
  213. */
  214. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  215. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  216. /**
  217. * Boolean attributes should be included if the value is truthy or ''.
  218. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  219. */
  220. function includeBooleanAttr(value) {
  221. return !!value || value === '';
  222. }
  223. function looseCompareArrays(a, b) {
  224. if (a.length !== b.length)
  225. return false;
  226. let equal = true;
  227. for (let i = 0; equal && i < a.length; i++) {
  228. equal = looseEqual(a[i], b[i]);
  229. }
  230. return equal;
  231. }
  232. function looseEqual(a, b) {
  233. if (a === b)
  234. return true;
  235. let aValidType = isDate(a);
  236. let bValidType = isDate(b);
  237. if (aValidType || bValidType) {
  238. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  239. }
  240. aValidType = isSymbol(a);
  241. bValidType = isSymbol(b);
  242. if (aValidType || bValidType) {
  243. return a === b;
  244. }
  245. aValidType = isArray(a);
  246. bValidType = isArray(b);
  247. if (aValidType || bValidType) {
  248. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  249. }
  250. aValidType = isObject(a);
  251. bValidType = isObject(b);
  252. if (aValidType || bValidType) {
  253. /* istanbul ignore if: this if will probably never be called */
  254. if (!aValidType || !bValidType) {
  255. return false;
  256. }
  257. const aKeysCount = Object.keys(a).length;
  258. const bKeysCount = Object.keys(b).length;
  259. if (aKeysCount !== bKeysCount) {
  260. return false;
  261. }
  262. for (const key in a) {
  263. const aHasKey = a.hasOwnProperty(key);
  264. const bHasKey = b.hasOwnProperty(key);
  265. if ((aHasKey && !bHasKey) ||
  266. (!aHasKey && bHasKey) ||
  267. !looseEqual(a[key], b[key])) {
  268. return false;
  269. }
  270. }
  271. }
  272. return String(a) === String(b);
  273. }
  274. function looseIndexOf(arr, val) {
  275. return arr.findIndex(item => looseEqual(item, val));
  276. }
  277. /**
  278. * For converting {{ interpolation }} values to displayed strings.
  279. * @private
  280. */
  281. const toDisplayString = (val) => {
  282. return isString(val)
  283. ? val
  284. : val == null
  285. ? ''
  286. : isArray(val) ||
  287. (isObject(val) &&
  288. (val.toString === objectToString || !isFunction(val.toString)))
  289. ? JSON.stringify(val, replacer, 2)
  290. : String(val);
  291. };
  292. const replacer = (_key, val) => {
  293. // can't use isRef here since @vue/shared has no deps
  294. if (val && val.__v_isRef) {
  295. return replacer(_key, val.value);
  296. }
  297. else if (isMap(val)) {
  298. return {
  299. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  300. entries[`${key} =>`] = val;
  301. return entries;
  302. }, {})
  303. };
  304. }
  305. else if (isSet(val)) {
  306. return {
  307. [`Set(${val.size})`]: [...val.values()]
  308. };
  309. }
  310. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  311. return String(val);
  312. }
  313. return val;
  314. };
  315. const EMPTY_OBJ = Object.freeze({})
  316. ;
  317. const EMPTY_ARR = Object.freeze([]) ;
  318. const NOOP = () => { };
  319. /**
  320. * Always return false.
  321. */
  322. const NO = () => false;
  323. const onRE = /^on[^a-z]/;
  324. const isOn = (key) => onRE.test(key);
  325. const isModelListener = (key) => key.startsWith('onUpdate:');
  326. const extend = Object.assign;
  327. const remove = (arr, el) => {
  328. const i = arr.indexOf(el);
  329. if (i > -1) {
  330. arr.splice(i, 1);
  331. }
  332. };
  333. const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  334. const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
  335. const isArray = Array.isArray;
  336. const isMap = (val) => toTypeString(val) === '[object Map]';
  337. const isSet = (val) => toTypeString(val) === '[object Set]';
  338. const isDate = (val) => toTypeString(val) === '[object Date]';
  339. const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
  340. const isFunction = (val) => typeof val === 'function';
  341. const isString = (val) => typeof val === 'string';
  342. const isSymbol = (val) => typeof val === 'symbol';
  343. const isObject = (val) => val !== null && typeof val === 'object';
  344. const isPromise = (val) => {
  345. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  346. };
  347. const objectToString = Object.prototype.toString;
  348. const toTypeString = (value) => objectToString.call(value);
  349. const toRawType = (value) => {
  350. // extract "RawType" from strings like "[object RawType]"
  351. return toTypeString(value).slice(8, -1);
  352. };
  353. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  354. const isIntegerKey = (key) => isString(key) &&
  355. key !== 'NaN' &&
  356. key[0] !== '-' &&
  357. '' + parseInt(key, 10) === key;
  358. const isReservedProp = /*#__PURE__*/ makeMap(
  359. // the leading comma is intentional so empty string "" is also included
  360. ',key,ref,ref_for,ref_key,' +
  361. 'onVnodeBeforeMount,onVnodeMounted,' +
  362. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  363. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  364. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  365. const cacheStringFunction = (fn) => {
  366. const cache = Object.create(null);
  367. return ((str) => {
  368. const hit = cache[str];
  369. return hit || (cache[str] = fn(str));
  370. });
  371. };
  372. const camelizeRE = /-(\w)/g;
  373. /**
  374. * @private
  375. */
  376. const camelize = cacheStringFunction((str) => {
  377. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  378. });
  379. const hyphenateRE = /\B([A-Z])/g;
  380. /**
  381. * @private
  382. */
  383. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  384. /**
  385. * @private
  386. */
  387. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  388. /**
  389. * @private
  390. */
  391. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  392. // compare whether a value has changed, accounting for NaN.
  393. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  394. const invokeArrayFns = (fns, arg) => {
  395. for (let i = 0; i < fns.length; i++) {
  396. fns[i](arg);
  397. }
  398. };
  399. const def = (obj, key, value) => {
  400. Object.defineProperty(obj, key, {
  401. configurable: true,
  402. enumerable: false,
  403. value
  404. });
  405. };
  406. /**
  407. * "123-foo" will be parsed to 123
  408. * This is used for the .number modifier in v-model
  409. */
  410. const looseToNumber = (val) => {
  411. const n = parseFloat(val);
  412. return isNaN(n) ? val : n;
  413. };
  414. /**
  415. * Only conerces number-like strings
  416. * "123-foo" will be returned as-is
  417. */
  418. const toNumber = (val) => {
  419. const n = isString(val) ? Number(val) : NaN;
  420. return isNaN(n) ? val : n;
  421. };
  422. let _globalThis;
  423. const getGlobalThis = () => {
  424. return (_globalThis ||
  425. (_globalThis =
  426. typeof globalThis !== 'undefined'
  427. ? globalThis
  428. : typeof self !== 'undefined'
  429. ? self
  430. : typeof window !== 'undefined'
  431. ? window
  432. : typeof global !== 'undefined'
  433. ? global
  434. : {}));
  435. };
  436. function warn$1(msg, ...args) {
  437. console.warn(`[Vue warn] ${msg}`, ...args);
  438. }
  439. let activeEffectScope;
  440. class EffectScope {
  441. constructor(detached = false) {
  442. this.detached = detached;
  443. /**
  444. * @internal
  445. */
  446. this._active = true;
  447. /**
  448. * @internal
  449. */
  450. this.effects = [];
  451. /**
  452. * @internal
  453. */
  454. this.cleanups = [];
  455. this.parent = activeEffectScope;
  456. if (!detached && activeEffectScope) {
  457. this.index =
  458. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  459. }
  460. }
  461. get active() {
  462. return this._active;
  463. }
  464. run(fn) {
  465. if (this._active) {
  466. const currentEffectScope = activeEffectScope;
  467. try {
  468. activeEffectScope = this;
  469. return fn();
  470. }
  471. finally {
  472. activeEffectScope = currentEffectScope;
  473. }
  474. }
  475. else {
  476. warn$1(`cannot run an inactive effect scope.`);
  477. }
  478. }
  479. /**
  480. * This should only be called on non-detached scopes
  481. * @internal
  482. */
  483. on() {
  484. activeEffectScope = this;
  485. }
  486. /**
  487. * This should only be called on non-detached scopes
  488. * @internal
  489. */
  490. off() {
  491. activeEffectScope = this.parent;
  492. }
  493. stop(fromParent) {
  494. if (this._active) {
  495. let i, l;
  496. for (i = 0, l = this.effects.length; i < l; i++) {
  497. this.effects[i].stop();
  498. }
  499. for (i = 0, l = this.cleanups.length; i < l; i++) {
  500. this.cleanups[i]();
  501. }
  502. if (this.scopes) {
  503. for (i = 0, l = this.scopes.length; i < l; i++) {
  504. this.scopes[i].stop(true);
  505. }
  506. }
  507. // nested scope, dereference from parent to avoid memory leaks
  508. if (!this.detached && this.parent && !fromParent) {
  509. // optimized O(1) removal
  510. const last = this.parent.scopes.pop();
  511. if (last && last !== this) {
  512. this.parent.scopes[this.index] = last;
  513. last.index = this.index;
  514. }
  515. }
  516. this.parent = undefined;
  517. this._active = false;
  518. }
  519. }
  520. }
  521. function effectScope(detached) {
  522. return new EffectScope(detached);
  523. }
  524. function recordEffectScope(effect, scope = activeEffectScope) {
  525. if (scope && scope.active) {
  526. scope.effects.push(effect);
  527. }
  528. }
  529. function getCurrentScope() {
  530. return activeEffectScope;
  531. }
  532. function onScopeDispose(fn) {
  533. if (activeEffectScope) {
  534. activeEffectScope.cleanups.push(fn);
  535. }
  536. else {
  537. warn$1(`onScopeDispose() is called when there is no active effect scope` +
  538. ` to be associated with.`);
  539. }
  540. }
  541. const createDep = (effects) => {
  542. const dep = new Set(effects);
  543. dep.w = 0;
  544. dep.n = 0;
  545. return dep;
  546. };
  547. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  548. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  549. const initDepMarkers = ({ deps }) => {
  550. if (deps.length) {
  551. for (let i = 0; i < deps.length; i++) {
  552. deps[i].w |= trackOpBit; // set was tracked
  553. }
  554. }
  555. };
  556. const finalizeDepMarkers = (effect) => {
  557. const { deps } = effect;
  558. if (deps.length) {
  559. let ptr = 0;
  560. for (let i = 0; i < deps.length; i++) {
  561. const dep = deps[i];
  562. if (wasTracked(dep) && !newTracked(dep)) {
  563. dep.delete(effect);
  564. }
  565. else {
  566. deps[ptr++] = dep;
  567. }
  568. // clear bits
  569. dep.w &= ~trackOpBit;
  570. dep.n &= ~trackOpBit;
  571. }
  572. deps.length = ptr;
  573. }
  574. };
  575. const targetMap = new WeakMap();
  576. // The number of effects currently being tracked recursively.
  577. let effectTrackDepth = 0;
  578. let trackOpBit = 1;
  579. /**
  580. * The bitwise track markers support at most 30 levels of recursion.
  581. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  582. * When recursion depth is greater, fall back to using a full cleanup.
  583. */
  584. const maxMarkerBits = 30;
  585. let activeEffect;
  586. const ITERATE_KEY = Symbol('iterate' );
  587. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  588. class ReactiveEffect {
  589. constructor(fn, scheduler = null, scope) {
  590. this.fn = fn;
  591. this.scheduler = scheduler;
  592. this.active = true;
  593. this.deps = [];
  594. this.parent = undefined;
  595. recordEffectScope(this, scope);
  596. }
  597. run() {
  598. if (!this.active) {
  599. return this.fn();
  600. }
  601. let parent = activeEffect;
  602. let lastShouldTrack = shouldTrack;
  603. while (parent) {
  604. if (parent === this) {
  605. return;
  606. }
  607. parent = parent.parent;
  608. }
  609. try {
  610. this.parent = activeEffect;
  611. activeEffect = this;
  612. shouldTrack = true;
  613. trackOpBit = 1 << ++effectTrackDepth;
  614. if (effectTrackDepth <= maxMarkerBits) {
  615. initDepMarkers(this);
  616. }
  617. else {
  618. cleanupEffect(this);
  619. }
  620. return this.fn();
  621. }
  622. finally {
  623. if (effectTrackDepth <= maxMarkerBits) {
  624. finalizeDepMarkers(this);
  625. }
  626. trackOpBit = 1 << --effectTrackDepth;
  627. activeEffect = this.parent;
  628. shouldTrack = lastShouldTrack;
  629. this.parent = undefined;
  630. if (this.deferStop) {
  631. this.stop();
  632. }
  633. }
  634. }
  635. stop() {
  636. // stopped while running itself - defer the cleanup
  637. if (activeEffect === this) {
  638. this.deferStop = true;
  639. }
  640. else if (this.active) {
  641. cleanupEffect(this);
  642. if (this.onStop) {
  643. this.onStop();
  644. }
  645. this.active = false;
  646. }
  647. }
  648. }
  649. function cleanupEffect(effect) {
  650. const { deps } = effect;
  651. if (deps.length) {
  652. for (let i = 0; i < deps.length; i++) {
  653. deps[i].delete(effect);
  654. }
  655. deps.length = 0;
  656. }
  657. }
  658. function effect(fn, options) {
  659. if (fn.effect) {
  660. fn = fn.effect.fn;
  661. }
  662. const _effect = new ReactiveEffect(fn);
  663. if (options) {
  664. extend(_effect, options);
  665. if (options.scope)
  666. recordEffectScope(_effect, options.scope);
  667. }
  668. if (!options || !options.lazy) {
  669. _effect.run();
  670. }
  671. const runner = _effect.run.bind(_effect);
  672. runner.effect = _effect;
  673. return runner;
  674. }
  675. function stop(runner) {
  676. runner.effect.stop();
  677. }
  678. let shouldTrack = true;
  679. const trackStack = [];
  680. function pauseTracking() {
  681. trackStack.push(shouldTrack);
  682. shouldTrack = false;
  683. }
  684. function resetTracking() {
  685. const last = trackStack.pop();
  686. shouldTrack = last === undefined ? true : last;
  687. }
  688. function track(target, type, key) {
  689. if (shouldTrack && activeEffect) {
  690. let depsMap = targetMap.get(target);
  691. if (!depsMap) {
  692. targetMap.set(target, (depsMap = new Map()));
  693. }
  694. let dep = depsMap.get(key);
  695. if (!dep) {
  696. depsMap.set(key, (dep = createDep()));
  697. }
  698. const eventInfo = { effect: activeEffect, target, type, key }
  699. ;
  700. trackEffects(dep, eventInfo);
  701. }
  702. }
  703. function trackEffects(dep, debuggerEventExtraInfo) {
  704. let shouldTrack = false;
  705. if (effectTrackDepth <= maxMarkerBits) {
  706. if (!newTracked(dep)) {
  707. dep.n |= trackOpBit; // set newly tracked
  708. shouldTrack = !wasTracked(dep);
  709. }
  710. }
  711. else {
  712. // Full cleanup mode.
  713. shouldTrack = !dep.has(activeEffect);
  714. }
  715. if (shouldTrack) {
  716. dep.add(activeEffect);
  717. activeEffect.deps.push(dep);
  718. if (activeEffect.onTrack) {
  719. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  720. }
  721. }
  722. }
  723. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  724. const depsMap = targetMap.get(target);
  725. if (!depsMap) {
  726. // never been tracked
  727. return;
  728. }
  729. let deps = [];
  730. if (type === "clear" /* TriggerOpTypes.CLEAR */) {
  731. // collection being cleared
  732. // trigger all effects for target
  733. deps = [...depsMap.values()];
  734. }
  735. else if (key === 'length' && isArray(target)) {
  736. const newLength = Number(newValue);
  737. depsMap.forEach((dep, key) => {
  738. if (key === 'length' || key >= newLength) {
  739. deps.push(dep);
  740. }
  741. });
  742. }
  743. else {
  744. // schedule runs for SET | ADD | DELETE
  745. if (key !== void 0) {
  746. deps.push(depsMap.get(key));
  747. }
  748. // also run for iteration key on ADD | DELETE | Map.SET
  749. switch (type) {
  750. case "add" /* TriggerOpTypes.ADD */:
  751. if (!isArray(target)) {
  752. deps.push(depsMap.get(ITERATE_KEY));
  753. if (isMap(target)) {
  754. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  755. }
  756. }
  757. else if (isIntegerKey(key)) {
  758. // new index added to array -> length changes
  759. deps.push(depsMap.get('length'));
  760. }
  761. break;
  762. case "delete" /* TriggerOpTypes.DELETE */:
  763. if (!isArray(target)) {
  764. deps.push(depsMap.get(ITERATE_KEY));
  765. if (isMap(target)) {
  766. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  767. }
  768. }
  769. break;
  770. case "set" /* TriggerOpTypes.SET */:
  771. if (isMap(target)) {
  772. deps.push(depsMap.get(ITERATE_KEY));
  773. }
  774. break;
  775. }
  776. }
  777. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  778. ;
  779. if (deps.length === 1) {
  780. if (deps[0]) {
  781. {
  782. triggerEffects(deps[0], eventInfo);
  783. }
  784. }
  785. }
  786. else {
  787. const effects = [];
  788. for (const dep of deps) {
  789. if (dep) {
  790. effects.push(...dep);
  791. }
  792. }
  793. {
  794. triggerEffects(createDep(effects), eventInfo);
  795. }
  796. }
  797. }
  798. function triggerEffects(dep, debuggerEventExtraInfo) {
  799. // spread into array for stabilization
  800. const effects = isArray(dep) ? dep : [...dep];
  801. for (const effect of effects) {
  802. if (effect.computed) {
  803. triggerEffect(effect, debuggerEventExtraInfo);
  804. }
  805. }
  806. for (const effect of effects) {
  807. if (!effect.computed) {
  808. triggerEffect(effect, debuggerEventExtraInfo);
  809. }
  810. }
  811. }
  812. function triggerEffect(effect, debuggerEventExtraInfo) {
  813. if (effect !== activeEffect || effect.allowRecurse) {
  814. if (effect.onTrigger) {
  815. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  816. }
  817. if (effect.scheduler) {
  818. effect.scheduler();
  819. }
  820. else {
  821. effect.run();
  822. }
  823. }
  824. }
  825. function getDepFromReactive(object, key) {
  826. var _a;
  827. return (_a = targetMap.get(object)) === null || _a === void 0 ? void 0 : _a.get(key);
  828. }
  829. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  830. const builtInSymbols = new Set(
  831. /*#__PURE__*/
  832. Object.getOwnPropertyNames(Symbol)
  833. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  834. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  835. // function
  836. .filter(key => key !== 'arguments' && key !== 'caller')
  837. .map(key => Symbol[key])
  838. .filter(isSymbol));
  839. const get$1 = /*#__PURE__*/ createGetter();
  840. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  841. const readonlyGet = /*#__PURE__*/ createGetter(true);
  842. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  843. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  844. function createArrayInstrumentations() {
  845. const instrumentations = {};
  846. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  847. instrumentations[key] = function (...args) {
  848. const arr = toRaw(this);
  849. for (let i = 0, l = this.length; i < l; i++) {
  850. track(arr, "get" /* TrackOpTypes.GET */, i + '');
  851. }
  852. // we run the method using the original args first (which may be reactive)
  853. const res = arr[key](...args);
  854. if (res === -1 || res === false) {
  855. // if that didn't work, run it again using raw values.
  856. return arr[key](...args.map(toRaw));
  857. }
  858. else {
  859. return res;
  860. }
  861. };
  862. });
  863. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  864. instrumentations[key] = function (...args) {
  865. pauseTracking();
  866. const res = toRaw(this)[key].apply(this, args);
  867. resetTracking();
  868. return res;
  869. };
  870. });
  871. return instrumentations;
  872. }
  873. function hasOwnProperty(key) {
  874. const obj = toRaw(this);
  875. track(obj, "has" /* TrackOpTypes.HAS */, key);
  876. return obj.hasOwnProperty(key);
  877. }
  878. function createGetter(isReadonly = false, shallow = false) {
  879. return function get(target, key, receiver) {
  880. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  881. return !isReadonly;
  882. }
  883. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  884. return isReadonly;
  885. }
  886. else if (key === "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */) {
  887. return shallow;
  888. }
  889. else if (key === "__v_raw" /* ReactiveFlags.RAW */ &&
  890. receiver ===
  891. (isReadonly
  892. ? shallow
  893. ? shallowReadonlyMap
  894. : readonlyMap
  895. : shallow
  896. ? shallowReactiveMap
  897. : reactiveMap).get(target)) {
  898. return target;
  899. }
  900. const targetIsArray = isArray(target);
  901. if (!isReadonly) {
  902. if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
  903. return Reflect.get(arrayInstrumentations, key, receiver);
  904. }
  905. if (key === 'hasOwnProperty') {
  906. return hasOwnProperty;
  907. }
  908. }
  909. const res = Reflect.get(target, key, receiver);
  910. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  911. return res;
  912. }
  913. if (!isReadonly) {
  914. track(target, "get" /* TrackOpTypes.GET */, key);
  915. }
  916. if (shallow) {
  917. return res;
  918. }
  919. if (isRef(res)) {
  920. // ref unwrapping - skip unwrap for Array + integer key.
  921. return targetIsArray && isIntegerKey(key) ? res : res.value;
  922. }
  923. if (isObject(res)) {
  924. // Convert returned value into a proxy as well. we do the isObject check
  925. // here to avoid invalid value warning. Also need to lazy access readonly
  926. // and reactive here to avoid circular dependency.
  927. return isReadonly ? readonly(res) : reactive(res);
  928. }
  929. return res;
  930. };
  931. }
  932. const set$1 = /*#__PURE__*/ createSetter();
  933. const shallowSet = /*#__PURE__*/ createSetter(true);
  934. function createSetter(shallow = false) {
  935. return function set(target, key, value, receiver) {
  936. let oldValue = target[key];
  937. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  938. return false;
  939. }
  940. if (!shallow) {
  941. if (!isShallow(value) && !isReadonly(value)) {
  942. oldValue = toRaw(oldValue);
  943. value = toRaw(value);
  944. }
  945. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  946. oldValue.value = value;
  947. return true;
  948. }
  949. }
  950. const hadKey = isArray(target) && isIntegerKey(key)
  951. ? Number(key) < target.length
  952. : hasOwn(target, key);
  953. const result = Reflect.set(target, key, value, receiver);
  954. // don't trigger if target is something up in the prototype chain of original
  955. if (target === toRaw(receiver)) {
  956. if (!hadKey) {
  957. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  958. }
  959. else if (hasChanged(value, oldValue)) {
  960. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  961. }
  962. }
  963. return result;
  964. };
  965. }
  966. function deleteProperty(target, key) {
  967. const hadKey = hasOwn(target, key);
  968. const oldValue = target[key];
  969. const result = Reflect.deleteProperty(target, key);
  970. if (result && hadKey) {
  971. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  972. }
  973. return result;
  974. }
  975. function has$1(target, key) {
  976. const result = Reflect.has(target, key);
  977. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  978. track(target, "has" /* TrackOpTypes.HAS */, key);
  979. }
  980. return result;
  981. }
  982. function ownKeys(target) {
  983. track(target, "iterate" /* TrackOpTypes.ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  984. return Reflect.ownKeys(target);
  985. }
  986. const mutableHandlers = {
  987. get: get$1,
  988. set: set$1,
  989. deleteProperty,
  990. has: has$1,
  991. ownKeys
  992. };
  993. const readonlyHandlers = {
  994. get: readonlyGet,
  995. set(target, key) {
  996. {
  997. warn$1(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  998. }
  999. return true;
  1000. },
  1001. deleteProperty(target, key) {
  1002. {
  1003. warn$1(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  1004. }
  1005. return true;
  1006. }
  1007. };
  1008. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  1009. get: shallowGet,
  1010. set: shallowSet
  1011. });
  1012. // Props handlers are special in the sense that it should not unwrap top-level
  1013. // refs (in order to allow refs to be explicitly passed down), but should
  1014. // retain the reactivity of the normal readonly object.
  1015. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  1016. get: shallowReadonlyGet
  1017. });
  1018. const toShallow = (value) => value;
  1019. const getProto = (v) => Reflect.getPrototypeOf(v);
  1020. function get(target, key, isReadonly = false, isShallow = false) {
  1021. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  1022. // of the value
  1023. target = target["__v_raw" /* ReactiveFlags.RAW */];
  1024. const rawTarget = toRaw(target);
  1025. const rawKey = toRaw(key);
  1026. if (!isReadonly) {
  1027. if (key !== rawKey) {
  1028. track(rawTarget, "get" /* TrackOpTypes.GET */, key);
  1029. }
  1030. track(rawTarget, "get" /* TrackOpTypes.GET */, rawKey);
  1031. }
  1032. const { has } = getProto(rawTarget);
  1033. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1034. if (has.call(rawTarget, key)) {
  1035. return wrap(target.get(key));
  1036. }
  1037. else if (has.call(rawTarget, rawKey)) {
  1038. return wrap(target.get(rawKey));
  1039. }
  1040. else if (target !== rawTarget) {
  1041. // #3602 readonly(reactive(Map))
  1042. // ensure that the nested reactive `Map` can do tracking for itself
  1043. target.get(key);
  1044. }
  1045. }
  1046. function has(key, isReadonly = false) {
  1047. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  1048. const rawTarget = toRaw(target);
  1049. const rawKey = toRaw(key);
  1050. if (!isReadonly) {
  1051. if (key !== rawKey) {
  1052. track(rawTarget, "has" /* TrackOpTypes.HAS */, key);
  1053. }
  1054. track(rawTarget, "has" /* TrackOpTypes.HAS */, rawKey);
  1055. }
  1056. return key === rawKey
  1057. ? target.has(key)
  1058. : target.has(key) || target.has(rawKey);
  1059. }
  1060. function size(target, isReadonly = false) {
  1061. target = target["__v_raw" /* ReactiveFlags.RAW */];
  1062. !isReadonly && track(toRaw(target), "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  1063. return Reflect.get(target, 'size', target);
  1064. }
  1065. function add(value) {
  1066. value = toRaw(value);
  1067. const target = toRaw(this);
  1068. const proto = getProto(target);
  1069. const hadKey = proto.has.call(target, value);
  1070. if (!hadKey) {
  1071. target.add(value);
  1072. trigger(target, "add" /* TriggerOpTypes.ADD */, value, value);
  1073. }
  1074. return this;
  1075. }
  1076. function set(key, value) {
  1077. value = toRaw(value);
  1078. const target = toRaw(this);
  1079. const { has, get } = getProto(target);
  1080. let hadKey = has.call(target, key);
  1081. if (!hadKey) {
  1082. key = toRaw(key);
  1083. hadKey = has.call(target, key);
  1084. }
  1085. else {
  1086. checkIdentityKeys(target, has, key);
  1087. }
  1088. const oldValue = get.call(target, key);
  1089. target.set(key, value);
  1090. if (!hadKey) {
  1091. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  1092. }
  1093. else if (hasChanged(value, oldValue)) {
  1094. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  1095. }
  1096. return this;
  1097. }
  1098. function deleteEntry(key) {
  1099. const target = toRaw(this);
  1100. const { has, get } = getProto(target);
  1101. let hadKey = has.call(target, key);
  1102. if (!hadKey) {
  1103. key = toRaw(key);
  1104. hadKey = has.call(target, key);
  1105. }
  1106. else {
  1107. checkIdentityKeys(target, has, key);
  1108. }
  1109. const oldValue = get ? get.call(target, key) : undefined;
  1110. // forward the operation before queueing reactions
  1111. const result = target.delete(key);
  1112. if (hadKey) {
  1113. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  1114. }
  1115. return result;
  1116. }
  1117. function clear() {
  1118. const target = toRaw(this);
  1119. const hadItems = target.size !== 0;
  1120. const oldTarget = isMap(target)
  1121. ? new Map(target)
  1122. : new Set(target)
  1123. ;
  1124. // forward the operation before queueing reactions
  1125. const result = target.clear();
  1126. if (hadItems) {
  1127. trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
  1128. }
  1129. return result;
  1130. }
  1131. function createForEach(isReadonly, isShallow) {
  1132. return function forEach(callback, thisArg) {
  1133. const observed = this;
  1134. const target = observed["__v_raw" /* ReactiveFlags.RAW */];
  1135. const rawTarget = toRaw(target);
  1136. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1137. !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  1138. return target.forEach((value, key) => {
  1139. // important: make sure the callback is
  1140. // 1. invoked with the reactive map as `this` and 3rd arg
  1141. // 2. the value received should be a corresponding reactive/readonly.
  1142. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1143. });
  1144. };
  1145. }
  1146. function createIterableMethod(method, isReadonly, isShallow) {
  1147. return function (...args) {
  1148. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  1149. const rawTarget = toRaw(target);
  1150. const targetIsMap = isMap(rawTarget);
  1151. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1152. const isKeyOnly = method === 'keys' && targetIsMap;
  1153. const innerIterator = target[method](...args);
  1154. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1155. !isReadonly &&
  1156. track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1157. // return a wrapped iterator which returns observed versions of the
  1158. // values emitted from the real iterator
  1159. return {
  1160. // iterator protocol
  1161. next() {
  1162. const { value, done } = innerIterator.next();
  1163. return done
  1164. ? { value, done }
  1165. : {
  1166. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1167. done
  1168. };
  1169. },
  1170. // iterable protocol
  1171. [Symbol.iterator]() {
  1172. return this;
  1173. }
  1174. };
  1175. };
  1176. }
  1177. function createReadonlyMethod(type) {
  1178. return function (...args) {
  1179. {
  1180. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1181. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1182. }
  1183. return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
  1184. };
  1185. }
  1186. function createInstrumentations() {
  1187. const mutableInstrumentations = {
  1188. get(key) {
  1189. return get(this, key);
  1190. },
  1191. get size() {
  1192. return size(this);
  1193. },
  1194. has,
  1195. add,
  1196. set,
  1197. delete: deleteEntry,
  1198. clear,
  1199. forEach: createForEach(false, false)
  1200. };
  1201. const shallowInstrumentations = {
  1202. get(key) {
  1203. return get(this, key, false, true);
  1204. },
  1205. get size() {
  1206. return size(this);
  1207. },
  1208. has,
  1209. add,
  1210. set,
  1211. delete: deleteEntry,
  1212. clear,
  1213. forEach: createForEach(false, true)
  1214. };
  1215. const readonlyInstrumentations = {
  1216. get(key) {
  1217. return get(this, key, true);
  1218. },
  1219. get size() {
  1220. return size(this, true);
  1221. },
  1222. has(key) {
  1223. return has.call(this, key, true);
  1224. },
  1225. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  1226. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  1227. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  1228. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  1229. forEach: createForEach(true, false)
  1230. };
  1231. const shallowReadonlyInstrumentations = {
  1232. get(key) {
  1233. return get(this, key, true, true);
  1234. },
  1235. get size() {
  1236. return size(this, true);
  1237. },
  1238. has(key) {
  1239. return has.call(this, key, true);
  1240. },
  1241. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  1242. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  1243. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  1244. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  1245. forEach: createForEach(true, true)
  1246. };
  1247. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1248. iteratorMethods.forEach(method => {
  1249. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1250. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1251. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1252. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1253. });
  1254. return [
  1255. mutableInstrumentations,
  1256. readonlyInstrumentations,
  1257. shallowInstrumentations,
  1258. shallowReadonlyInstrumentations
  1259. ];
  1260. }
  1261. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1262. function createInstrumentationGetter(isReadonly, shallow) {
  1263. const instrumentations = shallow
  1264. ? isReadonly
  1265. ? shallowReadonlyInstrumentations
  1266. : shallowInstrumentations
  1267. : isReadonly
  1268. ? readonlyInstrumentations
  1269. : mutableInstrumentations;
  1270. return (target, key, receiver) => {
  1271. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  1272. return !isReadonly;
  1273. }
  1274. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  1275. return isReadonly;
  1276. }
  1277. else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
  1278. return target;
  1279. }
  1280. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1281. ? instrumentations
  1282. : target, key, receiver);
  1283. };
  1284. }
  1285. const mutableCollectionHandlers = {
  1286. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1287. };
  1288. const shallowCollectionHandlers = {
  1289. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1290. };
  1291. const readonlyCollectionHandlers = {
  1292. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1293. };
  1294. const shallowReadonlyCollectionHandlers = {
  1295. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1296. };
  1297. function checkIdentityKeys(target, has, key) {
  1298. const rawKey = toRaw(key);
  1299. if (rawKey !== key && has.call(target, rawKey)) {
  1300. const type = toRawType(target);
  1301. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1302. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1303. `which can lead to inconsistencies. ` +
  1304. `Avoid differentiating between the raw and reactive versions ` +
  1305. `of an object and only use the reactive version if possible.`);
  1306. }
  1307. }
  1308. const reactiveMap = new WeakMap();
  1309. const shallowReactiveMap = new WeakMap();
  1310. const readonlyMap = new WeakMap();
  1311. const shallowReadonlyMap = new WeakMap();
  1312. function targetTypeMap(rawType) {
  1313. switch (rawType) {
  1314. case 'Object':
  1315. case 'Array':
  1316. return 1 /* TargetType.COMMON */;
  1317. case 'Map':
  1318. case 'Set':
  1319. case 'WeakMap':
  1320. case 'WeakSet':
  1321. return 2 /* TargetType.COLLECTION */;
  1322. default:
  1323. return 0 /* TargetType.INVALID */;
  1324. }
  1325. }
  1326. function getTargetType(value) {
  1327. return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
  1328. ? 0 /* TargetType.INVALID */
  1329. : targetTypeMap(toRawType(value));
  1330. }
  1331. function reactive(target) {
  1332. // if trying to observe a readonly proxy, return the readonly version.
  1333. if (isReadonly(target)) {
  1334. return target;
  1335. }
  1336. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1337. }
  1338. /**
  1339. * Return a shallowly-reactive copy of the original object, where only the root
  1340. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1341. * root level).
  1342. */
  1343. function shallowReactive(target) {
  1344. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1345. }
  1346. /**
  1347. * Creates a readonly copy of the original object. Note the returned copy is not
  1348. * made reactive, but `readonly` can be called on an already reactive object.
  1349. */
  1350. function readonly(target) {
  1351. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1352. }
  1353. /**
  1354. * Returns a reactive-copy of the original object, where only the root level
  1355. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1356. * returned properties.
  1357. * This is used for creating the props proxy object for stateful components.
  1358. */
  1359. function shallowReadonly(target) {
  1360. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1361. }
  1362. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1363. if (!isObject(target)) {
  1364. {
  1365. console.warn(`value cannot be made reactive: ${String(target)}`);
  1366. }
  1367. return target;
  1368. }
  1369. // target is already a Proxy, return it.
  1370. // exception: calling readonly() on a reactive object
  1371. if (target["__v_raw" /* ReactiveFlags.RAW */] &&
  1372. !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
  1373. return target;
  1374. }
  1375. // target already has corresponding Proxy
  1376. const existingProxy = proxyMap.get(target);
  1377. if (existingProxy) {
  1378. return existingProxy;
  1379. }
  1380. // only specific value types can be observed.
  1381. const targetType = getTargetType(target);
  1382. if (targetType === 0 /* TargetType.INVALID */) {
  1383. return target;
  1384. }
  1385. const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
  1386. proxyMap.set(target, proxy);
  1387. return proxy;
  1388. }
  1389. function isReactive(value) {
  1390. if (isReadonly(value)) {
  1391. return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
  1392. }
  1393. return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
  1394. }
  1395. function isReadonly(value) {
  1396. return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
  1397. }
  1398. function isShallow(value) {
  1399. return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
  1400. }
  1401. function isProxy(value) {
  1402. return isReactive(value) || isReadonly(value);
  1403. }
  1404. function toRaw(observed) {
  1405. const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
  1406. return raw ? toRaw(raw) : observed;
  1407. }
  1408. function markRaw(value) {
  1409. def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
  1410. return value;
  1411. }
  1412. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1413. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1414. function trackRefValue(ref) {
  1415. if (shouldTrack && activeEffect) {
  1416. ref = toRaw(ref);
  1417. {
  1418. trackEffects(ref.dep || (ref.dep = createDep()), {
  1419. target: ref,
  1420. type: "get" /* TrackOpTypes.GET */,
  1421. key: 'value'
  1422. });
  1423. }
  1424. }
  1425. }
  1426. function triggerRefValue(ref, newVal) {
  1427. ref = toRaw(ref);
  1428. const dep = ref.dep;
  1429. if (dep) {
  1430. {
  1431. triggerEffects(dep, {
  1432. target: ref,
  1433. type: "set" /* TriggerOpTypes.SET */,
  1434. key: 'value',
  1435. newValue: newVal
  1436. });
  1437. }
  1438. }
  1439. }
  1440. function isRef(r) {
  1441. return !!(r && r.__v_isRef === true);
  1442. }
  1443. function ref(value) {
  1444. return createRef(value, false);
  1445. }
  1446. function shallowRef(value) {
  1447. return createRef(value, true);
  1448. }
  1449. function createRef(rawValue, shallow) {
  1450. if (isRef(rawValue)) {
  1451. return rawValue;
  1452. }
  1453. return new RefImpl(rawValue, shallow);
  1454. }
  1455. class RefImpl {
  1456. constructor(value, __v_isShallow) {
  1457. this.__v_isShallow = __v_isShallow;
  1458. this.dep = undefined;
  1459. this.__v_isRef = true;
  1460. this._rawValue = __v_isShallow ? value : toRaw(value);
  1461. this._value = __v_isShallow ? value : toReactive(value);
  1462. }
  1463. get value() {
  1464. trackRefValue(this);
  1465. return this._value;
  1466. }
  1467. set value(newVal) {
  1468. const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
  1469. newVal = useDirectValue ? newVal : toRaw(newVal);
  1470. if (hasChanged(newVal, this._rawValue)) {
  1471. this._rawValue = newVal;
  1472. this._value = useDirectValue ? newVal : toReactive(newVal);
  1473. triggerRefValue(this, newVal);
  1474. }
  1475. }
  1476. }
  1477. function triggerRef(ref) {
  1478. triggerRefValue(ref, ref.value );
  1479. }
  1480. function unref(ref) {
  1481. return isRef(ref) ? ref.value : ref;
  1482. }
  1483. const shallowUnwrapHandlers = {
  1484. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1485. set: (target, key, value, receiver) => {
  1486. const oldValue = target[key];
  1487. if (isRef(oldValue) && !isRef(value)) {
  1488. oldValue.value = value;
  1489. return true;
  1490. }
  1491. else {
  1492. return Reflect.set(target, key, value, receiver);
  1493. }
  1494. }
  1495. };
  1496. function proxyRefs(objectWithRefs) {
  1497. return isReactive(objectWithRefs)
  1498. ? objectWithRefs
  1499. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1500. }
  1501. class CustomRefImpl {
  1502. constructor(factory) {
  1503. this.dep = undefined;
  1504. this.__v_isRef = true;
  1505. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1506. this._get = get;
  1507. this._set = set;
  1508. }
  1509. get value() {
  1510. return this._get();
  1511. }
  1512. set value(newVal) {
  1513. this._set(newVal);
  1514. }
  1515. }
  1516. function customRef(factory) {
  1517. return new CustomRefImpl(factory);
  1518. }
  1519. function toRefs(object) {
  1520. if (!isProxy(object)) {
  1521. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1522. }
  1523. const ret = isArray(object) ? new Array(object.length) : {};
  1524. for (const key in object) {
  1525. ret[key] = toRef(object, key);
  1526. }
  1527. return ret;
  1528. }
  1529. class ObjectRefImpl {
  1530. constructor(_object, _key, _defaultValue) {
  1531. this._object = _object;
  1532. this._key = _key;
  1533. this._defaultValue = _defaultValue;
  1534. this.__v_isRef = true;
  1535. }
  1536. get value() {
  1537. const val = this._object[this._key];
  1538. return val === undefined ? this._defaultValue : val;
  1539. }
  1540. set value(newVal) {
  1541. this._object[this._key] = newVal;
  1542. }
  1543. get dep() {
  1544. return getDepFromReactive(toRaw(this._object), this._key);
  1545. }
  1546. }
  1547. function toRef(object, key, defaultValue) {
  1548. const val = object[key];
  1549. return isRef(val)
  1550. ? val
  1551. : new ObjectRefImpl(object, key, defaultValue);
  1552. }
  1553. var _a;
  1554. class ComputedRefImpl {
  1555. constructor(getter, _setter, isReadonly, isSSR) {
  1556. this._setter = _setter;
  1557. this.dep = undefined;
  1558. this.__v_isRef = true;
  1559. this[_a] = false;
  1560. this._dirty = true;
  1561. this.effect = new ReactiveEffect(getter, () => {
  1562. if (!this._dirty) {
  1563. this._dirty = true;
  1564. triggerRefValue(this);
  1565. }
  1566. });
  1567. this.effect.computed = this;
  1568. this.effect.active = this._cacheable = !isSSR;
  1569. this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
  1570. }
  1571. get value() {
  1572. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1573. const self = toRaw(this);
  1574. trackRefValue(self);
  1575. if (self._dirty || !self._cacheable) {
  1576. self._dirty = false;
  1577. self._value = self.effect.run();
  1578. }
  1579. return self._value;
  1580. }
  1581. set value(newValue) {
  1582. this._setter(newValue);
  1583. }
  1584. }
  1585. _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
  1586. function computed$1(getterOrOptions, debugOptions, isSSR = false) {
  1587. let getter;
  1588. let setter;
  1589. const onlyGetter = isFunction(getterOrOptions);
  1590. if (onlyGetter) {
  1591. getter = getterOrOptions;
  1592. setter = () => {
  1593. console.warn('Write operation failed: computed value is readonly');
  1594. }
  1595. ;
  1596. }
  1597. else {
  1598. getter = getterOrOptions.get;
  1599. setter = getterOrOptions.set;
  1600. }
  1601. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1602. if (debugOptions && !isSSR) {
  1603. cRef.effect.onTrack = debugOptions.onTrack;
  1604. cRef.effect.onTrigger = debugOptions.onTrigger;
  1605. }
  1606. return cRef;
  1607. }
  1608. const stack = [];
  1609. function pushWarningContext(vnode) {
  1610. stack.push(vnode);
  1611. }
  1612. function popWarningContext() {
  1613. stack.pop();
  1614. }
  1615. function warn(msg, ...args) {
  1616. // avoid props formatting or warn handler tracking deps that might be mutated
  1617. // during patch, leading to infinite recursion.
  1618. pauseTracking();
  1619. const instance = stack.length ? stack[stack.length - 1].component : null;
  1620. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1621. const trace = getComponentTrace();
  1622. if (appWarnHandler) {
  1623. callWithErrorHandling(appWarnHandler, instance, 11 /* ErrorCodes.APP_WARN_HANDLER */, [
  1624. msg + args.join(''),
  1625. instance && instance.proxy,
  1626. trace
  1627. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1628. .join('\n'),
  1629. trace
  1630. ]);
  1631. }
  1632. else {
  1633. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1634. /* istanbul ignore if */
  1635. if (trace.length &&
  1636. // avoid spamming console during tests
  1637. !false) {
  1638. warnArgs.push(`\n`, ...formatTrace(trace));
  1639. }
  1640. console.warn(...warnArgs);
  1641. }
  1642. resetTracking();
  1643. }
  1644. function getComponentTrace() {
  1645. let currentVNode = stack[stack.length - 1];
  1646. if (!currentVNode) {
  1647. return [];
  1648. }
  1649. // we can't just use the stack because it will be incomplete during updates
  1650. // that did not start from the root. Re-construct the parent chain using
  1651. // instance parent pointers.
  1652. const normalizedStack = [];
  1653. while (currentVNode) {
  1654. const last = normalizedStack[0];
  1655. if (last && last.vnode === currentVNode) {
  1656. last.recurseCount++;
  1657. }
  1658. else {
  1659. normalizedStack.push({
  1660. vnode: currentVNode,
  1661. recurseCount: 0
  1662. });
  1663. }
  1664. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1665. currentVNode = parentInstance && parentInstance.vnode;
  1666. }
  1667. return normalizedStack;
  1668. }
  1669. /* istanbul ignore next */
  1670. function formatTrace(trace) {
  1671. const logs = [];
  1672. trace.forEach((entry, i) => {
  1673. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1674. });
  1675. return logs;
  1676. }
  1677. function formatTraceEntry({ vnode, recurseCount }) {
  1678. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1679. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1680. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1681. const close = `>` + postfix;
  1682. return vnode.props
  1683. ? [open, ...formatProps(vnode.props), close]
  1684. : [open + close];
  1685. }
  1686. /* istanbul ignore next */
  1687. function formatProps(props) {
  1688. const res = [];
  1689. const keys = Object.keys(props);
  1690. keys.slice(0, 3).forEach(key => {
  1691. res.push(...formatProp(key, props[key]));
  1692. });
  1693. if (keys.length > 3) {
  1694. res.push(` ...`);
  1695. }
  1696. return res;
  1697. }
  1698. /* istanbul ignore next */
  1699. function formatProp(key, value, raw) {
  1700. if (isString(value)) {
  1701. value = JSON.stringify(value);
  1702. return raw ? value : [`${key}=${value}`];
  1703. }
  1704. else if (typeof value === 'number' ||
  1705. typeof value === 'boolean' ||
  1706. value == null) {
  1707. return raw ? value : [`${key}=${value}`];
  1708. }
  1709. else if (isRef(value)) {
  1710. value = formatProp(key, toRaw(value.value), true);
  1711. return raw ? value : [`${key}=Ref<`, value, `>`];
  1712. }
  1713. else if (isFunction(value)) {
  1714. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1715. }
  1716. else {
  1717. value = toRaw(value);
  1718. return raw ? value : [`${key}=`, value];
  1719. }
  1720. }
  1721. /**
  1722. * @internal
  1723. */
  1724. function assertNumber(val, type) {
  1725. if (val === undefined) {
  1726. return;
  1727. }
  1728. else if (typeof val !== 'number') {
  1729. warn(`${type} is not a valid number - ` + `got ${JSON.stringify(val)}.`);
  1730. }
  1731. else if (isNaN(val)) {
  1732. warn(`${type} is NaN - ` + 'the duration expression might be incorrect.');
  1733. }
  1734. }
  1735. const ErrorTypeStrings = {
  1736. ["sp" /* LifecycleHooks.SERVER_PREFETCH */]: 'serverPrefetch hook',
  1737. ["bc" /* LifecycleHooks.BEFORE_CREATE */]: 'beforeCreate hook',
  1738. ["c" /* LifecycleHooks.CREATED */]: 'created hook',
  1739. ["bm" /* LifecycleHooks.BEFORE_MOUNT */]: 'beforeMount hook',
  1740. ["m" /* LifecycleHooks.MOUNTED */]: 'mounted hook',
  1741. ["bu" /* LifecycleHooks.BEFORE_UPDATE */]: 'beforeUpdate hook',
  1742. ["u" /* LifecycleHooks.UPDATED */]: 'updated',
  1743. ["bum" /* LifecycleHooks.BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1744. ["um" /* LifecycleHooks.UNMOUNTED */]: 'unmounted hook',
  1745. ["a" /* LifecycleHooks.ACTIVATED */]: 'activated hook',
  1746. ["da" /* LifecycleHooks.DEACTIVATED */]: 'deactivated hook',
  1747. ["ec" /* LifecycleHooks.ERROR_CAPTURED */]: 'errorCaptured hook',
  1748. ["rtc" /* LifecycleHooks.RENDER_TRACKED */]: 'renderTracked hook',
  1749. ["rtg" /* LifecycleHooks.RENDER_TRIGGERED */]: 'renderTriggered hook',
  1750. [0 /* ErrorCodes.SETUP_FUNCTION */]: 'setup function',
  1751. [1 /* ErrorCodes.RENDER_FUNCTION */]: 'render function',
  1752. [2 /* ErrorCodes.WATCH_GETTER */]: 'watcher getter',
  1753. [3 /* ErrorCodes.WATCH_CALLBACK */]: 'watcher callback',
  1754. [4 /* ErrorCodes.WATCH_CLEANUP */]: 'watcher cleanup function',
  1755. [5 /* ErrorCodes.NATIVE_EVENT_HANDLER */]: 'native event handler',
  1756. [6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1757. [7 /* ErrorCodes.VNODE_HOOK */]: 'vnode hook',
  1758. [8 /* ErrorCodes.DIRECTIVE_HOOK */]: 'directive hook',
  1759. [9 /* ErrorCodes.TRANSITION_HOOK */]: 'transition hook',
  1760. [10 /* ErrorCodes.APP_ERROR_HANDLER */]: 'app errorHandler',
  1761. [11 /* ErrorCodes.APP_WARN_HANDLER */]: 'app warnHandler',
  1762. [12 /* ErrorCodes.FUNCTION_REF */]: 'ref function',
  1763. [13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1764. [14 /* ErrorCodes.SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1765. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1766. };
  1767. function callWithErrorHandling(fn, instance, type, args) {
  1768. let res;
  1769. try {
  1770. res = args ? fn(...args) : fn();
  1771. }
  1772. catch (err) {
  1773. handleError(err, instance, type);
  1774. }
  1775. return res;
  1776. }
  1777. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1778. if (isFunction(fn)) {
  1779. const res = callWithErrorHandling(fn, instance, type, args);
  1780. if (res && isPromise(res)) {
  1781. res.catch(err => {
  1782. handleError(err, instance, type);
  1783. });
  1784. }
  1785. return res;
  1786. }
  1787. const values = [];
  1788. for (let i = 0; i < fn.length; i++) {
  1789. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1790. }
  1791. return values;
  1792. }
  1793. function handleError(err, instance, type, throwInDev = true) {
  1794. const contextVNode = instance ? instance.vnode : null;
  1795. if (instance) {
  1796. let cur = instance.parent;
  1797. // the exposed instance is the render proxy to keep it consistent with 2.x
  1798. const exposedInstance = instance.proxy;
  1799. // in production the hook receives only the error code
  1800. const errorInfo = ErrorTypeStrings[type] ;
  1801. while (cur) {
  1802. const errorCapturedHooks = cur.ec;
  1803. if (errorCapturedHooks) {
  1804. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1805. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1806. return;
  1807. }
  1808. }
  1809. }
  1810. cur = cur.parent;
  1811. }
  1812. // app-level handling
  1813. const appErrorHandler = instance.appContext.config.errorHandler;
  1814. if (appErrorHandler) {
  1815. callWithErrorHandling(appErrorHandler, null, 10 /* ErrorCodes.APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1816. return;
  1817. }
  1818. }
  1819. logError(err, type, contextVNode, throwInDev);
  1820. }
  1821. function logError(err, type, contextVNode, throwInDev = true) {
  1822. {
  1823. const info = ErrorTypeStrings[type];
  1824. if (contextVNode) {
  1825. pushWarningContext(contextVNode);
  1826. }
  1827. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1828. if (contextVNode) {
  1829. popWarningContext();
  1830. }
  1831. // crash in dev by default so it's more noticeable
  1832. if (throwInDev) {
  1833. throw err;
  1834. }
  1835. else {
  1836. console.error(err);
  1837. }
  1838. }
  1839. }
  1840. let isFlushing = false;
  1841. let isFlushPending = false;
  1842. const queue = [];
  1843. let flushIndex = 0;
  1844. const pendingPostFlushCbs = [];
  1845. let activePostFlushCbs = null;
  1846. let postFlushIndex = 0;
  1847. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1848. let currentFlushPromise = null;
  1849. const RECURSION_LIMIT = 100;
  1850. function nextTick(fn) {
  1851. const p = currentFlushPromise || resolvedPromise;
  1852. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1853. }
  1854. // #2768
  1855. // Use binary-search to find a suitable position in the queue,
  1856. // so that the queue maintains the increasing order of job's id,
  1857. // which can prevent the job from being skipped and also can avoid repeated patching.
  1858. function findInsertionIndex(id) {
  1859. // the start index should be `flushIndex + 1`
  1860. let start = flushIndex + 1;
  1861. let end = queue.length;
  1862. while (start < end) {
  1863. const middle = (start + end) >>> 1;
  1864. const middleJobId = getId(queue[middle]);
  1865. middleJobId < id ? (start = middle + 1) : (end = middle);
  1866. }
  1867. return start;
  1868. }
  1869. function queueJob(job) {
  1870. // the dedupe search uses the startIndex argument of Array.includes()
  1871. // by default the search index includes the current job that is being run
  1872. // so it cannot recursively trigger itself again.
  1873. // if the job is a watch() callback, the search will start with a +1 index to
  1874. // allow it recursively trigger itself - it is the user's responsibility to
  1875. // ensure it doesn't end up in an infinite loop.
  1876. if (!queue.length ||
  1877. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
  1878. if (job.id == null) {
  1879. queue.push(job);
  1880. }
  1881. else {
  1882. queue.splice(findInsertionIndex(job.id), 0, job);
  1883. }
  1884. queueFlush();
  1885. }
  1886. }
  1887. function queueFlush() {
  1888. if (!isFlushing && !isFlushPending) {
  1889. isFlushPending = true;
  1890. currentFlushPromise = resolvedPromise.then(flushJobs);
  1891. }
  1892. }
  1893. function invalidateJob(job) {
  1894. const i = queue.indexOf(job);
  1895. if (i > flushIndex) {
  1896. queue.splice(i, 1);
  1897. }
  1898. }
  1899. function queuePostFlushCb(cb) {
  1900. if (!isArray(cb)) {
  1901. if (!activePostFlushCbs ||
  1902. !activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
  1903. pendingPostFlushCbs.push(cb);
  1904. }
  1905. }
  1906. else {
  1907. // if cb is an array, it is a component lifecycle hook which can only be
  1908. // triggered by a job, which is already deduped in the main queue, so
  1909. // we can skip duplicate check here to improve perf
  1910. pendingPostFlushCbs.push(...cb);
  1911. }
  1912. queueFlush();
  1913. }
  1914. function flushPreFlushCbs(seen,
  1915. // if currently flushing, skip the current job itself
  1916. i = isFlushing ? flushIndex + 1 : 0) {
  1917. {
  1918. seen = seen || new Map();
  1919. }
  1920. for (; i < queue.length; i++) {
  1921. const cb = queue[i];
  1922. if (cb && cb.pre) {
  1923. if (checkRecursiveUpdates(seen, cb)) {
  1924. continue;
  1925. }
  1926. queue.splice(i, 1);
  1927. i--;
  1928. cb();
  1929. }
  1930. }
  1931. }
  1932. function flushPostFlushCbs(seen) {
  1933. if (pendingPostFlushCbs.length) {
  1934. const deduped = [...new Set(pendingPostFlushCbs)];
  1935. pendingPostFlushCbs.length = 0;
  1936. // #1947 already has active queue, nested flushPostFlushCbs call
  1937. if (activePostFlushCbs) {
  1938. activePostFlushCbs.push(...deduped);
  1939. return;
  1940. }
  1941. activePostFlushCbs = deduped;
  1942. {
  1943. seen = seen || new Map();
  1944. }
  1945. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1946. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1947. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1948. continue;
  1949. }
  1950. activePostFlushCbs[postFlushIndex]();
  1951. }
  1952. activePostFlushCbs = null;
  1953. postFlushIndex = 0;
  1954. }
  1955. }
  1956. const getId = (job) => job.id == null ? Infinity : job.id;
  1957. const comparator = (a, b) => {
  1958. const diff = getId(a) - getId(b);
  1959. if (diff === 0) {
  1960. if (a.pre && !b.pre)
  1961. return -1;
  1962. if (b.pre && !a.pre)
  1963. return 1;
  1964. }
  1965. return diff;
  1966. };
  1967. function flushJobs(seen) {
  1968. isFlushPending = false;
  1969. isFlushing = true;
  1970. {
  1971. seen = seen || new Map();
  1972. }
  1973. // Sort queue before flush.
  1974. // This ensures that:
  1975. // 1. Components are updated from parent to child. (because parent is always
  1976. // created before the child so its render effect will have smaller
  1977. // priority number)
  1978. // 2. If a component is unmounted during a parent component's update,
  1979. // its update can be skipped.
  1980. queue.sort(comparator);
  1981. // conditional usage of checkRecursiveUpdate must be determined out of
  1982. // try ... catch block since Rollup by default de-optimizes treeshaking
  1983. // inside try-catch. This can leave all warning code unshaked. Although
  1984. // they would get eventually shaken by a minifier like terser, some minifiers
  1985. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1986. const check = (job) => checkRecursiveUpdates(seen, job)
  1987. ;
  1988. try {
  1989. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1990. const job = queue[flushIndex];
  1991. if (job && job.active !== false) {
  1992. if (true && check(job)) {
  1993. continue;
  1994. }
  1995. // console.log(`running:`, job.id)
  1996. callWithErrorHandling(job, null, 14 /* ErrorCodes.SCHEDULER */);
  1997. }
  1998. }
  1999. }
  2000. finally {
  2001. flushIndex = 0;
  2002. queue.length = 0;
  2003. flushPostFlushCbs(seen);
  2004. isFlushing = false;
  2005. currentFlushPromise = null;
  2006. // some postFlushCb queued jobs!
  2007. // keep flushing until it drains.
  2008. if (queue.length || pendingPostFlushCbs.length) {
  2009. flushJobs(seen);
  2010. }
  2011. }
  2012. }
  2013. function checkRecursiveUpdates(seen, fn) {
  2014. if (!seen.has(fn)) {
  2015. seen.set(fn, 1);
  2016. }
  2017. else {
  2018. const count = seen.get(fn);
  2019. if (count > RECURSION_LIMIT) {
  2020. const instance = fn.ownerInstance;
  2021. const componentName = instance && getComponentName(instance.type);
  2022. warn(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  2023. `This means you have a reactive effect that is mutating its own ` +
  2024. `dependencies and thus recursively triggering itself. Possible sources ` +
  2025. `include component template, render function, updated hook or ` +
  2026. `watcher source function.`);
  2027. return true;
  2028. }
  2029. else {
  2030. seen.set(fn, count + 1);
  2031. }
  2032. }
  2033. }
  2034. /* eslint-disable no-restricted-globals */
  2035. let isHmrUpdating = false;
  2036. const hmrDirtyComponents = new Set();
  2037. // Expose the HMR runtime on the global object
  2038. // This makes it entirely tree-shakable without polluting the exports and makes
  2039. // it easier to be used in toolings like vue-loader
  2040. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  2041. // to be set so that its instances can be registered / removed.
  2042. {
  2043. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  2044. createRecord: tryWrap(createRecord),
  2045. rerender: tryWrap(rerender),
  2046. reload: tryWrap(reload)
  2047. };
  2048. }
  2049. const map = new Map();
  2050. function registerHMR(instance) {
  2051. const id = instance.type.__hmrId;
  2052. let record = map.get(id);
  2053. if (!record) {
  2054. createRecord(id, instance.type);
  2055. record = map.get(id);
  2056. }
  2057. record.instances.add(instance);
  2058. }
  2059. function unregisterHMR(instance) {
  2060. map.get(instance.type.__hmrId).instances.delete(instance);
  2061. }
  2062. function createRecord(id, initialDef) {
  2063. if (map.has(id)) {
  2064. return false;
  2065. }
  2066. map.set(id, {
  2067. initialDef: normalizeClassComponent(initialDef),
  2068. instances: new Set()
  2069. });
  2070. return true;
  2071. }
  2072. function normalizeClassComponent(component) {
  2073. return isClassComponent(component) ? component.__vccOpts : component;
  2074. }
  2075. function rerender(id, newRender) {
  2076. const record = map.get(id);
  2077. if (!record) {
  2078. return;
  2079. }
  2080. // update initial record (for not-yet-rendered component)
  2081. record.initialDef.render = newRender;
  2082. [...record.instances].forEach(instance => {
  2083. if (newRender) {
  2084. instance.render = newRender;
  2085. normalizeClassComponent(instance.type).render = newRender;
  2086. }
  2087. instance.renderCache = [];
  2088. // this flag forces child components with slot content to update
  2089. isHmrUpdating = true;
  2090. instance.update();
  2091. isHmrUpdating = false;
  2092. });
  2093. }
  2094. function reload(id, newComp) {
  2095. const record = map.get(id);
  2096. if (!record)
  2097. return;
  2098. newComp = normalizeClassComponent(newComp);
  2099. // update initial def (for not-yet-rendered components)
  2100. updateComponentDef(record.initialDef, newComp);
  2101. // create a snapshot which avoids the set being mutated during updates
  2102. const instances = [...record.instances];
  2103. for (const instance of instances) {
  2104. const oldComp = normalizeClassComponent(instance.type);
  2105. if (!hmrDirtyComponents.has(oldComp)) {
  2106. // 1. Update existing comp definition to match new one
  2107. if (oldComp !== record.initialDef) {
  2108. updateComponentDef(oldComp, newComp);
  2109. }
  2110. // 2. mark definition dirty. This forces the renderer to replace the
  2111. // component on patch.
  2112. hmrDirtyComponents.add(oldComp);
  2113. }
  2114. // 3. invalidate options resolution cache
  2115. instance.appContext.optionsCache.delete(instance.type);
  2116. // 4. actually update
  2117. if (instance.ceReload) {
  2118. // custom element
  2119. hmrDirtyComponents.add(oldComp);
  2120. instance.ceReload(newComp.styles);
  2121. hmrDirtyComponents.delete(oldComp);
  2122. }
  2123. else if (instance.parent) {
  2124. // 4. Force the parent instance to re-render. This will cause all updated
  2125. // components to be unmounted and re-mounted. Queue the update so that we
  2126. // don't end up forcing the same parent to re-render multiple times.
  2127. queueJob(instance.parent.update);
  2128. }
  2129. else if (instance.appContext.reload) {
  2130. // root instance mounted via createApp() has a reload method
  2131. instance.appContext.reload();
  2132. }
  2133. else if (typeof window !== 'undefined') {
  2134. // root instance inside tree created via raw render(). Force reload.
  2135. window.location.reload();
  2136. }
  2137. else {
  2138. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  2139. }
  2140. }
  2141. // 5. make sure to cleanup dirty hmr components after update
  2142. queuePostFlushCb(() => {
  2143. for (const instance of instances) {
  2144. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  2145. }
  2146. });
  2147. }
  2148. function updateComponentDef(oldComp, newComp) {
  2149. extend(oldComp, newComp);
  2150. for (const key in oldComp) {
  2151. if (key !== '__file' && !(key in newComp)) {
  2152. delete oldComp[key];
  2153. }
  2154. }
  2155. }
  2156. function tryWrap(fn) {
  2157. return (id, arg) => {
  2158. try {
  2159. return fn(id, arg);
  2160. }
  2161. catch (e) {
  2162. console.error(e);
  2163. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2164. `Full reload required.`);
  2165. }
  2166. };
  2167. }
  2168. exports.devtools = void 0;
  2169. let buffer = [];
  2170. let devtoolsNotInstalled = false;
  2171. function emit$1(event, ...args) {
  2172. if (exports.devtools) {
  2173. exports.devtools.emit(event, ...args);
  2174. }
  2175. else if (!devtoolsNotInstalled) {
  2176. buffer.push({ event, args });
  2177. }
  2178. }
  2179. function setDevtoolsHook(hook, target) {
  2180. var _a, _b;
  2181. exports.devtools = hook;
  2182. if (exports.devtools) {
  2183. exports.devtools.enabled = true;
  2184. buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
  2185. buffer = [];
  2186. }
  2187. else if (
  2188. // handle late devtools injection - only do this if we are in an actual
  2189. // browser environment to avoid the timer handle stalling test runner exit
  2190. // (#4815)
  2191. typeof window !== 'undefined' &&
  2192. // some envs mock window but not fully
  2193. window.HTMLElement &&
  2194. // also exclude jsdom
  2195. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2196. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2197. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2198. replay.push((newHook) => {
  2199. setDevtoolsHook(newHook, target);
  2200. });
  2201. // clear buffer after 3s - the user probably doesn't have devtools installed
  2202. // at all, and keeping the buffer will cause memory leaks (#4738)
  2203. setTimeout(() => {
  2204. if (!exports.devtools) {
  2205. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2206. devtoolsNotInstalled = true;
  2207. buffer = [];
  2208. }
  2209. }, 3000);
  2210. }
  2211. else {
  2212. // non-browser env, assume not installed
  2213. devtoolsNotInstalled = true;
  2214. buffer = [];
  2215. }
  2216. }
  2217. function devtoolsInitApp(app, version) {
  2218. emit$1("app:init" /* DevtoolsHooks.APP_INIT */, app, version, {
  2219. Fragment,
  2220. Text,
  2221. Comment,
  2222. Static
  2223. });
  2224. }
  2225. function devtoolsUnmountApp(app) {
  2226. emit$1("app:unmount" /* DevtoolsHooks.APP_UNMOUNT */, app);
  2227. }
  2228. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* DevtoolsHooks.COMPONENT_ADDED */);
  2229. const devtoolsComponentUpdated =
  2230. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* DevtoolsHooks.COMPONENT_UPDATED */);
  2231. const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* DevtoolsHooks.COMPONENT_REMOVED */);
  2232. const devtoolsComponentRemoved = (component) => {
  2233. if (exports.devtools &&
  2234. typeof exports.devtools.cleanupBuffer === 'function' &&
  2235. // remove the component if it wasn't buffered
  2236. !exports.devtools.cleanupBuffer(component)) {
  2237. _devtoolsComponentRemoved(component);
  2238. }
  2239. };
  2240. function createDevtoolsComponentHook(hook) {
  2241. return (component) => {
  2242. emit$1(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2243. };
  2244. }
  2245. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* DevtoolsHooks.PERFORMANCE_START */);
  2246. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* DevtoolsHooks.PERFORMANCE_END */);
  2247. function createDevtoolsPerformanceHook(hook) {
  2248. return (component, type, time) => {
  2249. emit$1(hook, component.appContext.app, component.uid, component, type, time);
  2250. };
  2251. }
  2252. function devtoolsComponentEmit(component, event, params) {
  2253. emit$1("component:emit" /* DevtoolsHooks.COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2254. }
  2255. function emit(instance, event, ...rawArgs) {
  2256. if (instance.isUnmounted)
  2257. return;
  2258. const props = instance.vnode.props || EMPTY_OBJ;
  2259. {
  2260. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2261. if (emitsOptions) {
  2262. if (!(event in emitsOptions) &&
  2263. !(false )) {
  2264. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2265. warn(`Component emitted event "${event}" but it is neither declared in ` +
  2266. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2267. }
  2268. }
  2269. else {
  2270. const validator = emitsOptions[event];
  2271. if (isFunction(validator)) {
  2272. const isValid = validator(...rawArgs);
  2273. if (!isValid) {
  2274. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  2275. }
  2276. }
  2277. }
  2278. }
  2279. }
  2280. let args = rawArgs;
  2281. const isModelListener = event.startsWith('update:');
  2282. // for v-model update:xxx events, apply modifiers on args
  2283. const modelArg = isModelListener && event.slice(7);
  2284. if (modelArg && modelArg in props) {
  2285. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2286. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2287. if (trim) {
  2288. args = rawArgs.map(a => (isString(a) ? a.trim() : a));
  2289. }
  2290. if (number) {
  2291. args = rawArgs.map(looseToNumber);
  2292. }
  2293. }
  2294. {
  2295. devtoolsComponentEmit(instance, event, args);
  2296. }
  2297. {
  2298. const lowerCaseEvent = event.toLowerCase();
  2299. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2300. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  2301. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2302. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2303. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2304. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2305. }
  2306. }
  2307. let handlerName;
  2308. let handler = props[(handlerName = toHandlerKey(event))] ||
  2309. // also try camelCase event handler (#2249)
  2310. props[(handlerName = toHandlerKey(camelize(event)))];
  2311. // for v-model update:xxx events, also trigger kebab-case equivalent
  2312. // for props passed via kebab-case
  2313. if (!handler && isModelListener) {
  2314. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2315. }
  2316. if (handler) {
  2317. callWithAsyncErrorHandling(handler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  2318. }
  2319. const onceHandler = props[handlerName + `Once`];
  2320. if (onceHandler) {
  2321. if (!instance.emitted) {
  2322. instance.emitted = {};
  2323. }
  2324. else if (instance.emitted[handlerName]) {
  2325. return;
  2326. }
  2327. instance.emitted[handlerName] = true;
  2328. callWithAsyncErrorHandling(onceHandler, instance, 6 /* ErrorCodes.COMPONENT_EVENT_HANDLER */, args);
  2329. }
  2330. }
  2331. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2332. const cache = appContext.emitsCache;
  2333. const cached = cache.get(comp);
  2334. if (cached !== undefined) {
  2335. return cached;
  2336. }
  2337. const raw = comp.emits;
  2338. let normalized = {};
  2339. // apply mixin/extends props
  2340. let hasExtends = false;
  2341. if (!isFunction(comp)) {
  2342. const extendEmits = (raw) => {
  2343. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2344. if (normalizedFromExtend) {
  2345. hasExtends = true;
  2346. extend(normalized, normalizedFromExtend);
  2347. }
  2348. };
  2349. if (!asMixin && appContext.mixins.length) {
  2350. appContext.mixins.forEach(extendEmits);
  2351. }
  2352. if (comp.extends) {
  2353. extendEmits(comp.extends);
  2354. }
  2355. if (comp.mixins) {
  2356. comp.mixins.forEach(extendEmits);
  2357. }
  2358. }
  2359. if (!raw && !hasExtends) {
  2360. if (isObject(comp)) {
  2361. cache.set(comp, null);
  2362. }
  2363. return null;
  2364. }
  2365. if (isArray(raw)) {
  2366. raw.forEach(key => (normalized[key] = null));
  2367. }
  2368. else {
  2369. extend(normalized, raw);
  2370. }
  2371. if (isObject(comp)) {
  2372. cache.set(comp, normalized);
  2373. }
  2374. return normalized;
  2375. }
  2376. // Check if an incoming prop key is a declared emit event listener.
  2377. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2378. // both considered matched listeners.
  2379. function isEmitListener(options, key) {
  2380. if (!options || !isOn(key)) {
  2381. return false;
  2382. }
  2383. key = key.slice(2).replace(/Once$/, '');
  2384. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2385. hasOwn(options, hyphenate(key)) ||
  2386. hasOwn(options, key));
  2387. }
  2388. /**
  2389. * mark the current rendering instance for asset resolution (e.g.
  2390. * resolveComponent, resolveDirective) during render
  2391. */
  2392. let currentRenderingInstance = null;
  2393. let currentScopeId = null;
  2394. /**
  2395. * Note: rendering calls maybe nested. The function returns the parent rendering
  2396. * instance if present, which should be restored after the render is done:
  2397. *
  2398. * ```js
  2399. * const prev = setCurrentRenderingInstance(i)
  2400. * // ...render
  2401. * setCurrentRenderingInstance(prev)
  2402. * ```
  2403. */
  2404. function setCurrentRenderingInstance(instance) {
  2405. const prev = currentRenderingInstance;
  2406. currentRenderingInstance = instance;
  2407. currentScopeId = (instance && instance.type.__scopeId) || null;
  2408. return prev;
  2409. }
  2410. /**
  2411. * Set scope id when creating hoisted vnodes.
  2412. * @private compiler helper
  2413. */
  2414. function pushScopeId(id) {
  2415. currentScopeId = id;
  2416. }
  2417. /**
  2418. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2419. * API for backwards compat w/ code generated by compilers.
  2420. * @private
  2421. */
  2422. function popScopeId() {
  2423. currentScopeId = null;
  2424. }
  2425. /**
  2426. * Only for backwards compat
  2427. * @private
  2428. */
  2429. const withScopeId = (_id) => withCtx;
  2430. /**
  2431. * Wrap a slot function to memoize current rendering instance
  2432. * @private compiler helper
  2433. */
  2434. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2435. ) {
  2436. if (!ctx)
  2437. return fn;
  2438. // already normalized
  2439. if (fn._n) {
  2440. return fn;
  2441. }
  2442. const renderFnWithContext = (...args) => {
  2443. // If a user calls a compiled slot inside a template expression (#1745), it
  2444. // can mess up block tracking, so by default we disable block tracking and
  2445. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2446. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2447. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2448. if (renderFnWithContext._d) {
  2449. setBlockTracking(-1);
  2450. }
  2451. const prevInstance = setCurrentRenderingInstance(ctx);
  2452. let res;
  2453. try {
  2454. res = fn(...args);
  2455. }
  2456. finally {
  2457. setCurrentRenderingInstance(prevInstance);
  2458. if (renderFnWithContext._d) {
  2459. setBlockTracking(1);
  2460. }
  2461. }
  2462. {
  2463. devtoolsComponentUpdated(ctx);
  2464. }
  2465. return res;
  2466. };
  2467. // mark normalized to avoid duplicated wrapping
  2468. renderFnWithContext._n = true;
  2469. // mark this as compiled by default
  2470. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2471. // rendering flag.
  2472. renderFnWithContext._c = true;
  2473. // disable block tracking by default
  2474. renderFnWithContext._d = true;
  2475. return renderFnWithContext;
  2476. }
  2477. /**
  2478. * dev only flag to track whether $attrs was used during render.
  2479. * If $attrs was used during render then the warning for failed attrs
  2480. * fallthrough can be suppressed.
  2481. */
  2482. let accessedAttrs = false;
  2483. function markAttrsAccessed() {
  2484. accessedAttrs = true;
  2485. }
  2486. function renderComponentRoot(instance) {
  2487. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2488. let result;
  2489. let fallthroughAttrs;
  2490. const prev = setCurrentRenderingInstance(instance);
  2491. {
  2492. accessedAttrs = false;
  2493. }
  2494. try {
  2495. if (vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) {
  2496. // withProxy is a proxy with a different `has` trap only for
  2497. // runtime-compiled render functions using `with` block.
  2498. const proxyToUse = withProxy || proxy;
  2499. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2500. fallthroughAttrs = attrs;
  2501. }
  2502. else {
  2503. // functional
  2504. const render = Component;
  2505. // in dev, mark attrs accessed if optional props (attrs === props)
  2506. if (true && attrs === props) {
  2507. markAttrsAccessed();
  2508. }
  2509. result = normalizeVNode(render.length > 1
  2510. ? render(props, true
  2511. ? {
  2512. get attrs() {
  2513. markAttrsAccessed();
  2514. return attrs;
  2515. },
  2516. slots,
  2517. emit
  2518. }
  2519. : { attrs, slots, emit })
  2520. : render(props, null /* we know it doesn't need it */));
  2521. fallthroughAttrs = Component.props
  2522. ? attrs
  2523. : getFunctionalFallthrough(attrs);
  2524. }
  2525. }
  2526. catch (err) {
  2527. blockStack.length = 0;
  2528. handleError(err, instance, 1 /* ErrorCodes.RENDER_FUNCTION */);
  2529. result = createVNode(Comment);
  2530. }
  2531. // attr merging
  2532. // in dev mode, comments are preserved, and it's possible for a template
  2533. // to have comments along side the root element which makes it a fragment
  2534. let root = result;
  2535. let setRoot = undefined;
  2536. if (result.patchFlag > 0 &&
  2537. result.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  2538. [root, setRoot] = getChildRoot(result);
  2539. }
  2540. if (fallthroughAttrs && inheritAttrs !== false) {
  2541. const keys = Object.keys(fallthroughAttrs);
  2542. const { shapeFlag } = root;
  2543. if (keys.length) {
  2544. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 6 /* ShapeFlags.COMPONENT */)) {
  2545. if (propsOptions && keys.some(isModelListener)) {
  2546. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2547. // prop, it indicates this component expects to handle v-model and
  2548. // it should not fallthrough.
  2549. // related: #1543, #1643, #1989
  2550. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2551. }
  2552. root = cloneVNode(root, fallthroughAttrs);
  2553. }
  2554. else if (!accessedAttrs && root.type !== Comment) {
  2555. const allAttrs = Object.keys(attrs);
  2556. const eventAttrs = [];
  2557. const extraAttrs = [];
  2558. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2559. const key = allAttrs[i];
  2560. if (isOn(key)) {
  2561. // ignore v-model handlers when they fail to fallthrough
  2562. if (!isModelListener(key)) {
  2563. // remove `on`, lowercase first letter to reflect event casing
  2564. // accurately
  2565. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2566. }
  2567. }
  2568. else {
  2569. extraAttrs.push(key);
  2570. }
  2571. }
  2572. if (extraAttrs.length) {
  2573. warn(`Extraneous non-props attributes (` +
  2574. `${extraAttrs.join(', ')}) ` +
  2575. `were passed to component but could not be automatically inherited ` +
  2576. `because component renders fragment or text root nodes.`);
  2577. }
  2578. if (eventAttrs.length) {
  2579. warn(`Extraneous non-emits event listeners (` +
  2580. `${eventAttrs.join(', ')}) ` +
  2581. `were passed to component but could not be automatically inherited ` +
  2582. `because component renders fragment or text root nodes. ` +
  2583. `If the listener is intended to be a component custom event listener only, ` +
  2584. `declare it using the "emits" option.`);
  2585. }
  2586. }
  2587. }
  2588. }
  2589. // inherit directives
  2590. if (vnode.dirs) {
  2591. if (!isElementRoot(root)) {
  2592. warn(`Runtime directive used on component with non-element root node. ` +
  2593. `The directives will not function as intended.`);
  2594. }
  2595. // clone before mutating since the root may be a hoisted vnode
  2596. root = cloneVNode(root);
  2597. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2598. }
  2599. // inherit transition data
  2600. if (vnode.transition) {
  2601. if (!isElementRoot(root)) {
  2602. warn(`Component inside <Transition> renders non-element root node ` +
  2603. `that cannot be animated.`);
  2604. }
  2605. root.transition = vnode.transition;
  2606. }
  2607. if (setRoot) {
  2608. setRoot(root);
  2609. }
  2610. else {
  2611. result = root;
  2612. }
  2613. setCurrentRenderingInstance(prev);
  2614. return result;
  2615. }
  2616. /**
  2617. * dev only
  2618. * In dev mode, template root level comments are rendered, which turns the
  2619. * template into a fragment root, but we need to locate the single element
  2620. * root for attrs and scope id processing.
  2621. */
  2622. const getChildRoot = (vnode) => {
  2623. const rawChildren = vnode.children;
  2624. const dynamicChildren = vnode.dynamicChildren;
  2625. const childRoot = filterSingleRoot(rawChildren);
  2626. if (!childRoot) {
  2627. return [vnode, undefined];
  2628. }
  2629. const index = rawChildren.indexOf(childRoot);
  2630. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2631. const setRoot = (updatedRoot) => {
  2632. rawChildren[index] = updatedRoot;
  2633. if (dynamicChildren) {
  2634. if (dynamicIndex > -1) {
  2635. dynamicChildren[dynamicIndex] = updatedRoot;
  2636. }
  2637. else if (updatedRoot.patchFlag > 0) {
  2638. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2639. }
  2640. }
  2641. };
  2642. return [normalizeVNode(childRoot), setRoot];
  2643. };
  2644. function filterSingleRoot(children) {
  2645. let singleRoot;
  2646. for (let i = 0; i < children.length; i++) {
  2647. const child = children[i];
  2648. if (isVNode(child)) {
  2649. // ignore user comment
  2650. if (child.type !== Comment || child.children === 'v-if') {
  2651. if (singleRoot) {
  2652. // has more than 1 non-comment child, return now
  2653. return;
  2654. }
  2655. else {
  2656. singleRoot = child;
  2657. }
  2658. }
  2659. }
  2660. else {
  2661. return;
  2662. }
  2663. }
  2664. return singleRoot;
  2665. }
  2666. const getFunctionalFallthrough = (attrs) => {
  2667. let res;
  2668. for (const key in attrs) {
  2669. if (key === 'class' || key === 'style' || isOn(key)) {
  2670. (res || (res = {}))[key] = attrs[key];
  2671. }
  2672. }
  2673. return res;
  2674. };
  2675. const filterModelListeners = (attrs, props) => {
  2676. const res = {};
  2677. for (const key in attrs) {
  2678. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2679. res[key] = attrs[key];
  2680. }
  2681. }
  2682. return res;
  2683. };
  2684. const isElementRoot = (vnode) => {
  2685. return (vnode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 1 /* ShapeFlags.ELEMENT */) ||
  2686. vnode.type === Comment // potential v-if branch switch
  2687. );
  2688. };
  2689. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2690. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2691. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2692. const emits = component.emitsOptions;
  2693. // Parent component's render function was hot-updated. Since this may have
  2694. // caused the child component's slots content to have changed, we need to
  2695. // force the child to update as well.
  2696. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2697. return true;
  2698. }
  2699. // force child update for runtime directive or transition on component vnode.
  2700. if (nextVNode.dirs || nextVNode.transition) {
  2701. return true;
  2702. }
  2703. if (optimized && patchFlag >= 0) {
  2704. if (patchFlag & 1024 /* PatchFlags.DYNAMIC_SLOTS */) {
  2705. // slot content that references values that might have changed,
  2706. // e.g. in a v-for
  2707. return true;
  2708. }
  2709. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  2710. if (!prevProps) {
  2711. return !!nextProps;
  2712. }
  2713. // presence of this flag indicates props are always non-null
  2714. return hasPropsChanged(prevProps, nextProps, emits);
  2715. }
  2716. else if (patchFlag & 8 /* PatchFlags.PROPS */) {
  2717. const dynamicProps = nextVNode.dynamicProps;
  2718. for (let i = 0; i < dynamicProps.length; i++) {
  2719. const key = dynamicProps[i];
  2720. if (nextProps[key] !== prevProps[key] &&
  2721. !isEmitListener(emits, key)) {
  2722. return true;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. else {
  2728. // this path is only taken by manually written render functions
  2729. // so presence of any children leads to a forced update
  2730. if (prevChildren || nextChildren) {
  2731. if (!nextChildren || !nextChildren.$stable) {
  2732. return true;
  2733. }
  2734. }
  2735. if (prevProps === nextProps) {
  2736. return false;
  2737. }
  2738. if (!prevProps) {
  2739. return !!nextProps;
  2740. }
  2741. if (!nextProps) {
  2742. return true;
  2743. }
  2744. return hasPropsChanged(prevProps, nextProps, emits);
  2745. }
  2746. return false;
  2747. }
  2748. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2749. const nextKeys = Object.keys(nextProps);
  2750. if (nextKeys.length !== Object.keys(prevProps).length) {
  2751. return true;
  2752. }
  2753. for (let i = 0; i < nextKeys.length; i++) {
  2754. const key = nextKeys[i];
  2755. if (nextProps[key] !== prevProps[key] &&
  2756. !isEmitListener(emitsOptions, key)) {
  2757. return true;
  2758. }
  2759. }
  2760. return false;
  2761. }
  2762. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2763. ) {
  2764. while (parent && parent.subTree === vnode) {
  2765. (vnode = parent.vnode).el = el;
  2766. parent = parent.parent;
  2767. }
  2768. }
  2769. const isSuspense = (type) => type.__isSuspense;
  2770. // Suspense exposes a component-like API, and is treated like a component
  2771. // in the compiler, but internally it's a special built-in type that hooks
  2772. // directly into the renderer.
  2773. const SuspenseImpl = {
  2774. name: 'Suspense',
  2775. // In order to make Suspense tree-shakable, we need to avoid importing it
  2776. // directly in the renderer. The renderer checks for the __isSuspense flag
  2777. // on a vnode's type and calls the `process` method, passing in renderer
  2778. // internals.
  2779. __isSuspense: true,
  2780. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2781. // platform-specific impl passed from renderer
  2782. rendererInternals) {
  2783. if (n1 == null) {
  2784. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2785. }
  2786. else {
  2787. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2788. }
  2789. },
  2790. hydrate: hydrateSuspense,
  2791. create: createSuspenseBoundary,
  2792. normalize: normalizeSuspenseChildren
  2793. };
  2794. // Force-casted public typing for h and TSX props inference
  2795. const Suspense = (SuspenseImpl
  2796. );
  2797. function triggerEvent(vnode, name) {
  2798. const eventListener = vnode.props && vnode.props[name];
  2799. if (isFunction(eventListener)) {
  2800. eventListener();
  2801. }
  2802. }
  2803. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2804. const { p: patch, o: { createElement } } = rendererInternals;
  2805. const hiddenContainer = createElement('div');
  2806. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2807. // start mounting the content subtree in an off-dom container
  2808. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2809. // now check if we have encountered any async deps
  2810. if (suspense.deps > 0) {
  2811. // has async
  2812. // invoke @fallback event
  2813. triggerEvent(vnode, 'onPending');
  2814. triggerEvent(vnode, 'onFallback');
  2815. // mount the fallback tree
  2816. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2817. isSVG, slotScopeIds);
  2818. setActiveBranch(suspense, vnode.ssFallback);
  2819. }
  2820. else {
  2821. // Suspense has no async deps. Just resolve.
  2822. suspense.resolve();
  2823. }
  2824. }
  2825. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2826. const suspense = (n2.suspense = n1.suspense);
  2827. suspense.vnode = n2;
  2828. n2.el = n1.el;
  2829. const newBranch = n2.ssContent;
  2830. const newFallback = n2.ssFallback;
  2831. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2832. if (pendingBranch) {
  2833. suspense.pendingBranch = newBranch;
  2834. if (isSameVNodeType(newBranch, pendingBranch)) {
  2835. // same root type but content may have changed.
  2836. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2837. if (suspense.deps <= 0) {
  2838. suspense.resolve();
  2839. }
  2840. else if (isInFallback) {
  2841. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2842. isSVG, slotScopeIds, optimized);
  2843. setActiveBranch(suspense, newFallback);
  2844. }
  2845. }
  2846. else {
  2847. // toggled before pending tree is resolved
  2848. suspense.pendingId++;
  2849. if (isHydrating) {
  2850. // if toggled before hydration is finished, the current DOM tree is
  2851. // no longer valid. set it as the active branch so it will be unmounted
  2852. // when resolved
  2853. suspense.isHydrating = false;
  2854. suspense.activeBranch = pendingBranch;
  2855. }
  2856. else {
  2857. unmount(pendingBranch, parentComponent, suspense);
  2858. }
  2859. // increment pending ID. this is used to invalidate async callbacks
  2860. // reset suspense state
  2861. suspense.deps = 0;
  2862. // discard effects from pending branch
  2863. suspense.effects.length = 0;
  2864. // discard previous container
  2865. suspense.hiddenContainer = createElement('div');
  2866. if (isInFallback) {
  2867. // already in fallback state
  2868. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2869. if (suspense.deps <= 0) {
  2870. suspense.resolve();
  2871. }
  2872. else {
  2873. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2874. isSVG, slotScopeIds, optimized);
  2875. setActiveBranch(suspense, newFallback);
  2876. }
  2877. }
  2878. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2879. // toggled "back" to current active branch
  2880. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2881. // force resolve
  2882. suspense.resolve(true);
  2883. }
  2884. else {
  2885. // switched to a 3rd branch
  2886. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2887. if (suspense.deps <= 0) {
  2888. suspense.resolve();
  2889. }
  2890. }
  2891. }
  2892. }
  2893. else {
  2894. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2895. // root did not change, just normal patch
  2896. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2897. setActiveBranch(suspense, newBranch);
  2898. }
  2899. else {
  2900. // root node toggled
  2901. // invoke @pending event
  2902. triggerEvent(n2, 'onPending');
  2903. // mount pending branch in off-dom container
  2904. suspense.pendingBranch = newBranch;
  2905. suspense.pendingId++;
  2906. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2907. if (suspense.deps <= 0) {
  2908. // incoming branch has no async deps, resolve now.
  2909. suspense.resolve();
  2910. }
  2911. else {
  2912. const { timeout, pendingId } = suspense;
  2913. if (timeout > 0) {
  2914. setTimeout(() => {
  2915. if (suspense.pendingId === pendingId) {
  2916. suspense.fallback(newFallback);
  2917. }
  2918. }, timeout);
  2919. }
  2920. else if (timeout === 0) {
  2921. suspense.fallback(newFallback);
  2922. }
  2923. }
  2924. }
  2925. }
  2926. }
  2927. let hasWarned = false;
  2928. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2929. /* istanbul ignore if */
  2930. if (!hasWarned) {
  2931. hasWarned = true;
  2932. // @ts-ignore `console.info` cannot be null error
  2933. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2934. }
  2935. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2936. const timeout = vnode.props ? toNumber(vnode.props.timeout) : undefined;
  2937. {
  2938. assertNumber(timeout, `Suspense timeout`);
  2939. }
  2940. const suspense = {
  2941. vnode,
  2942. parent,
  2943. parentComponent,
  2944. isSVG,
  2945. container,
  2946. hiddenContainer,
  2947. anchor,
  2948. deps: 0,
  2949. pendingId: 0,
  2950. timeout: typeof timeout === 'number' ? timeout : -1,
  2951. activeBranch: null,
  2952. pendingBranch: null,
  2953. isInFallback: true,
  2954. isHydrating,
  2955. isUnmounted: false,
  2956. effects: [],
  2957. resolve(resume = false) {
  2958. {
  2959. if (!resume && !suspense.pendingBranch) {
  2960. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2961. }
  2962. if (suspense.isUnmounted) {
  2963. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2964. }
  2965. }
  2966. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2967. if (suspense.isHydrating) {
  2968. suspense.isHydrating = false;
  2969. }
  2970. else if (!resume) {
  2971. const delayEnter = activeBranch &&
  2972. pendingBranch.transition &&
  2973. pendingBranch.transition.mode === 'out-in';
  2974. if (delayEnter) {
  2975. activeBranch.transition.afterLeave = () => {
  2976. if (pendingId === suspense.pendingId) {
  2977. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2978. }
  2979. };
  2980. }
  2981. // this is initial anchor on mount
  2982. let { anchor } = suspense;
  2983. // unmount current active tree
  2984. if (activeBranch) {
  2985. // if the fallback tree was mounted, it may have been moved
  2986. // as part of a parent suspense. get the latest anchor for insertion
  2987. anchor = next(activeBranch);
  2988. unmount(activeBranch, parentComponent, suspense, true);
  2989. }
  2990. if (!delayEnter) {
  2991. // move content from off-dom container to actual container
  2992. move(pendingBranch, container, anchor, 0 /* MoveType.ENTER */);
  2993. }
  2994. }
  2995. setActiveBranch(suspense, pendingBranch);
  2996. suspense.pendingBranch = null;
  2997. suspense.isInFallback = false;
  2998. // flush buffered effects
  2999. // check if there is a pending parent suspense
  3000. let parent = suspense.parent;
  3001. let hasUnresolvedAncestor = false;
  3002. while (parent) {
  3003. if (parent.pendingBranch) {
  3004. // found a pending parent suspense, merge buffered post jobs
  3005. // into that parent
  3006. parent.effects.push(...effects);
  3007. hasUnresolvedAncestor = true;
  3008. break;
  3009. }
  3010. parent = parent.parent;
  3011. }
  3012. // no pending parent suspense, flush all jobs
  3013. if (!hasUnresolvedAncestor) {
  3014. queuePostFlushCb(effects);
  3015. }
  3016. suspense.effects = [];
  3017. // invoke @resolve event
  3018. triggerEvent(vnode, 'onResolve');
  3019. },
  3020. fallback(fallbackVNode) {
  3021. if (!suspense.pendingBranch) {
  3022. return;
  3023. }
  3024. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  3025. // invoke @fallback event
  3026. triggerEvent(vnode, 'onFallback');
  3027. const anchor = next(activeBranch);
  3028. const mountFallback = () => {
  3029. if (!suspense.isInFallback) {
  3030. return;
  3031. }
  3032. // mount the fallback tree
  3033. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  3034. isSVG, slotScopeIds, optimized);
  3035. setActiveBranch(suspense, fallbackVNode);
  3036. };
  3037. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  3038. if (delayEnter) {
  3039. activeBranch.transition.afterLeave = mountFallback;
  3040. }
  3041. suspense.isInFallback = true;
  3042. // unmount current active branch
  3043. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  3044. true // shouldRemove
  3045. );
  3046. if (!delayEnter) {
  3047. mountFallback();
  3048. }
  3049. },
  3050. move(container, anchor, type) {
  3051. suspense.activeBranch &&
  3052. move(suspense.activeBranch, container, anchor, type);
  3053. suspense.container = container;
  3054. },
  3055. next() {
  3056. return suspense.activeBranch && next(suspense.activeBranch);
  3057. },
  3058. registerDep(instance, setupRenderEffect) {
  3059. const isInPendingSuspense = !!suspense.pendingBranch;
  3060. if (isInPendingSuspense) {
  3061. suspense.deps++;
  3062. }
  3063. const hydratedEl = instance.vnode.el;
  3064. instance
  3065. .asyncDep.catch(err => {
  3066. handleError(err, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  3067. })
  3068. .then(asyncSetupResult => {
  3069. // retry when the setup() promise resolves.
  3070. // component may have been unmounted before resolve.
  3071. if (instance.isUnmounted ||
  3072. suspense.isUnmounted ||
  3073. suspense.pendingId !== instance.suspenseId) {
  3074. return;
  3075. }
  3076. // retry from this component
  3077. instance.asyncResolved = true;
  3078. const { vnode } = instance;
  3079. {
  3080. pushWarningContext(vnode);
  3081. }
  3082. handleSetupResult(instance, asyncSetupResult, false);
  3083. if (hydratedEl) {
  3084. // vnode may have been replaced if an update happened before the
  3085. // async dep is resolved.
  3086. vnode.el = hydratedEl;
  3087. }
  3088. const placeholder = !hydratedEl && instance.subTree.el;
  3089. setupRenderEffect(instance, vnode,
  3090. // component may have been moved before resolve.
  3091. // if this is not a hydration, instance.subTree will be the comment
  3092. // placeholder.
  3093. parentNode(hydratedEl || instance.subTree.el),
  3094. // anchor will not be used if this is hydration, so only need to
  3095. // consider the comment placeholder case.
  3096. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  3097. if (placeholder) {
  3098. remove(placeholder);
  3099. }
  3100. updateHOCHostEl(instance, vnode.el);
  3101. {
  3102. popWarningContext();
  3103. }
  3104. // only decrease deps count if suspense is not already resolved
  3105. if (isInPendingSuspense && --suspense.deps === 0) {
  3106. suspense.resolve();
  3107. }
  3108. });
  3109. },
  3110. unmount(parentSuspense, doRemove) {
  3111. suspense.isUnmounted = true;
  3112. if (suspense.activeBranch) {
  3113. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  3114. }
  3115. if (suspense.pendingBranch) {
  3116. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  3117. }
  3118. }
  3119. };
  3120. return suspense;
  3121. }
  3122. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  3123. /* eslint-disable no-restricted-globals */
  3124. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  3125. // there are two possible scenarios for server-rendered suspense:
  3126. // - success: ssr content should be fully resolved
  3127. // - failure: ssr content should be the fallback branch.
  3128. // however, on the client we don't really know if it has failed or not
  3129. // attempt to hydrate the DOM assuming it has succeeded, but we still
  3130. // need to construct a suspense boundary first
  3131. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  3132. if (suspense.deps === 0) {
  3133. suspense.resolve();
  3134. }
  3135. return result;
  3136. /* eslint-enable no-restricted-globals */
  3137. }
  3138. function normalizeSuspenseChildren(vnode) {
  3139. const { shapeFlag, children } = vnode;
  3140. const isSlotChildren = shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */;
  3141. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  3142. vnode.ssFallback = isSlotChildren
  3143. ? normalizeSuspenseSlot(children.fallback)
  3144. : createVNode(Comment);
  3145. }
  3146. function normalizeSuspenseSlot(s) {
  3147. let block;
  3148. if (isFunction(s)) {
  3149. const trackBlock = isBlockTreeEnabled && s._c;
  3150. if (trackBlock) {
  3151. // disableTracking: false
  3152. // allow block tracking for compiled slots
  3153. // (see ./componentRenderContext.ts)
  3154. s._d = false;
  3155. openBlock();
  3156. }
  3157. s = s();
  3158. if (trackBlock) {
  3159. s._d = true;
  3160. block = currentBlock;
  3161. closeBlock();
  3162. }
  3163. }
  3164. if (isArray(s)) {
  3165. const singleChild = filterSingleRoot(s);
  3166. if (!singleChild) {
  3167. warn(`<Suspense> slots expect a single root node.`);
  3168. }
  3169. s = singleChild;
  3170. }
  3171. s = normalizeVNode(s);
  3172. if (block && !s.dynamicChildren) {
  3173. s.dynamicChildren = block.filter(c => c !== s);
  3174. }
  3175. return s;
  3176. }
  3177. function queueEffectWithSuspense(fn, suspense) {
  3178. if (suspense && suspense.pendingBranch) {
  3179. if (isArray(fn)) {
  3180. suspense.effects.push(...fn);
  3181. }
  3182. else {
  3183. suspense.effects.push(fn);
  3184. }
  3185. }
  3186. else {
  3187. queuePostFlushCb(fn);
  3188. }
  3189. }
  3190. function setActiveBranch(suspense, branch) {
  3191. suspense.activeBranch = branch;
  3192. const { vnode, parentComponent } = suspense;
  3193. const el = (vnode.el = branch.el);
  3194. // in case suspense is the root node of a component,
  3195. // recursively update the HOC el
  3196. if (parentComponent && parentComponent.subTree === vnode) {
  3197. parentComponent.vnode.el = el;
  3198. updateHOCHostEl(parentComponent, el);
  3199. }
  3200. }
  3201. function provide(key, value) {
  3202. if (!currentInstance) {
  3203. {
  3204. warn(`provide() can only be used inside setup().`);
  3205. }
  3206. }
  3207. else {
  3208. let provides = currentInstance.provides;
  3209. // by default an instance inherits its parent's provides object
  3210. // but when it needs to provide values of its own, it creates its
  3211. // own provides object using parent provides object as prototype.
  3212. // this way in `inject` we can simply look up injections from direct
  3213. // parent and let the prototype chain do the work.
  3214. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3215. if (parentProvides === provides) {
  3216. provides = currentInstance.provides = Object.create(parentProvides);
  3217. }
  3218. // TS doesn't allow symbol as index type
  3219. provides[key] = value;
  3220. }
  3221. }
  3222. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3223. // fallback to `currentRenderingInstance` so that this can be called in
  3224. // a functional component
  3225. const instance = currentInstance || currentRenderingInstance;
  3226. if (instance) {
  3227. // #2400
  3228. // to support `app.use` plugins,
  3229. // fallback to appContext's `provides` if the instance is at root
  3230. const provides = instance.parent == null
  3231. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3232. : instance.parent.provides;
  3233. if (provides && key in provides) {
  3234. // TS doesn't allow symbol as index type
  3235. return provides[key];
  3236. }
  3237. else if (arguments.length > 1) {
  3238. return treatDefaultAsFactory && isFunction(defaultValue)
  3239. ? defaultValue.call(instance.proxy)
  3240. : defaultValue;
  3241. }
  3242. else {
  3243. warn(`injection "${String(key)}" not found.`);
  3244. }
  3245. }
  3246. else {
  3247. warn(`inject() can only be used inside setup() or functional components.`);
  3248. }
  3249. }
  3250. // Simple effect.
  3251. function watchEffect(effect, options) {
  3252. return doWatch(effect, null, options);
  3253. }
  3254. function watchPostEffect(effect, options) {
  3255. return doWatch(effect, null, Object.assign(Object.assign({}, options), { flush: 'post' }) );
  3256. }
  3257. function watchSyncEffect(effect, options) {
  3258. return doWatch(effect, null, Object.assign(Object.assign({}, options), { flush: 'sync' }) );
  3259. }
  3260. // initial value for watchers to trigger on undefined initial values
  3261. const INITIAL_WATCHER_VALUE = {};
  3262. // implementation
  3263. function watch(source, cb, options) {
  3264. if (!isFunction(cb)) {
  3265. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3266. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3267. `supports \`watch(source, cb, options?) signature.`);
  3268. }
  3269. return doWatch(source, cb, options);
  3270. }
  3271. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3272. if (!cb) {
  3273. if (immediate !== undefined) {
  3274. warn(`watch() "immediate" option is only respected when using the ` +
  3275. `watch(source, callback, options?) signature.`);
  3276. }
  3277. if (deep !== undefined) {
  3278. warn(`watch() "deep" option is only respected when using the ` +
  3279. `watch(source, callback, options?) signature.`);
  3280. }
  3281. }
  3282. const warnInvalidSource = (s) => {
  3283. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3284. `a reactive object, or an array of these types.`);
  3285. };
  3286. const instance = getCurrentScope() === (currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance.scope) ? currentInstance : null;
  3287. // const instance = currentInstance
  3288. let getter;
  3289. let forceTrigger = false;
  3290. let isMultiSource = false;
  3291. if (isRef(source)) {
  3292. getter = () => source.value;
  3293. forceTrigger = isShallow(source);
  3294. }
  3295. else if (isReactive(source)) {
  3296. getter = () => source;
  3297. deep = true;
  3298. }
  3299. else if (isArray(source)) {
  3300. isMultiSource = true;
  3301. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  3302. getter = () => source.map(s => {
  3303. if (isRef(s)) {
  3304. return s.value;
  3305. }
  3306. else if (isReactive(s)) {
  3307. return traverse(s);
  3308. }
  3309. else if (isFunction(s)) {
  3310. return callWithErrorHandling(s, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  3311. }
  3312. else {
  3313. warnInvalidSource(s);
  3314. }
  3315. });
  3316. }
  3317. else if (isFunction(source)) {
  3318. if (cb) {
  3319. // getter with cb
  3320. getter = () => callWithErrorHandling(source, instance, 2 /* ErrorCodes.WATCH_GETTER */);
  3321. }
  3322. else {
  3323. // no cb -> simple effect
  3324. getter = () => {
  3325. if (instance && instance.isUnmounted) {
  3326. return;
  3327. }
  3328. if (cleanup) {
  3329. cleanup();
  3330. }
  3331. return callWithAsyncErrorHandling(source, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [onCleanup]);
  3332. };
  3333. }
  3334. }
  3335. else {
  3336. getter = NOOP;
  3337. warnInvalidSource(source);
  3338. }
  3339. if (cb && deep) {
  3340. const baseGetter = getter;
  3341. getter = () => traverse(baseGetter());
  3342. }
  3343. let cleanup;
  3344. let onCleanup = (fn) => {
  3345. cleanup = effect.onStop = () => {
  3346. callWithErrorHandling(fn, instance, 4 /* ErrorCodes.WATCH_CLEANUP */);
  3347. };
  3348. };
  3349. let oldValue = isMultiSource
  3350. ? new Array(source.length).fill(INITIAL_WATCHER_VALUE)
  3351. : INITIAL_WATCHER_VALUE;
  3352. const job = () => {
  3353. if (!effect.active) {
  3354. return;
  3355. }
  3356. if (cb) {
  3357. // watch(source, cb)
  3358. const newValue = effect.run();
  3359. if (deep ||
  3360. forceTrigger ||
  3361. (isMultiSource
  3362. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3363. : hasChanged(newValue, oldValue)) ||
  3364. (false )) {
  3365. // cleanup before running cb again
  3366. if (cleanup) {
  3367. cleanup();
  3368. }
  3369. callWithAsyncErrorHandling(cb, instance, 3 /* ErrorCodes.WATCH_CALLBACK */, [
  3370. newValue,
  3371. // pass undefined as the old value when it's changed for the first time
  3372. oldValue === INITIAL_WATCHER_VALUE
  3373. ? undefined
  3374. : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE
  3375. ? []
  3376. : oldValue,
  3377. onCleanup
  3378. ]);
  3379. oldValue = newValue;
  3380. }
  3381. }
  3382. else {
  3383. // watchEffect
  3384. effect.run();
  3385. }
  3386. };
  3387. // important: mark the job as a watcher callback so that scheduler knows
  3388. // it is allowed to self-trigger (#1727)
  3389. job.allowRecurse = !!cb;
  3390. let scheduler;
  3391. if (flush === 'sync') {
  3392. scheduler = job; // the scheduler function gets called directly
  3393. }
  3394. else if (flush === 'post') {
  3395. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3396. }
  3397. else {
  3398. // default: 'pre'
  3399. job.pre = true;
  3400. if (instance)
  3401. job.id = instance.uid;
  3402. scheduler = () => queueJob(job);
  3403. }
  3404. const effect = new ReactiveEffect(getter, scheduler);
  3405. {
  3406. effect.onTrack = onTrack;
  3407. effect.onTrigger = onTrigger;
  3408. }
  3409. // initial run
  3410. if (cb) {
  3411. if (immediate) {
  3412. job();
  3413. }
  3414. else {
  3415. oldValue = effect.run();
  3416. }
  3417. }
  3418. else if (flush === 'post') {
  3419. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3420. }
  3421. else {
  3422. effect.run();
  3423. }
  3424. const unwatch = () => {
  3425. effect.stop();
  3426. if (instance && instance.scope) {
  3427. remove(instance.scope.effects, effect);
  3428. }
  3429. };
  3430. return unwatch;
  3431. }
  3432. // this.$watch
  3433. function instanceWatch(source, value, options) {
  3434. const publicThis = this.proxy;
  3435. const getter = isString(source)
  3436. ? source.includes('.')
  3437. ? createPathGetter(publicThis, source)
  3438. : () => publicThis[source]
  3439. : source.bind(publicThis, publicThis);
  3440. let cb;
  3441. if (isFunction(value)) {
  3442. cb = value;
  3443. }
  3444. else {
  3445. cb = value.handler;
  3446. options = value;
  3447. }
  3448. const cur = currentInstance;
  3449. setCurrentInstance(this);
  3450. const res = doWatch(getter, cb.bind(publicThis), options);
  3451. if (cur) {
  3452. setCurrentInstance(cur);
  3453. }
  3454. else {
  3455. unsetCurrentInstance();
  3456. }
  3457. return res;
  3458. }
  3459. function createPathGetter(ctx, path) {
  3460. const segments = path.split('.');
  3461. return () => {
  3462. let cur = ctx;
  3463. for (let i = 0; i < segments.length && cur; i++) {
  3464. cur = cur[segments[i]];
  3465. }
  3466. return cur;
  3467. };
  3468. }
  3469. function traverse(value, seen) {
  3470. if (!isObject(value) || value["__v_skip" /* ReactiveFlags.SKIP */]) {
  3471. return value;
  3472. }
  3473. seen = seen || new Set();
  3474. if (seen.has(value)) {
  3475. return value;
  3476. }
  3477. seen.add(value);
  3478. if (isRef(value)) {
  3479. traverse(value.value, seen);
  3480. }
  3481. else if (isArray(value)) {
  3482. for (let i = 0; i < value.length; i++) {
  3483. traverse(value[i], seen);
  3484. }
  3485. }
  3486. else if (isSet(value) || isMap(value)) {
  3487. value.forEach((v) => {
  3488. traverse(v, seen);
  3489. });
  3490. }
  3491. else if (isPlainObject(value)) {
  3492. for (const key in value) {
  3493. traverse(value[key], seen);
  3494. }
  3495. }
  3496. return value;
  3497. }
  3498. function useTransitionState() {
  3499. const state = {
  3500. isMounted: false,
  3501. isLeaving: false,
  3502. isUnmounting: false,
  3503. leavingVNodes: new Map()
  3504. };
  3505. onMounted(() => {
  3506. state.isMounted = true;
  3507. });
  3508. onBeforeUnmount(() => {
  3509. state.isUnmounting = true;
  3510. });
  3511. return state;
  3512. }
  3513. const TransitionHookValidator = [Function, Array];
  3514. const BaseTransitionImpl = {
  3515. name: `BaseTransition`,
  3516. props: {
  3517. mode: String,
  3518. appear: Boolean,
  3519. persisted: Boolean,
  3520. // enter
  3521. onBeforeEnter: TransitionHookValidator,
  3522. onEnter: TransitionHookValidator,
  3523. onAfterEnter: TransitionHookValidator,
  3524. onEnterCancelled: TransitionHookValidator,
  3525. // leave
  3526. onBeforeLeave: TransitionHookValidator,
  3527. onLeave: TransitionHookValidator,
  3528. onAfterLeave: TransitionHookValidator,
  3529. onLeaveCancelled: TransitionHookValidator,
  3530. // appear
  3531. onBeforeAppear: TransitionHookValidator,
  3532. onAppear: TransitionHookValidator,
  3533. onAfterAppear: TransitionHookValidator,
  3534. onAppearCancelled: TransitionHookValidator
  3535. },
  3536. setup(props, { slots }) {
  3537. const instance = getCurrentInstance();
  3538. const state = useTransitionState();
  3539. let prevTransitionKey;
  3540. return () => {
  3541. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3542. if (!children || !children.length) {
  3543. return;
  3544. }
  3545. let child = children[0];
  3546. if (children.length > 1) {
  3547. let hasFound = false;
  3548. // locate first non-comment child
  3549. for (const c of children) {
  3550. if (c.type !== Comment) {
  3551. if (hasFound) {
  3552. // warn more than one non-comment child
  3553. warn('<transition> can only be used on a single element or component. ' +
  3554. 'Use <transition-group> for lists.');
  3555. break;
  3556. }
  3557. child = c;
  3558. hasFound = true;
  3559. }
  3560. }
  3561. }
  3562. // there's no need to track reactivity for these props so use the raw
  3563. // props for a bit better perf
  3564. const rawProps = toRaw(props);
  3565. const { mode } = rawProps;
  3566. // check mode
  3567. if (mode &&
  3568. mode !== 'in-out' &&
  3569. mode !== 'out-in' &&
  3570. mode !== 'default') {
  3571. warn(`invalid <transition> mode: ${mode}`);
  3572. }
  3573. if (state.isLeaving) {
  3574. return emptyPlaceholder(child);
  3575. }
  3576. // in the case of <transition><keep-alive/></transition>, we need to
  3577. // compare the type of the kept-alive children.
  3578. const innerChild = getKeepAliveChild(child);
  3579. if (!innerChild) {
  3580. return emptyPlaceholder(child);
  3581. }
  3582. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3583. setTransitionHooks(innerChild, enterHooks);
  3584. const oldChild = instance.subTree;
  3585. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3586. let transitionKeyChanged = false;
  3587. const { getTransitionKey } = innerChild.type;
  3588. if (getTransitionKey) {
  3589. const key = getTransitionKey();
  3590. if (prevTransitionKey === undefined) {
  3591. prevTransitionKey = key;
  3592. }
  3593. else if (key !== prevTransitionKey) {
  3594. prevTransitionKey = key;
  3595. transitionKeyChanged = true;
  3596. }
  3597. }
  3598. // handle mode
  3599. if (oldInnerChild &&
  3600. oldInnerChild.type !== Comment &&
  3601. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3602. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3603. // update old tree's hooks in case of dynamic transition
  3604. setTransitionHooks(oldInnerChild, leavingHooks);
  3605. // switching between different views
  3606. if (mode === 'out-in') {
  3607. state.isLeaving = true;
  3608. // return placeholder node and queue update when leave finishes
  3609. leavingHooks.afterLeave = () => {
  3610. state.isLeaving = false;
  3611. // #6835
  3612. // it also needs to be updated when active is undefined
  3613. if (instance.update.active !== false) {
  3614. instance.update();
  3615. }
  3616. };
  3617. return emptyPlaceholder(child);
  3618. }
  3619. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3620. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3621. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3622. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3623. // early removal callback
  3624. el._leaveCb = () => {
  3625. earlyRemove();
  3626. el._leaveCb = undefined;
  3627. delete enterHooks.delayedLeave;
  3628. };
  3629. enterHooks.delayedLeave = delayedLeave;
  3630. };
  3631. }
  3632. }
  3633. return child;
  3634. };
  3635. }
  3636. };
  3637. // export the public type for h/tsx inference
  3638. // also to avoid inline import() in generated d.ts files
  3639. const BaseTransition = BaseTransitionImpl;
  3640. function getLeavingNodesForType(state, vnode) {
  3641. const { leavingVNodes } = state;
  3642. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3643. if (!leavingVNodesCache) {
  3644. leavingVNodesCache = Object.create(null);
  3645. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3646. }
  3647. return leavingVNodesCache;
  3648. }
  3649. // The transition hooks are attached to the vnode as vnode.transition
  3650. // and will be called at appropriate timing in the renderer.
  3651. function resolveTransitionHooks(vnode, props, state, instance) {
  3652. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3653. const key = String(vnode.key);
  3654. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3655. const callHook = (hook, args) => {
  3656. hook &&
  3657. callWithAsyncErrorHandling(hook, instance, 9 /* ErrorCodes.TRANSITION_HOOK */, args);
  3658. };
  3659. const callAsyncHook = (hook, args) => {
  3660. const done = args[1];
  3661. callHook(hook, args);
  3662. if (isArray(hook)) {
  3663. if (hook.every(hook => hook.length <= 1))
  3664. done();
  3665. }
  3666. else if (hook.length <= 1) {
  3667. done();
  3668. }
  3669. };
  3670. const hooks = {
  3671. mode,
  3672. persisted,
  3673. beforeEnter(el) {
  3674. let hook = onBeforeEnter;
  3675. if (!state.isMounted) {
  3676. if (appear) {
  3677. hook = onBeforeAppear || onBeforeEnter;
  3678. }
  3679. else {
  3680. return;
  3681. }
  3682. }
  3683. // for same element (v-show)
  3684. if (el._leaveCb) {
  3685. el._leaveCb(true /* cancelled */);
  3686. }
  3687. // for toggled element with same key (v-if)
  3688. const leavingVNode = leavingVNodesCache[key];
  3689. if (leavingVNode &&
  3690. isSameVNodeType(vnode, leavingVNode) &&
  3691. leavingVNode.el._leaveCb) {
  3692. // force early removal (not cancelled)
  3693. leavingVNode.el._leaveCb();
  3694. }
  3695. callHook(hook, [el]);
  3696. },
  3697. enter(el) {
  3698. let hook = onEnter;
  3699. let afterHook = onAfterEnter;
  3700. let cancelHook = onEnterCancelled;
  3701. if (!state.isMounted) {
  3702. if (appear) {
  3703. hook = onAppear || onEnter;
  3704. afterHook = onAfterAppear || onAfterEnter;
  3705. cancelHook = onAppearCancelled || onEnterCancelled;
  3706. }
  3707. else {
  3708. return;
  3709. }
  3710. }
  3711. let called = false;
  3712. const done = (el._enterCb = (cancelled) => {
  3713. if (called)
  3714. return;
  3715. called = true;
  3716. if (cancelled) {
  3717. callHook(cancelHook, [el]);
  3718. }
  3719. else {
  3720. callHook(afterHook, [el]);
  3721. }
  3722. if (hooks.delayedLeave) {
  3723. hooks.delayedLeave();
  3724. }
  3725. el._enterCb = undefined;
  3726. });
  3727. if (hook) {
  3728. callAsyncHook(hook, [el, done]);
  3729. }
  3730. else {
  3731. done();
  3732. }
  3733. },
  3734. leave(el, remove) {
  3735. const key = String(vnode.key);
  3736. if (el._enterCb) {
  3737. el._enterCb(true /* cancelled */);
  3738. }
  3739. if (state.isUnmounting) {
  3740. return remove();
  3741. }
  3742. callHook(onBeforeLeave, [el]);
  3743. let called = false;
  3744. const done = (el._leaveCb = (cancelled) => {
  3745. if (called)
  3746. return;
  3747. called = true;
  3748. remove();
  3749. if (cancelled) {
  3750. callHook(onLeaveCancelled, [el]);
  3751. }
  3752. else {
  3753. callHook(onAfterLeave, [el]);
  3754. }
  3755. el._leaveCb = undefined;
  3756. if (leavingVNodesCache[key] === vnode) {
  3757. delete leavingVNodesCache[key];
  3758. }
  3759. });
  3760. leavingVNodesCache[key] = vnode;
  3761. if (onLeave) {
  3762. callAsyncHook(onLeave, [el, done]);
  3763. }
  3764. else {
  3765. done();
  3766. }
  3767. },
  3768. clone(vnode) {
  3769. return resolveTransitionHooks(vnode, props, state, instance);
  3770. }
  3771. };
  3772. return hooks;
  3773. }
  3774. // the placeholder really only handles one special case: KeepAlive
  3775. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3776. // placeholder with empty content to avoid the KeepAlive instance from being
  3777. // unmounted.
  3778. function emptyPlaceholder(vnode) {
  3779. if (isKeepAlive(vnode)) {
  3780. vnode = cloneVNode(vnode);
  3781. vnode.children = null;
  3782. return vnode;
  3783. }
  3784. }
  3785. function getKeepAliveChild(vnode) {
  3786. return isKeepAlive(vnode)
  3787. ? vnode.children
  3788. ? vnode.children[0]
  3789. : undefined
  3790. : vnode;
  3791. }
  3792. function setTransitionHooks(vnode, hooks) {
  3793. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */ && vnode.component) {
  3794. setTransitionHooks(vnode.component.subTree, hooks);
  3795. }
  3796. else if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  3797. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3798. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3799. }
  3800. else {
  3801. vnode.transition = hooks;
  3802. }
  3803. }
  3804. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3805. let ret = [];
  3806. let keyedFragmentCount = 0;
  3807. for (let i = 0; i < children.length; i++) {
  3808. let child = children[i];
  3809. // #5360 inherit parent key in case of <template v-for>
  3810. const key = parentKey == null
  3811. ? child.key
  3812. : String(parentKey) + String(child.key != null ? child.key : i);
  3813. // handle fragment children case, e.g. v-for
  3814. if (child.type === Fragment) {
  3815. if (child.patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */)
  3816. keyedFragmentCount++;
  3817. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3818. }
  3819. // comment placeholders should be skipped, e.g. v-if
  3820. else if (keepComment || child.type !== Comment) {
  3821. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3822. }
  3823. }
  3824. // #1126 if a transition children list contains multiple sub fragments, these
  3825. // fragments will be merged into a flat children array. Since each v-for
  3826. // fragment may contain different static bindings inside, we need to de-op
  3827. // these children to force full diffs to ensure correct behavior.
  3828. if (keyedFragmentCount > 1) {
  3829. for (let i = 0; i < ret.length; i++) {
  3830. ret[i].patchFlag = -2 /* PatchFlags.BAIL */;
  3831. }
  3832. }
  3833. return ret;
  3834. }
  3835. // implementation, close to no-op
  3836. function defineComponent(options) {
  3837. return isFunction(options) ? { setup: options, name: options.name } : options;
  3838. }
  3839. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3840. function defineAsyncComponent(source) {
  3841. if (isFunction(source)) {
  3842. source = { loader: source };
  3843. }
  3844. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3845. suspensible = true, onError: userOnError } = source;
  3846. let pendingRequest = null;
  3847. let resolvedComp;
  3848. let retries = 0;
  3849. const retry = () => {
  3850. retries++;
  3851. pendingRequest = null;
  3852. return load();
  3853. };
  3854. const load = () => {
  3855. let thisRequest;
  3856. return (pendingRequest ||
  3857. (thisRequest = pendingRequest =
  3858. loader()
  3859. .catch(err => {
  3860. err = err instanceof Error ? err : new Error(String(err));
  3861. if (userOnError) {
  3862. return new Promise((resolve, reject) => {
  3863. const userRetry = () => resolve(retry());
  3864. const userFail = () => reject(err);
  3865. userOnError(err, userRetry, userFail, retries + 1);
  3866. });
  3867. }
  3868. else {
  3869. throw err;
  3870. }
  3871. })
  3872. .then((comp) => {
  3873. if (thisRequest !== pendingRequest && pendingRequest) {
  3874. return pendingRequest;
  3875. }
  3876. if (!comp) {
  3877. warn(`Async component loader resolved to undefined. ` +
  3878. `If you are using retry(), make sure to return its return value.`);
  3879. }
  3880. // interop module default
  3881. if (comp &&
  3882. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3883. comp = comp.default;
  3884. }
  3885. if (comp && !isObject(comp) && !isFunction(comp)) {
  3886. throw new Error(`Invalid async component load result: ${comp}`);
  3887. }
  3888. resolvedComp = comp;
  3889. return comp;
  3890. })));
  3891. };
  3892. return defineComponent({
  3893. name: 'AsyncComponentWrapper',
  3894. __asyncLoader: load,
  3895. get __asyncResolved() {
  3896. return resolvedComp;
  3897. },
  3898. setup() {
  3899. const instance = currentInstance;
  3900. // already resolved
  3901. if (resolvedComp) {
  3902. return () => createInnerComp(resolvedComp, instance);
  3903. }
  3904. const onError = (err) => {
  3905. pendingRequest = null;
  3906. handleError(err, instance, 13 /* ErrorCodes.ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3907. };
  3908. // suspense-controlled or SSR.
  3909. if ((suspensible && instance.suspense) ||
  3910. (false )) {
  3911. return load()
  3912. .then(comp => {
  3913. return () => createInnerComp(comp, instance);
  3914. })
  3915. .catch(err => {
  3916. onError(err);
  3917. return () => errorComponent
  3918. ? createVNode(errorComponent, {
  3919. error: err
  3920. })
  3921. : null;
  3922. });
  3923. }
  3924. const loaded = ref(false);
  3925. const error = ref();
  3926. const delayed = ref(!!delay);
  3927. if (delay) {
  3928. setTimeout(() => {
  3929. delayed.value = false;
  3930. }, delay);
  3931. }
  3932. if (timeout != null) {
  3933. setTimeout(() => {
  3934. if (!loaded.value && !error.value) {
  3935. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3936. onError(err);
  3937. error.value = err;
  3938. }
  3939. }, timeout);
  3940. }
  3941. load()
  3942. .then(() => {
  3943. loaded.value = true;
  3944. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3945. // parent is keep-alive, force update so the loaded component's
  3946. // name is taken into account
  3947. queueJob(instance.parent.update);
  3948. }
  3949. })
  3950. .catch(err => {
  3951. onError(err);
  3952. error.value = err;
  3953. });
  3954. return () => {
  3955. if (loaded.value && resolvedComp) {
  3956. return createInnerComp(resolvedComp, instance);
  3957. }
  3958. else if (error.value && errorComponent) {
  3959. return createVNode(errorComponent, {
  3960. error: error.value
  3961. });
  3962. }
  3963. else if (loadingComponent && !delayed.value) {
  3964. return createVNode(loadingComponent);
  3965. }
  3966. };
  3967. }
  3968. });
  3969. }
  3970. function createInnerComp(comp, parent) {
  3971. const { ref, props, children, ce } = parent.vnode;
  3972. const vnode = createVNode(comp, props, children);
  3973. // ensure inner component inherits the async wrapper's ref owner
  3974. vnode.ref = ref;
  3975. // pass the custom element callback on to the inner comp
  3976. // and remove it from the async wrapper
  3977. vnode.ce = ce;
  3978. delete parent.vnode.ce;
  3979. return vnode;
  3980. }
  3981. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3982. const KeepAliveImpl = {
  3983. name: `KeepAlive`,
  3984. // Marker for special handling inside the renderer. We are not using a ===
  3985. // check directly on KeepAlive in the renderer, because importing it directly
  3986. // would prevent it from being tree-shaken.
  3987. __isKeepAlive: true,
  3988. props: {
  3989. include: [String, RegExp, Array],
  3990. exclude: [String, RegExp, Array],
  3991. max: [String, Number]
  3992. },
  3993. setup(props, { slots }) {
  3994. const instance = getCurrentInstance();
  3995. // KeepAlive communicates with the instantiated renderer via the
  3996. // ctx where the renderer passes in its internals,
  3997. // and the KeepAlive instance exposes activate/deactivate implementations.
  3998. // The whole point of this is to avoid importing KeepAlive directly in the
  3999. // renderer to facilitate tree-shaking.
  4000. const sharedContext = instance.ctx;
  4001. const cache = new Map();
  4002. const keys = new Set();
  4003. let current = null;
  4004. {
  4005. instance.__v_cache = cache;
  4006. }
  4007. const parentSuspense = instance.suspense;
  4008. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  4009. const storageContainer = createElement('div');
  4010. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  4011. const instance = vnode.component;
  4012. move(vnode, container, anchor, 0 /* MoveType.ENTER */, parentSuspense);
  4013. // in case props have changed
  4014. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  4015. queuePostRenderEffect(() => {
  4016. instance.isDeactivated = false;
  4017. if (instance.a) {
  4018. invokeArrayFns(instance.a);
  4019. }
  4020. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  4021. if (vnodeHook) {
  4022. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  4023. }
  4024. }, parentSuspense);
  4025. {
  4026. // Update components tree
  4027. devtoolsComponentAdded(instance);
  4028. }
  4029. };
  4030. sharedContext.deactivate = (vnode) => {
  4031. const instance = vnode.component;
  4032. move(vnode, storageContainer, null, 1 /* MoveType.LEAVE */, parentSuspense);
  4033. queuePostRenderEffect(() => {
  4034. if (instance.da) {
  4035. invokeArrayFns(instance.da);
  4036. }
  4037. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  4038. if (vnodeHook) {
  4039. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  4040. }
  4041. instance.isDeactivated = true;
  4042. }, parentSuspense);
  4043. {
  4044. // Update components tree
  4045. devtoolsComponentAdded(instance);
  4046. }
  4047. };
  4048. function unmount(vnode) {
  4049. // reset the shapeFlag so it can be properly unmounted
  4050. resetShapeFlag(vnode);
  4051. _unmount(vnode, instance, parentSuspense, true);
  4052. }
  4053. function pruneCache(filter) {
  4054. cache.forEach((vnode, key) => {
  4055. const name = getComponentName(vnode.type);
  4056. if (name && (!filter || !filter(name))) {
  4057. pruneCacheEntry(key);
  4058. }
  4059. });
  4060. }
  4061. function pruneCacheEntry(key) {
  4062. const cached = cache.get(key);
  4063. if (!current || !isSameVNodeType(cached, current)) {
  4064. unmount(cached);
  4065. }
  4066. else if (current) {
  4067. // current active instance should no longer be kept-alive.
  4068. // we can't unmount it now but it might be later, so reset its flag now.
  4069. resetShapeFlag(current);
  4070. }
  4071. cache.delete(key);
  4072. keys.delete(key);
  4073. }
  4074. // prune cache on include/exclude prop change
  4075. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  4076. include && pruneCache(name => matches(include, name));
  4077. exclude && pruneCache(name => !matches(exclude, name));
  4078. },
  4079. // prune post-render after `current` has been updated
  4080. { flush: 'post', deep: true });
  4081. // cache sub tree after render
  4082. let pendingCacheKey = null;
  4083. const cacheSubtree = () => {
  4084. // fix #1621, the pendingCacheKey could be 0
  4085. if (pendingCacheKey != null) {
  4086. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  4087. }
  4088. };
  4089. onMounted(cacheSubtree);
  4090. onUpdated(cacheSubtree);
  4091. onBeforeUnmount(() => {
  4092. cache.forEach(cached => {
  4093. const { subTree, suspense } = instance;
  4094. const vnode = getInnerChild(subTree);
  4095. if (cached.type === vnode.type && cached.key === vnode.key) {
  4096. // current instance will be unmounted as part of keep-alive's unmount
  4097. resetShapeFlag(vnode);
  4098. // but invoke its deactivated hook here
  4099. const da = vnode.component.da;
  4100. da && queuePostRenderEffect(da, suspense);
  4101. return;
  4102. }
  4103. unmount(cached);
  4104. });
  4105. });
  4106. return () => {
  4107. pendingCacheKey = null;
  4108. if (!slots.default) {
  4109. return null;
  4110. }
  4111. const children = slots.default();
  4112. const rawVNode = children[0];
  4113. if (children.length > 1) {
  4114. {
  4115. warn(`KeepAlive should contain exactly one component child.`);
  4116. }
  4117. current = null;
  4118. return children;
  4119. }
  4120. else if (!isVNode(rawVNode) ||
  4121. (!(rawVNode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */) &&
  4122. !(rawVNode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */))) {
  4123. current = null;
  4124. return rawVNode;
  4125. }
  4126. let vnode = getInnerChild(rawVNode);
  4127. const comp = vnode.type;
  4128. // for async components, name check should be based in its loaded
  4129. // inner component if available
  4130. const name = getComponentName(isAsyncWrapper(vnode)
  4131. ? vnode.type.__asyncResolved || {}
  4132. : comp);
  4133. const { include, exclude, max } = props;
  4134. if ((include && (!name || !matches(include, name))) ||
  4135. (exclude && name && matches(exclude, name))) {
  4136. current = vnode;
  4137. return rawVNode;
  4138. }
  4139. const key = vnode.key == null ? comp : vnode.key;
  4140. const cachedVNode = cache.get(key);
  4141. // clone vnode if it's reused because we are going to mutate it
  4142. if (vnode.el) {
  4143. vnode = cloneVNode(vnode);
  4144. if (rawVNode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  4145. rawVNode.ssContent = vnode;
  4146. }
  4147. }
  4148. // #1513 it's possible for the returned vnode to be cloned due to attr
  4149. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4150. // that is mounted. Instead of caching it directly, we store the pending
  4151. // key and cache `instance.subTree` (the normalized vnode) in
  4152. // beforeMount/beforeUpdate hooks.
  4153. pendingCacheKey = key;
  4154. if (cachedVNode) {
  4155. // copy over mounted state
  4156. vnode.el = cachedVNode.el;
  4157. vnode.component = cachedVNode.component;
  4158. if (vnode.transition) {
  4159. // recursively update transition hooks on subTree
  4160. setTransitionHooks(vnode, vnode.transition);
  4161. }
  4162. // avoid vnode being mounted as fresh
  4163. vnode.shapeFlag |= 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  4164. // make this key the freshest
  4165. keys.delete(key);
  4166. keys.add(key);
  4167. }
  4168. else {
  4169. keys.add(key);
  4170. // prune oldest entry
  4171. if (max && keys.size > parseInt(max, 10)) {
  4172. pruneCacheEntry(keys.values().next().value);
  4173. }
  4174. }
  4175. // avoid vnode being unmounted
  4176. vnode.shapeFlag |= 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  4177. current = vnode;
  4178. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  4179. };
  4180. }
  4181. };
  4182. // export the public type for h/tsx inference
  4183. // also to avoid inline import() in generated d.ts files
  4184. const KeepAlive = KeepAliveImpl;
  4185. function matches(pattern, name) {
  4186. if (isArray(pattern)) {
  4187. return pattern.some((p) => matches(p, name));
  4188. }
  4189. else if (isString(pattern)) {
  4190. return pattern.split(',').includes(name);
  4191. }
  4192. else if (isRegExp(pattern)) {
  4193. return pattern.test(name);
  4194. }
  4195. /* istanbul ignore next */
  4196. return false;
  4197. }
  4198. function onActivated(hook, target) {
  4199. registerKeepAliveHook(hook, "a" /* LifecycleHooks.ACTIVATED */, target);
  4200. }
  4201. function onDeactivated(hook, target) {
  4202. registerKeepAliveHook(hook, "da" /* LifecycleHooks.DEACTIVATED */, target);
  4203. }
  4204. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4205. // cache the deactivate branch check wrapper for injected hooks so the same
  4206. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4207. // deactivation check".
  4208. const wrappedHook = hook.__wdc ||
  4209. (hook.__wdc = () => {
  4210. // only fire the hook if the target instance is NOT in a deactivated branch.
  4211. let current = target;
  4212. while (current) {
  4213. if (current.isDeactivated) {
  4214. return;
  4215. }
  4216. current = current.parent;
  4217. }
  4218. return hook();
  4219. });
  4220. injectHook(type, wrappedHook, target);
  4221. // In addition to registering it on the target instance, we walk up the parent
  4222. // chain and register it on all ancestor instances that are keep-alive roots.
  4223. // This avoids the need to walk the entire component tree when invoking these
  4224. // hooks, and more importantly, avoids the need to track child components in
  4225. // arrays.
  4226. if (target) {
  4227. let current = target.parent;
  4228. while (current && current.parent) {
  4229. if (isKeepAlive(current.parent.vnode)) {
  4230. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4231. }
  4232. current = current.parent;
  4233. }
  4234. }
  4235. }
  4236. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4237. // injectHook wraps the original for error handling, so make sure to remove
  4238. // the wrapped version.
  4239. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4240. onUnmounted(() => {
  4241. remove(keepAliveRoot[type], injected);
  4242. }, target);
  4243. }
  4244. function resetShapeFlag(vnode) {
  4245. // bitwise operations to remove keep alive flags
  4246. vnode.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  4247. vnode.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  4248. }
  4249. function getInnerChild(vnode) {
  4250. return vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */ ? vnode.ssContent : vnode;
  4251. }
  4252. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4253. if (target) {
  4254. const hooks = target[type] || (target[type] = []);
  4255. // cache the error handling wrapper for injected hooks so the same hook
  4256. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4257. // handling".
  4258. const wrappedHook = hook.__weh ||
  4259. (hook.__weh = (...args) => {
  4260. if (target.isUnmounted) {
  4261. return;
  4262. }
  4263. // disable tracking inside all lifecycle hooks
  4264. // since they can potentially be called inside effects.
  4265. pauseTracking();
  4266. // Set currentInstance during hook invocation.
  4267. // This assumes the hook does not synchronously trigger other hooks, which
  4268. // can only be false when the user does something really funky.
  4269. setCurrentInstance(target);
  4270. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4271. unsetCurrentInstance();
  4272. resetTracking();
  4273. return res;
  4274. });
  4275. if (prepend) {
  4276. hooks.unshift(wrappedHook);
  4277. }
  4278. else {
  4279. hooks.push(wrappedHook);
  4280. }
  4281. return wrappedHook;
  4282. }
  4283. else {
  4284. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4285. warn(`${apiName} is called when there is no active component instance to be ` +
  4286. `associated with. ` +
  4287. `Lifecycle injection APIs can only be used during execution of setup().` +
  4288. (` If you are using async setup(), make sure to register lifecycle ` +
  4289. `hooks before the first await statement.`
  4290. ));
  4291. }
  4292. }
  4293. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4294. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4295. (!isInSSRComponentSetup || lifecycle === "sp" /* LifecycleHooks.SERVER_PREFETCH */) &&
  4296. injectHook(lifecycle, (...args) => hook(...args), target);
  4297. const onBeforeMount = createHook("bm" /* LifecycleHooks.BEFORE_MOUNT */);
  4298. const onMounted = createHook("m" /* LifecycleHooks.MOUNTED */);
  4299. const onBeforeUpdate = createHook("bu" /* LifecycleHooks.BEFORE_UPDATE */);
  4300. const onUpdated = createHook("u" /* LifecycleHooks.UPDATED */);
  4301. const onBeforeUnmount = createHook("bum" /* LifecycleHooks.BEFORE_UNMOUNT */);
  4302. const onUnmounted = createHook("um" /* LifecycleHooks.UNMOUNTED */);
  4303. const onServerPrefetch = createHook("sp" /* LifecycleHooks.SERVER_PREFETCH */);
  4304. const onRenderTriggered = createHook("rtg" /* LifecycleHooks.RENDER_TRIGGERED */);
  4305. const onRenderTracked = createHook("rtc" /* LifecycleHooks.RENDER_TRACKED */);
  4306. function onErrorCaptured(hook, target = currentInstance) {
  4307. injectHook("ec" /* LifecycleHooks.ERROR_CAPTURED */, hook, target);
  4308. }
  4309. /**
  4310. Runtime helper for applying directives to a vnode. Example usage:
  4311. const comp = resolveComponent('comp')
  4312. const foo = resolveDirective('foo')
  4313. const bar = resolveDirective('bar')
  4314. return withDirectives(h(comp), [
  4315. [foo, this.x],
  4316. [bar, this.y]
  4317. ])
  4318. */
  4319. function validateDirectiveName(name) {
  4320. if (isBuiltInDirective(name)) {
  4321. warn('Do not use built-in directive ids as custom directive id: ' + name);
  4322. }
  4323. }
  4324. /**
  4325. * Adds directives to a VNode.
  4326. */
  4327. function withDirectives(vnode, directives) {
  4328. const internalInstance = currentRenderingInstance;
  4329. if (internalInstance === null) {
  4330. warn(`withDirectives can only be used inside render functions.`);
  4331. return vnode;
  4332. }
  4333. const instance = getExposeProxy(internalInstance) ||
  4334. internalInstance.proxy;
  4335. const bindings = vnode.dirs || (vnode.dirs = []);
  4336. for (let i = 0; i < directives.length; i++) {
  4337. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4338. if (dir) {
  4339. if (isFunction(dir)) {
  4340. dir = {
  4341. mounted: dir,
  4342. updated: dir
  4343. };
  4344. }
  4345. if (dir.deep) {
  4346. traverse(value);
  4347. }
  4348. bindings.push({
  4349. dir,
  4350. instance,
  4351. value,
  4352. oldValue: void 0,
  4353. arg,
  4354. modifiers
  4355. });
  4356. }
  4357. }
  4358. return vnode;
  4359. }
  4360. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4361. const bindings = vnode.dirs;
  4362. const oldBindings = prevVNode && prevVNode.dirs;
  4363. for (let i = 0; i < bindings.length; i++) {
  4364. const binding = bindings[i];
  4365. if (oldBindings) {
  4366. binding.oldValue = oldBindings[i].value;
  4367. }
  4368. let hook = binding.dir[name];
  4369. if (hook) {
  4370. // disable tracking inside all lifecycle hooks
  4371. // since they can potentially be called inside effects.
  4372. pauseTracking();
  4373. callWithAsyncErrorHandling(hook, instance, 8 /* ErrorCodes.DIRECTIVE_HOOK */, [
  4374. vnode.el,
  4375. binding,
  4376. vnode,
  4377. prevVNode
  4378. ]);
  4379. resetTracking();
  4380. }
  4381. }
  4382. }
  4383. const COMPONENTS = 'components';
  4384. const DIRECTIVES = 'directives';
  4385. /**
  4386. * @private
  4387. */
  4388. function resolveComponent(name, maybeSelfReference) {
  4389. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  4390. }
  4391. const NULL_DYNAMIC_COMPONENT = Symbol();
  4392. /**
  4393. * @private
  4394. */
  4395. function resolveDynamicComponent(component) {
  4396. if (isString(component)) {
  4397. return resolveAsset(COMPONENTS, component, false) || component;
  4398. }
  4399. else {
  4400. // invalid types will fallthrough to createVNode and raise warning
  4401. return (component || NULL_DYNAMIC_COMPONENT);
  4402. }
  4403. }
  4404. /**
  4405. * @private
  4406. */
  4407. function resolveDirective(name) {
  4408. return resolveAsset(DIRECTIVES, name);
  4409. }
  4410. // implementation
  4411. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  4412. const instance = currentRenderingInstance || currentInstance;
  4413. if (instance) {
  4414. const Component = instance.type;
  4415. // explicit self name has highest priority
  4416. if (type === COMPONENTS) {
  4417. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  4418. if (selfName &&
  4419. (selfName === name ||
  4420. selfName === camelize(name) ||
  4421. selfName === capitalize(camelize(name)))) {
  4422. return Component;
  4423. }
  4424. }
  4425. const res =
  4426. // local registration
  4427. // check instance[type] first which is resolved for options API
  4428. resolve(instance[type] || Component[type], name) ||
  4429. // global registration
  4430. resolve(instance.appContext[type], name);
  4431. if (!res && maybeSelfReference) {
  4432. // fallback to implicit self-reference
  4433. return Component;
  4434. }
  4435. if (warnMissing && !res) {
  4436. const extra = type === COMPONENTS
  4437. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  4438. `component resolution via compilerOptions.isCustomElement.`
  4439. : ``;
  4440. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  4441. }
  4442. return res;
  4443. }
  4444. else {
  4445. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  4446. `can only be used in render() or setup().`);
  4447. }
  4448. }
  4449. function resolve(registry, name) {
  4450. return (registry &&
  4451. (registry[name] ||
  4452. registry[camelize(name)] ||
  4453. registry[capitalize(camelize(name))]));
  4454. }
  4455. /**
  4456. * Actual implementation
  4457. */
  4458. function renderList(source, renderItem, cache, index) {
  4459. let ret;
  4460. const cached = (cache && cache[index]);
  4461. if (isArray(source) || isString(source)) {
  4462. ret = new Array(source.length);
  4463. for (let i = 0, l = source.length; i < l; i++) {
  4464. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  4465. }
  4466. }
  4467. else if (typeof source === 'number') {
  4468. if (!Number.isInteger(source)) {
  4469. warn(`The v-for range expect an integer value but got ${source}.`);
  4470. }
  4471. ret = new Array(source);
  4472. for (let i = 0; i < source; i++) {
  4473. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  4474. }
  4475. }
  4476. else if (isObject(source)) {
  4477. if (source[Symbol.iterator]) {
  4478. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  4479. }
  4480. else {
  4481. const keys = Object.keys(source);
  4482. ret = new Array(keys.length);
  4483. for (let i = 0, l = keys.length; i < l; i++) {
  4484. const key = keys[i];
  4485. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  4486. }
  4487. }
  4488. }
  4489. else {
  4490. ret = [];
  4491. }
  4492. if (cache) {
  4493. cache[index] = ret;
  4494. }
  4495. return ret;
  4496. }
  4497. /**
  4498. * Compiler runtime helper for creating dynamic slots object
  4499. * @private
  4500. */
  4501. function createSlots(slots, dynamicSlots) {
  4502. for (let i = 0; i < dynamicSlots.length; i++) {
  4503. const slot = dynamicSlots[i];
  4504. // array of dynamic slot generated by <template v-for="..." #[...]>
  4505. if (isArray(slot)) {
  4506. for (let j = 0; j < slot.length; j++) {
  4507. slots[slot[j].name] = slot[j].fn;
  4508. }
  4509. }
  4510. else if (slot) {
  4511. // conditional single slot generated by <template v-if="..." #foo>
  4512. slots[slot.name] = slot.key
  4513. ? (...args) => {
  4514. const res = slot.fn(...args);
  4515. // attach branch key so each conditional branch is considered a
  4516. // different fragment
  4517. if (res)
  4518. res.key = slot.key;
  4519. return res;
  4520. }
  4521. : slot.fn;
  4522. }
  4523. }
  4524. return slots;
  4525. }
  4526. /**
  4527. * Compiler runtime helper for rendering `<slot/>`
  4528. * @private
  4529. */
  4530. function renderSlot(slots, name, props = {},
  4531. // this is not a user-facing function, so the fallback is always generated by
  4532. // the compiler and guaranteed to be a function returning an array
  4533. fallback, noSlotted) {
  4534. if (currentRenderingInstance.isCE ||
  4535. (currentRenderingInstance.parent &&
  4536. isAsyncWrapper(currentRenderingInstance.parent) &&
  4537. currentRenderingInstance.parent.isCE)) {
  4538. if (name !== 'default')
  4539. props.name = name;
  4540. return createVNode('slot', props, fallback && fallback());
  4541. }
  4542. let slot = slots[name];
  4543. if (slot && slot.length > 1) {
  4544. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  4545. `function. You need to mark this component with $dynamic-slots in the ` +
  4546. `parent template.`);
  4547. slot = () => [];
  4548. }
  4549. // a compiled slot disables block tracking by default to avoid manual
  4550. // invocation interfering with template-based block tracking, but in
  4551. // `renderSlot` we can be sure that it's template-based so we can force
  4552. // enable it.
  4553. if (slot && slot._c) {
  4554. slot._d = false;
  4555. }
  4556. openBlock();
  4557. const validSlotContent = slot && ensureValidVNode(slot(props));
  4558. const rendered = createBlock(Fragment, {
  4559. key: props.key ||
  4560. // slot content array of a dynamic conditional slot may have a branch
  4561. // key attached in the `createSlots` helper, respect that
  4562. (validSlotContent && validSlotContent.key) ||
  4563. `_${name}`
  4564. }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* SlotFlags.STABLE */
  4565. ? 64 /* PatchFlags.STABLE_FRAGMENT */
  4566. : -2 /* PatchFlags.BAIL */);
  4567. if (!noSlotted && rendered.scopeId) {
  4568. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  4569. }
  4570. if (slot && slot._c) {
  4571. slot._d = true;
  4572. }
  4573. return rendered;
  4574. }
  4575. function ensureValidVNode(vnodes) {
  4576. return vnodes.some(child => {
  4577. if (!isVNode(child))
  4578. return true;
  4579. if (child.type === Comment)
  4580. return false;
  4581. if (child.type === Fragment &&
  4582. !ensureValidVNode(child.children))
  4583. return false;
  4584. return true;
  4585. })
  4586. ? vnodes
  4587. : null;
  4588. }
  4589. /**
  4590. * For prefixing keys in v-on="obj" with "on"
  4591. * @private
  4592. */
  4593. function toHandlers(obj, preserveCaseIfNecessary) {
  4594. const ret = {};
  4595. if (!isObject(obj)) {
  4596. warn(`v-on with no argument expects an object value.`);
  4597. return ret;
  4598. }
  4599. for (const key in obj) {
  4600. ret[preserveCaseIfNecessary && /[A-Z]/.test(key)
  4601. ? `on:${key}`
  4602. : toHandlerKey(key)] = obj[key];
  4603. }
  4604. return ret;
  4605. }
  4606. /**
  4607. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4608. * they exist in the internal parent chain. For code that relies on traversing
  4609. * public $parent chains, skip functional ones and go to the parent instead.
  4610. */
  4611. const getPublicInstance = (i) => {
  4612. if (!i)
  4613. return null;
  4614. if (isStatefulComponent(i))
  4615. return getExposeProxy(i) || i.proxy;
  4616. return getPublicInstance(i.parent);
  4617. };
  4618. const publicPropertiesMap =
  4619. // Move PURE marker to new line to workaround compiler discarding it
  4620. // due to type annotation
  4621. /*#__PURE__*/ extend(Object.create(null), {
  4622. $: i => i,
  4623. $el: i => i.vnode.el,
  4624. $data: i => i.data,
  4625. $props: i => (shallowReadonly(i.props) ),
  4626. $attrs: i => (shallowReadonly(i.attrs) ),
  4627. $slots: i => (shallowReadonly(i.slots) ),
  4628. $refs: i => (shallowReadonly(i.refs) ),
  4629. $parent: i => getPublicInstance(i.parent),
  4630. $root: i => getPublicInstance(i.root),
  4631. $emit: i => i.emit,
  4632. $options: i => (resolveMergedOptions(i) ),
  4633. $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
  4634. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  4635. $watch: i => (instanceWatch.bind(i) )
  4636. });
  4637. const isReservedPrefix = (key) => key === '_' || key === '$';
  4638. const hasSetupBinding = (state, key) => state !== EMPTY_OBJ && !state.__isScriptSetup && hasOwn(state, key);
  4639. const PublicInstanceProxyHandlers = {
  4640. get({ _: instance }, key) {
  4641. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  4642. // for internal formatters to know that this is a Vue instance
  4643. if (key === '__isVue') {
  4644. return true;
  4645. }
  4646. // data / props / ctx
  4647. // This getter gets called for every property access on the render context
  4648. // during render and is a major hotspot. The most expensive part of this
  4649. // is the multiple hasOwn() calls. It's much faster to do a simple property
  4650. // access on a plain object, so we use an accessCache object (with null
  4651. // prototype) to memoize what access type a key corresponds to.
  4652. let normalizedProps;
  4653. if (key[0] !== '$') {
  4654. const n = accessCache[key];
  4655. if (n !== undefined) {
  4656. switch (n) {
  4657. case 1 /* AccessTypes.SETUP */:
  4658. return setupState[key];
  4659. case 2 /* AccessTypes.DATA */:
  4660. return data[key];
  4661. case 4 /* AccessTypes.CONTEXT */:
  4662. return ctx[key];
  4663. case 3 /* AccessTypes.PROPS */:
  4664. return props[key];
  4665. // default: just fallthrough
  4666. }
  4667. }
  4668. else if (hasSetupBinding(setupState, key)) {
  4669. accessCache[key] = 1 /* AccessTypes.SETUP */;
  4670. return setupState[key];
  4671. }
  4672. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4673. accessCache[key] = 2 /* AccessTypes.DATA */;
  4674. return data[key];
  4675. }
  4676. else if (
  4677. // only cache other properties when instance has declared (thus stable)
  4678. // props
  4679. (normalizedProps = instance.propsOptions[0]) &&
  4680. hasOwn(normalizedProps, key)) {
  4681. accessCache[key] = 3 /* AccessTypes.PROPS */;
  4682. return props[key];
  4683. }
  4684. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4685. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4686. return ctx[key];
  4687. }
  4688. else if (shouldCacheAccess) {
  4689. accessCache[key] = 0 /* AccessTypes.OTHER */;
  4690. }
  4691. }
  4692. const publicGetter = publicPropertiesMap[key];
  4693. let cssModule, globalProperties;
  4694. // public $xxx properties
  4695. if (publicGetter) {
  4696. if (key === '$attrs') {
  4697. track(instance, "get" /* TrackOpTypes.GET */, key);
  4698. markAttrsAccessed();
  4699. }
  4700. return publicGetter(instance);
  4701. }
  4702. else if (
  4703. // css module (injected by vue-loader)
  4704. (cssModule = type.__cssModules) &&
  4705. (cssModule = cssModule[key])) {
  4706. return cssModule;
  4707. }
  4708. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4709. // user may set custom properties to `this` that start with `$`
  4710. accessCache[key] = 4 /* AccessTypes.CONTEXT */;
  4711. return ctx[key];
  4712. }
  4713. else if (
  4714. // global properties
  4715. ((globalProperties = appContext.config.globalProperties),
  4716. hasOwn(globalProperties, key))) {
  4717. {
  4718. return globalProperties[key];
  4719. }
  4720. }
  4721. else if (currentRenderingInstance &&
  4722. (!isString(key) ||
  4723. // #1091 avoid internal isRef/isVNode checks on component instance leading
  4724. // to infinite warning loop
  4725. key.indexOf('__v') !== 0)) {
  4726. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  4727. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  4728. `character ("$" or "_") and is not proxied on the render context.`);
  4729. }
  4730. else if (instance === currentRenderingInstance) {
  4731. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  4732. `but is not defined on instance.`);
  4733. }
  4734. }
  4735. },
  4736. set({ _: instance }, key, value) {
  4737. const { data, setupState, ctx } = instance;
  4738. if (hasSetupBinding(setupState, key)) {
  4739. setupState[key] = value;
  4740. return true;
  4741. }
  4742. else if (setupState.__isScriptSetup &&
  4743. hasOwn(setupState, key)) {
  4744. warn(`Cannot mutate <script setup> binding "${key}" from Options API.`);
  4745. return false;
  4746. }
  4747. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4748. data[key] = value;
  4749. return true;
  4750. }
  4751. else if (hasOwn(instance.props, key)) {
  4752. warn(`Attempting to mutate prop "${key}". Props are readonly.`);
  4753. return false;
  4754. }
  4755. if (key[0] === '$' && key.slice(1) in instance) {
  4756. warn(`Attempting to mutate public property "${key}". ` +
  4757. `Properties starting with $ are reserved and readonly.`);
  4758. return false;
  4759. }
  4760. else {
  4761. if (key in instance.appContext.config.globalProperties) {
  4762. Object.defineProperty(ctx, key, {
  4763. enumerable: true,
  4764. configurable: true,
  4765. value
  4766. });
  4767. }
  4768. else {
  4769. ctx[key] = value;
  4770. }
  4771. }
  4772. return true;
  4773. },
  4774. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  4775. let normalizedProps;
  4776. return (!!accessCache[key] ||
  4777. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  4778. hasSetupBinding(setupState, key) ||
  4779. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  4780. hasOwn(ctx, key) ||
  4781. hasOwn(publicPropertiesMap, key) ||
  4782. hasOwn(appContext.config.globalProperties, key));
  4783. },
  4784. defineProperty(target, key, descriptor) {
  4785. if (descriptor.get != null) {
  4786. // invalidate key cache of a getter based property #5417
  4787. target._.accessCache[key] = 0;
  4788. }
  4789. else if (hasOwn(descriptor, 'value')) {
  4790. this.set(target, key, descriptor.value, null);
  4791. }
  4792. return Reflect.defineProperty(target, key, descriptor);
  4793. }
  4794. };
  4795. {
  4796. PublicInstanceProxyHandlers.ownKeys = (target) => {
  4797. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  4798. `The keys will be empty in production mode to avoid performance overhead.`);
  4799. return Reflect.ownKeys(target);
  4800. };
  4801. }
  4802. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  4803. get(target, key) {
  4804. // fast path for unscopables when using `with` block
  4805. if (key === Symbol.unscopables) {
  4806. return;
  4807. }
  4808. return PublicInstanceProxyHandlers.get(target, key, target);
  4809. },
  4810. has(_, key) {
  4811. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  4812. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  4813. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  4814. }
  4815. return has;
  4816. }
  4817. });
  4818. // dev only
  4819. // In dev mode, the proxy target exposes the same properties as seen on `this`
  4820. // for easier console inspection. In prod mode it will be an empty object so
  4821. // these properties definitions can be skipped.
  4822. function createDevRenderContext(instance) {
  4823. const target = {};
  4824. // expose internal instance for proxy handlers
  4825. Object.defineProperty(target, `_`, {
  4826. configurable: true,
  4827. enumerable: false,
  4828. get: () => instance
  4829. });
  4830. // expose public properties
  4831. Object.keys(publicPropertiesMap).forEach(key => {
  4832. Object.defineProperty(target, key, {
  4833. configurable: true,
  4834. enumerable: false,
  4835. get: () => publicPropertiesMap[key](instance),
  4836. // intercepted by the proxy so no need for implementation,
  4837. // but needed to prevent set errors
  4838. set: NOOP
  4839. });
  4840. });
  4841. return target;
  4842. }
  4843. // dev only
  4844. function exposePropsOnRenderContext(instance) {
  4845. const { ctx, propsOptions: [propsOptions] } = instance;
  4846. if (propsOptions) {
  4847. Object.keys(propsOptions).forEach(key => {
  4848. Object.defineProperty(ctx, key, {
  4849. enumerable: true,
  4850. configurable: true,
  4851. get: () => instance.props[key],
  4852. set: NOOP
  4853. });
  4854. });
  4855. }
  4856. }
  4857. // dev only
  4858. function exposeSetupStateOnRenderContext(instance) {
  4859. const { ctx, setupState } = instance;
  4860. Object.keys(toRaw(setupState)).forEach(key => {
  4861. if (!setupState.__isScriptSetup) {
  4862. if (isReservedPrefix(key[0])) {
  4863. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  4864. `which are reserved prefixes for Vue internals.`);
  4865. return;
  4866. }
  4867. Object.defineProperty(ctx, key, {
  4868. enumerable: true,
  4869. configurable: true,
  4870. get: () => setupState[key],
  4871. set: NOOP
  4872. });
  4873. }
  4874. });
  4875. }
  4876. function createDuplicateChecker() {
  4877. const cache = Object.create(null);
  4878. return (type, key) => {
  4879. if (cache[key]) {
  4880. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4881. }
  4882. else {
  4883. cache[key] = type;
  4884. }
  4885. };
  4886. }
  4887. let shouldCacheAccess = true;
  4888. function applyOptions(instance) {
  4889. const options = resolveMergedOptions(instance);
  4890. const publicThis = instance.proxy;
  4891. const ctx = instance.ctx;
  4892. // do not cache property access on public proxy during state initialization
  4893. shouldCacheAccess = false;
  4894. // call beforeCreate first before accessing other options since
  4895. // the hook may mutate resolved options (#2791)
  4896. if (options.beforeCreate) {
  4897. callHook$1(options.beforeCreate, instance, "bc" /* LifecycleHooks.BEFORE_CREATE */);
  4898. }
  4899. const {
  4900. // state
  4901. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4902. // lifecycle
  4903. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4904. // public API
  4905. expose, inheritAttrs,
  4906. // assets
  4907. components, directives, filters } = options;
  4908. const checkDuplicateProperties = createDuplicateChecker() ;
  4909. {
  4910. const [propsOptions] = instance.propsOptions;
  4911. if (propsOptions) {
  4912. for (const key in propsOptions) {
  4913. checkDuplicateProperties("Props" /* OptionTypes.PROPS */, key);
  4914. }
  4915. }
  4916. }
  4917. // options initialization order (to be consistent with Vue 2):
  4918. // - props (already done outside of this function)
  4919. // - inject
  4920. // - methods
  4921. // - data (deferred since it relies on `this` access)
  4922. // - computed
  4923. // - watch (deferred since it relies on `this` access)
  4924. if (injectOptions) {
  4925. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4926. }
  4927. if (methods) {
  4928. for (const key in methods) {
  4929. const methodHandler = methods[key];
  4930. if (isFunction(methodHandler)) {
  4931. // In dev mode, we use the `createRenderContext` function to define
  4932. // methods to the proxy target, and those are read-only but
  4933. // reconfigurable, so it needs to be redefined here
  4934. {
  4935. Object.defineProperty(ctx, key, {
  4936. value: methodHandler.bind(publicThis),
  4937. configurable: true,
  4938. enumerable: true,
  4939. writable: true
  4940. });
  4941. }
  4942. {
  4943. checkDuplicateProperties("Methods" /* OptionTypes.METHODS */, key);
  4944. }
  4945. }
  4946. else {
  4947. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4948. `Did you reference the function correctly?`);
  4949. }
  4950. }
  4951. }
  4952. if (dataOptions) {
  4953. if (!isFunction(dataOptions)) {
  4954. warn(`The data option must be a function. ` +
  4955. `Plain object usage is no longer supported.`);
  4956. }
  4957. const data = dataOptions.call(publicThis, publicThis);
  4958. if (isPromise(data)) {
  4959. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  4960. `intend to perform data fetching before component renders, use ` +
  4961. `async setup() + <Suspense>.`);
  4962. }
  4963. if (!isObject(data)) {
  4964. warn(`data() should return an object.`);
  4965. }
  4966. else {
  4967. instance.data = reactive(data);
  4968. {
  4969. for (const key in data) {
  4970. checkDuplicateProperties("Data" /* OptionTypes.DATA */, key);
  4971. // expose data on ctx during dev
  4972. if (!isReservedPrefix(key[0])) {
  4973. Object.defineProperty(ctx, key, {
  4974. configurable: true,
  4975. enumerable: true,
  4976. get: () => data[key],
  4977. set: NOOP
  4978. });
  4979. }
  4980. }
  4981. }
  4982. }
  4983. }
  4984. // state initialization complete at this point - start caching access
  4985. shouldCacheAccess = true;
  4986. if (computedOptions) {
  4987. for (const key in computedOptions) {
  4988. const opt = computedOptions[key];
  4989. const get = isFunction(opt)
  4990. ? opt.bind(publicThis, publicThis)
  4991. : isFunction(opt.get)
  4992. ? opt.get.bind(publicThis, publicThis)
  4993. : NOOP;
  4994. if (get === NOOP) {
  4995. warn(`Computed property "${key}" has no getter.`);
  4996. }
  4997. const set = !isFunction(opt) && isFunction(opt.set)
  4998. ? opt.set.bind(publicThis)
  4999. : () => {
  5000. warn(`Write operation failed: computed property "${key}" is readonly.`);
  5001. }
  5002. ;
  5003. const c = computed({
  5004. get,
  5005. set
  5006. });
  5007. Object.defineProperty(ctx, key, {
  5008. enumerable: true,
  5009. configurable: true,
  5010. get: () => c.value,
  5011. set: v => (c.value = v)
  5012. });
  5013. {
  5014. checkDuplicateProperties("Computed" /* OptionTypes.COMPUTED */, key);
  5015. }
  5016. }
  5017. }
  5018. if (watchOptions) {
  5019. for (const key in watchOptions) {
  5020. createWatcher(watchOptions[key], ctx, publicThis, key);
  5021. }
  5022. }
  5023. if (provideOptions) {
  5024. const provides = isFunction(provideOptions)
  5025. ? provideOptions.call(publicThis)
  5026. : provideOptions;
  5027. Reflect.ownKeys(provides).forEach(key => {
  5028. provide(key, provides[key]);
  5029. });
  5030. }
  5031. if (created) {
  5032. callHook$1(created, instance, "c" /* LifecycleHooks.CREATED */);
  5033. }
  5034. function registerLifecycleHook(register, hook) {
  5035. if (isArray(hook)) {
  5036. hook.forEach(_hook => register(_hook.bind(publicThis)));
  5037. }
  5038. else if (hook) {
  5039. register(hook.bind(publicThis));
  5040. }
  5041. }
  5042. registerLifecycleHook(onBeforeMount, beforeMount);
  5043. registerLifecycleHook(onMounted, mounted);
  5044. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  5045. registerLifecycleHook(onUpdated, updated);
  5046. registerLifecycleHook(onActivated, activated);
  5047. registerLifecycleHook(onDeactivated, deactivated);
  5048. registerLifecycleHook(onErrorCaptured, errorCaptured);
  5049. registerLifecycleHook(onRenderTracked, renderTracked);
  5050. registerLifecycleHook(onRenderTriggered, renderTriggered);
  5051. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  5052. registerLifecycleHook(onUnmounted, unmounted);
  5053. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  5054. if (isArray(expose)) {
  5055. if (expose.length) {
  5056. const exposed = instance.exposed || (instance.exposed = {});
  5057. expose.forEach(key => {
  5058. Object.defineProperty(exposed, key, {
  5059. get: () => publicThis[key],
  5060. set: val => (publicThis[key] = val)
  5061. });
  5062. });
  5063. }
  5064. else if (!instance.exposed) {
  5065. instance.exposed = {};
  5066. }
  5067. }
  5068. // options that are handled when creating the instance but also need to be
  5069. // applied from mixins
  5070. if (render && instance.render === NOOP) {
  5071. instance.render = render;
  5072. }
  5073. if (inheritAttrs != null) {
  5074. instance.inheritAttrs = inheritAttrs;
  5075. }
  5076. // asset options.
  5077. if (components)
  5078. instance.components = components;
  5079. if (directives)
  5080. instance.directives = directives;
  5081. }
  5082. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  5083. if (isArray(injectOptions)) {
  5084. injectOptions = normalizeInject(injectOptions);
  5085. }
  5086. for (const key in injectOptions) {
  5087. const opt = injectOptions[key];
  5088. let injected;
  5089. if (isObject(opt)) {
  5090. if ('default' in opt) {
  5091. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  5092. }
  5093. else {
  5094. injected = inject(opt.from || key);
  5095. }
  5096. }
  5097. else {
  5098. injected = inject(opt);
  5099. }
  5100. if (isRef(injected)) {
  5101. // TODO remove the check in 3.3
  5102. if (unwrapRef) {
  5103. Object.defineProperty(ctx, key, {
  5104. enumerable: true,
  5105. configurable: true,
  5106. get: () => injected.value,
  5107. set: v => (injected.value = v)
  5108. });
  5109. }
  5110. else {
  5111. {
  5112. warn(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  5113. `and no longer needs \`.value\` in the next minor release. ` +
  5114. `To opt-in to the new behavior now, ` +
  5115. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  5116. `temporary and will not be needed in the future.)`);
  5117. }
  5118. ctx[key] = injected;
  5119. }
  5120. }
  5121. else {
  5122. ctx[key] = injected;
  5123. }
  5124. {
  5125. checkDuplicateProperties("Inject" /* OptionTypes.INJECT */, key);
  5126. }
  5127. }
  5128. }
  5129. function callHook$1(hook, instance, type) {
  5130. callWithAsyncErrorHandling(isArray(hook)
  5131. ? hook.map(h => h.bind(instance.proxy))
  5132. : hook.bind(instance.proxy), instance, type);
  5133. }
  5134. function createWatcher(raw, ctx, publicThis, key) {
  5135. const getter = key.includes('.')
  5136. ? createPathGetter(publicThis, key)
  5137. : () => publicThis[key];
  5138. if (isString(raw)) {
  5139. const handler = ctx[raw];
  5140. if (isFunction(handler)) {
  5141. watch(getter, handler);
  5142. }
  5143. else {
  5144. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  5145. }
  5146. }
  5147. else if (isFunction(raw)) {
  5148. watch(getter, raw.bind(publicThis));
  5149. }
  5150. else if (isObject(raw)) {
  5151. if (isArray(raw)) {
  5152. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  5153. }
  5154. else {
  5155. const handler = isFunction(raw.handler)
  5156. ? raw.handler.bind(publicThis)
  5157. : ctx[raw.handler];
  5158. if (isFunction(handler)) {
  5159. watch(getter, handler, raw);
  5160. }
  5161. else {
  5162. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  5163. }
  5164. }
  5165. }
  5166. else {
  5167. warn(`Invalid watch option: "${key}"`, raw);
  5168. }
  5169. }
  5170. /**
  5171. * Resolve merged options and cache it on the component.
  5172. * This is done only once per-component since the merging does not involve
  5173. * instances.
  5174. */
  5175. function resolveMergedOptions(instance) {
  5176. const base = instance.type;
  5177. const { mixins, extends: extendsOptions } = base;
  5178. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  5179. const cached = cache.get(base);
  5180. let resolved;
  5181. if (cached) {
  5182. resolved = cached;
  5183. }
  5184. else if (!globalMixins.length && !mixins && !extendsOptions) {
  5185. {
  5186. resolved = base;
  5187. }
  5188. }
  5189. else {
  5190. resolved = {};
  5191. if (globalMixins.length) {
  5192. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  5193. }
  5194. mergeOptions(resolved, base, optionMergeStrategies);
  5195. }
  5196. if (isObject(base)) {
  5197. cache.set(base, resolved);
  5198. }
  5199. return resolved;
  5200. }
  5201. function mergeOptions(to, from, strats, asMixin = false) {
  5202. const { mixins, extends: extendsOptions } = from;
  5203. if (extendsOptions) {
  5204. mergeOptions(to, extendsOptions, strats, true);
  5205. }
  5206. if (mixins) {
  5207. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  5208. }
  5209. for (const key in from) {
  5210. if (asMixin && key === 'expose') {
  5211. warn(`"expose" option is ignored when declared in mixins or extends. ` +
  5212. `It should only be declared in the base component itself.`);
  5213. }
  5214. else {
  5215. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  5216. to[key] = strat ? strat(to[key], from[key]) : from[key];
  5217. }
  5218. }
  5219. return to;
  5220. }
  5221. const internalOptionMergeStrats = {
  5222. data: mergeDataFn,
  5223. props: mergeObjectOptions,
  5224. emits: mergeObjectOptions,
  5225. // objects
  5226. methods: mergeObjectOptions,
  5227. computed: mergeObjectOptions,
  5228. // lifecycle
  5229. beforeCreate: mergeAsArray$1,
  5230. created: mergeAsArray$1,
  5231. beforeMount: mergeAsArray$1,
  5232. mounted: mergeAsArray$1,
  5233. beforeUpdate: mergeAsArray$1,
  5234. updated: mergeAsArray$1,
  5235. beforeDestroy: mergeAsArray$1,
  5236. beforeUnmount: mergeAsArray$1,
  5237. destroyed: mergeAsArray$1,
  5238. unmounted: mergeAsArray$1,
  5239. activated: mergeAsArray$1,
  5240. deactivated: mergeAsArray$1,
  5241. errorCaptured: mergeAsArray$1,
  5242. serverPrefetch: mergeAsArray$1,
  5243. // assets
  5244. components: mergeObjectOptions,
  5245. directives: mergeObjectOptions,
  5246. // watch
  5247. watch: mergeWatchOptions,
  5248. // provide / inject
  5249. provide: mergeDataFn,
  5250. inject: mergeInject
  5251. };
  5252. function mergeDataFn(to, from) {
  5253. if (!from) {
  5254. return to;
  5255. }
  5256. if (!to) {
  5257. return from;
  5258. }
  5259. return function mergedDataFn() {
  5260. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  5261. };
  5262. }
  5263. function mergeInject(to, from) {
  5264. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  5265. }
  5266. function normalizeInject(raw) {
  5267. if (isArray(raw)) {
  5268. const res = {};
  5269. for (let i = 0; i < raw.length; i++) {
  5270. res[raw[i]] = raw[i];
  5271. }
  5272. return res;
  5273. }
  5274. return raw;
  5275. }
  5276. function mergeAsArray$1(to, from) {
  5277. return to ? [...new Set([].concat(to, from))] : from;
  5278. }
  5279. function mergeObjectOptions(to, from) {
  5280. return to ? extend(extend(Object.create(null), to), from) : from;
  5281. }
  5282. function mergeWatchOptions(to, from) {
  5283. if (!to)
  5284. return from;
  5285. if (!from)
  5286. return to;
  5287. const merged = extend(Object.create(null), to);
  5288. for (const key in from) {
  5289. merged[key] = mergeAsArray$1(to[key], from[key]);
  5290. }
  5291. return merged;
  5292. }
  5293. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  5294. isSSR = false) {
  5295. const props = {};
  5296. const attrs = {};
  5297. def(attrs, InternalObjectKey, 1);
  5298. instance.propsDefaults = Object.create(null);
  5299. setFullProps(instance, rawProps, props, attrs);
  5300. // ensure all declared prop keys are present
  5301. for (const key in instance.propsOptions[0]) {
  5302. if (!(key in props)) {
  5303. props[key] = undefined;
  5304. }
  5305. }
  5306. // validation
  5307. {
  5308. validateProps(rawProps || {}, props, instance);
  5309. }
  5310. if (isStateful) {
  5311. // stateful
  5312. instance.props = isSSR ? props : shallowReactive(props);
  5313. }
  5314. else {
  5315. if (!instance.type.props) {
  5316. // functional w/ optional props, props === attrs
  5317. instance.props = attrs;
  5318. }
  5319. else {
  5320. // functional w/ declared props
  5321. instance.props = props;
  5322. }
  5323. }
  5324. instance.attrs = attrs;
  5325. }
  5326. function isInHmrContext(instance) {
  5327. while (instance) {
  5328. if (instance.type.__hmrId)
  5329. return true;
  5330. instance = instance.parent;
  5331. }
  5332. }
  5333. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  5334. const { props, attrs, vnode: { patchFlag } } = instance;
  5335. const rawCurrentProps = toRaw(props);
  5336. const [options] = instance.propsOptions;
  5337. let hasAttrsChanged = false;
  5338. if (
  5339. // always force full diff in dev
  5340. // - #1942 if hmr is enabled with sfc component
  5341. // - vite#872 non-sfc component used by sfc component
  5342. !(isInHmrContext(instance)) &&
  5343. (optimized || patchFlag > 0) &&
  5344. !(patchFlag & 16 /* PatchFlags.FULL_PROPS */)) {
  5345. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  5346. // Compiler-generated props & no keys change, just set the updated
  5347. // the props.
  5348. const propsToUpdate = instance.vnode.dynamicProps;
  5349. for (let i = 0; i < propsToUpdate.length; i++) {
  5350. let key = propsToUpdate[i];
  5351. // skip if the prop key is a declared emit event listener
  5352. if (isEmitListener(instance.emitsOptions, key)) {
  5353. continue;
  5354. }
  5355. // PROPS flag guarantees rawProps to be non-null
  5356. const value = rawProps[key];
  5357. if (options) {
  5358. // attr / props separation was done on init and will be consistent
  5359. // in this code path, so just check if attrs have it.
  5360. if (hasOwn(attrs, key)) {
  5361. if (value !== attrs[key]) {
  5362. attrs[key] = value;
  5363. hasAttrsChanged = true;
  5364. }
  5365. }
  5366. else {
  5367. const camelizedKey = camelize(key);
  5368. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  5369. }
  5370. }
  5371. else {
  5372. if (value !== attrs[key]) {
  5373. attrs[key] = value;
  5374. hasAttrsChanged = true;
  5375. }
  5376. }
  5377. }
  5378. }
  5379. }
  5380. else {
  5381. // full props update.
  5382. if (setFullProps(instance, rawProps, props, attrs)) {
  5383. hasAttrsChanged = true;
  5384. }
  5385. // in case of dynamic props, check if we need to delete keys from
  5386. // the props object
  5387. let kebabKey;
  5388. for (const key in rawCurrentProps) {
  5389. if (!rawProps ||
  5390. // for camelCase
  5391. (!hasOwn(rawProps, key) &&
  5392. // it's possible the original props was passed in as kebab-case
  5393. // and converted to camelCase (#955)
  5394. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  5395. if (options) {
  5396. if (rawPrevProps &&
  5397. // for camelCase
  5398. (rawPrevProps[key] !== undefined ||
  5399. // for kebab-case
  5400. rawPrevProps[kebabKey] !== undefined)) {
  5401. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  5402. }
  5403. }
  5404. else {
  5405. delete props[key];
  5406. }
  5407. }
  5408. }
  5409. // in the case of functional component w/o props declaration, props and
  5410. // attrs point to the same object so it should already have been updated.
  5411. if (attrs !== rawCurrentProps) {
  5412. for (const key in attrs) {
  5413. if (!rawProps ||
  5414. (!hasOwn(rawProps, key) &&
  5415. (!false ))) {
  5416. delete attrs[key];
  5417. hasAttrsChanged = true;
  5418. }
  5419. }
  5420. }
  5421. }
  5422. // trigger updates for $attrs in case it's used in component slots
  5423. if (hasAttrsChanged) {
  5424. trigger(instance, "set" /* TriggerOpTypes.SET */, '$attrs');
  5425. }
  5426. {
  5427. validateProps(rawProps || {}, props, instance);
  5428. }
  5429. }
  5430. function setFullProps(instance, rawProps, props, attrs) {
  5431. const [options, needCastKeys] = instance.propsOptions;
  5432. let hasAttrsChanged = false;
  5433. let rawCastValues;
  5434. if (rawProps) {
  5435. for (let key in rawProps) {
  5436. // key, ref are reserved and never passed down
  5437. if (isReservedProp(key)) {
  5438. continue;
  5439. }
  5440. const value = rawProps[key];
  5441. // prop option names are camelized during normalization, so to support
  5442. // kebab -> camel conversion here we need to camelize the key.
  5443. let camelKey;
  5444. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  5445. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  5446. props[camelKey] = value;
  5447. }
  5448. else {
  5449. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  5450. }
  5451. }
  5452. else if (!isEmitListener(instance.emitsOptions, key)) {
  5453. if (!(key in attrs) || value !== attrs[key]) {
  5454. attrs[key] = value;
  5455. hasAttrsChanged = true;
  5456. }
  5457. }
  5458. }
  5459. }
  5460. if (needCastKeys) {
  5461. const rawCurrentProps = toRaw(props);
  5462. const castValues = rawCastValues || EMPTY_OBJ;
  5463. for (let i = 0; i < needCastKeys.length; i++) {
  5464. const key = needCastKeys[i];
  5465. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  5466. }
  5467. }
  5468. return hasAttrsChanged;
  5469. }
  5470. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  5471. const opt = options[key];
  5472. if (opt != null) {
  5473. const hasDefault = hasOwn(opt, 'default');
  5474. // default values
  5475. if (hasDefault && value === undefined) {
  5476. const defaultValue = opt.default;
  5477. if (opt.type !== Function && isFunction(defaultValue)) {
  5478. const { propsDefaults } = instance;
  5479. if (key in propsDefaults) {
  5480. value = propsDefaults[key];
  5481. }
  5482. else {
  5483. setCurrentInstance(instance);
  5484. value = propsDefaults[key] = defaultValue.call(null, props);
  5485. unsetCurrentInstance();
  5486. }
  5487. }
  5488. else {
  5489. value = defaultValue;
  5490. }
  5491. }
  5492. // boolean casting
  5493. if (opt[0 /* BooleanFlags.shouldCast */]) {
  5494. if (isAbsent && !hasDefault) {
  5495. value = false;
  5496. }
  5497. else if (opt[1 /* BooleanFlags.shouldCastTrue */] &&
  5498. (value === '' || value === hyphenate(key))) {
  5499. value = true;
  5500. }
  5501. }
  5502. }
  5503. return value;
  5504. }
  5505. function normalizePropsOptions(comp, appContext, asMixin = false) {
  5506. const cache = appContext.propsCache;
  5507. const cached = cache.get(comp);
  5508. if (cached) {
  5509. return cached;
  5510. }
  5511. const raw = comp.props;
  5512. const normalized = {};
  5513. const needCastKeys = [];
  5514. // apply mixin/extends props
  5515. let hasExtends = false;
  5516. if (!isFunction(comp)) {
  5517. const extendProps = (raw) => {
  5518. hasExtends = true;
  5519. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  5520. extend(normalized, props);
  5521. if (keys)
  5522. needCastKeys.push(...keys);
  5523. };
  5524. if (!asMixin && appContext.mixins.length) {
  5525. appContext.mixins.forEach(extendProps);
  5526. }
  5527. if (comp.extends) {
  5528. extendProps(comp.extends);
  5529. }
  5530. if (comp.mixins) {
  5531. comp.mixins.forEach(extendProps);
  5532. }
  5533. }
  5534. if (!raw && !hasExtends) {
  5535. if (isObject(comp)) {
  5536. cache.set(comp, EMPTY_ARR);
  5537. }
  5538. return EMPTY_ARR;
  5539. }
  5540. if (isArray(raw)) {
  5541. for (let i = 0; i < raw.length; i++) {
  5542. if (!isString(raw[i])) {
  5543. warn(`props must be strings when using array syntax.`, raw[i]);
  5544. }
  5545. const normalizedKey = camelize(raw[i]);
  5546. if (validatePropName(normalizedKey)) {
  5547. normalized[normalizedKey] = EMPTY_OBJ;
  5548. }
  5549. }
  5550. }
  5551. else if (raw) {
  5552. if (!isObject(raw)) {
  5553. warn(`invalid props options`, raw);
  5554. }
  5555. for (const key in raw) {
  5556. const normalizedKey = camelize(key);
  5557. if (validatePropName(normalizedKey)) {
  5558. const opt = raw[key];
  5559. const prop = (normalized[normalizedKey] =
  5560. isArray(opt) || isFunction(opt) ? { type: opt } : Object.assign({}, opt));
  5561. if (prop) {
  5562. const booleanIndex = getTypeIndex(Boolean, prop.type);
  5563. const stringIndex = getTypeIndex(String, prop.type);
  5564. prop[0 /* BooleanFlags.shouldCast */] = booleanIndex > -1;
  5565. prop[1 /* BooleanFlags.shouldCastTrue */] =
  5566. stringIndex < 0 || booleanIndex < stringIndex;
  5567. // if the prop needs boolean casting or default value
  5568. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  5569. needCastKeys.push(normalizedKey);
  5570. }
  5571. }
  5572. }
  5573. }
  5574. }
  5575. const res = [normalized, needCastKeys];
  5576. if (isObject(comp)) {
  5577. cache.set(comp, res);
  5578. }
  5579. return res;
  5580. }
  5581. function validatePropName(key) {
  5582. if (key[0] !== '$') {
  5583. return true;
  5584. }
  5585. else {
  5586. warn(`Invalid prop name: "${key}" is a reserved property.`);
  5587. }
  5588. return false;
  5589. }
  5590. // use function string name to check type constructors
  5591. // so that it works across vms / iframes.
  5592. function getType(ctor) {
  5593. const match = ctor && ctor.toString().match(/^\s*(function|class) (\w+)/);
  5594. return match ? match[2] : ctor === null ? 'null' : '';
  5595. }
  5596. function isSameType(a, b) {
  5597. return getType(a) === getType(b);
  5598. }
  5599. function getTypeIndex(type, expectedTypes) {
  5600. if (isArray(expectedTypes)) {
  5601. return expectedTypes.findIndex(t => isSameType(t, type));
  5602. }
  5603. else if (isFunction(expectedTypes)) {
  5604. return isSameType(expectedTypes, type) ? 0 : -1;
  5605. }
  5606. return -1;
  5607. }
  5608. /**
  5609. * dev only
  5610. */
  5611. function validateProps(rawProps, props, instance) {
  5612. const resolvedValues = toRaw(props);
  5613. const options = instance.propsOptions[0];
  5614. for (const key in options) {
  5615. let opt = options[key];
  5616. if (opt == null)
  5617. continue;
  5618. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  5619. }
  5620. }
  5621. /**
  5622. * dev only
  5623. */
  5624. function validateProp(name, value, prop, isAbsent) {
  5625. const { type, required, validator } = prop;
  5626. // required!
  5627. if (required && isAbsent) {
  5628. warn('Missing required prop: "' + name + '"');
  5629. return;
  5630. }
  5631. // missing but optional
  5632. if (value == null && !prop.required) {
  5633. return;
  5634. }
  5635. // type check
  5636. if (type != null && type !== true) {
  5637. let isValid = false;
  5638. const types = isArray(type) ? type : [type];
  5639. const expectedTypes = [];
  5640. // value is valid as long as one of the specified types match
  5641. for (let i = 0; i < types.length && !isValid; i++) {
  5642. const { valid, expectedType } = assertType(value, types[i]);
  5643. expectedTypes.push(expectedType || '');
  5644. isValid = valid;
  5645. }
  5646. if (!isValid) {
  5647. warn(getInvalidTypeMessage(name, value, expectedTypes));
  5648. return;
  5649. }
  5650. }
  5651. // custom validator
  5652. if (validator && !validator(value)) {
  5653. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  5654. }
  5655. }
  5656. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  5657. /**
  5658. * dev only
  5659. */
  5660. function assertType(value, type) {
  5661. let valid;
  5662. const expectedType = getType(type);
  5663. if (isSimpleType(expectedType)) {
  5664. const t = typeof value;
  5665. valid = t === expectedType.toLowerCase();
  5666. // for primitive wrapper objects
  5667. if (!valid && t === 'object') {
  5668. valid = value instanceof type;
  5669. }
  5670. }
  5671. else if (expectedType === 'Object') {
  5672. valid = isObject(value);
  5673. }
  5674. else if (expectedType === 'Array') {
  5675. valid = isArray(value);
  5676. }
  5677. else if (expectedType === 'null') {
  5678. valid = value === null;
  5679. }
  5680. else {
  5681. valid = value instanceof type;
  5682. }
  5683. return {
  5684. valid,
  5685. expectedType
  5686. };
  5687. }
  5688. /**
  5689. * dev only
  5690. */
  5691. function getInvalidTypeMessage(name, value, expectedTypes) {
  5692. let message = `Invalid prop: type check failed for prop "${name}".` +
  5693. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  5694. const expectedType = expectedTypes[0];
  5695. const receivedType = toRawType(value);
  5696. const expectedValue = styleValue(value, expectedType);
  5697. const receivedValue = styleValue(value, receivedType);
  5698. // check if we need to specify expected value
  5699. if (expectedTypes.length === 1 &&
  5700. isExplicable(expectedType) &&
  5701. !isBoolean(expectedType, receivedType)) {
  5702. message += ` with value ${expectedValue}`;
  5703. }
  5704. message += `, got ${receivedType} `;
  5705. // check if we need to specify received value
  5706. if (isExplicable(receivedType)) {
  5707. message += `with value ${receivedValue}.`;
  5708. }
  5709. return message;
  5710. }
  5711. /**
  5712. * dev only
  5713. */
  5714. function styleValue(value, type) {
  5715. if (type === 'String') {
  5716. return `"${value}"`;
  5717. }
  5718. else if (type === 'Number') {
  5719. return `${Number(value)}`;
  5720. }
  5721. else {
  5722. return `${value}`;
  5723. }
  5724. }
  5725. /**
  5726. * dev only
  5727. */
  5728. function isExplicable(type) {
  5729. const explicitTypes = ['string', 'number', 'boolean'];
  5730. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5731. }
  5732. /**
  5733. * dev only
  5734. */
  5735. function isBoolean(...args) {
  5736. return args.some(elem => elem.toLowerCase() === 'boolean');
  5737. }
  5738. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5739. const normalizeSlotValue = (value) => isArray(value)
  5740. ? value.map(normalizeVNode)
  5741. : [normalizeVNode(value)];
  5742. const normalizeSlot = (key, rawSlot, ctx) => {
  5743. if (rawSlot._n) {
  5744. // already normalized - #5353
  5745. return rawSlot;
  5746. }
  5747. const normalized = withCtx((...args) => {
  5748. if (true && currentInstance) {
  5749. warn(`Slot "${key}" invoked outside of the render function: ` +
  5750. `this will not track dependencies used in the slot. ` +
  5751. `Invoke the slot function inside the render function instead.`);
  5752. }
  5753. return normalizeSlotValue(rawSlot(...args));
  5754. }, ctx);
  5755. normalized._c = false;
  5756. return normalized;
  5757. };
  5758. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5759. const ctx = rawSlots._ctx;
  5760. for (const key in rawSlots) {
  5761. if (isInternalKey(key))
  5762. continue;
  5763. const value = rawSlots[key];
  5764. if (isFunction(value)) {
  5765. slots[key] = normalizeSlot(key, value, ctx);
  5766. }
  5767. else if (value != null) {
  5768. {
  5769. warn(`Non-function value encountered for slot "${key}". ` +
  5770. `Prefer function slots for better performance.`);
  5771. }
  5772. const normalized = normalizeSlotValue(value);
  5773. slots[key] = () => normalized;
  5774. }
  5775. }
  5776. };
  5777. const normalizeVNodeSlots = (instance, children) => {
  5778. if (!isKeepAlive(instance.vnode) &&
  5779. !(false )) {
  5780. warn(`Non-function value encountered for default slot. ` +
  5781. `Prefer function slots for better performance.`);
  5782. }
  5783. const normalized = normalizeSlotValue(children);
  5784. instance.slots.default = () => normalized;
  5785. };
  5786. const initSlots = (instance, children) => {
  5787. if (instance.vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5788. const type = children._;
  5789. if (type) {
  5790. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5791. // we should avoid the proxy object polluting the slots of the internal instance
  5792. instance.slots = toRaw(children);
  5793. // make compiler marker non-enumerable
  5794. def(children, '_', type);
  5795. }
  5796. else {
  5797. normalizeObjectSlots(children, (instance.slots = {}));
  5798. }
  5799. }
  5800. else {
  5801. instance.slots = {};
  5802. if (children) {
  5803. normalizeVNodeSlots(instance, children);
  5804. }
  5805. }
  5806. def(instance.slots, InternalObjectKey, 1);
  5807. };
  5808. const updateSlots = (instance, children, optimized) => {
  5809. const { vnode, slots } = instance;
  5810. let needDeletionCheck = true;
  5811. let deletionComparisonTarget = EMPTY_OBJ;
  5812. if (vnode.shapeFlag & 32 /* ShapeFlags.SLOTS_CHILDREN */) {
  5813. const type = children._;
  5814. if (type) {
  5815. // compiled slots.
  5816. if (isHmrUpdating) {
  5817. // Parent was HMR updated so slot content may have changed.
  5818. // force update slots and mark instance for hmr as well
  5819. extend(slots, children);
  5820. }
  5821. else if (optimized && type === 1 /* SlotFlags.STABLE */) {
  5822. // compiled AND stable.
  5823. // no need to update, and skip stale slots removal.
  5824. needDeletionCheck = false;
  5825. }
  5826. else {
  5827. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5828. // normalization.
  5829. extend(slots, children);
  5830. // #2893
  5831. // when rendering the optimized slots by manually written render function,
  5832. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5833. // i.e. let the `renderSlot` create the bailed Fragment
  5834. if (!optimized && type === 1 /* SlotFlags.STABLE */) {
  5835. delete slots._;
  5836. }
  5837. }
  5838. }
  5839. else {
  5840. needDeletionCheck = !children.$stable;
  5841. normalizeObjectSlots(children, slots);
  5842. }
  5843. deletionComparisonTarget = children;
  5844. }
  5845. else if (children) {
  5846. // non slot object children (direct value) passed to a component
  5847. normalizeVNodeSlots(instance, children);
  5848. deletionComparisonTarget = { default: 1 };
  5849. }
  5850. // delete stale slots
  5851. if (needDeletionCheck) {
  5852. for (const key in slots) {
  5853. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5854. delete slots[key];
  5855. }
  5856. }
  5857. }
  5858. };
  5859. function createAppContext() {
  5860. return {
  5861. app: null,
  5862. config: {
  5863. isNativeTag: NO,
  5864. performance: false,
  5865. globalProperties: {},
  5866. optionMergeStrategies: {},
  5867. errorHandler: undefined,
  5868. warnHandler: undefined,
  5869. compilerOptions: {}
  5870. },
  5871. mixins: [],
  5872. components: {},
  5873. directives: {},
  5874. provides: Object.create(null),
  5875. optionsCache: new WeakMap(),
  5876. propsCache: new WeakMap(),
  5877. emitsCache: new WeakMap()
  5878. };
  5879. }
  5880. let uid$1 = 0;
  5881. function createAppAPI(render, hydrate) {
  5882. return function createApp(rootComponent, rootProps = null) {
  5883. if (!isFunction(rootComponent)) {
  5884. rootComponent = Object.assign({}, rootComponent);
  5885. }
  5886. if (rootProps != null && !isObject(rootProps)) {
  5887. warn(`root props passed to app.mount() must be an object.`);
  5888. rootProps = null;
  5889. }
  5890. const context = createAppContext();
  5891. const installedPlugins = new Set();
  5892. let isMounted = false;
  5893. const app = (context.app = {
  5894. _uid: uid$1++,
  5895. _component: rootComponent,
  5896. _props: rootProps,
  5897. _container: null,
  5898. _context: context,
  5899. _instance: null,
  5900. version,
  5901. get config() {
  5902. return context.config;
  5903. },
  5904. set config(v) {
  5905. {
  5906. warn(`app.config cannot be replaced. Modify individual options instead.`);
  5907. }
  5908. },
  5909. use(plugin, ...options) {
  5910. if (installedPlugins.has(plugin)) {
  5911. warn(`Plugin has already been applied to target app.`);
  5912. }
  5913. else if (plugin && isFunction(plugin.install)) {
  5914. installedPlugins.add(plugin);
  5915. plugin.install(app, ...options);
  5916. }
  5917. else if (isFunction(plugin)) {
  5918. installedPlugins.add(plugin);
  5919. plugin(app, ...options);
  5920. }
  5921. else {
  5922. warn(`A plugin must either be a function or an object with an "install" ` +
  5923. `function.`);
  5924. }
  5925. return app;
  5926. },
  5927. mixin(mixin) {
  5928. {
  5929. if (!context.mixins.includes(mixin)) {
  5930. context.mixins.push(mixin);
  5931. }
  5932. else {
  5933. warn('Mixin has already been applied to target app' +
  5934. (mixin.name ? `: ${mixin.name}` : ''));
  5935. }
  5936. }
  5937. return app;
  5938. },
  5939. component(name, component) {
  5940. {
  5941. validateComponentName(name, context.config);
  5942. }
  5943. if (!component) {
  5944. return context.components[name];
  5945. }
  5946. if (context.components[name]) {
  5947. warn(`Component "${name}" has already been registered in target app.`);
  5948. }
  5949. context.components[name] = component;
  5950. return app;
  5951. },
  5952. directive(name, directive) {
  5953. {
  5954. validateDirectiveName(name);
  5955. }
  5956. if (!directive) {
  5957. return context.directives[name];
  5958. }
  5959. if (context.directives[name]) {
  5960. warn(`Directive "${name}" has already been registered in target app.`);
  5961. }
  5962. context.directives[name] = directive;
  5963. return app;
  5964. },
  5965. mount(rootContainer, isHydrate, isSVG) {
  5966. if (!isMounted) {
  5967. // #5571
  5968. if (rootContainer.__vue_app__) {
  5969. warn(`There is already an app instance mounted on the host container.\n` +
  5970. ` If you want to mount another app on the same host container,` +
  5971. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  5972. }
  5973. const vnode = createVNode(rootComponent, rootProps);
  5974. // store app context on the root VNode.
  5975. // this will be set on the root instance on initial mount.
  5976. vnode.appContext = context;
  5977. // HMR root reload
  5978. {
  5979. context.reload = () => {
  5980. render(cloneVNode(vnode), rootContainer, isSVG);
  5981. };
  5982. }
  5983. if (isHydrate && hydrate) {
  5984. hydrate(vnode, rootContainer);
  5985. }
  5986. else {
  5987. render(vnode, rootContainer, isSVG);
  5988. }
  5989. isMounted = true;
  5990. app._container = rootContainer;
  5991. rootContainer.__vue_app__ = app;
  5992. {
  5993. app._instance = vnode.component;
  5994. devtoolsInitApp(app, version);
  5995. }
  5996. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5997. }
  5998. else {
  5999. warn(`App has already been mounted.\n` +
  6000. `If you want to remount the same app, move your app creation logic ` +
  6001. `into a factory function and create fresh app instances for each ` +
  6002. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  6003. }
  6004. },
  6005. unmount() {
  6006. if (isMounted) {
  6007. render(null, app._container);
  6008. {
  6009. app._instance = null;
  6010. devtoolsUnmountApp(app);
  6011. }
  6012. delete app._container.__vue_app__;
  6013. }
  6014. else {
  6015. warn(`Cannot unmount an app that is not mounted.`);
  6016. }
  6017. },
  6018. provide(key, value) {
  6019. if (key in context.provides) {
  6020. warn(`App already provides property with key "${String(key)}". ` +
  6021. `It will be overwritten with the new value.`);
  6022. }
  6023. context.provides[key] = value;
  6024. return app;
  6025. }
  6026. });
  6027. return app;
  6028. };
  6029. }
  6030. /**
  6031. * Function for handling a template ref
  6032. */
  6033. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  6034. if (isArray(rawRef)) {
  6035. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  6036. return;
  6037. }
  6038. if (isAsyncWrapper(vnode) && !isUnmount) {
  6039. // when mounting async components, nothing needs to be done,
  6040. // because the template ref is forwarded to inner component
  6041. return;
  6042. }
  6043. const refValue = vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */
  6044. ? getExposeProxy(vnode.component) || vnode.component.proxy
  6045. : vnode.el;
  6046. const value = isUnmount ? null : refValue;
  6047. const { i: owner, r: ref } = rawRef;
  6048. if (!owner) {
  6049. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  6050. `A vnode with ref must be created inside the render function.`);
  6051. return;
  6052. }
  6053. const oldRef = oldRawRef && oldRawRef.r;
  6054. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  6055. const setupState = owner.setupState;
  6056. // dynamic ref changed. unset old ref
  6057. if (oldRef != null && oldRef !== ref) {
  6058. if (isString(oldRef)) {
  6059. refs[oldRef] = null;
  6060. if (hasOwn(setupState, oldRef)) {
  6061. setupState[oldRef] = null;
  6062. }
  6063. }
  6064. else if (isRef(oldRef)) {
  6065. oldRef.value = null;
  6066. }
  6067. }
  6068. if (isFunction(ref)) {
  6069. callWithErrorHandling(ref, owner, 12 /* ErrorCodes.FUNCTION_REF */, [value, refs]);
  6070. }
  6071. else {
  6072. const _isString = isString(ref);
  6073. const _isRef = isRef(ref);
  6074. if (_isString || _isRef) {
  6075. const doSet = () => {
  6076. if (rawRef.f) {
  6077. const existing = _isString
  6078. ? hasOwn(setupState, ref)
  6079. ? setupState[ref]
  6080. : refs[ref]
  6081. : ref.value;
  6082. if (isUnmount) {
  6083. isArray(existing) && remove(existing, refValue);
  6084. }
  6085. else {
  6086. if (!isArray(existing)) {
  6087. if (_isString) {
  6088. refs[ref] = [refValue];
  6089. if (hasOwn(setupState, ref)) {
  6090. setupState[ref] = refs[ref];
  6091. }
  6092. }
  6093. else {
  6094. ref.value = [refValue];
  6095. if (rawRef.k)
  6096. refs[rawRef.k] = ref.value;
  6097. }
  6098. }
  6099. else if (!existing.includes(refValue)) {
  6100. existing.push(refValue);
  6101. }
  6102. }
  6103. }
  6104. else if (_isString) {
  6105. refs[ref] = value;
  6106. if (hasOwn(setupState, ref)) {
  6107. setupState[ref] = value;
  6108. }
  6109. }
  6110. else if (_isRef) {
  6111. ref.value = value;
  6112. if (rawRef.k)
  6113. refs[rawRef.k] = value;
  6114. }
  6115. else {
  6116. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  6117. }
  6118. };
  6119. if (value) {
  6120. doSet.id = -1;
  6121. queuePostRenderEffect(doSet, parentSuspense);
  6122. }
  6123. else {
  6124. doSet();
  6125. }
  6126. }
  6127. else {
  6128. warn('Invalid template ref type:', ref, `(${typeof ref})`);
  6129. }
  6130. }
  6131. }
  6132. let hasMismatch = false;
  6133. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  6134. const isComment = (node) => node.nodeType === 8 /* DOMNodeTypes.COMMENT */;
  6135. // Note: hydration is DOM-specific
  6136. // But we have to place it in core due to tight coupling with core - splitting
  6137. // it out creates a ton of unnecessary complexity.
  6138. // Hydration also depends on some renderer internal logic which needs to be
  6139. // passed in via arguments.
  6140. function createHydrationFunctions(rendererInternals) {
  6141. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  6142. const hydrate = (vnode, container) => {
  6143. if (!container.hasChildNodes()) {
  6144. warn(`Attempting to hydrate existing markup but container is empty. ` +
  6145. `Performing full mount instead.`);
  6146. patch(null, vnode, container);
  6147. flushPostFlushCbs();
  6148. container._vnode = vnode;
  6149. return;
  6150. }
  6151. hasMismatch = false;
  6152. hydrateNode(container.firstChild, vnode, null, null, null);
  6153. flushPostFlushCbs();
  6154. container._vnode = vnode;
  6155. if (hasMismatch && !false) {
  6156. // this error should show up in production
  6157. console.error(`Hydration completed but contains mismatches.`);
  6158. }
  6159. };
  6160. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  6161. const isFragmentStart = isComment(node) && node.data === '[';
  6162. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  6163. const { type, ref, shapeFlag, patchFlag } = vnode;
  6164. let domType = node.nodeType;
  6165. vnode.el = node;
  6166. if (patchFlag === -2 /* PatchFlags.BAIL */) {
  6167. optimized = false;
  6168. vnode.dynamicChildren = null;
  6169. }
  6170. let nextNode = null;
  6171. switch (type) {
  6172. case Text:
  6173. if (domType !== 3 /* DOMNodeTypes.TEXT */) {
  6174. // #5728 empty text node inside a slot can cause hydration failure
  6175. // because the server rendered HTML won't contain a text node
  6176. if (vnode.children === '') {
  6177. insert((vnode.el = createText('')), parentNode(node), node);
  6178. nextNode = node;
  6179. }
  6180. else {
  6181. nextNode = onMismatch();
  6182. }
  6183. }
  6184. else {
  6185. if (node.data !== vnode.children) {
  6186. hasMismatch = true;
  6187. warn(`Hydration text mismatch:` +
  6188. `\n- Client: ${JSON.stringify(node.data)}` +
  6189. `\n- Server: ${JSON.stringify(vnode.children)}`);
  6190. node.data = vnode.children;
  6191. }
  6192. nextNode = nextSibling(node);
  6193. }
  6194. break;
  6195. case Comment:
  6196. if (domType !== 8 /* DOMNodeTypes.COMMENT */ || isFragmentStart) {
  6197. nextNode = onMismatch();
  6198. }
  6199. else {
  6200. nextNode = nextSibling(node);
  6201. }
  6202. break;
  6203. case Static:
  6204. if (isFragmentStart) {
  6205. // entire template is static but SSRed as a fragment
  6206. node = nextSibling(node);
  6207. domType = node.nodeType;
  6208. }
  6209. if (domType === 1 /* DOMNodeTypes.ELEMENT */ || domType === 3 /* DOMNodeTypes.TEXT */) {
  6210. // determine anchor, adopt content
  6211. nextNode = node;
  6212. // if the static vnode has its content stripped during build,
  6213. // adopt it from the server-rendered HTML.
  6214. const needToAdoptContent = !vnode.children.length;
  6215. for (let i = 0; i < vnode.staticCount; i++) {
  6216. if (needToAdoptContent)
  6217. vnode.children +=
  6218. nextNode.nodeType === 1 /* DOMNodeTypes.ELEMENT */
  6219. ? nextNode.outerHTML
  6220. : nextNode.data;
  6221. if (i === vnode.staticCount - 1) {
  6222. vnode.anchor = nextNode;
  6223. }
  6224. nextNode = nextSibling(nextNode);
  6225. }
  6226. return isFragmentStart ? nextSibling(nextNode) : nextNode;
  6227. }
  6228. else {
  6229. onMismatch();
  6230. }
  6231. break;
  6232. case Fragment:
  6233. if (!isFragmentStart) {
  6234. nextNode = onMismatch();
  6235. }
  6236. else {
  6237. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6238. }
  6239. break;
  6240. default:
  6241. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6242. if (domType !== 1 /* DOMNodeTypes.ELEMENT */ ||
  6243. vnode.type.toLowerCase() !==
  6244. node.tagName.toLowerCase()) {
  6245. nextNode = onMismatch();
  6246. }
  6247. else {
  6248. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6249. }
  6250. }
  6251. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6252. // when setting up the render effect, if the initial vnode already
  6253. // has .el set, the component will perform hydration instead of mount
  6254. // on its sub-tree.
  6255. vnode.slotScopeIds = slotScopeIds;
  6256. const container = parentNode(node);
  6257. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  6258. // component may be async, so in the case of fragments we cannot rely
  6259. // on component's rendered output to determine the end of the fragment
  6260. // instead, we do a lookahead to find the end anchor node.
  6261. nextNode = isFragmentStart
  6262. ? locateClosingAsyncAnchor(node)
  6263. : nextSibling(node);
  6264. // #4293 teleport as component root
  6265. if (nextNode &&
  6266. isComment(nextNode) &&
  6267. nextNode.data === 'teleport end') {
  6268. nextNode = nextSibling(nextNode);
  6269. }
  6270. // #3787
  6271. // if component is async, it may get moved / unmounted before its
  6272. // inner component is loaded, so we need to give it a placeholder
  6273. // vnode that matches its adopted DOM.
  6274. if (isAsyncWrapper(vnode)) {
  6275. let subTree;
  6276. if (isFragmentStart) {
  6277. subTree = createVNode(Fragment);
  6278. subTree.anchor = nextNode
  6279. ? nextNode.previousSibling
  6280. : container.lastChild;
  6281. }
  6282. else {
  6283. subTree =
  6284. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  6285. }
  6286. subTree.el = node;
  6287. vnode.component.subTree = subTree;
  6288. }
  6289. }
  6290. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6291. if (domType !== 8 /* DOMNodeTypes.COMMENT */) {
  6292. nextNode = onMismatch();
  6293. }
  6294. else {
  6295. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  6296. }
  6297. }
  6298. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6299. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  6300. }
  6301. else {
  6302. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  6303. }
  6304. }
  6305. if (ref != null) {
  6306. setRef(ref, null, parentSuspense, vnode);
  6307. }
  6308. return nextNode;
  6309. };
  6310. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6311. optimized = optimized || !!vnode.dynamicChildren;
  6312. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  6313. // #4006 for form elements with non-string v-model value bindings
  6314. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  6315. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  6316. // skip props & children if this is hoisted static nodes
  6317. // #5405 in dev, always hydrate children for HMR
  6318. {
  6319. if (dirs) {
  6320. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6321. }
  6322. // props
  6323. if (props) {
  6324. if (forcePatchValue ||
  6325. !optimized ||
  6326. patchFlag & (16 /* PatchFlags.FULL_PROPS */ | 32 /* PatchFlags.HYDRATE_EVENTS */)) {
  6327. for (const key in props) {
  6328. if ((forcePatchValue && key.endsWith('value')) ||
  6329. (isOn(key) && !isReservedProp(key))) {
  6330. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  6331. }
  6332. }
  6333. }
  6334. else if (props.onClick) {
  6335. // Fast path for click listeners (which is most often) to avoid
  6336. // iterating through props.
  6337. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  6338. }
  6339. }
  6340. // vnode / directive hooks
  6341. let vnodeHooks;
  6342. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  6343. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6344. }
  6345. if (dirs) {
  6346. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6347. }
  6348. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  6349. queueEffectWithSuspense(() => {
  6350. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6351. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6352. }, parentSuspense);
  6353. }
  6354. // children
  6355. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */ &&
  6356. // skip if element has innerHTML / textContent
  6357. !(props && (props.innerHTML || props.textContent))) {
  6358. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  6359. let hasWarned = false;
  6360. while (next) {
  6361. hasMismatch = true;
  6362. if (!hasWarned) {
  6363. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  6364. `server rendered element contains more child nodes than client vdom.`);
  6365. hasWarned = true;
  6366. }
  6367. // The SSRed DOM contains more nodes than it should. Remove them.
  6368. const cur = next;
  6369. next = next.nextSibling;
  6370. remove(cur);
  6371. }
  6372. }
  6373. else if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6374. if (el.textContent !== vnode.children) {
  6375. hasMismatch = true;
  6376. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  6377. `- Client: ${el.textContent}\n` +
  6378. `- Server: ${vnode.children}`);
  6379. el.textContent = vnode.children;
  6380. }
  6381. }
  6382. }
  6383. return el.nextSibling;
  6384. };
  6385. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6386. optimized = optimized || !!parentVNode.dynamicChildren;
  6387. const children = parentVNode.children;
  6388. const l = children.length;
  6389. let hasWarned = false;
  6390. for (let i = 0; i < l; i++) {
  6391. const vnode = optimized
  6392. ? children[i]
  6393. : (children[i] = normalizeVNode(children[i]));
  6394. if (node) {
  6395. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6396. }
  6397. else if (vnode.type === Text && !vnode.children) {
  6398. continue;
  6399. }
  6400. else {
  6401. hasMismatch = true;
  6402. if (!hasWarned) {
  6403. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  6404. `server rendered element contains fewer child nodes than client vdom.`);
  6405. hasWarned = true;
  6406. }
  6407. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  6408. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6409. }
  6410. }
  6411. return node;
  6412. };
  6413. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6414. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  6415. if (fragmentSlotScopeIds) {
  6416. slotScopeIds = slotScopeIds
  6417. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6418. : fragmentSlotScopeIds;
  6419. }
  6420. const container = parentNode(node);
  6421. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  6422. if (next && isComment(next) && next.data === ']') {
  6423. return nextSibling((vnode.anchor = next));
  6424. }
  6425. else {
  6426. // fragment didn't hydrate successfully, since we didn't get a end anchor
  6427. // back. This should have led to node/children mismatch warnings.
  6428. hasMismatch = true;
  6429. // since the anchor is missing, we need to create one and insert it
  6430. insert((vnode.anchor = createComment(`]`)), container, next);
  6431. return next;
  6432. }
  6433. };
  6434. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  6435. hasMismatch = true;
  6436. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* DOMNodeTypes.TEXT */
  6437. ? `(text)`
  6438. : isComment(node) && node.data === '['
  6439. ? `(start of fragment)`
  6440. : ``);
  6441. vnode.el = null;
  6442. if (isFragment) {
  6443. // remove excessive fragment nodes
  6444. const end = locateClosingAsyncAnchor(node);
  6445. while (true) {
  6446. const next = nextSibling(node);
  6447. if (next && next !== end) {
  6448. remove(next);
  6449. }
  6450. else {
  6451. break;
  6452. }
  6453. }
  6454. }
  6455. const next = nextSibling(node);
  6456. const container = parentNode(node);
  6457. remove(node);
  6458. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6459. return next;
  6460. };
  6461. const locateClosingAsyncAnchor = (node) => {
  6462. let match = 0;
  6463. while (node) {
  6464. node = nextSibling(node);
  6465. if (node && isComment(node)) {
  6466. if (node.data === '[')
  6467. match++;
  6468. if (node.data === ']') {
  6469. if (match === 0) {
  6470. return nextSibling(node);
  6471. }
  6472. else {
  6473. match--;
  6474. }
  6475. }
  6476. }
  6477. }
  6478. return node;
  6479. };
  6480. return [hydrate, hydrateNode];
  6481. }
  6482. /* eslint-disable no-restricted-globals */
  6483. let supported;
  6484. let perf;
  6485. function startMeasure(instance, type) {
  6486. if (instance.appContext.config.performance && isSupported()) {
  6487. perf.mark(`vue-${type}-${instance.uid}`);
  6488. }
  6489. {
  6490. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  6491. }
  6492. }
  6493. function endMeasure(instance, type) {
  6494. if (instance.appContext.config.performance && isSupported()) {
  6495. const startTag = `vue-${type}-${instance.uid}`;
  6496. const endTag = startTag + `:end`;
  6497. perf.mark(endTag);
  6498. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  6499. perf.clearMarks(startTag);
  6500. perf.clearMarks(endTag);
  6501. }
  6502. {
  6503. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  6504. }
  6505. }
  6506. function isSupported() {
  6507. if (supported !== undefined) {
  6508. return supported;
  6509. }
  6510. if (typeof window !== 'undefined' && window.performance) {
  6511. supported = true;
  6512. perf = window.performance;
  6513. }
  6514. else {
  6515. supported = false;
  6516. }
  6517. return supported;
  6518. }
  6519. const queuePostRenderEffect = queueEffectWithSuspense
  6520. ;
  6521. /**
  6522. * The createRenderer function accepts two generic arguments:
  6523. * HostNode and HostElement, corresponding to Node and Element types in the
  6524. * host environment. For example, for runtime-dom, HostNode would be the DOM
  6525. * `Node` interface and HostElement would be the DOM `Element` interface.
  6526. *
  6527. * Custom renderers can pass in the platform specific types like this:
  6528. *
  6529. * ``` js
  6530. * const { render, createApp } = createRenderer<Node, Element>({
  6531. * patchProp,
  6532. * ...nodeOps
  6533. * })
  6534. * ```
  6535. */
  6536. function createRenderer(options) {
  6537. return baseCreateRenderer(options);
  6538. }
  6539. // Separate API for creating hydration-enabled renderer.
  6540. // Hydration logic is only used when calling this function, making it
  6541. // tree-shakable.
  6542. function createHydrationRenderer(options) {
  6543. return baseCreateRenderer(options, createHydrationFunctions);
  6544. }
  6545. // implementation
  6546. function baseCreateRenderer(options, createHydrationFns) {
  6547. const target = getGlobalThis();
  6548. target.__VUE__ = true;
  6549. {
  6550. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  6551. }
  6552. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, insertStaticContent: hostInsertStaticContent } = options;
  6553. // Note: functions inside this closure should use `const xxx = () => {}`
  6554. // style in order to prevent being inlined by minifiers.
  6555. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  6556. if (n1 === n2) {
  6557. return;
  6558. }
  6559. // patching & not same type, unmount old tree
  6560. if (n1 && !isSameVNodeType(n1, n2)) {
  6561. anchor = getNextHostNode(n1);
  6562. unmount(n1, parentComponent, parentSuspense, true);
  6563. n1 = null;
  6564. }
  6565. if (n2.patchFlag === -2 /* PatchFlags.BAIL */) {
  6566. optimized = false;
  6567. n2.dynamicChildren = null;
  6568. }
  6569. const { type, ref, shapeFlag } = n2;
  6570. switch (type) {
  6571. case Text:
  6572. processText(n1, n2, container, anchor);
  6573. break;
  6574. case Comment:
  6575. processCommentNode(n1, n2, container, anchor);
  6576. break;
  6577. case Static:
  6578. if (n1 == null) {
  6579. mountStaticNode(n2, container, anchor, isSVG);
  6580. }
  6581. else {
  6582. patchStaticNode(n1, n2, container, isSVG);
  6583. }
  6584. break;
  6585. case Fragment:
  6586. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6587. break;
  6588. default:
  6589. if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6590. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6591. }
  6592. else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6593. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6594. }
  6595. else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  6596. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6597. }
  6598. else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6599. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6600. }
  6601. else {
  6602. warn('Invalid VNode type:', type, `(${typeof type})`);
  6603. }
  6604. }
  6605. // set ref
  6606. if (ref != null && parentComponent) {
  6607. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  6608. }
  6609. };
  6610. const processText = (n1, n2, container, anchor) => {
  6611. if (n1 == null) {
  6612. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  6613. }
  6614. else {
  6615. const el = (n2.el = n1.el);
  6616. if (n2.children !== n1.children) {
  6617. hostSetText(el, n2.children);
  6618. }
  6619. }
  6620. };
  6621. const processCommentNode = (n1, n2, container, anchor) => {
  6622. if (n1 == null) {
  6623. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  6624. }
  6625. else {
  6626. // there's no support for dynamic comments
  6627. n2.el = n1.el;
  6628. }
  6629. };
  6630. const mountStaticNode = (n2, container, anchor, isSVG) => {
  6631. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  6632. };
  6633. /**
  6634. * Dev / HMR only
  6635. */
  6636. const patchStaticNode = (n1, n2, container, isSVG) => {
  6637. // static nodes are only patched during dev for HMR
  6638. if (n2.children !== n1.children) {
  6639. const anchor = hostNextSibling(n1.anchor);
  6640. // remove existing
  6641. removeStaticNode(n1);
  6642. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  6643. }
  6644. else {
  6645. n2.el = n1.el;
  6646. n2.anchor = n1.anchor;
  6647. }
  6648. };
  6649. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6650. let next;
  6651. while (el && el !== anchor) {
  6652. next = hostNextSibling(el);
  6653. hostInsert(el, container, nextSibling);
  6654. el = next;
  6655. }
  6656. hostInsert(anchor, container, nextSibling);
  6657. };
  6658. const removeStaticNode = ({ el, anchor }) => {
  6659. let next;
  6660. while (el && el !== anchor) {
  6661. next = hostNextSibling(el);
  6662. hostRemove(el);
  6663. el = next;
  6664. }
  6665. hostRemove(anchor);
  6666. };
  6667. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6668. isSVG = isSVG || n2.type === 'svg';
  6669. if (n1 == null) {
  6670. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6671. }
  6672. else {
  6673. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6674. }
  6675. };
  6676. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6677. let el;
  6678. let vnodeHook;
  6679. const { type, props, shapeFlag, transition, dirs } = vnode;
  6680. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6681. // mount children first, since some props may rely on child content
  6682. // being already rendered, e.g. `<select value>`
  6683. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  6684. hostSetElementText(el, vnode.children);
  6685. }
  6686. else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6687. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6688. }
  6689. if (dirs) {
  6690. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6691. }
  6692. // scopeId
  6693. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6694. // props
  6695. if (props) {
  6696. for (const key in props) {
  6697. if (key !== 'value' && !isReservedProp(key)) {
  6698. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6699. }
  6700. }
  6701. /**
  6702. * Special case for setting value on DOM elements:
  6703. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6704. * - it needs to be forced (#1471)
  6705. * #2353 proposes adding another renderer option to configure this, but
  6706. * the properties affects are so finite it is worth special casing it
  6707. * here to reduce the complexity. (Special casing it also should not
  6708. * affect non-DOM renderers)
  6709. */
  6710. if ('value' in props) {
  6711. hostPatchProp(el, 'value', null, props.value);
  6712. }
  6713. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6714. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6715. }
  6716. }
  6717. {
  6718. Object.defineProperty(el, '__vnode', {
  6719. value: vnode,
  6720. enumerable: false
  6721. });
  6722. Object.defineProperty(el, '__vueParentComponent', {
  6723. value: parentComponent,
  6724. enumerable: false
  6725. });
  6726. }
  6727. if (dirs) {
  6728. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6729. }
  6730. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6731. // #1689 For inside suspense + suspense resolved case, just call it
  6732. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6733. transition &&
  6734. !transition.persisted;
  6735. if (needCallTransitionHooks) {
  6736. transition.beforeEnter(el);
  6737. }
  6738. hostInsert(el, container, anchor);
  6739. if ((vnodeHook = props && props.onVnodeMounted) ||
  6740. needCallTransitionHooks ||
  6741. dirs) {
  6742. queuePostRenderEffect(() => {
  6743. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6744. needCallTransitionHooks && transition.enter(el);
  6745. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6746. }, parentSuspense);
  6747. }
  6748. };
  6749. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6750. if (scopeId) {
  6751. hostSetScopeId(el, scopeId);
  6752. }
  6753. if (slotScopeIds) {
  6754. for (let i = 0; i < slotScopeIds.length; i++) {
  6755. hostSetScopeId(el, slotScopeIds[i]);
  6756. }
  6757. }
  6758. if (parentComponent) {
  6759. let subTree = parentComponent.subTree;
  6760. if (subTree.patchFlag > 0 &&
  6761. subTree.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */) {
  6762. subTree =
  6763. filterSingleRoot(subTree.children) || subTree;
  6764. }
  6765. if (vnode === subTree) {
  6766. const parentVNode = parentComponent.vnode;
  6767. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6768. }
  6769. }
  6770. };
  6771. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6772. for (let i = start; i < children.length; i++) {
  6773. const child = (children[i] = optimized
  6774. ? cloneIfMounted(children[i])
  6775. : normalizeVNode(children[i]));
  6776. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6777. }
  6778. };
  6779. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6780. const el = (n2.el = n1.el);
  6781. let { patchFlag, dynamicChildren, dirs } = n2;
  6782. // #1426 take the old vnode's patch flag into account since user may clone a
  6783. // compiler-generated vnode, which de-opts to FULL_PROPS
  6784. patchFlag |= n1.patchFlag & 16 /* PatchFlags.FULL_PROPS */;
  6785. const oldProps = n1.props || EMPTY_OBJ;
  6786. const newProps = n2.props || EMPTY_OBJ;
  6787. let vnodeHook;
  6788. // disable recurse in beforeUpdate hooks
  6789. parentComponent && toggleRecurse(parentComponent, false);
  6790. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6791. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6792. }
  6793. if (dirs) {
  6794. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6795. }
  6796. parentComponent && toggleRecurse(parentComponent, true);
  6797. if (isHmrUpdating) {
  6798. // HMR updated, force full diff
  6799. patchFlag = 0;
  6800. optimized = false;
  6801. dynamicChildren = null;
  6802. }
  6803. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6804. if (dynamicChildren) {
  6805. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6806. if (parentComponent && parentComponent.type.__hmrId) {
  6807. traverseStaticChildren(n1, n2);
  6808. }
  6809. }
  6810. else if (!optimized) {
  6811. // full diff
  6812. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6813. }
  6814. if (patchFlag > 0) {
  6815. // the presence of a patchFlag means this element's render code was
  6816. // generated by the compiler and can take the fast path.
  6817. // in this path old node and new node are guaranteed to have the same shape
  6818. // (i.e. at the exact same position in the source template)
  6819. if (patchFlag & 16 /* PatchFlags.FULL_PROPS */) {
  6820. // element props contain dynamic keys, full diff needed
  6821. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6822. }
  6823. else {
  6824. // class
  6825. // this flag is matched when the element has dynamic class bindings.
  6826. if (patchFlag & 2 /* PatchFlags.CLASS */) {
  6827. if (oldProps.class !== newProps.class) {
  6828. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6829. }
  6830. }
  6831. // style
  6832. // this flag is matched when the element has dynamic style bindings
  6833. if (patchFlag & 4 /* PatchFlags.STYLE */) {
  6834. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6835. }
  6836. // props
  6837. // This flag is matched when the element has dynamic prop/attr bindings
  6838. // other than class and style. The keys of dynamic prop/attrs are saved for
  6839. // faster iteration.
  6840. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6841. // bail out and go through a full diff because we need to unset the old key
  6842. if (patchFlag & 8 /* PatchFlags.PROPS */) {
  6843. // if the flag is present then dynamicProps must be non-null
  6844. const propsToUpdate = n2.dynamicProps;
  6845. for (let i = 0; i < propsToUpdate.length; i++) {
  6846. const key = propsToUpdate[i];
  6847. const prev = oldProps[key];
  6848. const next = newProps[key];
  6849. // #1471 force patch value
  6850. if (next !== prev || key === 'value') {
  6851. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6852. }
  6853. }
  6854. }
  6855. }
  6856. // text
  6857. // This flag is matched when the element has only dynamic text children.
  6858. if (patchFlag & 1 /* PatchFlags.TEXT */) {
  6859. if (n1.children !== n2.children) {
  6860. hostSetElementText(el, n2.children);
  6861. }
  6862. }
  6863. }
  6864. else if (!optimized && dynamicChildren == null) {
  6865. // unoptimized, full diff
  6866. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6867. }
  6868. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6869. queuePostRenderEffect(() => {
  6870. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6871. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6872. }, parentSuspense);
  6873. }
  6874. };
  6875. // The fast path for blocks.
  6876. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6877. for (let i = 0; i < newChildren.length; i++) {
  6878. const oldVNode = oldChildren[i];
  6879. const newVNode = newChildren[i];
  6880. // Determine the container (parent element) for the patch.
  6881. const container =
  6882. // oldVNode may be an errored async setup() component inside Suspense
  6883. // which will not have a mounted element
  6884. oldVNode.el &&
  6885. // - In the case of a Fragment, we need to provide the actual parent
  6886. // of the Fragment itself so it can move its children.
  6887. (oldVNode.type === Fragment ||
  6888. // - In the case of different nodes, there is going to be a replacement
  6889. // which also requires the correct parent container
  6890. !isSameVNodeType(oldVNode, newVNode) ||
  6891. // - In the case of a component, it could contain anything.
  6892. oldVNode.shapeFlag & (6 /* ShapeFlags.COMPONENT */ | 64 /* ShapeFlags.TELEPORT */))
  6893. ? hostParentNode(oldVNode.el)
  6894. : // In other cases, the parent container is not actually used so we
  6895. // just pass the block element here to avoid a DOM parentNode call.
  6896. fallbackContainer;
  6897. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6898. }
  6899. };
  6900. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6901. if (oldProps !== newProps) {
  6902. if (oldProps !== EMPTY_OBJ) {
  6903. for (const key in oldProps) {
  6904. if (!isReservedProp(key) && !(key in newProps)) {
  6905. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6906. }
  6907. }
  6908. }
  6909. for (const key in newProps) {
  6910. // empty string is not valid prop
  6911. if (isReservedProp(key))
  6912. continue;
  6913. const next = newProps[key];
  6914. const prev = oldProps[key];
  6915. // defer patching value
  6916. if (next !== prev && key !== 'value') {
  6917. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6918. }
  6919. }
  6920. if ('value' in newProps) {
  6921. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6922. }
  6923. }
  6924. };
  6925. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6926. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6927. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6928. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6929. if (// #5523 dev root fragment may inherit directives
  6930. (isHmrUpdating || patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */)) {
  6931. // HMR updated / Dev root fragment (w/ comments), force full diff
  6932. patchFlag = 0;
  6933. optimized = false;
  6934. dynamicChildren = null;
  6935. }
  6936. // check if this is a slot fragment with :slotted scope ids
  6937. if (fragmentSlotScopeIds) {
  6938. slotScopeIds = slotScopeIds
  6939. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6940. : fragmentSlotScopeIds;
  6941. }
  6942. if (n1 == null) {
  6943. hostInsert(fragmentStartAnchor, container, anchor);
  6944. hostInsert(fragmentEndAnchor, container, anchor);
  6945. // a fragment can only have array children
  6946. // since they are either generated by the compiler, or implicitly created
  6947. // from arrays.
  6948. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6949. }
  6950. else {
  6951. if (patchFlag > 0 &&
  6952. patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */ &&
  6953. dynamicChildren &&
  6954. // #2715 the previous fragment could've been a BAILed one as a result
  6955. // of renderSlot() with no valid children
  6956. n1.dynamicChildren) {
  6957. // a stable fragment (template root or <template v-for>) doesn't need to
  6958. // patch children order, but it may contain dynamicChildren.
  6959. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6960. if (parentComponent && parentComponent.type.__hmrId) {
  6961. traverseStaticChildren(n1, n2);
  6962. }
  6963. else if (
  6964. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6965. // get moved around. Make sure all root level vnodes inherit el.
  6966. // #2134 or if it's a component root, it may also get moved around
  6967. // as the component is being moved.
  6968. n2.key != null ||
  6969. (parentComponent && n2 === parentComponent.subTree)) {
  6970. traverseStaticChildren(n1, n2, true /* shallow */);
  6971. }
  6972. }
  6973. else {
  6974. // keyed / unkeyed, or manual fragments.
  6975. // for keyed & unkeyed, since they are compiler generated from v-for,
  6976. // each child is guaranteed to be a block so the fragment will never
  6977. // have dynamicChildren.
  6978. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6979. }
  6980. }
  6981. };
  6982. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6983. n2.slotScopeIds = slotScopeIds;
  6984. if (n1 == null) {
  6985. if (n2.shapeFlag & 512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */) {
  6986. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6987. }
  6988. else {
  6989. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6990. }
  6991. }
  6992. else {
  6993. updateComponent(n1, n2, optimized);
  6994. }
  6995. };
  6996. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6997. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6998. if (instance.type.__hmrId) {
  6999. registerHMR(instance);
  7000. }
  7001. {
  7002. pushWarningContext(initialVNode);
  7003. startMeasure(instance, `mount`);
  7004. }
  7005. // inject renderer internals for keepAlive
  7006. if (isKeepAlive(initialVNode)) {
  7007. instance.ctx.renderer = internals;
  7008. }
  7009. // resolve props and slots for setup context
  7010. {
  7011. {
  7012. startMeasure(instance, `init`);
  7013. }
  7014. setupComponent(instance);
  7015. {
  7016. endMeasure(instance, `init`);
  7017. }
  7018. }
  7019. // setup() is async. This component relies on async logic to be resolved
  7020. // before proceeding
  7021. if (instance.asyncDep) {
  7022. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  7023. // Give it a placeholder if this is not hydration
  7024. // TODO handle self-defined fallback
  7025. if (!initialVNode.el) {
  7026. const placeholder = (instance.subTree = createVNode(Comment));
  7027. processCommentNode(null, placeholder, container, anchor);
  7028. }
  7029. return;
  7030. }
  7031. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  7032. {
  7033. popWarningContext();
  7034. endMeasure(instance, `mount`);
  7035. }
  7036. };
  7037. const updateComponent = (n1, n2, optimized) => {
  7038. const instance = (n2.component = n1.component);
  7039. if (shouldUpdateComponent(n1, n2, optimized)) {
  7040. if (instance.asyncDep &&
  7041. !instance.asyncResolved) {
  7042. // async & still pending - just update props and slots
  7043. // since the component's reactive effect for render isn't set-up yet
  7044. {
  7045. pushWarningContext(n2);
  7046. }
  7047. updateComponentPreRender(instance, n2, optimized);
  7048. {
  7049. popWarningContext();
  7050. }
  7051. return;
  7052. }
  7053. else {
  7054. // normal update
  7055. instance.next = n2;
  7056. // in case the child component is also queued, remove it to avoid
  7057. // double updating the same child component in the same flush.
  7058. invalidateJob(instance.update);
  7059. // instance.update is the reactive effect.
  7060. instance.update();
  7061. }
  7062. }
  7063. else {
  7064. // no update needed. just copy over properties
  7065. n2.el = n1.el;
  7066. instance.vnode = n2;
  7067. }
  7068. };
  7069. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  7070. const componentUpdateFn = () => {
  7071. if (!instance.isMounted) {
  7072. let vnodeHook;
  7073. const { el, props } = initialVNode;
  7074. const { bm, m, parent } = instance;
  7075. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  7076. toggleRecurse(instance, false);
  7077. // beforeMount hook
  7078. if (bm) {
  7079. invokeArrayFns(bm);
  7080. }
  7081. // onVnodeBeforeMount
  7082. if (!isAsyncWrapperVNode &&
  7083. (vnodeHook = props && props.onVnodeBeforeMount)) {
  7084. invokeVNodeHook(vnodeHook, parent, initialVNode);
  7085. }
  7086. toggleRecurse(instance, true);
  7087. if (el && hydrateNode) {
  7088. // vnode has adopted host node - perform hydration instead of mount.
  7089. const hydrateSubTree = () => {
  7090. {
  7091. startMeasure(instance, `render`);
  7092. }
  7093. instance.subTree = renderComponentRoot(instance);
  7094. {
  7095. endMeasure(instance, `render`);
  7096. }
  7097. {
  7098. startMeasure(instance, `hydrate`);
  7099. }
  7100. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  7101. {
  7102. endMeasure(instance, `hydrate`);
  7103. }
  7104. };
  7105. if (isAsyncWrapperVNode) {
  7106. initialVNode.type.__asyncLoader().then(
  7107. // note: we are moving the render call into an async callback,
  7108. // which means it won't track dependencies - but it's ok because
  7109. // a server-rendered async wrapper is already in resolved state
  7110. // and it will never need to change.
  7111. () => !instance.isUnmounted && hydrateSubTree());
  7112. }
  7113. else {
  7114. hydrateSubTree();
  7115. }
  7116. }
  7117. else {
  7118. {
  7119. startMeasure(instance, `render`);
  7120. }
  7121. const subTree = (instance.subTree = renderComponentRoot(instance));
  7122. {
  7123. endMeasure(instance, `render`);
  7124. }
  7125. {
  7126. startMeasure(instance, `patch`);
  7127. }
  7128. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  7129. {
  7130. endMeasure(instance, `patch`);
  7131. }
  7132. initialVNode.el = subTree.el;
  7133. }
  7134. // mounted hook
  7135. if (m) {
  7136. queuePostRenderEffect(m, parentSuspense);
  7137. }
  7138. // onVnodeMounted
  7139. if (!isAsyncWrapperVNode &&
  7140. (vnodeHook = props && props.onVnodeMounted)) {
  7141. const scopedInitialVNode = initialVNode;
  7142. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  7143. }
  7144. // activated hook for keep-alive roots.
  7145. // #1742 activated hook must be accessed after first render
  7146. // since the hook may be injected by a child keep-alive
  7147. if (initialVNode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */ ||
  7148. (parent &&
  7149. isAsyncWrapper(parent.vnode) &&
  7150. parent.vnode.shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */)) {
  7151. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  7152. }
  7153. instance.isMounted = true;
  7154. {
  7155. devtoolsComponentAdded(instance);
  7156. }
  7157. // #2458: deference mount-only object parameters to prevent memleaks
  7158. initialVNode = container = anchor = null;
  7159. }
  7160. else {
  7161. // updateComponent
  7162. // This is triggered by mutation of component's own state (next: null)
  7163. // OR parent calling processComponent (next: VNode)
  7164. let { next, bu, u, parent, vnode } = instance;
  7165. let originNext = next;
  7166. let vnodeHook;
  7167. {
  7168. pushWarningContext(next || instance.vnode);
  7169. }
  7170. // Disallow component effect recursion during pre-lifecycle hooks.
  7171. toggleRecurse(instance, false);
  7172. if (next) {
  7173. next.el = vnode.el;
  7174. updateComponentPreRender(instance, next, optimized);
  7175. }
  7176. else {
  7177. next = vnode;
  7178. }
  7179. // beforeUpdate hook
  7180. if (bu) {
  7181. invokeArrayFns(bu);
  7182. }
  7183. // onVnodeBeforeUpdate
  7184. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  7185. invokeVNodeHook(vnodeHook, parent, next, vnode);
  7186. }
  7187. toggleRecurse(instance, true);
  7188. // render
  7189. {
  7190. startMeasure(instance, `render`);
  7191. }
  7192. const nextTree = renderComponentRoot(instance);
  7193. {
  7194. endMeasure(instance, `render`);
  7195. }
  7196. const prevTree = instance.subTree;
  7197. instance.subTree = nextTree;
  7198. {
  7199. startMeasure(instance, `patch`);
  7200. }
  7201. patch(prevTree, nextTree,
  7202. // parent may have changed if it's in a teleport
  7203. hostParentNode(prevTree.el),
  7204. // anchor may have changed if it's in a fragment
  7205. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  7206. {
  7207. endMeasure(instance, `patch`);
  7208. }
  7209. next.el = nextTree.el;
  7210. if (originNext === null) {
  7211. // self-triggered update. In case of HOC, update parent component
  7212. // vnode el. HOC is indicated by parent instance's subTree pointing
  7213. // to child component's vnode
  7214. updateHOCHostEl(instance, nextTree.el);
  7215. }
  7216. // updated hook
  7217. if (u) {
  7218. queuePostRenderEffect(u, parentSuspense);
  7219. }
  7220. // onVnodeUpdated
  7221. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  7222. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  7223. }
  7224. {
  7225. devtoolsComponentUpdated(instance);
  7226. }
  7227. {
  7228. popWarningContext();
  7229. }
  7230. }
  7231. };
  7232. // create reactive effect for rendering
  7233. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  7234. ));
  7235. const update = (instance.update = () => effect.run());
  7236. update.id = instance.uid;
  7237. // allowRecurse
  7238. // #1801, #2043 component render effects should allow recursive updates
  7239. toggleRecurse(instance, true);
  7240. {
  7241. effect.onTrack = instance.rtc
  7242. ? e => invokeArrayFns(instance.rtc, e)
  7243. : void 0;
  7244. effect.onTrigger = instance.rtg
  7245. ? e => invokeArrayFns(instance.rtg, e)
  7246. : void 0;
  7247. update.ownerInstance = instance;
  7248. }
  7249. update();
  7250. };
  7251. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  7252. nextVNode.component = instance;
  7253. const prevProps = instance.vnode.props;
  7254. instance.vnode = nextVNode;
  7255. instance.next = null;
  7256. updateProps(instance, nextVNode.props, prevProps, optimized);
  7257. updateSlots(instance, nextVNode.children, optimized);
  7258. pauseTracking();
  7259. // props update may have triggered pre-flush watchers.
  7260. // flush them before the render update.
  7261. flushPreFlushCbs();
  7262. resetTracking();
  7263. };
  7264. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  7265. const c1 = n1 && n1.children;
  7266. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  7267. const c2 = n2.children;
  7268. const { patchFlag, shapeFlag } = n2;
  7269. // fast path
  7270. if (patchFlag > 0) {
  7271. if (patchFlag & 128 /* PatchFlags.KEYED_FRAGMENT */) {
  7272. // this could be either fully-keyed or mixed (some keyed some not)
  7273. // presence of patchFlag means children are guaranteed to be arrays
  7274. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7275. return;
  7276. }
  7277. else if (patchFlag & 256 /* PatchFlags.UNKEYED_FRAGMENT */) {
  7278. // unkeyed
  7279. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7280. return;
  7281. }
  7282. }
  7283. // children has 3 possibilities: text, array or no children.
  7284. if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7285. // text children fast path
  7286. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7287. unmountChildren(c1, parentComponent, parentSuspense);
  7288. }
  7289. if (c2 !== c1) {
  7290. hostSetElementText(container, c2);
  7291. }
  7292. }
  7293. else {
  7294. if (prevShapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7295. // prev children was array
  7296. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7297. // two arrays, cannot assume anything, do full diff
  7298. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7299. }
  7300. else {
  7301. // no new children, just unmount old
  7302. unmountChildren(c1, parentComponent, parentSuspense, true);
  7303. }
  7304. }
  7305. else {
  7306. // prev children was text OR null
  7307. // new children is array OR null
  7308. if (prevShapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
  7309. hostSetElementText(container, '');
  7310. }
  7311. // mount new if array
  7312. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7313. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7314. }
  7315. }
  7316. }
  7317. };
  7318. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7319. c1 = c1 || EMPTY_ARR;
  7320. c2 = c2 || EMPTY_ARR;
  7321. const oldLength = c1.length;
  7322. const newLength = c2.length;
  7323. const commonLength = Math.min(oldLength, newLength);
  7324. let i;
  7325. for (i = 0; i < commonLength; i++) {
  7326. const nextChild = (c2[i] = optimized
  7327. ? cloneIfMounted(c2[i])
  7328. : normalizeVNode(c2[i]));
  7329. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7330. }
  7331. if (oldLength > newLength) {
  7332. // remove old
  7333. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  7334. }
  7335. else {
  7336. // mount new
  7337. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  7338. }
  7339. };
  7340. // can be all-keyed or mixed
  7341. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7342. let i = 0;
  7343. const l2 = c2.length;
  7344. let e1 = c1.length - 1; // prev ending index
  7345. let e2 = l2 - 1; // next ending index
  7346. // 1. sync from start
  7347. // (a b) c
  7348. // (a b) d e
  7349. while (i <= e1 && i <= e2) {
  7350. const n1 = c1[i];
  7351. const n2 = (c2[i] = optimized
  7352. ? cloneIfMounted(c2[i])
  7353. : normalizeVNode(c2[i]));
  7354. if (isSameVNodeType(n1, n2)) {
  7355. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7356. }
  7357. else {
  7358. break;
  7359. }
  7360. i++;
  7361. }
  7362. // 2. sync from end
  7363. // a (b c)
  7364. // d e (b c)
  7365. while (i <= e1 && i <= e2) {
  7366. const n1 = c1[e1];
  7367. const n2 = (c2[e2] = optimized
  7368. ? cloneIfMounted(c2[e2])
  7369. : normalizeVNode(c2[e2]));
  7370. if (isSameVNodeType(n1, n2)) {
  7371. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7372. }
  7373. else {
  7374. break;
  7375. }
  7376. e1--;
  7377. e2--;
  7378. }
  7379. // 3. common sequence + mount
  7380. // (a b)
  7381. // (a b) c
  7382. // i = 2, e1 = 1, e2 = 2
  7383. // (a b)
  7384. // c (a b)
  7385. // i = 0, e1 = -1, e2 = 0
  7386. if (i > e1) {
  7387. if (i <= e2) {
  7388. const nextPos = e2 + 1;
  7389. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  7390. while (i <= e2) {
  7391. patch(null, (c2[i] = optimized
  7392. ? cloneIfMounted(c2[i])
  7393. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7394. i++;
  7395. }
  7396. }
  7397. }
  7398. // 4. common sequence + unmount
  7399. // (a b) c
  7400. // (a b)
  7401. // i = 2, e1 = 2, e2 = 1
  7402. // a (b c)
  7403. // (b c)
  7404. // i = 0, e1 = 0, e2 = -1
  7405. else if (i > e2) {
  7406. while (i <= e1) {
  7407. unmount(c1[i], parentComponent, parentSuspense, true);
  7408. i++;
  7409. }
  7410. }
  7411. // 5. unknown sequence
  7412. // [i ... e1 + 1]: a b [c d e] f g
  7413. // [i ... e2 + 1]: a b [e d c h] f g
  7414. // i = 2, e1 = 4, e2 = 5
  7415. else {
  7416. const s1 = i; // prev starting index
  7417. const s2 = i; // next starting index
  7418. // 5.1 build key:index map for newChildren
  7419. const keyToNewIndexMap = new Map();
  7420. for (i = s2; i <= e2; i++) {
  7421. const nextChild = (c2[i] = optimized
  7422. ? cloneIfMounted(c2[i])
  7423. : normalizeVNode(c2[i]));
  7424. if (nextChild.key != null) {
  7425. if (keyToNewIndexMap.has(nextChild.key)) {
  7426. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  7427. }
  7428. keyToNewIndexMap.set(nextChild.key, i);
  7429. }
  7430. }
  7431. // 5.2 loop through old children left to be patched and try to patch
  7432. // matching nodes & remove nodes that are no longer present
  7433. let j;
  7434. let patched = 0;
  7435. const toBePatched = e2 - s2 + 1;
  7436. let moved = false;
  7437. // used to track whether any node has moved
  7438. let maxNewIndexSoFar = 0;
  7439. // works as Map<newIndex, oldIndex>
  7440. // Note that oldIndex is offset by +1
  7441. // and oldIndex = 0 is a special value indicating the new node has
  7442. // no corresponding old node.
  7443. // used for determining longest stable subsequence
  7444. const newIndexToOldIndexMap = new Array(toBePatched);
  7445. for (i = 0; i < toBePatched; i++)
  7446. newIndexToOldIndexMap[i] = 0;
  7447. for (i = s1; i <= e1; i++) {
  7448. const prevChild = c1[i];
  7449. if (patched >= toBePatched) {
  7450. // all new children have been patched so this can only be a removal
  7451. unmount(prevChild, parentComponent, parentSuspense, true);
  7452. continue;
  7453. }
  7454. let newIndex;
  7455. if (prevChild.key != null) {
  7456. newIndex = keyToNewIndexMap.get(prevChild.key);
  7457. }
  7458. else {
  7459. // key-less node, try to locate a key-less node of the same type
  7460. for (j = s2; j <= e2; j++) {
  7461. if (newIndexToOldIndexMap[j - s2] === 0 &&
  7462. isSameVNodeType(prevChild, c2[j])) {
  7463. newIndex = j;
  7464. break;
  7465. }
  7466. }
  7467. }
  7468. if (newIndex === undefined) {
  7469. unmount(prevChild, parentComponent, parentSuspense, true);
  7470. }
  7471. else {
  7472. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  7473. if (newIndex >= maxNewIndexSoFar) {
  7474. maxNewIndexSoFar = newIndex;
  7475. }
  7476. else {
  7477. moved = true;
  7478. }
  7479. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7480. patched++;
  7481. }
  7482. }
  7483. // 5.3 move and mount
  7484. // generate longest stable subsequence only when nodes have moved
  7485. const increasingNewIndexSequence = moved
  7486. ? getSequence(newIndexToOldIndexMap)
  7487. : EMPTY_ARR;
  7488. j = increasingNewIndexSequence.length - 1;
  7489. // looping backwards so that we can use last patched node as anchor
  7490. for (i = toBePatched - 1; i >= 0; i--) {
  7491. const nextIndex = s2 + i;
  7492. const nextChild = c2[nextIndex];
  7493. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  7494. if (newIndexToOldIndexMap[i] === 0) {
  7495. // mount new
  7496. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7497. }
  7498. else if (moved) {
  7499. // move if:
  7500. // There is no stable subsequence (e.g. a reverse)
  7501. // OR current node is not among the stable sequence
  7502. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  7503. move(nextChild, container, anchor, 2 /* MoveType.REORDER */);
  7504. }
  7505. else {
  7506. j--;
  7507. }
  7508. }
  7509. }
  7510. }
  7511. };
  7512. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  7513. const { el, type, transition, children, shapeFlag } = vnode;
  7514. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7515. move(vnode.component.subTree, container, anchor, moveType);
  7516. return;
  7517. }
  7518. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7519. vnode.suspense.move(container, anchor, moveType);
  7520. return;
  7521. }
  7522. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7523. type.move(vnode, container, anchor, internals);
  7524. return;
  7525. }
  7526. if (type === Fragment) {
  7527. hostInsert(el, container, anchor);
  7528. for (let i = 0; i < children.length; i++) {
  7529. move(children[i], container, anchor, moveType);
  7530. }
  7531. hostInsert(vnode.anchor, container, anchor);
  7532. return;
  7533. }
  7534. if (type === Static) {
  7535. moveStaticNode(vnode, container, anchor);
  7536. return;
  7537. }
  7538. // single nodes
  7539. const needTransition = moveType !== 2 /* MoveType.REORDER */ &&
  7540. shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7541. transition;
  7542. if (needTransition) {
  7543. if (moveType === 0 /* MoveType.ENTER */) {
  7544. transition.beforeEnter(el);
  7545. hostInsert(el, container, anchor);
  7546. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  7547. }
  7548. else {
  7549. const { leave, delayLeave, afterLeave } = transition;
  7550. const remove = () => hostInsert(el, container, anchor);
  7551. const performLeave = () => {
  7552. leave(el, () => {
  7553. remove();
  7554. afterLeave && afterLeave();
  7555. });
  7556. };
  7557. if (delayLeave) {
  7558. delayLeave(el, remove, performLeave);
  7559. }
  7560. else {
  7561. performLeave();
  7562. }
  7563. }
  7564. }
  7565. else {
  7566. hostInsert(el, container, anchor);
  7567. }
  7568. };
  7569. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  7570. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  7571. // unset ref
  7572. if (ref != null) {
  7573. setRef(ref, null, parentSuspense, vnode, true);
  7574. }
  7575. if (shapeFlag & 256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */) {
  7576. parentComponent.ctx.deactivate(vnode);
  7577. return;
  7578. }
  7579. const shouldInvokeDirs = shapeFlag & 1 /* ShapeFlags.ELEMENT */ && dirs;
  7580. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  7581. let vnodeHook;
  7582. if (shouldInvokeVnodeHook &&
  7583. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  7584. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7585. }
  7586. if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7587. unmountComponent(vnode.component, parentSuspense, doRemove);
  7588. }
  7589. else {
  7590. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7591. vnode.suspense.unmount(parentSuspense, doRemove);
  7592. return;
  7593. }
  7594. if (shouldInvokeDirs) {
  7595. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  7596. }
  7597. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  7598. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  7599. }
  7600. else if (dynamicChildren &&
  7601. // #1153: fast path should not be taken for non-stable (v-for) fragments
  7602. (type !== Fragment ||
  7603. (patchFlag > 0 && patchFlag & 64 /* PatchFlags.STABLE_FRAGMENT */))) {
  7604. // fast path for block nodes: only need to unmount dynamic children.
  7605. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  7606. }
  7607. else if ((type === Fragment &&
  7608. patchFlag &
  7609. (128 /* PatchFlags.KEYED_FRAGMENT */ | 256 /* PatchFlags.UNKEYED_FRAGMENT */)) ||
  7610. (!optimized && shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */)) {
  7611. unmountChildren(children, parentComponent, parentSuspense);
  7612. }
  7613. if (doRemove) {
  7614. remove(vnode);
  7615. }
  7616. }
  7617. if ((shouldInvokeVnodeHook &&
  7618. (vnodeHook = props && props.onVnodeUnmounted)) ||
  7619. shouldInvokeDirs) {
  7620. queuePostRenderEffect(() => {
  7621. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7622. shouldInvokeDirs &&
  7623. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  7624. }, parentSuspense);
  7625. }
  7626. };
  7627. const remove = vnode => {
  7628. const { type, el, anchor, transition } = vnode;
  7629. if (type === Fragment) {
  7630. if (vnode.patchFlag > 0 &&
  7631. vnode.patchFlag & 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */ &&
  7632. transition &&
  7633. !transition.persisted) {
  7634. vnode.children.forEach(child => {
  7635. if (child.type === Comment) {
  7636. hostRemove(child.el);
  7637. }
  7638. else {
  7639. remove(child);
  7640. }
  7641. });
  7642. }
  7643. else {
  7644. removeFragment(el, anchor);
  7645. }
  7646. return;
  7647. }
  7648. if (type === Static) {
  7649. removeStaticNode(vnode);
  7650. return;
  7651. }
  7652. const performRemove = () => {
  7653. hostRemove(el);
  7654. if (transition && !transition.persisted && transition.afterLeave) {
  7655. transition.afterLeave();
  7656. }
  7657. };
  7658. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ &&
  7659. transition &&
  7660. !transition.persisted) {
  7661. const { leave, delayLeave } = transition;
  7662. const performLeave = () => leave(el, performRemove);
  7663. if (delayLeave) {
  7664. delayLeave(vnode.el, performRemove, performLeave);
  7665. }
  7666. else {
  7667. performLeave();
  7668. }
  7669. }
  7670. else {
  7671. performRemove();
  7672. }
  7673. };
  7674. const removeFragment = (cur, end) => {
  7675. // For fragments, directly remove all contained DOM nodes.
  7676. // (fragment child nodes cannot have transition)
  7677. let next;
  7678. while (cur !== end) {
  7679. next = hostNextSibling(cur);
  7680. hostRemove(cur);
  7681. cur = next;
  7682. }
  7683. hostRemove(end);
  7684. };
  7685. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7686. if (instance.type.__hmrId) {
  7687. unregisterHMR(instance);
  7688. }
  7689. const { bum, scope, update, subTree, um } = instance;
  7690. // beforeUnmount hook
  7691. if (bum) {
  7692. invokeArrayFns(bum);
  7693. }
  7694. // stop effects in component scope
  7695. scope.stop();
  7696. // update may be null if a component is unmounted before its async
  7697. // setup has resolved.
  7698. if (update) {
  7699. // so that scheduler will no longer invoke it
  7700. update.active = false;
  7701. unmount(subTree, instance, parentSuspense, doRemove);
  7702. }
  7703. // unmounted hook
  7704. if (um) {
  7705. queuePostRenderEffect(um, parentSuspense);
  7706. }
  7707. queuePostRenderEffect(() => {
  7708. instance.isUnmounted = true;
  7709. }, parentSuspense);
  7710. // A component with async dep inside a pending suspense is unmounted before
  7711. // its async dep resolves. This should remove the dep from the suspense, and
  7712. // cause the suspense to resolve immediately if that was the last dep.
  7713. if (parentSuspense &&
  7714. parentSuspense.pendingBranch &&
  7715. !parentSuspense.isUnmounted &&
  7716. instance.asyncDep &&
  7717. !instance.asyncResolved &&
  7718. instance.suspenseId === parentSuspense.pendingId) {
  7719. parentSuspense.deps--;
  7720. if (parentSuspense.deps === 0) {
  7721. parentSuspense.resolve();
  7722. }
  7723. }
  7724. {
  7725. devtoolsComponentRemoved(instance);
  7726. }
  7727. };
  7728. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7729. for (let i = start; i < children.length; i++) {
  7730. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7731. }
  7732. };
  7733. const getNextHostNode = vnode => {
  7734. if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  7735. return getNextHostNode(vnode.component.subTree);
  7736. }
  7737. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  7738. return vnode.suspense.next();
  7739. }
  7740. return hostNextSibling((vnode.anchor || vnode.el));
  7741. };
  7742. const render = (vnode, container, isSVG) => {
  7743. if (vnode == null) {
  7744. if (container._vnode) {
  7745. unmount(container._vnode, null, null, true);
  7746. }
  7747. }
  7748. else {
  7749. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7750. }
  7751. flushPreFlushCbs();
  7752. flushPostFlushCbs();
  7753. container._vnode = vnode;
  7754. };
  7755. const internals = {
  7756. p: patch,
  7757. um: unmount,
  7758. m: move,
  7759. r: remove,
  7760. mt: mountComponent,
  7761. mc: mountChildren,
  7762. pc: patchChildren,
  7763. pbc: patchBlockChildren,
  7764. n: getNextHostNode,
  7765. o: options
  7766. };
  7767. let hydrate;
  7768. let hydrateNode;
  7769. if (createHydrationFns) {
  7770. [hydrate, hydrateNode] = createHydrationFns(internals);
  7771. }
  7772. return {
  7773. render,
  7774. hydrate,
  7775. createApp: createAppAPI(render, hydrate)
  7776. };
  7777. }
  7778. function toggleRecurse({ effect, update }, allowed) {
  7779. effect.allowRecurse = update.allowRecurse = allowed;
  7780. }
  7781. /**
  7782. * #1156
  7783. * When a component is HMR-enabled, we need to make sure that all static nodes
  7784. * inside a block also inherit the DOM element from the previous tree so that
  7785. * HMR updates (which are full updates) can retrieve the element for patching.
  7786. *
  7787. * #2080
  7788. * Inside keyed `template` fragment static children, if a fragment is moved,
  7789. * the children will always be moved. Therefore, in order to ensure correct move
  7790. * position, el should be inherited from previous nodes.
  7791. */
  7792. function traverseStaticChildren(n1, n2, shallow = false) {
  7793. const ch1 = n1.children;
  7794. const ch2 = n2.children;
  7795. if (isArray(ch1) && isArray(ch2)) {
  7796. for (let i = 0; i < ch1.length; i++) {
  7797. // this is only called in the optimized path so array children are
  7798. // guaranteed to be vnodes
  7799. const c1 = ch1[i];
  7800. let c2 = ch2[i];
  7801. if (c2.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && !c2.dynamicChildren) {
  7802. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) {
  7803. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7804. c2.el = c1.el;
  7805. }
  7806. if (!shallow)
  7807. traverseStaticChildren(c1, c2);
  7808. }
  7809. // #6852 also inherit for text nodes
  7810. if (c2.type === Text) {
  7811. c2.el = c1.el;
  7812. }
  7813. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7814. // would have received .el during block patch)
  7815. if (c2.type === Comment && !c2.el) {
  7816. c2.el = c1.el;
  7817. }
  7818. }
  7819. }
  7820. }
  7821. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7822. function getSequence(arr) {
  7823. const p = arr.slice();
  7824. const result = [0];
  7825. let i, j, u, v, c;
  7826. const len = arr.length;
  7827. for (i = 0; i < len; i++) {
  7828. const arrI = arr[i];
  7829. if (arrI !== 0) {
  7830. j = result[result.length - 1];
  7831. if (arr[j] < arrI) {
  7832. p[i] = j;
  7833. result.push(i);
  7834. continue;
  7835. }
  7836. u = 0;
  7837. v = result.length - 1;
  7838. while (u < v) {
  7839. c = (u + v) >> 1;
  7840. if (arr[result[c]] < arrI) {
  7841. u = c + 1;
  7842. }
  7843. else {
  7844. v = c;
  7845. }
  7846. }
  7847. if (arrI < arr[result[u]]) {
  7848. if (u > 0) {
  7849. p[i] = result[u - 1];
  7850. }
  7851. result[u] = i;
  7852. }
  7853. }
  7854. }
  7855. u = result.length;
  7856. v = result[u - 1];
  7857. while (u-- > 0) {
  7858. result[u] = v;
  7859. v = p[v];
  7860. }
  7861. return result;
  7862. }
  7863. const isTeleport = (type) => type.__isTeleport;
  7864. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7865. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7866. const resolveTarget = (props, select) => {
  7867. const targetSelector = props && props.to;
  7868. if (isString(targetSelector)) {
  7869. if (!select) {
  7870. warn(`Current renderer does not support string target for Teleports. ` +
  7871. `(missing querySelector renderer option)`);
  7872. return null;
  7873. }
  7874. else {
  7875. const target = select(targetSelector);
  7876. if (!target) {
  7877. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7878. `Note the target element must exist before the component is mounted - ` +
  7879. `i.e. the target cannot be rendered by the component itself, and ` +
  7880. `ideally should be outside of the entire Vue component tree.`);
  7881. }
  7882. return target;
  7883. }
  7884. }
  7885. else {
  7886. if (!targetSelector && !isTeleportDisabled(props)) {
  7887. warn(`Invalid Teleport target: ${targetSelector}`);
  7888. }
  7889. return targetSelector;
  7890. }
  7891. };
  7892. const TeleportImpl = {
  7893. __isTeleport: true,
  7894. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7895. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7896. const disabled = isTeleportDisabled(n2.props);
  7897. let { shapeFlag, children, dynamicChildren } = n2;
  7898. // #3302
  7899. // HMR updated, force full diff
  7900. if (isHmrUpdating) {
  7901. optimized = false;
  7902. dynamicChildren = null;
  7903. }
  7904. if (n1 == null) {
  7905. // insert anchors in the main view
  7906. const placeholder = (n2.el = createComment('teleport start')
  7907. );
  7908. const mainAnchor = (n2.anchor = createComment('teleport end')
  7909. );
  7910. insert(placeholder, container, anchor);
  7911. insert(mainAnchor, container, anchor);
  7912. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7913. const targetAnchor = (n2.targetAnchor = createText(''));
  7914. if (target) {
  7915. insert(targetAnchor, target);
  7916. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7917. isSVG = isSVG || isTargetSVG(target);
  7918. }
  7919. else if (!disabled) {
  7920. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7921. }
  7922. const mount = (container, anchor) => {
  7923. // Teleport *always* has Array children. This is enforced in both the
  7924. // compiler and vnode children normalization.
  7925. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7926. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7927. }
  7928. };
  7929. if (disabled) {
  7930. mount(container, mainAnchor);
  7931. }
  7932. else if (target) {
  7933. mount(target, targetAnchor);
  7934. }
  7935. }
  7936. else {
  7937. // update content
  7938. n2.el = n1.el;
  7939. const mainAnchor = (n2.anchor = n1.anchor);
  7940. const target = (n2.target = n1.target);
  7941. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7942. const wasDisabled = isTeleportDisabled(n1.props);
  7943. const currentContainer = wasDisabled ? container : target;
  7944. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7945. isSVG = isSVG || isTargetSVG(target);
  7946. if (dynamicChildren) {
  7947. // fast path when the teleport happens to be a block root
  7948. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7949. // even in block tree mode we need to make sure all root-level nodes
  7950. // in the teleport inherit previous DOM references so that they can
  7951. // be moved in future patches.
  7952. traverseStaticChildren(n1, n2, true);
  7953. }
  7954. else if (!optimized) {
  7955. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7956. }
  7957. if (disabled) {
  7958. if (!wasDisabled) {
  7959. // enabled -> disabled
  7960. // move into main container
  7961. moveTeleport(n2, container, mainAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7962. }
  7963. }
  7964. else {
  7965. // target changed
  7966. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7967. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7968. if (nextTarget) {
  7969. moveTeleport(n2, nextTarget, null, internals, 0 /* TeleportMoveTypes.TARGET_CHANGE */);
  7970. }
  7971. else {
  7972. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  7973. }
  7974. }
  7975. else if (wasDisabled) {
  7976. // disabled -> enabled
  7977. // move into teleport target
  7978. moveTeleport(n2, target, targetAnchor, internals, 1 /* TeleportMoveTypes.TOGGLE */);
  7979. }
  7980. }
  7981. }
  7982. updateCssVars(n2);
  7983. },
  7984. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7985. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7986. if (target) {
  7987. hostRemove(targetAnchor);
  7988. }
  7989. // an unmounted teleport should always remove its children if not disabled
  7990. if (doRemove || !isTeleportDisabled(props)) {
  7991. hostRemove(anchor);
  7992. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  7993. for (let i = 0; i < children.length; i++) {
  7994. const child = children[i];
  7995. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7996. }
  7997. }
  7998. }
  7999. },
  8000. move: moveTeleport,
  8001. hydrate: hydrateTeleport
  8002. };
  8003. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* TeleportMoveTypes.REORDER */) {
  8004. // move target anchor if this is a target change.
  8005. if (moveType === 0 /* TeleportMoveTypes.TARGET_CHANGE */) {
  8006. insert(vnode.targetAnchor, container, parentAnchor);
  8007. }
  8008. const { el, anchor, shapeFlag, children, props } = vnode;
  8009. const isReorder = moveType === 2 /* TeleportMoveTypes.REORDER */;
  8010. // move main view anchor if this is a re-order.
  8011. if (isReorder) {
  8012. insert(el, container, parentAnchor);
  8013. }
  8014. // if this is a re-order and teleport is enabled (content is in target)
  8015. // do not move children. So the opposite is: only move children if this
  8016. // is not a reorder, or the teleport is disabled
  8017. if (!isReorder || isTeleportDisabled(props)) {
  8018. // Teleport has either Array children or no children.
  8019. if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  8020. for (let i = 0; i < children.length; i++) {
  8021. move(children[i], container, parentAnchor, 2 /* MoveType.REORDER */);
  8022. }
  8023. }
  8024. }
  8025. // move main view anchor if this is a re-order.
  8026. if (isReorder) {
  8027. insert(anchor, container, parentAnchor);
  8028. }
  8029. }
  8030. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  8031. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  8032. if (target) {
  8033. // if multiple teleports rendered to the same target element, we need to
  8034. // pick up from where the last teleport finished instead of the first node
  8035. const targetNode = target._lpa || target.firstChild;
  8036. if (vnode.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  8037. if (isTeleportDisabled(vnode.props)) {
  8038. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  8039. vnode.targetAnchor = targetNode;
  8040. }
  8041. else {
  8042. vnode.anchor = nextSibling(node);
  8043. // lookahead until we find the target anchor
  8044. // we cannot rely on return value of hydrateChildren() because there
  8045. // could be nested teleports
  8046. let targetAnchor = targetNode;
  8047. while (targetAnchor) {
  8048. targetAnchor = nextSibling(targetAnchor);
  8049. if (targetAnchor &&
  8050. targetAnchor.nodeType === 8 &&
  8051. targetAnchor.data === 'teleport anchor') {
  8052. vnode.targetAnchor = targetAnchor;
  8053. target._lpa =
  8054. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  8055. break;
  8056. }
  8057. }
  8058. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  8059. }
  8060. }
  8061. updateCssVars(vnode);
  8062. }
  8063. return vnode.anchor && nextSibling(vnode.anchor);
  8064. }
  8065. // Force-casted public typing for h and TSX props inference
  8066. const Teleport = TeleportImpl;
  8067. function updateCssVars(vnode) {
  8068. // presence of .ut method indicates owner component uses css vars.
  8069. // code path here can assume browser environment.
  8070. const ctx = vnode.ctx;
  8071. if (ctx && ctx.ut) {
  8072. let node = vnode.children[0].el;
  8073. while (node !== vnode.targetAnchor) {
  8074. if (node.nodeType === 1)
  8075. node.setAttribute('data-v-owner', ctx.uid);
  8076. node = node.nextSibling;
  8077. }
  8078. ctx.ut();
  8079. }
  8080. }
  8081. const Fragment = Symbol('Fragment' );
  8082. const Text = Symbol('Text' );
  8083. const Comment = Symbol('Comment' );
  8084. const Static = Symbol('Static' );
  8085. // Since v-if and v-for are the two possible ways node structure can dynamically
  8086. // change, once we consider v-if branches and each v-for fragment a block, we
  8087. // can divide a template into nested blocks, and within each block the node
  8088. // structure would be stable. This allows us to skip most children diffing
  8089. // and only worry about the dynamic nodes (indicated by patch flags).
  8090. const blockStack = [];
  8091. let currentBlock = null;
  8092. /**
  8093. * Open a block.
  8094. * This must be called before `createBlock`. It cannot be part of `createBlock`
  8095. * because the children of the block are evaluated before `createBlock` itself
  8096. * is called. The generated code typically looks like this:
  8097. *
  8098. * ```js
  8099. * function render() {
  8100. * return (openBlock(),createBlock('div', null, [...]))
  8101. * }
  8102. * ```
  8103. * disableTracking is true when creating a v-for fragment block, since a v-for
  8104. * fragment always diffs its children.
  8105. *
  8106. * @private
  8107. */
  8108. function openBlock(disableTracking = false) {
  8109. blockStack.push((currentBlock = disableTracking ? null : []));
  8110. }
  8111. function closeBlock() {
  8112. blockStack.pop();
  8113. currentBlock = blockStack[blockStack.length - 1] || null;
  8114. }
  8115. // Whether we should be tracking dynamic child nodes inside a block.
  8116. // Only tracks when this value is > 0
  8117. // We are not using a simple boolean because this value may need to be
  8118. // incremented/decremented by nested usage of v-once (see below)
  8119. let isBlockTreeEnabled = 1;
  8120. /**
  8121. * Block tracking sometimes needs to be disabled, for example during the
  8122. * creation of a tree that needs to be cached by v-once. The compiler generates
  8123. * code like this:
  8124. *
  8125. * ``` js
  8126. * _cache[1] || (
  8127. * setBlockTracking(-1),
  8128. * _cache[1] = createVNode(...),
  8129. * setBlockTracking(1),
  8130. * _cache[1]
  8131. * )
  8132. * ```
  8133. *
  8134. * @private
  8135. */
  8136. function setBlockTracking(value) {
  8137. isBlockTreeEnabled += value;
  8138. }
  8139. function setupBlock(vnode) {
  8140. // save current block children on the block vnode
  8141. vnode.dynamicChildren =
  8142. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  8143. // close block
  8144. closeBlock();
  8145. // a block is always going to be patched, so track it as a child of its
  8146. // parent block
  8147. if (isBlockTreeEnabled > 0 && currentBlock) {
  8148. currentBlock.push(vnode);
  8149. }
  8150. return vnode;
  8151. }
  8152. /**
  8153. * @private
  8154. */
  8155. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  8156. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  8157. }
  8158. /**
  8159. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  8160. * A block root keeps track of dynamic nodes within the block in the
  8161. * `dynamicChildren` array.
  8162. *
  8163. * @private
  8164. */
  8165. function createBlock(type, props, children, patchFlag, dynamicProps) {
  8166. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  8167. }
  8168. function isVNode(value) {
  8169. return value ? value.__v_isVNode === true : false;
  8170. }
  8171. function isSameVNodeType(n1, n2) {
  8172. if (n2.shapeFlag & 6 /* ShapeFlags.COMPONENT */ &&
  8173. hmrDirtyComponents.has(n2.type)) {
  8174. // #7042, ensure the vnode being unmounted during HMR
  8175. // bitwise operations to remove keep alive flags
  8176. n1.shapeFlag &= ~256 /* ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE */;
  8177. n2.shapeFlag &= ~512 /* ShapeFlags.COMPONENT_KEPT_ALIVE */;
  8178. // HMR only: if the component has been hot-updated, force a reload.
  8179. return false;
  8180. }
  8181. return n1.type === n2.type && n1.key === n2.key;
  8182. }
  8183. let vnodeArgsTransformer;
  8184. /**
  8185. * Internal API for registering an arguments transform for createVNode
  8186. * used for creating stubs in the test-utils
  8187. * It is *internal* but needs to be exposed for test-utils to pick up proper
  8188. * typings
  8189. */
  8190. function transformVNodeArgs(transformer) {
  8191. vnodeArgsTransformer = transformer;
  8192. }
  8193. const createVNodeWithArgsTransform = (...args) => {
  8194. return _createVNode(...(vnodeArgsTransformer
  8195. ? vnodeArgsTransformer(args, currentRenderingInstance)
  8196. : args));
  8197. };
  8198. const InternalObjectKey = `__vInternal`;
  8199. const normalizeKey = ({ key }) => key != null ? key : null;
  8200. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  8201. return (ref != null
  8202. ? isString(ref) || isRef(ref) || isFunction(ref)
  8203. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  8204. : ref
  8205. : null);
  8206. };
  8207. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ShapeFlags.ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  8208. const vnode = {
  8209. __v_isVNode: true,
  8210. __v_skip: true,
  8211. type,
  8212. props,
  8213. key: props && normalizeKey(props),
  8214. ref: props && normalizeRef(props),
  8215. scopeId: currentScopeId,
  8216. slotScopeIds: null,
  8217. children,
  8218. component: null,
  8219. suspense: null,
  8220. ssContent: null,
  8221. ssFallback: null,
  8222. dirs: null,
  8223. transition: null,
  8224. el: null,
  8225. anchor: null,
  8226. target: null,
  8227. targetAnchor: null,
  8228. staticCount: 0,
  8229. shapeFlag,
  8230. patchFlag,
  8231. dynamicProps,
  8232. dynamicChildren: null,
  8233. appContext: null,
  8234. ctx: currentRenderingInstance
  8235. };
  8236. if (needFullChildrenNormalization) {
  8237. normalizeChildren(vnode, children);
  8238. // normalize suspense children
  8239. if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  8240. type.normalize(vnode);
  8241. }
  8242. }
  8243. else if (children) {
  8244. // compiled element vnode - if children is passed, only possible types are
  8245. // string or Array.
  8246. vnode.shapeFlag |= isString(children)
  8247. ? 8 /* ShapeFlags.TEXT_CHILDREN */
  8248. : 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8249. }
  8250. // validate key
  8251. if (vnode.key !== vnode.key) {
  8252. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  8253. }
  8254. // track vnode for block tree
  8255. if (isBlockTreeEnabled > 0 &&
  8256. // avoid a block node from tracking itself
  8257. !isBlockNode &&
  8258. // has current parent block
  8259. currentBlock &&
  8260. // presence of a patch flag indicates this node needs patching on updates.
  8261. // component nodes also should always be patched, because even if the
  8262. // component doesn't need to update, it needs to persist the instance on to
  8263. // the next vnode so that it can be properly unmounted later.
  8264. (vnode.patchFlag > 0 || shapeFlag & 6 /* ShapeFlags.COMPONENT */) &&
  8265. // the EVENTS flag is only for hydration and if it is the only flag, the
  8266. // vnode should not be considered dynamic due to handler caching.
  8267. vnode.patchFlag !== 32 /* PatchFlags.HYDRATE_EVENTS */) {
  8268. currentBlock.push(vnode);
  8269. }
  8270. return vnode;
  8271. }
  8272. const createVNode = (createVNodeWithArgsTransform );
  8273. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  8274. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  8275. if (!type) {
  8276. warn(`Invalid vnode type when creating vnode: ${type}.`);
  8277. }
  8278. type = Comment;
  8279. }
  8280. if (isVNode(type)) {
  8281. // createVNode receiving an existing vnode. This happens in cases like
  8282. // <component :is="vnode"/>
  8283. // #2078 make sure to merge refs during the clone instead of overwriting it
  8284. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  8285. if (children) {
  8286. normalizeChildren(cloned, children);
  8287. }
  8288. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  8289. if (cloned.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  8290. currentBlock[currentBlock.indexOf(type)] = cloned;
  8291. }
  8292. else {
  8293. currentBlock.push(cloned);
  8294. }
  8295. }
  8296. cloned.patchFlag |= -2 /* PatchFlags.BAIL */;
  8297. return cloned;
  8298. }
  8299. // class component normalization.
  8300. if (isClassComponent(type)) {
  8301. type = type.__vccOpts;
  8302. }
  8303. // class & style normalization.
  8304. if (props) {
  8305. // for reactive or proxy objects, we need to clone it to enable mutation.
  8306. props = guardReactiveProps(props);
  8307. let { class: klass, style } = props;
  8308. if (klass && !isString(klass)) {
  8309. props.class = normalizeClass(klass);
  8310. }
  8311. if (isObject(style)) {
  8312. // reactive state objects need to be cloned since they are likely to be
  8313. // mutated
  8314. if (isProxy(style) && !isArray(style)) {
  8315. style = extend({}, style);
  8316. }
  8317. props.style = normalizeStyle(style);
  8318. }
  8319. }
  8320. // encode the vnode type information into a bitmap
  8321. const shapeFlag = isString(type)
  8322. ? 1 /* ShapeFlags.ELEMENT */
  8323. : isSuspense(type)
  8324. ? 128 /* ShapeFlags.SUSPENSE */
  8325. : isTeleport(type)
  8326. ? 64 /* ShapeFlags.TELEPORT */
  8327. : isObject(type)
  8328. ? 4 /* ShapeFlags.STATEFUL_COMPONENT */
  8329. : isFunction(type)
  8330. ? 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */
  8331. : 0;
  8332. if (shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ && isProxy(type)) {
  8333. type = toRaw(type);
  8334. warn(`Vue received a Component which was made a reactive object. This can ` +
  8335. `lead to unnecessary performance overhead, and should be avoided by ` +
  8336. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  8337. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  8338. }
  8339. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  8340. }
  8341. function guardReactiveProps(props) {
  8342. if (!props)
  8343. return null;
  8344. return isProxy(props) || InternalObjectKey in props
  8345. ? extend({}, props)
  8346. : props;
  8347. }
  8348. function cloneVNode(vnode, extraProps, mergeRef = false) {
  8349. // This is intentionally NOT using spread or extend to avoid the runtime
  8350. // key enumeration cost.
  8351. const { props, ref, patchFlag, children } = vnode;
  8352. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  8353. const cloned = {
  8354. __v_isVNode: true,
  8355. __v_skip: true,
  8356. type: vnode.type,
  8357. props: mergedProps,
  8358. key: mergedProps && normalizeKey(mergedProps),
  8359. ref: extraProps && extraProps.ref
  8360. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  8361. // if the vnode itself already has a ref, cloneVNode will need to merge
  8362. // the refs so the single vnode can be set on multiple refs
  8363. mergeRef && ref
  8364. ? isArray(ref)
  8365. ? ref.concat(normalizeRef(extraProps))
  8366. : [ref, normalizeRef(extraProps)]
  8367. : normalizeRef(extraProps)
  8368. : ref,
  8369. scopeId: vnode.scopeId,
  8370. slotScopeIds: vnode.slotScopeIds,
  8371. children: patchFlag === -1 /* PatchFlags.HOISTED */ && isArray(children)
  8372. ? children.map(deepCloneVNode)
  8373. : children,
  8374. target: vnode.target,
  8375. targetAnchor: vnode.targetAnchor,
  8376. staticCount: vnode.staticCount,
  8377. shapeFlag: vnode.shapeFlag,
  8378. // if the vnode is cloned with extra props, we can no longer assume its
  8379. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  8380. // note: preserve flag for fragments since they use the flag for children
  8381. // fast paths only.
  8382. patchFlag: extraProps && vnode.type !== Fragment
  8383. ? patchFlag === -1 // hoisted node
  8384. ? 16 /* PatchFlags.FULL_PROPS */
  8385. : patchFlag | 16 /* PatchFlags.FULL_PROPS */
  8386. : patchFlag,
  8387. dynamicProps: vnode.dynamicProps,
  8388. dynamicChildren: vnode.dynamicChildren,
  8389. appContext: vnode.appContext,
  8390. dirs: vnode.dirs,
  8391. transition: vnode.transition,
  8392. // These should technically only be non-null on mounted VNodes. However,
  8393. // they *should* be copied for kept-alive vnodes. So we just always copy
  8394. // them since them being non-null during a mount doesn't affect the logic as
  8395. // they will simply be overwritten.
  8396. component: vnode.component,
  8397. suspense: vnode.suspense,
  8398. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  8399. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  8400. el: vnode.el,
  8401. anchor: vnode.anchor,
  8402. ctx: vnode.ctx,
  8403. ce: vnode.ce
  8404. };
  8405. return cloned;
  8406. }
  8407. /**
  8408. * Dev only, for HMR of hoisted vnodes reused in v-for
  8409. * https://github.com/vitejs/vite/issues/2022
  8410. */
  8411. function deepCloneVNode(vnode) {
  8412. const cloned = cloneVNode(vnode);
  8413. if (isArray(vnode.children)) {
  8414. cloned.children = vnode.children.map(deepCloneVNode);
  8415. }
  8416. return cloned;
  8417. }
  8418. /**
  8419. * @private
  8420. */
  8421. function createTextVNode(text = ' ', flag = 0) {
  8422. return createVNode(Text, null, text, flag);
  8423. }
  8424. /**
  8425. * @private
  8426. */
  8427. function createStaticVNode(content, numberOfNodes) {
  8428. // A static vnode can contain multiple stringified elements, and the number
  8429. // of elements is necessary for hydration.
  8430. const vnode = createVNode(Static, null, content);
  8431. vnode.staticCount = numberOfNodes;
  8432. return vnode;
  8433. }
  8434. /**
  8435. * @private
  8436. */
  8437. function createCommentVNode(text = '',
  8438. // when used as the v-else branch, the comment node must be created as a
  8439. // block to ensure correct updates.
  8440. asBlock = false) {
  8441. return asBlock
  8442. ? (openBlock(), createBlock(Comment, null, text))
  8443. : createVNode(Comment, null, text);
  8444. }
  8445. function normalizeVNode(child) {
  8446. if (child == null || typeof child === 'boolean') {
  8447. // empty placeholder
  8448. return createVNode(Comment);
  8449. }
  8450. else if (isArray(child)) {
  8451. // fragment
  8452. return createVNode(Fragment, null,
  8453. // #3666, avoid reference pollution when reusing vnode
  8454. child.slice());
  8455. }
  8456. else if (typeof child === 'object') {
  8457. // already vnode, this should be the most common since compiled templates
  8458. // always produce all-vnode children arrays
  8459. return cloneIfMounted(child);
  8460. }
  8461. else {
  8462. // strings and numbers
  8463. return createVNode(Text, null, String(child));
  8464. }
  8465. }
  8466. // optimized normalization for template-compiled render fns
  8467. function cloneIfMounted(child) {
  8468. return (child.el === null && child.patchFlag !== -1 /* PatchFlags.HOISTED */) ||
  8469. child.memo
  8470. ? child
  8471. : cloneVNode(child);
  8472. }
  8473. function normalizeChildren(vnode, children) {
  8474. let type = 0;
  8475. const { shapeFlag } = vnode;
  8476. if (children == null) {
  8477. children = null;
  8478. }
  8479. else if (isArray(children)) {
  8480. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8481. }
  8482. else if (typeof children === 'object') {
  8483. if (shapeFlag & (1 /* ShapeFlags.ELEMENT */ | 64 /* ShapeFlags.TELEPORT */)) {
  8484. // Normalize slot to plain children for plain element and Teleport
  8485. const slot = children.default;
  8486. if (slot) {
  8487. // _c marker is added by withCtx() indicating this is a compiled slot
  8488. slot._c && (slot._d = false);
  8489. normalizeChildren(vnode, slot());
  8490. slot._c && (slot._d = true);
  8491. }
  8492. return;
  8493. }
  8494. else {
  8495. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8496. const slotFlag = children._;
  8497. if (!slotFlag && !(InternalObjectKey in children)) {
  8498. children._ctx = currentRenderingInstance;
  8499. }
  8500. else if (slotFlag === 3 /* SlotFlags.FORWARDED */ && currentRenderingInstance) {
  8501. // a child component receives forwarded slots from the parent.
  8502. // its slot type is determined by its parent's slot type.
  8503. if (currentRenderingInstance.slots._ === 1 /* SlotFlags.STABLE */) {
  8504. children._ = 1 /* SlotFlags.STABLE */;
  8505. }
  8506. else {
  8507. children._ = 2 /* SlotFlags.DYNAMIC */;
  8508. vnode.patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  8509. }
  8510. }
  8511. }
  8512. }
  8513. else if (isFunction(children)) {
  8514. children = { default: children, _ctx: currentRenderingInstance };
  8515. type = 32 /* ShapeFlags.SLOTS_CHILDREN */;
  8516. }
  8517. else {
  8518. children = String(children);
  8519. // force teleport children to array so it can be moved around
  8520. if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
  8521. type = 16 /* ShapeFlags.ARRAY_CHILDREN */;
  8522. children = [createTextVNode(children)];
  8523. }
  8524. else {
  8525. type = 8 /* ShapeFlags.TEXT_CHILDREN */;
  8526. }
  8527. }
  8528. vnode.children = children;
  8529. vnode.shapeFlag |= type;
  8530. }
  8531. function mergeProps(...args) {
  8532. const ret = {};
  8533. for (let i = 0; i < args.length; i++) {
  8534. const toMerge = args[i];
  8535. for (const key in toMerge) {
  8536. if (key === 'class') {
  8537. if (ret.class !== toMerge.class) {
  8538. ret.class = normalizeClass([ret.class, toMerge.class]);
  8539. }
  8540. }
  8541. else if (key === 'style') {
  8542. ret.style = normalizeStyle([ret.style, toMerge.style]);
  8543. }
  8544. else if (isOn(key)) {
  8545. const existing = ret[key];
  8546. const incoming = toMerge[key];
  8547. if (incoming &&
  8548. existing !== incoming &&
  8549. !(isArray(existing) && existing.includes(incoming))) {
  8550. ret[key] = existing
  8551. ? [].concat(existing, incoming)
  8552. : incoming;
  8553. }
  8554. }
  8555. else if (key !== '') {
  8556. ret[key] = toMerge[key];
  8557. }
  8558. }
  8559. }
  8560. return ret;
  8561. }
  8562. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  8563. callWithAsyncErrorHandling(hook, instance, 7 /* ErrorCodes.VNODE_HOOK */, [
  8564. vnode,
  8565. prevVNode
  8566. ]);
  8567. }
  8568. const emptyAppContext = createAppContext();
  8569. let uid = 0;
  8570. function createComponentInstance(vnode, parent, suspense) {
  8571. const type = vnode.type;
  8572. // inherit parent app context - or - if root, adopt from root vnode
  8573. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8574. const instance = {
  8575. uid: uid++,
  8576. vnode,
  8577. type,
  8578. parent,
  8579. appContext,
  8580. root: null,
  8581. next: null,
  8582. subTree: null,
  8583. effect: null,
  8584. update: null,
  8585. scope: new EffectScope(true /* detached */),
  8586. render: null,
  8587. proxy: null,
  8588. exposed: null,
  8589. exposeProxy: null,
  8590. withProxy: null,
  8591. provides: parent ? parent.provides : Object.create(appContext.provides),
  8592. accessCache: null,
  8593. renderCache: [],
  8594. // local resolved assets
  8595. components: null,
  8596. directives: null,
  8597. // resolved props and emits options
  8598. propsOptions: normalizePropsOptions(type, appContext),
  8599. emitsOptions: normalizeEmitsOptions(type, appContext),
  8600. // emit
  8601. emit: null,
  8602. emitted: null,
  8603. // props default value
  8604. propsDefaults: EMPTY_OBJ,
  8605. // inheritAttrs
  8606. inheritAttrs: type.inheritAttrs,
  8607. // state
  8608. ctx: EMPTY_OBJ,
  8609. data: EMPTY_OBJ,
  8610. props: EMPTY_OBJ,
  8611. attrs: EMPTY_OBJ,
  8612. slots: EMPTY_OBJ,
  8613. refs: EMPTY_OBJ,
  8614. setupState: EMPTY_OBJ,
  8615. setupContext: null,
  8616. // suspense related
  8617. suspense,
  8618. suspenseId: suspense ? suspense.pendingId : 0,
  8619. asyncDep: null,
  8620. asyncResolved: false,
  8621. // lifecycle hooks
  8622. // not using enums here because it results in computed properties
  8623. isMounted: false,
  8624. isUnmounted: false,
  8625. isDeactivated: false,
  8626. bc: null,
  8627. c: null,
  8628. bm: null,
  8629. m: null,
  8630. bu: null,
  8631. u: null,
  8632. um: null,
  8633. bum: null,
  8634. da: null,
  8635. a: null,
  8636. rtg: null,
  8637. rtc: null,
  8638. ec: null,
  8639. sp: null
  8640. };
  8641. {
  8642. instance.ctx = createDevRenderContext(instance);
  8643. }
  8644. instance.root = parent ? parent.root : instance;
  8645. instance.emit = emit.bind(null, instance);
  8646. // apply custom element special handling
  8647. if (vnode.ce) {
  8648. vnode.ce(instance);
  8649. }
  8650. return instance;
  8651. }
  8652. let currentInstance = null;
  8653. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8654. const setCurrentInstance = (instance) => {
  8655. currentInstance = instance;
  8656. instance.scope.on();
  8657. };
  8658. const unsetCurrentInstance = () => {
  8659. currentInstance && currentInstance.scope.off();
  8660. currentInstance = null;
  8661. };
  8662. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8663. function validateComponentName(name, config) {
  8664. const appIsNativeTag = config.isNativeTag || NO;
  8665. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8666. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  8667. }
  8668. }
  8669. function isStatefulComponent(instance) {
  8670. return instance.vnode.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */;
  8671. }
  8672. let isInSSRComponentSetup = false;
  8673. function setupComponent(instance, isSSR = false) {
  8674. isInSSRComponentSetup = isSSR;
  8675. const { props, children } = instance.vnode;
  8676. const isStateful = isStatefulComponent(instance);
  8677. initProps(instance, props, isStateful, isSSR);
  8678. initSlots(instance, children);
  8679. const setupResult = isStateful
  8680. ? setupStatefulComponent(instance, isSSR)
  8681. : undefined;
  8682. isInSSRComponentSetup = false;
  8683. return setupResult;
  8684. }
  8685. function setupStatefulComponent(instance, isSSR) {
  8686. var _a;
  8687. const Component = instance.type;
  8688. {
  8689. if (Component.name) {
  8690. validateComponentName(Component.name, instance.appContext.config);
  8691. }
  8692. if (Component.components) {
  8693. const names = Object.keys(Component.components);
  8694. for (let i = 0; i < names.length; i++) {
  8695. validateComponentName(names[i], instance.appContext.config);
  8696. }
  8697. }
  8698. if (Component.directives) {
  8699. const names = Object.keys(Component.directives);
  8700. for (let i = 0; i < names.length; i++) {
  8701. validateDirectiveName(names[i]);
  8702. }
  8703. }
  8704. if (Component.compilerOptions && isRuntimeOnly()) {
  8705. warn(`"compilerOptions" is only supported when using a build of Vue that ` +
  8706. `includes the runtime compiler. Since you are using a runtime-only ` +
  8707. `build, the options should be passed via your build tool config instead.`);
  8708. }
  8709. }
  8710. // 0. create render proxy property access cache
  8711. instance.accessCache = Object.create(null);
  8712. // 1. create public instance / render proxy
  8713. // also mark it raw so it's never observed
  8714. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8715. {
  8716. exposePropsOnRenderContext(instance);
  8717. }
  8718. // 2. call setup()
  8719. const { setup } = Component;
  8720. if (setup) {
  8721. const setupContext = (instance.setupContext =
  8722. setup.length > 1 ? createSetupContext(instance) : null);
  8723. setCurrentInstance(instance);
  8724. pauseTracking();
  8725. const setupResult = callWithErrorHandling(setup, instance, 0 /* ErrorCodes.SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8726. resetTracking();
  8727. unsetCurrentInstance();
  8728. if (isPromise(setupResult)) {
  8729. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8730. if (isSSR) {
  8731. // return the promise so server-renderer can wait on it
  8732. return setupResult
  8733. .then((resolvedResult) => {
  8734. handleSetupResult(instance, resolvedResult, isSSR);
  8735. })
  8736. .catch(e => {
  8737. handleError(e, instance, 0 /* ErrorCodes.SETUP_FUNCTION */);
  8738. });
  8739. }
  8740. else {
  8741. // async setup returned Promise.
  8742. // bail here and wait for re-entry.
  8743. instance.asyncDep = setupResult;
  8744. if (!instance.suspense) {
  8745. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8746. warn(`Component <${name}>: setup function returned a promise, but no ` +
  8747. `<Suspense> boundary was found in the parent component tree. ` +
  8748. `A component with async setup() must be nested in a <Suspense> ` +
  8749. `in order to be rendered.`);
  8750. }
  8751. }
  8752. }
  8753. else {
  8754. handleSetupResult(instance, setupResult, isSSR);
  8755. }
  8756. }
  8757. else {
  8758. finishComponentSetup(instance, isSSR);
  8759. }
  8760. }
  8761. function handleSetupResult(instance, setupResult, isSSR) {
  8762. if (isFunction(setupResult)) {
  8763. // setup returned an inline render function
  8764. {
  8765. instance.render = setupResult;
  8766. }
  8767. }
  8768. else if (isObject(setupResult)) {
  8769. if (isVNode(setupResult)) {
  8770. warn(`setup() should not return VNodes directly - ` +
  8771. `return a render function instead.`);
  8772. }
  8773. // setup returned bindings.
  8774. // assuming a render function compiled from template is present.
  8775. {
  8776. instance.devtoolsRawSetupState = setupResult;
  8777. }
  8778. instance.setupState = proxyRefs(setupResult);
  8779. {
  8780. exposeSetupStateOnRenderContext(instance);
  8781. }
  8782. }
  8783. else if (setupResult !== undefined) {
  8784. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8785. }
  8786. finishComponentSetup(instance, isSSR);
  8787. }
  8788. let compile$1;
  8789. let installWithProxy;
  8790. /**
  8791. * For runtime-dom to register the compiler.
  8792. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8793. */
  8794. function registerRuntimeCompiler(_compile) {
  8795. compile$1 = _compile;
  8796. installWithProxy = i => {
  8797. if (i.render._rc) {
  8798. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8799. }
  8800. };
  8801. }
  8802. // dev only
  8803. const isRuntimeOnly = () => !compile$1;
  8804. function finishComponentSetup(instance, isSSR, skipOptions) {
  8805. const Component = instance.type;
  8806. // template / render function normalization
  8807. // could be already set when returned from setup()
  8808. if (!instance.render) {
  8809. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8810. // is done by server-renderer
  8811. if (!isSSR && compile$1 && !Component.render) {
  8812. const template = Component.template ||
  8813. resolveMergedOptions(instance).template;
  8814. if (template) {
  8815. {
  8816. startMeasure(instance, `compile`);
  8817. }
  8818. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8819. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8820. const finalCompilerOptions = extend(extend({
  8821. isCustomElement,
  8822. delimiters
  8823. }, compilerOptions), componentCompilerOptions);
  8824. Component.render = compile$1(template, finalCompilerOptions);
  8825. {
  8826. endMeasure(instance, `compile`);
  8827. }
  8828. }
  8829. }
  8830. instance.render = (Component.render || NOOP);
  8831. // for runtime-compiled render functions using `with` blocks, the render
  8832. // proxy used needs a different `has` handler which is more performant and
  8833. // also only allows a whitelist of globals to fallthrough.
  8834. if (installWithProxy) {
  8835. installWithProxy(instance);
  8836. }
  8837. }
  8838. // support for 2.x options
  8839. {
  8840. setCurrentInstance(instance);
  8841. pauseTracking();
  8842. applyOptions(instance);
  8843. resetTracking();
  8844. unsetCurrentInstance();
  8845. }
  8846. // warn missing template/render
  8847. // the runtime compilation of template in SSR is done by server-render
  8848. if (!Component.render && instance.render === NOOP && !isSSR) {
  8849. /* istanbul ignore if */
  8850. if (!compile$1 && Component.template) {
  8851. warn(`Component provided template option but ` +
  8852. `runtime compilation is not supported in this build of Vue.` +
  8853. (` Use "vue.global.js" instead.`
  8854. ) /* should not happen */);
  8855. }
  8856. else {
  8857. warn(`Component is missing template or render function.`);
  8858. }
  8859. }
  8860. }
  8861. function createAttrsProxy(instance) {
  8862. return new Proxy(instance.attrs, {
  8863. get(target, key) {
  8864. markAttrsAccessed();
  8865. track(instance, "get" /* TrackOpTypes.GET */, '$attrs');
  8866. return target[key];
  8867. },
  8868. set() {
  8869. warn(`setupContext.attrs is readonly.`);
  8870. return false;
  8871. },
  8872. deleteProperty() {
  8873. warn(`setupContext.attrs is readonly.`);
  8874. return false;
  8875. }
  8876. }
  8877. );
  8878. }
  8879. function createSetupContext(instance) {
  8880. const expose = exposed => {
  8881. {
  8882. if (instance.exposed) {
  8883. warn(`expose() should be called only once per setup().`);
  8884. }
  8885. if (exposed != null) {
  8886. let exposedType = typeof exposed;
  8887. if (exposedType === 'object') {
  8888. if (isArray(exposed)) {
  8889. exposedType = 'array';
  8890. }
  8891. else if (isRef(exposed)) {
  8892. exposedType = 'ref';
  8893. }
  8894. }
  8895. if (exposedType !== 'object') {
  8896. warn(`expose() should be passed a plain object, received ${exposedType}.`);
  8897. }
  8898. }
  8899. }
  8900. instance.exposed = exposed || {};
  8901. };
  8902. let attrs;
  8903. {
  8904. // We use getters in dev in case libs like test-utils overwrite instance
  8905. // properties (overwrites should not be done in prod)
  8906. return Object.freeze({
  8907. get attrs() {
  8908. return attrs || (attrs = createAttrsProxy(instance));
  8909. },
  8910. get slots() {
  8911. return shallowReadonly(instance.slots);
  8912. },
  8913. get emit() {
  8914. return (event, ...args) => instance.emit(event, ...args);
  8915. },
  8916. expose
  8917. });
  8918. }
  8919. }
  8920. function getExposeProxy(instance) {
  8921. if (instance.exposed) {
  8922. return (instance.exposeProxy ||
  8923. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8924. get(target, key) {
  8925. if (key in target) {
  8926. return target[key];
  8927. }
  8928. else if (key in publicPropertiesMap) {
  8929. return publicPropertiesMap[key](instance);
  8930. }
  8931. },
  8932. has(target, key) {
  8933. return key in target || key in publicPropertiesMap;
  8934. }
  8935. })));
  8936. }
  8937. }
  8938. const classifyRE = /(?:^|[-_])(\w)/g;
  8939. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8940. function getComponentName(Component, includeInferred = true) {
  8941. return isFunction(Component)
  8942. ? Component.displayName || Component.name
  8943. : Component.name || (includeInferred && Component.__name);
  8944. }
  8945. /* istanbul ignore next */
  8946. function formatComponentName(instance, Component, isRoot = false) {
  8947. let name = getComponentName(Component);
  8948. if (!name && Component.__file) {
  8949. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8950. if (match) {
  8951. name = match[1];
  8952. }
  8953. }
  8954. if (!name && instance && instance.parent) {
  8955. // try to infer the name based on reverse resolution
  8956. const inferFromRegistry = (registry) => {
  8957. for (const key in registry) {
  8958. if (registry[key] === Component) {
  8959. return key;
  8960. }
  8961. }
  8962. };
  8963. name =
  8964. inferFromRegistry(instance.components ||
  8965. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8966. }
  8967. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8968. }
  8969. function isClassComponent(value) {
  8970. return isFunction(value) && '__vccOpts' in value;
  8971. }
  8972. const computed = ((getterOrOptions, debugOptions) => {
  8973. // @ts-ignore
  8974. return computed$1(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8975. });
  8976. // dev only
  8977. const warnRuntimeUsage = (method) => warn(`${method}() is a compiler-hint helper that is only usable inside ` +
  8978. `<script setup> of a single file component. Its arguments should be ` +
  8979. `compiled away and passing it at runtime has no effect.`);
  8980. // implementation
  8981. function defineProps() {
  8982. {
  8983. warnRuntimeUsage(`defineProps`);
  8984. }
  8985. return null;
  8986. }
  8987. // implementation
  8988. function defineEmits() {
  8989. {
  8990. warnRuntimeUsage(`defineEmits`);
  8991. }
  8992. return null;
  8993. }
  8994. /**
  8995. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8996. * instance properties when it is accessed by a parent component via template
  8997. * refs.
  8998. *
  8999. * `<script setup>` components are closed by default - i.e. variables inside
  9000. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  9001. * via `defineExpose`.
  9002. *
  9003. * This is only usable inside `<script setup>`, is compiled away in the
  9004. * output and should **not** be actually called at runtime.
  9005. */
  9006. function defineExpose(exposed) {
  9007. {
  9008. warnRuntimeUsage(`defineExpose`);
  9009. }
  9010. }
  9011. /**
  9012. * Vue `<script setup>` compiler macro for providing props default values when
  9013. * using type-based `defineProps` declaration.
  9014. *
  9015. * Example usage:
  9016. * ```ts
  9017. * withDefaults(defineProps<{
  9018. * size?: number
  9019. * labels?: string[]
  9020. * }>(), {
  9021. * size: 3,
  9022. * labels: () => ['default label']
  9023. * })
  9024. * ```
  9025. *
  9026. * This is only usable inside `<script setup>`, is compiled away in the output
  9027. * and should **not** be actually called at runtime.
  9028. */
  9029. function withDefaults(props, defaults) {
  9030. {
  9031. warnRuntimeUsage(`withDefaults`);
  9032. }
  9033. return null;
  9034. }
  9035. function useSlots() {
  9036. return getContext().slots;
  9037. }
  9038. function useAttrs() {
  9039. return getContext().attrs;
  9040. }
  9041. function getContext() {
  9042. const i = getCurrentInstance();
  9043. if (!i) {
  9044. warn(`useContext() called without active instance.`);
  9045. }
  9046. return i.setupContext || (i.setupContext = createSetupContext(i));
  9047. }
  9048. /**
  9049. * Runtime helper for merging default declarations. Imported by compiled code
  9050. * only.
  9051. * @internal
  9052. */
  9053. function mergeDefaults(raw, defaults) {
  9054. const props = isArray(raw)
  9055. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  9056. : raw;
  9057. for (const key in defaults) {
  9058. const opt = props[key];
  9059. if (opt) {
  9060. if (isArray(opt) || isFunction(opt)) {
  9061. props[key] = { type: opt, default: defaults[key] };
  9062. }
  9063. else {
  9064. opt.default = defaults[key];
  9065. }
  9066. }
  9067. else if (opt === null) {
  9068. props[key] = { default: defaults[key] };
  9069. }
  9070. else {
  9071. warn(`props default key "${key}" has no corresponding declaration.`);
  9072. }
  9073. }
  9074. return props;
  9075. }
  9076. /**
  9077. * Used to create a proxy for the rest element when destructuring props with
  9078. * defineProps().
  9079. * @internal
  9080. */
  9081. function createPropsRestProxy(props, excludedKeys) {
  9082. const ret = {};
  9083. for (const key in props) {
  9084. if (!excludedKeys.includes(key)) {
  9085. Object.defineProperty(ret, key, {
  9086. enumerable: true,
  9087. get: () => props[key]
  9088. });
  9089. }
  9090. }
  9091. return ret;
  9092. }
  9093. /**
  9094. * `<script setup>` helper for persisting the current instance context over
  9095. * async/await flows.
  9096. *
  9097. * `@vue/compiler-sfc` converts the following:
  9098. *
  9099. * ```ts
  9100. * const x = await foo()
  9101. * ```
  9102. *
  9103. * into:
  9104. *
  9105. * ```ts
  9106. * let __temp, __restore
  9107. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  9108. * ```
  9109. * @internal
  9110. */
  9111. function withAsyncContext(getAwaitable) {
  9112. const ctx = getCurrentInstance();
  9113. if (!ctx) {
  9114. warn(`withAsyncContext called without active current instance. ` +
  9115. `This is likely a bug.`);
  9116. }
  9117. let awaitable = getAwaitable();
  9118. unsetCurrentInstance();
  9119. if (isPromise(awaitable)) {
  9120. awaitable = awaitable.catch(e => {
  9121. setCurrentInstance(ctx);
  9122. throw e;
  9123. });
  9124. }
  9125. return [awaitable, () => setCurrentInstance(ctx)];
  9126. }
  9127. // Actual implementation
  9128. function h(type, propsOrChildren, children) {
  9129. const l = arguments.length;
  9130. if (l === 2) {
  9131. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  9132. // single vnode without props
  9133. if (isVNode(propsOrChildren)) {
  9134. return createVNode(type, null, [propsOrChildren]);
  9135. }
  9136. // props without children
  9137. return createVNode(type, propsOrChildren);
  9138. }
  9139. else {
  9140. // omit props
  9141. return createVNode(type, null, propsOrChildren);
  9142. }
  9143. }
  9144. else {
  9145. if (l > 3) {
  9146. children = Array.prototype.slice.call(arguments, 2);
  9147. }
  9148. else if (l === 3 && isVNode(children)) {
  9149. children = [children];
  9150. }
  9151. return createVNode(type, propsOrChildren, children);
  9152. }
  9153. }
  9154. const ssrContextKey = Symbol(`ssrContext` );
  9155. const useSSRContext = () => {
  9156. {
  9157. warn(`useSSRContext() is not supported in the global build.`);
  9158. }
  9159. };
  9160. function initCustomFormatter() {
  9161. /* eslint-disable no-restricted-globals */
  9162. if (typeof window === 'undefined') {
  9163. return;
  9164. }
  9165. const vueStyle = { style: 'color:#3ba776' };
  9166. const numberStyle = { style: 'color:#0b1bc9' };
  9167. const stringStyle = { style: 'color:#b62e24' };
  9168. const keywordStyle = { style: 'color:#9d288c' };
  9169. // custom formatter for Chrome
  9170. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  9171. const formatter = {
  9172. header(obj) {
  9173. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  9174. if (!isObject(obj)) {
  9175. return null;
  9176. }
  9177. if (obj.__isVue) {
  9178. return ['div', vueStyle, `VueInstance`];
  9179. }
  9180. else if (isRef(obj)) {
  9181. return [
  9182. 'div',
  9183. {},
  9184. ['span', vueStyle, genRefFlag(obj)],
  9185. '<',
  9186. formatValue(obj.value),
  9187. `>`
  9188. ];
  9189. }
  9190. else if (isReactive(obj)) {
  9191. return [
  9192. 'div',
  9193. {},
  9194. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  9195. '<',
  9196. formatValue(obj),
  9197. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  9198. ];
  9199. }
  9200. else if (isReadonly(obj)) {
  9201. return [
  9202. 'div',
  9203. {},
  9204. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  9205. '<',
  9206. formatValue(obj),
  9207. '>'
  9208. ];
  9209. }
  9210. return null;
  9211. },
  9212. hasBody(obj) {
  9213. return obj && obj.__isVue;
  9214. },
  9215. body(obj) {
  9216. if (obj && obj.__isVue) {
  9217. return [
  9218. 'div',
  9219. {},
  9220. ...formatInstance(obj.$)
  9221. ];
  9222. }
  9223. }
  9224. };
  9225. function formatInstance(instance) {
  9226. const blocks = [];
  9227. if (instance.type.props && instance.props) {
  9228. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  9229. }
  9230. if (instance.setupState !== EMPTY_OBJ) {
  9231. blocks.push(createInstanceBlock('setup', instance.setupState));
  9232. }
  9233. if (instance.data !== EMPTY_OBJ) {
  9234. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  9235. }
  9236. const computed = extractKeys(instance, 'computed');
  9237. if (computed) {
  9238. blocks.push(createInstanceBlock('computed', computed));
  9239. }
  9240. const injected = extractKeys(instance, 'inject');
  9241. if (injected) {
  9242. blocks.push(createInstanceBlock('injected', injected));
  9243. }
  9244. blocks.push([
  9245. 'div',
  9246. {},
  9247. [
  9248. 'span',
  9249. {
  9250. style: keywordStyle.style + ';opacity:0.66'
  9251. },
  9252. '$ (internal): '
  9253. ],
  9254. ['object', { object: instance }]
  9255. ]);
  9256. return blocks;
  9257. }
  9258. function createInstanceBlock(type, target) {
  9259. target = extend({}, target);
  9260. if (!Object.keys(target).length) {
  9261. return ['span', {}];
  9262. }
  9263. return [
  9264. 'div',
  9265. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9266. [
  9267. 'div',
  9268. {
  9269. style: 'color:#476582'
  9270. },
  9271. type
  9272. ],
  9273. [
  9274. 'div',
  9275. {
  9276. style: 'padding-left:1.25em'
  9277. },
  9278. ...Object.keys(target).map(key => {
  9279. return [
  9280. 'div',
  9281. {},
  9282. ['span', keywordStyle, key + ': '],
  9283. formatValue(target[key], false)
  9284. ];
  9285. })
  9286. ]
  9287. ];
  9288. }
  9289. function formatValue(v, asRaw = true) {
  9290. if (typeof v === 'number') {
  9291. return ['span', numberStyle, v];
  9292. }
  9293. else if (typeof v === 'string') {
  9294. return ['span', stringStyle, JSON.stringify(v)];
  9295. }
  9296. else if (typeof v === 'boolean') {
  9297. return ['span', keywordStyle, v];
  9298. }
  9299. else if (isObject(v)) {
  9300. return ['object', { object: asRaw ? toRaw(v) : v }];
  9301. }
  9302. else {
  9303. return ['span', stringStyle, String(v)];
  9304. }
  9305. }
  9306. function extractKeys(instance, type) {
  9307. const Comp = instance.type;
  9308. if (isFunction(Comp)) {
  9309. return;
  9310. }
  9311. const extracted = {};
  9312. for (const key in instance.ctx) {
  9313. if (isKeyOfType(Comp, key, type)) {
  9314. extracted[key] = instance.ctx[key];
  9315. }
  9316. }
  9317. return extracted;
  9318. }
  9319. function isKeyOfType(Comp, key, type) {
  9320. const opts = Comp[type];
  9321. if ((isArray(opts) && opts.includes(key)) ||
  9322. (isObject(opts) && key in opts)) {
  9323. return true;
  9324. }
  9325. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9326. return true;
  9327. }
  9328. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9329. return true;
  9330. }
  9331. }
  9332. function genRefFlag(v) {
  9333. if (isShallow(v)) {
  9334. return `ShallowRef`;
  9335. }
  9336. if (v.effect) {
  9337. return `ComputedRef`;
  9338. }
  9339. return `Ref`;
  9340. }
  9341. if (window.devtoolsFormatters) {
  9342. window.devtoolsFormatters.push(formatter);
  9343. }
  9344. else {
  9345. window.devtoolsFormatters = [formatter];
  9346. }
  9347. }
  9348. function withMemo(memo, render, cache, index) {
  9349. const cached = cache[index];
  9350. if (cached && isMemoSame(cached, memo)) {
  9351. return cached;
  9352. }
  9353. const ret = render();
  9354. // shallow clone
  9355. ret.memo = memo.slice();
  9356. return (cache[index] = ret);
  9357. }
  9358. function isMemoSame(cached, memo) {
  9359. const prev = cached.memo;
  9360. if (prev.length != memo.length) {
  9361. return false;
  9362. }
  9363. for (let i = 0; i < prev.length; i++) {
  9364. if (hasChanged(prev[i], memo[i])) {
  9365. return false;
  9366. }
  9367. }
  9368. // make sure to let parent block track it when returning cached
  9369. if (isBlockTreeEnabled > 0 && currentBlock) {
  9370. currentBlock.push(cached);
  9371. }
  9372. return true;
  9373. }
  9374. // Core API ------------------------------------------------------------------
  9375. const version = "3.2.47";
  9376. /**
  9377. * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
  9378. * @internal
  9379. */
  9380. const ssrUtils = (null);
  9381. /**
  9382. * @internal only exposed in compat builds
  9383. */
  9384. const resolveFilter = null;
  9385. /**
  9386. * @internal only exposed in compat builds.
  9387. */
  9388. const compatUtils = (null);
  9389. const svgNS = 'http://www.w3.org/2000/svg';
  9390. const doc = (typeof document !== 'undefined' ? document : null);
  9391. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9392. const nodeOps = {
  9393. insert: (child, parent, anchor) => {
  9394. parent.insertBefore(child, anchor || null);
  9395. },
  9396. remove: child => {
  9397. const parent = child.parentNode;
  9398. if (parent) {
  9399. parent.removeChild(child);
  9400. }
  9401. },
  9402. createElement: (tag, isSVG, is, props) => {
  9403. const el = isSVG
  9404. ? doc.createElementNS(svgNS, tag)
  9405. : doc.createElement(tag, is ? { is } : undefined);
  9406. if (tag === 'select' && props && props.multiple != null) {
  9407. el.setAttribute('multiple', props.multiple);
  9408. }
  9409. return el;
  9410. },
  9411. createText: text => doc.createTextNode(text),
  9412. createComment: text => doc.createComment(text),
  9413. setText: (node, text) => {
  9414. node.nodeValue = text;
  9415. },
  9416. setElementText: (el, text) => {
  9417. el.textContent = text;
  9418. },
  9419. parentNode: node => node.parentNode,
  9420. nextSibling: node => node.nextSibling,
  9421. querySelector: selector => doc.querySelector(selector),
  9422. setScopeId(el, id) {
  9423. el.setAttribute(id, '');
  9424. },
  9425. // __UNSAFE__
  9426. // Reason: innerHTML.
  9427. // Static content here can only come from compiled templates.
  9428. // As long as the user only uses trusted templates, this is safe.
  9429. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9430. // <parent> before | first ... last | anchor </parent>
  9431. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9432. // #5308 can only take cached path if:
  9433. // - has a single root node
  9434. // - nextSibling info is still available
  9435. if (start && (start === end || start.nextSibling)) {
  9436. // cached
  9437. while (true) {
  9438. parent.insertBefore(start.cloneNode(true), anchor);
  9439. if (start === end || !(start = start.nextSibling))
  9440. break;
  9441. }
  9442. }
  9443. else {
  9444. // fresh insert
  9445. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9446. const template = templateContainer.content;
  9447. if (isSVG) {
  9448. // remove outer svg wrapper
  9449. const wrapper = template.firstChild;
  9450. while (wrapper.firstChild) {
  9451. template.appendChild(wrapper.firstChild);
  9452. }
  9453. template.removeChild(wrapper);
  9454. }
  9455. parent.insertBefore(template, anchor);
  9456. }
  9457. return [
  9458. // first
  9459. before ? before.nextSibling : parent.firstChild,
  9460. // last
  9461. anchor ? anchor.previousSibling : parent.lastChild
  9462. ];
  9463. }
  9464. };
  9465. // compiler should normalize class + :class bindings on the same element
  9466. // into a single binding ['staticClass', dynamic]
  9467. function patchClass(el, value, isSVG) {
  9468. // directly setting className should be faster than setAttribute in theory
  9469. // if this is an element during a transition, take the temporary transition
  9470. // classes into account.
  9471. const transitionClasses = el._vtc;
  9472. if (transitionClasses) {
  9473. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9474. }
  9475. if (value == null) {
  9476. el.removeAttribute('class');
  9477. }
  9478. else if (isSVG) {
  9479. el.setAttribute('class', value);
  9480. }
  9481. else {
  9482. el.className = value;
  9483. }
  9484. }
  9485. function patchStyle(el, prev, next) {
  9486. const style = el.style;
  9487. const isCssString = isString(next);
  9488. if (next && !isCssString) {
  9489. if (prev && !isString(prev)) {
  9490. for (const key in prev) {
  9491. if (next[key] == null) {
  9492. setStyle(style, key, '');
  9493. }
  9494. }
  9495. }
  9496. for (const key in next) {
  9497. setStyle(style, key, next[key]);
  9498. }
  9499. }
  9500. else {
  9501. const currentDisplay = style.display;
  9502. if (isCssString) {
  9503. if (prev !== next) {
  9504. style.cssText = next;
  9505. }
  9506. }
  9507. else if (prev) {
  9508. el.removeAttribute('style');
  9509. }
  9510. // indicates that the `display` of the element is controlled by `v-show`,
  9511. // so we always keep the current `display` value regardless of the `style`
  9512. // value, thus handing over control to `v-show`.
  9513. if ('_vod' in el) {
  9514. style.display = currentDisplay;
  9515. }
  9516. }
  9517. }
  9518. const semicolonRE = /[^\\];\s*$/;
  9519. const importantRE = /\s*!important$/;
  9520. function setStyle(style, name, val) {
  9521. if (isArray(val)) {
  9522. val.forEach(v => setStyle(style, name, v));
  9523. }
  9524. else {
  9525. if (val == null)
  9526. val = '';
  9527. {
  9528. if (semicolonRE.test(val)) {
  9529. warn(`Unexpected semicolon at the end of '${name}' style value: '${val}'`);
  9530. }
  9531. }
  9532. if (name.startsWith('--')) {
  9533. // custom property definition
  9534. style.setProperty(name, val);
  9535. }
  9536. else {
  9537. const prefixed = autoPrefix(style, name);
  9538. if (importantRE.test(val)) {
  9539. // !important
  9540. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9541. }
  9542. else {
  9543. style[prefixed] = val;
  9544. }
  9545. }
  9546. }
  9547. }
  9548. const prefixes = ['Webkit', 'Moz', 'ms'];
  9549. const prefixCache = {};
  9550. function autoPrefix(style, rawName) {
  9551. const cached = prefixCache[rawName];
  9552. if (cached) {
  9553. return cached;
  9554. }
  9555. let name = camelize(rawName);
  9556. if (name !== 'filter' && name in style) {
  9557. return (prefixCache[rawName] = name);
  9558. }
  9559. name = capitalize(name);
  9560. for (let i = 0; i < prefixes.length; i++) {
  9561. const prefixed = prefixes[i] + name;
  9562. if (prefixed in style) {
  9563. return (prefixCache[rawName] = prefixed);
  9564. }
  9565. }
  9566. return rawName;
  9567. }
  9568. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9569. function patchAttr(el, key, value, isSVG, instance) {
  9570. if (isSVG && key.startsWith('xlink:')) {
  9571. if (value == null) {
  9572. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9573. }
  9574. else {
  9575. el.setAttributeNS(xlinkNS, key, value);
  9576. }
  9577. }
  9578. else {
  9579. // note we are only checking boolean attributes that don't have a
  9580. // corresponding dom prop of the same name here.
  9581. const isBoolean = isSpecialBooleanAttr(key);
  9582. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9583. el.removeAttribute(key);
  9584. }
  9585. else {
  9586. el.setAttribute(key, isBoolean ? '' : value);
  9587. }
  9588. }
  9589. }
  9590. // __UNSAFE__
  9591. // functions. The user is responsible for using them with only trusted content.
  9592. function patchDOMProp(el, key, value,
  9593. // the following args are passed only due to potential innerHTML/textContent
  9594. // overriding existing VNodes, in which case the old tree must be properly
  9595. // unmounted.
  9596. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9597. if (key === 'innerHTML' || key === 'textContent') {
  9598. if (prevChildren) {
  9599. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9600. }
  9601. el[key] = value == null ? '' : value;
  9602. return;
  9603. }
  9604. if (key === 'value' &&
  9605. el.tagName !== 'PROGRESS' &&
  9606. // custom elements may use _value internally
  9607. !el.tagName.includes('-')) {
  9608. // store value as _value as well since
  9609. // non-string values will be stringified.
  9610. el._value = value;
  9611. const newValue = value == null ? '' : value;
  9612. if (el.value !== newValue ||
  9613. // #4956: always set for OPTION elements because its value falls back to
  9614. // textContent if no value attribute is present. And setting .value for
  9615. // OPTION has no side effect
  9616. el.tagName === 'OPTION') {
  9617. el.value = newValue;
  9618. }
  9619. if (value == null) {
  9620. el.removeAttribute(key);
  9621. }
  9622. return;
  9623. }
  9624. let needRemove = false;
  9625. if (value === '' || value == null) {
  9626. const type = typeof el[key];
  9627. if (type === 'boolean') {
  9628. // e.g. <select multiple> compiles to { multiple: '' }
  9629. value = includeBooleanAttr(value);
  9630. }
  9631. else if (value == null && type === 'string') {
  9632. // e.g. <div :id="null">
  9633. value = '';
  9634. needRemove = true;
  9635. }
  9636. else if (type === 'number') {
  9637. // e.g. <img :width="null">
  9638. value = 0;
  9639. needRemove = true;
  9640. }
  9641. }
  9642. // some properties perform value validation and throw,
  9643. // some properties has getter, no setter, will error in 'use strict'
  9644. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9645. try {
  9646. el[key] = value;
  9647. }
  9648. catch (e) {
  9649. // do not warn if value is auto-coerced from nullish values
  9650. if (!needRemove) {
  9651. warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9652. `value ${value} is invalid.`, e);
  9653. }
  9654. }
  9655. needRemove && el.removeAttribute(key);
  9656. }
  9657. function addEventListener(el, event, handler, options) {
  9658. el.addEventListener(event, handler, options);
  9659. }
  9660. function removeEventListener(el, event, handler, options) {
  9661. el.removeEventListener(event, handler, options);
  9662. }
  9663. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9664. // vei = vue event invokers
  9665. const invokers = el._vei || (el._vei = {});
  9666. const existingInvoker = invokers[rawName];
  9667. if (nextValue && existingInvoker) {
  9668. // patch
  9669. existingInvoker.value = nextValue;
  9670. }
  9671. else {
  9672. const [name, options] = parseName(rawName);
  9673. if (nextValue) {
  9674. // add
  9675. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9676. addEventListener(el, name, invoker, options);
  9677. }
  9678. else if (existingInvoker) {
  9679. // remove
  9680. removeEventListener(el, name, existingInvoker, options);
  9681. invokers[rawName] = undefined;
  9682. }
  9683. }
  9684. }
  9685. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9686. function parseName(name) {
  9687. let options;
  9688. if (optionsModifierRE.test(name)) {
  9689. options = {};
  9690. let m;
  9691. while ((m = name.match(optionsModifierRE))) {
  9692. name = name.slice(0, name.length - m[0].length);
  9693. options[m[0].toLowerCase()] = true;
  9694. }
  9695. }
  9696. const event = name[2] === ':' ? name.slice(3) : hyphenate(name.slice(2));
  9697. return [event, options];
  9698. }
  9699. // To avoid the overhead of repeatedly calling Date.now(), we cache
  9700. // and use the same timestamp for all event listeners attached in the same tick.
  9701. let cachedNow = 0;
  9702. const p = /*#__PURE__*/ Promise.resolve();
  9703. const getNow = () => cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = Date.now()));
  9704. function createInvoker(initialValue, instance) {
  9705. const invoker = (e) => {
  9706. // async edge case vuejs/vue#6566
  9707. // inner click event triggers patch, event handler
  9708. // attached to outer element during patch, and triggered again. This
  9709. // happens because browsers fire microtask ticks between event propagation.
  9710. // this no longer happens for templates in Vue 3, but could still be
  9711. // theoretically possible for hand-written render functions.
  9712. // the solution: we save the timestamp when a handler is attached,
  9713. // and also attach the timestamp to any event that was handled by vue
  9714. // for the first time (to avoid inconsistent event timestamp implementations
  9715. // or events fired from iframes, e.g. #2513)
  9716. // The handler would only fire if the event passed to it was fired
  9717. // AFTER it was attached.
  9718. if (!e._vts) {
  9719. e._vts = Date.now();
  9720. }
  9721. else if (e._vts <= invoker.attached) {
  9722. return;
  9723. }
  9724. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */, [e]);
  9725. };
  9726. invoker.value = initialValue;
  9727. invoker.attached = getNow();
  9728. return invoker;
  9729. }
  9730. function patchStopImmediatePropagation(e, value) {
  9731. if (isArray(value)) {
  9732. const originalStop = e.stopImmediatePropagation;
  9733. e.stopImmediatePropagation = () => {
  9734. originalStop.call(e);
  9735. e._stopped = true;
  9736. };
  9737. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9738. }
  9739. else {
  9740. return value;
  9741. }
  9742. }
  9743. const nativeOnRE = /^on[a-z]/;
  9744. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9745. if (key === 'class') {
  9746. patchClass(el, nextValue, isSVG);
  9747. }
  9748. else if (key === 'style') {
  9749. patchStyle(el, prevValue, nextValue);
  9750. }
  9751. else if (isOn(key)) {
  9752. // ignore v-model listeners
  9753. if (!isModelListener(key)) {
  9754. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9755. }
  9756. }
  9757. else if (key[0] === '.'
  9758. ? ((key = key.slice(1)), true)
  9759. : key[0] === '^'
  9760. ? ((key = key.slice(1)), false)
  9761. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9762. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9763. }
  9764. else {
  9765. // special case for <input v-model type="checkbox"> with
  9766. // :true-value & :false-value
  9767. // store value as dom properties since non-string values will be
  9768. // stringified.
  9769. if (key === 'true-value') {
  9770. el._trueValue = nextValue;
  9771. }
  9772. else if (key === 'false-value') {
  9773. el._falseValue = nextValue;
  9774. }
  9775. patchAttr(el, key, nextValue, isSVG);
  9776. }
  9777. };
  9778. function shouldSetAsProp(el, key, value, isSVG) {
  9779. if (isSVG) {
  9780. // most keys must be set as attribute on svg elements to work
  9781. // ...except innerHTML & textContent
  9782. if (key === 'innerHTML' || key === 'textContent') {
  9783. return true;
  9784. }
  9785. // or native onclick with function values
  9786. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9787. return true;
  9788. }
  9789. return false;
  9790. }
  9791. // these are enumerated attrs, however their corresponding DOM properties
  9792. // are actually booleans - this leads to setting it with a string "false"
  9793. // value leading it to be coerced to `true`, so we need to always treat
  9794. // them as attributes.
  9795. // Note that `contentEditable` doesn't have this problem: its DOM
  9796. // property is also enumerated string values.
  9797. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9798. return false;
  9799. }
  9800. // #1787, #2840 form property on form elements is readonly and must be set as
  9801. // attribute.
  9802. if (key === 'form') {
  9803. return false;
  9804. }
  9805. // #1526 <input list> must be set as attribute
  9806. if (key === 'list' && el.tagName === 'INPUT') {
  9807. return false;
  9808. }
  9809. // #2766 <textarea type> must be set as attribute
  9810. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9811. return false;
  9812. }
  9813. // native onclick with string value, must be set as attribute
  9814. if (nativeOnRE.test(key) && isString(value)) {
  9815. return false;
  9816. }
  9817. return key in el;
  9818. }
  9819. function defineCustomElement(options, hydrate) {
  9820. const Comp = defineComponent(options);
  9821. class VueCustomElement extends VueElement {
  9822. constructor(initialProps) {
  9823. super(Comp, initialProps, hydrate);
  9824. }
  9825. }
  9826. VueCustomElement.def = Comp;
  9827. return VueCustomElement;
  9828. }
  9829. const defineSSRCustomElement = ((options) => {
  9830. // @ts-ignore
  9831. return defineCustomElement(options, hydrate);
  9832. });
  9833. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9834. });
  9835. class VueElement extends BaseClass {
  9836. constructor(_def, _props = {}, hydrate) {
  9837. super();
  9838. this._def = _def;
  9839. this._props = _props;
  9840. /**
  9841. * @internal
  9842. */
  9843. this._instance = null;
  9844. this._connected = false;
  9845. this._resolved = false;
  9846. this._numberProps = null;
  9847. if (this.shadowRoot && hydrate) {
  9848. hydrate(this._createVNode(), this.shadowRoot);
  9849. }
  9850. else {
  9851. if (this.shadowRoot) {
  9852. warn(`Custom element has pre-rendered declarative shadow root but is not ` +
  9853. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9854. }
  9855. this.attachShadow({ mode: 'open' });
  9856. if (!this._def.__asyncLoader) {
  9857. // for sync component defs we can immediately resolve props
  9858. this._resolveProps(this._def);
  9859. }
  9860. }
  9861. }
  9862. connectedCallback() {
  9863. this._connected = true;
  9864. if (!this._instance) {
  9865. if (this._resolved) {
  9866. this._update();
  9867. }
  9868. else {
  9869. this._resolveDef();
  9870. }
  9871. }
  9872. }
  9873. disconnectedCallback() {
  9874. this._connected = false;
  9875. nextTick(() => {
  9876. if (!this._connected) {
  9877. render(null, this.shadowRoot);
  9878. this._instance = null;
  9879. }
  9880. });
  9881. }
  9882. /**
  9883. * resolve inner component definition (handle possible async component)
  9884. */
  9885. _resolveDef() {
  9886. this._resolved = true;
  9887. // set initial attrs
  9888. for (let i = 0; i < this.attributes.length; i++) {
  9889. this._setAttr(this.attributes[i].name);
  9890. }
  9891. // watch future attr changes
  9892. new MutationObserver(mutations => {
  9893. for (const m of mutations) {
  9894. this._setAttr(m.attributeName);
  9895. }
  9896. }).observe(this, { attributes: true });
  9897. const resolve = (def, isAsync = false) => {
  9898. const { props, styles } = def;
  9899. // cast Number-type props set before resolve
  9900. let numberProps;
  9901. if (props && !isArray(props)) {
  9902. for (const key in props) {
  9903. const opt = props[key];
  9904. if (opt === Number || (opt && opt.type === Number)) {
  9905. if (key in this._props) {
  9906. this._props[key] = toNumber(this._props[key]);
  9907. }
  9908. (numberProps || (numberProps = Object.create(null)))[camelize(key)] = true;
  9909. }
  9910. }
  9911. }
  9912. this._numberProps = numberProps;
  9913. if (isAsync) {
  9914. // defining getter/setters on prototype
  9915. // for sync defs, this already happened in the constructor
  9916. this._resolveProps(def);
  9917. }
  9918. // apply CSS
  9919. this._applyStyles(styles);
  9920. // initial render
  9921. this._update();
  9922. };
  9923. const asyncDef = this._def.__asyncLoader;
  9924. if (asyncDef) {
  9925. asyncDef().then(def => resolve(def, true));
  9926. }
  9927. else {
  9928. resolve(this._def);
  9929. }
  9930. }
  9931. _resolveProps(def) {
  9932. const { props } = def;
  9933. const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
  9934. // check if there are props set pre-upgrade or connect
  9935. for (const key of Object.keys(this)) {
  9936. if (key[0] !== '_' && declaredPropKeys.includes(key)) {
  9937. this._setProp(key, this[key], true, false);
  9938. }
  9939. }
  9940. // defining getter/setters on prototype
  9941. for (const key of declaredPropKeys.map(camelize)) {
  9942. Object.defineProperty(this, key, {
  9943. get() {
  9944. return this._getProp(key);
  9945. },
  9946. set(val) {
  9947. this._setProp(key, val);
  9948. }
  9949. });
  9950. }
  9951. }
  9952. _setAttr(key) {
  9953. let value = this.getAttribute(key);
  9954. const camelKey = camelize(key);
  9955. if (this._numberProps && this._numberProps[camelKey]) {
  9956. value = toNumber(value);
  9957. }
  9958. this._setProp(camelKey, value, false);
  9959. }
  9960. /**
  9961. * @internal
  9962. */
  9963. _getProp(key) {
  9964. return this._props[key];
  9965. }
  9966. /**
  9967. * @internal
  9968. */
  9969. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9970. if (val !== this._props[key]) {
  9971. this._props[key] = val;
  9972. if (shouldUpdate && this._instance) {
  9973. this._update();
  9974. }
  9975. // reflect
  9976. if (shouldReflect) {
  9977. if (val === true) {
  9978. this.setAttribute(hyphenate(key), '');
  9979. }
  9980. else if (typeof val === 'string' || typeof val === 'number') {
  9981. this.setAttribute(hyphenate(key), val + '');
  9982. }
  9983. else if (!val) {
  9984. this.removeAttribute(hyphenate(key));
  9985. }
  9986. }
  9987. }
  9988. }
  9989. _update() {
  9990. render(this._createVNode(), this.shadowRoot);
  9991. }
  9992. _createVNode() {
  9993. const vnode = createVNode(this._def, extend({}, this._props));
  9994. if (!this._instance) {
  9995. vnode.ce = instance => {
  9996. this._instance = instance;
  9997. instance.isCE = true;
  9998. // HMR
  9999. {
  10000. instance.ceReload = newStyles => {
  10001. // always reset styles
  10002. if (this._styles) {
  10003. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  10004. this._styles.length = 0;
  10005. }
  10006. this._applyStyles(newStyles);
  10007. this._instance = null;
  10008. this._update();
  10009. };
  10010. }
  10011. const dispatch = (event, args) => {
  10012. this.dispatchEvent(new CustomEvent(event, {
  10013. detail: args
  10014. }));
  10015. };
  10016. // intercept emit
  10017. instance.emit = (event, ...args) => {
  10018. // dispatch both the raw and hyphenated versions of an event
  10019. // to match Vue behavior
  10020. dispatch(event, args);
  10021. if (hyphenate(event) !== event) {
  10022. dispatch(hyphenate(event), args);
  10023. }
  10024. };
  10025. // locate nearest Vue custom element parent for provide/inject
  10026. let parent = this;
  10027. while ((parent =
  10028. parent && (parent.parentNode || parent.host))) {
  10029. if (parent instanceof VueElement) {
  10030. instance.parent = parent._instance;
  10031. instance.provides = parent._instance.provides;
  10032. break;
  10033. }
  10034. }
  10035. };
  10036. }
  10037. return vnode;
  10038. }
  10039. _applyStyles(styles) {
  10040. if (styles) {
  10041. styles.forEach(css => {
  10042. const s = document.createElement('style');
  10043. s.textContent = css;
  10044. this.shadowRoot.appendChild(s);
  10045. // record for HMR
  10046. {
  10047. (this._styles || (this._styles = [])).push(s);
  10048. }
  10049. });
  10050. }
  10051. }
  10052. }
  10053. function useCssModule(name = '$style') {
  10054. /* istanbul ignore else */
  10055. {
  10056. {
  10057. warn(`useCssModule() is not supported in the global build.`);
  10058. }
  10059. return EMPTY_OBJ;
  10060. }
  10061. }
  10062. /**
  10063. * Runtime helper for SFC's CSS variable injection feature.
  10064. * @private
  10065. */
  10066. function useCssVars(getter) {
  10067. const instance = getCurrentInstance();
  10068. /* istanbul ignore next */
  10069. if (!instance) {
  10070. warn(`useCssVars is called without current active component instance.`);
  10071. return;
  10072. }
  10073. const updateTeleports = (instance.ut = (vars = getter(instance.proxy)) => {
  10074. Array.from(document.querySelectorAll(`[data-v-owner="${instance.uid}"]`)).forEach(node => setVarsOnNode(node, vars));
  10075. });
  10076. const setVars = () => {
  10077. const vars = getter(instance.proxy);
  10078. setVarsOnVNode(instance.subTree, vars);
  10079. updateTeleports(vars);
  10080. };
  10081. watchPostEffect(setVars);
  10082. onMounted(() => {
  10083. const ob = new MutationObserver(setVars);
  10084. ob.observe(instance.subTree.el.parentNode, { childList: true });
  10085. onUnmounted(() => ob.disconnect());
  10086. });
  10087. }
  10088. function setVarsOnVNode(vnode, vars) {
  10089. if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  10090. const suspense = vnode.suspense;
  10091. vnode = suspense.activeBranch;
  10092. if (suspense.pendingBranch && !suspense.isHydrating) {
  10093. suspense.effects.push(() => {
  10094. setVarsOnVNode(suspense.activeBranch, vars);
  10095. });
  10096. }
  10097. }
  10098. // drill down HOCs until it's a non-component vnode
  10099. while (vnode.component) {
  10100. vnode = vnode.component.subTree;
  10101. }
  10102. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && vnode.el) {
  10103. setVarsOnNode(vnode.el, vars);
  10104. }
  10105. else if (vnode.type === Fragment) {
  10106. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  10107. }
  10108. else if (vnode.type === Static) {
  10109. let { el, anchor } = vnode;
  10110. while (el) {
  10111. setVarsOnNode(el, vars);
  10112. if (el === anchor)
  10113. break;
  10114. el = el.nextSibling;
  10115. }
  10116. }
  10117. }
  10118. function setVarsOnNode(el, vars) {
  10119. if (el.nodeType === 1) {
  10120. const style = el.style;
  10121. for (const key in vars) {
  10122. style.setProperty(`--${key}`, vars[key]);
  10123. }
  10124. }
  10125. }
  10126. const TRANSITION$1 = 'transition';
  10127. const ANIMATION = 'animation';
  10128. // DOM Transition is a higher-order-component based on the platform-agnostic
  10129. // base Transition component, with DOM-specific logic.
  10130. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  10131. Transition.displayName = 'Transition';
  10132. const DOMTransitionPropsValidators = {
  10133. name: String,
  10134. type: String,
  10135. css: {
  10136. type: Boolean,
  10137. default: true
  10138. },
  10139. duration: [String, Number, Object],
  10140. enterFromClass: String,
  10141. enterActiveClass: String,
  10142. enterToClass: String,
  10143. appearFromClass: String,
  10144. appearActiveClass: String,
  10145. appearToClass: String,
  10146. leaveFromClass: String,
  10147. leaveActiveClass: String,
  10148. leaveToClass: String
  10149. };
  10150. const TransitionPropsValidators = (Transition.props =
  10151. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  10152. /**
  10153. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  10154. * with custom HOCs.
  10155. */
  10156. const callHook = (hook, args = []) => {
  10157. if (isArray(hook)) {
  10158. hook.forEach(h => h(...args));
  10159. }
  10160. else if (hook) {
  10161. hook(...args);
  10162. }
  10163. };
  10164. /**
  10165. * Check if a hook expects a callback (2nd arg), which means the user
  10166. * intends to explicitly control the end of the transition.
  10167. */
  10168. const hasExplicitCallback = (hook) => {
  10169. return hook
  10170. ? isArray(hook)
  10171. ? hook.some(h => h.length > 1)
  10172. : hook.length > 1
  10173. : false;
  10174. };
  10175. function resolveTransitionProps(rawProps) {
  10176. const baseProps = {};
  10177. for (const key in rawProps) {
  10178. if (!(key in DOMTransitionPropsValidators)) {
  10179. baseProps[key] = rawProps[key];
  10180. }
  10181. }
  10182. if (rawProps.css === false) {
  10183. return baseProps;
  10184. }
  10185. 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;
  10186. const durations = normalizeDuration(duration);
  10187. const enterDuration = durations && durations[0];
  10188. const leaveDuration = durations && durations[1];
  10189. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  10190. const finishEnter = (el, isAppear, done) => {
  10191. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10192. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  10193. done && done();
  10194. };
  10195. const finishLeave = (el, done) => {
  10196. el._isLeaving = false;
  10197. removeTransitionClass(el, leaveFromClass);
  10198. removeTransitionClass(el, leaveToClass);
  10199. removeTransitionClass(el, leaveActiveClass);
  10200. done && done();
  10201. };
  10202. const makeEnterHook = (isAppear) => {
  10203. return (el, done) => {
  10204. const hook = isAppear ? onAppear : onEnter;
  10205. const resolve = () => finishEnter(el, isAppear, done);
  10206. callHook(hook, [el, resolve]);
  10207. nextFrame(() => {
  10208. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  10209. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10210. if (!hasExplicitCallback(hook)) {
  10211. whenTransitionEnds(el, type, enterDuration, resolve);
  10212. }
  10213. });
  10214. };
  10215. };
  10216. return extend(baseProps, {
  10217. onBeforeEnter(el) {
  10218. callHook(onBeforeEnter, [el]);
  10219. addTransitionClass(el, enterFromClass);
  10220. addTransitionClass(el, enterActiveClass);
  10221. },
  10222. onBeforeAppear(el) {
  10223. callHook(onBeforeAppear, [el]);
  10224. addTransitionClass(el, appearFromClass);
  10225. addTransitionClass(el, appearActiveClass);
  10226. },
  10227. onEnter: makeEnterHook(false),
  10228. onAppear: makeEnterHook(true),
  10229. onLeave(el, done) {
  10230. el._isLeaving = true;
  10231. const resolve = () => finishLeave(el, done);
  10232. addTransitionClass(el, leaveFromClass);
  10233. // force reflow so *-leave-from classes immediately take effect (#2593)
  10234. forceReflow();
  10235. addTransitionClass(el, leaveActiveClass);
  10236. nextFrame(() => {
  10237. if (!el._isLeaving) {
  10238. // cancelled
  10239. return;
  10240. }
  10241. removeTransitionClass(el, leaveFromClass);
  10242. addTransitionClass(el, leaveToClass);
  10243. if (!hasExplicitCallback(onLeave)) {
  10244. whenTransitionEnds(el, type, leaveDuration, resolve);
  10245. }
  10246. });
  10247. callHook(onLeave, [el, resolve]);
  10248. },
  10249. onEnterCancelled(el) {
  10250. finishEnter(el, false);
  10251. callHook(onEnterCancelled, [el]);
  10252. },
  10253. onAppearCancelled(el) {
  10254. finishEnter(el, true);
  10255. callHook(onAppearCancelled, [el]);
  10256. },
  10257. onLeaveCancelled(el) {
  10258. finishLeave(el);
  10259. callHook(onLeaveCancelled, [el]);
  10260. }
  10261. });
  10262. }
  10263. function normalizeDuration(duration) {
  10264. if (duration == null) {
  10265. return null;
  10266. }
  10267. else if (isObject(duration)) {
  10268. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10269. }
  10270. else {
  10271. const n = NumberOf(duration);
  10272. return [n, n];
  10273. }
  10274. }
  10275. function NumberOf(val) {
  10276. const res = toNumber(val);
  10277. {
  10278. assertNumber(res, '<transition> explicit duration');
  10279. }
  10280. return res;
  10281. }
  10282. function addTransitionClass(el, cls) {
  10283. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10284. (el._vtc ||
  10285. (el._vtc = new Set())).add(cls);
  10286. }
  10287. function removeTransitionClass(el, cls) {
  10288. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10289. const { _vtc } = el;
  10290. if (_vtc) {
  10291. _vtc.delete(cls);
  10292. if (!_vtc.size) {
  10293. el._vtc = undefined;
  10294. }
  10295. }
  10296. }
  10297. function nextFrame(cb) {
  10298. requestAnimationFrame(() => {
  10299. requestAnimationFrame(cb);
  10300. });
  10301. }
  10302. let endId = 0;
  10303. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10304. const id = (el._endId = ++endId);
  10305. const resolveIfNotStale = () => {
  10306. if (id === el._endId) {
  10307. resolve();
  10308. }
  10309. };
  10310. if (explicitTimeout) {
  10311. return setTimeout(resolveIfNotStale, explicitTimeout);
  10312. }
  10313. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10314. if (!type) {
  10315. return resolve();
  10316. }
  10317. const endEvent = type + 'end';
  10318. let ended = 0;
  10319. const end = () => {
  10320. el.removeEventListener(endEvent, onEnd);
  10321. resolveIfNotStale();
  10322. };
  10323. const onEnd = (e) => {
  10324. if (e.target === el && ++ended >= propCount) {
  10325. end();
  10326. }
  10327. };
  10328. setTimeout(() => {
  10329. if (ended < propCount) {
  10330. end();
  10331. }
  10332. }, timeout + 1);
  10333. el.addEventListener(endEvent, onEnd);
  10334. }
  10335. function getTransitionInfo(el, expectedType) {
  10336. const styles = window.getComputedStyle(el);
  10337. // JSDOM may return undefined for transition properties
  10338. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10339. const transitionDelays = getStyleProperties(`${TRANSITION$1}Delay`);
  10340. const transitionDurations = getStyleProperties(`${TRANSITION$1}Duration`);
  10341. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10342. const animationDelays = getStyleProperties(`${ANIMATION}Delay`);
  10343. const animationDurations = getStyleProperties(`${ANIMATION}Duration`);
  10344. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10345. let type = null;
  10346. let timeout = 0;
  10347. let propCount = 0;
  10348. /* istanbul ignore if */
  10349. if (expectedType === TRANSITION$1) {
  10350. if (transitionTimeout > 0) {
  10351. type = TRANSITION$1;
  10352. timeout = transitionTimeout;
  10353. propCount = transitionDurations.length;
  10354. }
  10355. }
  10356. else if (expectedType === ANIMATION) {
  10357. if (animationTimeout > 0) {
  10358. type = ANIMATION;
  10359. timeout = animationTimeout;
  10360. propCount = animationDurations.length;
  10361. }
  10362. }
  10363. else {
  10364. timeout = Math.max(transitionTimeout, animationTimeout);
  10365. type =
  10366. timeout > 0
  10367. ? transitionTimeout > animationTimeout
  10368. ? TRANSITION$1
  10369. : ANIMATION
  10370. : null;
  10371. propCount = type
  10372. ? type === TRANSITION$1
  10373. ? transitionDurations.length
  10374. : animationDurations.length
  10375. : 0;
  10376. }
  10377. const hasTransform = type === TRANSITION$1 &&
  10378. /\b(transform|all)(,|$)/.test(getStyleProperties(`${TRANSITION$1}Property`).toString());
  10379. return {
  10380. type,
  10381. timeout,
  10382. propCount,
  10383. hasTransform
  10384. };
  10385. }
  10386. function getTimeout(delays, durations) {
  10387. while (delays.length < durations.length) {
  10388. delays = delays.concat(delays);
  10389. }
  10390. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10391. }
  10392. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10393. // numbers in a locale-dependent way, using a comma instead of a dot.
  10394. // If comma is not replaced with a dot, the input will be rounded down
  10395. // (i.e. acting as a floor function) causing unexpected behaviors
  10396. function toMs(s) {
  10397. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10398. }
  10399. // synchronously force layout to put elements into a certain state
  10400. function forceReflow() {
  10401. return document.body.offsetHeight;
  10402. }
  10403. const positionMap = new WeakMap();
  10404. const newPositionMap = new WeakMap();
  10405. const TransitionGroupImpl = {
  10406. name: 'TransitionGroup',
  10407. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10408. tag: String,
  10409. moveClass: String
  10410. }),
  10411. setup(props, { slots }) {
  10412. const instance = getCurrentInstance();
  10413. const state = useTransitionState();
  10414. let prevChildren;
  10415. let children;
  10416. onUpdated(() => {
  10417. // children is guaranteed to exist after initial render
  10418. if (!prevChildren.length) {
  10419. return;
  10420. }
  10421. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10422. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10423. return;
  10424. }
  10425. // we divide the work into three loops to avoid mixing DOM reads and writes
  10426. // in each iteration - which helps prevent layout thrashing.
  10427. prevChildren.forEach(callPendingCbs);
  10428. prevChildren.forEach(recordPosition);
  10429. const movedChildren = prevChildren.filter(applyTranslation);
  10430. // force reflow to put everything in position
  10431. forceReflow();
  10432. movedChildren.forEach(c => {
  10433. const el = c.el;
  10434. const style = el.style;
  10435. addTransitionClass(el, moveClass);
  10436. style.transform = style.webkitTransform = style.transitionDuration = '';
  10437. const cb = (el._moveCb = (e) => {
  10438. if (e && e.target !== el) {
  10439. return;
  10440. }
  10441. if (!e || /transform$/.test(e.propertyName)) {
  10442. el.removeEventListener('transitionend', cb);
  10443. el._moveCb = null;
  10444. removeTransitionClass(el, moveClass);
  10445. }
  10446. });
  10447. el.addEventListener('transitionend', cb);
  10448. });
  10449. });
  10450. return () => {
  10451. const rawProps = toRaw(props);
  10452. const cssTransitionProps = resolveTransitionProps(rawProps);
  10453. let tag = rawProps.tag || Fragment;
  10454. prevChildren = children;
  10455. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10456. for (let i = 0; i < children.length; i++) {
  10457. const child = children[i];
  10458. if (child.key != null) {
  10459. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10460. }
  10461. else {
  10462. warn(`<TransitionGroup> children must be keyed.`);
  10463. }
  10464. }
  10465. if (prevChildren) {
  10466. for (let i = 0; i < prevChildren.length; i++) {
  10467. const child = prevChildren[i];
  10468. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10469. positionMap.set(child, child.el.getBoundingClientRect());
  10470. }
  10471. }
  10472. return createVNode(tag, null, children);
  10473. };
  10474. }
  10475. };
  10476. /**
  10477. * TransitionGroup does not support "mode" so we need to remove it from the
  10478. * props declarations, but direct delete operation is considered a side effect
  10479. * and will make the entire transition feature non-tree-shakeable, so we do it
  10480. * in a function and mark the function's invocation as pure.
  10481. */
  10482. const removeMode = (props) => delete props.mode;
  10483. /*#__PURE__*/ removeMode(TransitionGroupImpl.props);
  10484. const TransitionGroup = TransitionGroupImpl;
  10485. function callPendingCbs(c) {
  10486. const el = c.el;
  10487. if (el._moveCb) {
  10488. el._moveCb();
  10489. }
  10490. if (el._enterCb) {
  10491. el._enterCb();
  10492. }
  10493. }
  10494. function recordPosition(c) {
  10495. newPositionMap.set(c, c.el.getBoundingClientRect());
  10496. }
  10497. function applyTranslation(c) {
  10498. const oldPos = positionMap.get(c);
  10499. const newPos = newPositionMap.get(c);
  10500. const dx = oldPos.left - newPos.left;
  10501. const dy = oldPos.top - newPos.top;
  10502. if (dx || dy) {
  10503. const s = c.el.style;
  10504. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10505. s.transitionDuration = '0s';
  10506. return c;
  10507. }
  10508. }
  10509. function hasCSSTransform(el, root, moveClass) {
  10510. // Detect whether an element with the move class applied has
  10511. // CSS transitions. Since the element may be inside an entering
  10512. // transition at this very moment, we make a clone of it and remove
  10513. // all other transition classes applied to ensure only the move class
  10514. // is applied.
  10515. const clone = el.cloneNode();
  10516. if (el._vtc) {
  10517. el._vtc.forEach(cls => {
  10518. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10519. });
  10520. }
  10521. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10522. clone.style.display = 'none';
  10523. const container = (root.nodeType === 1 ? root : root.parentNode);
  10524. container.appendChild(clone);
  10525. const { hasTransform } = getTransitionInfo(clone);
  10526. container.removeChild(clone);
  10527. return hasTransform;
  10528. }
  10529. const getModelAssigner = (vnode) => {
  10530. const fn = vnode.props['onUpdate:modelValue'] ||
  10531. (false );
  10532. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10533. };
  10534. function onCompositionStart(e) {
  10535. e.target.composing = true;
  10536. }
  10537. function onCompositionEnd(e) {
  10538. const target = e.target;
  10539. if (target.composing) {
  10540. target.composing = false;
  10541. target.dispatchEvent(new Event('input'));
  10542. }
  10543. }
  10544. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10545. // be tree-shaken in case v-model is never used.
  10546. const vModelText = {
  10547. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10548. el._assign = getModelAssigner(vnode);
  10549. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10550. addEventListener(el, lazy ? 'change' : 'input', e => {
  10551. if (e.target.composing)
  10552. return;
  10553. let domValue = el.value;
  10554. if (trim) {
  10555. domValue = domValue.trim();
  10556. }
  10557. if (castToNumber) {
  10558. domValue = looseToNumber(domValue);
  10559. }
  10560. el._assign(domValue);
  10561. });
  10562. if (trim) {
  10563. addEventListener(el, 'change', () => {
  10564. el.value = el.value.trim();
  10565. });
  10566. }
  10567. if (!lazy) {
  10568. addEventListener(el, 'compositionstart', onCompositionStart);
  10569. addEventListener(el, 'compositionend', onCompositionEnd);
  10570. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10571. // switching focus before confirming composition choice
  10572. // this also fixes the issue where some browsers e.g. iOS Chrome
  10573. // fires "change" instead of "input" on autocomplete.
  10574. addEventListener(el, 'change', onCompositionEnd);
  10575. }
  10576. },
  10577. // set value on mounted so it's after min/max for type="range"
  10578. mounted(el, { value }) {
  10579. el.value = value == null ? '' : value;
  10580. },
  10581. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10582. el._assign = getModelAssigner(vnode);
  10583. // avoid clearing unresolved text. #2302
  10584. if (el.composing)
  10585. return;
  10586. if (document.activeElement === el && el.type !== 'range') {
  10587. if (lazy) {
  10588. return;
  10589. }
  10590. if (trim && el.value.trim() === value) {
  10591. return;
  10592. }
  10593. if ((number || el.type === 'number') &&
  10594. looseToNumber(el.value) === value) {
  10595. return;
  10596. }
  10597. }
  10598. const newValue = value == null ? '' : value;
  10599. if (el.value !== newValue) {
  10600. el.value = newValue;
  10601. }
  10602. }
  10603. };
  10604. const vModelCheckbox = {
  10605. // #4096 array checkboxes need to be deep traversed
  10606. deep: true,
  10607. created(el, _, vnode) {
  10608. el._assign = getModelAssigner(vnode);
  10609. addEventListener(el, 'change', () => {
  10610. const modelValue = el._modelValue;
  10611. const elementValue = getValue(el);
  10612. const checked = el.checked;
  10613. const assign = el._assign;
  10614. if (isArray(modelValue)) {
  10615. const index = looseIndexOf(modelValue, elementValue);
  10616. const found = index !== -1;
  10617. if (checked && !found) {
  10618. assign(modelValue.concat(elementValue));
  10619. }
  10620. else if (!checked && found) {
  10621. const filtered = [...modelValue];
  10622. filtered.splice(index, 1);
  10623. assign(filtered);
  10624. }
  10625. }
  10626. else if (isSet(modelValue)) {
  10627. const cloned = new Set(modelValue);
  10628. if (checked) {
  10629. cloned.add(elementValue);
  10630. }
  10631. else {
  10632. cloned.delete(elementValue);
  10633. }
  10634. assign(cloned);
  10635. }
  10636. else {
  10637. assign(getCheckboxValue(el, checked));
  10638. }
  10639. });
  10640. },
  10641. // set initial checked on mount to wait for true-value/false-value
  10642. mounted: setChecked,
  10643. beforeUpdate(el, binding, vnode) {
  10644. el._assign = getModelAssigner(vnode);
  10645. setChecked(el, binding, vnode);
  10646. }
  10647. };
  10648. function setChecked(el, { value, oldValue }, vnode) {
  10649. el._modelValue = value;
  10650. if (isArray(value)) {
  10651. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10652. }
  10653. else if (isSet(value)) {
  10654. el.checked = value.has(vnode.props.value);
  10655. }
  10656. else if (value !== oldValue) {
  10657. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10658. }
  10659. }
  10660. const vModelRadio = {
  10661. created(el, { value }, vnode) {
  10662. el.checked = looseEqual(value, vnode.props.value);
  10663. el._assign = getModelAssigner(vnode);
  10664. addEventListener(el, 'change', () => {
  10665. el._assign(getValue(el));
  10666. });
  10667. },
  10668. beforeUpdate(el, { value, oldValue }, vnode) {
  10669. el._assign = getModelAssigner(vnode);
  10670. if (value !== oldValue) {
  10671. el.checked = looseEqual(value, vnode.props.value);
  10672. }
  10673. }
  10674. };
  10675. const vModelSelect = {
  10676. // <select multiple> value need to be deep traversed
  10677. deep: true,
  10678. created(el, { value, modifiers: { number } }, vnode) {
  10679. const isSetModel = isSet(value);
  10680. addEventListener(el, 'change', () => {
  10681. const selectedVal = Array.prototype.filter
  10682. .call(el.options, (o) => o.selected)
  10683. .map((o) => number ? looseToNumber(getValue(o)) : getValue(o));
  10684. el._assign(el.multiple
  10685. ? isSetModel
  10686. ? new Set(selectedVal)
  10687. : selectedVal
  10688. : selectedVal[0]);
  10689. });
  10690. el._assign = getModelAssigner(vnode);
  10691. },
  10692. // set value in mounted & updated because <select> relies on its children
  10693. // <option>s.
  10694. mounted(el, { value }) {
  10695. setSelected(el, value);
  10696. },
  10697. beforeUpdate(el, _binding, vnode) {
  10698. el._assign = getModelAssigner(vnode);
  10699. },
  10700. updated(el, { value }) {
  10701. setSelected(el, value);
  10702. }
  10703. };
  10704. function setSelected(el, value) {
  10705. const isMultiple = el.multiple;
  10706. if (isMultiple && !isArray(value) && !isSet(value)) {
  10707. warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10708. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10709. return;
  10710. }
  10711. for (let i = 0, l = el.options.length; i < l; i++) {
  10712. const option = el.options[i];
  10713. const optionValue = getValue(option);
  10714. if (isMultiple) {
  10715. if (isArray(value)) {
  10716. option.selected = looseIndexOf(value, optionValue) > -1;
  10717. }
  10718. else {
  10719. option.selected = value.has(optionValue);
  10720. }
  10721. }
  10722. else {
  10723. if (looseEqual(getValue(option), value)) {
  10724. if (el.selectedIndex !== i)
  10725. el.selectedIndex = i;
  10726. return;
  10727. }
  10728. }
  10729. }
  10730. if (!isMultiple && el.selectedIndex !== -1) {
  10731. el.selectedIndex = -1;
  10732. }
  10733. }
  10734. // retrieve raw value set via :value bindings
  10735. function getValue(el) {
  10736. return '_value' in el ? el._value : el.value;
  10737. }
  10738. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10739. function getCheckboxValue(el, checked) {
  10740. const key = checked ? '_trueValue' : '_falseValue';
  10741. return key in el ? el[key] : checked;
  10742. }
  10743. const vModelDynamic = {
  10744. created(el, binding, vnode) {
  10745. callModelHook(el, binding, vnode, null, 'created');
  10746. },
  10747. mounted(el, binding, vnode) {
  10748. callModelHook(el, binding, vnode, null, 'mounted');
  10749. },
  10750. beforeUpdate(el, binding, vnode, prevVNode) {
  10751. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10752. },
  10753. updated(el, binding, vnode, prevVNode) {
  10754. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10755. }
  10756. };
  10757. function resolveDynamicModel(tagName, type) {
  10758. switch (tagName) {
  10759. case 'SELECT':
  10760. return vModelSelect;
  10761. case 'TEXTAREA':
  10762. return vModelText;
  10763. default:
  10764. switch (type) {
  10765. case 'checkbox':
  10766. return vModelCheckbox;
  10767. case 'radio':
  10768. return vModelRadio;
  10769. default:
  10770. return vModelText;
  10771. }
  10772. }
  10773. }
  10774. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10775. const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
  10776. const fn = modelToUse[hook];
  10777. fn && fn(el, binding, vnode, prevVNode);
  10778. }
  10779. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10780. const modifierGuards = {
  10781. stop: e => e.stopPropagation(),
  10782. prevent: e => e.preventDefault(),
  10783. self: e => e.target !== e.currentTarget,
  10784. ctrl: e => !e.ctrlKey,
  10785. shift: e => !e.shiftKey,
  10786. alt: e => !e.altKey,
  10787. meta: e => !e.metaKey,
  10788. left: e => 'button' in e && e.button !== 0,
  10789. middle: e => 'button' in e && e.button !== 1,
  10790. right: e => 'button' in e && e.button !== 2,
  10791. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10792. };
  10793. /**
  10794. * @private
  10795. */
  10796. const withModifiers = (fn, modifiers) => {
  10797. return (event, ...args) => {
  10798. for (let i = 0; i < modifiers.length; i++) {
  10799. const guard = modifierGuards[modifiers[i]];
  10800. if (guard && guard(event, modifiers))
  10801. return;
  10802. }
  10803. return fn(event, ...args);
  10804. };
  10805. };
  10806. // Kept for 2.x compat.
  10807. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10808. const keyNames = {
  10809. esc: 'escape',
  10810. space: ' ',
  10811. up: 'arrow-up',
  10812. left: 'arrow-left',
  10813. right: 'arrow-right',
  10814. down: 'arrow-down',
  10815. delete: 'backspace'
  10816. };
  10817. /**
  10818. * @private
  10819. */
  10820. const withKeys = (fn, modifiers) => {
  10821. return (event) => {
  10822. if (!('key' in event)) {
  10823. return;
  10824. }
  10825. const eventKey = hyphenate(event.key);
  10826. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10827. return fn(event);
  10828. }
  10829. };
  10830. };
  10831. const vShow = {
  10832. beforeMount(el, { value }, { transition }) {
  10833. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10834. if (transition && value) {
  10835. transition.beforeEnter(el);
  10836. }
  10837. else {
  10838. setDisplay(el, value);
  10839. }
  10840. },
  10841. mounted(el, { value }, { transition }) {
  10842. if (transition && value) {
  10843. transition.enter(el);
  10844. }
  10845. },
  10846. updated(el, { value, oldValue }, { transition }) {
  10847. if (!value === !oldValue)
  10848. return;
  10849. if (transition) {
  10850. if (value) {
  10851. transition.beforeEnter(el);
  10852. setDisplay(el, true);
  10853. transition.enter(el);
  10854. }
  10855. else {
  10856. transition.leave(el, () => {
  10857. setDisplay(el, false);
  10858. });
  10859. }
  10860. }
  10861. else {
  10862. setDisplay(el, value);
  10863. }
  10864. },
  10865. beforeUnmount(el, { value }) {
  10866. setDisplay(el, value);
  10867. }
  10868. };
  10869. function setDisplay(el, value) {
  10870. el.style.display = value ? el._vod : 'none';
  10871. }
  10872. const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
  10873. // lazy create the renderer - this makes core renderer logic tree-shakable
  10874. // in case the user only imports reactivity utilities from Vue.
  10875. let renderer;
  10876. let enabledHydration = false;
  10877. function ensureRenderer() {
  10878. return (renderer ||
  10879. (renderer = createRenderer(rendererOptions)));
  10880. }
  10881. function ensureHydrationRenderer() {
  10882. renderer = enabledHydration
  10883. ? renderer
  10884. : createHydrationRenderer(rendererOptions);
  10885. enabledHydration = true;
  10886. return renderer;
  10887. }
  10888. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10889. const render = ((...args) => {
  10890. ensureRenderer().render(...args);
  10891. });
  10892. const hydrate = ((...args) => {
  10893. ensureHydrationRenderer().hydrate(...args);
  10894. });
  10895. const createApp = ((...args) => {
  10896. const app = ensureRenderer().createApp(...args);
  10897. {
  10898. injectNativeTagCheck(app);
  10899. injectCompilerOptionsCheck(app);
  10900. }
  10901. const { mount } = app;
  10902. app.mount = (containerOrSelector) => {
  10903. const container = normalizeContainer(containerOrSelector);
  10904. if (!container)
  10905. return;
  10906. const component = app._component;
  10907. if (!isFunction(component) && !component.render && !component.template) {
  10908. // __UNSAFE__
  10909. // Reason: potential execution of JS expressions in in-DOM template.
  10910. // The user must make sure the in-DOM template is trusted. If it's
  10911. // rendered by the server, the template should not contain any user data.
  10912. component.template = container.innerHTML;
  10913. }
  10914. // clear content before mounting
  10915. container.innerHTML = '';
  10916. const proxy = mount(container, false, container instanceof SVGElement);
  10917. if (container instanceof Element) {
  10918. container.removeAttribute('v-cloak');
  10919. container.setAttribute('data-v-app', '');
  10920. }
  10921. return proxy;
  10922. };
  10923. return app;
  10924. });
  10925. const createSSRApp = ((...args) => {
  10926. const app = ensureHydrationRenderer().createApp(...args);
  10927. {
  10928. injectNativeTagCheck(app);
  10929. injectCompilerOptionsCheck(app);
  10930. }
  10931. const { mount } = app;
  10932. app.mount = (containerOrSelector) => {
  10933. const container = normalizeContainer(containerOrSelector);
  10934. if (container) {
  10935. return mount(container, true, container instanceof SVGElement);
  10936. }
  10937. };
  10938. return app;
  10939. });
  10940. function injectNativeTagCheck(app) {
  10941. // Inject `isNativeTag`
  10942. // this is used for component name validation (dev only)
  10943. Object.defineProperty(app.config, 'isNativeTag', {
  10944. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10945. writable: false
  10946. });
  10947. }
  10948. // dev only
  10949. function injectCompilerOptionsCheck(app) {
  10950. if (isRuntimeOnly()) {
  10951. const isCustomElement = app.config.isCustomElement;
  10952. Object.defineProperty(app.config, 'isCustomElement', {
  10953. get() {
  10954. return isCustomElement;
  10955. },
  10956. set() {
  10957. warn(`The \`isCustomElement\` config option is deprecated. Use ` +
  10958. `\`compilerOptions.isCustomElement\` instead.`);
  10959. }
  10960. });
  10961. const compilerOptions = app.config.compilerOptions;
  10962. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10963. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10964. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10965. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10966. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10967. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10968. `- 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`;
  10969. Object.defineProperty(app.config, 'compilerOptions', {
  10970. get() {
  10971. warn(msg);
  10972. return compilerOptions;
  10973. },
  10974. set() {
  10975. warn(msg);
  10976. }
  10977. });
  10978. }
  10979. }
  10980. function normalizeContainer(container) {
  10981. if (isString(container)) {
  10982. const res = document.querySelector(container);
  10983. if (!res) {
  10984. warn(`Failed to mount app: mount target selector "${container}" returned null.`);
  10985. }
  10986. return res;
  10987. }
  10988. if (window.ShadowRoot &&
  10989. container instanceof window.ShadowRoot &&
  10990. container.mode === 'closed') {
  10991. warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10992. }
  10993. return container;
  10994. }
  10995. /**
  10996. * @internal
  10997. */
  10998. const initDirectivesForSSR = NOOP;
  10999. function initDev() {
  11000. {
  11001. /* istanbul ignore if */
  11002. {
  11003. console.info(`You are running a development build of Vue.\n` +
  11004. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  11005. }
  11006. initCustomFormatter();
  11007. }
  11008. }
  11009. function defaultOnError(error) {
  11010. throw error;
  11011. }
  11012. function defaultOnWarn(msg) {
  11013. console.warn(`[Vue warn] ${msg.message}`);
  11014. }
  11015. function createCompilerError(code, loc, messages, additionalMessage) {
  11016. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  11017. ;
  11018. const error = new SyntaxError(String(msg));
  11019. error.code = code;
  11020. error.loc = loc;
  11021. return error;
  11022. }
  11023. const errorMessages = {
  11024. // parse errors
  11025. [0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  11026. [1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  11027. [2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  11028. [3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  11029. [4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  11030. [5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  11031. [6 /* ErrorCodes.EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  11032. [7 /* ErrorCodes.EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  11033. [8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  11034. [9 /* ErrorCodes.EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  11035. [10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  11036. [11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  11037. [12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  11038. [13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  11039. [14 /* ErrorCodes.MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  11040. [15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  11041. [16 /* ErrorCodes.NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  11042. [17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  11043. [18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  11044. [19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  11045. [21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  11046. [20 /* ErrorCodes.UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  11047. [22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  11048. // Vue-specific parse errors
  11049. [23 /* ErrorCodes.X_INVALID_END_TAG */]: 'Invalid end tag.',
  11050. [24 /* ErrorCodes.X_MISSING_END_TAG */]: 'Element is missing end tag.',
  11051. [25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  11052. [27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  11053. 'Note that dynamic directive argument cannot contain spaces.',
  11054. [26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  11055. // transform errors
  11056. [28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  11057. [29 /* ErrorCodes.X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  11058. [30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  11059. [31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  11060. [32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  11061. [33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  11062. [34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  11063. [35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  11064. [36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  11065. [37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>. ` +
  11066. `When there are multiple named slots, all slots should use <template> ` +
  11067. `syntax to avoid scope ambiguity.`,
  11068. [38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  11069. [39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  11070. `default slot. These children will be ignored.`,
  11071. [40 /* ErrorCodes.X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  11072. [41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  11073. [42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  11074. [43 /* ErrorCodes.X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  11075. [44 /* ErrorCodes.X_V_MODEL_ON_PROPS */]: `v-model cannot be used on a prop, because local prop bindings are not writable.\nUse a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  11076. [45 /* ErrorCodes.X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  11077. [46 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  11078. // generic errors
  11079. [47 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  11080. [48 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  11081. [49 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  11082. [50 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  11083. // just to fulfill types
  11084. [51 /* ErrorCodes.__EXTEND_POINT__ */]: ``
  11085. };
  11086. const FRAGMENT = Symbol(`Fragment` );
  11087. const TELEPORT = Symbol(`Teleport` );
  11088. const SUSPENSE = Symbol(`Suspense` );
  11089. const KEEP_ALIVE = Symbol(`KeepAlive` );
  11090. const BASE_TRANSITION = Symbol(`BaseTransition` );
  11091. const OPEN_BLOCK = Symbol(`openBlock` );
  11092. const CREATE_BLOCK = Symbol(`createBlock` );
  11093. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  11094. const CREATE_VNODE = Symbol(`createVNode` );
  11095. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  11096. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  11097. const CREATE_TEXT = Symbol(`createTextVNode` );
  11098. const CREATE_STATIC = Symbol(`createStaticVNode` );
  11099. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  11100. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  11101. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  11102. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  11103. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  11104. const RENDER_LIST = Symbol(`renderList` );
  11105. const RENDER_SLOT = Symbol(`renderSlot` );
  11106. const CREATE_SLOTS = Symbol(`createSlots` );
  11107. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  11108. const MERGE_PROPS = Symbol(`mergeProps` );
  11109. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  11110. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  11111. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  11112. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  11113. const TO_HANDLERS = Symbol(`toHandlers` );
  11114. const CAMELIZE = Symbol(`camelize` );
  11115. const CAPITALIZE = Symbol(`capitalize` );
  11116. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  11117. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  11118. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  11119. const POP_SCOPE_ID = Symbol(`popScopeId` );
  11120. const WITH_CTX = Symbol(`withCtx` );
  11121. const UNREF = Symbol(`unref` );
  11122. const IS_REF = Symbol(`isRef` );
  11123. const WITH_MEMO = Symbol(`withMemo` );
  11124. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  11125. // Name mapping for runtime helpers that need to be imported from 'vue' in
  11126. // generated code. Make sure these are correctly exported in the runtime!
  11127. const helperNameMap = {
  11128. [FRAGMENT]: `Fragment`,
  11129. [TELEPORT]: `Teleport`,
  11130. [SUSPENSE]: `Suspense`,
  11131. [KEEP_ALIVE]: `KeepAlive`,
  11132. [BASE_TRANSITION]: `BaseTransition`,
  11133. [OPEN_BLOCK]: `openBlock`,
  11134. [CREATE_BLOCK]: `createBlock`,
  11135. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  11136. [CREATE_VNODE]: `createVNode`,
  11137. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  11138. [CREATE_COMMENT]: `createCommentVNode`,
  11139. [CREATE_TEXT]: `createTextVNode`,
  11140. [CREATE_STATIC]: `createStaticVNode`,
  11141. [RESOLVE_COMPONENT]: `resolveComponent`,
  11142. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  11143. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  11144. [RESOLVE_FILTER]: `resolveFilter`,
  11145. [WITH_DIRECTIVES]: `withDirectives`,
  11146. [RENDER_LIST]: `renderList`,
  11147. [RENDER_SLOT]: `renderSlot`,
  11148. [CREATE_SLOTS]: `createSlots`,
  11149. [TO_DISPLAY_STRING]: `toDisplayString`,
  11150. [MERGE_PROPS]: `mergeProps`,
  11151. [NORMALIZE_CLASS]: `normalizeClass`,
  11152. [NORMALIZE_STYLE]: `normalizeStyle`,
  11153. [NORMALIZE_PROPS]: `normalizeProps`,
  11154. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  11155. [TO_HANDLERS]: `toHandlers`,
  11156. [CAMELIZE]: `camelize`,
  11157. [CAPITALIZE]: `capitalize`,
  11158. [TO_HANDLER_KEY]: `toHandlerKey`,
  11159. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  11160. [PUSH_SCOPE_ID]: `pushScopeId`,
  11161. [POP_SCOPE_ID]: `popScopeId`,
  11162. [WITH_CTX]: `withCtx`,
  11163. [UNREF]: `unref`,
  11164. [IS_REF]: `isRef`,
  11165. [WITH_MEMO]: `withMemo`,
  11166. [IS_MEMO_SAME]: `isMemoSame`
  11167. };
  11168. function registerRuntimeHelpers(helpers) {
  11169. Object.getOwnPropertySymbols(helpers).forEach(s => {
  11170. helperNameMap[s] = helpers[s];
  11171. });
  11172. }
  11173. // AST Utilities ---------------------------------------------------------------
  11174. // Some expressions, e.g. sequence and conditional expressions, are never
  11175. // associated with template nodes, so their source locations are just a stub.
  11176. // Container types like CompoundExpression also don't need a real location.
  11177. const locStub = {
  11178. source: '',
  11179. start: { line: 1, column: 1, offset: 0 },
  11180. end: { line: 1, column: 1, offset: 0 }
  11181. };
  11182. function createRoot(children, loc = locStub) {
  11183. return {
  11184. type: 0 /* NodeTypes.ROOT */,
  11185. children,
  11186. helpers: new Set(),
  11187. components: [],
  11188. directives: [],
  11189. hoists: [],
  11190. imports: [],
  11191. cached: 0,
  11192. temps: 0,
  11193. codegenNode: undefined,
  11194. loc
  11195. };
  11196. }
  11197. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  11198. if (context) {
  11199. if (isBlock) {
  11200. context.helper(OPEN_BLOCK);
  11201. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  11202. }
  11203. else {
  11204. context.helper(getVNodeHelper(context.inSSR, isComponent));
  11205. }
  11206. if (directives) {
  11207. context.helper(WITH_DIRECTIVES);
  11208. }
  11209. }
  11210. return {
  11211. type: 13 /* NodeTypes.VNODE_CALL */,
  11212. tag,
  11213. props,
  11214. children,
  11215. patchFlag,
  11216. dynamicProps,
  11217. directives,
  11218. isBlock,
  11219. disableTracking,
  11220. isComponent,
  11221. loc
  11222. };
  11223. }
  11224. function createArrayExpression(elements, loc = locStub) {
  11225. return {
  11226. type: 17 /* NodeTypes.JS_ARRAY_EXPRESSION */,
  11227. loc,
  11228. elements
  11229. };
  11230. }
  11231. function createObjectExpression(properties, loc = locStub) {
  11232. return {
  11233. type: 15 /* NodeTypes.JS_OBJECT_EXPRESSION */,
  11234. loc,
  11235. properties
  11236. };
  11237. }
  11238. function createObjectProperty(key, value) {
  11239. return {
  11240. type: 16 /* NodeTypes.JS_PROPERTY */,
  11241. loc: locStub,
  11242. key: isString(key) ? createSimpleExpression(key, true) : key,
  11243. value
  11244. };
  11245. }
  11246. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* ConstantTypes.NOT_CONSTANT */) {
  11247. return {
  11248. type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
  11249. loc,
  11250. content,
  11251. isStatic,
  11252. constType: isStatic ? 3 /* ConstantTypes.CAN_STRINGIFY */ : constType
  11253. };
  11254. }
  11255. function createCompoundExpression(children, loc = locStub) {
  11256. return {
  11257. type: 8 /* NodeTypes.COMPOUND_EXPRESSION */,
  11258. loc,
  11259. children
  11260. };
  11261. }
  11262. function createCallExpression(callee, args = [], loc = locStub) {
  11263. return {
  11264. type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
  11265. loc,
  11266. callee,
  11267. arguments: args
  11268. };
  11269. }
  11270. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  11271. return {
  11272. type: 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */,
  11273. params,
  11274. returns,
  11275. newline,
  11276. isSlot,
  11277. loc
  11278. };
  11279. }
  11280. function createConditionalExpression(test, consequent, alternate, newline = true) {
  11281. return {
  11282. type: 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */,
  11283. test,
  11284. consequent,
  11285. alternate,
  11286. newline,
  11287. loc: locStub
  11288. };
  11289. }
  11290. function createCacheExpression(index, value, isVNode = false) {
  11291. return {
  11292. type: 20 /* NodeTypes.JS_CACHE_EXPRESSION */,
  11293. index,
  11294. value,
  11295. isVNode,
  11296. loc: locStub
  11297. };
  11298. }
  11299. function createBlockStatement(body) {
  11300. return {
  11301. type: 21 /* NodeTypes.JS_BLOCK_STATEMENT */,
  11302. body,
  11303. loc: locStub
  11304. };
  11305. }
  11306. const isStaticExp = (p) => p.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && p.isStatic;
  11307. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  11308. function isCoreComponent(tag) {
  11309. if (isBuiltInType(tag, 'Teleport')) {
  11310. return TELEPORT;
  11311. }
  11312. else if (isBuiltInType(tag, 'Suspense')) {
  11313. return SUSPENSE;
  11314. }
  11315. else if (isBuiltInType(tag, 'KeepAlive')) {
  11316. return KEEP_ALIVE;
  11317. }
  11318. else if (isBuiltInType(tag, 'BaseTransition')) {
  11319. return BASE_TRANSITION;
  11320. }
  11321. }
  11322. const nonIdentifierRE = /^\d|[^\$\w]/;
  11323. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  11324. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  11325. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  11326. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  11327. /**
  11328. * Simple lexer to check if an expression is a member expression. This is
  11329. * lax and only checks validity at the root level (i.e. does not validate exps
  11330. * inside square brackets), but it's ok since these are only used on template
  11331. * expressions and false positives are invalid expressions in the first place.
  11332. */
  11333. const isMemberExpressionBrowser = (path) => {
  11334. // remove whitespaces around . or [ first
  11335. path = path.trim().replace(whitespaceRE, s => s.trim());
  11336. let state = 0 /* MemberExpLexState.inMemberExp */;
  11337. let stateStack = [];
  11338. let currentOpenBracketCount = 0;
  11339. let currentOpenParensCount = 0;
  11340. let currentStringType = null;
  11341. for (let i = 0; i < path.length; i++) {
  11342. const char = path.charAt(i);
  11343. switch (state) {
  11344. case 0 /* MemberExpLexState.inMemberExp */:
  11345. if (char === '[') {
  11346. stateStack.push(state);
  11347. state = 1 /* MemberExpLexState.inBrackets */;
  11348. currentOpenBracketCount++;
  11349. }
  11350. else if (char === '(') {
  11351. stateStack.push(state);
  11352. state = 2 /* MemberExpLexState.inParens */;
  11353. currentOpenParensCount++;
  11354. }
  11355. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  11356. return false;
  11357. }
  11358. break;
  11359. case 1 /* MemberExpLexState.inBrackets */:
  11360. if (char === `'` || char === `"` || char === '`') {
  11361. stateStack.push(state);
  11362. state = 3 /* MemberExpLexState.inString */;
  11363. currentStringType = char;
  11364. }
  11365. else if (char === `[`) {
  11366. currentOpenBracketCount++;
  11367. }
  11368. else if (char === `]`) {
  11369. if (!--currentOpenBracketCount) {
  11370. state = stateStack.pop();
  11371. }
  11372. }
  11373. break;
  11374. case 2 /* MemberExpLexState.inParens */:
  11375. if (char === `'` || char === `"` || char === '`') {
  11376. stateStack.push(state);
  11377. state = 3 /* MemberExpLexState.inString */;
  11378. currentStringType = char;
  11379. }
  11380. else if (char === `(`) {
  11381. currentOpenParensCount++;
  11382. }
  11383. else if (char === `)`) {
  11384. // if the exp ends as a call then it should not be considered valid
  11385. if (i === path.length - 1) {
  11386. return false;
  11387. }
  11388. if (!--currentOpenParensCount) {
  11389. state = stateStack.pop();
  11390. }
  11391. }
  11392. break;
  11393. case 3 /* MemberExpLexState.inString */:
  11394. if (char === currentStringType) {
  11395. state = stateStack.pop();
  11396. currentStringType = null;
  11397. }
  11398. break;
  11399. }
  11400. }
  11401. return !currentOpenBracketCount && !currentOpenParensCount;
  11402. };
  11403. const isMemberExpression = isMemberExpressionBrowser
  11404. ;
  11405. function getInnerRange(loc, offset, length) {
  11406. const source = loc.source.slice(offset, offset + length);
  11407. const newLoc = {
  11408. source,
  11409. start: advancePositionWithClone(loc.start, loc.source, offset),
  11410. end: loc.end
  11411. };
  11412. if (length != null) {
  11413. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  11414. }
  11415. return newLoc;
  11416. }
  11417. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  11418. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  11419. }
  11420. // advance by mutation without cloning (for performance reasons), since this
  11421. // gets called a lot in the parser
  11422. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  11423. let linesCount = 0;
  11424. let lastNewLinePos = -1;
  11425. for (let i = 0; i < numberOfCharacters; i++) {
  11426. if (source.charCodeAt(i) === 10 /* newline char code */) {
  11427. linesCount++;
  11428. lastNewLinePos = i;
  11429. }
  11430. }
  11431. pos.offset += numberOfCharacters;
  11432. pos.line += linesCount;
  11433. pos.column =
  11434. lastNewLinePos === -1
  11435. ? pos.column + numberOfCharacters
  11436. : numberOfCharacters - lastNewLinePos;
  11437. return pos;
  11438. }
  11439. function assert(condition, msg) {
  11440. /* istanbul ignore if */
  11441. if (!condition) {
  11442. throw new Error(msg || `unexpected compiler condition`);
  11443. }
  11444. }
  11445. function findDir(node, name, allowEmpty = false) {
  11446. for (let i = 0; i < node.props.length; i++) {
  11447. const p = node.props[i];
  11448. if (p.type === 7 /* NodeTypes.DIRECTIVE */ &&
  11449. (allowEmpty || p.exp) &&
  11450. (isString(name) ? p.name === name : name.test(p.name))) {
  11451. return p;
  11452. }
  11453. }
  11454. }
  11455. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  11456. for (let i = 0; i < node.props.length; i++) {
  11457. const p = node.props[i];
  11458. if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
  11459. if (dynamicOnly)
  11460. continue;
  11461. if (p.name === name && (p.value || allowEmpty)) {
  11462. return p;
  11463. }
  11464. }
  11465. else if (p.name === 'bind' &&
  11466. (p.exp || allowEmpty) &&
  11467. isStaticArgOf(p.arg, name)) {
  11468. return p;
  11469. }
  11470. }
  11471. }
  11472. function isStaticArgOf(arg, name) {
  11473. return !!(arg && isStaticExp(arg) && arg.content === name);
  11474. }
  11475. function hasDynamicKeyVBind(node) {
  11476. return node.props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
  11477. p.name === 'bind' &&
  11478. (!p.arg || // v-bind="obj"
  11479. p.arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  11480. !p.arg.isStatic) // v-bind:[foo]
  11481. );
  11482. }
  11483. function isText$1(node) {
  11484. return node.type === 5 /* NodeTypes.INTERPOLATION */ || node.type === 2 /* NodeTypes.TEXT */;
  11485. }
  11486. function isVSlot(p) {
  11487. return p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'slot';
  11488. }
  11489. function isTemplateNode(node) {
  11490. return (node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 3 /* ElementTypes.TEMPLATE */);
  11491. }
  11492. function isSlotOutlet(node) {
  11493. return node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 2 /* ElementTypes.SLOT */;
  11494. }
  11495. function getVNodeHelper(ssr, isComponent) {
  11496. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  11497. }
  11498. function getVNodeBlockHelper(ssr, isComponent) {
  11499. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  11500. }
  11501. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  11502. function getUnnormalizedProps(props, callPath = []) {
  11503. if (props &&
  11504. !isString(props) &&
  11505. props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  11506. const callee = props.callee;
  11507. if (!isString(callee) && propsHelperSet.has(callee)) {
  11508. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  11509. }
  11510. }
  11511. return [props, callPath];
  11512. }
  11513. function injectProp(node, prop, context) {
  11514. let propsWithInjection;
  11515. /**
  11516. * 1. mergeProps(...)
  11517. * 2. toHandlers(...)
  11518. * 3. normalizeProps(...)
  11519. * 4. normalizeProps(guardReactiveProps(...))
  11520. *
  11521. * we need to get the real props before normalization
  11522. */
  11523. let props = node.type === 13 /* NodeTypes.VNODE_CALL */ ? node.props : node.arguments[2];
  11524. let callPath = [];
  11525. let parentCall;
  11526. if (props &&
  11527. !isString(props) &&
  11528. props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  11529. const ret = getUnnormalizedProps(props);
  11530. props = ret[0];
  11531. callPath = ret[1];
  11532. parentCall = callPath[callPath.length - 1];
  11533. }
  11534. if (props == null || isString(props)) {
  11535. propsWithInjection = createObjectExpression([prop]);
  11536. }
  11537. else if (props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  11538. // merged props... add ours
  11539. // only inject key to object literal if it's the first argument so that
  11540. // if doesn't override user provided keys
  11541. const first = props.arguments[0];
  11542. if (!isString(first) && first.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
  11543. // #6631
  11544. if (!hasProp(prop, first)) {
  11545. first.properties.unshift(prop);
  11546. }
  11547. }
  11548. else {
  11549. if (props.callee === TO_HANDLERS) {
  11550. // #2366
  11551. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11552. createObjectExpression([prop]),
  11553. props
  11554. ]);
  11555. }
  11556. else {
  11557. props.arguments.unshift(createObjectExpression([prop]));
  11558. }
  11559. }
  11560. !propsWithInjection && (propsWithInjection = props);
  11561. }
  11562. else if (props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
  11563. if (!hasProp(prop, props)) {
  11564. props.properties.unshift(prop);
  11565. }
  11566. propsWithInjection = props;
  11567. }
  11568. else {
  11569. // single v-bind with expression, return a merged replacement
  11570. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11571. createObjectExpression([prop]),
  11572. props
  11573. ]);
  11574. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  11575. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  11576. // the `guardReactiveProps` will no longer be needed
  11577. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  11578. parentCall = callPath[callPath.length - 2];
  11579. }
  11580. }
  11581. if (node.type === 13 /* NodeTypes.VNODE_CALL */) {
  11582. if (parentCall) {
  11583. parentCall.arguments[0] = propsWithInjection;
  11584. }
  11585. else {
  11586. node.props = propsWithInjection;
  11587. }
  11588. }
  11589. else {
  11590. if (parentCall) {
  11591. parentCall.arguments[0] = propsWithInjection;
  11592. }
  11593. else {
  11594. node.arguments[2] = propsWithInjection;
  11595. }
  11596. }
  11597. }
  11598. // check existing key to avoid overriding user provided keys
  11599. function hasProp(prop, props) {
  11600. let result = false;
  11601. if (prop.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  11602. const propKeyName = prop.key.content;
  11603. result = props.properties.some(p => p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  11604. p.key.content === propKeyName);
  11605. }
  11606. return result;
  11607. }
  11608. function toValidAssetId(name, type) {
  11609. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  11610. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  11611. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  11612. })}`;
  11613. }
  11614. function getMemoedVNodeCall(node) {
  11615. if (node.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  11616. return node.arguments[1].returns;
  11617. }
  11618. else {
  11619. return node;
  11620. }
  11621. }
  11622. function makeBlock(node, { helper, removeHelper, inSSR }) {
  11623. if (!node.isBlock) {
  11624. node.isBlock = true;
  11625. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  11626. helper(OPEN_BLOCK);
  11627. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  11628. }
  11629. }
  11630. const deprecationData = {
  11631. ["COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */]: {
  11632. message: `Platform-native elements with "is" prop will no longer be ` +
  11633. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  11634. `prefixed with "vue:".`,
  11635. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  11636. },
  11637. ["COMPILER_V_BIND_SYNC" /* CompilerDeprecationTypes.COMPILER_V_BIND_SYNC */]: {
  11638. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  11639. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  11640. `\`v-model:${key}\`.`,
  11641. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  11642. },
  11643. ["COMPILER_V_BIND_PROP" /* CompilerDeprecationTypes.COMPILER_V_BIND_PROP */]: {
  11644. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  11645. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  11646. },
  11647. ["COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */]: {
  11648. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  11649. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  11650. `that appears before v-bind in the case of conflict. ` +
  11651. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  11652. `You can also suppress this warning if the usage is intended.`,
  11653. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  11654. },
  11655. ["COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */]: {
  11656. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  11657. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  11658. },
  11659. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  11660. message: `v-if / v-for precedence when used on the same element has changed ` +
  11661. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  11662. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  11663. `with <template> tags or use a computed property that filters v-for ` +
  11664. `data source.`,
  11665. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  11666. },
  11667. ["COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */]: {
  11668. message: `<template> with no special directives will render as a native template ` +
  11669. `element instead of its inner content in Vue 3.`
  11670. },
  11671. ["COMPILER_INLINE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE */]: {
  11672. message: `"inline-template" has been removed in Vue 3.`,
  11673. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  11674. },
  11675. ["COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */]: {
  11676. message: `filters have been removed in Vue 3. ` +
  11677. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  11678. `Use method calls or computed properties instead.`,
  11679. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  11680. }
  11681. };
  11682. function getCompatValue(key, context) {
  11683. const config = context.options
  11684. ? context.options.compatConfig
  11685. : context.compatConfig;
  11686. const value = config && config[key];
  11687. if (key === 'MODE') {
  11688. return value || 3; // compiler defaults to v3 behavior
  11689. }
  11690. else {
  11691. return value;
  11692. }
  11693. }
  11694. function isCompatEnabled(key, context) {
  11695. const mode = getCompatValue('MODE', context);
  11696. const value = getCompatValue(key, context);
  11697. // in v3 mode, only enable if explicitly set to true
  11698. // otherwise enable for any non-false value
  11699. return mode === 3 ? value === true : value !== false;
  11700. }
  11701. function checkCompatEnabled(key, context, loc, ...args) {
  11702. const enabled = isCompatEnabled(key, context);
  11703. if (enabled) {
  11704. warnDeprecation(key, context, loc, ...args);
  11705. }
  11706. return enabled;
  11707. }
  11708. function warnDeprecation(key, context, loc, ...args) {
  11709. const val = getCompatValue(key, context);
  11710. if (val === 'suppress-warning') {
  11711. return;
  11712. }
  11713. const { message, link } = deprecationData[key];
  11714. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  11715. const err = new SyntaxError(msg);
  11716. err.code = key;
  11717. if (loc)
  11718. err.loc = loc;
  11719. context.onWarn(err);
  11720. }
  11721. // The default decoder only provides escapes for characters reserved as part of
  11722. // the template syntax, and is only used if the custom renderer did not provide
  11723. // a platform-specific decoder.
  11724. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  11725. const decodeMap = {
  11726. gt: '>',
  11727. lt: '<',
  11728. amp: '&',
  11729. apos: "'",
  11730. quot: '"'
  11731. };
  11732. const defaultParserOptions = {
  11733. delimiters: [`{{`, `}}`],
  11734. getNamespace: () => 0 /* Namespaces.HTML */,
  11735. getTextMode: () => 0 /* TextModes.DATA */,
  11736. isVoidTag: NO,
  11737. isPreTag: NO,
  11738. isCustomElement: NO,
  11739. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  11740. onError: defaultOnError,
  11741. onWarn: defaultOnWarn,
  11742. comments: true
  11743. };
  11744. function baseParse(content, options = {}) {
  11745. const context = createParserContext(content, options);
  11746. const start = getCursor(context);
  11747. return createRoot(parseChildren(context, 0 /* TextModes.DATA */, []), getSelection(context, start));
  11748. }
  11749. function createParserContext(content, rawOptions) {
  11750. const options = extend({}, defaultParserOptions);
  11751. let key;
  11752. for (key in rawOptions) {
  11753. // @ts-ignore
  11754. options[key] =
  11755. rawOptions[key] === undefined
  11756. ? defaultParserOptions[key]
  11757. : rawOptions[key];
  11758. }
  11759. return {
  11760. options,
  11761. column: 1,
  11762. line: 1,
  11763. offset: 0,
  11764. originalSource: content,
  11765. source: content,
  11766. inPre: false,
  11767. inVPre: false,
  11768. onWarn: options.onWarn
  11769. };
  11770. }
  11771. function parseChildren(context, mode, ancestors) {
  11772. const parent = last(ancestors);
  11773. const ns = parent ? parent.ns : 0 /* Namespaces.HTML */;
  11774. const nodes = [];
  11775. while (!isEnd(context, mode, ancestors)) {
  11776. const s = context.source;
  11777. let node = undefined;
  11778. if (mode === 0 /* TextModes.DATA */ || mode === 1 /* TextModes.RCDATA */) {
  11779. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  11780. // '{{'
  11781. node = parseInterpolation(context, mode);
  11782. }
  11783. else if (mode === 0 /* TextModes.DATA */ && s[0] === '<') {
  11784. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  11785. if (s.length === 1) {
  11786. emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 1);
  11787. }
  11788. else if (s[1] === '!') {
  11789. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  11790. if (startsWith(s, '<!--')) {
  11791. node = parseComment(context);
  11792. }
  11793. else if (startsWith(s, '<!DOCTYPE')) {
  11794. // Ignore DOCTYPE by a limitation.
  11795. node = parseBogusComment(context);
  11796. }
  11797. else if (startsWith(s, '<![CDATA[')) {
  11798. if (ns !== 0 /* Namespaces.HTML */) {
  11799. node = parseCDATA(context, ancestors);
  11800. }
  11801. else {
  11802. emitError(context, 1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */);
  11803. node = parseBogusComment(context);
  11804. }
  11805. }
  11806. else {
  11807. emitError(context, 11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */);
  11808. node = parseBogusComment(context);
  11809. }
  11810. }
  11811. else if (s[1] === '/') {
  11812. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  11813. if (s.length === 2) {
  11814. emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 2);
  11815. }
  11816. else if (s[2] === '>') {
  11817. emitError(context, 14 /* ErrorCodes.MISSING_END_TAG_NAME */, 2);
  11818. advanceBy(context, 3);
  11819. continue;
  11820. }
  11821. else if (/[a-z]/i.test(s[2])) {
  11822. emitError(context, 23 /* ErrorCodes.X_INVALID_END_TAG */);
  11823. parseTag(context, 1 /* TagType.End */, parent);
  11824. continue;
  11825. }
  11826. else {
  11827. emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  11828. node = parseBogusComment(context);
  11829. }
  11830. }
  11831. else if (/[a-z]/i.test(s[1])) {
  11832. node = parseElement(context, ancestors);
  11833. }
  11834. else if (s[1] === '?') {
  11835. emitError(context, 21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  11836. node = parseBogusComment(context);
  11837. }
  11838. else {
  11839. emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  11840. }
  11841. }
  11842. }
  11843. if (!node) {
  11844. node = parseText(context, mode);
  11845. }
  11846. if (isArray(node)) {
  11847. for (let i = 0; i < node.length; i++) {
  11848. pushNode(nodes, node[i]);
  11849. }
  11850. }
  11851. else {
  11852. pushNode(nodes, node);
  11853. }
  11854. }
  11855. // Whitespace handling strategy like v2
  11856. let removedWhitespace = false;
  11857. if (mode !== 2 /* TextModes.RAWTEXT */ && mode !== 1 /* TextModes.RCDATA */) {
  11858. const shouldCondense = context.options.whitespace !== 'preserve';
  11859. for (let i = 0; i < nodes.length; i++) {
  11860. const node = nodes[i];
  11861. if (node.type === 2 /* NodeTypes.TEXT */) {
  11862. if (!context.inPre) {
  11863. if (!/[^\t\r\n\f ]/.test(node.content)) {
  11864. const prev = nodes[i - 1];
  11865. const next = nodes[i + 1];
  11866. // Remove if:
  11867. // - the whitespace is the first or last node, or:
  11868. // - (condense mode) the whitespace is between twos comments, or:
  11869. // - (condense mode) the whitespace is between comment and element, or:
  11870. // - (condense mode) the whitespace is between two elements AND contains newline
  11871. if (!prev ||
  11872. !next ||
  11873. (shouldCondense &&
  11874. ((prev.type === 3 /* NodeTypes.COMMENT */ &&
  11875. next.type === 3 /* NodeTypes.COMMENT */) ||
  11876. (prev.type === 3 /* NodeTypes.COMMENT */ &&
  11877. next.type === 1 /* NodeTypes.ELEMENT */) ||
  11878. (prev.type === 1 /* NodeTypes.ELEMENT */ &&
  11879. next.type === 3 /* NodeTypes.COMMENT */) ||
  11880. (prev.type === 1 /* NodeTypes.ELEMENT */ &&
  11881. next.type === 1 /* NodeTypes.ELEMENT */ &&
  11882. /[\r\n]/.test(node.content))))) {
  11883. removedWhitespace = true;
  11884. nodes[i] = null;
  11885. }
  11886. else {
  11887. // Otherwise, the whitespace is condensed into a single space
  11888. node.content = ' ';
  11889. }
  11890. }
  11891. else if (shouldCondense) {
  11892. // in condense mode, consecutive whitespaces in text are condensed
  11893. // down to a single space.
  11894. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  11895. }
  11896. }
  11897. else {
  11898. // #6410 normalize windows newlines in <pre>:
  11899. // in SSR, browsers normalize server-rendered \r\n into a single \n
  11900. // in the DOM
  11901. node.content = node.content.replace(/\r\n/g, '\n');
  11902. }
  11903. }
  11904. // Remove comment nodes if desired by configuration.
  11905. else if (node.type === 3 /* NodeTypes.COMMENT */ && !context.options.comments) {
  11906. removedWhitespace = true;
  11907. nodes[i] = null;
  11908. }
  11909. }
  11910. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  11911. // remove leading newline per html spec
  11912. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  11913. const first = nodes[0];
  11914. if (first && first.type === 2 /* NodeTypes.TEXT */) {
  11915. first.content = first.content.replace(/^\r?\n/, '');
  11916. }
  11917. }
  11918. }
  11919. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  11920. }
  11921. function pushNode(nodes, node) {
  11922. if (node.type === 2 /* NodeTypes.TEXT */) {
  11923. const prev = last(nodes);
  11924. // Merge if both this and the previous node are text and those are
  11925. // consecutive. This happens for cases like "a < b".
  11926. if (prev &&
  11927. prev.type === 2 /* NodeTypes.TEXT */ &&
  11928. prev.loc.end.offset === node.loc.start.offset) {
  11929. prev.content += node.content;
  11930. prev.loc.end = node.loc.end;
  11931. prev.loc.source += node.loc.source;
  11932. return;
  11933. }
  11934. }
  11935. nodes.push(node);
  11936. }
  11937. function parseCDATA(context, ancestors) {
  11938. advanceBy(context, 9);
  11939. const nodes = parseChildren(context, 3 /* TextModes.CDATA */, ancestors);
  11940. if (context.source.length === 0) {
  11941. emitError(context, 6 /* ErrorCodes.EOF_IN_CDATA */);
  11942. }
  11943. else {
  11944. advanceBy(context, 3);
  11945. }
  11946. return nodes;
  11947. }
  11948. function parseComment(context) {
  11949. const start = getCursor(context);
  11950. let content;
  11951. // Regular comment.
  11952. const match = /--(\!)?>/.exec(context.source);
  11953. if (!match) {
  11954. content = context.source.slice(4);
  11955. advanceBy(context, context.source.length);
  11956. emitError(context, 7 /* ErrorCodes.EOF_IN_COMMENT */);
  11957. }
  11958. else {
  11959. if (match.index <= 3) {
  11960. emitError(context, 0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  11961. }
  11962. if (match[1]) {
  11963. emitError(context, 10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */);
  11964. }
  11965. content = context.source.slice(4, match.index);
  11966. // Advancing with reporting nested comments.
  11967. const s = context.source.slice(0, match.index);
  11968. let prevIndex = 1, nestedIndex = 0;
  11969. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  11970. advanceBy(context, nestedIndex - prevIndex + 1);
  11971. if (nestedIndex + 4 < s.length) {
  11972. emitError(context, 16 /* ErrorCodes.NESTED_COMMENT */);
  11973. }
  11974. prevIndex = nestedIndex + 1;
  11975. }
  11976. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  11977. }
  11978. return {
  11979. type: 3 /* NodeTypes.COMMENT */,
  11980. content,
  11981. loc: getSelection(context, start)
  11982. };
  11983. }
  11984. function parseBogusComment(context) {
  11985. const start = getCursor(context);
  11986. const contentStart = context.source[1] === '?' ? 1 : 2;
  11987. let content;
  11988. const closeIndex = context.source.indexOf('>');
  11989. if (closeIndex === -1) {
  11990. content = context.source.slice(contentStart);
  11991. advanceBy(context, context.source.length);
  11992. }
  11993. else {
  11994. content = context.source.slice(contentStart, closeIndex);
  11995. advanceBy(context, closeIndex + 1);
  11996. }
  11997. return {
  11998. type: 3 /* NodeTypes.COMMENT */,
  11999. content,
  12000. loc: getSelection(context, start)
  12001. };
  12002. }
  12003. function parseElement(context, ancestors) {
  12004. // Start tag.
  12005. const wasInPre = context.inPre;
  12006. const wasInVPre = context.inVPre;
  12007. const parent = last(ancestors);
  12008. const element = parseTag(context, 0 /* TagType.Start */, parent);
  12009. const isPreBoundary = context.inPre && !wasInPre;
  12010. const isVPreBoundary = context.inVPre && !wasInVPre;
  12011. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  12012. // #4030 self-closing <pre> tag
  12013. if (isPreBoundary) {
  12014. context.inPre = false;
  12015. }
  12016. if (isVPreBoundary) {
  12017. context.inVPre = false;
  12018. }
  12019. return element;
  12020. }
  12021. // Children.
  12022. ancestors.push(element);
  12023. const mode = context.options.getTextMode(element, parent);
  12024. const children = parseChildren(context, mode, ancestors);
  12025. ancestors.pop();
  12026. element.children = children;
  12027. // End tag.
  12028. if (startsWithEndTagOpen(context.source, element.tag)) {
  12029. parseTag(context, 1 /* TagType.End */, parent);
  12030. }
  12031. else {
  12032. emitError(context, 24 /* ErrorCodes.X_MISSING_END_TAG */, 0, element.loc.start);
  12033. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  12034. const first = children[0];
  12035. if (first && startsWith(first.loc.source, '<!--')) {
  12036. emitError(context, 8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  12037. }
  12038. }
  12039. }
  12040. element.loc = getSelection(context, element.loc.start);
  12041. if (isPreBoundary) {
  12042. context.inPre = false;
  12043. }
  12044. if (isVPreBoundary) {
  12045. context.inVPre = false;
  12046. }
  12047. return element;
  12048. }
  12049. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  12050. function parseTag(context, type, parent) {
  12051. // Tag open.
  12052. const start = getCursor(context);
  12053. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  12054. const tag = match[1];
  12055. const ns = context.options.getNamespace(tag, parent);
  12056. advanceBy(context, match[0].length);
  12057. advanceSpaces(context);
  12058. // save current state in case we need to re-parse attributes with v-pre
  12059. const cursor = getCursor(context);
  12060. const currentSource = context.source;
  12061. // check <pre> tag
  12062. if (context.options.isPreTag(tag)) {
  12063. context.inPre = true;
  12064. }
  12065. // Attributes.
  12066. let props = parseAttributes(context, type);
  12067. // check v-pre
  12068. if (type === 0 /* TagType.Start */ &&
  12069. !context.inVPre &&
  12070. props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'pre')) {
  12071. context.inVPre = true;
  12072. // reset context
  12073. extend(context, cursor);
  12074. context.source = currentSource;
  12075. // re-parse attrs and filter out v-pre itself
  12076. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  12077. }
  12078. // Tag close.
  12079. let isSelfClosing = false;
  12080. if (context.source.length === 0) {
  12081. emitError(context, 9 /* ErrorCodes.EOF_IN_TAG */);
  12082. }
  12083. else {
  12084. isSelfClosing = startsWith(context.source, '/>');
  12085. if (type === 1 /* TagType.End */ && isSelfClosing) {
  12086. emitError(context, 4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */);
  12087. }
  12088. advanceBy(context, isSelfClosing ? 2 : 1);
  12089. }
  12090. if (type === 1 /* TagType.End */) {
  12091. return;
  12092. }
  12093. let tagType = 0 /* ElementTypes.ELEMENT */;
  12094. if (!context.inVPre) {
  12095. if (tag === 'slot') {
  12096. tagType = 2 /* ElementTypes.SLOT */;
  12097. }
  12098. else if (tag === 'template') {
  12099. if (props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  12100. tagType = 3 /* ElementTypes.TEMPLATE */;
  12101. }
  12102. }
  12103. else if (isComponent(tag, props, context)) {
  12104. tagType = 1 /* ElementTypes.COMPONENT */;
  12105. }
  12106. }
  12107. return {
  12108. type: 1 /* NodeTypes.ELEMENT */,
  12109. ns,
  12110. tag,
  12111. tagType,
  12112. props,
  12113. isSelfClosing,
  12114. children: [],
  12115. loc: getSelection(context, start),
  12116. codegenNode: undefined // to be created during transform phase
  12117. };
  12118. }
  12119. function isComponent(tag, props, context) {
  12120. const options = context.options;
  12121. if (options.isCustomElement(tag)) {
  12122. return false;
  12123. }
  12124. if (tag === 'component' ||
  12125. /^[A-Z]/.test(tag) ||
  12126. isCoreComponent(tag) ||
  12127. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  12128. (options.isNativeTag && !options.isNativeTag(tag))) {
  12129. return true;
  12130. }
  12131. // at this point the tag should be a native tag, but check for potential "is"
  12132. // casting
  12133. for (let i = 0; i < props.length; i++) {
  12134. const p = props[i];
  12135. if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
  12136. if (p.name === 'is' && p.value) {
  12137. if (p.value.content.startsWith('vue:')) {
  12138. return true;
  12139. }
  12140. }
  12141. }
  12142. else {
  12143. // directive
  12144. // v-is (TODO Deprecate)
  12145. if (p.name === 'is') {
  12146. return true;
  12147. }
  12148. else if (
  12149. // :is on plain element - only treat as component in compat mode
  12150. p.name === 'bind' &&
  12151. isStaticArgOf(p.arg, 'is') &&
  12152. false &&
  12153. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  12154. return true;
  12155. }
  12156. }
  12157. }
  12158. }
  12159. function parseAttributes(context, type) {
  12160. const props = [];
  12161. const attributeNames = new Set();
  12162. while (context.source.length > 0 &&
  12163. !startsWith(context.source, '>') &&
  12164. !startsWith(context.source, '/>')) {
  12165. if (startsWith(context.source, '/')) {
  12166. emitError(context, 22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */);
  12167. advanceBy(context, 1);
  12168. advanceSpaces(context);
  12169. continue;
  12170. }
  12171. if (type === 1 /* TagType.End */) {
  12172. emitError(context, 3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */);
  12173. }
  12174. const attr = parseAttribute(context, attributeNames);
  12175. // Trim whitespace between class
  12176. // https://github.com/vuejs/core/issues/4251
  12177. if (attr.type === 6 /* NodeTypes.ATTRIBUTE */ &&
  12178. attr.value &&
  12179. attr.name === 'class') {
  12180. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  12181. }
  12182. if (type === 0 /* TagType.Start */) {
  12183. props.push(attr);
  12184. }
  12185. if (/^[^\t\r\n\f />]/.test(context.source)) {
  12186. emitError(context, 15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  12187. }
  12188. advanceSpaces(context);
  12189. }
  12190. return props;
  12191. }
  12192. function parseAttribute(context, nameSet) {
  12193. // Name.
  12194. const start = getCursor(context);
  12195. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  12196. const name = match[0];
  12197. if (nameSet.has(name)) {
  12198. emitError(context, 2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */);
  12199. }
  12200. nameSet.add(name);
  12201. if (name[0] === '=') {
  12202. emitError(context, 19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  12203. }
  12204. {
  12205. const pattern = /["'<]/g;
  12206. let m;
  12207. while ((m = pattern.exec(name))) {
  12208. emitError(context, 17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  12209. }
  12210. }
  12211. advanceBy(context, name.length);
  12212. // Value
  12213. let value = undefined;
  12214. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  12215. advanceSpaces(context);
  12216. advanceBy(context, 1);
  12217. advanceSpaces(context);
  12218. value = parseAttributeValue(context);
  12219. if (!value) {
  12220. emitError(context, 13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */);
  12221. }
  12222. }
  12223. const loc = getSelection(context, start);
  12224. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  12225. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  12226. let isPropShorthand = startsWith(name, '.');
  12227. let dirName = match[1] ||
  12228. (isPropShorthand || startsWith(name, ':')
  12229. ? 'bind'
  12230. : startsWith(name, '@')
  12231. ? 'on'
  12232. : 'slot');
  12233. let arg;
  12234. if (match[2]) {
  12235. const isSlot = dirName === 'slot';
  12236. const startOffset = name.lastIndexOf(match[2]);
  12237. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  12238. let content = match[2];
  12239. let isStatic = true;
  12240. if (content.startsWith('[')) {
  12241. isStatic = false;
  12242. if (!content.endsWith(']')) {
  12243. emitError(context, 27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  12244. content = content.slice(1);
  12245. }
  12246. else {
  12247. content = content.slice(1, content.length - 1);
  12248. }
  12249. }
  12250. else if (isSlot) {
  12251. // #1241 special case for v-slot: vuetify relies extensively on slot
  12252. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  12253. // supports such usage so we are keeping it consistent with 2.x.
  12254. content += match[3] || '';
  12255. }
  12256. arg = {
  12257. type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
  12258. content,
  12259. isStatic,
  12260. constType: isStatic
  12261. ? 3 /* ConstantTypes.CAN_STRINGIFY */
  12262. : 0 /* ConstantTypes.NOT_CONSTANT */,
  12263. loc
  12264. };
  12265. }
  12266. if (value && value.isQuoted) {
  12267. const valueLoc = value.loc;
  12268. valueLoc.start.offset++;
  12269. valueLoc.start.column++;
  12270. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  12271. valueLoc.source = valueLoc.source.slice(1, -1);
  12272. }
  12273. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  12274. if (isPropShorthand)
  12275. modifiers.push('prop');
  12276. return {
  12277. type: 7 /* NodeTypes.DIRECTIVE */,
  12278. name: dirName,
  12279. exp: value && {
  12280. type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
  12281. content: value.content,
  12282. isStatic: false,
  12283. // Treat as non-constant by default. This can be potentially set to
  12284. // other values by `transformExpression` to make it eligible for hoisting.
  12285. constType: 0 /* ConstantTypes.NOT_CONSTANT */,
  12286. loc: value.loc
  12287. },
  12288. arg,
  12289. modifiers,
  12290. loc
  12291. };
  12292. }
  12293. // missing directive name or illegal directive name
  12294. if (!context.inVPre && startsWith(name, 'v-')) {
  12295. emitError(context, 26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */);
  12296. }
  12297. return {
  12298. type: 6 /* NodeTypes.ATTRIBUTE */,
  12299. name,
  12300. value: value && {
  12301. type: 2 /* NodeTypes.TEXT */,
  12302. content: value.content,
  12303. loc: value.loc
  12304. },
  12305. loc
  12306. };
  12307. }
  12308. function parseAttributeValue(context) {
  12309. const start = getCursor(context);
  12310. let content;
  12311. const quote = context.source[0];
  12312. const isQuoted = quote === `"` || quote === `'`;
  12313. if (isQuoted) {
  12314. // Quoted value.
  12315. advanceBy(context, 1);
  12316. const endIndex = context.source.indexOf(quote);
  12317. if (endIndex === -1) {
  12318. content = parseTextData(context, context.source.length, 4 /* TextModes.ATTRIBUTE_VALUE */);
  12319. }
  12320. else {
  12321. content = parseTextData(context, endIndex, 4 /* TextModes.ATTRIBUTE_VALUE */);
  12322. advanceBy(context, 1);
  12323. }
  12324. }
  12325. else {
  12326. // Unquoted
  12327. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  12328. if (!match) {
  12329. return undefined;
  12330. }
  12331. const unexpectedChars = /["'<=`]/g;
  12332. let m;
  12333. while ((m = unexpectedChars.exec(match[0]))) {
  12334. emitError(context, 18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  12335. }
  12336. content = parseTextData(context, match[0].length, 4 /* TextModes.ATTRIBUTE_VALUE */);
  12337. }
  12338. return { content, isQuoted, loc: getSelection(context, start) };
  12339. }
  12340. function parseInterpolation(context, mode) {
  12341. const [open, close] = context.options.delimiters;
  12342. const closeIndex = context.source.indexOf(close, open.length);
  12343. if (closeIndex === -1) {
  12344. emitError(context, 25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */);
  12345. return undefined;
  12346. }
  12347. const start = getCursor(context);
  12348. advanceBy(context, open.length);
  12349. const innerStart = getCursor(context);
  12350. const innerEnd = getCursor(context);
  12351. const rawContentLength = closeIndex - open.length;
  12352. const rawContent = context.source.slice(0, rawContentLength);
  12353. const preTrimContent = parseTextData(context, rawContentLength, mode);
  12354. const content = preTrimContent.trim();
  12355. const startOffset = preTrimContent.indexOf(content);
  12356. if (startOffset > 0) {
  12357. advancePositionWithMutation(innerStart, rawContent, startOffset);
  12358. }
  12359. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  12360. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  12361. advanceBy(context, close.length);
  12362. return {
  12363. type: 5 /* NodeTypes.INTERPOLATION */,
  12364. content: {
  12365. type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
  12366. isStatic: false,
  12367. // Set `isConstant` to false by default and will decide in transformExpression
  12368. constType: 0 /* ConstantTypes.NOT_CONSTANT */,
  12369. content,
  12370. loc: getSelection(context, innerStart, innerEnd)
  12371. },
  12372. loc: getSelection(context, start)
  12373. };
  12374. }
  12375. function parseText(context, mode) {
  12376. const endTokens = mode === 3 /* TextModes.CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  12377. let endIndex = context.source.length;
  12378. for (let i = 0; i < endTokens.length; i++) {
  12379. const index = context.source.indexOf(endTokens[i], 1);
  12380. if (index !== -1 && endIndex > index) {
  12381. endIndex = index;
  12382. }
  12383. }
  12384. const start = getCursor(context);
  12385. const content = parseTextData(context, endIndex, mode);
  12386. return {
  12387. type: 2 /* NodeTypes.TEXT */,
  12388. content,
  12389. loc: getSelection(context, start)
  12390. };
  12391. }
  12392. /**
  12393. * Get text data with a given length from the current location.
  12394. * This translates HTML entities in the text data.
  12395. */
  12396. function parseTextData(context, length, mode) {
  12397. const rawText = context.source.slice(0, length);
  12398. advanceBy(context, length);
  12399. if (mode === 2 /* TextModes.RAWTEXT */ ||
  12400. mode === 3 /* TextModes.CDATA */ ||
  12401. !rawText.includes('&')) {
  12402. return rawText;
  12403. }
  12404. else {
  12405. // DATA or RCDATA containing "&"". Entity decoding required.
  12406. return context.options.decodeEntities(rawText, mode === 4 /* TextModes.ATTRIBUTE_VALUE */);
  12407. }
  12408. }
  12409. function getCursor(context) {
  12410. const { column, line, offset } = context;
  12411. return { column, line, offset };
  12412. }
  12413. function getSelection(context, start, end) {
  12414. end = end || getCursor(context);
  12415. return {
  12416. start,
  12417. end,
  12418. source: context.originalSource.slice(start.offset, end.offset)
  12419. };
  12420. }
  12421. function last(xs) {
  12422. return xs[xs.length - 1];
  12423. }
  12424. function startsWith(source, searchString) {
  12425. return source.startsWith(searchString);
  12426. }
  12427. function advanceBy(context, numberOfCharacters) {
  12428. const { source } = context;
  12429. advancePositionWithMutation(context, source, numberOfCharacters);
  12430. context.source = source.slice(numberOfCharacters);
  12431. }
  12432. function advanceSpaces(context) {
  12433. const match = /^[\t\r\n\f ]+/.exec(context.source);
  12434. if (match) {
  12435. advanceBy(context, match[0].length);
  12436. }
  12437. }
  12438. function getNewPosition(context, start, numberOfCharacters) {
  12439. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  12440. }
  12441. function emitError(context, code, offset, loc = getCursor(context)) {
  12442. if (offset) {
  12443. loc.offset += offset;
  12444. loc.column += offset;
  12445. }
  12446. context.options.onError(createCompilerError(code, {
  12447. start: loc,
  12448. end: loc,
  12449. source: ''
  12450. }));
  12451. }
  12452. function isEnd(context, mode, ancestors) {
  12453. const s = context.source;
  12454. switch (mode) {
  12455. case 0 /* TextModes.DATA */:
  12456. if (startsWith(s, '</')) {
  12457. // TODO: probably bad performance
  12458. for (let i = ancestors.length - 1; i >= 0; --i) {
  12459. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  12460. return true;
  12461. }
  12462. }
  12463. }
  12464. break;
  12465. case 1 /* TextModes.RCDATA */:
  12466. case 2 /* TextModes.RAWTEXT */: {
  12467. const parent = last(ancestors);
  12468. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  12469. return true;
  12470. }
  12471. break;
  12472. }
  12473. case 3 /* TextModes.CDATA */:
  12474. if (startsWith(s, ']]>')) {
  12475. return true;
  12476. }
  12477. break;
  12478. }
  12479. return !s;
  12480. }
  12481. function startsWithEndTagOpen(source, tag) {
  12482. return (startsWith(source, '</') &&
  12483. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  12484. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  12485. }
  12486. function hoistStatic(root, context) {
  12487. walk(root, context,
  12488. // Root node is unfortunately non-hoistable due to potential parent
  12489. // fallthrough attributes.
  12490. isSingleElementRoot(root, root.children[0]));
  12491. }
  12492. function isSingleElementRoot(root, child) {
  12493. const { children } = root;
  12494. return (children.length === 1 &&
  12495. child.type === 1 /* NodeTypes.ELEMENT */ &&
  12496. !isSlotOutlet(child));
  12497. }
  12498. function walk(node, context, doNotHoistNode = false) {
  12499. const { children } = node;
  12500. const originalCount = children.length;
  12501. let hoistedCount = 0;
  12502. for (let i = 0; i < children.length; i++) {
  12503. const child = children[i];
  12504. // only plain elements & text calls are eligible for hoisting.
  12505. if (child.type === 1 /* NodeTypes.ELEMENT */ &&
  12506. child.tagType === 0 /* ElementTypes.ELEMENT */) {
  12507. const constantType = doNotHoistNode
  12508. ? 0 /* ConstantTypes.NOT_CONSTANT */
  12509. : getConstantType(child, context);
  12510. if (constantType > 0 /* ConstantTypes.NOT_CONSTANT */) {
  12511. if (constantType >= 2 /* ConstantTypes.CAN_HOIST */) {
  12512. child.codegenNode.patchFlag =
  12513. -1 /* PatchFlags.HOISTED */ + (` /* HOISTED */` );
  12514. child.codegenNode = context.hoist(child.codegenNode);
  12515. hoistedCount++;
  12516. continue;
  12517. }
  12518. }
  12519. else {
  12520. // node may contain dynamic children, but its props may be eligible for
  12521. // hoisting.
  12522. const codegenNode = child.codegenNode;
  12523. if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
  12524. const flag = getPatchFlag(codegenNode);
  12525. if ((!flag ||
  12526. flag === 512 /* PatchFlags.NEED_PATCH */ ||
  12527. flag === 1 /* PatchFlags.TEXT */) &&
  12528. getGeneratedPropsConstantType(child, context) >=
  12529. 2 /* ConstantTypes.CAN_HOIST */) {
  12530. const props = getNodeProps(child);
  12531. if (props) {
  12532. codegenNode.props = context.hoist(props);
  12533. }
  12534. }
  12535. if (codegenNode.dynamicProps) {
  12536. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  12537. }
  12538. }
  12539. }
  12540. }
  12541. // walk further
  12542. if (child.type === 1 /* NodeTypes.ELEMENT */) {
  12543. const isComponent = child.tagType === 1 /* ElementTypes.COMPONENT */;
  12544. if (isComponent) {
  12545. context.scopes.vSlot++;
  12546. }
  12547. walk(child, context);
  12548. if (isComponent) {
  12549. context.scopes.vSlot--;
  12550. }
  12551. }
  12552. else if (child.type === 11 /* NodeTypes.FOR */) {
  12553. // Do not hoist v-for single child because it has to be a block
  12554. walk(child, context, child.children.length === 1);
  12555. }
  12556. else if (child.type === 9 /* NodeTypes.IF */) {
  12557. for (let i = 0; i < child.branches.length; i++) {
  12558. // Do not hoist v-if single child because it has to be a block
  12559. walk(child.branches[i], context, child.branches[i].children.length === 1);
  12560. }
  12561. }
  12562. }
  12563. if (hoistedCount && context.transformHoist) {
  12564. context.transformHoist(children, context, node);
  12565. }
  12566. // all children were hoisted - the entire children array is hoistable.
  12567. if (hoistedCount &&
  12568. hoistedCount === originalCount &&
  12569. node.type === 1 /* NodeTypes.ELEMENT */ &&
  12570. node.tagType === 0 /* ElementTypes.ELEMENT */ &&
  12571. node.codegenNode &&
  12572. node.codegenNode.type === 13 /* NodeTypes.VNODE_CALL */ &&
  12573. isArray(node.codegenNode.children)) {
  12574. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  12575. }
  12576. }
  12577. function getConstantType(node, context) {
  12578. const { constantCache } = context;
  12579. switch (node.type) {
  12580. case 1 /* NodeTypes.ELEMENT */:
  12581. if (node.tagType !== 0 /* ElementTypes.ELEMENT */) {
  12582. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12583. }
  12584. const cached = constantCache.get(node);
  12585. if (cached !== undefined) {
  12586. return cached;
  12587. }
  12588. const codegenNode = node.codegenNode;
  12589. if (codegenNode.type !== 13 /* NodeTypes.VNODE_CALL */) {
  12590. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12591. }
  12592. if (codegenNode.isBlock &&
  12593. node.tag !== 'svg' &&
  12594. node.tag !== 'foreignObject') {
  12595. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12596. }
  12597. const flag = getPatchFlag(codegenNode);
  12598. if (!flag) {
  12599. let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
  12600. // Element itself has no patch flag. However we still need to check:
  12601. // 1. Even for a node with no patch flag, it is possible for it to contain
  12602. // non-hoistable expressions that refers to scope variables, e.g. compiler
  12603. // injected keys or cached event handlers. Therefore we need to always
  12604. // check the codegenNode's props to be sure.
  12605. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  12606. if (generatedPropsType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12607. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12608. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12609. }
  12610. if (generatedPropsType < returnType) {
  12611. returnType = generatedPropsType;
  12612. }
  12613. // 2. its children.
  12614. for (let i = 0; i < node.children.length; i++) {
  12615. const childType = getConstantType(node.children[i], context);
  12616. if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12617. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12618. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12619. }
  12620. if (childType < returnType) {
  12621. returnType = childType;
  12622. }
  12623. }
  12624. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  12625. // type, check if any of the props can cause the type to be lowered
  12626. // we can skip can_patch because it's guaranteed by the absence of a
  12627. // patchFlag.
  12628. if (returnType > 1 /* ConstantTypes.CAN_SKIP_PATCH */) {
  12629. for (let i = 0; i < node.props.length; i++) {
  12630. const p = node.props[i];
  12631. if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'bind' && p.exp) {
  12632. const expType = getConstantType(p.exp, context);
  12633. if (expType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12634. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12635. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12636. }
  12637. if (expType < returnType) {
  12638. returnType = expType;
  12639. }
  12640. }
  12641. }
  12642. }
  12643. // only svg/foreignObject could be block here, however if they are
  12644. // static then they don't need to be blocks since there will be no
  12645. // nested updates.
  12646. if (codegenNode.isBlock) {
  12647. // except set custom directives.
  12648. for (let i = 0; i < node.props.length; i++) {
  12649. const p = node.props[i];
  12650. if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
  12651. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12652. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12653. }
  12654. }
  12655. context.removeHelper(OPEN_BLOCK);
  12656. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  12657. codegenNode.isBlock = false;
  12658. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  12659. }
  12660. constantCache.set(node, returnType);
  12661. return returnType;
  12662. }
  12663. else {
  12664. constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
  12665. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12666. }
  12667. case 2 /* NodeTypes.TEXT */:
  12668. case 3 /* NodeTypes.COMMENT */:
  12669. return 3 /* ConstantTypes.CAN_STRINGIFY */;
  12670. case 9 /* NodeTypes.IF */:
  12671. case 11 /* NodeTypes.FOR */:
  12672. case 10 /* NodeTypes.IF_BRANCH */:
  12673. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12674. case 5 /* NodeTypes.INTERPOLATION */:
  12675. case 12 /* NodeTypes.TEXT_CALL */:
  12676. return getConstantType(node.content, context);
  12677. case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
  12678. return node.constType;
  12679. case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
  12680. let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
  12681. for (let i = 0; i < node.children.length; i++) {
  12682. const child = node.children[i];
  12683. if (isString(child) || isSymbol(child)) {
  12684. continue;
  12685. }
  12686. const childType = getConstantType(child, context);
  12687. if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12688. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12689. }
  12690. else if (childType < returnType) {
  12691. returnType = childType;
  12692. }
  12693. }
  12694. return returnType;
  12695. default:
  12696. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12697. }
  12698. }
  12699. const allowHoistedHelperSet = new Set([
  12700. NORMALIZE_CLASS,
  12701. NORMALIZE_STYLE,
  12702. NORMALIZE_PROPS,
  12703. GUARD_REACTIVE_PROPS
  12704. ]);
  12705. function getConstantTypeOfHelperCall(value, context) {
  12706. if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ &&
  12707. !isString(value.callee) &&
  12708. allowHoistedHelperSet.has(value.callee)) {
  12709. const arg = value.arguments[0];
  12710. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  12711. return getConstantType(arg, context);
  12712. }
  12713. else if (arg.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  12714. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  12715. return getConstantTypeOfHelperCall(arg, context);
  12716. }
  12717. }
  12718. return 0 /* ConstantTypes.NOT_CONSTANT */;
  12719. }
  12720. function getGeneratedPropsConstantType(node, context) {
  12721. let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
  12722. const props = getNodeProps(node);
  12723. if (props && props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
  12724. const { properties } = props;
  12725. for (let i = 0; i < properties.length; i++) {
  12726. const { key, value } = properties[i];
  12727. const keyType = getConstantType(key, context);
  12728. if (keyType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12729. return keyType;
  12730. }
  12731. if (keyType < returnType) {
  12732. returnType = keyType;
  12733. }
  12734. let valueType;
  12735. if (value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  12736. valueType = getConstantType(value, context);
  12737. }
  12738. else if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
  12739. // some helper calls can be hoisted,
  12740. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  12741. // in this case we need to respect the ConstantType of the helper's arguments
  12742. valueType = getConstantTypeOfHelperCall(value, context);
  12743. }
  12744. else {
  12745. valueType = 0 /* ConstantTypes.NOT_CONSTANT */;
  12746. }
  12747. if (valueType === 0 /* ConstantTypes.NOT_CONSTANT */) {
  12748. return valueType;
  12749. }
  12750. if (valueType < returnType) {
  12751. returnType = valueType;
  12752. }
  12753. }
  12754. }
  12755. return returnType;
  12756. }
  12757. function getNodeProps(node) {
  12758. const codegenNode = node.codegenNode;
  12759. if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
  12760. return codegenNode.props;
  12761. }
  12762. }
  12763. function getPatchFlag(node) {
  12764. const flag = node.patchFlag;
  12765. return flag ? parseInt(flag, 10) : undefined;
  12766. }
  12767. 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 }) {
  12768. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  12769. const context = {
  12770. // options
  12771. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  12772. prefixIdentifiers,
  12773. hoistStatic,
  12774. cacheHandlers,
  12775. nodeTransforms,
  12776. directiveTransforms,
  12777. transformHoist,
  12778. isBuiltInComponent,
  12779. isCustomElement,
  12780. expressionPlugins,
  12781. scopeId,
  12782. slotted,
  12783. ssr,
  12784. inSSR,
  12785. ssrCssVars,
  12786. bindingMetadata,
  12787. inline,
  12788. isTS,
  12789. onError,
  12790. onWarn,
  12791. compatConfig,
  12792. // state
  12793. root,
  12794. helpers: new Map(),
  12795. components: new Set(),
  12796. directives: new Set(),
  12797. hoists: [],
  12798. imports: [],
  12799. constantCache: new Map(),
  12800. temps: 0,
  12801. cached: 0,
  12802. identifiers: Object.create(null),
  12803. scopes: {
  12804. vFor: 0,
  12805. vSlot: 0,
  12806. vPre: 0,
  12807. vOnce: 0
  12808. },
  12809. parent: null,
  12810. currentNode: root,
  12811. childIndex: 0,
  12812. inVOnce: false,
  12813. // methods
  12814. helper(name) {
  12815. const count = context.helpers.get(name) || 0;
  12816. context.helpers.set(name, count + 1);
  12817. return name;
  12818. },
  12819. removeHelper(name) {
  12820. const count = context.helpers.get(name);
  12821. if (count) {
  12822. const currentCount = count - 1;
  12823. if (!currentCount) {
  12824. context.helpers.delete(name);
  12825. }
  12826. else {
  12827. context.helpers.set(name, currentCount);
  12828. }
  12829. }
  12830. },
  12831. helperString(name) {
  12832. return `_${helperNameMap[context.helper(name)]}`;
  12833. },
  12834. replaceNode(node) {
  12835. /* istanbul ignore if */
  12836. {
  12837. if (!context.currentNode) {
  12838. throw new Error(`Node being replaced is already removed.`);
  12839. }
  12840. if (!context.parent) {
  12841. throw new Error(`Cannot replace root node.`);
  12842. }
  12843. }
  12844. context.parent.children[context.childIndex] = context.currentNode = node;
  12845. },
  12846. removeNode(node) {
  12847. if (!context.parent) {
  12848. throw new Error(`Cannot remove root node.`);
  12849. }
  12850. const list = context.parent.children;
  12851. const removalIndex = node
  12852. ? list.indexOf(node)
  12853. : context.currentNode
  12854. ? context.childIndex
  12855. : -1;
  12856. /* istanbul ignore if */
  12857. if (removalIndex < 0) {
  12858. throw new Error(`node being removed is not a child of current parent`);
  12859. }
  12860. if (!node || node === context.currentNode) {
  12861. // current node removed
  12862. context.currentNode = null;
  12863. context.onNodeRemoved();
  12864. }
  12865. else {
  12866. // sibling node removed
  12867. if (context.childIndex > removalIndex) {
  12868. context.childIndex--;
  12869. context.onNodeRemoved();
  12870. }
  12871. }
  12872. context.parent.children.splice(removalIndex, 1);
  12873. },
  12874. onNodeRemoved: () => { },
  12875. addIdentifiers(exp) {
  12876. },
  12877. removeIdentifiers(exp) {
  12878. },
  12879. hoist(exp) {
  12880. if (isString(exp))
  12881. exp = createSimpleExpression(exp);
  12882. context.hoists.push(exp);
  12883. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* ConstantTypes.CAN_HOIST */);
  12884. identifier.hoisted = exp;
  12885. return identifier;
  12886. },
  12887. cache(exp, isVNode = false) {
  12888. return createCacheExpression(context.cached++, exp, isVNode);
  12889. }
  12890. };
  12891. return context;
  12892. }
  12893. function transform(root, options) {
  12894. const context = createTransformContext(root, options);
  12895. traverseNode(root, context);
  12896. if (options.hoistStatic) {
  12897. hoistStatic(root, context);
  12898. }
  12899. if (!options.ssr) {
  12900. createRootCodegen(root, context);
  12901. }
  12902. // finalize meta information
  12903. root.helpers = new Set([...context.helpers.keys()]);
  12904. root.components = [...context.components];
  12905. root.directives = [...context.directives];
  12906. root.imports = context.imports;
  12907. root.hoists = context.hoists;
  12908. root.temps = context.temps;
  12909. root.cached = context.cached;
  12910. }
  12911. function createRootCodegen(root, context) {
  12912. const { helper } = context;
  12913. const { children } = root;
  12914. if (children.length === 1) {
  12915. const child = children[0];
  12916. // if the single child is an element, turn it into a block.
  12917. if (isSingleElementRoot(root, child) && child.codegenNode) {
  12918. // single element root is never hoisted so codegenNode will never be
  12919. // SimpleExpressionNode
  12920. const codegenNode = child.codegenNode;
  12921. if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
  12922. makeBlock(codegenNode, context);
  12923. }
  12924. root.codegenNode = codegenNode;
  12925. }
  12926. else {
  12927. // - single <slot/>, IfNode, ForNode: already blocks.
  12928. // - single text node: always patched.
  12929. // root codegen falls through via genNode()
  12930. root.codegenNode = child;
  12931. }
  12932. }
  12933. else if (children.length > 1) {
  12934. // root has multiple nodes - return a fragment block.
  12935. let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
  12936. let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
  12937. // check if the fragment actually contains a single valid child with
  12938. // the rest being comments
  12939. if (children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
  12940. patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
  12941. patchFlagText += `, ${PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
  12942. }
  12943. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
  12944. }
  12945. else ;
  12946. }
  12947. function traverseChildren(parent, context) {
  12948. let i = 0;
  12949. const nodeRemoved = () => {
  12950. i--;
  12951. };
  12952. for (; i < parent.children.length; i++) {
  12953. const child = parent.children[i];
  12954. if (isString(child))
  12955. continue;
  12956. context.parent = parent;
  12957. context.childIndex = i;
  12958. context.onNodeRemoved = nodeRemoved;
  12959. traverseNode(child, context);
  12960. }
  12961. }
  12962. function traverseNode(node, context) {
  12963. context.currentNode = node;
  12964. // apply transform plugins
  12965. const { nodeTransforms } = context;
  12966. const exitFns = [];
  12967. for (let i = 0; i < nodeTransforms.length; i++) {
  12968. const onExit = nodeTransforms[i](node, context);
  12969. if (onExit) {
  12970. if (isArray(onExit)) {
  12971. exitFns.push(...onExit);
  12972. }
  12973. else {
  12974. exitFns.push(onExit);
  12975. }
  12976. }
  12977. if (!context.currentNode) {
  12978. // node was removed
  12979. return;
  12980. }
  12981. else {
  12982. // node may have been replaced
  12983. node = context.currentNode;
  12984. }
  12985. }
  12986. switch (node.type) {
  12987. case 3 /* NodeTypes.COMMENT */:
  12988. if (!context.ssr) {
  12989. // inject import for the Comment symbol, which is needed for creating
  12990. // comment nodes with `createVNode`
  12991. context.helper(CREATE_COMMENT);
  12992. }
  12993. break;
  12994. case 5 /* NodeTypes.INTERPOLATION */:
  12995. // no need to traverse, but we need to inject toString helper
  12996. if (!context.ssr) {
  12997. context.helper(TO_DISPLAY_STRING);
  12998. }
  12999. break;
  13000. // for container types, further traverse downwards
  13001. case 9 /* NodeTypes.IF */:
  13002. for (let i = 0; i < node.branches.length; i++) {
  13003. traverseNode(node.branches[i], context);
  13004. }
  13005. break;
  13006. case 10 /* NodeTypes.IF_BRANCH */:
  13007. case 11 /* NodeTypes.FOR */:
  13008. case 1 /* NodeTypes.ELEMENT */:
  13009. case 0 /* NodeTypes.ROOT */:
  13010. traverseChildren(node, context);
  13011. break;
  13012. }
  13013. // exit transforms
  13014. context.currentNode = node;
  13015. let i = exitFns.length;
  13016. while (i--) {
  13017. exitFns[i]();
  13018. }
  13019. }
  13020. function createStructuralDirectiveTransform(name, fn) {
  13021. const matches = isString(name)
  13022. ? (n) => n === name
  13023. : (n) => name.test(n);
  13024. return (node, context) => {
  13025. if (node.type === 1 /* NodeTypes.ELEMENT */) {
  13026. const { props } = node;
  13027. // structural directive transforms are not concerned with slots
  13028. // as they are handled separately in vSlot.ts
  13029. if (node.tagType === 3 /* ElementTypes.TEMPLATE */ && props.some(isVSlot)) {
  13030. return;
  13031. }
  13032. const exitFns = [];
  13033. for (let i = 0; i < props.length; i++) {
  13034. const prop = props[i];
  13035. if (prop.type === 7 /* NodeTypes.DIRECTIVE */ && matches(prop.name)) {
  13036. // structural directives are removed to avoid infinite recursion
  13037. // also we remove them *before* applying so that it can further
  13038. // traverse itself in case it moves the node around
  13039. props.splice(i, 1);
  13040. i--;
  13041. const onExit = fn(node, prop, context);
  13042. if (onExit)
  13043. exitFns.push(onExit);
  13044. }
  13045. }
  13046. return exitFns;
  13047. }
  13048. };
  13049. }
  13050. const PURE_ANNOTATION = `/*#__PURE__*/`;
  13051. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  13052. 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 }) {
  13053. const context = {
  13054. mode,
  13055. prefixIdentifiers,
  13056. sourceMap,
  13057. filename,
  13058. scopeId,
  13059. optimizeImports,
  13060. runtimeGlobalName,
  13061. runtimeModuleName,
  13062. ssrRuntimeModuleName,
  13063. ssr,
  13064. isTS,
  13065. inSSR,
  13066. source: ast.loc.source,
  13067. code: ``,
  13068. column: 1,
  13069. line: 1,
  13070. offset: 0,
  13071. indentLevel: 0,
  13072. pure: false,
  13073. map: undefined,
  13074. helper(key) {
  13075. return `_${helperNameMap[key]}`;
  13076. },
  13077. push(code, node) {
  13078. context.code += code;
  13079. },
  13080. indent() {
  13081. newline(++context.indentLevel);
  13082. },
  13083. deindent(withoutNewLine = false) {
  13084. if (withoutNewLine) {
  13085. --context.indentLevel;
  13086. }
  13087. else {
  13088. newline(--context.indentLevel);
  13089. }
  13090. },
  13091. newline() {
  13092. newline(context.indentLevel);
  13093. }
  13094. };
  13095. function newline(n) {
  13096. context.push('\n' + ` `.repeat(n));
  13097. }
  13098. return context;
  13099. }
  13100. function generate(ast, options = {}) {
  13101. const context = createCodegenContext(ast, options);
  13102. if (options.onContextCreated)
  13103. options.onContextCreated(context);
  13104. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  13105. const helpers = Array.from(ast.helpers);
  13106. const hasHelpers = helpers.length > 0;
  13107. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  13108. const isSetupInlined = !true ;
  13109. // preambles
  13110. // in setup() inline mode, the preamble is generated in a sub context
  13111. // and returned separately.
  13112. const preambleContext = isSetupInlined
  13113. ? createCodegenContext(ast, options)
  13114. : context;
  13115. {
  13116. genFunctionPreamble(ast, preambleContext);
  13117. }
  13118. // enter render function
  13119. const functionName = ssr ? `ssrRender` : `render`;
  13120. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  13121. const signature = args.join(', ');
  13122. {
  13123. push(`function ${functionName}(${signature}) {`);
  13124. }
  13125. indent();
  13126. if (useWithBlock) {
  13127. push(`with (_ctx) {`);
  13128. indent();
  13129. // function mode const declarations should be inside with block
  13130. // also they should be renamed to avoid collision with user properties
  13131. if (hasHelpers) {
  13132. push(`const { ${helpers.map(aliasHelper).join(', ')} } = _Vue`);
  13133. push(`\n`);
  13134. newline();
  13135. }
  13136. }
  13137. // generate asset resolution statements
  13138. if (ast.components.length) {
  13139. genAssets(ast.components, 'component', context);
  13140. if (ast.directives.length || ast.temps > 0) {
  13141. newline();
  13142. }
  13143. }
  13144. if (ast.directives.length) {
  13145. genAssets(ast.directives, 'directive', context);
  13146. if (ast.temps > 0) {
  13147. newline();
  13148. }
  13149. }
  13150. if (ast.temps > 0) {
  13151. push(`let `);
  13152. for (let i = 0; i < ast.temps; i++) {
  13153. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  13154. }
  13155. }
  13156. if (ast.components.length || ast.directives.length || ast.temps) {
  13157. push(`\n`);
  13158. newline();
  13159. }
  13160. // generate the VNode tree expression
  13161. if (!ssr) {
  13162. push(`return `);
  13163. }
  13164. if (ast.codegenNode) {
  13165. genNode(ast.codegenNode, context);
  13166. }
  13167. else {
  13168. push(`null`);
  13169. }
  13170. if (useWithBlock) {
  13171. deindent();
  13172. push(`}`);
  13173. }
  13174. deindent();
  13175. push(`}`);
  13176. return {
  13177. ast,
  13178. code: context.code,
  13179. preamble: isSetupInlined ? preambleContext.code : ``,
  13180. // SourceMapGenerator does have toJSON() method but it's not in the types
  13181. map: context.map ? context.map.toJSON() : undefined
  13182. };
  13183. }
  13184. function genFunctionPreamble(ast, context) {
  13185. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  13186. const VueBinding = runtimeGlobalName;
  13187. // Generate const declaration for helpers
  13188. // In prefix mode, we place the const declaration at top so it's done
  13189. // only once; But if we not prefixing, we place the declaration inside the
  13190. // with block so it doesn't incur the `in` check cost for every helper access.
  13191. const helpers = Array.from(ast.helpers);
  13192. if (helpers.length > 0) {
  13193. {
  13194. // "with" mode.
  13195. // save Vue in a separate variable to avoid collision
  13196. push(`const _Vue = ${VueBinding}\n`);
  13197. // in "with" mode, helpers are declared inside the with block to avoid
  13198. // has check cost, but hoists are lifted out of the function - we need
  13199. // to provide the helper here.
  13200. if (ast.hoists.length) {
  13201. const staticHelpers = [
  13202. CREATE_VNODE,
  13203. CREATE_ELEMENT_VNODE,
  13204. CREATE_COMMENT,
  13205. CREATE_TEXT,
  13206. CREATE_STATIC
  13207. ]
  13208. .filter(helper => helpers.includes(helper))
  13209. .map(aliasHelper)
  13210. .join(', ');
  13211. push(`const { ${staticHelpers} } = _Vue\n`);
  13212. }
  13213. }
  13214. }
  13215. genHoists(ast.hoists, context);
  13216. newline();
  13217. push(`return `);
  13218. }
  13219. function genAssets(assets, type, { helper, push, newline, isTS }) {
  13220. const resolver = helper(type === 'component'
  13221. ? RESOLVE_COMPONENT
  13222. : RESOLVE_DIRECTIVE);
  13223. for (let i = 0; i < assets.length; i++) {
  13224. let id = assets[i];
  13225. // potential component implicit self-reference inferred from SFC filename
  13226. const maybeSelfReference = id.endsWith('__self');
  13227. if (maybeSelfReference) {
  13228. id = id.slice(0, -6);
  13229. }
  13230. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  13231. if (i < assets.length - 1) {
  13232. newline();
  13233. }
  13234. }
  13235. }
  13236. function genHoists(hoists, context) {
  13237. if (!hoists.length) {
  13238. return;
  13239. }
  13240. context.pure = true;
  13241. const { push, newline, helper, scopeId, mode } = context;
  13242. newline();
  13243. for (let i = 0; i < hoists.length; i++) {
  13244. const exp = hoists[i];
  13245. if (exp) {
  13246. push(`const _hoisted_${i + 1} = ${``}`);
  13247. genNode(exp, context);
  13248. newline();
  13249. }
  13250. }
  13251. context.pure = false;
  13252. }
  13253. function isText(n) {
  13254. return (isString(n) ||
  13255. n.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
  13256. n.type === 2 /* NodeTypes.TEXT */ ||
  13257. n.type === 5 /* NodeTypes.INTERPOLATION */ ||
  13258. n.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */);
  13259. }
  13260. function genNodeListAsArray(nodes, context) {
  13261. const multilines = nodes.length > 3 ||
  13262. (nodes.some(n => isArray(n) || !isText(n)));
  13263. context.push(`[`);
  13264. multilines && context.indent();
  13265. genNodeList(nodes, context, multilines);
  13266. multilines && context.deindent();
  13267. context.push(`]`);
  13268. }
  13269. function genNodeList(nodes, context, multilines = false, comma = true) {
  13270. const { push, newline } = context;
  13271. for (let i = 0; i < nodes.length; i++) {
  13272. const node = nodes[i];
  13273. if (isString(node)) {
  13274. push(node);
  13275. }
  13276. else if (isArray(node)) {
  13277. genNodeListAsArray(node, context);
  13278. }
  13279. else {
  13280. genNode(node, context);
  13281. }
  13282. if (i < nodes.length - 1) {
  13283. if (multilines) {
  13284. comma && push(',');
  13285. newline();
  13286. }
  13287. else {
  13288. comma && push(', ');
  13289. }
  13290. }
  13291. }
  13292. }
  13293. function genNode(node, context) {
  13294. if (isString(node)) {
  13295. context.push(node);
  13296. return;
  13297. }
  13298. if (isSymbol(node)) {
  13299. context.push(context.helper(node));
  13300. return;
  13301. }
  13302. switch (node.type) {
  13303. case 1 /* NodeTypes.ELEMENT */:
  13304. case 9 /* NodeTypes.IF */:
  13305. case 11 /* NodeTypes.FOR */:
  13306. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  13307. `Apply appropriate transforms first.`);
  13308. genNode(node.codegenNode, context);
  13309. break;
  13310. case 2 /* NodeTypes.TEXT */:
  13311. genText(node, context);
  13312. break;
  13313. case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
  13314. genExpression(node, context);
  13315. break;
  13316. case 5 /* NodeTypes.INTERPOLATION */:
  13317. genInterpolation(node, context);
  13318. break;
  13319. case 12 /* NodeTypes.TEXT_CALL */:
  13320. genNode(node.codegenNode, context);
  13321. break;
  13322. case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
  13323. genCompoundExpression(node, context);
  13324. break;
  13325. case 3 /* NodeTypes.COMMENT */:
  13326. genComment(node, context);
  13327. break;
  13328. case 13 /* NodeTypes.VNODE_CALL */:
  13329. genVNodeCall(node, context);
  13330. break;
  13331. case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
  13332. genCallExpression(node, context);
  13333. break;
  13334. case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
  13335. genObjectExpression(node, context);
  13336. break;
  13337. case 17 /* NodeTypes.JS_ARRAY_EXPRESSION */:
  13338. genArrayExpression(node, context);
  13339. break;
  13340. case 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */:
  13341. genFunctionExpression(node, context);
  13342. break;
  13343. case 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */:
  13344. genConditionalExpression(node, context);
  13345. break;
  13346. case 20 /* NodeTypes.JS_CACHE_EXPRESSION */:
  13347. genCacheExpression(node, context);
  13348. break;
  13349. case 21 /* NodeTypes.JS_BLOCK_STATEMENT */:
  13350. genNodeList(node.body, context, true, false);
  13351. break;
  13352. // SSR only types
  13353. case 22 /* NodeTypes.JS_TEMPLATE_LITERAL */:
  13354. break;
  13355. case 23 /* NodeTypes.JS_IF_STATEMENT */:
  13356. break;
  13357. case 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */:
  13358. break;
  13359. case 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */:
  13360. break;
  13361. case 26 /* NodeTypes.JS_RETURN_STATEMENT */:
  13362. break;
  13363. /* istanbul ignore next */
  13364. case 10 /* NodeTypes.IF_BRANCH */:
  13365. // noop
  13366. break;
  13367. default:
  13368. {
  13369. assert(false, `unhandled codegen node type: ${node.type}`);
  13370. // make sure we exhaust all possible types
  13371. const exhaustiveCheck = node;
  13372. return exhaustiveCheck;
  13373. }
  13374. }
  13375. }
  13376. function genText(node, context) {
  13377. context.push(JSON.stringify(node.content), node);
  13378. }
  13379. function genExpression(node, context) {
  13380. const { content, isStatic } = node;
  13381. context.push(isStatic ? JSON.stringify(content) : content, node);
  13382. }
  13383. function genInterpolation(node, context) {
  13384. const { push, helper, pure } = context;
  13385. if (pure)
  13386. push(PURE_ANNOTATION);
  13387. push(`${helper(TO_DISPLAY_STRING)}(`);
  13388. genNode(node.content, context);
  13389. push(`)`);
  13390. }
  13391. function genCompoundExpression(node, context) {
  13392. for (let i = 0; i < node.children.length; i++) {
  13393. const child = node.children[i];
  13394. if (isString(child)) {
  13395. context.push(child);
  13396. }
  13397. else {
  13398. genNode(child, context);
  13399. }
  13400. }
  13401. }
  13402. function genExpressionAsPropertyKey(node, context) {
  13403. const { push } = context;
  13404. if (node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
  13405. push(`[`);
  13406. genCompoundExpression(node, context);
  13407. push(`]`);
  13408. }
  13409. else if (node.isStatic) {
  13410. // only quote keys if necessary
  13411. const text = isSimpleIdentifier(node.content)
  13412. ? node.content
  13413. : JSON.stringify(node.content);
  13414. push(text, node);
  13415. }
  13416. else {
  13417. push(`[${node.content}]`, node);
  13418. }
  13419. }
  13420. function genComment(node, context) {
  13421. const { push, helper, pure } = context;
  13422. if (pure) {
  13423. push(PURE_ANNOTATION);
  13424. }
  13425. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  13426. }
  13427. function genVNodeCall(node, context) {
  13428. const { push, helper, pure } = context;
  13429. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  13430. if (directives) {
  13431. push(helper(WITH_DIRECTIVES) + `(`);
  13432. }
  13433. if (isBlock) {
  13434. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  13435. }
  13436. if (pure) {
  13437. push(PURE_ANNOTATION);
  13438. }
  13439. const callHelper = isBlock
  13440. ? getVNodeBlockHelper(context.inSSR, isComponent)
  13441. : getVNodeHelper(context.inSSR, isComponent);
  13442. push(helper(callHelper) + `(`, node);
  13443. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  13444. push(`)`);
  13445. if (isBlock) {
  13446. push(`)`);
  13447. }
  13448. if (directives) {
  13449. push(`, `);
  13450. genNode(directives, context);
  13451. push(`)`);
  13452. }
  13453. }
  13454. function genNullableArgs(args) {
  13455. let i = args.length;
  13456. while (i--) {
  13457. if (args[i] != null)
  13458. break;
  13459. }
  13460. return args.slice(0, i + 1).map(arg => arg || `null`);
  13461. }
  13462. // JavaScript
  13463. function genCallExpression(node, context) {
  13464. const { push, helper, pure } = context;
  13465. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  13466. if (pure) {
  13467. push(PURE_ANNOTATION);
  13468. }
  13469. push(callee + `(`, node);
  13470. genNodeList(node.arguments, context);
  13471. push(`)`);
  13472. }
  13473. function genObjectExpression(node, context) {
  13474. const { push, indent, deindent, newline } = context;
  13475. const { properties } = node;
  13476. if (!properties.length) {
  13477. push(`{}`, node);
  13478. return;
  13479. }
  13480. const multilines = properties.length > 1 ||
  13481. (properties.some(p => p.value.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */));
  13482. push(multilines ? `{` : `{ `);
  13483. multilines && indent();
  13484. for (let i = 0; i < properties.length; i++) {
  13485. const { key, value } = properties[i];
  13486. // key
  13487. genExpressionAsPropertyKey(key, context);
  13488. push(`: `);
  13489. // value
  13490. genNode(value, context);
  13491. if (i < properties.length - 1) {
  13492. // will only reach this if it's multilines
  13493. push(`,`);
  13494. newline();
  13495. }
  13496. }
  13497. multilines && deindent();
  13498. push(multilines ? `}` : ` }`);
  13499. }
  13500. function genArrayExpression(node, context) {
  13501. genNodeListAsArray(node.elements, context);
  13502. }
  13503. function genFunctionExpression(node, context) {
  13504. const { push, indent, deindent } = context;
  13505. const { params, returns, body, newline, isSlot } = node;
  13506. if (isSlot) {
  13507. // wrap slot functions with owner context
  13508. push(`_${helperNameMap[WITH_CTX]}(`);
  13509. }
  13510. push(`(`, node);
  13511. if (isArray(params)) {
  13512. genNodeList(params, context);
  13513. }
  13514. else if (params) {
  13515. genNode(params, context);
  13516. }
  13517. push(`) => `);
  13518. if (newline || body) {
  13519. push(`{`);
  13520. indent();
  13521. }
  13522. if (returns) {
  13523. if (newline) {
  13524. push(`return `);
  13525. }
  13526. if (isArray(returns)) {
  13527. genNodeListAsArray(returns, context);
  13528. }
  13529. else {
  13530. genNode(returns, context);
  13531. }
  13532. }
  13533. else if (body) {
  13534. genNode(body, context);
  13535. }
  13536. if (newline || body) {
  13537. deindent();
  13538. push(`}`);
  13539. }
  13540. if (isSlot) {
  13541. push(`)`);
  13542. }
  13543. }
  13544. function genConditionalExpression(node, context) {
  13545. const { test, consequent, alternate, newline: needNewline } = node;
  13546. const { push, indent, deindent, newline } = context;
  13547. if (test.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  13548. const needsParens = !isSimpleIdentifier(test.content);
  13549. needsParens && push(`(`);
  13550. genExpression(test, context);
  13551. needsParens && push(`)`);
  13552. }
  13553. else {
  13554. push(`(`);
  13555. genNode(test, context);
  13556. push(`)`);
  13557. }
  13558. needNewline && indent();
  13559. context.indentLevel++;
  13560. needNewline || push(` `);
  13561. push(`? `);
  13562. genNode(consequent, context);
  13563. context.indentLevel--;
  13564. needNewline && newline();
  13565. needNewline || push(` `);
  13566. push(`: `);
  13567. const isNested = alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */;
  13568. if (!isNested) {
  13569. context.indentLevel++;
  13570. }
  13571. genNode(alternate, context);
  13572. if (!isNested) {
  13573. context.indentLevel--;
  13574. }
  13575. needNewline && deindent(true /* without newline */);
  13576. }
  13577. function genCacheExpression(node, context) {
  13578. const { push, helper, indent, deindent, newline } = context;
  13579. push(`_cache[${node.index}] || (`);
  13580. if (node.isVNode) {
  13581. indent();
  13582. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  13583. newline();
  13584. }
  13585. push(`_cache[${node.index}] = `);
  13586. genNode(node.value, context);
  13587. if (node.isVNode) {
  13588. push(`,`);
  13589. newline();
  13590. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  13591. newline();
  13592. push(`_cache[${node.index}]`);
  13593. deindent();
  13594. }
  13595. push(`)`);
  13596. }
  13597. // these keywords should not appear inside expressions, but operators like
  13598. // 'typeof', 'instanceof', and 'in' are allowed
  13599. const prohibitedKeywordRE = new RegExp('\\b' +
  13600. ('arguments,await,break,case,catch,class,const,continue,debugger,default,' +
  13601. 'delete,do,else,export,extends,finally,for,function,if,import,let,new,' +
  13602. 'return,super,switch,throw,try,var,void,while,with,yield')
  13603. .split(',')
  13604. .join('\\b|\\b') +
  13605. '\\b');
  13606. // strip strings in expressions
  13607. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  13608. /**
  13609. * Validate a non-prefixed expression.
  13610. * This is only called when using the in-browser runtime compiler since it
  13611. * doesn't prefix expressions.
  13612. */
  13613. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  13614. const exp = node.content;
  13615. // empty expressions are validated per-directive since some directives
  13616. // do allow empty expressions.
  13617. if (!exp.trim()) {
  13618. return;
  13619. }
  13620. try {
  13621. new Function(asRawStatements
  13622. ? ` ${exp} `
  13623. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  13624. }
  13625. catch (e) {
  13626. let message = e.message;
  13627. const keywordMatch = exp
  13628. .replace(stripStringRE, '')
  13629. .match(prohibitedKeywordRE);
  13630. if (keywordMatch) {
  13631. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  13632. }
  13633. context.onError(createCompilerError(45 /* ErrorCodes.X_INVALID_EXPRESSION */, node.loc, undefined, message));
  13634. }
  13635. }
  13636. const transformExpression = (node, context) => {
  13637. if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
  13638. node.content = processExpression(node.content, context);
  13639. }
  13640. else if (node.type === 1 /* NodeTypes.ELEMENT */) {
  13641. // handle directives on element
  13642. for (let i = 0; i < node.props.length; i++) {
  13643. const dir = node.props[i];
  13644. // do not process for v-on & v-for since they are special handled
  13645. if (dir.type === 7 /* NodeTypes.DIRECTIVE */ && dir.name !== 'for') {
  13646. const exp = dir.exp;
  13647. const arg = dir.arg;
  13648. // do not process exp if this is v-on:arg - we need special handling
  13649. // for wrapping inline statements.
  13650. if (exp &&
  13651. exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  13652. !(dir.name === 'on' && arg)) {
  13653. dir.exp = processExpression(exp, context,
  13654. // slot args must be processed as function params
  13655. dir.name === 'slot');
  13656. }
  13657. if (arg && arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !arg.isStatic) {
  13658. dir.arg = processExpression(arg, context);
  13659. }
  13660. }
  13661. }
  13662. }
  13663. };
  13664. // Important: since this function uses Node.js only dependencies, it should
  13665. // always be used with a leading !true check so that it can be
  13666. // tree-shaken from the browser build.
  13667. function processExpression(node, context,
  13668. // some expressions like v-slot props & v-for aliases should be parsed as
  13669. // function params
  13670. asParams = false,
  13671. // v-on handler values may contain multiple statements
  13672. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  13673. {
  13674. {
  13675. // simple in-browser validation (same logic in 2.x)
  13676. validateBrowserExpression(node, context, asParams, asRawStatements);
  13677. }
  13678. return node;
  13679. }
  13680. }
  13681. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  13682. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  13683. // #1587: We need to dynamically increment the key based on the current
  13684. // node's sibling nodes, since chained v-if/else branches are
  13685. // rendered at the same depth
  13686. const siblings = context.parent.children;
  13687. let i = siblings.indexOf(ifNode);
  13688. let key = 0;
  13689. while (i-- >= 0) {
  13690. const sibling = siblings[i];
  13691. if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
  13692. key += sibling.branches.length;
  13693. }
  13694. }
  13695. // Exit callback. Complete the codegenNode when all children have been
  13696. // transformed.
  13697. return () => {
  13698. if (isRoot) {
  13699. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  13700. }
  13701. else {
  13702. // attach this branch's codegen node to the v-if root.
  13703. const parentCondition = getParentCondition(ifNode.codegenNode);
  13704. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  13705. }
  13706. };
  13707. });
  13708. });
  13709. // target-agnostic transform used for both Client and SSR
  13710. function processIf(node, dir, context, processCodegen) {
  13711. if (dir.name !== 'else' &&
  13712. (!dir.exp || !dir.exp.content.trim())) {
  13713. const loc = dir.exp ? dir.exp.loc : node.loc;
  13714. context.onError(createCompilerError(28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */, dir.loc));
  13715. dir.exp = createSimpleExpression(`true`, false, loc);
  13716. }
  13717. if (dir.exp) {
  13718. validateBrowserExpression(dir.exp, context);
  13719. }
  13720. if (dir.name === 'if') {
  13721. const branch = createIfBranch(node, dir);
  13722. const ifNode = {
  13723. type: 9 /* NodeTypes.IF */,
  13724. loc: node.loc,
  13725. branches: [branch]
  13726. };
  13727. context.replaceNode(ifNode);
  13728. if (processCodegen) {
  13729. return processCodegen(ifNode, branch, true);
  13730. }
  13731. }
  13732. else {
  13733. // locate the adjacent v-if
  13734. const siblings = context.parent.children;
  13735. const comments = [];
  13736. let i = siblings.indexOf(node);
  13737. while (i-- >= -1) {
  13738. const sibling = siblings[i];
  13739. if (sibling && sibling.type === 3 /* NodeTypes.COMMENT */) {
  13740. context.removeNode(sibling);
  13741. comments.unshift(sibling);
  13742. continue;
  13743. }
  13744. if (sibling &&
  13745. sibling.type === 2 /* NodeTypes.TEXT */ &&
  13746. !sibling.content.trim().length) {
  13747. context.removeNode(sibling);
  13748. continue;
  13749. }
  13750. if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
  13751. // Check if v-else was followed by v-else-if
  13752. if (dir.name === 'else-if' &&
  13753. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  13754. context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13755. }
  13756. // move the node to the if node's branches
  13757. context.removeNode();
  13758. const branch = createIfBranch(node, dir);
  13759. if (comments.length &&
  13760. // #3619 ignore comments if the v-if is direct child of <transition>
  13761. !(context.parent &&
  13762. context.parent.type === 1 /* NodeTypes.ELEMENT */ &&
  13763. isBuiltInType(context.parent.tag, 'transition'))) {
  13764. branch.children = [...comments, ...branch.children];
  13765. }
  13766. // check if user is forcing same key on different branches
  13767. {
  13768. const key = branch.userKey;
  13769. if (key) {
  13770. sibling.branches.forEach(({ userKey }) => {
  13771. if (isSameKey(userKey, key)) {
  13772. context.onError(createCompilerError(29 /* ErrorCodes.X_V_IF_SAME_KEY */, branch.userKey.loc));
  13773. }
  13774. });
  13775. }
  13776. }
  13777. sibling.branches.push(branch);
  13778. const onExit = processCodegen && processCodegen(sibling, branch, false);
  13779. // since the branch was removed, it will not be traversed.
  13780. // make sure to traverse here.
  13781. traverseNode(branch, context);
  13782. // call on exit
  13783. if (onExit)
  13784. onExit();
  13785. // make sure to reset currentNode after traversal to indicate this
  13786. // node has been removed.
  13787. context.currentNode = null;
  13788. }
  13789. else {
  13790. context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13791. }
  13792. break;
  13793. }
  13794. }
  13795. }
  13796. function createIfBranch(node, dir) {
  13797. const isTemplateIf = node.tagType === 3 /* ElementTypes.TEMPLATE */;
  13798. return {
  13799. type: 10 /* NodeTypes.IF_BRANCH */,
  13800. loc: node.loc,
  13801. condition: dir.name === 'else' ? undefined : dir.exp,
  13802. children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
  13803. userKey: findProp(node, `key`),
  13804. isTemplateIf
  13805. };
  13806. }
  13807. function createCodegenNodeForBranch(branch, keyIndex, context) {
  13808. if (branch.condition) {
  13809. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  13810. // make sure to pass in asBlock: true so that the comment node call
  13811. // closes the current block.
  13812. createCallExpression(context.helper(CREATE_COMMENT), [
  13813. '"v-if"' ,
  13814. 'true'
  13815. ]));
  13816. }
  13817. else {
  13818. return createChildrenCodegenNode(branch, keyIndex, context);
  13819. }
  13820. }
  13821. function createChildrenCodegenNode(branch, keyIndex, context) {
  13822. const { helper } = context;
  13823. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* ConstantTypes.CAN_HOIST */));
  13824. const { children } = branch;
  13825. const firstChild = children[0];
  13826. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* NodeTypes.ELEMENT */;
  13827. if (needFragmentWrapper) {
  13828. if (children.length === 1 && firstChild.type === 11 /* NodeTypes.FOR */) {
  13829. // optimize away nested fragments when child is a ForNode
  13830. const vnodeCall = firstChild.codegenNode;
  13831. injectProp(vnodeCall, keyProperty, context);
  13832. return vnodeCall;
  13833. }
  13834. else {
  13835. let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
  13836. let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
  13837. // check if the fragment actually contains a single valid child with
  13838. // the rest being comments
  13839. if (!branch.isTemplateIf &&
  13840. children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
  13841. patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
  13842. patchFlagText += `, ${PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
  13843. }
  13844. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  13845. }
  13846. }
  13847. else {
  13848. const ret = firstChild.codegenNode;
  13849. const vnodeCall = getMemoedVNodeCall(ret);
  13850. // Change createVNode to createBlock.
  13851. if (vnodeCall.type === 13 /* NodeTypes.VNODE_CALL */) {
  13852. makeBlock(vnodeCall, context);
  13853. }
  13854. // inject branch key
  13855. injectProp(vnodeCall, keyProperty, context);
  13856. return ret;
  13857. }
  13858. }
  13859. function isSameKey(a, b) {
  13860. if (!a || a.type !== b.type) {
  13861. return false;
  13862. }
  13863. if (a.type === 6 /* NodeTypes.ATTRIBUTE */) {
  13864. if (a.value.content !== b.value.content) {
  13865. return false;
  13866. }
  13867. }
  13868. else {
  13869. // directive
  13870. const exp = a.exp;
  13871. const branchExp = b.exp;
  13872. if (exp.type !== branchExp.type) {
  13873. return false;
  13874. }
  13875. if (exp.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
  13876. exp.isStatic !== branchExp.isStatic ||
  13877. exp.content !== branchExp.content) {
  13878. return false;
  13879. }
  13880. }
  13881. return true;
  13882. }
  13883. function getParentCondition(node) {
  13884. while (true) {
  13885. if (node.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
  13886. if (node.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
  13887. node = node.alternate;
  13888. }
  13889. else {
  13890. return node;
  13891. }
  13892. }
  13893. else if (node.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */) {
  13894. node = node.value;
  13895. }
  13896. }
  13897. }
  13898. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  13899. const { helper, removeHelper } = context;
  13900. return processFor(node, dir, context, forNode => {
  13901. // create the loop render function expression now, and add the
  13902. // iterator on exit after all children have been traversed
  13903. const renderExp = createCallExpression(helper(RENDER_LIST), [
  13904. forNode.source
  13905. ]);
  13906. const isTemplate = isTemplateNode(node);
  13907. const memo = findDir(node, 'memo');
  13908. const keyProp = findProp(node, `key`);
  13909. const keyExp = keyProp &&
  13910. (keyProp.type === 6 /* NodeTypes.ATTRIBUTE */
  13911. ? createSimpleExpression(keyProp.value.content, true)
  13912. : keyProp.exp);
  13913. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  13914. const isStableFragment = forNode.source.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  13915. forNode.source.constType > 0 /* ConstantTypes.NOT_CONSTANT */;
  13916. const fragmentFlag = isStableFragment
  13917. ? 64 /* PatchFlags.STABLE_FRAGMENT */
  13918. : keyProp
  13919. ? 128 /* PatchFlags.KEYED_FRAGMENT */
  13920. : 256 /* PatchFlags.UNKEYED_FRAGMENT */;
  13921. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  13922. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  13923. return () => {
  13924. // finish the codegen now that all children have been traversed
  13925. let childBlock;
  13926. const { children } = forNode;
  13927. // check <template v-for> key placement
  13928. if (isTemplate) {
  13929. node.children.some(c => {
  13930. if (c.type === 1 /* NodeTypes.ELEMENT */) {
  13931. const key = findProp(c, 'key');
  13932. if (key) {
  13933. context.onError(createCompilerError(33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  13934. return true;
  13935. }
  13936. }
  13937. });
  13938. }
  13939. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* NodeTypes.ELEMENT */;
  13940. const slotOutlet = isSlotOutlet(node)
  13941. ? node
  13942. : isTemplate &&
  13943. node.children.length === 1 &&
  13944. isSlotOutlet(node.children[0])
  13945. ? node.children[0] // api-extractor somehow fails to infer this
  13946. : null;
  13947. if (slotOutlet) {
  13948. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  13949. childBlock = slotOutlet.codegenNode;
  13950. if (isTemplate && keyProperty) {
  13951. // <template v-for="..." :key="..."><slot/></template>
  13952. // we need to inject the key to the renderSlot() call.
  13953. // the props for renderSlot is passed as the 3rd argument.
  13954. injectProp(childBlock, keyProperty, context);
  13955. }
  13956. }
  13957. else if (needFragmentWrapper) {
  13958. // <template v-for="..."> with text or multi-elements
  13959. // should generate a fragment block for each loop
  13960. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* PatchFlags.STABLE_FRAGMENT */ +
  13961. (` /* ${PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */]} */`
  13962. ), undefined, undefined, true, undefined, false /* isComponent */);
  13963. }
  13964. else {
  13965. // Normal element v-for. Directly use the child's codegenNode
  13966. // but mark it as a block.
  13967. childBlock = children[0]
  13968. .codegenNode;
  13969. if (isTemplate && keyProperty) {
  13970. injectProp(childBlock, keyProperty, context);
  13971. }
  13972. if (childBlock.isBlock !== !isStableFragment) {
  13973. if (childBlock.isBlock) {
  13974. // switch from block to vnode
  13975. removeHelper(OPEN_BLOCK);
  13976. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13977. }
  13978. else {
  13979. // switch from vnode to block
  13980. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13981. }
  13982. }
  13983. childBlock.isBlock = !isStableFragment;
  13984. if (childBlock.isBlock) {
  13985. helper(OPEN_BLOCK);
  13986. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13987. }
  13988. else {
  13989. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13990. }
  13991. }
  13992. if (memo) {
  13993. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  13994. createSimpleExpression(`_cached`)
  13995. ]));
  13996. loop.body = createBlockStatement([
  13997. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  13998. createCompoundExpression([
  13999. `if (_cached`,
  14000. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  14001. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  14002. ]),
  14003. createCompoundExpression([`const _item = `, childBlock]),
  14004. createSimpleExpression(`_item.memo = _memo`),
  14005. createSimpleExpression(`return _item`)
  14006. ]);
  14007. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  14008. }
  14009. else {
  14010. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  14011. }
  14012. };
  14013. });
  14014. });
  14015. // target-agnostic transform used for both Client and SSR
  14016. function processFor(node, dir, context, processCodegen) {
  14017. if (!dir.exp) {
  14018. context.onError(createCompilerError(31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */, dir.loc));
  14019. return;
  14020. }
  14021. const parseResult = parseForExpression(
  14022. // can only be simple expression because vFor transform is applied
  14023. // before expression transform.
  14024. dir.exp, context);
  14025. if (!parseResult) {
  14026. context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  14027. return;
  14028. }
  14029. const { addIdentifiers, removeIdentifiers, scopes } = context;
  14030. const { source, value, key, index } = parseResult;
  14031. const forNode = {
  14032. type: 11 /* NodeTypes.FOR */,
  14033. loc: dir.loc,
  14034. source,
  14035. valueAlias: value,
  14036. keyAlias: key,
  14037. objectIndexAlias: index,
  14038. parseResult,
  14039. children: isTemplateNode(node) ? node.children : [node]
  14040. };
  14041. context.replaceNode(forNode);
  14042. // bookkeeping
  14043. scopes.vFor++;
  14044. const onExit = processCodegen && processCodegen(forNode);
  14045. return () => {
  14046. scopes.vFor--;
  14047. if (onExit)
  14048. onExit();
  14049. };
  14050. }
  14051. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  14052. // This regex doesn't cover the case if key or index aliases have destructuring,
  14053. // but those do not make sense in the first place, so this works in practice.
  14054. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  14055. const stripParensRE = /^\(|\)$/g;
  14056. function parseForExpression(input, context) {
  14057. const loc = input.loc;
  14058. const exp = input.content;
  14059. const inMatch = exp.match(forAliasRE);
  14060. if (!inMatch)
  14061. return;
  14062. const [, LHS, RHS] = inMatch;
  14063. const result = {
  14064. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  14065. value: undefined,
  14066. key: undefined,
  14067. index: undefined
  14068. };
  14069. {
  14070. validateBrowserExpression(result.source, context);
  14071. }
  14072. let valueContent = LHS.trim().replace(stripParensRE, '').trim();
  14073. const trimmedOffset = LHS.indexOf(valueContent);
  14074. const iteratorMatch = valueContent.match(forIteratorRE);
  14075. if (iteratorMatch) {
  14076. valueContent = valueContent.replace(forIteratorRE, '').trim();
  14077. const keyContent = iteratorMatch[1].trim();
  14078. let keyOffset;
  14079. if (keyContent) {
  14080. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  14081. result.key = createAliasExpression(loc, keyContent, keyOffset);
  14082. {
  14083. validateBrowserExpression(result.key, context, true);
  14084. }
  14085. }
  14086. if (iteratorMatch[2]) {
  14087. const indexContent = iteratorMatch[2].trim();
  14088. if (indexContent) {
  14089. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  14090. ? keyOffset + keyContent.length
  14091. : trimmedOffset + valueContent.length));
  14092. {
  14093. validateBrowserExpression(result.index, context, true);
  14094. }
  14095. }
  14096. }
  14097. }
  14098. if (valueContent) {
  14099. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  14100. {
  14101. validateBrowserExpression(result.value, context, true);
  14102. }
  14103. }
  14104. return result;
  14105. }
  14106. function createAliasExpression(range, content, offset) {
  14107. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  14108. }
  14109. function createForLoopParams({ value, key, index }, memoArgs = []) {
  14110. return createParamsList([value, key, index, ...memoArgs]);
  14111. }
  14112. function createParamsList(args) {
  14113. let i = args.length;
  14114. while (i--) {
  14115. if (args[i])
  14116. break;
  14117. }
  14118. return args
  14119. .slice(0, i + 1)
  14120. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  14121. }
  14122. const defaultFallback = createSimpleExpression(`undefined`, false);
  14123. // A NodeTransform that:
  14124. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  14125. // by transformExpression. This is only applied in non-browser builds with
  14126. // { prefixIdentifiers: true }.
  14127. // 2. Track v-slot depths so that we know a slot is inside another slot.
  14128. // Note the exit callback is executed before buildSlots() on the same node,
  14129. // so only nested slots see positive numbers.
  14130. const trackSlotScopes = (node, context) => {
  14131. if (node.type === 1 /* NodeTypes.ELEMENT */ &&
  14132. (node.tagType === 1 /* ElementTypes.COMPONENT */ ||
  14133. node.tagType === 3 /* ElementTypes.TEMPLATE */)) {
  14134. // We are only checking non-empty v-slot here
  14135. // since we only care about slots that introduce scope variables.
  14136. const vSlot = findDir(node, 'slot');
  14137. if (vSlot) {
  14138. vSlot.exp;
  14139. context.scopes.vSlot++;
  14140. return () => {
  14141. context.scopes.vSlot--;
  14142. };
  14143. }
  14144. }
  14145. };
  14146. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  14147. // Instead of being a DirectiveTransform, v-slot processing is called during
  14148. // transformElement to build the slots object for a component.
  14149. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  14150. context.helper(WITH_CTX);
  14151. const { children, loc } = node;
  14152. const slotsProperties = [];
  14153. const dynamicSlots = [];
  14154. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  14155. // since it likely uses a scope variable.
  14156. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  14157. // 1. Check for slot with slotProps on component itself.
  14158. // <Comp v-slot="{ prop }"/>
  14159. const onComponentSlot = findDir(node, 'slot', true);
  14160. if (onComponentSlot) {
  14161. const { arg, exp } = onComponentSlot;
  14162. if (arg && !isStaticExp(arg)) {
  14163. hasDynamicSlots = true;
  14164. }
  14165. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  14166. }
  14167. // 2. Iterate through children and check for template slots
  14168. // <template v-slot:foo="{ prop }">
  14169. let hasTemplateSlots = false;
  14170. let hasNamedDefaultSlot = false;
  14171. const implicitDefaultChildren = [];
  14172. const seenSlotNames = new Set();
  14173. let conditionalBranchIndex = 0;
  14174. for (let i = 0; i < children.length; i++) {
  14175. const slotElement = children[i];
  14176. let slotDir;
  14177. if (!isTemplateNode(slotElement) ||
  14178. !(slotDir = findDir(slotElement, 'slot', true))) {
  14179. // not a <template v-slot>, skip.
  14180. if (slotElement.type !== 3 /* NodeTypes.COMMENT */) {
  14181. implicitDefaultChildren.push(slotElement);
  14182. }
  14183. continue;
  14184. }
  14185. if (onComponentSlot) {
  14186. // already has on-component slot - this is incorrect usage.
  14187. context.onError(createCompilerError(37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  14188. break;
  14189. }
  14190. hasTemplateSlots = true;
  14191. const { children: slotChildren, loc: slotLoc } = slotElement;
  14192. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  14193. // check if name is dynamic.
  14194. let staticSlotName;
  14195. if (isStaticExp(slotName)) {
  14196. staticSlotName = slotName ? slotName.content : `default`;
  14197. }
  14198. else {
  14199. hasDynamicSlots = true;
  14200. }
  14201. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  14202. // check if this slot is conditional (v-if/v-for)
  14203. let vIf;
  14204. let vElse;
  14205. let vFor;
  14206. if ((vIf = findDir(slotElement, 'if'))) {
  14207. hasDynamicSlots = true;
  14208. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback));
  14209. }
  14210. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  14211. // find adjacent v-if
  14212. let j = i;
  14213. let prev;
  14214. while (j--) {
  14215. prev = children[j];
  14216. if (prev.type !== 3 /* NodeTypes.COMMENT */) {
  14217. break;
  14218. }
  14219. }
  14220. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  14221. // remove node
  14222. children.splice(i, 1);
  14223. i--;
  14224. // attach this slot to previous conditional
  14225. let conditional = dynamicSlots[dynamicSlots.length - 1];
  14226. while (conditional.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
  14227. conditional = conditional.alternate;
  14228. }
  14229. conditional.alternate = vElse.exp
  14230. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback)
  14231. : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  14232. }
  14233. else {
  14234. context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  14235. }
  14236. }
  14237. else if ((vFor = findDir(slotElement, 'for'))) {
  14238. hasDynamicSlots = true;
  14239. const parseResult = vFor.parseResult ||
  14240. parseForExpression(vFor.exp, context);
  14241. if (parseResult) {
  14242. // Render the dynamic slots as an array and add it to the createSlot()
  14243. // args. The runtime knows how to handle it appropriately.
  14244. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  14245. parseResult.source,
  14246. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  14247. ]));
  14248. }
  14249. else {
  14250. context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  14251. }
  14252. }
  14253. else {
  14254. // check duplicate static names
  14255. if (staticSlotName) {
  14256. if (seenSlotNames.has(staticSlotName)) {
  14257. context.onError(createCompilerError(38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  14258. continue;
  14259. }
  14260. seenSlotNames.add(staticSlotName);
  14261. if (staticSlotName === 'default') {
  14262. hasNamedDefaultSlot = true;
  14263. }
  14264. }
  14265. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  14266. }
  14267. }
  14268. if (!onComponentSlot) {
  14269. const buildDefaultSlotProperty = (props, children) => {
  14270. const fn = buildSlotFn(props, children, loc);
  14271. return createObjectProperty(`default`, fn);
  14272. };
  14273. if (!hasTemplateSlots) {
  14274. // implicit default slot (on component)
  14275. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  14276. }
  14277. else if (implicitDefaultChildren.length &&
  14278. // #3766
  14279. // with whitespace: 'preserve', whitespaces between slots will end up in
  14280. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  14281. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  14282. // implicit default slot (mixed with named slots)
  14283. if (hasNamedDefaultSlot) {
  14284. context.onError(createCompilerError(39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  14285. }
  14286. else {
  14287. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  14288. }
  14289. }
  14290. }
  14291. const slotFlag = hasDynamicSlots
  14292. ? 2 /* SlotFlags.DYNAMIC */
  14293. : hasForwardedSlots(node.children)
  14294. ? 3 /* SlotFlags.FORWARDED */
  14295. : 1 /* SlotFlags.STABLE */;
  14296. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  14297. // 2 = compiled but dynamic = can skip normalization, but must run diff
  14298. // 1 = compiled and static = can skip normalization AND diff as optimized
  14299. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  14300. if (dynamicSlots.length) {
  14301. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  14302. slots,
  14303. createArrayExpression(dynamicSlots)
  14304. ]);
  14305. }
  14306. return {
  14307. slots,
  14308. hasDynamicSlots
  14309. };
  14310. }
  14311. function buildDynamicSlot(name, fn, index) {
  14312. const props = [
  14313. createObjectProperty(`name`, name),
  14314. createObjectProperty(`fn`, fn)
  14315. ];
  14316. if (index != null) {
  14317. props.push(createObjectProperty(`key`, createSimpleExpression(String(index), true)));
  14318. }
  14319. return createObjectExpression(props);
  14320. }
  14321. function hasForwardedSlots(children) {
  14322. for (let i = 0; i < children.length; i++) {
  14323. const child = children[i];
  14324. switch (child.type) {
  14325. case 1 /* NodeTypes.ELEMENT */:
  14326. if (child.tagType === 2 /* ElementTypes.SLOT */ ||
  14327. hasForwardedSlots(child.children)) {
  14328. return true;
  14329. }
  14330. break;
  14331. case 9 /* NodeTypes.IF */:
  14332. if (hasForwardedSlots(child.branches))
  14333. return true;
  14334. break;
  14335. case 10 /* NodeTypes.IF_BRANCH */:
  14336. case 11 /* NodeTypes.FOR */:
  14337. if (hasForwardedSlots(child.children))
  14338. return true;
  14339. break;
  14340. }
  14341. }
  14342. return false;
  14343. }
  14344. function isNonWhitespaceContent(node) {
  14345. if (node.type !== 2 /* NodeTypes.TEXT */ && node.type !== 12 /* NodeTypes.TEXT_CALL */)
  14346. return true;
  14347. return node.type === 2 /* NodeTypes.TEXT */
  14348. ? !!node.content.trim()
  14349. : isNonWhitespaceContent(node.content);
  14350. }
  14351. // some directive transforms (e.g. v-model) may return a symbol for runtime
  14352. // import, which should be used instead of a resolveDirective call.
  14353. const directiveImportMap = new WeakMap();
  14354. // generate a JavaScript AST for this element's codegen
  14355. const transformElement = (node, context) => {
  14356. // perform the work on exit, after all child expressions have been
  14357. // processed and merged.
  14358. return function postTransformElement() {
  14359. node = context.currentNode;
  14360. if (!(node.type === 1 /* NodeTypes.ELEMENT */ &&
  14361. (node.tagType === 0 /* ElementTypes.ELEMENT */ ||
  14362. node.tagType === 1 /* ElementTypes.COMPONENT */))) {
  14363. return;
  14364. }
  14365. const { tag, props } = node;
  14366. const isComponent = node.tagType === 1 /* ElementTypes.COMPONENT */;
  14367. // The goal of the transform is to create a codegenNode implementing the
  14368. // VNodeCall interface.
  14369. let vnodeTag = isComponent
  14370. ? resolveComponentType(node, context)
  14371. : `"${tag}"`;
  14372. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  14373. let vnodeProps;
  14374. let vnodeChildren;
  14375. let vnodePatchFlag;
  14376. let patchFlag = 0;
  14377. let vnodeDynamicProps;
  14378. let dynamicPropNames;
  14379. let vnodeDirectives;
  14380. let shouldUseBlock =
  14381. // dynamic component may resolve to plain elements
  14382. isDynamicComponent ||
  14383. vnodeTag === TELEPORT ||
  14384. vnodeTag === SUSPENSE ||
  14385. (!isComponent &&
  14386. // <svg> and <foreignObject> must be forced into blocks so that block
  14387. // updates inside get proper isSVG flag at runtime. (#639, #643)
  14388. // This is technically web-specific, but splitting the logic out of core
  14389. // leads to too much unnecessary complexity.
  14390. (tag === 'svg' || tag === 'foreignObject'));
  14391. // props
  14392. if (props.length > 0) {
  14393. const propsBuildResult = buildProps(node, context, undefined, isComponent, isDynamicComponent);
  14394. vnodeProps = propsBuildResult.props;
  14395. patchFlag = propsBuildResult.patchFlag;
  14396. dynamicPropNames = propsBuildResult.dynamicPropNames;
  14397. const directives = propsBuildResult.directives;
  14398. vnodeDirectives =
  14399. directives && directives.length
  14400. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  14401. : undefined;
  14402. if (propsBuildResult.shouldUseBlock) {
  14403. shouldUseBlock = true;
  14404. }
  14405. }
  14406. // children
  14407. if (node.children.length > 0) {
  14408. if (vnodeTag === KEEP_ALIVE) {
  14409. // Although a built-in component, we compile KeepAlive with raw children
  14410. // instead of slot functions so that it can be used inside Transition
  14411. // or other Transition-wrapping HOCs.
  14412. // To ensure correct updates with block optimizations, we need to:
  14413. // 1. Force keep-alive into a block. This avoids its children being
  14414. // collected by a parent block.
  14415. shouldUseBlock = true;
  14416. // 2. Force keep-alive to always be updated, since it uses raw children.
  14417. patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  14418. if (node.children.length > 1) {
  14419. context.onError(createCompilerError(46 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */, {
  14420. start: node.children[0].loc.start,
  14421. end: node.children[node.children.length - 1].loc.end,
  14422. source: ''
  14423. }));
  14424. }
  14425. }
  14426. const shouldBuildAsSlots = isComponent &&
  14427. // Teleport is not a real component and has dedicated runtime handling
  14428. vnodeTag !== TELEPORT &&
  14429. // explained above.
  14430. vnodeTag !== KEEP_ALIVE;
  14431. if (shouldBuildAsSlots) {
  14432. const { slots, hasDynamicSlots } = buildSlots(node, context);
  14433. vnodeChildren = slots;
  14434. if (hasDynamicSlots) {
  14435. patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
  14436. }
  14437. }
  14438. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  14439. const child = node.children[0];
  14440. const type = child.type;
  14441. // check for dynamic text children
  14442. const hasDynamicTextChild = type === 5 /* NodeTypes.INTERPOLATION */ ||
  14443. type === 8 /* NodeTypes.COMPOUND_EXPRESSION */;
  14444. if (hasDynamicTextChild &&
  14445. getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
  14446. patchFlag |= 1 /* PatchFlags.TEXT */;
  14447. }
  14448. // pass directly if the only child is a text node
  14449. // (plain / interpolation / expression)
  14450. if (hasDynamicTextChild || type === 2 /* NodeTypes.TEXT */) {
  14451. vnodeChildren = child;
  14452. }
  14453. else {
  14454. vnodeChildren = node.children;
  14455. }
  14456. }
  14457. else {
  14458. vnodeChildren = node.children;
  14459. }
  14460. }
  14461. // patchFlag & dynamicPropNames
  14462. if (patchFlag !== 0) {
  14463. {
  14464. if (patchFlag < 0) {
  14465. // special flags (negative and mutually exclusive)
  14466. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  14467. }
  14468. else {
  14469. // bitwise flags
  14470. const flagNames = Object.keys(PatchFlagNames)
  14471. .map(Number)
  14472. .filter(n => n > 0 && patchFlag & n)
  14473. .map(n => PatchFlagNames[n])
  14474. .join(`, `);
  14475. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  14476. }
  14477. }
  14478. if (dynamicPropNames && dynamicPropNames.length) {
  14479. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  14480. }
  14481. }
  14482. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  14483. };
  14484. };
  14485. function resolveComponentType(node, context, ssr = false) {
  14486. let { tag } = node;
  14487. // 1. dynamic component
  14488. const isExplicitDynamic = isComponentTag(tag);
  14489. const isProp = findProp(node, 'is');
  14490. if (isProp) {
  14491. if (isExplicitDynamic ||
  14492. (false )) {
  14493. const exp = isProp.type === 6 /* NodeTypes.ATTRIBUTE */
  14494. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  14495. : isProp.exp;
  14496. if (exp) {
  14497. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14498. exp
  14499. ]);
  14500. }
  14501. }
  14502. else if (isProp.type === 6 /* NodeTypes.ATTRIBUTE */ &&
  14503. isProp.value.content.startsWith('vue:')) {
  14504. // <button is="vue:xxx">
  14505. // if not <component>, only is value that starts with "vue:" will be
  14506. // treated as component by the parse phase and reach here, unless it's
  14507. // compat mode where all is values are considered components
  14508. tag = isProp.value.content.slice(4);
  14509. }
  14510. }
  14511. // 1.5 v-is (TODO: Deprecate)
  14512. const isDir = !isExplicitDynamic && findDir(node, 'is');
  14513. if (isDir && isDir.exp) {
  14514. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14515. isDir.exp
  14516. ]);
  14517. }
  14518. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  14519. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  14520. if (builtIn) {
  14521. // built-ins are simply fallthroughs / have special handling during ssr
  14522. // so we don't need to import their runtime equivalents
  14523. if (!ssr)
  14524. context.helper(builtIn);
  14525. return builtIn;
  14526. }
  14527. // 5. user component (resolve)
  14528. context.helper(RESOLVE_COMPONENT);
  14529. context.components.add(tag);
  14530. return toValidAssetId(tag, `component`);
  14531. }
  14532. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  14533. const { tag, loc: elementLoc, children } = node;
  14534. let properties = [];
  14535. const mergeArgs = [];
  14536. const runtimeDirectives = [];
  14537. const hasChildren = children.length > 0;
  14538. let shouldUseBlock = false;
  14539. // patchFlag analysis
  14540. let patchFlag = 0;
  14541. let hasRef = false;
  14542. let hasClassBinding = false;
  14543. let hasStyleBinding = false;
  14544. let hasHydrationEventBinding = false;
  14545. let hasDynamicKeys = false;
  14546. let hasVnodeHook = false;
  14547. const dynamicPropNames = [];
  14548. const pushMergeArg = (arg) => {
  14549. if (properties.length) {
  14550. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14551. properties = [];
  14552. }
  14553. if (arg)
  14554. mergeArgs.push(arg);
  14555. };
  14556. const analyzePatchFlag = ({ key, value }) => {
  14557. if (isStaticExp(key)) {
  14558. const name = key.content;
  14559. const isEventHandler = isOn(name);
  14560. if (isEventHandler &&
  14561. (!isComponent || isDynamicComponent) &&
  14562. // omit the flag for click handlers because hydration gives click
  14563. // dedicated fast path.
  14564. name.toLowerCase() !== 'onclick' &&
  14565. // omit v-model handlers
  14566. name !== 'onUpdate:modelValue' &&
  14567. // omit onVnodeXXX hooks
  14568. !isReservedProp(name)) {
  14569. hasHydrationEventBinding = true;
  14570. }
  14571. if (isEventHandler && isReservedProp(name)) {
  14572. hasVnodeHook = true;
  14573. }
  14574. if (value.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */ ||
  14575. ((value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
  14576. value.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) &&
  14577. getConstantType(value, context) > 0)) {
  14578. // skip if the prop is a cached handler or has constant value
  14579. return;
  14580. }
  14581. if (name === 'ref') {
  14582. hasRef = true;
  14583. }
  14584. else if (name === 'class') {
  14585. hasClassBinding = true;
  14586. }
  14587. else if (name === 'style') {
  14588. hasStyleBinding = true;
  14589. }
  14590. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  14591. dynamicPropNames.push(name);
  14592. }
  14593. // treat the dynamic class and style binding of the component as dynamic props
  14594. if (isComponent &&
  14595. (name === 'class' || name === 'style') &&
  14596. !dynamicPropNames.includes(name)) {
  14597. dynamicPropNames.push(name);
  14598. }
  14599. }
  14600. else {
  14601. hasDynamicKeys = true;
  14602. }
  14603. };
  14604. for (let i = 0; i < props.length; i++) {
  14605. // static attribute
  14606. const prop = props[i];
  14607. if (prop.type === 6 /* NodeTypes.ATTRIBUTE */) {
  14608. const { loc, name, value } = prop;
  14609. let isStatic = true;
  14610. if (name === 'ref') {
  14611. hasRef = true;
  14612. if (context.scopes.vFor > 0) {
  14613. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14614. }
  14615. }
  14616. // skip is on <component>, or is="vue:xxx"
  14617. if (name === 'is' &&
  14618. (isComponentTag(tag) ||
  14619. (value && value.content.startsWith('vue:')) ||
  14620. (false ))) {
  14621. continue;
  14622. }
  14623. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  14624. }
  14625. else {
  14626. // directives
  14627. const { name, arg, exp, loc } = prop;
  14628. const isVBind = name === 'bind';
  14629. const isVOn = name === 'on';
  14630. // skip v-slot - it is handled by its dedicated transform.
  14631. if (name === 'slot') {
  14632. if (!isComponent) {
  14633. context.onError(createCompilerError(40 /* ErrorCodes.X_V_SLOT_MISPLACED */, loc));
  14634. }
  14635. continue;
  14636. }
  14637. // skip v-once/v-memo - they are handled by dedicated transforms.
  14638. if (name === 'once' || name === 'memo') {
  14639. continue;
  14640. }
  14641. // skip v-is and :is on <component>
  14642. if (name === 'is' ||
  14643. (isVBind &&
  14644. isStaticArgOf(arg, 'is') &&
  14645. (isComponentTag(tag) ||
  14646. (false )))) {
  14647. continue;
  14648. }
  14649. // skip v-on in SSR compilation
  14650. if (isVOn && ssr) {
  14651. continue;
  14652. }
  14653. if (
  14654. // #938: elements with dynamic keys should be forced into blocks
  14655. (isVBind && isStaticArgOf(arg, 'key')) ||
  14656. // inline before-update hooks need to force block so that it is invoked
  14657. // before children
  14658. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  14659. shouldUseBlock = true;
  14660. }
  14661. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  14662. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14663. }
  14664. // special case for v-bind and v-on with no argument
  14665. if (!arg && (isVBind || isVOn)) {
  14666. hasDynamicKeys = true;
  14667. if (exp) {
  14668. if (isVBind) {
  14669. // have to merge early for compat build check
  14670. pushMergeArg();
  14671. mergeArgs.push(exp);
  14672. }
  14673. else {
  14674. // v-on="obj" -> toHandlers(obj)
  14675. pushMergeArg({
  14676. type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
  14677. loc,
  14678. callee: context.helper(TO_HANDLERS),
  14679. arguments: isComponent ? [exp] : [exp, `true`]
  14680. });
  14681. }
  14682. }
  14683. else {
  14684. context.onError(createCompilerError(isVBind
  14685. ? 34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */
  14686. : 35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
  14687. }
  14688. continue;
  14689. }
  14690. const directiveTransform = context.directiveTransforms[name];
  14691. if (directiveTransform) {
  14692. // has built-in directive transform.
  14693. const { props, needRuntime } = directiveTransform(prop, node, context);
  14694. !ssr && props.forEach(analyzePatchFlag);
  14695. if (isVOn && arg && !isStaticExp(arg)) {
  14696. pushMergeArg(createObjectExpression(props, elementLoc));
  14697. }
  14698. else {
  14699. properties.push(...props);
  14700. }
  14701. if (needRuntime) {
  14702. runtimeDirectives.push(prop);
  14703. if (isSymbol(needRuntime)) {
  14704. directiveImportMap.set(prop, needRuntime);
  14705. }
  14706. }
  14707. }
  14708. else if (!isBuiltInDirective(name)) {
  14709. // no built-in transform, this is a user custom directive.
  14710. runtimeDirectives.push(prop);
  14711. // custom dirs may use beforeUpdate so they need to force blocks
  14712. // to ensure before-update gets called before children update
  14713. if (hasChildren) {
  14714. shouldUseBlock = true;
  14715. }
  14716. }
  14717. }
  14718. }
  14719. let propsExpression = undefined;
  14720. // has v-bind="object" or v-on="object", wrap with mergeProps
  14721. if (mergeArgs.length) {
  14722. // close up any not-yet-merged props
  14723. pushMergeArg();
  14724. if (mergeArgs.length > 1) {
  14725. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  14726. }
  14727. else {
  14728. // single v-bind with nothing else - no need for a mergeProps call
  14729. propsExpression = mergeArgs[0];
  14730. }
  14731. }
  14732. else if (properties.length) {
  14733. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  14734. }
  14735. // patchFlag analysis
  14736. if (hasDynamicKeys) {
  14737. patchFlag |= 16 /* PatchFlags.FULL_PROPS */;
  14738. }
  14739. else {
  14740. if (hasClassBinding && !isComponent) {
  14741. patchFlag |= 2 /* PatchFlags.CLASS */;
  14742. }
  14743. if (hasStyleBinding && !isComponent) {
  14744. patchFlag |= 4 /* PatchFlags.STYLE */;
  14745. }
  14746. if (dynamicPropNames.length) {
  14747. patchFlag |= 8 /* PatchFlags.PROPS */;
  14748. }
  14749. if (hasHydrationEventBinding) {
  14750. patchFlag |= 32 /* PatchFlags.HYDRATE_EVENTS */;
  14751. }
  14752. }
  14753. if (!shouldUseBlock &&
  14754. (patchFlag === 0 || patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) &&
  14755. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  14756. patchFlag |= 512 /* PatchFlags.NEED_PATCH */;
  14757. }
  14758. // pre-normalize props, SSR is skipped for now
  14759. if (!context.inSSR && propsExpression) {
  14760. switch (propsExpression.type) {
  14761. case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
  14762. // means that there is no v-bind,
  14763. // but still need to deal with dynamic key binding
  14764. let classKeyIndex = -1;
  14765. let styleKeyIndex = -1;
  14766. let hasDynamicKey = false;
  14767. for (let i = 0; i < propsExpression.properties.length; i++) {
  14768. const key = propsExpression.properties[i].key;
  14769. if (isStaticExp(key)) {
  14770. if (key.content === 'class') {
  14771. classKeyIndex = i;
  14772. }
  14773. else if (key.content === 'style') {
  14774. styleKeyIndex = i;
  14775. }
  14776. }
  14777. else if (!key.isHandlerKey) {
  14778. hasDynamicKey = true;
  14779. }
  14780. }
  14781. const classProp = propsExpression.properties[classKeyIndex];
  14782. const styleProp = propsExpression.properties[styleKeyIndex];
  14783. // no dynamic key
  14784. if (!hasDynamicKey) {
  14785. if (classProp && !isStaticExp(classProp.value)) {
  14786. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  14787. }
  14788. if (styleProp &&
  14789. // the static style is compiled into an object,
  14790. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  14791. (hasStyleBinding ||
  14792. (styleProp.value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  14793. styleProp.value.content.trim()[0] === `[`) ||
  14794. // v-bind:style and style both exist,
  14795. // v-bind:style with static literal object
  14796. styleProp.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */)) {
  14797. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  14798. }
  14799. }
  14800. else {
  14801. // dynamic key binding, wrap with `normalizeProps`
  14802. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  14803. }
  14804. break;
  14805. case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
  14806. // mergeProps call, do nothing
  14807. break;
  14808. default:
  14809. // single v-bind
  14810. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  14811. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  14812. propsExpression
  14813. ])
  14814. ]);
  14815. break;
  14816. }
  14817. }
  14818. return {
  14819. props: propsExpression,
  14820. directives: runtimeDirectives,
  14821. patchFlag,
  14822. dynamicPropNames,
  14823. shouldUseBlock
  14824. };
  14825. }
  14826. // Dedupe props in an object literal.
  14827. // Literal duplicated attributes would have been warned during the parse phase,
  14828. // however, it's possible to encounter duplicated `onXXX` handlers with different
  14829. // modifiers. We also need to merge static and dynamic class / style attributes.
  14830. // - onXXX handlers / style: merge into array
  14831. // - class: merge into single expression with concatenation
  14832. function dedupeProperties(properties) {
  14833. const knownProps = new Map();
  14834. const deduped = [];
  14835. for (let i = 0; i < properties.length; i++) {
  14836. const prop = properties[i];
  14837. // dynamic keys are always allowed
  14838. if (prop.key.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  14839. deduped.push(prop);
  14840. continue;
  14841. }
  14842. const name = prop.key.content;
  14843. const existing = knownProps.get(name);
  14844. if (existing) {
  14845. if (name === 'style' || name === 'class' || isOn(name)) {
  14846. mergeAsArray(existing, prop);
  14847. }
  14848. // unexpected duplicate, should have emitted error during parse
  14849. }
  14850. else {
  14851. knownProps.set(name, prop);
  14852. deduped.push(prop);
  14853. }
  14854. }
  14855. return deduped;
  14856. }
  14857. function mergeAsArray(existing, incoming) {
  14858. if (existing.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */) {
  14859. existing.value.elements.push(incoming.value);
  14860. }
  14861. else {
  14862. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  14863. }
  14864. }
  14865. function buildDirectiveArgs(dir, context) {
  14866. const dirArgs = [];
  14867. const runtime = directiveImportMap.get(dir);
  14868. if (runtime) {
  14869. // built-in directive with runtime
  14870. dirArgs.push(context.helperString(runtime));
  14871. }
  14872. else {
  14873. {
  14874. // inject statement for resolving directive
  14875. context.helper(RESOLVE_DIRECTIVE);
  14876. context.directives.add(dir.name);
  14877. dirArgs.push(toValidAssetId(dir.name, `directive`));
  14878. }
  14879. }
  14880. const { loc } = dir;
  14881. if (dir.exp)
  14882. dirArgs.push(dir.exp);
  14883. if (dir.arg) {
  14884. if (!dir.exp) {
  14885. dirArgs.push(`void 0`);
  14886. }
  14887. dirArgs.push(dir.arg);
  14888. }
  14889. if (Object.keys(dir.modifiers).length) {
  14890. if (!dir.arg) {
  14891. if (!dir.exp) {
  14892. dirArgs.push(`void 0`);
  14893. }
  14894. dirArgs.push(`void 0`);
  14895. }
  14896. const trueExpression = createSimpleExpression(`true`, false, loc);
  14897. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  14898. }
  14899. return createArrayExpression(dirArgs, dir.loc);
  14900. }
  14901. function stringifyDynamicPropNames(props) {
  14902. let propsNamesString = `[`;
  14903. for (let i = 0, l = props.length; i < l; i++) {
  14904. propsNamesString += JSON.stringify(props[i]);
  14905. if (i < l - 1)
  14906. propsNamesString += ', ';
  14907. }
  14908. return propsNamesString + `]`;
  14909. }
  14910. function isComponentTag(tag) {
  14911. return tag === 'component' || tag === 'Component';
  14912. }
  14913. const transformSlotOutlet = (node, context) => {
  14914. if (isSlotOutlet(node)) {
  14915. const { children, loc } = node;
  14916. const { slotName, slotProps } = processSlotOutlet(node, context);
  14917. const slotArgs = [
  14918. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  14919. slotName,
  14920. '{}',
  14921. 'undefined',
  14922. 'true'
  14923. ];
  14924. let expectedLen = 2;
  14925. if (slotProps) {
  14926. slotArgs[2] = slotProps;
  14927. expectedLen = 3;
  14928. }
  14929. if (children.length) {
  14930. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  14931. expectedLen = 4;
  14932. }
  14933. if (context.scopeId && !context.slotted) {
  14934. expectedLen = 5;
  14935. }
  14936. slotArgs.splice(expectedLen); // remove unused arguments
  14937. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  14938. }
  14939. };
  14940. function processSlotOutlet(node, context) {
  14941. let slotName = `"default"`;
  14942. let slotProps = undefined;
  14943. const nonNameProps = [];
  14944. for (let i = 0; i < node.props.length; i++) {
  14945. const p = node.props[i];
  14946. if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
  14947. if (p.value) {
  14948. if (p.name === 'name') {
  14949. slotName = JSON.stringify(p.value.content);
  14950. }
  14951. else {
  14952. p.name = camelize(p.name);
  14953. nonNameProps.push(p);
  14954. }
  14955. }
  14956. }
  14957. else {
  14958. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  14959. if (p.exp)
  14960. slotName = p.exp;
  14961. }
  14962. else {
  14963. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  14964. p.arg.content = camelize(p.arg.content);
  14965. }
  14966. nonNameProps.push(p);
  14967. }
  14968. }
  14969. }
  14970. if (nonNameProps.length > 0) {
  14971. const { props, directives } = buildProps(node, context, nonNameProps, false, false);
  14972. slotProps = props;
  14973. if (directives.length) {
  14974. context.onError(createCompilerError(36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  14975. }
  14976. }
  14977. return {
  14978. slotName,
  14979. slotProps
  14980. };
  14981. }
  14982. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  14983. const transformOn$1 = (dir, node, context, augmentor) => {
  14984. const { loc, modifiers, arg } = dir;
  14985. if (!dir.exp && !modifiers.length) {
  14986. context.onError(createCompilerError(35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
  14987. }
  14988. let eventName;
  14989. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  14990. if (arg.isStatic) {
  14991. let rawName = arg.content;
  14992. // TODO deprecate @vnodeXXX usage
  14993. if (rawName.startsWith('vue:')) {
  14994. rawName = `vnode-${rawName.slice(4)}`;
  14995. }
  14996. const eventString = node.tagType !== 0 /* ElementTypes.ELEMENT */ ||
  14997. rawName.startsWith('vnode') ||
  14998. !/[A-Z]/.test(rawName)
  14999. ? // for non-element and vnode lifecycle event listeners, auto convert
  15000. // it to camelCase. See issue #2249
  15001. toHandlerKey(camelize(rawName))
  15002. : // preserve case for plain element listeners that have uppercase
  15003. // letters, as these may be custom elements' custom events
  15004. `on:${rawName}`;
  15005. eventName = createSimpleExpression(eventString, true, arg.loc);
  15006. }
  15007. else {
  15008. // #2388
  15009. eventName = createCompoundExpression([
  15010. `${context.helperString(TO_HANDLER_KEY)}(`,
  15011. arg,
  15012. `)`
  15013. ]);
  15014. }
  15015. }
  15016. else {
  15017. // already a compound expression.
  15018. eventName = arg;
  15019. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  15020. eventName.children.push(`)`);
  15021. }
  15022. // handler processing
  15023. let exp = dir.exp;
  15024. if (exp && !exp.content.trim()) {
  15025. exp = undefined;
  15026. }
  15027. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  15028. if (exp) {
  15029. const isMemberExp = isMemberExpression(exp.content);
  15030. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  15031. const hasMultipleStatements = exp.content.includes(`;`);
  15032. {
  15033. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  15034. }
  15035. if (isInlineStatement || (shouldCache && isMemberExp)) {
  15036. // wrap inline statement in a function expression
  15037. exp = createCompoundExpression([
  15038. `${isInlineStatement
  15039. ? `$event`
  15040. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  15041. exp,
  15042. hasMultipleStatements ? `}` : `)`
  15043. ]);
  15044. }
  15045. }
  15046. let ret = {
  15047. props: [
  15048. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  15049. ]
  15050. };
  15051. // apply extended compiler augmentor
  15052. if (augmentor) {
  15053. ret = augmentor(ret);
  15054. }
  15055. if (shouldCache) {
  15056. // cache handlers so that it's always the same handler being passed down.
  15057. // this avoids unnecessary re-renders when users use inline handlers on
  15058. // components.
  15059. ret.props[0].value = context.cache(ret.props[0].value);
  15060. }
  15061. // mark the key as handler for props normalization check
  15062. ret.props.forEach(p => (p.key.isHandlerKey = true));
  15063. return ret;
  15064. };
  15065. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  15066. // codegen for the entire props object. This transform here is only for v-bind
  15067. // *with* args.
  15068. const transformBind = (dir, _node, context) => {
  15069. const { exp, modifiers, loc } = dir;
  15070. const arg = dir.arg;
  15071. if (arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  15072. arg.children.unshift(`(`);
  15073. arg.children.push(`) || ""`);
  15074. }
  15075. else if (!arg.isStatic) {
  15076. arg.content = `${arg.content} || ""`;
  15077. }
  15078. // .sync is replaced by v-model:arg
  15079. if (modifiers.includes('camel')) {
  15080. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  15081. if (arg.isStatic) {
  15082. arg.content = camelize(arg.content);
  15083. }
  15084. else {
  15085. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  15086. }
  15087. }
  15088. else {
  15089. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  15090. arg.children.push(`)`);
  15091. }
  15092. }
  15093. if (!context.inSSR) {
  15094. if (modifiers.includes('prop')) {
  15095. injectPrefix(arg, '.');
  15096. }
  15097. if (modifiers.includes('attr')) {
  15098. injectPrefix(arg, '^');
  15099. }
  15100. }
  15101. if (!exp ||
  15102. (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  15103. context.onError(createCompilerError(34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */, loc));
  15104. return {
  15105. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  15106. };
  15107. }
  15108. return {
  15109. props: [createObjectProperty(arg, exp)]
  15110. };
  15111. };
  15112. const injectPrefix = (arg, prefix) => {
  15113. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  15114. if (arg.isStatic) {
  15115. arg.content = prefix + arg.content;
  15116. }
  15117. else {
  15118. arg.content = `\`${prefix}\${${arg.content}}\``;
  15119. }
  15120. }
  15121. else {
  15122. arg.children.unshift(`'${prefix}' + (`);
  15123. arg.children.push(`)`);
  15124. }
  15125. };
  15126. // Merge adjacent text nodes and expressions into a single expression
  15127. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  15128. const transformText = (node, context) => {
  15129. if (node.type === 0 /* NodeTypes.ROOT */ ||
  15130. node.type === 1 /* NodeTypes.ELEMENT */ ||
  15131. node.type === 11 /* NodeTypes.FOR */ ||
  15132. node.type === 10 /* NodeTypes.IF_BRANCH */) {
  15133. // perform the transform on node exit so that all expressions have already
  15134. // been processed.
  15135. return () => {
  15136. const children = node.children;
  15137. let currentContainer = undefined;
  15138. let hasText = false;
  15139. for (let i = 0; i < children.length; i++) {
  15140. const child = children[i];
  15141. if (isText$1(child)) {
  15142. hasText = true;
  15143. for (let j = i + 1; j < children.length; j++) {
  15144. const next = children[j];
  15145. if (isText$1(next)) {
  15146. if (!currentContainer) {
  15147. currentContainer = children[i] = createCompoundExpression([child], child.loc);
  15148. }
  15149. // merge adjacent text node into current
  15150. currentContainer.children.push(` + `, next);
  15151. children.splice(j, 1);
  15152. j--;
  15153. }
  15154. else {
  15155. currentContainer = undefined;
  15156. break;
  15157. }
  15158. }
  15159. }
  15160. }
  15161. if (!hasText ||
  15162. // if this is a plain element with a single text child, leave it
  15163. // as-is since the runtime has dedicated fast path for this by directly
  15164. // setting textContent of the element.
  15165. // for component root it's always normalized anyway.
  15166. (children.length === 1 &&
  15167. (node.type === 0 /* NodeTypes.ROOT */ ||
  15168. (node.type === 1 /* NodeTypes.ELEMENT */ &&
  15169. node.tagType === 0 /* ElementTypes.ELEMENT */ &&
  15170. // #3756
  15171. // custom directives can potentially add DOM elements arbitrarily,
  15172. // we need to avoid setting textContent of the element at runtime
  15173. // to avoid accidentally overwriting the DOM elements added
  15174. // by the user through custom directives.
  15175. !node.props.find(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
  15176. !context.directiveTransforms[p.name]) &&
  15177. // in compat mode, <template> tags with no special directives
  15178. // will be rendered as a fragment so its children must be
  15179. // converted into vnodes.
  15180. !(false ))))) {
  15181. return;
  15182. }
  15183. // pre-convert text nodes into createTextVNode(text) calls to avoid
  15184. // runtime normalization.
  15185. for (let i = 0; i < children.length; i++) {
  15186. const child = children[i];
  15187. if (isText$1(child) || child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
  15188. const callArgs = [];
  15189. // createTextVNode defaults to single whitespace, so if it is a
  15190. // single space the code could be an empty call to save bytes.
  15191. if (child.type !== 2 /* NodeTypes.TEXT */ || child.content !== ' ') {
  15192. callArgs.push(child);
  15193. }
  15194. // mark dynamic text with flag so it gets patched inside a block
  15195. if (!context.ssr &&
  15196. getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
  15197. callArgs.push(1 /* PatchFlags.TEXT */ +
  15198. (` /* ${PatchFlagNames[1 /* PatchFlags.TEXT */]} */` ));
  15199. }
  15200. children[i] = {
  15201. type: 12 /* NodeTypes.TEXT_CALL */,
  15202. content: child,
  15203. loc: child.loc,
  15204. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  15205. };
  15206. }
  15207. }
  15208. };
  15209. }
  15210. };
  15211. const seen$1 = new WeakSet();
  15212. const transformOnce = (node, context) => {
  15213. if (node.type === 1 /* NodeTypes.ELEMENT */ && findDir(node, 'once', true)) {
  15214. if (seen$1.has(node) || context.inVOnce) {
  15215. return;
  15216. }
  15217. seen$1.add(node);
  15218. context.inVOnce = true;
  15219. context.helper(SET_BLOCK_TRACKING);
  15220. return () => {
  15221. context.inVOnce = false;
  15222. const cur = context.currentNode;
  15223. if (cur.codegenNode) {
  15224. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  15225. }
  15226. };
  15227. }
  15228. };
  15229. const transformModel$1 = (dir, node, context) => {
  15230. const { exp, arg } = dir;
  15231. if (!exp) {
  15232. context.onError(createCompilerError(41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */, dir.loc));
  15233. return createTransformProps();
  15234. }
  15235. const rawExp = exp.loc.source;
  15236. const expString = exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  15237. // im SFC <script setup> inline mode, the exp may have been transformed into
  15238. // _unref(exp)
  15239. const bindingType = context.bindingMetadata[rawExp];
  15240. // check props
  15241. if (bindingType === "props" /* BindingTypes.PROPS */ ||
  15242. bindingType === "props-aliased" /* BindingTypes.PROPS_ALIASED */) {
  15243. context.onError(createCompilerError(44 /* ErrorCodes.X_V_MODEL_ON_PROPS */, exp.loc));
  15244. return createTransformProps();
  15245. }
  15246. const maybeRef = !true ;
  15247. if (!expString.trim() ||
  15248. (!isMemberExpression(expString) && !maybeRef)) {
  15249. context.onError(createCompilerError(42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  15250. return createTransformProps();
  15251. }
  15252. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  15253. const eventName = arg
  15254. ? isStaticExp(arg)
  15255. ? `onUpdate:${camelize(arg.content)}`
  15256. : createCompoundExpression(['"onUpdate:" + ', arg])
  15257. : `onUpdate:modelValue`;
  15258. let assignmentExp;
  15259. const eventArg = context.isTS ? `($event: any)` : `$event`;
  15260. {
  15261. assignmentExp = createCompoundExpression([
  15262. `${eventArg} => ((`,
  15263. exp,
  15264. `) = $event)`
  15265. ]);
  15266. }
  15267. const props = [
  15268. // modelValue: foo
  15269. createObjectProperty(propName, dir.exp),
  15270. // "onUpdate:modelValue": $event => (foo = $event)
  15271. createObjectProperty(eventName, assignmentExp)
  15272. ];
  15273. // modelModifiers: { foo: true, "bar-baz": true }
  15274. if (dir.modifiers.length && node.tagType === 1 /* ElementTypes.COMPONENT */) {
  15275. const modifiers = dir.modifiers
  15276. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  15277. .join(`, `);
  15278. const modifiersKey = arg
  15279. ? isStaticExp(arg)
  15280. ? `${arg.content}Modifiers`
  15281. : createCompoundExpression([arg, ' + "Modifiers"'])
  15282. : `modelModifiers`;
  15283. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* ConstantTypes.CAN_HOIST */)));
  15284. }
  15285. return createTransformProps(props);
  15286. };
  15287. function createTransformProps(props = []) {
  15288. return { props };
  15289. }
  15290. const seen = new WeakSet();
  15291. const transformMemo = (node, context) => {
  15292. if (node.type === 1 /* NodeTypes.ELEMENT */) {
  15293. const dir = findDir(node, 'memo');
  15294. if (!dir || seen.has(node)) {
  15295. return;
  15296. }
  15297. seen.add(node);
  15298. return () => {
  15299. const codegenNode = node.codegenNode ||
  15300. context.currentNode.codegenNode;
  15301. if (codegenNode && codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
  15302. // non-component sub tree should be turned into a block
  15303. if (node.tagType !== 1 /* ElementTypes.COMPONENT */) {
  15304. makeBlock(codegenNode, context);
  15305. }
  15306. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  15307. dir.exp,
  15308. createFunctionExpression(undefined, codegenNode),
  15309. `_cache`,
  15310. String(context.cached++)
  15311. ]);
  15312. }
  15313. };
  15314. }
  15315. };
  15316. function getBaseTransformPreset(prefixIdentifiers) {
  15317. return [
  15318. [
  15319. transformOnce,
  15320. transformIf,
  15321. transformMemo,
  15322. transformFor,
  15323. ...([]),
  15324. ...([transformExpression]
  15325. ),
  15326. transformSlotOutlet,
  15327. transformElement,
  15328. trackSlotScopes,
  15329. transformText
  15330. ],
  15331. {
  15332. on: transformOn$1,
  15333. bind: transformBind,
  15334. model: transformModel$1
  15335. }
  15336. ];
  15337. }
  15338. // we name it `baseCompile` so that higher order compilers like
  15339. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  15340. function baseCompile(template, options = {}) {
  15341. const onError = options.onError || defaultOnError;
  15342. const isModuleMode = options.mode === 'module';
  15343. /* istanbul ignore if */
  15344. {
  15345. if (options.prefixIdentifiers === true) {
  15346. onError(createCompilerError(47 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */));
  15347. }
  15348. else if (isModuleMode) {
  15349. onError(createCompilerError(48 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */));
  15350. }
  15351. }
  15352. const prefixIdentifiers = !true ;
  15353. if (options.cacheHandlers) {
  15354. onError(createCompilerError(49 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */));
  15355. }
  15356. if (options.scopeId && !isModuleMode) {
  15357. onError(createCompilerError(50 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */));
  15358. }
  15359. const ast = isString(template) ? baseParse(template, options) : template;
  15360. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  15361. transform(ast, extend({}, options, {
  15362. prefixIdentifiers,
  15363. nodeTransforms: [
  15364. ...nodeTransforms,
  15365. ...(options.nodeTransforms || []) // user transforms
  15366. ],
  15367. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  15368. )
  15369. }));
  15370. return generate(ast, extend({}, options, {
  15371. prefixIdentifiers
  15372. }));
  15373. }
  15374. const noopDirectiveTransform = () => ({ props: [] });
  15375. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  15376. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  15377. const V_MODEL_TEXT = Symbol(`vModelText` );
  15378. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  15379. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  15380. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  15381. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  15382. const V_SHOW = Symbol(`vShow` );
  15383. const TRANSITION = Symbol(`Transition` );
  15384. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  15385. registerRuntimeHelpers({
  15386. [V_MODEL_RADIO]: `vModelRadio`,
  15387. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  15388. [V_MODEL_TEXT]: `vModelText`,
  15389. [V_MODEL_SELECT]: `vModelSelect`,
  15390. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  15391. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  15392. [V_ON_WITH_KEYS]: `withKeys`,
  15393. [V_SHOW]: `vShow`,
  15394. [TRANSITION]: `Transition`,
  15395. [TRANSITION_GROUP]: `TransitionGroup`
  15396. });
  15397. /* eslint-disable no-restricted-globals */
  15398. let decoder;
  15399. function decodeHtmlBrowser(raw, asAttr = false) {
  15400. if (!decoder) {
  15401. decoder = document.createElement('div');
  15402. }
  15403. if (asAttr) {
  15404. decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
  15405. return decoder.children[0].getAttribute('foo');
  15406. }
  15407. else {
  15408. decoder.innerHTML = raw;
  15409. return decoder.textContent;
  15410. }
  15411. }
  15412. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  15413. const parserOptions = {
  15414. isVoidTag,
  15415. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  15416. isPreTag: tag => tag === 'pre',
  15417. decodeEntities: decodeHtmlBrowser ,
  15418. isBuiltInComponent: (tag) => {
  15419. if (isBuiltInType(tag, `Transition`)) {
  15420. return TRANSITION;
  15421. }
  15422. else if (isBuiltInType(tag, `TransitionGroup`)) {
  15423. return TRANSITION_GROUP;
  15424. }
  15425. },
  15426. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  15427. getNamespace(tag, parent) {
  15428. let ns = parent ? parent.ns : 0 /* DOMNamespaces.HTML */;
  15429. if (parent && ns === 2 /* DOMNamespaces.MATH_ML */) {
  15430. if (parent.tag === 'annotation-xml') {
  15431. if (tag === 'svg') {
  15432. return 1 /* DOMNamespaces.SVG */;
  15433. }
  15434. if (parent.props.some(a => a.type === 6 /* NodeTypes.ATTRIBUTE */ &&
  15435. a.name === 'encoding' &&
  15436. a.value != null &&
  15437. (a.value.content === 'text/html' ||
  15438. a.value.content === 'application/xhtml+xml'))) {
  15439. ns = 0 /* DOMNamespaces.HTML */;
  15440. }
  15441. }
  15442. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  15443. tag !== 'mglyph' &&
  15444. tag !== 'malignmark') {
  15445. ns = 0 /* DOMNamespaces.HTML */;
  15446. }
  15447. }
  15448. else if (parent && ns === 1 /* DOMNamespaces.SVG */) {
  15449. if (parent.tag === 'foreignObject' ||
  15450. parent.tag === 'desc' ||
  15451. parent.tag === 'title') {
  15452. ns = 0 /* DOMNamespaces.HTML */;
  15453. }
  15454. }
  15455. if (ns === 0 /* DOMNamespaces.HTML */) {
  15456. if (tag === 'svg') {
  15457. return 1 /* DOMNamespaces.SVG */;
  15458. }
  15459. if (tag === 'math') {
  15460. return 2 /* DOMNamespaces.MATH_ML */;
  15461. }
  15462. }
  15463. return ns;
  15464. },
  15465. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  15466. getTextMode({ tag, ns }) {
  15467. if (ns === 0 /* DOMNamespaces.HTML */) {
  15468. if (tag === 'textarea' || tag === 'title') {
  15469. return 1 /* TextModes.RCDATA */;
  15470. }
  15471. if (isRawTextContainer(tag)) {
  15472. return 2 /* TextModes.RAWTEXT */;
  15473. }
  15474. }
  15475. return 0 /* TextModes.DATA */;
  15476. }
  15477. };
  15478. // Parse inline CSS strings for static style attributes into an object.
  15479. // This is a NodeTransform since it works on the static `style` attribute and
  15480. // converts it into a dynamic equivalent:
  15481. // style="color: red" -> :style='{ "color": "red" }'
  15482. // It is then processed by `transformElement` and included in the generated
  15483. // props.
  15484. const transformStyle = node => {
  15485. if (node.type === 1 /* NodeTypes.ELEMENT */) {
  15486. node.props.forEach((p, i) => {
  15487. if (p.type === 6 /* NodeTypes.ATTRIBUTE */ && p.name === 'style' && p.value) {
  15488. // replace p with an expression node
  15489. node.props[i] = {
  15490. type: 7 /* NodeTypes.DIRECTIVE */,
  15491. name: `bind`,
  15492. arg: createSimpleExpression(`style`, true, p.loc),
  15493. exp: parseInlineCSS(p.value.content, p.loc),
  15494. modifiers: [],
  15495. loc: p.loc
  15496. };
  15497. }
  15498. });
  15499. }
  15500. };
  15501. const parseInlineCSS = (cssText, loc) => {
  15502. const normalized = parseStringStyle(cssText);
  15503. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
  15504. };
  15505. function createDOMCompilerError(code, loc) {
  15506. return createCompilerError(code, loc, DOMErrorMessages );
  15507. }
  15508. const DOMErrorMessages = {
  15509. [51 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  15510. [52 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  15511. [53 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  15512. [54 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  15513. [55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  15514. [56 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  15515. [57 /* DOMErrorCodes.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.`,
  15516. [58 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  15517. [59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  15518. [60 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  15519. [61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  15520. };
  15521. const transformVHtml = (dir, node, context) => {
  15522. const { exp, loc } = dir;
  15523. if (!exp) {
  15524. context.onError(createDOMCompilerError(51 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */, loc));
  15525. }
  15526. if (node.children.length) {
  15527. context.onError(createDOMCompilerError(52 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */, loc));
  15528. node.children.length = 0;
  15529. }
  15530. return {
  15531. props: [
  15532. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  15533. ]
  15534. };
  15535. };
  15536. const transformVText = (dir, node, context) => {
  15537. const { exp, loc } = dir;
  15538. if (!exp) {
  15539. context.onError(createDOMCompilerError(53 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */, loc));
  15540. }
  15541. if (node.children.length) {
  15542. context.onError(createDOMCompilerError(54 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */, loc));
  15543. node.children.length = 0;
  15544. }
  15545. return {
  15546. props: [
  15547. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  15548. ? getConstantType(exp, context) > 0
  15549. ? exp
  15550. : createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  15551. : createSimpleExpression('', true))
  15552. ]
  15553. };
  15554. };
  15555. const transformModel = (dir, node, context) => {
  15556. const baseResult = transformModel$1(dir, node, context);
  15557. // base transform has errors OR component v-model (only need props)
  15558. if (!baseResult.props.length || node.tagType === 1 /* ElementTypes.COMPONENT */) {
  15559. return baseResult;
  15560. }
  15561. if (dir.arg) {
  15562. context.onError(createDOMCompilerError(56 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  15563. }
  15564. function checkDuplicatedValue() {
  15565. const value = findProp(node, 'value');
  15566. if (value) {
  15567. context.onError(createDOMCompilerError(58 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  15568. }
  15569. }
  15570. const { tag } = node;
  15571. const isCustomElement = context.isCustomElement(tag);
  15572. if (tag === 'input' ||
  15573. tag === 'textarea' ||
  15574. tag === 'select' ||
  15575. isCustomElement) {
  15576. let directiveToUse = V_MODEL_TEXT;
  15577. let isInvalidType = false;
  15578. if (tag === 'input' || isCustomElement) {
  15579. const type = findProp(node, `type`);
  15580. if (type) {
  15581. if (type.type === 7 /* NodeTypes.DIRECTIVE */) {
  15582. // :type="foo"
  15583. directiveToUse = V_MODEL_DYNAMIC;
  15584. }
  15585. else if (type.value) {
  15586. switch (type.value.content) {
  15587. case 'radio':
  15588. directiveToUse = V_MODEL_RADIO;
  15589. break;
  15590. case 'checkbox':
  15591. directiveToUse = V_MODEL_CHECKBOX;
  15592. break;
  15593. case 'file':
  15594. isInvalidType = true;
  15595. context.onError(createDOMCompilerError(57 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  15596. break;
  15597. default:
  15598. // text type
  15599. checkDuplicatedValue();
  15600. break;
  15601. }
  15602. }
  15603. }
  15604. else if (hasDynamicKeyVBind(node)) {
  15605. // element has bindings with dynamic keys, which can possibly contain
  15606. // "type".
  15607. directiveToUse = V_MODEL_DYNAMIC;
  15608. }
  15609. else {
  15610. // text type
  15611. checkDuplicatedValue();
  15612. }
  15613. }
  15614. else if (tag === 'select') {
  15615. directiveToUse = V_MODEL_SELECT;
  15616. }
  15617. else {
  15618. // textarea
  15619. checkDuplicatedValue();
  15620. }
  15621. // inject runtime directive
  15622. // by returning the helper symbol via needRuntime
  15623. // the import will replaced a resolveDirective call.
  15624. if (!isInvalidType) {
  15625. baseResult.needRuntime = context.helper(directiveToUse);
  15626. }
  15627. }
  15628. else {
  15629. context.onError(createDOMCompilerError(55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  15630. }
  15631. // native vmodel doesn't need the `modelValue` props since they are also
  15632. // passed to the runtime as `binding.value`. removing it reduces code size.
  15633. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
  15634. p.key.content === 'modelValue'));
  15635. return baseResult;
  15636. };
  15637. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  15638. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  15639. // event propagation management
  15640. `stop,prevent,self,` +
  15641. // system modifiers + exact
  15642. `ctrl,shift,alt,meta,exact,` +
  15643. // mouse
  15644. `middle`);
  15645. // left & right could be mouse or key modifiers based on event type
  15646. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  15647. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  15648. const resolveModifiers = (key, modifiers, context, loc) => {
  15649. const keyModifiers = [];
  15650. const nonKeyModifiers = [];
  15651. const eventOptionModifiers = [];
  15652. for (let i = 0; i < modifiers.length; i++) {
  15653. const modifier = modifiers[i];
  15654. if (isEventOptionModifier(modifier)) {
  15655. // eventOptionModifiers: modifiers for addEventListener() options,
  15656. // e.g. .passive & .capture
  15657. eventOptionModifiers.push(modifier);
  15658. }
  15659. else {
  15660. // runtimeModifiers: modifiers that needs runtime guards
  15661. if (maybeKeyModifier(modifier)) {
  15662. if (isStaticExp(key)) {
  15663. if (isKeyboardEvent(key.content)) {
  15664. keyModifiers.push(modifier);
  15665. }
  15666. else {
  15667. nonKeyModifiers.push(modifier);
  15668. }
  15669. }
  15670. else {
  15671. keyModifiers.push(modifier);
  15672. nonKeyModifiers.push(modifier);
  15673. }
  15674. }
  15675. else {
  15676. if (isNonKeyModifier(modifier)) {
  15677. nonKeyModifiers.push(modifier);
  15678. }
  15679. else {
  15680. keyModifiers.push(modifier);
  15681. }
  15682. }
  15683. }
  15684. }
  15685. return {
  15686. keyModifiers,
  15687. nonKeyModifiers,
  15688. eventOptionModifiers
  15689. };
  15690. };
  15691. const transformClick = (key, event) => {
  15692. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  15693. return isStaticClick
  15694. ? createSimpleExpression(event, true)
  15695. : key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */
  15696. ? createCompoundExpression([
  15697. `(`,
  15698. key,
  15699. `) === "onClick" ? "${event}" : (`,
  15700. key,
  15701. `)`
  15702. ])
  15703. : key;
  15704. };
  15705. const transformOn = (dir, node, context) => {
  15706. return transformOn$1(dir, node, context, baseResult => {
  15707. const { modifiers } = dir;
  15708. if (!modifiers.length)
  15709. return baseResult;
  15710. let { key, value: handlerExp } = baseResult.props[0];
  15711. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  15712. // normalize click.right and click.middle since they don't actually fire
  15713. if (nonKeyModifiers.includes('right')) {
  15714. key = transformClick(key, `onContextmenu`);
  15715. }
  15716. if (nonKeyModifiers.includes('middle')) {
  15717. key = transformClick(key, `onMouseup`);
  15718. }
  15719. if (nonKeyModifiers.length) {
  15720. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  15721. handlerExp,
  15722. JSON.stringify(nonKeyModifiers)
  15723. ]);
  15724. }
  15725. if (keyModifiers.length &&
  15726. // if event name is dynamic, always wrap with keys guard
  15727. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  15728. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  15729. handlerExp,
  15730. JSON.stringify(keyModifiers)
  15731. ]);
  15732. }
  15733. if (eventOptionModifiers.length) {
  15734. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  15735. key = isStaticExp(key)
  15736. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  15737. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  15738. }
  15739. return {
  15740. props: [createObjectProperty(key, handlerExp)]
  15741. };
  15742. });
  15743. };
  15744. const transformShow = (dir, node, context) => {
  15745. const { exp, loc } = dir;
  15746. if (!exp) {
  15747. context.onError(createDOMCompilerError(59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */, loc));
  15748. }
  15749. return {
  15750. props: [],
  15751. needRuntime: context.helper(V_SHOW)
  15752. };
  15753. };
  15754. const transformTransition = (node, context) => {
  15755. if (node.type === 1 /* NodeTypes.ELEMENT */ &&
  15756. node.tagType === 1 /* ElementTypes.COMPONENT */) {
  15757. const component = context.isBuiltInComponent(node.tag);
  15758. if (component === TRANSITION) {
  15759. return () => {
  15760. if (!node.children.length) {
  15761. return;
  15762. }
  15763. // warn multiple transition children
  15764. if (hasMultipleChildren(node)) {
  15765. context.onError(createDOMCompilerError(60 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */, {
  15766. start: node.children[0].loc.start,
  15767. end: node.children[node.children.length - 1].loc.end,
  15768. source: ''
  15769. }));
  15770. }
  15771. // check if it's s single child w/ v-show
  15772. // if yes, inject "persisted: true" to the transition props
  15773. const child = node.children[0];
  15774. if (child.type === 1 /* NodeTypes.ELEMENT */) {
  15775. for (const p of child.props) {
  15776. if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'show') {
  15777. node.props.push({
  15778. type: 6 /* NodeTypes.ATTRIBUTE */,
  15779. name: 'persisted',
  15780. value: undefined,
  15781. loc: node.loc
  15782. });
  15783. }
  15784. }
  15785. }
  15786. };
  15787. }
  15788. }
  15789. };
  15790. function hasMultipleChildren(node) {
  15791. // #1352 filter out potential comment nodes.
  15792. const children = (node.children = node.children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */ &&
  15793. !(c.type === 2 /* NodeTypes.TEXT */ && !c.content.trim())));
  15794. const child = children[0];
  15795. return (children.length !== 1 ||
  15796. child.type === 11 /* NodeTypes.FOR */ ||
  15797. (child.type === 9 /* NodeTypes.IF */ && child.branches.some(hasMultipleChildren)));
  15798. }
  15799. const ignoreSideEffectTags = (node, context) => {
  15800. if (node.type === 1 /* NodeTypes.ELEMENT */ &&
  15801. node.tagType === 0 /* ElementTypes.ELEMENT */ &&
  15802. (node.tag === 'script' || node.tag === 'style')) {
  15803. context.onError(createDOMCompilerError(61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  15804. context.removeNode();
  15805. }
  15806. };
  15807. const DOMNodeTransforms = [
  15808. transformStyle,
  15809. ...([transformTransition] )
  15810. ];
  15811. const DOMDirectiveTransforms = {
  15812. cloak: noopDirectiveTransform,
  15813. html: transformVHtml,
  15814. text: transformVText,
  15815. model: transformModel,
  15816. on: transformOn,
  15817. show: transformShow
  15818. };
  15819. function compile(template, options = {}) {
  15820. return baseCompile(template, extend({}, parserOptions, options, {
  15821. nodeTransforms: [
  15822. // ignore <script> and <tag>
  15823. // this is not put inside DOMNodeTransforms because that list is used
  15824. // by compiler-ssr to generate vnode fallback branches
  15825. ignoreSideEffectTags,
  15826. ...DOMNodeTransforms,
  15827. ...(options.nodeTransforms || [])
  15828. ],
  15829. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  15830. transformHoist: null
  15831. }));
  15832. }
  15833. // This entry is the "full-build" that includes both the runtime
  15834. {
  15835. initDev();
  15836. }
  15837. const compileCache = Object.create(null);
  15838. function compileToFunction(template, options) {
  15839. if (!isString(template)) {
  15840. if (template.nodeType) {
  15841. template = template.innerHTML;
  15842. }
  15843. else {
  15844. warn(`invalid template option: `, template);
  15845. return NOOP;
  15846. }
  15847. }
  15848. const key = template;
  15849. const cached = compileCache[key];
  15850. if (cached) {
  15851. return cached;
  15852. }
  15853. if (template[0] === '#') {
  15854. const el = document.querySelector(template);
  15855. if (!el) {
  15856. warn(`Template element not found or is empty: ${template}`);
  15857. }
  15858. // __UNSAFE__
  15859. // Reason: potential execution of JS expressions in in-DOM template.
  15860. // The user must make sure the in-DOM template is trusted. If it's rendered
  15861. // by the server, the template should not contain any user data.
  15862. template = el ? el.innerHTML : ``;
  15863. }
  15864. const opts = extend({
  15865. hoistStatic: true,
  15866. onError: onError ,
  15867. onWarn: e => onError(e, true)
  15868. }, options);
  15869. if (!opts.isCustomElement && typeof customElements !== 'undefined') {
  15870. opts.isCustomElement = tag => !!customElements.get(tag);
  15871. }
  15872. const { code } = compile(template, opts);
  15873. function onError(err, asWarning = false) {
  15874. const message = asWarning
  15875. ? err.message
  15876. : `Template compilation error: ${err.message}`;
  15877. const codeFrame = err.loc &&
  15878. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  15879. warn(codeFrame ? `${message}\n${codeFrame}` : message);
  15880. }
  15881. // The wildcard import results in a huge object with every export
  15882. // with keys that cannot be mangled, and can be quite heavy size-wise.
  15883. // In the global build we know `Vue` is available globally so we can avoid
  15884. // the wildcard object.
  15885. const render = (new Function(code)() );
  15886. render._rc = true;
  15887. return (compileCache[key] = render);
  15888. }
  15889. registerRuntimeCompiler(compileToFunction);
  15890. exports.BaseTransition = BaseTransition;
  15891. exports.Comment = Comment;
  15892. exports.EffectScope = EffectScope;
  15893. exports.Fragment = Fragment;
  15894. exports.KeepAlive = KeepAlive;
  15895. exports.ReactiveEffect = ReactiveEffect;
  15896. exports.Static = Static;
  15897. exports.Suspense = Suspense;
  15898. exports.Teleport = Teleport;
  15899. exports.Text = Text;
  15900. exports.Transition = Transition;
  15901. exports.TransitionGroup = TransitionGroup;
  15902. exports.VueElement = VueElement;
  15903. exports.assertNumber = assertNumber;
  15904. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  15905. exports.callWithErrorHandling = callWithErrorHandling;
  15906. exports.camelize = camelize;
  15907. exports.capitalize = capitalize;
  15908. exports.cloneVNode = cloneVNode;
  15909. exports.compatUtils = compatUtils;
  15910. exports.compile = compileToFunction;
  15911. exports.computed = computed;
  15912. exports.createApp = createApp;
  15913. exports.createBlock = createBlock;
  15914. exports.createCommentVNode = createCommentVNode;
  15915. exports.createElementBlock = createElementBlock;
  15916. exports.createElementVNode = createBaseVNode;
  15917. exports.createHydrationRenderer = createHydrationRenderer;
  15918. exports.createPropsRestProxy = createPropsRestProxy;
  15919. exports.createRenderer = createRenderer;
  15920. exports.createSSRApp = createSSRApp;
  15921. exports.createSlots = createSlots;
  15922. exports.createStaticVNode = createStaticVNode;
  15923. exports.createTextVNode = createTextVNode;
  15924. exports.createVNode = createVNode;
  15925. exports.customRef = customRef;
  15926. exports.defineAsyncComponent = defineAsyncComponent;
  15927. exports.defineComponent = defineComponent;
  15928. exports.defineCustomElement = defineCustomElement;
  15929. exports.defineEmits = defineEmits;
  15930. exports.defineExpose = defineExpose;
  15931. exports.defineProps = defineProps;
  15932. exports.defineSSRCustomElement = defineSSRCustomElement;
  15933. exports.effect = effect;
  15934. exports.effectScope = effectScope;
  15935. exports.getCurrentInstance = getCurrentInstance;
  15936. exports.getCurrentScope = getCurrentScope;
  15937. exports.getTransitionRawChildren = getTransitionRawChildren;
  15938. exports.guardReactiveProps = guardReactiveProps;
  15939. exports.h = h;
  15940. exports.handleError = handleError;
  15941. exports.hydrate = hydrate;
  15942. exports.initCustomFormatter = initCustomFormatter;
  15943. exports.initDirectivesForSSR = initDirectivesForSSR;
  15944. exports.inject = inject;
  15945. exports.isMemoSame = isMemoSame;
  15946. exports.isProxy = isProxy;
  15947. exports.isReactive = isReactive;
  15948. exports.isReadonly = isReadonly;
  15949. exports.isRef = isRef;
  15950. exports.isRuntimeOnly = isRuntimeOnly;
  15951. exports.isShallow = isShallow;
  15952. exports.isVNode = isVNode;
  15953. exports.markRaw = markRaw;
  15954. exports.mergeDefaults = mergeDefaults;
  15955. exports.mergeProps = mergeProps;
  15956. exports.nextTick = nextTick;
  15957. exports.normalizeClass = normalizeClass;
  15958. exports.normalizeProps = normalizeProps;
  15959. exports.normalizeStyle = normalizeStyle;
  15960. exports.onActivated = onActivated;
  15961. exports.onBeforeMount = onBeforeMount;
  15962. exports.onBeforeUnmount = onBeforeUnmount;
  15963. exports.onBeforeUpdate = onBeforeUpdate;
  15964. exports.onDeactivated = onDeactivated;
  15965. exports.onErrorCaptured = onErrorCaptured;
  15966. exports.onMounted = onMounted;
  15967. exports.onRenderTracked = onRenderTracked;
  15968. exports.onRenderTriggered = onRenderTriggered;
  15969. exports.onScopeDispose = onScopeDispose;
  15970. exports.onServerPrefetch = onServerPrefetch;
  15971. exports.onUnmounted = onUnmounted;
  15972. exports.onUpdated = onUpdated;
  15973. exports.openBlock = openBlock;
  15974. exports.popScopeId = popScopeId;
  15975. exports.provide = provide;
  15976. exports.proxyRefs = proxyRefs;
  15977. exports.pushScopeId = pushScopeId;
  15978. exports.queuePostFlushCb = queuePostFlushCb;
  15979. exports.reactive = reactive;
  15980. exports.readonly = readonly;
  15981. exports.ref = ref;
  15982. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  15983. exports.render = render;
  15984. exports.renderList = renderList;
  15985. exports.renderSlot = renderSlot;
  15986. exports.resolveComponent = resolveComponent;
  15987. exports.resolveDirective = resolveDirective;
  15988. exports.resolveDynamicComponent = resolveDynamicComponent;
  15989. exports.resolveFilter = resolveFilter;
  15990. exports.resolveTransitionHooks = resolveTransitionHooks;
  15991. exports.setBlockTracking = setBlockTracking;
  15992. exports.setDevtoolsHook = setDevtoolsHook;
  15993. exports.setTransitionHooks = setTransitionHooks;
  15994. exports.shallowReactive = shallowReactive;
  15995. exports.shallowReadonly = shallowReadonly;
  15996. exports.shallowRef = shallowRef;
  15997. exports.ssrContextKey = ssrContextKey;
  15998. exports.ssrUtils = ssrUtils;
  15999. exports.stop = stop;
  16000. exports.toDisplayString = toDisplayString;
  16001. exports.toHandlerKey = toHandlerKey;
  16002. exports.toHandlers = toHandlers;
  16003. exports.toRaw = toRaw;
  16004. exports.toRef = toRef;
  16005. exports.toRefs = toRefs;
  16006. exports.transformVNodeArgs = transformVNodeArgs;
  16007. exports.triggerRef = triggerRef;
  16008. exports.unref = unref;
  16009. exports.useAttrs = useAttrs;
  16010. exports.useCssModule = useCssModule;
  16011. exports.useCssVars = useCssVars;
  16012. exports.useSSRContext = useSSRContext;
  16013. exports.useSlots = useSlots;
  16014. exports.useTransitionState = useTransitionState;
  16015. exports.vModelCheckbox = vModelCheckbox;
  16016. exports.vModelDynamic = vModelDynamic;
  16017. exports.vModelRadio = vModelRadio;
  16018. exports.vModelSelect = vModelSelect;
  16019. exports.vModelText = vModelText;
  16020. exports.vShow = vShow;
  16021. exports.version = version;
  16022. exports.warn = warn;
  16023. exports.watch = watch;
  16024. exports.watchEffect = watchEffect;
  16025. exports.watchPostEffect = watchPostEffect;
  16026. exports.watchSyncEffect = watchSyncEffect;
  16027. exports.withAsyncContext = withAsyncContext;
  16028. exports.withCtx = withCtx;
  16029. exports.withDefaults = withDefaults;
  16030. exports.withDirectives = withDirectives;
  16031. exports.withKeys = withKeys;
  16032. exports.withMemo = withMemo;
  16033. exports.withModifiers = withModifiers;
  16034. exports.withScopeId = withScopeId;
  16035. Object.defineProperty(exports, '__esModule', { value: true });
  16036. return exports;
  16037. })({});