vue.global.js 602 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754
  1. var Vue = (function (exports) {
  2. 'use strict';
  3. /**
  4. * Make a map and return a function for checking if a key
  5. * is in that map.
  6. * IMPORTANT: all calls of this function must be prefixed with
  7. * \/\*#\_\_PURE\_\_\*\/
  8. * So that rollup can tree-shake them if necessary.
  9. */
  10. function makeMap(str, expectsLowerCase) {
  11. const map = Object.create(null);
  12. const list = str.split(',');
  13. for (let i = 0; i < list.length; i++) {
  14. map[list[i]] = true;
  15. }
  16. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  17. }
  18. /**
  19. * dev only flag -> name mapping
  20. */
  21. const PatchFlagNames = {
  22. [1 /* TEXT */]: `TEXT`,
  23. [2 /* CLASS */]: `CLASS`,
  24. [4 /* STYLE */]: `STYLE`,
  25. [8 /* PROPS */]: `PROPS`,
  26. [16 /* FULL_PROPS */]: `FULL_PROPS`,
  27. [32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  28. [64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  29. [128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  30. [256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  31. [512 /* NEED_PATCH */]: `NEED_PATCH`,
  32. [1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  33. [2048 /* DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  34. [-1 /* HOISTED */]: `HOISTED`,
  35. [-2 /* BAIL */]: `BAIL`
  36. };
  37. /**
  38. * Dev only
  39. */
  40. const slotFlagsText = {
  41. [1 /* STABLE */]: 'STABLE',
  42. [2 /* DYNAMIC */]: 'DYNAMIC',
  43. [3 /* FORWARDED */]: 'FORWARDED'
  44. };
  45. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  46. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  47. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  48. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  49. const range = 2;
  50. function generateCodeFrame(source, start = 0, end = source.length) {
  51. // Split the content into individual lines but capture the newline sequence
  52. // that separated each line. This is important because the actual sequence is
  53. // needed to properly take into account the full line length for offset
  54. // comparison
  55. let lines = source.split(/(\r?\n)/);
  56. // Separate the lines and newline sequences into separate arrays for easier referencing
  57. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  58. lines = lines.filter((_, idx) => idx % 2 === 0);
  59. let count = 0;
  60. const res = [];
  61. for (let i = 0; i < lines.length; i++) {
  62. count +=
  63. lines[i].length +
  64. ((newlineSequences[i] && newlineSequences[i].length) || 0);
  65. if (count >= start) {
  66. for (let j = i - range; j <= i + range || end > count; j++) {
  67. if (j < 0 || j >= lines.length)
  68. continue;
  69. const line = j + 1;
  70. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  71. const lineLength = lines[j].length;
  72. const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
  73. if (j === i) {
  74. // push underline
  75. const pad = start - (count - (lineLength + newLineSeqLength));
  76. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  77. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  78. }
  79. else if (j > i) {
  80. if (end > count) {
  81. const length = Math.max(Math.min(end - count, lineLength), 1);
  82. res.push(` | ` + '^'.repeat(length));
  83. }
  84. count += lineLength + newLineSeqLength;
  85. }
  86. }
  87. break;
  88. }
  89. }
  90. return res.join('\n');
  91. }
  92. /**
  93. * On the client we only need to offer special cases for boolean attributes that
  94. * have different names from their corresponding dom properties:
  95. * - itemscope -> N/A
  96. * - allowfullscreen -> allowFullscreen
  97. * - formnovalidate -> formNoValidate
  98. * - ismap -> isMap
  99. * - nomodule -> noModule
  100. * - novalidate -> noValidate
  101. * - readonly -> readOnly
  102. */
  103. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  104. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  105. /**
  106. * Boolean attributes should be included if the value is truthy or ''.
  107. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  108. */
  109. function includeBooleanAttr(value) {
  110. return !!value || value === '';
  111. }
  112. function normalizeStyle(value) {
  113. if (isArray(value)) {
  114. const res = {};
  115. for (let i = 0; i < value.length; i++) {
  116. const item = value[i];
  117. const normalized = isString(item)
  118. ? parseStringStyle(item)
  119. : normalizeStyle(item);
  120. if (normalized) {
  121. for (const key in normalized) {
  122. res[key] = normalized[key];
  123. }
  124. }
  125. }
  126. return res;
  127. }
  128. else if (isString(value)) {
  129. return value;
  130. }
  131. else if (isObject(value)) {
  132. return value;
  133. }
  134. }
  135. const listDelimiterRE = /;(?![^(]*\))/g;
  136. const propertyDelimiterRE = /:(.+)/;
  137. function parseStringStyle(cssText) {
  138. const ret = {};
  139. cssText.split(listDelimiterRE).forEach(item => {
  140. if (item) {
  141. const tmp = item.split(propertyDelimiterRE);
  142. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  143. }
  144. });
  145. return ret;
  146. }
  147. function normalizeClass(value) {
  148. let res = '';
  149. if (isString(value)) {
  150. res = value;
  151. }
  152. else if (isArray(value)) {
  153. for (let i = 0; i < value.length; i++) {
  154. const normalized = normalizeClass(value[i]);
  155. if (normalized) {
  156. res += normalized + ' ';
  157. }
  158. }
  159. }
  160. else if (isObject(value)) {
  161. for (const name in value) {
  162. if (value[name]) {
  163. res += name + ' ';
  164. }
  165. }
  166. }
  167. return res.trim();
  168. }
  169. function normalizeProps(props) {
  170. if (!props)
  171. return null;
  172. let { class: klass, style } = props;
  173. if (klass && !isString(klass)) {
  174. props.class = normalizeClass(klass);
  175. }
  176. if (style) {
  177. props.style = normalizeStyle(style);
  178. }
  179. return props;
  180. }
  181. // These tag configs are shared between compiler-dom and runtime-dom, so they
  182. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  183. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  184. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  185. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  186. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  187. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  188. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  189. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  190. 'option,output,progress,select,textarea,details,dialog,menu,' +
  191. 'summary,template,blockquote,iframe,tfoot';
  192. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  193. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  194. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  195. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  196. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  197. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  198. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  199. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  200. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  201. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  202. 'text,textPath,title,tspan,unknown,use,view';
  203. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  204. /**
  205. * Compiler only.
  206. * Do NOT use in runtime code paths unless behind `true` flag.
  207. */
  208. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  209. /**
  210. * Compiler only.
  211. * Do NOT use in runtime code paths unless behind `true` flag.
  212. */
  213. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  214. /**
  215. * Compiler only.
  216. * Do NOT use in runtime code paths unless behind `true` flag.
  217. */
  218. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  219. function looseCompareArrays(a, b) {
  220. if (a.length !== b.length)
  221. return false;
  222. let equal = true;
  223. for (let i = 0; equal && i < a.length; i++) {
  224. equal = looseEqual(a[i], b[i]);
  225. }
  226. return equal;
  227. }
  228. function looseEqual(a, b) {
  229. if (a === b)
  230. return true;
  231. let aValidType = isDate(a);
  232. let bValidType = isDate(b);
  233. if (aValidType || bValidType) {
  234. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  235. }
  236. aValidType = isArray(a);
  237. bValidType = isArray(b);
  238. if (aValidType || bValidType) {
  239. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  240. }
  241. aValidType = isObject(a);
  242. bValidType = isObject(b);
  243. if (aValidType || bValidType) {
  244. /* istanbul ignore if: this if will probably never be called */
  245. if (!aValidType || !bValidType) {
  246. return false;
  247. }
  248. const aKeysCount = Object.keys(a).length;
  249. const bKeysCount = Object.keys(b).length;
  250. if (aKeysCount !== bKeysCount) {
  251. return false;
  252. }
  253. for (const key in a) {
  254. const aHasKey = a.hasOwnProperty(key);
  255. const bHasKey = b.hasOwnProperty(key);
  256. if ((aHasKey && !bHasKey) ||
  257. (!aHasKey && bHasKey) ||
  258. !looseEqual(a[key], b[key])) {
  259. return false;
  260. }
  261. }
  262. }
  263. return String(a) === String(b);
  264. }
  265. function looseIndexOf(arr, val) {
  266. return arr.findIndex(item => looseEqual(item, val));
  267. }
  268. /**
  269. * For converting {{ interpolation }} values to displayed strings.
  270. * @private
  271. */
  272. const toDisplayString = (val) => {
  273. return isString(val)
  274. ? val
  275. : val == null
  276. ? ''
  277. : isArray(val) ||
  278. (isObject(val) &&
  279. (val.toString === objectToString || !isFunction(val.toString)))
  280. ? JSON.stringify(val, replacer, 2)
  281. : String(val);
  282. };
  283. const replacer = (_key, val) => {
  284. // can't use isRef here since @vue/shared has no deps
  285. if (val && val.__v_isRef) {
  286. return replacer(_key, val.value);
  287. }
  288. else if (isMap(val)) {
  289. return {
  290. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  291. entries[`${key} =>`] = val;
  292. return entries;
  293. }, {})
  294. };
  295. }
  296. else if (isSet(val)) {
  297. return {
  298. [`Set(${val.size})`]: [...val.values()]
  299. };
  300. }
  301. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  302. return String(val);
  303. }
  304. return val;
  305. };
  306. const EMPTY_OBJ = Object.freeze({})
  307. ;
  308. const EMPTY_ARR = Object.freeze([]) ;
  309. const NOOP = () => { };
  310. /**
  311. * Always return false.
  312. */
  313. const NO = () => false;
  314. const onRE = /^on[^a-z]/;
  315. const isOn = (key) => onRE.test(key);
  316. const isModelListener = (key) => key.startsWith('onUpdate:');
  317. const extend = Object.assign;
  318. const remove = (arr, el) => {
  319. const i = arr.indexOf(el);
  320. if (i > -1) {
  321. arr.splice(i, 1);
  322. }
  323. };
  324. const hasOwnProperty = Object.prototype.hasOwnProperty;
  325. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  326. const isArray = Array.isArray;
  327. const isMap = (val) => toTypeString(val) === '[object Map]';
  328. const isSet = (val) => toTypeString(val) === '[object Set]';
  329. const isDate = (val) => val instanceof Date;
  330. const isFunction = (val) => typeof val === 'function';
  331. const isString = (val) => typeof val === 'string';
  332. const isSymbol = (val) => typeof val === 'symbol';
  333. const isObject = (val) => val !== null && typeof val === 'object';
  334. const isPromise = (val) => {
  335. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  336. };
  337. const objectToString = Object.prototype.toString;
  338. const toTypeString = (value) => objectToString.call(value);
  339. const toRawType = (value) => {
  340. // extract "RawType" from strings like "[object RawType]"
  341. return toTypeString(value).slice(8, -1);
  342. };
  343. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  344. const isIntegerKey = (key) => isString(key) &&
  345. key !== 'NaN' &&
  346. key[0] !== '-' &&
  347. '' + parseInt(key, 10) === key;
  348. const isReservedProp = /*#__PURE__*/ makeMap(
  349. // the leading comma is intentional so empty string "" is also included
  350. ',key,ref,ref_for,ref_key,' +
  351. 'onVnodeBeforeMount,onVnodeMounted,' +
  352. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  353. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  354. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  355. const cacheStringFunction = (fn) => {
  356. const cache = Object.create(null);
  357. return ((str) => {
  358. const hit = cache[str];
  359. return hit || (cache[str] = fn(str));
  360. });
  361. };
  362. const camelizeRE = /-(\w)/g;
  363. /**
  364. * @private
  365. */
  366. const camelize = cacheStringFunction((str) => {
  367. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  368. });
  369. const hyphenateRE = /\B([A-Z])/g;
  370. /**
  371. * @private
  372. */
  373. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  374. /**
  375. * @private
  376. */
  377. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  378. /**
  379. * @private
  380. */
  381. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  382. // compare whether a value has changed, accounting for NaN.
  383. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  384. const invokeArrayFns = (fns, arg) => {
  385. for (let i = 0; i < fns.length; i++) {
  386. fns[i](arg);
  387. }
  388. };
  389. const def = (obj, key, value) => {
  390. Object.defineProperty(obj, key, {
  391. configurable: true,
  392. enumerable: false,
  393. value
  394. });
  395. };
  396. const toNumber = (val) => {
  397. const n = parseFloat(val);
  398. return isNaN(n) ? val : n;
  399. };
  400. let _globalThis;
  401. const getGlobalThis = () => {
  402. return (_globalThis ||
  403. (_globalThis =
  404. typeof globalThis !== 'undefined'
  405. ? globalThis
  406. : typeof self !== 'undefined'
  407. ? self
  408. : typeof window !== 'undefined'
  409. ? window
  410. : typeof global !== 'undefined'
  411. ? global
  412. : {}));
  413. };
  414. function warn(msg, ...args) {
  415. console.warn(`[Vue warn] ${msg}`, ...args);
  416. }
  417. let activeEffectScope;
  418. class EffectScope {
  419. constructor(detached = false) {
  420. this.active = true;
  421. this.effects = [];
  422. this.cleanups = [];
  423. if (!detached && activeEffectScope) {
  424. this.parent = activeEffectScope;
  425. this.index =
  426. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  427. }
  428. }
  429. run(fn) {
  430. if (this.active) {
  431. try {
  432. activeEffectScope = this;
  433. return fn();
  434. }
  435. finally {
  436. activeEffectScope = this.parent;
  437. }
  438. }
  439. else {
  440. warn(`cannot run an inactive effect scope.`);
  441. }
  442. }
  443. on() {
  444. activeEffectScope = this;
  445. }
  446. off() {
  447. activeEffectScope = this.parent;
  448. }
  449. stop(fromParent) {
  450. if (this.active) {
  451. let i, l;
  452. for (i = 0, l = this.effects.length; i < l; i++) {
  453. this.effects[i].stop();
  454. }
  455. for (i = 0, l = this.cleanups.length; i < l; i++) {
  456. this.cleanups[i]();
  457. }
  458. if (this.scopes) {
  459. for (i = 0, l = this.scopes.length; i < l; i++) {
  460. this.scopes[i].stop(true);
  461. }
  462. }
  463. // nested scope, dereference from parent to avoid memory leaks
  464. if (this.parent && !fromParent) {
  465. // optimized O(1) removal
  466. const last = this.parent.scopes.pop();
  467. if (last && last !== this) {
  468. this.parent.scopes[this.index] = last;
  469. last.index = this.index;
  470. }
  471. }
  472. this.active = false;
  473. }
  474. }
  475. }
  476. function effectScope(detached) {
  477. return new EffectScope(detached);
  478. }
  479. function recordEffectScope(effect, scope = activeEffectScope) {
  480. if (scope && scope.active) {
  481. scope.effects.push(effect);
  482. }
  483. }
  484. function getCurrentScope() {
  485. return activeEffectScope;
  486. }
  487. function onScopeDispose(fn) {
  488. if (activeEffectScope) {
  489. activeEffectScope.cleanups.push(fn);
  490. }
  491. else {
  492. warn(`onScopeDispose() is called when there is no active effect scope` +
  493. ` to be associated with.`);
  494. }
  495. }
  496. const createDep = (effects) => {
  497. const dep = new Set(effects);
  498. dep.w = 0;
  499. dep.n = 0;
  500. return dep;
  501. };
  502. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  503. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  504. const initDepMarkers = ({ deps }) => {
  505. if (deps.length) {
  506. for (let i = 0; i < deps.length; i++) {
  507. deps[i].w |= trackOpBit; // set was tracked
  508. }
  509. }
  510. };
  511. const finalizeDepMarkers = (effect) => {
  512. const { deps } = effect;
  513. if (deps.length) {
  514. let ptr = 0;
  515. for (let i = 0; i < deps.length; i++) {
  516. const dep = deps[i];
  517. if (wasTracked(dep) && !newTracked(dep)) {
  518. dep.delete(effect);
  519. }
  520. else {
  521. deps[ptr++] = dep;
  522. }
  523. // clear bits
  524. dep.w &= ~trackOpBit;
  525. dep.n &= ~trackOpBit;
  526. }
  527. deps.length = ptr;
  528. }
  529. };
  530. const targetMap = new WeakMap();
  531. // The number of effects currently being tracked recursively.
  532. let effectTrackDepth = 0;
  533. let trackOpBit = 1;
  534. /**
  535. * The bitwise track markers support at most 30 levels of recursion.
  536. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  537. * When recursion depth is greater, fall back to using a full cleanup.
  538. */
  539. const maxMarkerBits = 30;
  540. let activeEffect;
  541. const ITERATE_KEY = Symbol('iterate' );
  542. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  543. class ReactiveEffect {
  544. constructor(fn, scheduler = null, scope) {
  545. this.fn = fn;
  546. this.scheduler = scheduler;
  547. this.active = true;
  548. this.deps = [];
  549. this.parent = undefined;
  550. recordEffectScope(this, scope);
  551. }
  552. run() {
  553. if (!this.active) {
  554. return this.fn();
  555. }
  556. let parent = activeEffect;
  557. let lastShouldTrack = shouldTrack;
  558. while (parent) {
  559. if (parent === this) {
  560. return;
  561. }
  562. parent = parent.parent;
  563. }
  564. try {
  565. this.parent = activeEffect;
  566. activeEffect = this;
  567. shouldTrack = true;
  568. trackOpBit = 1 << ++effectTrackDepth;
  569. if (effectTrackDepth <= maxMarkerBits) {
  570. initDepMarkers(this);
  571. }
  572. else {
  573. cleanupEffect(this);
  574. }
  575. return this.fn();
  576. }
  577. finally {
  578. if (effectTrackDepth <= maxMarkerBits) {
  579. finalizeDepMarkers(this);
  580. }
  581. trackOpBit = 1 << --effectTrackDepth;
  582. activeEffect = this.parent;
  583. shouldTrack = lastShouldTrack;
  584. this.parent = undefined;
  585. }
  586. }
  587. stop() {
  588. if (this.active) {
  589. cleanupEffect(this);
  590. if (this.onStop) {
  591. this.onStop();
  592. }
  593. this.active = false;
  594. }
  595. }
  596. }
  597. function cleanupEffect(effect) {
  598. const { deps } = effect;
  599. if (deps.length) {
  600. for (let i = 0; i < deps.length; i++) {
  601. deps[i].delete(effect);
  602. }
  603. deps.length = 0;
  604. }
  605. }
  606. function effect(fn, options) {
  607. if (fn.effect) {
  608. fn = fn.effect.fn;
  609. }
  610. const _effect = new ReactiveEffect(fn);
  611. if (options) {
  612. extend(_effect, options);
  613. if (options.scope)
  614. recordEffectScope(_effect, options.scope);
  615. }
  616. if (!options || !options.lazy) {
  617. _effect.run();
  618. }
  619. const runner = _effect.run.bind(_effect);
  620. runner.effect = _effect;
  621. return runner;
  622. }
  623. function stop(runner) {
  624. runner.effect.stop();
  625. }
  626. let shouldTrack = true;
  627. const trackStack = [];
  628. function pauseTracking() {
  629. trackStack.push(shouldTrack);
  630. shouldTrack = false;
  631. }
  632. function resetTracking() {
  633. const last = trackStack.pop();
  634. shouldTrack = last === undefined ? true : last;
  635. }
  636. function track(target, type, key) {
  637. if (shouldTrack && activeEffect) {
  638. let depsMap = targetMap.get(target);
  639. if (!depsMap) {
  640. targetMap.set(target, (depsMap = new Map()));
  641. }
  642. let dep = depsMap.get(key);
  643. if (!dep) {
  644. depsMap.set(key, (dep = createDep()));
  645. }
  646. const eventInfo = { effect: activeEffect, target, type, key }
  647. ;
  648. trackEffects(dep, eventInfo);
  649. }
  650. }
  651. function trackEffects(dep, debuggerEventExtraInfo) {
  652. let shouldTrack = false;
  653. if (effectTrackDepth <= maxMarkerBits) {
  654. if (!newTracked(dep)) {
  655. dep.n |= trackOpBit; // set newly tracked
  656. shouldTrack = !wasTracked(dep);
  657. }
  658. }
  659. else {
  660. // Full cleanup mode.
  661. shouldTrack = !dep.has(activeEffect);
  662. }
  663. if (shouldTrack) {
  664. dep.add(activeEffect);
  665. activeEffect.deps.push(dep);
  666. if (activeEffect.onTrack) {
  667. activeEffect.onTrack(Object.assign({
  668. effect: activeEffect
  669. }, debuggerEventExtraInfo));
  670. }
  671. }
  672. }
  673. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  674. const depsMap = targetMap.get(target);
  675. if (!depsMap) {
  676. // never been tracked
  677. return;
  678. }
  679. let deps = [];
  680. if (type === "clear" /* CLEAR */) {
  681. // collection being cleared
  682. // trigger all effects for target
  683. deps = [...depsMap.values()];
  684. }
  685. else if (key === 'length' && isArray(target)) {
  686. depsMap.forEach((dep, key) => {
  687. if (key === 'length' || key >= newValue) {
  688. deps.push(dep);
  689. }
  690. });
  691. }
  692. else {
  693. // schedule runs for SET | ADD | DELETE
  694. if (key !== void 0) {
  695. deps.push(depsMap.get(key));
  696. }
  697. // also run for iteration key on ADD | DELETE | Map.SET
  698. switch (type) {
  699. case "add" /* ADD */:
  700. if (!isArray(target)) {
  701. deps.push(depsMap.get(ITERATE_KEY));
  702. if (isMap(target)) {
  703. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  704. }
  705. }
  706. else if (isIntegerKey(key)) {
  707. // new index added to array -> length changes
  708. deps.push(depsMap.get('length'));
  709. }
  710. break;
  711. case "delete" /* DELETE */:
  712. if (!isArray(target)) {
  713. deps.push(depsMap.get(ITERATE_KEY));
  714. if (isMap(target)) {
  715. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  716. }
  717. }
  718. break;
  719. case "set" /* SET */:
  720. if (isMap(target)) {
  721. deps.push(depsMap.get(ITERATE_KEY));
  722. }
  723. break;
  724. }
  725. }
  726. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  727. ;
  728. if (deps.length === 1) {
  729. if (deps[0]) {
  730. {
  731. triggerEffects(deps[0], eventInfo);
  732. }
  733. }
  734. }
  735. else {
  736. const effects = [];
  737. for (const dep of deps) {
  738. if (dep) {
  739. effects.push(...dep);
  740. }
  741. }
  742. {
  743. triggerEffects(createDep(effects), eventInfo);
  744. }
  745. }
  746. }
  747. function triggerEffects(dep, debuggerEventExtraInfo) {
  748. // spread into array for stabilization
  749. for (const effect of isArray(dep) ? dep : [...dep]) {
  750. if (effect !== activeEffect || effect.allowRecurse) {
  751. if (effect.onTrigger) {
  752. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  753. }
  754. if (effect.scheduler) {
  755. effect.scheduler();
  756. }
  757. else {
  758. effect.run();
  759. }
  760. }
  761. }
  762. }
  763. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  764. const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
  765. .map(key => Symbol[key])
  766. .filter(isSymbol));
  767. const get = /*#__PURE__*/ createGetter();
  768. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  769. const readonlyGet = /*#__PURE__*/ createGetter(true);
  770. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  771. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  772. function createArrayInstrumentations() {
  773. const instrumentations = {};
  774. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  775. instrumentations[key] = function (...args) {
  776. const arr = toRaw(this);
  777. for (let i = 0, l = this.length; i < l; i++) {
  778. track(arr, "get" /* GET */, i + '');
  779. }
  780. // we run the method using the original args first (which may be reactive)
  781. const res = arr[key](...args);
  782. if (res === -1 || res === false) {
  783. // if that didn't work, run it again using raw values.
  784. return arr[key](...args.map(toRaw));
  785. }
  786. else {
  787. return res;
  788. }
  789. };
  790. });
  791. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  792. instrumentations[key] = function (...args) {
  793. pauseTracking();
  794. const res = toRaw(this)[key].apply(this, args);
  795. resetTracking();
  796. return res;
  797. };
  798. });
  799. return instrumentations;
  800. }
  801. function createGetter(isReadonly = false, shallow = false) {
  802. return function get(target, key, receiver) {
  803. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  804. return !isReadonly;
  805. }
  806. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  807. return isReadonly;
  808. }
  809. else if (key === "__v_isShallow" /* IS_SHALLOW */) {
  810. return shallow;
  811. }
  812. else if (key === "__v_raw" /* RAW */ &&
  813. receiver ===
  814. (isReadonly
  815. ? shallow
  816. ? shallowReadonlyMap
  817. : readonlyMap
  818. : shallow
  819. ? shallowReactiveMap
  820. : reactiveMap).get(target)) {
  821. return target;
  822. }
  823. const targetIsArray = isArray(target);
  824. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  825. return Reflect.get(arrayInstrumentations, key, receiver);
  826. }
  827. const res = Reflect.get(target, key, receiver);
  828. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  829. return res;
  830. }
  831. if (!isReadonly) {
  832. track(target, "get" /* GET */, key);
  833. }
  834. if (shallow) {
  835. return res;
  836. }
  837. if (isRef(res)) {
  838. // ref unwrapping - does not apply for Array + integer key.
  839. const shouldUnwrap = !targetIsArray || !isIntegerKey(key);
  840. return shouldUnwrap ? res.value : res;
  841. }
  842. if (isObject(res)) {
  843. // Convert returned value into a proxy as well. we do the isObject check
  844. // here to avoid invalid value warning. Also need to lazy access readonly
  845. // and reactive here to avoid circular dependency.
  846. return isReadonly ? readonly(res) : reactive(res);
  847. }
  848. return res;
  849. };
  850. }
  851. const set = /*#__PURE__*/ createSetter();
  852. const shallowSet = /*#__PURE__*/ createSetter(true);
  853. function createSetter(shallow = false) {
  854. return function set(target, key, value, receiver) {
  855. let oldValue = target[key];
  856. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  857. return false;
  858. }
  859. if (!shallow && !isReadonly(value)) {
  860. if (!isShallow(value)) {
  861. value = toRaw(value);
  862. oldValue = toRaw(oldValue);
  863. }
  864. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  865. oldValue.value = value;
  866. return true;
  867. }
  868. }
  869. const hadKey = isArray(target) && isIntegerKey(key)
  870. ? Number(key) < target.length
  871. : hasOwn(target, key);
  872. const result = Reflect.set(target, key, value, receiver);
  873. // don't trigger if target is something up in the prototype chain of original
  874. if (target === toRaw(receiver)) {
  875. if (!hadKey) {
  876. trigger(target, "add" /* ADD */, key, value);
  877. }
  878. else if (hasChanged(value, oldValue)) {
  879. trigger(target, "set" /* SET */, key, value, oldValue);
  880. }
  881. }
  882. return result;
  883. };
  884. }
  885. function deleteProperty(target, key) {
  886. const hadKey = hasOwn(target, key);
  887. const oldValue = target[key];
  888. const result = Reflect.deleteProperty(target, key);
  889. if (result && hadKey) {
  890. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  891. }
  892. return result;
  893. }
  894. function has(target, key) {
  895. const result = Reflect.has(target, key);
  896. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  897. track(target, "has" /* HAS */, key);
  898. }
  899. return result;
  900. }
  901. function ownKeys(target) {
  902. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  903. return Reflect.ownKeys(target);
  904. }
  905. const mutableHandlers = {
  906. get,
  907. set,
  908. deleteProperty,
  909. has,
  910. ownKeys
  911. };
  912. const readonlyHandlers = {
  913. get: readonlyGet,
  914. set(target, key) {
  915. {
  916. console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  917. }
  918. return true;
  919. },
  920. deleteProperty(target, key) {
  921. {
  922. console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  923. }
  924. return true;
  925. }
  926. };
  927. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  928. get: shallowGet,
  929. set: shallowSet
  930. });
  931. // Props handlers are special in the sense that it should not unwrap top-level
  932. // refs (in order to allow refs to be explicitly passed down), but should
  933. // retain the reactivity of the normal readonly object.
  934. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  935. get: shallowReadonlyGet
  936. });
  937. const toShallow = (value) => value;
  938. const getProto = (v) => Reflect.getPrototypeOf(v);
  939. function get$1(target, key, isReadonly = false, isShallow = false) {
  940. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  941. // of the value
  942. target = target["__v_raw" /* RAW */];
  943. const rawTarget = toRaw(target);
  944. const rawKey = toRaw(key);
  945. if (key !== rawKey) {
  946. !isReadonly && track(rawTarget, "get" /* GET */, key);
  947. }
  948. !isReadonly && track(rawTarget, "get" /* GET */, rawKey);
  949. const { has } = getProto(rawTarget);
  950. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  951. if (has.call(rawTarget, key)) {
  952. return wrap(target.get(key));
  953. }
  954. else if (has.call(rawTarget, rawKey)) {
  955. return wrap(target.get(rawKey));
  956. }
  957. else if (target !== rawTarget) {
  958. // #3602 readonly(reactive(Map))
  959. // ensure that the nested reactive `Map` can do tracking for itself
  960. target.get(key);
  961. }
  962. }
  963. function has$1(key, isReadonly = false) {
  964. const target = this["__v_raw" /* RAW */];
  965. const rawTarget = toRaw(target);
  966. const rawKey = toRaw(key);
  967. if (key !== rawKey) {
  968. !isReadonly && track(rawTarget, "has" /* HAS */, key);
  969. }
  970. !isReadonly && track(rawTarget, "has" /* HAS */, rawKey);
  971. return key === rawKey
  972. ? target.has(key)
  973. : target.has(key) || target.has(rawKey);
  974. }
  975. function size(target, isReadonly = false) {
  976. target = target["__v_raw" /* RAW */];
  977. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  978. return Reflect.get(target, 'size', target);
  979. }
  980. function add(value) {
  981. value = toRaw(value);
  982. const target = toRaw(this);
  983. const proto = getProto(target);
  984. const hadKey = proto.has.call(target, value);
  985. if (!hadKey) {
  986. target.add(value);
  987. trigger(target, "add" /* ADD */, value, value);
  988. }
  989. return this;
  990. }
  991. function set$1(key, value) {
  992. value = toRaw(value);
  993. const target = toRaw(this);
  994. const { has, get } = getProto(target);
  995. let hadKey = has.call(target, key);
  996. if (!hadKey) {
  997. key = toRaw(key);
  998. hadKey = has.call(target, key);
  999. }
  1000. else {
  1001. checkIdentityKeys(target, has, key);
  1002. }
  1003. const oldValue = get.call(target, key);
  1004. target.set(key, value);
  1005. if (!hadKey) {
  1006. trigger(target, "add" /* ADD */, key, value);
  1007. }
  1008. else if (hasChanged(value, oldValue)) {
  1009. trigger(target, "set" /* SET */, key, value, oldValue);
  1010. }
  1011. return this;
  1012. }
  1013. function deleteEntry(key) {
  1014. const target = toRaw(this);
  1015. const { has, get } = getProto(target);
  1016. let hadKey = has.call(target, key);
  1017. if (!hadKey) {
  1018. key = toRaw(key);
  1019. hadKey = has.call(target, key);
  1020. }
  1021. else {
  1022. checkIdentityKeys(target, has, key);
  1023. }
  1024. const oldValue = get ? get.call(target, key) : undefined;
  1025. // forward the operation before queueing reactions
  1026. const result = target.delete(key);
  1027. if (hadKey) {
  1028. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  1029. }
  1030. return result;
  1031. }
  1032. function clear() {
  1033. const target = toRaw(this);
  1034. const hadItems = target.size !== 0;
  1035. const oldTarget = isMap(target)
  1036. ? new Map(target)
  1037. : new Set(target)
  1038. ;
  1039. // forward the operation before queueing reactions
  1040. const result = target.clear();
  1041. if (hadItems) {
  1042. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  1043. }
  1044. return result;
  1045. }
  1046. function createForEach(isReadonly, isShallow) {
  1047. return function forEach(callback, thisArg) {
  1048. const observed = this;
  1049. const target = observed["__v_raw" /* RAW */];
  1050. const rawTarget = toRaw(target);
  1051. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1052. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  1053. return target.forEach((value, key) => {
  1054. // important: make sure the callback is
  1055. // 1. invoked with the reactive map as `this` and 3rd arg
  1056. // 2. the value received should be a corresponding reactive/readonly.
  1057. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1058. });
  1059. };
  1060. }
  1061. function createIterableMethod(method, isReadonly, isShallow) {
  1062. return function (...args) {
  1063. const target = this["__v_raw" /* RAW */];
  1064. const rawTarget = toRaw(target);
  1065. const targetIsMap = isMap(rawTarget);
  1066. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1067. const isKeyOnly = method === 'keys' && targetIsMap;
  1068. const innerIterator = target[method](...args);
  1069. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1070. !isReadonly &&
  1071. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1072. // return a wrapped iterator which returns observed versions of the
  1073. // values emitted from the real iterator
  1074. return {
  1075. // iterator protocol
  1076. next() {
  1077. const { value, done } = innerIterator.next();
  1078. return done
  1079. ? { value, done }
  1080. : {
  1081. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1082. done
  1083. };
  1084. },
  1085. // iterable protocol
  1086. [Symbol.iterator]() {
  1087. return this;
  1088. }
  1089. };
  1090. };
  1091. }
  1092. function createReadonlyMethod(type) {
  1093. return function (...args) {
  1094. {
  1095. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1096. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1097. }
  1098. return type === "delete" /* DELETE */ ? false : this;
  1099. };
  1100. }
  1101. function createInstrumentations() {
  1102. const mutableInstrumentations = {
  1103. get(key) {
  1104. return get$1(this, key);
  1105. },
  1106. get size() {
  1107. return size(this);
  1108. },
  1109. has: has$1,
  1110. add,
  1111. set: set$1,
  1112. delete: deleteEntry,
  1113. clear,
  1114. forEach: createForEach(false, false)
  1115. };
  1116. const shallowInstrumentations = {
  1117. get(key) {
  1118. return get$1(this, key, false, true);
  1119. },
  1120. get size() {
  1121. return size(this);
  1122. },
  1123. has: has$1,
  1124. add,
  1125. set: set$1,
  1126. delete: deleteEntry,
  1127. clear,
  1128. forEach: createForEach(false, true)
  1129. };
  1130. const readonlyInstrumentations = {
  1131. get(key) {
  1132. return get$1(this, key, true);
  1133. },
  1134. get size() {
  1135. return size(this, true);
  1136. },
  1137. has(key) {
  1138. return has$1.call(this, key, true);
  1139. },
  1140. add: createReadonlyMethod("add" /* ADD */),
  1141. set: createReadonlyMethod("set" /* SET */),
  1142. delete: createReadonlyMethod("delete" /* DELETE */),
  1143. clear: createReadonlyMethod("clear" /* CLEAR */),
  1144. forEach: createForEach(true, false)
  1145. };
  1146. const shallowReadonlyInstrumentations = {
  1147. get(key) {
  1148. return get$1(this, key, true, true);
  1149. },
  1150. get size() {
  1151. return size(this, true);
  1152. },
  1153. has(key) {
  1154. return has$1.call(this, key, true);
  1155. },
  1156. add: createReadonlyMethod("add" /* ADD */),
  1157. set: createReadonlyMethod("set" /* SET */),
  1158. delete: createReadonlyMethod("delete" /* DELETE */),
  1159. clear: createReadonlyMethod("clear" /* CLEAR */),
  1160. forEach: createForEach(true, true)
  1161. };
  1162. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1163. iteratorMethods.forEach(method => {
  1164. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1165. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1166. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1167. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1168. });
  1169. return [
  1170. mutableInstrumentations,
  1171. readonlyInstrumentations,
  1172. shallowInstrumentations,
  1173. shallowReadonlyInstrumentations
  1174. ];
  1175. }
  1176. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1177. function createInstrumentationGetter(isReadonly, shallow) {
  1178. const instrumentations = shallow
  1179. ? isReadonly
  1180. ? shallowReadonlyInstrumentations
  1181. : shallowInstrumentations
  1182. : isReadonly
  1183. ? readonlyInstrumentations
  1184. : mutableInstrumentations;
  1185. return (target, key, receiver) => {
  1186. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  1187. return !isReadonly;
  1188. }
  1189. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  1190. return isReadonly;
  1191. }
  1192. else if (key === "__v_raw" /* RAW */) {
  1193. return target;
  1194. }
  1195. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1196. ? instrumentations
  1197. : target, key, receiver);
  1198. };
  1199. }
  1200. const mutableCollectionHandlers = {
  1201. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1202. };
  1203. const shallowCollectionHandlers = {
  1204. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1205. };
  1206. const readonlyCollectionHandlers = {
  1207. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1208. };
  1209. const shallowReadonlyCollectionHandlers = {
  1210. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1211. };
  1212. function checkIdentityKeys(target, has, key) {
  1213. const rawKey = toRaw(key);
  1214. if (rawKey !== key && has.call(target, rawKey)) {
  1215. const type = toRawType(target);
  1216. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1217. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1218. `which can lead to inconsistencies. ` +
  1219. `Avoid differentiating between the raw and reactive versions ` +
  1220. `of an object and only use the reactive version if possible.`);
  1221. }
  1222. }
  1223. const reactiveMap = new WeakMap();
  1224. const shallowReactiveMap = new WeakMap();
  1225. const readonlyMap = new WeakMap();
  1226. const shallowReadonlyMap = new WeakMap();
  1227. function targetTypeMap(rawType) {
  1228. switch (rawType) {
  1229. case 'Object':
  1230. case 'Array':
  1231. return 1 /* COMMON */;
  1232. case 'Map':
  1233. case 'Set':
  1234. case 'WeakMap':
  1235. case 'WeakSet':
  1236. return 2 /* COLLECTION */;
  1237. default:
  1238. return 0 /* INVALID */;
  1239. }
  1240. }
  1241. function getTargetType(value) {
  1242. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  1243. ? 0 /* INVALID */
  1244. : targetTypeMap(toRawType(value));
  1245. }
  1246. function reactive(target) {
  1247. // if trying to observe a readonly proxy, return the readonly version.
  1248. if (isReadonly(target)) {
  1249. return target;
  1250. }
  1251. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1252. }
  1253. /**
  1254. * Return a shallowly-reactive copy of the original object, where only the root
  1255. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1256. * root level).
  1257. */
  1258. function shallowReactive(target) {
  1259. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1260. }
  1261. /**
  1262. * Creates a readonly copy of the original object. Note the returned copy is not
  1263. * made reactive, but `readonly` can be called on an already reactive object.
  1264. */
  1265. function readonly(target) {
  1266. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1267. }
  1268. /**
  1269. * Returns a reactive-copy of the original object, where only the root level
  1270. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1271. * returned properties.
  1272. * This is used for creating the props proxy object for stateful components.
  1273. */
  1274. function shallowReadonly(target) {
  1275. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1276. }
  1277. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1278. if (!isObject(target)) {
  1279. {
  1280. console.warn(`value cannot be made reactive: ${String(target)}`);
  1281. }
  1282. return target;
  1283. }
  1284. // target is already a Proxy, return it.
  1285. // exception: calling readonly() on a reactive object
  1286. if (target["__v_raw" /* RAW */] &&
  1287. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1288. return target;
  1289. }
  1290. // target already has corresponding Proxy
  1291. const existingProxy = proxyMap.get(target);
  1292. if (existingProxy) {
  1293. return existingProxy;
  1294. }
  1295. // only a whitelist of value types can be observed.
  1296. const targetType = getTargetType(target);
  1297. if (targetType === 0 /* INVALID */) {
  1298. return target;
  1299. }
  1300. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1301. proxyMap.set(target, proxy);
  1302. return proxy;
  1303. }
  1304. function isReactive(value) {
  1305. if (isReadonly(value)) {
  1306. return isReactive(value["__v_raw" /* RAW */]);
  1307. }
  1308. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1309. }
  1310. function isReadonly(value) {
  1311. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1312. }
  1313. function isShallow(value) {
  1314. return !!(value && value["__v_isShallow" /* IS_SHALLOW */]);
  1315. }
  1316. function isProxy(value) {
  1317. return isReactive(value) || isReadonly(value);
  1318. }
  1319. function toRaw(observed) {
  1320. const raw = observed && observed["__v_raw" /* RAW */];
  1321. return raw ? toRaw(raw) : observed;
  1322. }
  1323. function markRaw(value) {
  1324. def(value, "__v_skip" /* SKIP */, true);
  1325. return value;
  1326. }
  1327. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1328. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1329. function trackRefValue(ref) {
  1330. if (shouldTrack && activeEffect) {
  1331. ref = toRaw(ref);
  1332. {
  1333. trackEffects(ref.dep || (ref.dep = createDep()), {
  1334. target: ref,
  1335. type: "get" /* GET */,
  1336. key: 'value'
  1337. });
  1338. }
  1339. }
  1340. }
  1341. function triggerRefValue(ref, newVal) {
  1342. ref = toRaw(ref);
  1343. if (ref.dep) {
  1344. {
  1345. triggerEffects(ref.dep, {
  1346. target: ref,
  1347. type: "set" /* SET */,
  1348. key: 'value',
  1349. newValue: newVal
  1350. });
  1351. }
  1352. }
  1353. }
  1354. function isRef(r) {
  1355. return !!(r && r.__v_isRef === true);
  1356. }
  1357. function ref(value) {
  1358. return createRef(value, false);
  1359. }
  1360. function shallowRef(value) {
  1361. return createRef(value, true);
  1362. }
  1363. function createRef(rawValue, shallow) {
  1364. if (isRef(rawValue)) {
  1365. return rawValue;
  1366. }
  1367. return new RefImpl(rawValue, shallow);
  1368. }
  1369. class RefImpl {
  1370. constructor(value, __v_isShallow) {
  1371. this.__v_isShallow = __v_isShallow;
  1372. this.dep = undefined;
  1373. this.__v_isRef = true;
  1374. this._rawValue = __v_isShallow ? value : toRaw(value);
  1375. this._value = __v_isShallow ? value : toReactive(value);
  1376. }
  1377. get value() {
  1378. trackRefValue(this);
  1379. return this._value;
  1380. }
  1381. set value(newVal) {
  1382. newVal = this.__v_isShallow ? newVal : toRaw(newVal);
  1383. if (hasChanged(newVal, this._rawValue)) {
  1384. this._rawValue = newVal;
  1385. this._value = this.__v_isShallow ? newVal : toReactive(newVal);
  1386. triggerRefValue(this, newVal);
  1387. }
  1388. }
  1389. }
  1390. function triggerRef(ref) {
  1391. triggerRefValue(ref, ref.value );
  1392. }
  1393. function unref(ref) {
  1394. return isRef(ref) ? ref.value : ref;
  1395. }
  1396. const shallowUnwrapHandlers = {
  1397. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1398. set: (target, key, value, receiver) => {
  1399. const oldValue = target[key];
  1400. if (isRef(oldValue) && !isRef(value)) {
  1401. oldValue.value = value;
  1402. return true;
  1403. }
  1404. else {
  1405. return Reflect.set(target, key, value, receiver);
  1406. }
  1407. }
  1408. };
  1409. function proxyRefs(objectWithRefs) {
  1410. return isReactive(objectWithRefs)
  1411. ? objectWithRefs
  1412. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1413. }
  1414. class CustomRefImpl {
  1415. constructor(factory) {
  1416. this.dep = undefined;
  1417. this.__v_isRef = true;
  1418. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1419. this._get = get;
  1420. this._set = set;
  1421. }
  1422. get value() {
  1423. return this._get();
  1424. }
  1425. set value(newVal) {
  1426. this._set(newVal);
  1427. }
  1428. }
  1429. function customRef(factory) {
  1430. return new CustomRefImpl(factory);
  1431. }
  1432. function toRefs(object) {
  1433. if (!isProxy(object)) {
  1434. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1435. }
  1436. const ret = isArray(object) ? new Array(object.length) : {};
  1437. for (const key in object) {
  1438. ret[key] = toRef(object, key);
  1439. }
  1440. return ret;
  1441. }
  1442. class ObjectRefImpl {
  1443. constructor(_object, _key, _defaultValue) {
  1444. this._object = _object;
  1445. this._key = _key;
  1446. this._defaultValue = _defaultValue;
  1447. this.__v_isRef = true;
  1448. }
  1449. get value() {
  1450. const val = this._object[this._key];
  1451. return val === undefined ? this._defaultValue : val;
  1452. }
  1453. set value(newVal) {
  1454. this._object[this._key] = newVal;
  1455. }
  1456. }
  1457. function toRef(object, key, defaultValue) {
  1458. const val = object[key];
  1459. return isRef(val)
  1460. ? val
  1461. : new ObjectRefImpl(object, key, defaultValue);
  1462. }
  1463. class ComputedRefImpl {
  1464. constructor(getter, _setter, isReadonly, isSSR) {
  1465. this._setter = _setter;
  1466. this.dep = undefined;
  1467. this.__v_isRef = true;
  1468. this._dirty = true;
  1469. this.effect = new ReactiveEffect(getter, () => {
  1470. if (!this._dirty) {
  1471. this._dirty = true;
  1472. triggerRefValue(this);
  1473. }
  1474. });
  1475. this.effect.computed = this;
  1476. this.effect.active = this._cacheable = !isSSR;
  1477. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1478. }
  1479. get value() {
  1480. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1481. const self = toRaw(this);
  1482. trackRefValue(self);
  1483. if (self._dirty || !self._cacheable) {
  1484. self._dirty = false;
  1485. self._value = self.effect.run();
  1486. }
  1487. return self._value;
  1488. }
  1489. set value(newValue) {
  1490. this._setter(newValue);
  1491. }
  1492. }
  1493. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1494. let getter;
  1495. let setter;
  1496. const onlyGetter = isFunction(getterOrOptions);
  1497. if (onlyGetter) {
  1498. getter = getterOrOptions;
  1499. setter = () => {
  1500. console.warn('Write operation failed: computed value is readonly');
  1501. }
  1502. ;
  1503. }
  1504. else {
  1505. getter = getterOrOptions.get;
  1506. setter = getterOrOptions.set;
  1507. }
  1508. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1509. if (debugOptions && !isSSR) {
  1510. cRef.effect.onTrack = debugOptions.onTrack;
  1511. cRef.effect.onTrigger = debugOptions.onTrigger;
  1512. }
  1513. return cRef;
  1514. }
  1515. const stack = [];
  1516. function pushWarningContext(vnode) {
  1517. stack.push(vnode);
  1518. }
  1519. function popWarningContext() {
  1520. stack.pop();
  1521. }
  1522. function warn$1(msg, ...args) {
  1523. // avoid props formatting or warn handler tracking deps that might be mutated
  1524. // during patch, leading to infinite recursion.
  1525. pauseTracking();
  1526. const instance = stack.length ? stack[stack.length - 1].component : null;
  1527. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1528. const trace = getComponentTrace();
  1529. if (appWarnHandler) {
  1530. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1531. msg + args.join(''),
  1532. instance && instance.proxy,
  1533. trace
  1534. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1535. .join('\n'),
  1536. trace
  1537. ]);
  1538. }
  1539. else {
  1540. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1541. /* istanbul ignore if */
  1542. if (trace.length &&
  1543. // avoid spamming console during tests
  1544. !false) {
  1545. warnArgs.push(`\n`, ...formatTrace(trace));
  1546. }
  1547. console.warn(...warnArgs);
  1548. }
  1549. resetTracking();
  1550. }
  1551. function getComponentTrace() {
  1552. let currentVNode = stack[stack.length - 1];
  1553. if (!currentVNode) {
  1554. return [];
  1555. }
  1556. // we can't just use the stack because it will be incomplete during updates
  1557. // that did not start from the root. Re-construct the parent chain using
  1558. // instance parent pointers.
  1559. const normalizedStack = [];
  1560. while (currentVNode) {
  1561. const last = normalizedStack[0];
  1562. if (last && last.vnode === currentVNode) {
  1563. last.recurseCount++;
  1564. }
  1565. else {
  1566. normalizedStack.push({
  1567. vnode: currentVNode,
  1568. recurseCount: 0
  1569. });
  1570. }
  1571. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1572. currentVNode = parentInstance && parentInstance.vnode;
  1573. }
  1574. return normalizedStack;
  1575. }
  1576. /* istanbul ignore next */
  1577. function formatTrace(trace) {
  1578. const logs = [];
  1579. trace.forEach((entry, i) => {
  1580. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1581. });
  1582. return logs;
  1583. }
  1584. function formatTraceEntry({ vnode, recurseCount }) {
  1585. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1586. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1587. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1588. const close = `>` + postfix;
  1589. return vnode.props
  1590. ? [open, ...formatProps(vnode.props), close]
  1591. : [open + close];
  1592. }
  1593. /* istanbul ignore next */
  1594. function formatProps(props) {
  1595. const res = [];
  1596. const keys = Object.keys(props);
  1597. keys.slice(0, 3).forEach(key => {
  1598. res.push(...formatProp(key, props[key]));
  1599. });
  1600. if (keys.length > 3) {
  1601. res.push(` ...`);
  1602. }
  1603. return res;
  1604. }
  1605. /* istanbul ignore next */
  1606. function formatProp(key, value, raw) {
  1607. if (isString(value)) {
  1608. value = JSON.stringify(value);
  1609. return raw ? value : [`${key}=${value}`];
  1610. }
  1611. else if (typeof value === 'number' ||
  1612. typeof value === 'boolean' ||
  1613. value == null) {
  1614. return raw ? value : [`${key}=${value}`];
  1615. }
  1616. else if (isRef(value)) {
  1617. value = formatProp(key, toRaw(value.value), true);
  1618. return raw ? value : [`${key}=Ref<`, value, `>`];
  1619. }
  1620. else if (isFunction(value)) {
  1621. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1622. }
  1623. else {
  1624. value = toRaw(value);
  1625. return raw ? value : [`${key}=`, value];
  1626. }
  1627. }
  1628. const ErrorTypeStrings = {
  1629. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  1630. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1631. ["c" /* CREATED */]: 'created hook',
  1632. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1633. ["m" /* MOUNTED */]: 'mounted hook',
  1634. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1635. ["u" /* UPDATED */]: 'updated',
  1636. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1637. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1638. ["a" /* ACTIVATED */]: 'activated hook',
  1639. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1640. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1641. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1642. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1643. [0 /* SETUP_FUNCTION */]: 'setup function',
  1644. [1 /* RENDER_FUNCTION */]: 'render function',
  1645. [2 /* WATCH_GETTER */]: 'watcher getter',
  1646. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1647. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1648. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1649. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1650. [7 /* VNODE_HOOK */]: 'vnode hook',
  1651. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1652. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1653. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1654. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1655. [12 /* FUNCTION_REF */]: 'ref function',
  1656. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1657. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1658. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1659. };
  1660. function callWithErrorHandling(fn, instance, type, args) {
  1661. let res;
  1662. try {
  1663. res = args ? fn(...args) : fn();
  1664. }
  1665. catch (err) {
  1666. handleError(err, instance, type);
  1667. }
  1668. return res;
  1669. }
  1670. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1671. if (isFunction(fn)) {
  1672. const res = callWithErrorHandling(fn, instance, type, args);
  1673. if (res && isPromise(res)) {
  1674. res.catch(err => {
  1675. handleError(err, instance, type);
  1676. });
  1677. }
  1678. return res;
  1679. }
  1680. const values = [];
  1681. for (let i = 0; i < fn.length; i++) {
  1682. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1683. }
  1684. return values;
  1685. }
  1686. function handleError(err, instance, type, throwInDev = true) {
  1687. const contextVNode = instance ? instance.vnode : null;
  1688. if (instance) {
  1689. let cur = instance.parent;
  1690. // the exposed instance is the render proxy to keep it consistent with 2.x
  1691. const exposedInstance = instance.proxy;
  1692. // in production the hook receives only the error code
  1693. const errorInfo = ErrorTypeStrings[type] ;
  1694. while (cur) {
  1695. const errorCapturedHooks = cur.ec;
  1696. if (errorCapturedHooks) {
  1697. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1698. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1699. return;
  1700. }
  1701. }
  1702. }
  1703. cur = cur.parent;
  1704. }
  1705. // app-level handling
  1706. const appErrorHandler = instance.appContext.config.errorHandler;
  1707. if (appErrorHandler) {
  1708. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1709. return;
  1710. }
  1711. }
  1712. logError(err, type, contextVNode, throwInDev);
  1713. }
  1714. function logError(err, type, contextVNode, throwInDev = true) {
  1715. {
  1716. const info = ErrorTypeStrings[type];
  1717. if (contextVNode) {
  1718. pushWarningContext(contextVNode);
  1719. }
  1720. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1721. if (contextVNode) {
  1722. popWarningContext();
  1723. }
  1724. // crash in dev by default so it's more noticeable
  1725. if (throwInDev) {
  1726. throw err;
  1727. }
  1728. else {
  1729. console.error(err);
  1730. }
  1731. }
  1732. }
  1733. let isFlushing = false;
  1734. let isFlushPending = false;
  1735. const queue = [];
  1736. let flushIndex = 0;
  1737. const pendingPreFlushCbs = [];
  1738. let activePreFlushCbs = null;
  1739. let preFlushIndex = 0;
  1740. const pendingPostFlushCbs = [];
  1741. let activePostFlushCbs = null;
  1742. let postFlushIndex = 0;
  1743. const resolvedPromise = Promise.resolve();
  1744. let currentFlushPromise = null;
  1745. let currentPreFlushParentJob = null;
  1746. const RECURSION_LIMIT = 100;
  1747. function nextTick(fn) {
  1748. const p = currentFlushPromise || resolvedPromise;
  1749. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1750. }
  1751. // #2768
  1752. // Use binary-search to find a suitable position in the queue,
  1753. // so that the queue maintains the increasing order of job's id,
  1754. // which can prevent the job from being skipped and also can avoid repeated patching.
  1755. function findInsertionIndex(id) {
  1756. // the start index should be `flushIndex + 1`
  1757. let start = flushIndex + 1;
  1758. let end = queue.length;
  1759. while (start < end) {
  1760. const middle = (start + end) >>> 1;
  1761. const middleJobId = getId(queue[middle]);
  1762. middleJobId < id ? (start = middle + 1) : (end = middle);
  1763. }
  1764. return start;
  1765. }
  1766. function queueJob(job) {
  1767. // the dedupe search uses the startIndex argument of Array.includes()
  1768. // by default the search index includes the current job that is being run
  1769. // so it cannot recursively trigger itself again.
  1770. // if the job is a watch() callback, the search will start with a +1 index to
  1771. // allow it recursively trigger itself - it is the user's responsibility to
  1772. // ensure it doesn't end up in an infinite loop.
  1773. if ((!queue.length ||
  1774. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1775. job !== currentPreFlushParentJob) {
  1776. if (job.id == null) {
  1777. queue.push(job);
  1778. }
  1779. else {
  1780. queue.splice(findInsertionIndex(job.id), 0, job);
  1781. }
  1782. queueFlush();
  1783. }
  1784. }
  1785. function queueFlush() {
  1786. if (!isFlushing && !isFlushPending) {
  1787. isFlushPending = true;
  1788. currentFlushPromise = resolvedPromise.then(flushJobs);
  1789. }
  1790. }
  1791. function invalidateJob(job) {
  1792. const i = queue.indexOf(job);
  1793. if (i > flushIndex) {
  1794. queue.splice(i, 1);
  1795. }
  1796. }
  1797. function queueCb(cb, activeQueue, pendingQueue, index) {
  1798. if (!isArray(cb)) {
  1799. if (!activeQueue ||
  1800. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1801. pendingQueue.push(cb);
  1802. }
  1803. }
  1804. else {
  1805. // if cb is an array, it is a component lifecycle hook which can only be
  1806. // triggered by a job, which is already deduped in the main queue, so
  1807. // we can skip duplicate check here to improve perf
  1808. pendingQueue.push(...cb);
  1809. }
  1810. queueFlush();
  1811. }
  1812. function queuePreFlushCb(cb) {
  1813. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1814. }
  1815. function queuePostFlushCb(cb) {
  1816. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1817. }
  1818. function flushPreFlushCbs(seen, parentJob = null) {
  1819. if (pendingPreFlushCbs.length) {
  1820. currentPreFlushParentJob = parentJob;
  1821. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1822. pendingPreFlushCbs.length = 0;
  1823. {
  1824. seen = seen || new Map();
  1825. }
  1826. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1827. if (checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  1828. continue;
  1829. }
  1830. activePreFlushCbs[preFlushIndex]();
  1831. }
  1832. activePreFlushCbs = null;
  1833. preFlushIndex = 0;
  1834. currentPreFlushParentJob = null;
  1835. // recursively flush until it drains
  1836. flushPreFlushCbs(seen, parentJob);
  1837. }
  1838. }
  1839. function flushPostFlushCbs(seen) {
  1840. if (pendingPostFlushCbs.length) {
  1841. const deduped = [...new Set(pendingPostFlushCbs)];
  1842. pendingPostFlushCbs.length = 0;
  1843. // #1947 already has active queue, nested flushPostFlushCbs call
  1844. if (activePostFlushCbs) {
  1845. activePostFlushCbs.push(...deduped);
  1846. return;
  1847. }
  1848. activePostFlushCbs = deduped;
  1849. {
  1850. seen = seen || new Map();
  1851. }
  1852. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1853. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1854. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1855. continue;
  1856. }
  1857. activePostFlushCbs[postFlushIndex]();
  1858. }
  1859. activePostFlushCbs = null;
  1860. postFlushIndex = 0;
  1861. }
  1862. }
  1863. const getId = (job) => job.id == null ? Infinity : job.id;
  1864. function flushJobs(seen) {
  1865. isFlushPending = false;
  1866. isFlushing = true;
  1867. {
  1868. seen = seen || new Map();
  1869. }
  1870. flushPreFlushCbs(seen);
  1871. // Sort queue before flush.
  1872. // This ensures that:
  1873. // 1. Components are updated from parent to child. (because parent is always
  1874. // created before the child so its render effect will have smaller
  1875. // priority number)
  1876. // 2. If a component is unmounted during a parent component's update,
  1877. // its update can be skipped.
  1878. queue.sort((a, b) => getId(a) - getId(b));
  1879. // conditional usage of checkRecursiveUpdate must be determined out of
  1880. // try ... catch block since Rollup by default de-optimizes treeshaking
  1881. // inside try-catch. This can leave all warning code unshaked. Although
  1882. // they would get eventually shaken by a minifier like terser, some minifiers
  1883. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1884. const check = (job) => checkRecursiveUpdates(seen, job)
  1885. ;
  1886. try {
  1887. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1888. const job = queue[flushIndex];
  1889. if (job && job.active !== false) {
  1890. if (true && check(job)) {
  1891. continue;
  1892. }
  1893. // console.log(`running:`, job.id)
  1894. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1895. }
  1896. }
  1897. }
  1898. finally {
  1899. flushIndex = 0;
  1900. queue.length = 0;
  1901. flushPostFlushCbs(seen);
  1902. isFlushing = false;
  1903. currentFlushPromise = null;
  1904. // some postFlushCb queued jobs!
  1905. // keep flushing until it drains.
  1906. if (queue.length ||
  1907. pendingPreFlushCbs.length ||
  1908. pendingPostFlushCbs.length) {
  1909. flushJobs(seen);
  1910. }
  1911. }
  1912. }
  1913. function checkRecursiveUpdates(seen, fn) {
  1914. if (!seen.has(fn)) {
  1915. seen.set(fn, 1);
  1916. }
  1917. else {
  1918. const count = seen.get(fn);
  1919. if (count > RECURSION_LIMIT) {
  1920. const instance = fn.ownerInstance;
  1921. const componentName = instance && getComponentName(instance.type);
  1922. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1923. `This means you have a reactive effect that is mutating its own ` +
  1924. `dependencies and thus recursively triggering itself. Possible sources ` +
  1925. `include component template, render function, updated hook or ` +
  1926. `watcher source function.`);
  1927. return true;
  1928. }
  1929. else {
  1930. seen.set(fn, count + 1);
  1931. }
  1932. }
  1933. }
  1934. /* eslint-disable no-restricted-globals */
  1935. let isHmrUpdating = false;
  1936. const hmrDirtyComponents = new Set();
  1937. // Expose the HMR runtime on the global object
  1938. // This makes it entirely tree-shakable without polluting the exports and makes
  1939. // it easier to be used in toolings like vue-loader
  1940. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1941. // to be set so that its instances can be registered / removed.
  1942. {
  1943. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1944. createRecord: tryWrap(createRecord),
  1945. rerender: tryWrap(rerender),
  1946. reload: tryWrap(reload)
  1947. };
  1948. }
  1949. const map = new Map();
  1950. function registerHMR(instance) {
  1951. const id = instance.type.__hmrId;
  1952. let record = map.get(id);
  1953. if (!record) {
  1954. createRecord(id, instance.type);
  1955. record = map.get(id);
  1956. }
  1957. record.instances.add(instance);
  1958. }
  1959. function unregisterHMR(instance) {
  1960. map.get(instance.type.__hmrId).instances.delete(instance);
  1961. }
  1962. function createRecord(id, initialDef) {
  1963. if (map.has(id)) {
  1964. return false;
  1965. }
  1966. map.set(id, {
  1967. initialDef: normalizeClassComponent(initialDef),
  1968. instances: new Set()
  1969. });
  1970. return true;
  1971. }
  1972. function normalizeClassComponent(component) {
  1973. return isClassComponent(component) ? component.__vccOpts : component;
  1974. }
  1975. function rerender(id, newRender) {
  1976. const record = map.get(id);
  1977. if (!record) {
  1978. return;
  1979. }
  1980. // update initial record (for not-yet-rendered component)
  1981. record.initialDef.render = newRender;
  1982. [...record.instances].forEach(instance => {
  1983. if (newRender) {
  1984. instance.render = newRender;
  1985. normalizeClassComponent(instance.type).render = newRender;
  1986. }
  1987. instance.renderCache = [];
  1988. // this flag forces child components with slot content to update
  1989. isHmrUpdating = true;
  1990. instance.update();
  1991. isHmrUpdating = false;
  1992. });
  1993. }
  1994. function reload(id, newComp) {
  1995. const record = map.get(id);
  1996. if (!record)
  1997. return;
  1998. newComp = normalizeClassComponent(newComp);
  1999. // update initial def (for not-yet-rendered components)
  2000. updateComponentDef(record.initialDef, newComp);
  2001. // create a snapshot which avoids the set being mutated during updates
  2002. const instances = [...record.instances];
  2003. for (const instance of instances) {
  2004. const oldComp = normalizeClassComponent(instance.type);
  2005. if (!hmrDirtyComponents.has(oldComp)) {
  2006. // 1. Update existing comp definition to match new one
  2007. if (oldComp !== record.initialDef) {
  2008. updateComponentDef(oldComp, newComp);
  2009. }
  2010. // 2. mark definition dirty. This forces the renderer to replace the
  2011. // component on patch.
  2012. hmrDirtyComponents.add(oldComp);
  2013. }
  2014. // 3. invalidate options resolution cache
  2015. instance.appContext.optionsCache.delete(instance.type);
  2016. // 4. actually update
  2017. if (instance.ceReload) {
  2018. // custom element
  2019. hmrDirtyComponents.add(oldComp);
  2020. instance.ceReload(newComp.styles);
  2021. hmrDirtyComponents.delete(oldComp);
  2022. }
  2023. else if (instance.parent) {
  2024. // 4. Force the parent instance to re-render. This will cause all updated
  2025. // components to be unmounted and re-mounted. Queue the update so that we
  2026. // don't end up forcing the same parent to re-render multiple times.
  2027. queueJob(instance.parent.update);
  2028. // instance is the inner component of an async custom element
  2029. // invoke to reset styles
  2030. if (instance.parent.type.__asyncLoader &&
  2031. instance.parent.ceReload) {
  2032. instance.parent.ceReload(newComp.styles);
  2033. }
  2034. }
  2035. else if (instance.appContext.reload) {
  2036. // root instance mounted via createApp() has a reload method
  2037. instance.appContext.reload();
  2038. }
  2039. else if (typeof window !== 'undefined') {
  2040. // root instance inside tree created via raw render(). Force reload.
  2041. window.location.reload();
  2042. }
  2043. else {
  2044. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  2045. }
  2046. }
  2047. // 5. make sure to cleanup dirty hmr components after update
  2048. queuePostFlushCb(() => {
  2049. for (const instance of instances) {
  2050. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  2051. }
  2052. });
  2053. }
  2054. function updateComponentDef(oldComp, newComp) {
  2055. extend(oldComp, newComp);
  2056. for (const key in oldComp) {
  2057. if (key !== '__file' && !(key in newComp)) {
  2058. delete oldComp[key];
  2059. }
  2060. }
  2061. }
  2062. function tryWrap(fn) {
  2063. return (id, arg) => {
  2064. try {
  2065. return fn(id, arg);
  2066. }
  2067. catch (e) {
  2068. console.error(e);
  2069. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2070. `Full reload required.`);
  2071. }
  2072. };
  2073. }
  2074. let buffer = [];
  2075. let devtoolsNotInstalled = false;
  2076. function emit(event, ...args) {
  2077. if (exports.devtools) {
  2078. exports.devtools.emit(event, ...args);
  2079. }
  2080. else if (!devtoolsNotInstalled) {
  2081. buffer.push({ event, args });
  2082. }
  2083. }
  2084. function setDevtoolsHook(hook, target) {
  2085. var _a, _b;
  2086. exports.devtools = hook;
  2087. if (exports.devtools) {
  2088. exports.devtools.enabled = true;
  2089. buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
  2090. buffer = [];
  2091. }
  2092. else if (
  2093. // handle late devtools injection - only do this if we are in an actual
  2094. // browser environment to avoid the timer handle stalling test runner exit
  2095. // (#4815)
  2096. // eslint-disable-next-line no-restricted-globals
  2097. typeof window !== 'undefined' &&
  2098. // some envs mock window but not fully
  2099. window.HTMLElement &&
  2100. // also exclude jsdom
  2101. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2102. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2103. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2104. replay.push((newHook) => {
  2105. setDevtoolsHook(newHook, target);
  2106. });
  2107. // clear buffer after 3s - the user probably doesn't have devtools installed
  2108. // at all, and keeping the buffer will cause memory leaks (#4738)
  2109. setTimeout(() => {
  2110. if (!exports.devtools) {
  2111. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2112. devtoolsNotInstalled = true;
  2113. buffer = [];
  2114. }
  2115. }, 3000);
  2116. }
  2117. else {
  2118. // non-browser env, assume not installed
  2119. devtoolsNotInstalled = true;
  2120. buffer = [];
  2121. }
  2122. }
  2123. function devtoolsInitApp(app, version) {
  2124. emit("app:init" /* APP_INIT */, app, version, {
  2125. Fragment,
  2126. Text,
  2127. Comment,
  2128. Static
  2129. });
  2130. }
  2131. function devtoolsUnmountApp(app) {
  2132. emit("app:unmount" /* APP_UNMOUNT */, app);
  2133. }
  2134. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  2135. const devtoolsComponentUpdated =
  2136. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  2137. const devtoolsComponentRemoved =
  2138. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  2139. function createDevtoolsComponentHook(hook) {
  2140. return (component) => {
  2141. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2142. };
  2143. }
  2144. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  2145. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  2146. function createDevtoolsPerformanceHook(hook) {
  2147. return (component, type, time) => {
  2148. emit(hook, component.appContext.app, component.uid, component, type, time);
  2149. };
  2150. }
  2151. function devtoolsComponentEmit(component, event, params) {
  2152. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2153. }
  2154. function emit$1(instance, event, ...rawArgs) {
  2155. const props = instance.vnode.props || EMPTY_OBJ;
  2156. {
  2157. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2158. if (emitsOptions) {
  2159. if (!(event in emitsOptions) &&
  2160. !(false )) {
  2161. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2162. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  2163. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2164. }
  2165. }
  2166. else {
  2167. const validator = emitsOptions[event];
  2168. if (isFunction(validator)) {
  2169. const isValid = validator(...rawArgs);
  2170. if (!isValid) {
  2171. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  2172. }
  2173. }
  2174. }
  2175. }
  2176. }
  2177. let args = rawArgs;
  2178. const isModelListener = event.startsWith('update:');
  2179. // for v-model update:xxx events, apply modifiers on args
  2180. const modelArg = isModelListener && event.slice(7);
  2181. if (modelArg && modelArg in props) {
  2182. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2183. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2184. if (trim) {
  2185. args = rawArgs.map(a => a.trim());
  2186. }
  2187. else if (number) {
  2188. args = rawArgs.map(toNumber);
  2189. }
  2190. }
  2191. {
  2192. devtoolsComponentEmit(instance, event, args);
  2193. }
  2194. {
  2195. const lowerCaseEvent = event.toLowerCase();
  2196. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2197. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  2198. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2199. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2200. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2201. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2202. }
  2203. }
  2204. let handlerName;
  2205. let handler = props[(handlerName = toHandlerKey(event))] ||
  2206. // also try camelCase event handler (#2249)
  2207. props[(handlerName = toHandlerKey(camelize(event)))];
  2208. // for v-model update:xxx events, also trigger kebab-case equivalent
  2209. // for props passed via kebab-case
  2210. if (!handler && isModelListener) {
  2211. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2212. }
  2213. if (handler) {
  2214. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2215. }
  2216. const onceHandler = props[handlerName + `Once`];
  2217. if (onceHandler) {
  2218. if (!instance.emitted) {
  2219. instance.emitted = {};
  2220. }
  2221. else if (instance.emitted[handlerName]) {
  2222. return;
  2223. }
  2224. instance.emitted[handlerName] = true;
  2225. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2226. }
  2227. }
  2228. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2229. const cache = appContext.emitsCache;
  2230. const cached = cache.get(comp);
  2231. if (cached !== undefined) {
  2232. return cached;
  2233. }
  2234. const raw = comp.emits;
  2235. let normalized = {};
  2236. // apply mixin/extends props
  2237. let hasExtends = false;
  2238. if (!isFunction(comp)) {
  2239. const extendEmits = (raw) => {
  2240. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2241. if (normalizedFromExtend) {
  2242. hasExtends = true;
  2243. extend(normalized, normalizedFromExtend);
  2244. }
  2245. };
  2246. if (!asMixin && appContext.mixins.length) {
  2247. appContext.mixins.forEach(extendEmits);
  2248. }
  2249. if (comp.extends) {
  2250. extendEmits(comp.extends);
  2251. }
  2252. if (comp.mixins) {
  2253. comp.mixins.forEach(extendEmits);
  2254. }
  2255. }
  2256. if (!raw && !hasExtends) {
  2257. cache.set(comp, null);
  2258. return null;
  2259. }
  2260. if (isArray(raw)) {
  2261. raw.forEach(key => (normalized[key] = null));
  2262. }
  2263. else {
  2264. extend(normalized, raw);
  2265. }
  2266. cache.set(comp, normalized);
  2267. return normalized;
  2268. }
  2269. // Check if an incoming prop key is a declared emit event listener.
  2270. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2271. // both considered matched listeners.
  2272. function isEmitListener(options, key) {
  2273. if (!options || !isOn(key)) {
  2274. return false;
  2275. }
  2276. key = key.slice(2).replace(/Once$/, '');
  2277. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2278. hasOwn(options, hyphenate(key)) ||
  2279. hasOwn(options, key));
  2280. }
  2281. /**
  2282. * mark the current rendering instance for asset resolution (e.g.
  2283. * resolveComponent, resolveDirective) during render
  2284. */
  2285. let currentRenderingInstance = null;
  2286. let currentScopeId = null;
  2287. /**
  2288. * Note: rendering calls maybe nested. The function returns the parent rendering
  2289. * instance if present, which should be restored after the render is done:
  2290. *
  2291. * ```js
  2292. * const prev = setCurrentRenderingInstance(i)
  2293. * // ...render
  2294. * setCurrentRenderingInstance(prev)
  2295. * ```
  2296. */
  2297. function setCurrentRenderingInstance(instance) {
  2298. const prev = currentRenderingInstance;
  2299. currentRenderingInstance = instance;
  2300. currentScopeId = (instance && instance.type.__scopeId) || null;
  2301. return prev;
  2302. }
  2303. /**
  2304. * Set scope id when creating hoisted vnodes.
  2305. * @private compiler helper
  2306. */
  2307. function pushScopeId(id) {
  2308. currentScopeId = id;
  2309. }
  2310. /**
  2311. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2312. * API for backwards compat w/ code generated by compilers.
  2313. * @private
  2314. */
  2315. function popScopeId() {
  2316. currentScopeId = null;
  2317. }
  2318. /**
  2319. * Only for backwards compat
  2320. * @private
  2321. */
  2322. const withScopeId = (_id) => withCtx;
  2323. /**
  2324. * Wrap a slot function to memoize current rendering instance
  2325. * @private compiler helper
  2326. */
  2327. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2328. ) {
  2329. if (!ctx)
  2330. return fn;
  2331. // already normalized
  2332. if (fn._n) {
  2333. return fn;
  2334. }
  2335. const renderFnWithContext = (...args) => {
  2336. // If a user calls a compiled slot inside a template expression (#1745), it
  2337. // can mess up block tracking, so by default we disable block tracking and
  2338. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2339. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2340. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2341. if (renderFnWithContext._d) {
  2342. setBlockTracking(-1);
  2343. }
  2344. const prevInstance = setCurrentRenderingInstance(ctx);
  2345. const res = fn(...args);
  2346. setCurrentRenderingInstance(prevInstance);
  2347. if (renderFnWithContext._d) {
  2348. setBlockTracking(1);
  2349. }
  2350. {
  2351. devtoolsComponentUpdated(ctx);
  2352. }
  2353. return res;
  2354. };
  2355. // mark normalized to avoid duplicated wrapping
  2356. renderFnWithContext._n = true;
  2357. // mark this as compiled by default
  2358. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2359. // rendering flag.
  2360. renderFnWithContext._c = true;
  2361. // disable block tracking by default
  2362. renderFnWithContext._d = true;
  2363. return renderFnWithContext;
  2364. }
  2365. /**
  2366. * dev only flag to track whether $attrs was used during render.
  2367. * If $attrs was used during render then the warning for failed attrs
  2368. * fallthrough can be suppressed.
  2369. */
  2370. let accessedAttrs = false;
  2371. function markAttrsAccessed() {
  2372. accessedAttrs = true;
  2373. }
  2374. function renderComponentRoot(instance) {
  2375. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2376. let result;
  2377. let fallthroughAttrs;
  2378. const prev = setCurrentRenderingInstance(instance);
  2379. {
  2380. accessedAttrs = false;
  2381. }
  2382. try {
  2383. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  2384. // withProxy is a proxy with a different `has` trap only for
  2385. // runtime-compiled render functions using `with` block.
  2386. const proxyToUse = withProxy || proxy;
  2387. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2388. fallthroughAttrs = attrs;
  2389. }
  2390. else {
  2391. // functional
  2392. const render = Component;
  2393. // in dev, mark attrs accessed if optional props (attrs === props)
  2394. if (true && attrs === props) {
  2395. markAttrsAccessed();
  2396. }
  2397. result = normalizeVNode(render.length > 1
  2398. ? render(props, true
  2399. ? {
  2400. get attrs() {
  2401. markAttrsAccessed();
  2402. return attrs;
  2403. },
  2404. slots,
  2405. emit
  2406. }
  2407. : { attrs, slots, emit })
  2408. : render(props, null /* we know it doesn't need it */));
  2409. fallthroughAttrs = Component.props
  2410. ? attrs
  2411. : getFunctionalFallthrough(attrs);
  2412. }
  2413. }
  2414. catch (err) {
  2415. blockStack.length = 0;
  2416. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  2417. result = createVNode(Comment);
  2418. }
  2419. // attr merging
  2420. // in dev mode, comments are preserved, and it's possible for a template
  2421. // to have comments along side the root element which makes it a fragment
  2422. let root = result;
  2423. let setRoot = undefined;
  2424. if (result.patchFlag > 0 &&
  2425. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  2426. [root, setRoot] = getChildRoot(result);
  2427. }
  2428. if (fallthroughAttrs && inheritAttrs !== false) {
  2429. const keys = Object.keys(fallthroughAttrs);
  2430. const { shapeFlag } = root;
  2431. if (keys.length) {
  2432. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  2433. if (propsOptions && keys.some(isModelListener)) {
  2434. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2435. // prop, it indicates this component expects to handle v-model and
  2436. // it should not fallthrough.
  2437. // related: #1543, #1643, #1989
  2438. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2439. }
  2440. root = cloneVNode(root, fallthroughAttrs);
  2441. }
  2442. else if (!accessedAttrs && root.type !== Comment) {
  2443. const allAttrs = Object.keys(attrs);
  2444. const eventAttrs = [];
  2445. const extraAttrs = [];
  2446. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2447. const key = allAttrs[i];
  2448. if (isOn(key)) {
  2449. // ignore v-model handlers when they fail to fallthrough
  2450. if (!isModelListener(key)) {
  2451. // remove `on`, lowercase first letter to reflect event casing
  2452. // accurately
  2453. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2454. }
  2455. }
  2456. else {
  2457. extraAttrs.push(key);
  2458. }
  2459. }
  2460. if (extraAttrs.length) {
  2461. warn$1(`Extraneous non-props attributes (` +
  2462. `${extraAttrs.join(', ')}) ` +
  2463. `were passed to component but could not be automatically inherited ` +
  2464. `because component renders fragment or text root nodes.`);
  2465. }
  2466. if (eventAttrs.length) {
  2467. warn$1(`Extraneous non-emits event listeners (` +
  2468. `${eventAttrs.join(', ')}) ` +
  2469. `were passed to component but could not be automatically inherited ` +
  2470. `because component renders fragment or text root nodes. ` +
  2471. `If the listener is intended to be a component custom event listener only, ` +
  2472. `declare it using the "emits" option.`);
  2473. }
  2474. }
  2475. }
  2476. }
  2477. // inherit directives
  2478. if (vnode.dirs) {
  2479. if (!isElementRoot(root)) {
  2480. warn$1(`Runtime directive used on component with non-element root node. ` +
  2481. `The directives will not function as intended.`);
  2482. }
  2483. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2484. }
  2485. // inherit transition data
  2486. if (vnode.transition) {
  2487. if (!isElementRoot(root)) {
  2488. warn$1(`Component inside <Transition> renders non-element root node ` +
  2489. `that cannot be animated.`);
  2490. }
  2491. root.transition = vnode.transition;
  2492. }
  2493. if (setRoot) {
  2494. setRoot(root);
  2495. }
  2496. else {
  2497. result = root;
  2498. }
  2499. setCurrentRenderingInstance(prev);
  2500. return result;
  2501. }
  2502. /**
  2503. * dev only
  2504. * In dev mode, template root level comments are rendered, which turns the
  2505. * template into a fragment root, but we need to locate the single element
  2506. * root for attrs and scope id processing.
  2507. */
  2508. const getChildRoot = (vnode) => {
  2509. const rawChildren = vnode.children;
  2510. const dynamicChildren = vnode.dynamicChildren;
  2511. const childRoot = filterSingleRoot(rawChildren);
  2512. if (!childRoot) {
  2513. return [vnode, undefined];
  2514. }
  2515. const index = rawChildren.indexOf(childRoot);
  2516. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2517. const setRoot = (updatedRoot) => {
  2518. rawChildren[index] = updatedRoot;
  2519. if (dynamicChildren) {
  2520. if (dynamicIndex > -1) {
  2521. dynamicChildren[dynamicIndex] = updatedRoot;
  2522. }
  2523. else if (updatedRoot.patchFlag > 0) {
  2524. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2525. }
  2526. }
  2527. };
  2528. return [normalizeVNode(childRoot), setRoot];
  2529. };
  2530. function filterSingleRoot(children) {
  2531. let singleRoot;
  2532. for (let i = 0; i < children.length; i++) {
  2533. const child = children[i];
  2534. if (isVNode(child)) {
  2535. // ignore user comment
  2536. if (child.type !== Comment || child.children === 'v-if') {
  2537. if (singleRoot) {
  2538. // has more than 1 non-comment child, return now
  2539. return;
  2540. }
  2541. else {
  2542. singleRoot = child;
  2543. }
  2544. }
  2545. }
  2546. else {
  2547. return;
  2548. }
  2549. }
  2550. return singleRoot;
  2551. }
  2552. const getFunctionalFallthrough = (attrs) => {
  2553. let res;
  2554. for (const key in attrs) {
  2555. if (key === 'class' || key === 'style' || isOn(key)) {
  2556. (res || (res = {}))[key] = attrs[key];
  2557. }
  2558. }
  2559. return res;
  2560. };
  2561. const filterModelListeners = (attrs, props) => {
  2562. const res = {};
  2563. for (const key in attrs) {
  2564. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2565. res[key] = attrs[key];
  2566. }
  2567. }
  2568. return res;
  2569. };
  2570. const isElementRoot = (vnode) => {
  2571. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  2572. vnode.type === Comment // potential v-if branch switch
  2573. );
  2574. };
  2575. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2576. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2577. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2578. const emits = component.emitsOptions;
  2579. // Parent component's render function was hot-updated. Since this may have
  2580. // caused the child component's slots content to have changed, we need to
  2581. // force the child to update as well.
  2582. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2583. return true;
  2584. }
  2585. // force child update for runtime directive or transition on component vnode.
  2586. if (nextVNode.dirs || nextVNode.transition) {
  2587. return true;
  2588. }
  2589. if (optimized && patchFlag >= 0) {
  2590. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2591. // slot content that references values that might have changed,
  2592. // e.g. in a v-for
  2593. return true;
  2594. }
  2595. if (patchFlag & 16 /* FULL_PROPS */) {
  2596. if (!prevProps) {
  2597. return !!nextProps;
  2598. }
  2599. // presence of this flag indicates props are always non-null
  2600. return hasPropsChanged(prevProps, nextProps, emits);
  2601. }
  2602. else if (patchFlag & 8 /* PROPS */) {
  2603. const dynamicProps = nextVNode.dynamicProps;
  2604. for (let i = 0; i < dynamicProps.length; i++) {
  2605. const key = dynamicProps[i];
  2606. if (nextProps[key] !== prevProps[key] &&
  2607. !isEmitListener(emits, key)) {
  2608. return true;
  2609. }
  2610. }
  2611. }
  2612. }
  2613. else {
  2614. // this path is only taken by manually written render functions
  2615. // so presence of any children leads to a forced update
  2616. if (prevChildren || nextChildren) {
  2617. if (!nextChildren || !nextChildren.$stable) {
  2618. return true;
  2619. }
  2620. }
  2621. if (prevProps === nextProps) {
  2622. return false;
  2623. }
  2624. if (!prevProps) {
  2625. return !!nextProps;
  2626. }
  2627. if (!nextProps) {
  2628. return true;
  2629. }
  2630. return hasPropsChanged(prevProps, nextProps, emits);
  2631. }
  2632. return false;
  2633. }
  2634. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2635. const nextKeys = Object.keys(nextProps);
  2636. if (nextKeys.length !== Object.keys(prevProps).length) {
  2637. return true;
  2638. }
  2639. for (let i = 0; i < nextKeys.length; i++) {
  2640. const key = nextKeys[i];
  2641. if (nextProps[key] !== prevProps[key] &&
  2642. !isEmitListener(emitsOptions, key)) {
  2643. return true;
  2644. }
  2645. }
  2646. return false;
  2647. }
  2648. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2649. ) {
  2650. while (parent && parent.subTree === vnode) {
  2651. (vnode = parent.vnode).el = el;
  2652. parent = parent.parent;
  2653. }
  2654. }
  2655. const isSuspense = (type) => type.__isSuspense;
  2656. // Suspense exposes a component-like API, and is treated like a component
  2657. // in the compiler, but internally it's a special built-in type that hooks
  2658. // directly into the renderer.
  2659. const SuspenseImpl = {
  2660. name: 'Suspense',
  2661. // In order to make Suspense tree-shakable, we need to avoid importing it
  2662. // directly in the renderer. The renderer checks for the __isSuspense flag
  2663. // on a vnode's type and calls the `process` method, passing in renderer
  2664. // internals.
  2665. __isSuspense: true,
  2666. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2667. // platform-specific impl passed from renderer
  2668. rendererInternals) {
  2669. if (n1 == null) {
  2670. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2671. }
  2672. else {
  2673. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2674. }
  2675. },
  2676. hydrate: hydrateSuspense,
  2677. create: createSuspenseBoundary,
  2678. normalize: normalizeSuspenseChildren
  2679. };
  2680. // Force-casted public typing for h and TSX props inference
  2681. const Suspense = (SuspenseImpl );
  2682. function triggerEvent(vnode, name) {
  2683. const eventListener = vnode.props && vnode.props[name];
  2684. if (isFunction(eventListener)) {
  2685. eventListener();
  2686. }
  2687. }
  2688. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2689. const { p: patch, o: { createElement } } = rendererInternals;
  2690. const hiddenContainer = createElement('div');
  2691. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2692. // start mounting the content subtree in an off-dom container
  2693. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2694. // now check if we have encountered any async deps
  2695. if (suspense.deps > 0) {
  2696. // has async
  2697. // invoke @fallback event
  2698. triggerEvent(vnode, 'onPending');
  2699. triggerEvent(vnode, 'onFallback');
  2700. // mount the fallback tree
  2701. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2702. isSVG, slotScopeIds);
  2703. setActiveBranch(suspense, vnode.ssFallback);
  2704. }
  2705. else {
  2706. // Suspense has no async deps. Just resolve.
  2707. suspense.resolve();
  2708. }
  2709. }
  2710. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2711. const suspense = (n2.suspense = n1.suspense);
  2712. suspense.vnode = n2;
  2713. n2.el = n1.el;
  2714. const newBranch = n2.ssContent;
  2715. const newFallback = n2.ssFallback;
  2716. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2717. if (pendingBranch) {
  2718. suspense.pendingBranch = newBranch;
  2719. if (isSameVNodeType(newBranch, pendingBranch)) {
  2720. // same root type but content may have changed.
  2721. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2722. if (suspense.deps <= 0) {
  2723. suspense.resolve();
  2724. }
  2725. else if (isInFallback) {
  2726. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2727. isSVG, slotScopeIds, optimized);
  2728. setActiveBranch(suspense, newFallback);
  2729. }
  2730. }
  2731. else {
  2732. // toggled before pending tree is resolved
  2733. suspense.pendingId++;
  2734. if (isHydrating) {
  2735. // if toggled before hydration is finished, the current DOM tree is
  2736. // no longer valid. set it as the active branch so it will be unmounted
  2737. // when resolved
  2738. suspense.isHydrating = false;
  2739. suspense.activeBranch = pendingBranch;
  2740. }
  2741. else {
  2742. unmount(pendingBranch, parentComponent, suspense);
  2743. }
  2744. // increment pending ID. this is used to invalidate async callbacks
  2745. // reset suspense state
  2746. suspense.deps = 0;
  2747. // discard effects from pending branch
  2748. suspense.effects.length = 0;
  2749. // discard previous container
  2750. suspense.hiddenContainer = createElement('div');
  2751. if (isInFallback) {
  2752. // already in fallback state
  2753. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2754. if (suspense.deps <= 0) {
  2755. suspense.resolve();
  2756. }
  2757. else {
  2758. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2759. isSVG, slotScopeIds, optimized);
  2760. setActiveBranch(suspense, newFallback);
  2761. }
  2762. }
  2763. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2764. // toggled "back" to current active branch
  2765. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2766. // force resolve
  2767. suspense.resolve(true);
  2768. }
  2769. else {
  2770. // switched to a 3rd branch
  2771. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2772. if (suspense.deps <= 0) {
  2773. suspense.resolve();
  2774. }
  2775. }
  2776. }
  2777. }
  2778. else {
  2779. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2780. // root did not change, just normal patch
  2781. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2782. setActiveBranch(suspense, newBranch);
  2783. }
  2784. else {
  2785. // root node toggled
  2786. // invoke @pending event
  2787. triggerEvent(n2, 'onPending');
  2788. // mount pending branch in off-dom container
  2789. suspense.pendingBranch = newBranch;
  2790. suspense.pendingId++;
  2791. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2792. if (suspense.deps <= 0) {
  2793. // incoming branch has no async deps, resolve now.
  2794. suspense.resolve();
  2795. }
  2796. else {
  2797. const { timeout, pendingId } = suspense;
  2798. if (timeout > 0) {
  2799. setTimeout(() => {
  2800. if (suspense.pendingId === pendingId) {
  2801. suspense.fallback(newFallback);
  2802. }
  2803. }, timeout);
  2804. }
  2805. else if (timeout === 0) {
  2806. suspense.fallback(newFallback);
  2807. }
  2808. }
  2809. }
  2810. }
  2811. }
  2812. let hasWarned = false;
  2813. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2814. /* istanbul ignore if */
  2815. if (!hasWarned) {
  2816. hasWarned = true;
  2817. // @ts-ignore `console.info` cannot be null error
  2818. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2819. }
  2820. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2821. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2822. const suspense = {
  2823. vnode,
  2824. parent,
  2825. parentComponent,
  2826. isSVG,
  2827. container,
  2828. hiddenContainer,
  2829. anchor,
  2830. deps: 0,
  2831. pendingId: 0,
  2832. timeout: typeof timeout === 'number' ? timeout : -1,
  2833. activeBranch: null,
  2834. pendingBranch: null,
  2835. isInFallback: true,
  2836. isHydrating,
  2837. isUnmounted: false,
  2838. effects: [],
  2839. resolve(resume = false) {
  2840. {
  2841. if (!resume && !suspense.pendingBranch) {
  2842. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2843. }
  2844. if (suspense.isUnmounted) {
  2845. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2846. }
  2847. }
  2848. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2849. if (suspense.isHydrating) {
  2850. suspense.isHydrating = false;
  2851. }
  2852. else if (!resume) {
  2853. const delayEnter = activeBranch &&
  2854. pendingBranch.transition &&
  2855. pendingBranch.transition.mode === 'out-in';
  2856. if (delayEnter) {
  2857. activeBranch.transition.afterLeave = () => {
  2858. if (pendingId === suspense.pendingId) {
  2859. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2860. }
  2861. };
  2862. }
  2863. // this is initial anchor on mount
  2864. let { anchor } = suspense;
  2865. // unmount current active tree
  2866. if (activeBranch) {
  2867. // if the fallback tree was mounted, it may have been moved
  2868. // as part of a parent suspense. get the latest anchor for insertion
  2869. anchor = next(activeBranch);
  2870. unmount(activeBranch, parentComponent, suspense, true);
  2871. }
  2872. if (!delayEnter) {
  2873. // move content from off-dom container to actual container
  2874. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2875. }
  2876. }
  2877. setActiveBranch(suspense, pendingBranch);
  2878. suspense.pendingBranch = null;
  2879. suspense.isInFallback = false;
  2880. // flush buffered effects
  2881. // check if there is a pending parent suspense
  2882. let parent = suspense.parent;
  2883. let hasUnresolvedAncestor = false;
  2884. while (parent) {
  2885. if (parent.pendingBranch) {
  2886. // found a pending parent suspense, merge buffered post jobs
  2887. // into that parent
  2888. parent.effects.push(...effects);
  2889. hasUnresolvedAncestor = true;
  2890. break;
  2891. }
  2892. parent = parent.parent;
  2893. }
  2894. // no pending parent suspense, flush all jobs
  2895. if (!hasUnresolvedAncestor) {
  2896. queuePostFlushCb(effects);
  2897. }
  2898. suspense.effects = [];
  2899. // invoke @resolve event
  2900. triggerEvent(vnode, 'onResolve');
  2901. },
  2902. fallback(fallbackVNode) {
  2903. if (!suspense.pendingBranch) {
  2904. return;
  2905. }
  2906. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2907. // invoke @fallback event
  2908. triggerEvent(vnode, 'onFallback');
  2909. const anchor = next(activeBranch);
  2910. const mountFallback = () => {
  2911. if (!suspense.isInFallback) {
  2912. return;
  2913. }
  2914. // mount the fallback tree
  2915. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2916. isSVG, slotScopeIds, optimized);
  2917. setActiveBranch(suspense, fallbackVNode);
  2918. };
  2919. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2920. if (delayEnter) {
  2921. activeBranch.transition.afterLeave = mountFallback;
  2922. }
  2923. suspense.isInFallback = true;
  2924. // unmount current active branch
  2925. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2926. true // shouldRemove
  2927. );
  2928. if (!delayEnter) {
  2929. mountFallback();
  2930. }
  2931. },
  2932. move(container, anchor, type) {
  2933. suspense.activeBranch &&
  2934. move(suspense.activeBranch, container, anchor, type);
  2935. suspense.container = container;
  2936. },
  2937. next() {
  2938. return suspense.activeBranch && next(suspense.activeBranch);
  2939. },
  2940. registerDep(instance, setupRenderEffect) {
  2941. const isInPendingSuspense = !!suspense.pendingBranch;
  2942. if (isInPendingSuspense) {
  2943. suspense.deps++;
  2944. }
  2945. const hydratedEl = instance.vnode.el;
  2946. instance
  2947. .asyncDep.catch(err => {
  2948. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  2949. })
  2950. .then(asyncSetupResult => {
  2951. // retry when the setup() promise resolves.
  2952. // component may have been unmounted before resolve.
  2953. if (instance.isUnmounted ||
  2954. suspense.isUnmounted ||
  2955. suspense.pendingId !== instance.suspenseId) {
  2956. return;
  2957. }
  2958. // retry from this component
  2959. instance.asyncResolved = true;
  2960. const { vnode } = instance;
  2961. {
  2962. pushWarningContext(vnode);
  2963. }
  2964. handleSetupResult(instance, asyncSetupResult, false);
  2965. if (hydratedEl) {
  2966. // vnode may have been replaced if an update happened before the
  2967. // async dep is resolved.
  2968. vnode.el = hydratedEl;
  2969. }
  2970. const placeholder = !hydratedEl && instance.subTree.el;
  2971. setupRenderEffect(instance, vnode,
  2972. // component may have been moved before resolve.
  2973. // if this is not a hydration, instance.subTree will be the comment
  2974. // placeholder.
  2975. parentNode(hydratedEl || instance.subTree.el),
  2976. // anchor will not be used if this is hydration, so only need to
  2977. // consider the comment placeholder case.
  2978. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2979. if (placeholder) {
  2980. remove(placeholder);
  2981. }
  2982. updateHOCHostEl(instance, vnode.el);
  2983. {
  2984. popWarningContext();
  2985. }
  2986. // only decrease deps count if suspense is not already resolved
  2987. if (isInPendingSuspense && --suspense.deps === 0) {
  2988. suspense.resolve();
  2989. }
  2990. });
  2991. },
  2992. unmount(parentSuspense, doRemove) {
  2993. suspense.isUnmounted = true;
  2994. if (suspense.activeBranch) {
  2995. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2996. }
  2997. if (suspense.pendingBranch) {
  2998. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2999. }
  3000. }
  3001. };
  3002. return suspense;
  3003. }
  3004. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  3005. /* eslint-disable no-restricted-globals */
  3006. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  3007. // there are two possible scenarios for server-rendered suspense:
  3008. // - success: ssr content should be fully resolved
  3009. // - failure: ssr content should be the fallback branch.
  3010. // however, on the client we don't really know if it has failed or not
  3011. // attempt to hydrate the DOM assuming it has succeeded, but we still
  3012. // need to construct a suspense boundary first
  3013. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  3014. if (suspense.deps === 0) {
  3015. suspense.resolve();
  3016. }
  3017. return result;
  3018. /* eslint-enable no-restricted-globals */
  3019. }
  3020. function normalizeSuspenseChildren(vnode) {
  3021. const { shapeFlag, children } = vnode;
  3022. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  3023. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  3024. vnode.ssFallback = isSlotChildren
  3025. ? normalizeSuspenseSlot(children.fallback)
  3026. : createVNode(Comment);
  3027. }
  3028. function normalizeSuspenseSlot(s) {
  3029. let block;
  3030. if (isFunction(s)) {
  3031. const trackBlock = isBlockTreeEnabled && s._c;
  3032. if (trackBlock) {
  3033. // disableTracking: false
  3034. // allow block tracking for compiled slots
  3035. // (see ./componentRenderContext.ts)
  3036. s._d = false;
  3037. openBlock();
  3038. }
  3039. s = s();
  3040. if (trackBlock) {
  3041. s._d = true;
  3042. block = currentBlock;
  3043. closeBlock();
  3044. }
  3045. }
  3046. if (isArray(s)) {
  3047. const singleChild = filterSingleRoot(s);
  3048. if (!singleChild) {
  3049. warn$1(`<Suspense> slots expect a single root node.`);
  3050. }
  3051. s = singleChild;
  3052. }
  3053. s = normalizeVNode(s);
  3054. if (block && !s.dynamicChildren) {
  3055. s.dynamicChildren = block.filter(c => c !== s);
  3056. }
  3057. return s;
  3058. }
  3059. function queueEffectWithSuspense(fn, suspense) {
  3060. if (suspense && suspense.pendingBranch) {
  3061. if (isArray(fn)) {
  3062. suspense.effects.push(...fn);
  3063. }
  3064. else {
  3065. suspense.effects.push(fn);
  3066. }
  3067. }
  3068. else {
  3069. queuePostFlushCb(fn);
  3070. }
  3071. }
  3072. function setActiveBranch(suspense, branch) {
  3073. suspense.activeBranch = branch;
  3074. const { vnode, parentComponent } = suspense;
  3075. const el = (vnode.el = branch.el);
  3076. // in case suspense is the root node of a component,
  3077. // recursively update the HOC el
  3078. if (parentComponent && parentComponent.subTree === vnode) {
  3079. parentComponent.vnode.el = el;
  3080. updateHOCHostEl(parentComponent, el);
  3081. }
  3082. }
  3083. function provide(key, value) {
  3084. if (!currentInstance) {
  3085. {
  3086. warn$1(`provide() can only be used inside setup().`);
  3087. }
  3088. }
  3089. else {
  3090. let provides = currentInstance.provides;
  3091. // by default an instance inherits its parent's provides object
  3092. // but when it needs to provide values of its own, it creates its
  3093. // own provides object using parent provides object as prototype.
  3094. // this way in `inject` we can simply look up injections from direct
  3095. // parent and let the prototype chain do the work.
  3096. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3097. if (parentProvides === provides) {
  3098. provides = currentInstance.provides = Object.create(parentProvides);
  3099. }
  3100. // TS doesn't allow symbol as index type
  3101. provides[key] = value;
  3102. }
  3103. }
  3104. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3105. // fallback to `currentRenderingInstance` so that this can be called in
  3106. // a functional component
  3107. const instance = currentInstance || currentRenderingInstance;
  3108. if (instance) {
  3109. // #2400
  3110. // to support `app.use` plugins,
  3111. // fallback to appContext's `provides` if the instance is at root
  3112. const provides = instance.parent == null
  3113. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3114. : instance.parent.provides;
  3115. if (provides && key in provides) {
  3116. // TS doesn't allow symbol as index type
  3117. return provides[key];
  3118. }
  3119. else if (arguments.length > 1) {
  3120. return treatDefaultAsFactory && isFunction(defaultValue)
  3121. ? defaultValue.call(instance.proxy)
  3122. : defaultValue;
  3123. }
  3124. else {
  3125. warn$1(`injection "${String(key)}" not found.`);
  3126. }
  3127. }
  3128. else {
  3129. warn$1(`inject() can only be used inside setup() or functional components.`);
  3130. }
  3131. }
  3132. // Simple effect.
  3133. function watchEffect(effect, options) {
  3134. return doWatch(effect, null, options);
  3135. }
  3136. function watchPostEffect(effect, options) {
  3137. return doWatch(effect, null, (Object.assign(options || {}, { flush: 'post' })
  3138. ));
  3139. }
  3140. function watchSyncEffect(effect, options) {
  3141. return doWatch(effect, null, (Object.assign(options || {}, { flush: 'sync' })
  3142. ));
  3143. }
  3144. // initial value for watchers to trigger on undefined initial values
  3145. const INITIAL_WATCHER_VALUE = {};
  3146. // implementation
  3147. function watch(source, cb, options) {
  3148. if (!isFunction(cb)) {
  3149. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3150. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3151. `supports \`watch(source, cb, options?) signature.`);
  3152. }
  3153. return doWatch(source, cb, options);
  3154. }
  3155. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3156. if (!cb) {
  3157. if (immediate !== undefined) {
  3158. warn$1(`watch() "immediate" option is only respected when using the ` +
  3159. `watch(source, callback, options?) signature.`);
  3160. }
  3161. if (deep !== undefined) {
  3162. warn$1(`watch() "deep" option is only respected when using the ` +
  3163. `watch(source, callback, options?) signature.`);
  3164. }
  3165. }
  3166. const warnInvalidSource = (s) => {
  3167. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3168. `a reactive object, or an array of these types.`);
  3169. };
  3170. const instance = currentInstance;
  3171. let getter;
  3172. let forceTrigger = false;
  3173. let isMultiSource = false;
  3174. if (isRef(source)) {
  3175. getter = () => source.value;
  3176. forceTrigger = isShallow(source);
  3177. }
  3178. else if (isReactive(source)) {
  3179. getter = () => source;
  3180. deep = true;
  3181. }
  3182. else if (isArray(source)) {
  3183. isMultiSource = true;
  3184. forceTrigger = source.some(isReactive);
  3185. getter = () => source.map(s => {
  3186. if (isRef(s)) {
  3187. return s.value;
  3188. }
  3189. else if (isReactive(s)) {
  3190. return traverse(s);
  3191. }
  3192. else if (isFunction(s)) {
  3193. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  3194. }
  3195. else {
  3196. warnInvalidSource(s);
  3197. }
  3198. });
  3199. }
  3200. else if (isFunction(source)) {
  3201. if (cb) {
  3202. // getter with cb
  3203. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  3204. }
  3205. else {
  3206. // no cb -> simple effect
  3207. getter = () => {
  3208. if (instance && instance.isUnmounted) {
  3209. return;
  3210. }
  3211. if (cleanup) {
  3212. cleanup();
  3213. }
  3214. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onCleanup]);
  3215. };
  3216. }
  3217. }
  3218. else {
  3219. getter = NOOP;
  3220. warnInvalidSource(source);
  3221. }
  3222. if (cb && deep) {
  3223. const baseGetter = getter;
  3224. getter = () => traverse(baseGetter());
  3225. }
  3226. let cleanup;
  3227. let onCleanup = (fn) => {
  3228. cleanup = effect.onStop = () => {
  3229. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  3230. };
  3231. };
  3232. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  3233. const job = () => {
  3234. if (!effect.active) {
  3235. return;
  3236. }
  3237. if (cb) {
  3238. // watch(source, cb)
  3239. const newValue = effect.run();
  3240. if (deep ||
  3241. forceTrigger ||
  3242. (isMultiSource
  3243. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3244. : hasChanged(newValue, oldValue)) ||
  3245. (false )) {
  3246. // cleanup before running cb again
  3247. if (cleanup) {
  3248. cleanup();
  3249. }
  3250. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  3251. newValue,
  3252. // pass undefined as the old value when it's changed for the first time
  3253. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  3254. onCleanup
  3255. ]);
  3256. oldValue = newValue;
  3257. }
  3258. }
  3259. else {
  3260. // watchEffect
  3261. effect.run();
  3262. }
  3263. };
  3264. // important: mark the job as a watcher callback so that scheduler knows
  3265. // it is allowed to self-trigger (#1727)
  3266. job.allowRecurse = !!cb;
  3267. let scheduler;
  3268. if (flush === 'sync') {
  3269. scheduler = job; // the scheduler function gets called directly
  3270. }
  3271. else if (flush === 'post') {
  3272. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3273. }
  3274. else {
  3275. // default: 'pre'
  3276. scheduler = () => {
  3277. if (!instance || instance.isMounted) {
  3278. queuePreFlushCb(job);
  3279. }
  3280. else {
  3281. // with 'pre' option, the first call must happen before
  3282. // the component is mounted so it is called synchronously.
  3283. job();
  3284. }
  3285. };
  3286. }
  3287. const effect = new ReactiveEffect(getter, scheduler);
  3288. {
  3289. effect.onTrack = onTrack;
  3290. effect.onTrigger = onTrigger;
  3291. }
  3292. // initial run
  3293. if (cb) {
  3294. if (immediate) {
  3295. job();
  3296. }
  3297. else {
  3298. oldValue = effect.run();
  3299. }
  3300. }
  3301. else if (flush === 'post') {
  3302. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3303. }
  3304. else {
  3305. effect.run();
  3306. }
  3307. return () => {
  3308. effect.stop();
  3309. if (instance && instance.scope) {
  3310. remove(instance.scope.effects, effect);
  3311. }
  3312. };
  3313. }
  3314. // this.$watch
  3315. function instanceWatch(source, value, options) {
  3316. const publicThis = this.proxy;
  3317. const getter = isString(source)
  3318. ? source.includes('.')
  3319. ? createPathGetter(publicThis, source)
  3320. : () => publicThis[source]
  3321. : source.bind(publicThis, publicThis);
  3322. let cb;
  3323. if (isFunction(value)) {
  3324. cb = value;
  3325. }
  3326. else {
  3327. cb = value.handler;
  3328. options = value;
  3329. }
  3330. const cur = currentInstance;
  3331. setCurrentInstance(this);
  3332. const res = doWatch(getter, cb.bind(publicThis), options);
  3333. if (cur) {
  3334. setCurrentInstance(cur);
  3335. }
  3336. else {
  3337. unsetCurrentInstance();
  3338. }
  3339. return res;
  3340. }
  3341. function createPathGetter(ctx, path) {
  3342. const segments = path.split('.');
  3343. return () => {
  3344. let cur = ctx;
  3345. for (let i = 0; i < segments.length && cur; i++) {
  3346. cur = cur[segments[i]];
  3347. }
  3348. return cur;
  3349. };
  3350. }
  3351. function traverse(value, seen) {
  3352. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  3353. return value;
  3354. }
  3355. seen = seen || new Set();
  3356. if (seen.has(value)) {
  3357. return value;
  3358. }
  3359. seen.add(value);
  3360. if (isRef(value)) {
  3361. traverse(value.value, seen);
  3362. }
  3363. else if (isArray(value)) {
  3364. for (let i = 0; i < value.length; i++) {
  3365. traverse(value[i], seen);
  3366. }
  3367. }
  3368. else if (isSet(value) || isMap(value)) {
  3369. value.forEach((v) => {
  3370. traverse(v, seen);
  3371. });
  3372. }
  3373. else if (isPlainObject(value)) {
  3374. for (const key in value) {
  3375. traverse(value[key], seen);
  3376. }
  3377. }
  3378. return value;
  3379. }
  3380. function useTransitionState() {
  3381. const state = {
  3382. isMounted: false,
  3383. isLeaving: false,
  3384. isUnmounting: false,
  3385. leavingVNodes: new Map()
  3386. };
  3387. onMounted(() => {
  3388. state.isMounted = true;
  3389. });
  3390. onBeforeUnmount(() => {
  3391. state.isUnmounting = true;
  3392. });
  3393. return state;
  3394. }
  3395. const TransitionHookValidator = [Function, Array];
  3396. const BaseTransitionImpl = {
  3397. name: `BaseTransition`,
  3398. props: {
  3399. mode: String,
  3400. appear: Boolean,
  3401. persisted: Boolean,
  3402. // enter
  3403. onBeforeEnter: TransitionHookValidator,
  3404. onEnter: TransitionHookValidator,
  3405. onAfterEnter: TransitionHookValidator,
  3406. onEnterCancelled: TransitionHookValidator,
  3407. // leave
  3408. onBeforeLeave: TransitionHookValidator,
  3409. onLeave: TransitionHookValidator,
  3410. onAfterLeave: TransitionHookValidator,
  3411. onLeaveCancelled: TransitionHookValidator,
  3412. // appear
  3413. onBeforeAppear: TransitionHookValidator,
  3414. onAppear: TransitionHookValidator,
  3415. onAfterAppear: TransitionHookValidator,
  3416. onAppearCancelled: TransitionHookValidator
  3417. },
  3418. setup(props, { slots }) {
  3419. const instance = getCurrentInstance();
  3420. const state = useTransitionState();
  3421. let prevTransitionKey;
  3422. return () => {
  3423. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3424. if (!children || !children.length) {
  3425. return;
  3426. }
  3427. // warn multiple elements
  3428. if (children.length > 1) {
  3429. warn$1('<transition> can only be used on a single element or component. Use ' +
  3430. '<transition-group> for lists.');
  3431. }
  3432. // there's no need to track reactivity for these props so use the raw
  3433. // props for a bit better perf
  3434. const rawProps = toRaw(props);
  3435. const { mode } = rawProps;
  3436. // check mode
  3437. if (mode &&
  3438. mode !== 'in-out' && mode !== 'out-in' && mode !== 'default') {
  3439. warn$1(`invalid <transition> mode: ${mode}`);
  3440. }
  3441. // at this point children has a guaranteed length of 1.
  3442. const child = children[0];
  3443. if (state.isLeaving) {
  3444. return emptyPlaceholder(child);
  3445. }
  3446. // in the case of <transition><keep-alive/></transition>, we need to
  3447. // compare the type of the kept-alive children.
  3448. const innerChild = getKeepAliveChild(child);
  3449. if (!innerChild) {
  3450. return emptyPlaceholder(child);
  3451. }
  3452. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3453. setTransitionHooks(innerChild, enterHooks);
  3454. const oldChild = instance.subTree;
  3455. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3456. let transitionKeyChanged = false;
  3457. const { getTransitionKey } = innerChild.type;
  3458. if (getTransitionKey) {
  3459. const key = getTransitionKey();
  3460. if (prevTransitionKey === undefined) {
  3461. prevTransitionKey = key;
  3462. }
  3463. else if (key !== prevTransitionKey) {
  3464. prevTransitionKey = key;
  3465. transitionKeyChanged = true;
  3466. }
  3467. }
  3468. // handle mode
  3469. if (oldInnerChild &&
  3470. oldInnerChild.type !== Comment &&
  3471. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3472. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3473. // update old tree's hooks in case of dynamic transition
  3474. setTransitionHooks(oldInnerChild, leavingHooks);
  3475. // switching between different views
  3476. if (mode === 'out-in') {
  3477. state.isLeaving = true;
  3478. // return placeholder node and queue update when leave finishes
  3479. leavingHooks.afterLeave = () => {
  3480. state.isLeaving = false;
  3481. instance.update();
  3482. };
  3483. return emptyPlaceholder(child);
  3484. }
  3485. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3486. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3487. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3488. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3489. // early removal callback
  3490. el._leaveCb = () => {
  3491. earlyRemove();
  3492. el._leaveCb = undefined;
  3493. delete enterHooks.delayedLeave;
  3494. };
  3495. enterHooks.delayedLeave = delayedLeave;
  3496. };
  3497. }
  3498. }
  3499. return child;
  3500. };
  3501. }
  3502. };
  3503. // export the public type for h/tsx inference
  3504. // also to avoid inline import() in generated d.ts files
  3505. const BaseTransition = BaseTransitionImpl;
  3506. function getLeavingNodesForType(state, vnode) {
  3507. const { leavingVNodes } = state;
  3508. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3509. if (!leavingVNodesCache) {
  3510. leavingVNodesCache = Object.create(null);
  3511. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3512. }
  3513. return leavingVNodesCache;
  3514. }
  3515. // The transition hooks are attached to the vnode as vnode.transition
  3516. // and will be called at appropriate timing in the renderer.
  3517. function resolveTransitionHooks(vnode, props, state, instance) {
  3518. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3519. const key = String(vnode.key);
  3520. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3521. const callHook = (hook, args) => {
  3522. hook &&
  3523. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3524. };
  3525. const hooks = {
  3526. mode,
  3527. persisted,
  3528. beforeEnter(el) {
  3529. let hook = onBeforeEnter;
  3530. if (!state.isMounted) {
  3531. if (appear) {
  3532. hook = onBeforeAppear || onBeforeEnter;
  3533. }
  3534. else {
  3535. return;
  3536. }
  3537. }
  3538. // for same element (v-show)
  3539. if (el._leaveCb) {
  3540. el._leaveCb(true /* cancelled */);
  3541. }
  3542. // for toggled element with same key (v-if)
  3543. const leavingVNode = leavingVNodesCache[key];
  3544. if (leavingVNode &&
  3545. isSameVNodeType(vnode, leavingVNode) &&
  3546. leavingVNode.el._leaveCb) {
  3547. // force early removal (not cancelled)
  3548. leavingVNode.el._leaveCb();
  3549. }
  3550. callHook(hook, [el]);
  3551. },
  3552. enter(el) {
  3553. let hook = onEnter;
  3554. let afterHook = onAfterEnter;
  3555. let cancelHook = onEnterCancelled;
  3556. if (!state.isMounted) {
  3557. if (appear) {
  3558. hook = onAppear || onEnter;
  3559. afterHook = onAfterAppear || onAfterEnter;
  3560. cancelHook = onAppearCancelled || onEnterCancelled;
  3561. }
  3562. else {
  3563. return;
  3564. }
  3565. }
  3566. let called = false;
  3567. const done = (el._enterCb = (cancelled) => {
  3568. if (called)
  3569. return;
  3570. called = true;
  3571. if (cancelled) {
  3572. callHook(cancelHook, [el]);
  3573. }
  3574. else {
  3575. callHook(afterHook, [el]);
  3576. }
  3577. if (hooks.delayedLeave) {
  3578. hooks.delayedLeave();
  3579. }
  3580. el._enterCb = undefined;
  3581. });
  3582. if (hook) {
  3583. hook(el, done);
  3584. if (hook.length <= 1) {
  3585. done();
  3586. }
  3587. }
  3588. else {
  3589. done();
  3590. }
  3591. },
  3592. leave(el, remove) {
  3593. const key = String(vnode.key);
  3594. if (el._enterCb) {
  3595. el._enterCb(true /* cancelled */);
  3596. }
  3597. if (state.isUnmounting) {
  3598. return remove();
  3599. }
  3600. callHook(onBeforeLeave, [el]);
  3601. let called = false;
  3602. const done = (el._leaveCb = (cancelled) => {
  3603. if (called)
  3604. return;
  3605. called = true;
  3606. remove();
  3607. if (cancelled) {
  3608. callHook(onLeaveCancelled, [el]);
  3609. }
  3610. else {
  3611. callHook(onAfterLeave, [el]);
  3612. }
  3613. el._leaveCb = undefined;
  3614. if (leavingVNodesCache[key] === vnode) {
  3615. delete leavingVNodesCache[key];
  3616. }
  3617. });
  3618. leavingVNodesCache[key] = vnode;
  3619. if (onLeave) {
  3620. onLeave(el, done);
  3621. if (onLeave.length <= 1) {
  3622. done();
  3623. }
  3624. }
  3625. else {
  3626. done();
  3627. }
  3628. },
  3629. clone(vnode) {
  3630. return resolveTransitionHooks(vnode, props, state, instance);
  3631. }
  3632. };
  3633. return hooks;
  3634. }
  3635. // the placeholder really only handles one special case: KeepAlive
  3636. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3637. // placeholder with empty content to avoid the KeepAlive instance from being
  3638. // unmounted.
  3639. function emptyPlaceholder(vnode) {
  3640. if (isKeepAlive(vnode)) {
  3641. vnode = cloneVNode(vnode);
  3642. vnode.children = null;
  3643. return vnode;
  3644. }
  3645. }
  3646. function getKeepAliveChild(vnode) {
  3647. return isKeepAlive(vnode)
  3648. ? vnode.children
  3649. ? vnode.children[0]
  3650. : undefined
  3651. : vnode;
  3652. }
  3653. function setTransitionHooks(vnode, hooks) {
  3654. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3655. setTransitionHooks(vnode.component.subTree, hooks);
  3656. }
  3657. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3658. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3659. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3660. }
  3661. else {
  3662. vnode.transition = hooks;
  3663. }
  3664. }
  3665. function getTransitionRawChildren(children, keepComment = false) {
  3666. let ret = [];
  3667. let keyedFragmentCount = 0;
  3668. for (let i = 0; i < children.length; i++) {
  3669. const child = children[i];
  3670. // handle fragment children case, e.g. v-for
  3671. if (child.type === Fragment) {
  3672. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  3673. keyedFragmentCount++;
  3674. ret = ret.concat(getTransitionRawChildren(child.children, keepComment));
  3675. }
  3676. // comment placeholders should be skipped, e.g. v-if
  3677. else if (keepComment || child.type !== Comment) {
  3678. ret.push(child);
  3679. }
  3680. }
  3681. // #1126 if a transition children list contains multiple sub fragments, these
  3682. // fragments will be merged into a flat children array. Since each v-for
  3683. // fragment may contain different static bindings inside, we need to de-op
  3684. // these children to force full diffs to ensure correct behavior.
  3685. if (keyedFragmentCount > 1) {
  3686. for (let i = 0; i < ret.length; i++) {
  3687. ret[i].patchFlag = -2 /* BAIL */;
  3688. }
  3689. }
  3690. return ret;
  3691. }
  3692. // implementation, close to no-op
  3693. function defineComponent(options) {
  3694. return isFunction(options) ? { setup: options, name: options.name } : options;
  3695. }
  3696. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3697. function defineAsyncComponent(source) {
  3698. if (isFunction(source)) {
  3699. source = { loader: source };
  3700. }
  3701. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3702. suspensible = true, onError: userOnError } = source;
  3703. let pendingRequest = null;
  3704. let resolvedComp;
  3705. let retries = 0;
  3706. const retry = () => {
  3707. retries++;
  3708. pendingRequest = null;
  3709. return load();
  3710. };
  3711. const load = () => {
  3712. let thisRequest;
  3713. return (pendingRequest ||
  3714. (thisRequest = pendingRequest =
  3715. loader()
  3716. .catch(err => {
  3717. err = err instanceof Error ? err : new Error(String(err));
  3718. if (userOnError) {
  3719. return new Promise((resolve, reject) => {
  3720. const userRetry = () => resolve(retry());
  3721. const userFail = () => reject(err);
  3722. userOnError(err, userRetry, userFail, retries + 1);
  3723. });
  3724. }
  3725. else {
  3726. throw err;
  3727. }
  3728. })
  3729. .then((comp) => {
  3730. if (thisRequest !== pendingRequest && pendingRequest) {
  3731. return pendingRequest;
  3732. }
  3733. if (!comp) {
  3734. warn$1(`Async component loader resolved to undefined. ` +
  3735. `If you are using retry(), make sure to return its return value.`);
  3736. }
  3737. // interop module default
  3738. if (comp &&
  3739. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3740. comp = comp.default;
  3741. }
  3742. if (comp && !isObject(comp) && !isFunction(comp)) {
  3743. throw new Error(`Invalid async component load result: ${comp}`);
  3744. }
  3745. resolvedComp = comp;
  3746. return comp;
  3747. })));
  3748. };
  3749. return defineComponent({
  3750. name: 'AsyncComponentWrapper',
  3751. __asyncLoader: load,
  3752. get __asyncResolved() {
  3753. return resolvedComp;
  3754. },
  3755. setup() {
  3756. const instance = currentInstance;
  3757. // already resolved
  3758. if (resolvedComp) {
  3759. return () => createInnerComp(resolvedComp, instance);
  3760. }
  3761. const onError = (err) => {
  3762. pendingRequest = null;
  3763. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3764. };
  3765. // suspense-controlled or SSR.
  3766. if ((suspensible && instance.suspense) ||
  3767. (false )) {
  3768. return load()
  3769. .then(comp => {
  3770. return () => createInnerComp(comp, instance);
  3771. })
  3772. .catch(err => {
  3773. onError(err);
  3774. return () => errorComponent
  3775. ? createVNode(errorComponent, {
  3776. error: err
  3777. })
  3778. : null;
  3779. });
  3780. }
  3781. const loaded = ref(false);
  3782. const error = ref();
  3783. const delayed = ref(!!delay);
  3784. if (delay) {
  3785. setTimeout(() => {
  3786. delayed.value = false;
  3787. }, delay);
  3788. }
  3789. if (timeout != null) {
  3790. setTimeout(() => {
  3791. if (!loaded.value && !error.value) {
  3792. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3793. onError(err);
  3794. error.value = err;
  3795. }
  3796. }, timeout);
  3797. }
  3798. load()
  3799. .then(() => {
  3800. loaded.value = true;
  3801. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3802. // parent is keep-alive, force update so the loaded component's
  3803. // name is taken into account
  3804. queueJob(instance.parent.update);
  3805. }
  3806. })
  3807. .catch(err => {
  3808. onError(err);
  3809. error.value = err;
  3810. });
  3811. return () => {
  3812. if (loaded.value && resolvedComp) {
  3813. return createInnerComp(resolvedComp, instance);
  3814. }
  3815. else if (error.value && errorComponent) {
  3816. return createVNode(errorComponent, {
  3817. error: error.value
  3818. });
  3819. }
  3820. else if (loadingComponent && !delayed.value) {
  3821. return createVNode(loadingComponent);
  3822. }
  3823. };
  3824. }
  3825. });
  3826. }
  3827. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  3828. const vnode = createVNode(comp, props, children);
  3829. // ensure inner component inherits the async wrapper's ref owner
  3830. vnode.ref = ref;
  3831. return vnode;
  3832. }
  3833. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3834. const KeepAliveImpl = {
  3835. name: `KeepAlive`,
  3836. // Marker for special handling inside the renderer. We are not using a ===
  3837. // check directly on KeepAlive in the renderer, because importing it directly
  3838. // would prevent it from being tree-shaken.
  3839. __isKeepAlive: true,
  3840. props: {
  3841. include: [String, RegExp, Array],
  3842. exclude: [String, RegExp, Array],
  3843. max: [String, Number]
  3844. },
  3845. setup(props, { slots }) {
  3846. const instance = getCurrentInstance();
  3847. // KeepAlive communicates with the instantiated renderer via the
  3848. // ctx where the renderer passes in its internals,
  3849. // and the KeepAlive instance exposes activate/deactivate implementations.
  3850. // The whole point of this is to avoid importing KeepAlive directly in the
  3851. // renderer to facilitate tree-shaking.
  3852. const sharedContext = instance.ctx;
  3853. // if the internal renderer is not registered, it indicates that this is server-side rendering,
  3854. // for KeepAlive, we just need to render its children
  3855. if (!sharedContext.renderer) {
  3856. return slots.default;
  3857. }
  3858. const cache = new Map();
  3859. const keys = new Set();
  3860. let current = null;
  3861. {
  3862. instance.__v_cache = cache;
  3863. }
  3864. const parentSuspense = instance.suspense;
  3865. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3866. const storageContainer = createElement('div');
  3867. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3868. const instance = vnode.component;
  3869. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3870. // in case props have changed
  3871. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3872. queuePostRenderEffect(() => {
  3873. instance.isDeactivated = false;
  3874. if (instance.a) {
  3875. invokeArrayFns(instance.a);
  3876. }
  3877. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3878. if (vnodeHook) {
  3879. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3880. }
  3881. }, parentSuspense);
  3882. {
  3883. // Update components tree
  3884. devtoolsComponentAdded(instance);
  3885. }
  3886. };
  3887. sharedContext.deactivate = (vnode) => {
  3888. const instance = vnode.component;
  3889. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3890. queuePostRenderEffect(() => {
  3891. if (instance.da) {
  3892. invokeArrayFns(instance.da);
  3893. }
  3894. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3895. if (vnodeHook) {
  3896. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3897. }
  3898. instance.isDeactivated = true;
  3899. }, parentSuspense);
  3900. {
  3901. // Update components tree
  3902. devtoolsComponentAdded(instance);
  3903. }
  3904. };
  3905. function unmount(vnode) {
  3906. // reset the shapeFlag so it can be properly unmounted
  3907. resetShapeFlag(vnode);
  3908. _unmount(vnode, instance, parentSuspense, true);
  3909. }
  3910. function pruneCache(filter) {
  3911. cache.forEach((vnode, key) => {
  3912. const name = getComponentName(vnode.type);
  3913. if (name && (!filter || !filter(name))) {
  3914. pruneCacheEntry(key);
  3915. }
  3916. });
  3917. }
  3918. function pruneCacheEntry(key) {
  3919. const cached = cache.get(key);
  3920. if (!current || cached.type !== current.type) {
  3921. unmount(cached);
  3922. }
  3923. else if (current) {
  3924. // current active instance should no longer be kept-alive.
  3925. // we can't unmount it now but it might be later, so reset its flag now.
  3926. resetShapeFlag(current);
  3927. }
  3928. cache.delete(key);
  3929. keys.delete(key);
  3930. }
  3931. // prune cache on include/exclude prop change
  3932. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3933. include && pruneCache(name => matches(include, name));
  3934. exclude && pruneCache(name => !matches(exclude, name));
  3935. },
  3936. // prune post-render after `current` has been updated
  3937. { flush: 'post', deep: true });
  3938. // cache sub tree after render
  3939. let pendingCacheKey = null;
  3940. const cacheSubtree = () => {
  3941. // fix #1621, the pendingCacheKey could be 0
  3942. if (pendingCacheKey != null) {
  3943. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3944. }
  3945. };
  3946. onMounted(cacheSubtree);
  3947. onUpdated(cacheSubtree);
  3948. onBeforeUnmount(() => {
  3949. cache.forEach(cached => {
  3950. const { subTree, suspense } = instance;
  3951. const vnode = getInnerChild(subTree);
  3952. if (cached.type === vnode.type) {
  3953. // current instance will be unmounted as part of keep-alive's unmount
  3954. resetShapeFlag(vnode);
  3955. // but invoke its deactivated hook here
  3956. const da = vnode.component.da;
  3957. da && queuePostRenderEffect(da, suspense);
  3958. return;
  3959. }
  3960. unmount(cached);
  3961. });
  3962. });
  3963. return () => {
  3964. pendingCacheKey = null;
  3965. if (!slots.default) {
  3966. return null;
  3967. }
  3968. const children = slots.default();
  3969. const rawVNode = children[0];
  3970. if (children.length > 1) {
  3971. {
  3972. warn$1(`KeepAlive should contain exactly one component child.`);
  3973. }
  3974. current = null;
  3975. return children;
  3976. }
  3977. else if (!isVNode(rawVNode) ||
  3978. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  3979. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  3980. current = null;
  3981. return rawVNode;
  3982. }
  3983. let vnode = getInnerChild(rawVNode);
  3984. const comp = vnode.type;
  3985. // for async components, name check should be based in its loaded
  3986. // inner component if available
  3987. const name = getComponentName(isAsyncWrapper(vnode)
  3988. ? vnode.type.__asyncResolved || {}
  3989. : comp);
  3990. const { include, exclude, max } = props;
  3991. if ((include && (!name || !matches(include, name))) ||
  3992. (exclude && name && matches(exclude, name))) {
  3993. current = vnode;
  3994. return rawVNode;
  3995. }
  3996. const key = vnode.key == null ? comp : vnode.key;
  3997. const cachedVNode = cache.get(key);
  3998. // clone vnode if it's reused because we are going to mutate it
  3999. if (vnode.el) {
  4000. vnode = cloneVNode(vnode);
  4001. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  4002. rawVNode.ssContent = vnode;
  4003. }
  4004. }
  4005. // #1513 it's possible for the returned vnode to be cloned due to attr
  4006. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4007. // that is mounted. Instead of caching it directly, we store the pending
  4008. // key and cache `instance.subTree` (the normalized vnode) in
  4009. // beforeMount/beforeUpdate hooks.
  4010. pendingCacheKey = key;
  4011. if (cachedVNode) {
  4012. // copy over mounted state
  4013. vnode.el = cachedVNode.el;
  4014. vnode.component = cachedVNode.component;
  4015. if (vnode.transition) {
  4016. // recursively update transition hooks on subTree
  4017. setTransitionHooks(vnode, vnode.transition);
  4018. }
  4019. // avoid vnode being mounted as fresh
  4020. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  4021. // make this key the freshest
  4022. keys.delete(key);
  4023. keys.add(key);
  4024. }
  4025. else {
  4026. keys.add(key);
  4027. // prune oldest entry
  4028. if (max && keys.size > parseInt(max, 10)) {
  4029. pruneCacheEntry(keys.values().next().value);
  4030. }
  4031. }
  4032. // avoid vnode being unmounted
  4033. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4034. current = vnode;
  4035. return rawVNode;
  4036. };
  4037. }
  4038. };
  4039. // export the public type for h/tsx inference
  4040. // also to avoid inline import() in generated d.ts files
  4041. const KeepAlive = KeepAliveImpl;
  4042. function matches(pattern, name) {
  4043. if (isArray(pattern)) {
  4044. return pattern.some((p) => matches(p, name));
  4045. }
  4046. else if (isString(pattern)) {
  4047. return pattern.split(',').includes(name);
  4048. }
  4049. else if (pattern.test) {
  4050. return pattern.test(name);
  4051. }
  4052. /* istanbul ignore next */
  4053. return false;
  4054. }
  4055. function onActivated(hook, target) {
  4056. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  4057. }
  4058. function onDeactivated(hook, target) {
  4059. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  4060. }
  4061. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4062. // cache the deactivate branch check wrapper for injected hooks so the same
  4063. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4064. // deactivation check".
  4065. const wrappedHook = hook.__wdc ||
  4066. (hook.__wdc = () => {
  4067. // only fire the hook if the target instance is NOT in a deactivated branch.
  4068. let current = target;
  4069. while (current) {
  4070. if (current.isDeactivated) {
  4071. return;
  4072. }
  4073. current = current.parent;
  4074. }
  4075. return hook();
  4076. });
  4077. injectHook(type, wrappedHook, target);
  4078. // In addition to registering it on the target instance, we walk up the parent
  4079. // chain and register it on all ancestor instances that are keep-alive roots.
  4080. // This avoids the need to walk the entire component tree when invoking these
  4081. // hooks, and more importantly, avoids the need to track child components in
  4082. // arrays.
  4083. if (target) {
  4084. let current = target.parent;
  4085. while (current && current.parent) {
  4086. if (isKeepAlive(current.parent.vnode)) {
  4087. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4088. }
  4089. current = current.parent;
  4090. }
  4091. }
  4092. }
  4093. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4094. // injectHook wraps the original for error handling, so make sure to remove
  4095. // the wrapped version.
  4096. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4097. onUnmounted(() => {
  4098. remove(keepAliveRoot[type], injected);
  4099. }, target);
  4100. }
  4101. function resetShapeFlag(vnode) {
  4102. let shapeFlag = vnode.shapeFlag;
  4103. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4104. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4105. }
  4106. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  4107. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  4108. }
  4109. vnode.shapeFlag = shapeFlag;
  4110. }
  4111. function getInnerChild(vnode) {
  4112. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  4113. }
  4114. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4115. if (target) {
  4116. const hooks = target[type] || (target[type] = []);
  4117. // cache the error handling wrapper for injected hooks so the same hook
  4118. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4119. // handling".
  4120. const wrappedHook = hook.__weh ||
  4121. (hook.__weh = (...args) => {
  4122. if (target.isUnmounted) {
  4123. return;
  4124. }
  4125. // disable tracking inside all lifecycle hooks
  4126. // since they can potentially be called inside effects.
  4127. pauseTracking();
  4128. // Set currentInstance during hook invocation.
  4129. // This assumes the hook does not synchronously trigger other hooks, which
  4130. // can only be false when the user does something really funky.
  4131. setCurrentInstance(target);
  4132. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4133. unsetCurrentInstance();
  4134. resetTracking();
  4135. return res;
  4136. });
  4137. if (prepend) {
  4138. hooks.unshift(wrappedHook);
  4139. }
  4140. else {
  4141. hooks.push(wrappedHook);
  4142. }
  4143. return wrappedHook;
  4144. }
  4145. else {
  4146. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4147. warn$1(`${apiName} is called when there is no active component instance to be ` +
  4148. `associated with. ` +
  4149. `Lifecycle injection APIs can only be used during execution of setup().` +
  4150. (` If you are using async setup(), make sure to register lifecycle ` +
  4151. `hooks before the first await statement.`
  4152. ));
  4153. }
  4154. }
  4155. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4156. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4157. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  4158. injectHook(lifecycle, hook, target);
  4159. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  4160. const onMounted = createHook("m" /* MOUNTED */);
  4161. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  4162. const onUpdated = createHook("u" /* UPDATED */);
  4163. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  4164. const onUnmounted = createHook("um" /* UNMOUNTED */);
  4165. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  4166. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  4167. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  4168. function onErrorCaptured(hook, target = currentInstance) {
  4169. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  4170. }
  4171. function createDuplicateChecker() {
  4172. const cache = Object.create(null);
  4173. return (type, key) => {
  4174. if (cache[key]) {
  4175. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4176. }
  4177. else {
  4178. cache[key] = type;
  4179. }
  4180. };
  4181. }
  4182. let shouldCacheAccess = true;
  4183. function applyOptions(instance) {
  4184. const options = resolveMergedOptions(instance);
  4185. const publicThis = instance.proxy;
  4186. const ctx = instance.ctx;
  4187. // do not cache property access on public proxy during state initialization
  4188. shouldCacheAccess = false;
  4189. // call beforeCreate first before accessing other options since
  4190. // the hook may mutate resolved options (#2791)
  4191. if (options.beforeCreate) {
  4192. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  4193. }
  4194. const {
  4195. // state
  4196. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4197. // lifecycle
  4198. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4199. // public API
  4200. expose, inheritAttrs,
  4201. // assets
  4202. components, directives, filters } = options;
  4203. const checkDuplicateProperties = createDuplicateChecker() ;
  4204. {
  4205. const [propsOptions] = instance.propsOptions;
  4206. if (propsOptions) {
  4207. for (const key in propsOptions) {
  4208. checkDuplicateProperties("Props" /* PROPS */, key);
  4209. }
  4210. }
  4211. }
  4212. // options initialization order (to be consistent with Vue 2):
  4213. // - props (already done outside of this function)
  4214. // - inject
  4215. // - methods
  4216. // - data (deferred since it relies on `this` access)
  4217. // - computed
  4218. // - watch (deferred since it relies on `this` access)
  4219. if (injectOptions) {
  4220. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4221. }
  4222. if (methods) {
  4223. for (const key in methods) {
  4224. const methodHandler = methods[key];
  4225. if (isFunction(methodHandler)) {
  4226. // In dev mode, we use the `createRenderContext` function to define
  4227. // methods to the proxy target, and those are read-only but
  4228. // reconfigurable, so it needs to be redefined here
  4229. {
  4230. Object.defineProperty(ctx, key, {
  4231. value: methodHandler.bind(publicThis),
  4232. configurable: true,
  4233. enumerable: true,
  4234. writable: true
  4235. });
  4236. }
  4237. {
  4238. checkDuplicateProperties("Methods" /* METHODS */, key);
  4239. }
  4240. }
  4241. else {
  4242. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4243. `Did you reference the function correctly?`);
  4244. }
  4245. }
  4246. }
  4247. if (dataOptions) {
  4248. if (!isFunction(dataOptions)) {
  4249. warn$1(`The data option must be a function. ` +
  4250. `Plain object usage is no longer supported.`);
  4251. }
  4252. const data = dataOptions.call(publicThis, publicThis);
  4253. if (isPromise(data)) {
  4254. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  4255. `intend to perform data fetching before component renders, use ` +
  4256. `async setup() + <Suspense>.`);
  4257. }
  4258. if (!isObject(data)) {
  4259. warn$1(`data() should return an object.`);
  4260. }
  4261. else {
  4262. instance.data = reactive(data);
  4263. {
  4264. for (const key in data) {
  4265. checkDuplicateProperties("Data" /* DATA */, key);
  4266. // expose data on ctx during dev
  4267. if (key[0] !== '$' && key[0] !== '_') {
  4268. Object.defineProperty(ctx, key, {
  4269. configurable: true,
  4270. enumerable: true,
  4271. get: () => data[key],
  4272. set: NOOP
  4273. });
  4274. }
  4275. }
  4276. }
  4277. }
  4278. }
  4279. // state initialization complete at this point - start caching access
  4280. shouldCacheAccess = true;
  4281. if (computedOptions) {
  4282. for (const key in computedOptions) {
  4283. const opt = computedOptions[key];
  4284. const get = isFunction(opt)
  4285. ? opt.bind(publicThis, publicThis)
  4286. : isFunction(opt.get)
  4287. ? opt.get.bind(publicThis, publicThis)
  4288. : NOOP;
  4289. if (get === NOOP) {
  4290. warn$1(`Computed property "${key}" has no getter.`);
  4291. }
  4292. const set = !isFunction(opt) && isFunction(opt.set)
  4293. ? opt.set.bind(publicThis)
  4294. : () => {
  4295. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  4296. }
  4297. ;
  4298. const c = computed$1({
  4299. get,
  4300. set
  4301. });
  4302. Object.defineProperty(ctx, key, {
  4303. enumerable: true,
  4304. configurable: true,
  4305. get: () => c.value,
  4306. set: v => (c.value = v)
  4307. });
  4308. {
  4309. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  4310. }
  4311. }
  4312. }
  4313. if (watchOptions) {
  4314. for (const key in watchOptions) {
  4315. createWatcher(watchOptions[key], ctx, publicThis, key);
  4316. }
  4317. }
  4318. if (provideOptions) {
  4319. const provides = isFunction(provideOptions)
  4320. ? provideOptions.call(publicThis)
  4321. : provideOptions;
  4322. Reflect.ownKeys(provides).forEach(key => {
  4323. provide(key, provides[key]);
  4324. });
  4325. }
  4326. if (created) {
  4327. callHook(created, instance, "c" /* CREATED */);
  4328. }
  4329. function registerLifecycleHook(register, hook) {
  4330. if (isArray(hook)) {
  4331. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4332. }
  4333. else if (hook) {
  4334. register(hook.bind(publicThis));
  4335. }
  4336. }
  4337. registerLifecycleHook(onBeforeMount, beforeMount);
  4338. registerLifecycleHook(onMounted, mounted);
  4339. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4340. registerLifecycleHook(onUpdated, updated);
  4341. registerLifecycleHook(onActivated, activated);
  4342. registerLifecycleHook(onDeactivated, deactivated);
  4343. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4344. registerLifecycleHook(onRenderTracked, renderTracked);
  4345. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4346. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4347. registerLifecycleHook(onUnmounted, unmounted);
  4348. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4349. if (isArray(expose)) {
  4350. if (expose.length) {
  4351. const exposed = instance.exposed || (instance.exposed = {});
  4352. expose.forEach(key => {
  4353. Object.defineProperty(exposed, key, {
  4354. get: () => publicThis[key],
  4355. set: val => (publicThis[key] = val)
  4356. });
  4357. });
  4358. }
  4359. else if (!instance.exposed) {
  4360. instance.exposed = {};
  4361. }
  4362. }
  4363. // options that are handled when creating the instance but also need to be
  4364. // applied from mixins
  4365. if (render && instance.render === NOOP) {
  4366. instance.render = render;
  4367. }
  4368. if (inheritAttrs != null) {
  4369. instance.inheritAttrs = inheritAttrs;
  4370. }
  4371. // asset options.
  4372. if (components)
  4373. instance.components = components;
  4374. if (directives)
  4375. instance.directives = directives;
  4376. }
  4377. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  4378. if (isArray(injectOptions)) {
  4379. injectOptions = normalizeInject(injectOptions);
  4380. }
  4381. for (const key in injectOptions) {
  4382. const opt = injectOptions[key];
  4383. let injected;
  4384. if (isObject(opt)) {
  4385. if ('default' in opt) {
  4386. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4387. }
  4388. else {
  4389. injected = inject(opt.from || key);
  4390. }
  4391. }
  4392. else {
  4393. injected = inject(opt);
  4394. }
  4395. if (isRef(injected)) {
  4396. // TODO remove the check in 3.3
  4397. if (unwrapRef) {
  4398. Object.defineProperty(ctx, key, {
  4399. enumerable: true,
  4400. configurable: true,
  4401. get: () => injected.value,
  4402. set: v => (injected.value = v)
  4403. });
  4404. }
  4405. else {
  4406. {
  4407. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  4408. `and no longer needs \`.value\` in the next minor release. ` +
  4409. `To opt-in to the new behavior now, ` +
  4410. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  4411. `temporary and will not be needed in the future.)`);
  4412. }
  4413. ctx[key] = injected;
  4414. }
  4415. }
  4416. else {
  4417. ctx[key] = injected;
  4418. }
  4419. {
  4420. checkDuplicateProperties("Inject" /* INJECT */, key);
  4421. }
  4422. }
  4423. }
  4424. function callHook(hook, instance, type) {
  4425. callWithAsyncErrorHandling(isArray(hook)
  4426. ? hook.map(h => h.bind(instance.proxy))
  4427. : hook.bind(instance.proxy), instance, type);
  4428. }
  4429. function createWatcher(raw, ctx, publicThis, key) {
  4430. const getter = key.includes('.')
  4431. ? createPathGetter(publicThis, key)
  4432. : () => publicThis[key];
  4433. if (isString(raw)) {
  4434. const handler = ctx[raw];
  4435. if (isFunction(handler)) {
  4436. watch(getter, handler);
  4437. }
  4438. else {
  4439. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  4440. }
  4441. }
  4442. else if (isFunction(raw)) {
  4443. watch(getter, raw.bind(publicThis));
  4444. }
  4445. else if (isObject(raw)) {
  4446. if (isArray(raw)) {
  4447. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  4448. }
  4449. else {
  4450. const handler = isFunction(raw.handler)
  4451. ? raw.handler.bind(publicThis)
  4452. : ctx[raw.handler];
  4453. if (isFunction(handler)) {
  4454. watch(getter, handler, raw);
  4455. }
  4456. else {
  4457. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  4458. }
  4459. }
  4460. }
  4461. else {
  4462. warn$1(`Invalid watch option: "${key}"`, raw);
  4463. }
  4464. }
  4465. /**
  4466. * Resolve merged options and cache it on the component.
  4467. * This is done only once per-component since the merging does not involve
  4468. * instances.
  4469. */
  4470. function resolveMergedOptions(instance) {
  4471. const base = instance.type;
  4472. const { mixins, extends: extendsOptions } = base;
  4473. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  4474. const cached = cache.get(base);
  4475. let resolved;
  4476. if (cached) {
  4477. resolved = cached;
  4478. }
  4479. else if (!globalMixins.length && !mixins && !extendsOptions) {
  4480. {
  4481. resolved = base;
  4482. }
  4483. }
  4484. else {
  4485. resolved = {};
  4486. if (globalMixins.length) {
  4487. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  4488. }
  4489. mergeOptions(resolved, base, optionMergeStrategies);
  4490. }
  4491. cache.set(base, resolved);
  4492. return resolved;
  4493. }
  4494. function mergeOptions(to, from, strats, asMixin = false) {
  4495. const { mixins, extends: extendsOptions } = from;
  4496. if (extendsOptions) {
  4497. mergeOptions(to, extendsOptions, strats, true);
  4498. }
  4499. if (mixins) {
  4500. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  4501. }
  4502. for (const key in from) {
  4503. if (asMixin && key === 'expose') {
  4504. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  4505. `It should only be declared in the base component itself.`);
  4506. }
  4507. else {
  4508. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  4509. to[key] = strat ? strat(to[key], from[key]) : from[key];
  4510. }
  4511. }
  4512. return to;
  4513. }
  4514. const internalOptionMergeStrats = {
  4515. data: mergeDataFn,
  4516. props: mergeObjectOptions,
  4517. emits: mergeObjectOptions,
  4518. // objects
  4519. methods: mergeObjectOptions,
  4520. computed: mergeObjectOptions,
  4521. // lifecycle
  4522. beforeCreate: mergeAsArray,
  4523. created: mergeAsArray,
  4524. beforeMount: mergeAsArray,
  4525. mounted: mergeAsArray,
  4526. beforeUpdate: mergeAsArray,
  4527. updated: mergeAsArray,
  4528. beforeDestroy: mergeAsArray,
  4529. beforeUnmount: mergeAsArray,
  4530. destroyed: mergeAsArray,
  4531. unmounted: mergeAsArray,
  4532. activated: mergeAsArray,
  4533. deactivated: mergeAsArray,
  4534. errorCaptured: mergeAsArray,
  4535. serverPrefetch: mergeAsArray,
  4536. // assets
  4537. components: mergeObjectOptions,
  4538. directives: mergeObjectOptions,
  4539. // watch
  4540. watch: mergeWatchOptions,
  4541. // provide / inject
  4542. provide: mergeDataFn,
  4543. inject: mergeInject
  4544. };
  4545. function mergeDataFn(to, from) {
  4546. if (!from) {
  4547. return to;
  4548. }
  4549. if (!to) {
  4550. return from;
  4551. }
  4552. return function mergedDataFn() {
  4553. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  4554. };
  4555. }
  4556. function mergeInject(to, from) {
  4557. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  4558. }
  4559. function normalizeInject(raw) {
  4560. if (isArray(raw)) {
  4561. const res = {};
  4562. for (let i = 0; i < raw.length; i++) {
  4563. res[raw[i]] = raw[i];
  4564. }
  4565. return res;
  4566. }
  4567. return raw;
  4568. }
  4569. function mergeAsArray(to, from) {
  4570. return to ? [...new Set([].concat(to, from))] : from;
  4571. }
  4572. function mergeObjectOptions(to, from) {
  4573. return to ? extend(extend(Object.create(null), to), from) : from;
  4574. }
  4575. function mergeWatchOptions(to, from) {
  4576. if (!to)
  4577. return from;
  4578. if (!from)
  4579. return to;
  4580. const merged = extend(Object.create(null), to);
  4581. for (const key in from) {
  4582. merged[key] = mergeAsArray(to[key], from[key]);
  4583. }
  4584. return merged;
  4585. }
  4586. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  4587. isSSR = false) {
  4588. const props = {};
  4589. const attrs = {};
  4590. def(attrs, InternalObjectKey, 1);
  4591. instance.propsDefaults = Object.create(null);
  4592. setFullProps(instance, rawProps, props, attrs);
  4593. // ensure all declared prop keys are present
  4594. for (const key in instance.propsOptions[0]) {
  4595. if (!(key in props)) {
  4596. props[key] = undefined;
  4597. }
  4598. }
  4599. // validation
  4600. {
  4601. validateProps(rawProps || {}, props, instance);
  4602. }
  4603. if (isStateful) {
  4604. // stateful
  4605. instance.props = isSSR ? props : shallowReactive(props);
  4606. }
  4607. else {
  4608. if (!instance.type.props) {
  4609. // functional w/ optional props, props === attrs
  4610. instance.props = attrs;
  4611. }
  4612. else {
  4613. // functional w/ declared props
  4614. instance.props = props;
  4615. }
  4616. }
  4617. instance.attrs = attrs;
  4618. }
  4619. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  4620. const { props, attrs, vnode: { patchFlag } } = instance;
  4621. const rawCurrentProps = toRaw(props);
  4622. const [options] = instance.propsOptions;
  4623. let hasAttrsChanged = false;
  4624. if (
  4625. // always force full diff in dev
  4626. // - #1942 if hmr is enabled with sfc component
  4627. // - vite#872 non-sfc component used by sfc component
  4628. !((instance.type.__hmrId ||
  4629. (instance.parent && instance.parent.type.__hmrId))) &&
  4630. (optimized || patchFlag > 0) &&
  4631. !(patchFlag & 16 /* FULL_PROPS */)) {
  4632. if (patchFlag & 8 /* PROPS */) {
  4633. // Compiler-generated props & no keys change, just set the updated
  4634. // the props.
  4635. const propsToUpdate = instance.vnode.dynamicProps;
  4636. for (let i = 0; i < propsToUpdate.length; i++) {
  4637. let key = propsToUpdate[i];
  4638. // PROPS flag guarantees rawProps to be non-null
  4639. const value = rawProps[key];
  4640. if (options) {
  4641. // attr / props separation was done on init and will be consistent
  4642. // in this code path, so just check if attrs have it.
  4643. if (hasOwn(attrs, key)) {
  4644. if (value !== attrs[key]) {
  4645. attrs[key] = value;
  4646. hasAttrsChanged = true;
  4647. }
  4648. }
  4649. else {
  4650. const camelizedKey = camelize(key);
  4651. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  4652. }
  4653. }
  4654. else {
  4655. if (value !== attrs[key]) {
  4656. attrs[key] = value;
  4657. hasAttrsChanged = true;
  4658. }
  4659. }
  4660. }
  4661. }
  4662. }
  4663. else {
  4664. // full props update.
  4665. if (setFullProps(instance, rawProps, props, attrs)) {
  4666. hasAttrsChanged = true;
  4667. }
  4668. // in case of dynamic props, check if we need to delete keys from
  4669. // the props object
  4670. let kebabKey;
  4671. for (const key in rawCurrentProps) {
  4672. if (!rawProps ||
  4673. // for camelCase
  4674. (!hasOwn(rawProps, key) &&
  4675. // it's possible the original props was passed in as kebab-case
  4676. // and converted to camelCase (#955)
  4677. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  4678. if (options) {
  4679. if (rawPrevProps &&
  4680. // for camelCase
  4681. (rawPrevProps[key] !== undefined ||
  4682. // for kebab-case
  4683. rawPrevProps[kebabKey] !== undefined)) {
  4684. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  4685. }
  4686. }
  4687. else {
  4688. delete props[key];
  4689. }
  4690. }
  4691. }
  4692. // in the case of functional component w/o props declaration, props and
  4693. // attrs point to the same object so it should already have been updated.
  4694. if (attrs !== rawCurrentProps) {
  4695. for (const key in attrs) {
  4696. if (!rawProps ||
  4697. (!hasOwn(rawProps, key) &&
  4698. (!false ))) {
  4699. delete attrs[key];
  4700. hasAttrsChanged = true;
  4701. }
  4702. }
  4703. }
  4704. }
  4705. // trigger updates for $attrs in case it's used in component slots
  4706. if (hasAttrsChanged) {
  4707. trigger(instance, "set" /* SET */, '$attrs');
  4708. }
  4709. {
  4710. validateProps(rawProps || {}, props, instance);
  4711. }
  4712. }
  4713. function setFullProps(instance, rawProps, props, attrs) {
  4714. const [options, needCastKeys] = instance.propsOptions;
  4715. let hasAttrsChanged = false;
  4716. let rawCastValues;
  4717. if (rawProps) {
  4718. for (let key in rawProps) {
  4719. // key, ref are reserved and never passed down
  4720. if (isReservedProp(key)) {
  4721. continue;
  4722. }
  4723. const value = rawProps[key];
  4724. // prop option names are camelized during normalization, so to support
  4725. // kebab -> camel conversion here we need to camelize the key.
  4726. let camelKey;
  4727. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  4728. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  4729. props[camelKey] = value;
  4730. }
  4731. else {
  4732. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  4733. }
  4734. }
  4735. else if (!isEmitListener(instance.emitsOptions, key)) {
  4736. if (!(key in attrs) || value !== attrs[key]) {
  4737. attrs[key] = value;
  4738. hasAttrsChanged = true;
  4739. }
  4740. }
  4741. }
  4742. }
  4743. if (needCastKeys) {
  4744. const rawCurrentProps = toRaw(props);
  4745. const castValues = rawCastValues || EMPTY_OBJ;
  4746. for (let i = 0; i < needCastKeys.length; i++) {
  4747. const key = needCastKeys[i];
  4748. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  4749. }
  4750. }
  4751. return hasAttrsChanged;
  4752. }
  4753. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  4754. const opt = options[key];
  4755. if (opt != null) {
  4756. const hasDefault = hasOwn(opt, 'default');
  4757. // default values
  4758. if (hasDefault && value === undefined) {
  4759. const defaultValue = opt.default;
  4760. if (opt.type !== Function && isFunction(defaultValue)) {
  4761. const { propsDefaults } = instance;
  4762. if (key in propsDefaults) {
  4763. value = propsDefaults[key];
  4764. }
  4765. else {
  4766. setCurrentInstance(instance);
  4767. value = propsDefaults[key] = defaultValue.call(null, props);
  4768. unsetCurrentInstance();
  4769. }
  4770. }
  4771. else {
  4772. value = defaultValue;
  4773. }
  4774. }
  4775. // boolean casting
  4776. if (opt[0 /* shouldCast */]) {
  4777. if (isAbsent && !hasDefault) {
  4778. value = false;
  4779. }
  4780. else if (opt[1 /* shouldCastTrue */] &&
  4781. (value === '' || value === hyphenate(key))) {
  4782. value = true;
  4783. }
  4784. }
  4785. }
  4786. return value;
  4787. }
  4788. function normalizePropsOptions(comp, appContext, asMixin = false) {
  4789. const cache = appContext.propsCache;
  4790. const cached = cache.get(comp);
  4791. if (cached) {
  4792. return cached;
  4793. }
  4794. const raw = comp.props;
  4795. const normalized = {};
  4796. const needCastKeys = [];
  4797. // apply mixin/extends props
  4798. let hasExtends = false;
  4799. if (!isFunction(comp)) {
  4800. const extendProps = (raw) => {
  4801. hasExtends = true;
  4802. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  4803. extend(normalized, props);
  4804. if (keys)
  4805. needCastKeys.push(...keys);
  4806. };
  4807. if (!asMixin && appContext.mixins.length) {
  4808. appContext.mixins.forEach(extendProps);
  4809. }
  4810. if (comp.extends) {
  4811. extendProps(comp.extends);
  4812. }
  4813. if (comp.mixins) {
  4814. comp.mixins.forEach(extendProps);
  4815. }
  4816. }
  4817. if (!raw && !hasExtends) {
  4818. cache.set(comp, EMPTY_ARR);
  4819. return EMPTY_ARR;
  4820. }
  4821. if (isArray(raw)) {
  4822. for (let i = 0; i < raw.length; i++) {
  4823. if (!isString(raw[i])) {
  4824. warn$1(`props must be strings when using array syntax.`, raw[i]);
  4825. }
  4826. const normalizedKey = camelize(raw[i]);
  4827. if (validatePropName(normalizedKey)) {
  4828. normalized[normalizedKey] = EMPTY_OBJ;
  4829. }
  4830. }
  4831. }
  4832. else if (raw) {
  4833. if (!isObject(raw)) {
  4834. warn$1(`invalid props options`, raw);
  4835. }
  4836. for (const key in raw) {
  4837. const normalizedKey = camelize(key);
  4838. if (validatePropName(normalizedKey)) {
  4839. const opt = raw[key];
  4840. const prop = (normalized[normalizedKey] =
  4841. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  4842. if (prop) {
  4843. const booleanIndex = getTypeIndex(Boolean, prop.type);
  4844. const stringIndex = getTypeIndex(String, prop.type);
  4845. prop[0 /* shouldCast */] = booleanIndex > -1;
  4846. prop[1 /* shouldCastTrue */] =
  4847. stringIndex < 0 || booleanIndex < stringIndex;
  4848. // if the prop needs boolean casting or default value
  4849. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  4850. needCastKeys.push(normalizedKey);
  4851. }
  4852. }
  4853. }
  4854. }
  4855. }
  4856. const res = [normalized, needCastKeys];
  4857. cache.set(comp, res);
  4858. return res;
  4859. }
  4860. function validatePropName(key) {
  4861. if (key[0] !== '$') {
  4862. return true;
  4863. }
  4864. else {
  4865. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  4866. }
  4867. return false;
  4868. }
  4869. // use function string name to check type constructors
  4870. // so that it works across vms / iframes.
  4871. function getType(ctor) {
  4872. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  4873. return match ? match[1] : ctor === null ? 'null' : '';
  4874. }
  4875. function isSameType(a, b) {
  4876. return getType(a) === getType(b);
  4877. }
  4878. function getTypeIndex(type, expectedTypes) {
  4879. if (isArray(expectedTypes)) {
  4880. return expectedTypes.findIndex(t => isSameType(t, type));
  4881. }
  4882. else if (isFunction(expectedTypes)) {
  4883. return isSameType(expectedTypes, type) ? 0 : -1;
  4884. }
  4885. return -1;
  4886. }
  4887. /**
  4888. * dev only
  4889. */
  4890. function validateProps(rawProps, props, instance) {
  4891. const resolvedValues = toRaw(props);
  4892. const options = instance.propsOptions[0];
  4893. for (const key in options) {
  4894. let opt = options[key];
  4895. if (opt == null)
  4896. continue;
  4897. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  4898. }
  4899. }
  4900. /**
  4901. * dev only
  4902. */
  4903. function validateProp(name, value, prop, isAbsent) {
  4904. const { type, required, validator } = prop;
  4905. // required!
  4906. if (required && isAbsent) {
  4907. warn$1('Missing required prop: "' + name + '"');
  4908. return;
  4909. }
  4910. // missing but optional
  4911. if (value == null && !prop.required) {
  4912. return;
  4913. }
  4914. // type check
  4915. if (type != null && type !== true) {
  4916. let isValid = false;
  4917. const types = isArray(type) ? type : [type];
  4918. const expectedTypes = [];
  4919. // value is valid as long as one of the specified types match
  4920. for (let i = 0; i < types.length && !isValid; i++) {
  4921. const { valid, expectedType } = assertType(value, types[i]);
  4922. expectedTypes.push(expectedType || '');
  4923. isValid = valid;
  4924. }
  4925. if (!isValid) {
  4926. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  4927. return;
  4928. }
  4929. }
  4930. // custom validator
  4931. if (validator && !validator(value)) {
  4932. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  4933. }
  4934. }
  4935. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  4936. /**
  4937. * dev only
  4938. */
  4939. function assertType(value, type) {
  4940. let valid;
  4941. const expectedType = getType(type);
  4942. if (isSimpleType(expectedType)) {
  4943. const t = typeof value;
  4944. valid = t === expectedType.toLowerCase();
  4945. // for primitive wrapper objects
  4946. if (!valid && t === 'object') {
  4947. valid = value instanceof type;
  4948. }
  4949. }
  4950. else if (expectedType === 'Object') {
  4951. valid = isObject(value);
  4952. }
  4953. else if (expectedType === 'Array') {
  4954. valid = isArray(value);
  4955. }
  4956. else if (expectedType === 'null') {
  4957. valid = value === null;
  4958. }
  4959. else {
  4960. valid = value instanceof type;
  4961. }
  4962. return {
  4963. valid,
  4964. expectedType
  4965. };
  4966. }
  4967. /**
  4968. * dev only
  4969. */
  4970. function getInvalidTypeMessage(name, value, expectedTypes) {
  4971. let message = `Invalid prop: type check failed for prop "${name}".` +
  4972. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  4973. const expectedType = expectedTypes[0];
  4974. const receivedType = toRawType(value);
  4975. const expectedValue = styleValue(value, expectedType);
  4976. const receivedValue = styleValue(value, receivedType);
  4977. // check if we need to specify expected value
  4978. if (expectedTypes.length === 1 &&
  4979. isExplicable(expectedType) &&
  4980. !isBoolean(expectedType, receivedType)) {
  4981. message += ` with value ${expectedValue}`;
  4982. }
  4983. message += `, got ${receivedType} `;
  4984. // check if we need to specify received value
  4985. if (isExplicable(receivedType)) {
  4986. message += `with value ${receivedValue}.`;
  4987. }
  4988. return message;
  4989. }
  4990. /**
  4991. * dev only
  4992. */
  4993. function styleValue(value, type) {
  4994. if (type === 'String') {
  4995. return `"${value}"`;
  4996. }
  4997. else if (type === 'Number') {
  4998. return `${Number(value)}`;
  4999. }
  5000. else {
  5001. return `${value}`;
  5002. }
  5003. }
  5004. /**
  5005. * dev only
  5006. */
  5007. function isExplicable(type) {
  5008. const explicitTypes = ['string', 'number', 'boolean'];
  5009. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5010. }
  5011. /**
  5012. * dev only
  5013. */
  5014. function isBoolean(...args) {
  5015. return args.some(elem => elem.toLowerCase() === 'boolean');
  5016. }
  5017. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5018. const normalizeSlotValue = (value) => isArray(value)
  5019. ? value.map(normalizeVNode)
  5020. : [normalizeVNode(value)];
  5021. const normalizeSlot = (key, rawSlot, ctx) => {
  5022. const normalized = withCtx((...args) => {
  5023. if (currentInstance) {
  5024. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  5025. `this will not track dependencies used in the slot. ` +
  5026. `Invoke the slot function inside the render function instead.`);
  5027. }
  5028. return normalizeSlotValue(rawSlot(...args));
  5029. }, ctx);
  5030. normalized._c = false;
  5031. return normalized;
  5032. };
  5033. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5034. const ctx = rawSlots._ctx;
  5035. for (const key in rawSlots) {
  5036. if (isInternalKey(key))
  5037. continue;
  5038. const value = rawSlots[key];
  5039. if (isFunction(value)) {
  5040. slots[key] = normalizeSlot(key, value, ctx);
  5041. }
  5042. else if (value != null) {
  5043. {
  5044. warn$1(`Non-function value encountered for slot "${key}". ` +
  5045. `Prefer function slots for better performance.`);
  5046. }
  5047. const normalized = normalizeSlotValue(value);
  5048. slots[key] = () => normalized;
  5049. }
  5050. }
  5051. };
  5052. const normalizeVNodeSlots = (instance, children) => {
  5053. if (!isKeepAlive(instance.vnode) &&
  5054. !(false )) {
  5055. warn$1(`Non-function value encountered for default slot. ` +
  5056. `Prefer function slots for better performance.`);
  5057. }
  5058. const normalized = normalizeSlotValue(children);
  5059. instance.slots.default = () => normalized;
  5060. };
  5061. const initSlots = (instance, children) => {
  5062. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5063. const type = children._;
  5064. if (type) {
  5065. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5066. // we should avoid the proxy object polluting the slots of the internal instance
  5067. instance.slots = toRaw(children);
  5068. // make compiler marker non-enumerable
  5069. def(children, '_', type);
  5070. }
  5071. else {
  5072. normalizeObjectSlots(children, (instance.slots = {}));
  5073. }
  5074. }
  5075. else {
  5076. instance.slots = {};
  5077. if (children) {
  5078. normalizeVNodeSlots(instance, children);
  5079. }
  5080. }
  5081. def(instance.slots, InternalObjectKey, 1);
  5082. };
  5083. const updateSlots = (instance, children, optimized) => {
  5084. const { vnode, slots } = instance;
  5085. let needDeletionCheck = true;
  5086. let deletionComparisonTarget = EMPTY_OBJ;
  5087. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5088. const type = children._;
  5089. if (type) {
  5090. // compiled slots.
  5091. if (isHmrUpdating) {
  5092. // Parent was HMR updated so slot content may have changed.
  5093. // force update slots and mark instance for hmr as well
  5094. extend(slots, children);
  5095. }
  5096. else if (optimized && type === 1 /* STABLE */) {
  5097. // compiled AND stable.
  5098. // no need to update, and skip stale slots removal.
  5099. needDeletionCheck = false;
  5100. }
  5101. else {
  5102. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5103. // normalization.
  5104. extend(slots, children);
  5105. // #2893
  5106. // when rendering the optimized slots by manually written render function,
  5107. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5108. // i.e. let the `renderSlot` create the bailed Fragment
  5109. if (!optimized && type === 1 /* STABLE */) {
  5110. delete slots._;
  5111. }
  5112. }
  5113. }
  5114. else {
  5115. needDeletionCheck = !children.$stable;
  5116. normalizeObjectSlots(children, slots);
  5117. }
  5118. deletionComparisonTarget = children;
  5119. }
  5120. else if (children) {
  5121. // non slot object children (direct value) passed to a component
  5122. normalizeVNodeSlots(instance, children);
  5123. deletionComparisonTarget = { default: 1 };
  5124. }
  5125. // delete stale slots
  5126. if (needDeletionCheck) {
  5127. for (const key in slots) {
  5128. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5129. delete slots[key];
  5130. }
  5131. }
  5132. }
  5133. };
  5134. /**
  5135. Runtime helper for applying directives to a vnode. Example usage:
  5136. const comp = resolveComponent('comp')
  5137. const foo = resolveDirective('foo')
  5138. const bar = resolveDirective('bar')
  5139. return withDirectives(h(comp), [
  5140. [foo, this.x],
  5141. [bar, this.y]
  5142. ])
  5143. */
  5144. function validateDirectiveName(name) {
  5145. if (isBuiltInDirective(name)) {
  5146. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  5147. }
  5148. }
  5149. /**
  5150. * Adds directives to a VNode.
  5151. */
  5152. function withDirectives(vnode, directives) {
  5153. const internalInstance = currentRenderingInstance;
  5154. if (internalInstance === null) {
  5155. warn$1(`withDirectives can only be used inside render functions.`);
  5156. return vnode;
  5157. }
  5158. const instance = internalInstance.proxy;
  5159. const bindings = vnode.dirs || (vnode.dirs = []);
  5160. for (let i = 0; i < directives.length; i++) {
  5161. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  5162. if (isFunction(dir)) {
  5163. dir = {
  5164. mounted: dir,
  5165. updated: dir
  5166. };
  5167. }
  5168. if (dir.deep) {
  5169. traverse(value);
  5170. }
  5171. bindings.push({
  5172. dir,
  5173. instance,
  5174. value,
  5175. oldValue: void 0,
  5176. arg,
  5177. modifiers
  5178. });
  5179. }
  5180. return vnode;
  5181. }
  5182. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  5183. const bindings = vnode.dirs;
  5184. const oldBindings = prevVNode && prevVNode.dirs;
  5185. for (let i = 0; i < bindings.length; i++) {
  5186. const binding = bindings[i];
  5187. if (oldBindings) {
  5188. binding.oldValue = oldBindings[i].value;
  5189. }
  5190. let hook = binding.dir[name];
  5191. if (hook) {
  5192. // disable tracking inside all lifecycle hooks
  5193. // since they can potentially be called inside effects.
  5194. pauseTracking();
  5195. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  5196. vnode.el,
  5197. binding,
  5198. vnode,
  5199. prevVNode
  5200. ]);
  5201. resetTracking();
  5202. }
  5203. }
  5204. }
  5205. function createAppContext() {
  5206. return {
  5207. app: null,
  5208. config: {
  5209. isNativeTag: NO,
  5210. performance: false,
  5211. globalProperties: {},
  5212. optionMergeStrategies: {},
  5213. errorHandler: undefined,
  5214. warnHandler: undefined,
  5215. compilerOptions: {}
  5216. },
  5217. mixins: [],
  5218. components: {},
  5219. directives: {},
  5220. provides: Object.create(null),
  5221. optionsCache: new WeakMap(),
  5222. propsCache: new WeakMap(),
  5223. emitsCache: new WeakMap()
  5224. };
  5225. }
  5226. let uid = 0;
  5227. function createAppAPI(render, hydrate) {
  5228. return function createApp(rootComponent, rootProps = null) {
  5229. if (rootProps != null && !isObject(rootProps)) {
  5230. warn$1(`root props passed to app.mount() must be an object.`);
  5231. rootProps = null;
  5232. }
  5233. const context = createAppContext();
  5234. const installedPlugins = new Set();
  5235. let isMounted = false;
  5236. const app = (context.app = {
  5237. _uid: uid++,
  5238. _component: rootComponent,
  5239. _props: rootProps,
  5240. _container: null,
  5241. _context: context,
  5242. _instance: null,
  5243. version,
  5244. get config() {
  5245. return context.config;
  5246. },
  5247. set config(v) {
  5248. {
  5249. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  5250. }
  5251. },
  5252. use(plugin, ...options) {
  5253. if (installedPlugins.has(plugin)) {
  5254. warn$1(`Plugin has already been applied to target app.`);
  5255. }
  5256. else if (plugin && isFunction(plugin.install)) {
  5257. installedPlugins.add(plugin);
  5258. plugin.install(app, ...options);
  5259. }
  5260. else if (isFunction(plugin)) {
  5261. installedPlugins.add(plugin);
  5262. plugin(app, ...options);
  5263. }
  5264. else {
  5265. warn$1(`A plugin must either be a function or an object with an "install" ` +
  5266. `function.`);
  5267. }
  5268. return app;
  5269. },
  5270. mixin(mixin) {
  5271. {
  5272. if (!context.mixins.includes(mixin)) {
  5273. context.mixins.push(mixin);
  5274. }
  5275. else {
  5276. warn$1('Mixin has already been applied to target app' +
  5277. (mixin.name ? `: ${mixin.name}` : ''));
  5278. }
  5279. }
  5280. return app;
  5281. },
  5282. component(name, component) {
  5283. {
  5284. validateComponentName(name, context.config);
  5285. }
  5286. if (!component) {
  5287. return context.components[name];
  5288. }
  5289. if (context.components[name]) {
  5290. warn$1(`Component "${name}" has already been registered in target app.`);
  5291. }
  5292. context.components[name] = component;
  5293. return app;
  5294. },
  5295. directive(name, directive) {
  5296. {
  5297. validateDirectiveName(name);
  5298. }
  5299. if (!directive) {
  5300. return context.directives[name];
  5301. }
  5302. if (context.directives[name]) {
  5303. warn$1(`Directive "${name}" has already been registered in target app.`);
  5304. }
  5305. context.directives[name] = directive;
  5306. return app;
  5307. },
  5308. mount(rootContainer, isHydrate, isSVG) {
  5309. if (!isMounted) {
  5310. const vnode = createVNode(rootComponent, rootProps);
  5311. // store app context on the root VNode.
  5312. // this will be set on the root instance on initial mount.
  5313. vnode.appContext = context;
  5314. // HMR root reload
  5315. {
  5316. context.reload = () => {
  5317. render(cloneVNode(vnode), rootContainer, isSVG);
  5318. };
  5319. }
  5320. if (isHydrate && hydrate) {
  5321. hydrate(vnode, rootContainer);
  5322. }
  5323. else {
  5324. render(vnode, rootContainer, isSVG);
  5325. }
  5326. isMounted = true;
  5327. app._container = rootContainer;
  5328. rootContainer.__vue_app__ = app;
  5329. {
  5330. app._instance = vnode.component;
  5331. devtoolsInitApp(app, version);
  5332. }
  5333. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5334. }
  5335. else {
  5336. warn$1(`App has already been mounted.\n` +
  5337. `If you want to remount the same app, move your app creation logic ` +
  5338. `into a factory function and create fresh app instances for each ` +
  5339. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5340. }
  5341. },
  5342. unmount() {
  5343. if (isMounted) {
  5344. render(null, app._container);
  5345. {
  5346. app._instance = null;
  5347. devtoolsUnmountApp(app);
  5348. }
  5349. delete app._container.__vue_app__;
  5350. }
  5351. else {
  5352. warn$1(`Cannot unmount an app that is not mounted.`);
  5353. }
  5354. },
  5355. provide(key, value) {
  5356. if (key in context.provides) {
  5357. warn$1(`App already provides property with key "${String(key)}". ` +
  5358. `It will be overwritten with the new value.`);
  5359. }
  5360. // TypeScript doesn't allow symbols as index type
  5361. // https://github.com/Microsoft/TypeScript/issues/24587
  5362. context.provides[key] = value;
  5363. return app;
  5364. }
  5365. });
  5366. return app;
  5367. };
  5368. }
  5369. /**
  5370. * Function for handling a template ref
  5371. */
  5372. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5373. if (isArray(rawRef)) {
  5374. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5375. return;
  5376. }
  5377. if (isAsyncWrapper(vnode) && !isUnmount) {
  5378. // when mounting async components, nothing needs to be done,
  5379. // because the template ref is forwarded to inner component
  5380. return;
  5381. }
  5382. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  5383. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5384. : vnode.el;
  5385. const value = isUnmount ? null : refValue;
  5386. const { i: owner, r: ref } = rawRef;
  5387. if (!owner) {
  5388. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5389. `A vnode with ref must be created inside the render function.`);
  5390. return;
  5391. }
  5392. const oldRef = oldRawRef && oldRawRef.r;
  5393. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5394. const setupState = owner.setupState;
  5395. // dynamic ref changed. unset old ref
  5396. if (oldRef != null && oldRef !== ref) {
  5397. if (isString(oldRef)) {
  5398. refs[oldRef] = null;
  5399. if (hasOwn(setupState, oldRef)) {
  5400. setupState[oldRef] = null;
  5401. }
  5402. }
  5403. else if (isRef(oldRef)) {
  5404. oldRef.value = null;
  5405. }
  5406. }
  5407. if (isFunction(ref)) {
  5408. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  5409. }
  5410. else {
  5411. const _isString = isString(ref);
  5412. const _isRef = isRef(ref);
  5413. if (_isString || _isRef) {
  5414. const doSet = () => {
  5415. if (rawRef.f) {
  5416. const existing = _isString ? refs[ref] : ref.value;
  5417. if (isUnmount) {
  5418. isArray(existing) && remove(existing, refValue);
  5419. }
  5420. else {
  5421. if (!isArray(existing)) {
  5422. if (_isString) {
  5423. refs[ref] = [refValue];
  5424. }
  5425. else {
  5426. ref.value = [refValue];
  5427. if (rawRef.k)
  5428. refs[rawRef.k] = ref.value;
  5429. }
  5430. }
  5431. else if (!existing.includes(refValue)) {
  5432. existing.push(refValue);
  5433. }
  5434. }
  5435. }
  5436. else if (_isString) {
  5437. refs[ref] = value;
  5438. if (hasOwn(setupState, ref)) {
  5439. setupState[ref] = value;
  5440. }
  5441. }
  5442. else if (isRef(ref)) {
  5443. ref.value = value;
  5444. if (rawRef.k)
  5445. refs[rawRef.k] = value;
  5446. }
  5447. else {
  5448. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  5449. }
  5450. };
  5451. if (value) {
  5452. doSet.id = -1;
  5453. queuePostRenderEffect(doSet, parentSuspense);
  5454. }
  5455. else {
  5456. doSet();
  5457. }
  5458. }
  5459. else {
  5460. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  5461. }
  5462. }
  5463. }
  5464. let hasMismatch = false;
  5465. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  5466. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  5467. // Note: hydration is DOM-specific
  5468. // But we have to place it in core due to tight coupling with core - splitting
  5469. // it out creates a ton of unnecessary complexity.
  5470. // Hydration also depends on some renderer internal logic which needs to be
  5471. // passed in via arguments.
  5472. function createHydrationFunctions(rendererInternals) {
  5473. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  5474. const hydrate = (vnode, container) => {
  5475. if (!container.hasChildNodes()) {
  5476. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  5477. `Performing full mount instead.`);
  5478. patch(null, vnode, container);
  5479. flushPostFlushCbs();
  5480. return;
  5481. }
  5482. hasMismatch = false;
  5483. hydrateNode(container.firstChild, vnode, null, null, null);
  5484. flushPostFlushCbs();
  5485. if (hasMismatch && !false) {
  5486. // this error should show up in production
  5487. console.error(`Hydration completed but contains mismatches.`);
  5488. }
  5489. };
  5490. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  5491. const isFragmentStart = isComment(node) && node.data === '[';
  5492. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  5493. const { type, ref, shapeFlag } = vnode;
  5494. const domType = node.nodeType;
  5495. vnode.el = node;
  5496. let nextNode = null;
  5497. switch (type) {
  5498. case Text:
  5499. if (domType !== 3 /* TEXT */) {
  5500. nextNode = onMismatch();
  5501. }
  5502. else {
  5503. if (node.data !== vnode.children) {
  5504. hasMismatch = true;
  5505. warn$1(`Hydration text mismatch:` +
  5506. `\n- Client: ${JSON.stringify(node.data)}` +
  5507. `\n- Server: ${JSON.stringify(vnode.children)}`);
  5508. node.data = vnode.children;
  5509. }
  5510. nextNode = nextSibling(node);
  5511. }
  5512. break;
  5513. case Comment:
  5514. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  5515. nextNode = onMismatch();
  5516. }
  5517. else {
  5518. nextNode = nextSibling(node);
  5519. }
  5520. break;
  5521. case Static:
  5522. if (domType !== 1 /* ELEMENT */) {
  5523. nextNode = onMismatch();
  5524. }
  5525. else {
  5526. // determine anchor, adopt content
  5527. nextNode = node;
  5528. // if the static vnode has its content stripped during build,
  5529. // adopt it from the server-rendered HTML.
  5530. const needToAdoptContent = !vnode.children.length;
  5531. for (let i = 0; i < vnode.staticCount; i++) {
  5532. if (needToAdoptContent)
  5533. vnode.children += nextNode.outerHTML;
  5534. if (i === vnode.staticCount - 1) {
  5535. vnode.anchor = nextNode;
  5536. }
  5537. nextNode = nextSibling(nextNode);
  5538. }
  5539. return nextNode;
  5540. }
  5541. break;
  5542. case Fragment:
  5543. if (!isFragmentStart) {
  5544. nextNode = onMismatch();
  5545. }
  5546. else {
  5547. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5548. }
  5549. break;
  5550. default:
  5551. if (shapeFlag & 1 /* ELEMENT */) {
  5552. if (domType !== 1 /* ELEMENT */ ||
  5553. vnode.type.toLowerCase() !==
  5554. node.tagName.toLowerCase()) {
  5555. nextNode = onMismatch();
  5556. }
  5557. else {
  5558. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5559. }
  5560. }
  5561. else if (shapeFlag & 6 /* COMPONENT */) {
  5562. // when setting up the render effect, if the initial vnode already
  5563. // has .el set, the component will perform hydration instead of mount
  5564. // on its sub-tree.
  5565. vnode.slotScopeIds = slotScopeIds;
  5566. const container = parentNode(node);
  5567. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  5568. // component may be async, so in the case of fragments we cannot rely
  5569. // on component's rendered output to determine the end of the fragment
  5570. // instead, we do a lookahead to find the end anchor node.
  5571. nextNode = isFragmentStart
  5572. ? locateClosingAsyncAnchor(node)
  5573. : nextSibling(node);
  5574. // #3787
  5575. // if component is async, it may get moved / unmounted before its
  5576. // inner component is loaded, so we need to give it a placeholder
  5577. // vnode that matches its adopted DOM.
  5578. if (isAsyncWrapper(vnode)) {
  5579. let subTree;
  5580. if (isFragmentStart) {
  5581. subTree = createVNode(Fragment);
  5582. subTree.anchor = nextNode
  5583. ? nextNode.previousSibling
  5584. : container.lastChild;
  5585. }
  5586. else {
  5587. subTree =
  5588. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  5589. }
  5590. subTree.el = node;
  5591. vnode.component.subTree = subTree;
  5592. }
  5593. }
  5594. else if (shapeFlag & 64 /* TELEPORT */) {
  5595. if (domType !== 8 /* COMMENT */) {
  5596. nextNode = onMismatch();
  5597. }
  5598. else {
  5599. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  5600. }
  5601. }
  5602. else if (shapeFlag & 128 /* SUSPENSE */) {
  5603. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  5604. }
  5605. else {
  5606. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  5607. }
  5608. }
  5609. if (ref != null) {
  5610. setRef(ref, null, parentSuspense, vnode);
  5611. }
  5612. return nextNode;
  5613. };
  5614. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5615. optimized = optimized || !!vnode.dynamicChildren;
  5616. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  5617. // #4006 for form elements with non-string v-model value bindings
  5618. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  5619. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  5620. // skip props & children if this is hoisted static nodes
  5621. // #5405 in dev, always hydrate children for HMR
  5622. {
  5623. if (dirs) {
  5624. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5625. }
  5626. // props
  5627. if (props) {
  5628. if (forcePatchValue ||
  5629. !optimized ||
  5630. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  5631. for (const key in props) {
  5632. if ((forcePatchValue && key.endsWith('value')) ||
  5633. (isOn(key) && !isReservedProp(key))) {
  5634. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  5635. }
  5636. }
  5637. }
  5638. else if (props.onClick) {
  5639. // Fast path for click listeners (which is most often) to avoid
  5640. // iterating through props.
  5641. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  5642. }
  5643. }
  5644. // vnode / directive hooks
  5645. let vnodeHooks;
  5646. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  5647. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  5648. }
  5649. if (dirs) {
  5650. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  5651. }
  5652. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  5653. queueEffectWithSuspense(() => {
  5654. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  5655. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  5656. }, parentSuspense);
  5657. }
  5658. // children
  5659. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  5660. // skip if element has innerHTML / textContent
  5661. !(props && (props.innerHTML || props.textContent))) {
  5662. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  5663. let hasWarned = false;
  5664. while (next) {
  5665. hasMismatch = true;
  5666. if (!hasWarned) {
  5667. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  5668. `server rendered element contains more child nodes than client vdom.`);
  5669. hasWarned = true;
  5670. }
  5671. // The SSRed DOM contains more nodes than it should. Remove them.
  5672. const cur = next;
  5673. next = next.nextSibling;
  5674. remove(cur);
  5675. }
  5676. }
  5677. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5678. if (el.textContent !== vnode.children) {
  5679. hasMismatch = true;
  5680. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  5681. `- Client: ${el.textContent}\n` +
  5682. `- Server: ${vnode.children}`);
  5683. el.textContent = vnode.children;
  5684. }
  5685. }
  5686. }
  5687. return el.nextSibling;
  5688. };
  5689. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5690. optimized = optimized || !!parentVNode.dynamicChildren;
  5691. const children = parentVNode.children;
  5692. const l = children.length;
  5693. let hasWarned = false;
  5694. for (let i = 0; i < l; i++) {
  5695. const vnode = optimized
  5696. ? children[i]
  5697. : (children[i] = normalizeVNode(children[i]));
  5698. if (node) {
  5699. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  5700. }
  5701. else if (vnode.type === Text && !vnode.children) {
  5702. continue;
  5703. }
  5704. else {
  5705. hasMismatch = true;
  5706. if (!hasWarned) {
  5707. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  5708. `server rendered element contains fewer child nodes than client vdom.`);
  5709. hasWarned = true;
  5710. }
  5711. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  5712. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  5713. }
  5714. }
  5715. return node;
  5716. };
  5717. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  5718. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  5719. if (fragmentSlotScopeIds) {
  5720. slotScopeIds = slotScopeIds
  5721. ? slotScopeIds.concat(fragmentSlotScopeIds)
  5722. : fragmentSlotScopeIds;
  5723. }
  5724. const container = parentNode(node);
  5725. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  5726. if (next && isComment(next) && next.data === ']') {
  5727. return nextSibling((vnode.anchor = next));
  5728. }
  5729. else {
  5730. // fragment didn't hydrate successfully, since we didn't get a end anchor
  5731. // back. This should have led to node/children mismatch warnings.
  5732. hasMismatch = true;
  5733. // since the anchor is missing, we need to create one and insert it
  5734. insert((vnode.anchor = createComment(`]`)), container, next);
  5735. return next;
  5736. }
  5737. };
  5738. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  5739. hasMismatch = true;
  5740. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  5741. ? `(text)`
  5742. : isComment(node) && node.data === '['
  5743. ? `(start of fragment)`
  5744. : ``);
  5745. vnode.el = null;
  5746. if (isFragment) {
  5747. // remove excessive fragment nodes
  5748. const end = locateClosingAsyncAnchor(node);
  5749. while (true) {
  5750. const next = nextSibling(node);
  5751. if (next && next !== end) {
  5752. remove(next);
  5753. }
  5754. else {
  5755. break;
  5756. }
  5757. }
  5758. }
  5759. const next = nextSibling(node);
  5760. const container = parentNode(node);
  5761. remove(node);
  5762. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  5763. return next;
  5764. };
  5765. const locateClosingAsyncAnchor = (node) => {
  5766. let match = 0;
  5767. while (node) {
  5768. node = nextSibling(node);
  5769. if (node && isComment(node)) {
  5770. if (node.data === '[')
  5771. match++;
  5772. if (node.data === ']') {
  5773. if (match === 0) {
  5774. return nextSibling(node);
  5775. }
  5776. else {
  5777. match--;
  5778. }
  5779. }
  5780. }
  5781. }
  5782. return node;
  5783. };
  5784. return [hydrate, hydrateNode];
  5785. }
  5786. /* eslint-disable no-restricted-globals */
  5787. let supported;
  5788. let perf;
  5789. function startMeasure(instance, type) {
  5790. if (instance.appContext.config.performance && isSupported()) {
  5791. perf.mark(`vue-${type}-${instance.uid}`);
  5792. }
  5793. {
  5794. devtoolsPerfStart(instance, type, supported ? perf.now() : Date.now());
  5795. }
  5796. }
  5797. function endMeasure(instance, type) {
  5798. if (instance.appContext.config.performance && isSupported()) {
  5799. const startTag = `vue-${type}-${instance.uid}`;
  5800. const endTag = startTag + `:end`;
  5801. perf.mark(endTag);
  5802. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  5803. perf.clearMarks(startTag);
  5804. perf.clearMarks(endTag);
  5805. }
  5806. {
  5807. devtoolsPerfEnd(instance, type, supported ? perf.now() : Date.now());
  5808. }
  5809. }
  5810. function isSupported() {
  5811. if (supported !== undefined) {
  5812. return supported;
  5813. }
  5814. if (typeof window !== 'undefined' && window.performance) {
  5815. supported = true;
  5816. perf = window.performance;
  5817. }
  5818. else {
  5819. supported = false;
  5820. }
  5821. return supported;
  5822. }
  5823. const queuePostRenderEffect = queueEffectWithSuspense
  5824. ;
  5825. /**
  5826. * The createRenderer function accepts two generic arguments:
  5827. * HostNode and HostElement, corresponding to Node and Element types in the
  5828. * host environment. For example, for runtime-dom, HostNode would be the DOM
  5829. * `Node` interface and HostElement would be the DOM `Element` interface.
  5830. *
  5831. * Custom renderers can pass in the platform specific types like this:
  5832. *
  5833. * ``` js
  5834. * const { render, createApp } = createRenderer<Node, Element>({
  5835. * patchProp,
  5836. * ...nodeOps
  5837. * })
  5838. * ```
  5839. */
  5840. function createRenderer(options) {
  5841. return baseCreateRenderer(options);
  5842. }
  5843. // Separate API for creating hydration-enabled renderer.
  5844. // Hydration logic is only used when calling this function, making it
  5845. // tree-shakable.
  5846. function createHydrationRenderer(options) {
  5847. return baseCreateRenderer(options, createHydrationFunctions);
  5848. }
  5849. // implementation
  5850. function baseCreateRenderer(options, createHydrationFns) {
  5851. const target = getGlobalThis();
  5852. target.__VUE__ = true;
  5853. {
  5854. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  5855. }
  5856. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
  5857. // Note: functions inside this closure should use `const xxx = () => {}`
  5858. // style in order to prevent being inlined by minifiers.
  5859. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  5860. if (n1 === n2) {
  5861. return;
  5862. }
  5863. // patching & not same type, unmount old tree
  5864. if (n1 && !isSameVNodeType(n1, n2)) {
  5865. anchor = getNextHostNode(n1);
  5866. unmount(n1, parentComponent, parentSuspense, true);
  5867. n1 = null;
  5868. }
  5869. if (n2.patchFlag === -2 /* BAIL */) {
  5870. optimized = false;
  5871. n2.dynamicChildren = null;
  5872. }
  5873. const { type, ref, shapeFlag } = n2;
  5874. switch (type) {
  5875. case Text:
  5876. processText(n1, n2, container, anchor);
  5877. break;
  5878. case Comment:
  5879. processCommentNode(n1, n2, container, anchor);
  5880. break;
  5881. case Static:
  5882. if (n1 == null) {
  5883. mountStaticNode(n2, container, anchor, isSVG);
  5884. }
  5885. else {
  5886. patchStaticNode(n1, n2, container, isSVG);
  5887. }
  5888. break;
  5889. case Fragment:
  5890. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5891. break;
  5892. default:
  5893. if (shapeFlag & 1 /* ELEMENT */) {
  5894. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5895. }
  5896. else if (shapeFlag & 6 /* COMPONENT */) {
  5897. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5898. }
  5899. else if (shapeFlag & 64 /* TELEPORT */) {
  5900. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5901. }
  5902. else if (shapeFlag & 128 /* SUSPENSE */) {
  5903. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  5904. }
  5905. else {
  5906. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  5907. }
  5908. }
  5909. // set ref
  5910. if (ref != null && parentComponent) {
  5911. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  5912. }
  5913. };
  5914. const processText = (n1, n2, container, anchor) => {
  5915. if (n1 == null) {
  5916. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  5917. }
  5918. else {
  5919. const el = (n2.el = n1.el);
  5920. if (n2.children !== n1.children) {
  5921. hostSetText(el, n2.children);
  5922. }
  5923. }
  5924. };
  5925. const processCommentNode = (n1, n2, container, anchor) => {
  5926. if (n1 == null) {
  5927. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  5928. }
  5929. else {
  5930. // there's no support for dynamic comments
  5931. n2.el = n1.el;
  5932. }
  5933. };
  5934. const mountStaticNode = (n2, container, anchor, isSVG) => {
  5935. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  5936. };
  5937. /**
  5938. * Dev / HMR only
  5939. */
  5940. const patchStaticNode = (n1, n2, container, isSVG) => {
  5941. // static nodes are only patched during dev for HMR
  5942. if (n2.children !== n1.children) {
  5943. const anchor = hostNextSibling(n1.anchor);
  5944. // remove existing
  5945. removeStaticNode(n1);
  5946. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5947. }
  5948. else {
  5949. n2.el = n1.el;
  5950. n2.anchor = n1.anchor;
  5951. }
  5952. };
  5953. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  5954. let next;
  5955. while (el && el !== anchor) {
  5956. next = hostNextSibling(el);
  5957. hostInsert(el, container, nextSibling);
  5958. el = next;
  5959. }
  5960. hostInsert(anchor, container, nextSibling);
  5961. };
  5962. const removeStaticNode = ({ el, anchor }) => {
  5963. let next;
  5964. while (el && el !== anchor) {
  5965. next = hostNextSibling(el);
  5966. hostRemove(el);
  5967. el = next;
  5968. }
  5969. hostRemove(anchor);
  5970. };
  5971. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5972. isSVG = isSVG || n2.type === 'svg';
  5973. if (n1 == null) {
  5974. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5975. }
  5976. else {
  5977. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  5978. }
  5979. };
  5980. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  5981. let el;
  5982. let vnodeHook;
  5983. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  5984. {
  5985. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  5986. // mount children first, since some props may rely on child content
  5987. // being already rendered, e.g. `<select value>`
  5988. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5989. hostSetElementText(el, vnode.children);
  5990. }
  5991. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5992. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  5993. }
  5994. if (dirs) {
  5995. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5996. }
  5997. // props
  5998. if (props) {
  5999. for (const key in props) {
  6000. if (key !== 'value' && !isReservedProp(key)) {
  6001. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6002. }
  6003. }
  6004. /**
  6005. * Special case for setting value on DOM elements:
  6006. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6007. * - it needs to be forced (#1471)
  6008. * #2353 proposes adding another renderer option to configure this, but
  6009. * the properties affects are so finite it is worth special casing it
  6010. * here to reduce the complexity. (Special casing it also should not
  6011. * affect non-DOM renderers)
  6012. */
  6013. if ('value' in props) {
  6014. hostPatchProp(el, 'value', null, props.value);
  6015. }
  6016. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6017. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6018. }
  6019. }
  6020. // scopeId
  6021. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6022. }
  6023. {
  6024. Object.defineProperty(el, '__vnode', {
  6025. value: vnode,
  6026. enumerable: false
  6027. });
  6028. Object.defineProperty(el, '__vueParentComponent', {
  6029. value: parentComponent,
  6030. enumerable: false
  6031. });
  6032. }
  6033. if (dirs) {
  6034. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6035. }
  6036. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6037. // #1689 For inside suspense + suspense resolved case, just call it
  6038. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6039. transition &&
  6040. !transition.persisted;
  6041. if (needCallTransitionHooks) {
  6042. transition.beforeEnter(el);
  6043. }
  6044. hostInsert(el, container, anchor);
  6045. if ((vnodeHook = props && props.onVnodeMounted) ||
  6046. needCallTransitionHooks ||
  6047. dirs) {
  6048. queuePostRenderEffect(() => {
  6049. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6050. needCallTransitionHooks && transition.enter(el);
  6051. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6052. }, parentSuspense);
  6053. }
  6054. };
  6055. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6056. if (scopeId) {
  6057. hostSetScopeId(el, scopeId);
  6058. }
  6059. if (slotScopeIds) {
  6060. for (let i = 0; i < slotScopeIds.length; i++) {
  6061. hostSetScopeId(el, slotScopeIds[i]);
  6062. }
  6063. }
  6064. if (parentComponent) {
  6065. let subTree = parentComponent.subTree;
  6066. if (subTree.patchFlag > 0 &&
  6067. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  6068. subTree =
  6069. filterSingleRoot(subTree.children) || subTree;
  6070. }
  6071. if (vnode === subTree) {
  6072. const parentVNode = parentComponent.vnode;
  6073. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6074. }
  6075. }
  6076. };
  6077. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6078. for (let i = start; i < children.length; i++) {
  6079. const child = (children[i] = optimized
  6080. ? cloneIfMounted(children[i])
  6081. : normalizeVNode(children[i]));
  6082. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6083. }
  6084. };
  6085. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6086. const el = (n2.el = n1.el);
  6087. let { patchFlag, dynamicChildren, dirs } = n2;
  6088. // #1426 take the old vnode's patch flag into account since user may clone a
  6089. // compiler-generated vnode, which de-opts to FULL_PROPS
  6090. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  6091. const oldProps = n1.props || EMPTY_OBJ;
  6092. const newProps = n2.props || EMPTY_OBJ;
  6093. let vnodeHook;
  6094. // disable recurse in beforeUpdate hooks
  6095. parentComponent && toggleRecurse(parentComponent, false);
  6096. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6097. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6098. }
  6099. if (dirs) {
  6100. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6101. }
  6102. parentComponent && toggleRecurse(parentComponent, true);
  6103. if (isHmrUpdating) {
  6104. // HMR updated, force full diff
  6105. patchFlag = 0;
  6106. optimized = false;
  6107. dynamicChildren = null;
  6108. }
  6109. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6110. if (dynamicChildren) {
  6111. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6112. if (parentComponent && parentComponent.type.__hmrId) {
  6113. traverseStaticChildren(n1, n2);
  6114. }
  6115. }
  6116. else if (!optimized) {
  6117. // full diff
  6118. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6119. }
  6120. if (patchFlag > 0) {
  6121. // the presence of a patchFlag means this element's render code was
  6122. // generated by the compiler and can take the fast path.
  6123. // in this path old node and new node are guaranteed to have the same shape
  6124. // (i.e. at the exact same position in the source template)
  6125. if (patchFlag & 16 /* FULL_PROPS */) {
  6126. // element props contain dynamic keys, full diff needed
  6127. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6128. }
  6129. else {
  6130. // class
  6131. // this flag is matched when the element has dynamic class bindings.
  6132. if (patchFlag & 2 /* CLASS */) {
  6133. if (oldProps.class !== newProps.class) {
  6134. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6135. }
  6136. }
  6137. // style
  6138. // this flag is matched when the element has dynamic style bindings
  6139. if (patchFlag & 4 /* STYLE */) {
  6140. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6141. }
  6142. // props
  6143. // This flag is matched when the element has dynamic prop/attr bindings
  6144. // other than class and style. The keys of dynamic prop/attrs are saved for
  6145. // faster iteration.
  6146. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6147. // bail out and go through a full diff because we need to unset the old key
  6148. if (patchFlag & 8 /* PROPS */) {
  6149. // if the flag is present then dynamicProps must be non-null
  6150. const propsToUpdate = n2.dynamicProps;
  6151. for (let i = 0; i < propsToUpdate.length; i++) {
  6152. const key = propsToUpdate[i];
  6153. const prev = oldProps[key];
  6154. const next = newProps[key];
  6155. // #1471 force patch value
  6156. if (next !== prev || key === 'value') {
  6157. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6158. }
  6159. }
  6160. }
  6161. }
  6162. // text
  6163. // This flag is matched when the element has only dynamic text children.
  6164. if (patchFlag & 1 /* TEXT */) {
  6165. if (n1.children !== n2.children) {
  6166. hostSetElementText(el, n2.children);
  6167. }
  6168. }
  6169. }
  6170. else if (!optimized && dynamicChildren == null) {
  6171. // unoptimized, full diff
  6172. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6173. }
  6174. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6175. queuePostRenderEffect(() => {
  6176. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6177. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6178. }, parentSuspense);
  6179. }
  6180. };
  6181. // The fast path for blocks.
  6182. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6183. for (let i = 0; i < newChildren.length; i++) {
  6184. const oldVNode = oldChildren[i];
  6185. const newVNode = newChildren[i];
  6186. // Determine the container (parent element) for the patch.
  6187. const container =
  6188. // oldVNode may be an errored async setup() component inside Suspense
  6189. // which will not have a mounted element
  6190. oldVNode.el &&
  6191. // - In the case of a Fragment, we need to provide the actual parent
  6192. // of the Fragment itself so it can move its children.
  6193. (oldVNode.type === Fragment ||
  6194. // - In the case of different nodes, there is going to be a replacement
  6195. // which also requires the correct parent container
  6196. !isSameVNodeType(oldVNode, newVNode) ||
  6197. // - In the case of a component, it could contain anything.
  6198. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  6199. ? hostParentNode(oldVNode.el)
  6200. : // In other cases, the parent container is not actually used so we
  6201. // just pass the block element here to avoid a DOM parentNode call.
  6202. fallbackContainer;
  6203. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6204. }
  6205. };
  6206. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6207. if (oldProps !== newProps) {
  6208. for (const key in newProps) {
  6209. // empty string is not valid prop
  6210. if (isReservedProp(key))
  6211. continue;
  6212. const next = newProps[key];
  6213. const prev = oldProps[key];
  6214. // defer patching value
  6215. if (next !== prev && key !== 'value') {
  6216. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6217. }
  6218. }
  6219. if (oldProps !== EMPTY_OBJ) {
  6220. for (const key in oldProps) {
  6221. if (!isReservedProp(key) && !(key in newProps)) {
  6222. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6223. }
  6224. }
  6225. }
  6226. if ('value' in newProps) {
  6227. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6228. }
  6229. }
  6230. };
  6231. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6232. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6233. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6234. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6235. if (isHmrUpdating) {
  6236. // HMR updated, force full diff
  6237. patchFlag = 0;
  6238. optimized = false;
  6239. dynamicChildren = null;
  6240. }
  6241. // check if this is a slot fragment with :slotted scope ids
  6242. if (fragmentSlotScopeIds) {
  6243. slotScopeIds = slotScopeIds
  6244. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6245. : fragmentSlotScopeIds;
  6246. }
  6247. if (n1 == null) {
  6248. hostInsert(fragmentStartAnchor, container, anchor);
  6249. hostInsert(fragmentEndAnchor, container, anchor);
  6250. // a fragment can only have array children
  6251. // since they are either generated by the compiler, or implicitly created
  6252. // from arrays.
  6253. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6254. }
  6255. else {
  6256. if (patchFlag > 0 &&
  6257. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  6258. dynamicChildren &&
  6259. // #2715 the previous fragment could've been a BAILed one as a result
  6260. // of renderSlot() with no valid children
  6261. n1.dynamicChildren) {
  6262. // a stable fragment (template root or <template v-for>) doesn't need to
  6263. // patch children order, but it may contain dynamicChildren.
  6264. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6265. if (parentComponent && parentComponent.type.__hmrId) {
  6266. traverseStaticChildren(n1, n2);
  6267. }
  6268. else if (
  6269. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6270. // get moved around. Make sure all root level vnodes inherit el.
  6271. // #2134 or if it's a component root, it may also get moved around
  6272. // as the component is being moved.
  6273. n2.key != null ||
  6274. (parentComponent && n2 === parentComponent.subTree)) {
  6275. traverseStaticChildren(n1, n2, true /* shallow */);
  6276. }
  6277. }
  6278. else {
  6279. // keyed / unkeyed, or manual fragments.
  6280. // for keyed & unkeyed, since they are compiler generated from v-for,
  6281. // each child is guaranteed to be a block so the fragment will never
  6282. // have dynamicChildren.
  6283. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6284. }
  6285. }
  6286. };
  6287. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6288. n2.slotScopeIds = slotScopeIds;
  6289. if (n1 == null) {
  6290. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  6291. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6292. }
  6293. else {
  6294. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6295. }
  6296. }
  6297. else {
  6298. updateComponent(n1, n2, optimized);
  6299. }
  6300. };
  6301. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6302. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6303. if (instance.type.__hmrId) {
  6304. registerHMR(instance);
  6305. }
  6306. {
  6307. pushWarningContext(initialVNode);
  6308. startMeasure(instance, `mount`);
  6309. }
  6310. // inject renderer internals for keepAlive
  6311. if (isKeepAlive(initialVNode)) {
  6312. instance.ctx.renderer = internals;
  6313. }
  6314. // resolve props and slots for setup context
  6315. {
  6316. {
  6317. startMeasure(instance, `init`);
  6318. }
  6319. setupComponent(instance);
  6320. {
  6321. endMeasure(instance, `init`);
  6322. }
  6323. }
  6324. // setup() is async. This component relies on async logic to be resolved
  6325. // before proceeding
  6326. if (instance.asyncDep) {
  6327. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6328. // Give it a placeholder if this is not hydration
  6329. // TODO handle self-defined fallback
  6330. if (!initialVNode.el) {
  6331. const placeholder = (instance.subTree = createVNode(Comment));
  6332. processCommentNode(null, placeholder, container, anchor);
  6333. }
  6334. return;
  6335. }
  6336. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6337. {
  6338. popWarningContext();
  6339. endMeasure(instance, `mount`);
  6340. }
  6341. };
  6342. const updateComponent = (n1, n2, optimized) => {
  6343. const instance = (n2.component = n1.component);
  6344. if (shouldUpdateComponent(n1, n2, optimized)) {
  6345. if (instance.asyncDep &&
  6346. !instance.asyncResolved) {
  6347. // async & still pending - just update props and slots
  6348. // since the component's reactive effect for render isn't set-up yet
  6349. {
  6350. pushWarningContext(n2);
  6351. }
  6352. updateComponentPreRender(instance, n2, optimized);
  6353. {
  6354. popWarningContext();
  6355. }
  6356. return;
  6357. }
  6358. else {
  6359. // normal update
  6360. instance.next = n2;
  6361. // in case the child component is also queued, remove it to avoid
  6362. // double updating the same child component in the same flush.
  6363. invalidateJob(instance.update);
  6364. // instance.update is the reactive effect.
  6365. instance.update();
  6366. }
  6367. }
  6368. else {
  6369. // no update needed. just copy over properties
  6370. n2.component = n1.component;
  6371. n2.el = n1.el;
  6372. instance.vnode = n2;
  6373. }
  6374. };
  6375. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6376. const componentUpdateFn = () => {
  6377. if (!instance.isMounted) {
  6378. let vnodeHook;
  6379. const { el, props } = initialVNode;
  6380. const { bm, m, parent } = instance;
  6381. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6382. toggleRecurse(instance, false);
  6383. // beforeMount hook
  6384. if (bm) {
  6385. invokeArrayFns(bm);
  6386. }
  6387. // onVnodeBeforeMount
  6388. if (!isAsyncWrapperVNode &&
  6389. (vnodeHook = props && props.onVnodeBeforeMount)) {
  6390. invokeVNodeHook(vnodeHook, parent, initialVNode);
  6391. }
  6392. toggleRecurse(instance, true);
  6393. if (el && hydrateNode) {
  6394. // vnode has adopted host node - perform hydration instead of mount.
  6395. const hydrateSubTree = () => {
  6396. {
  6397. startMeasure(instance, `render`);
  6398. }
  6399. instance.subTree = renderComponentRoot(instance);
  6400. {
  6401. endMeasure(instance, `render`);
  6402. }
  6403. {
  6404. startMeasure(instance, `hydrate`);
  6405. }
  6406. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  6407. {
  6408. endMeasure(instance, `hydrate`);
  6409. }
  6410. };
  6411. if (isAsyncWrapperVNode) {
  6412. initialVNode.type.__asyncLoader().then(
  6413. // note: we are moving the render call into an async callback,
  6414. // which means it won't track dependencies - but it's ok because
  6415. // a server-rendered async wrapper is already in resolved state
  6416. // and it will never need to change.
  6417. () => !instance.isUnmounted && hydrateSubTree());
  6418. }
  6419. else {
  6420. hydrateSubTree();
  6421. }
  6422. }
  6423. else {
  6424. {
  6425. startMeasure(instance, `render`);
  6426. }
  6427. const subTree = (instance.subTree = renderComponentRoot(instance));
  6428. {
  6429. endMeasure(instance, `render`);
  6430. }
  6431. {
  6432. startMeasure(instance, `patch`);
  6433. }
  6434. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  6435. {
  6436. endMeasure(instance, `patch`);
  6437. }
  6438. initialVNode.el = subTree.el;
  6439. }
  6440. // mounted hook
  6441. if (m) {
  6442. queuePostRenderEffect(m, parentSuspense);
  6443. }
  6444. // onVnodeMounted
  6445. if (!isAsyncWrapperVNode &&
  6446. (vnodeHook = props && props.onVnodeMounted)) {
  6447. const scopedInitialVNode = initialVNode;
  6448. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  6449. }
  6450. // activated hook for keep-alive roots.
  6451. // #1742 activated hook must be accessed after first render
  6452. // since the hook may be injected by a child keep-alive
  6453. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6454. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  6455. }
  6456. instance.isMounted = true;
  6457. {
  6458. devtoolsComponentAdded(instance);
  6459. }
  6460. // #2458: deference mount-only object parameters to prevent memleaks
  6461. initialVNode = container = anchor = null;
  6462. }
  6463. else {
  6464. // updateComponent
  6465. // This is triggered by mutation of component's own state (next: null)
  6466. // OR parent calling processComponent (next: VNode)
  6467. let { next, bu, u, parent, vnode } = instance;
  6468. let originNext = next;
  6469. let vnodeHook;
  6470. {
  6471. pushWarningContext(next || instance.vnode);
  6472. }
  6473. // Disallow component effect recursion during pre-lifecycle hooks.
  6474. toggleRecurse(instance, false);
  6475. if (next) {
  6476. next.el = vnode.el;
  6477. updateComponentPreRender(instance, next, optimized);
  6478. }
  6479. else {
  6480. next = vnode;
  6481. }
  6482. // beforeUpdate hook
  6483. if (bu) {
  6484. invokeArrayFns(bu);
  6485. }
  6486. // onVnodeBeforeUpdate
  6487. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  6488. invokeVNodeHook(vnodeHook, parent, next, vnode);
  6489. }
  6490. toggleRecurse(instance, true);
  6491. // render
  6492. {
  6493. startMeasure(instance, `render`);
  6494. }
  6495. const nextTree = renderComponentRoot(instance);
  6496. {
  6497. endMeasure(instance, `render`);
  6498. }
  6499. const prevTree = instance.subTree;
  6500. instance.subTree = nextTree;
  6501. {
  6502. startMeasure(instance, `patch`);
  6503. }
  6504. patch(prevTree, nextTree,
  6505. // parent may have changed if it's in a teleport
  6506. hostParentNode(prevTree.el),
  6507. // anchor may have changed if it's in a fragment
  6508. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  6509. {
  6510. endMeasure(instance, `patch`);
  6511. }
  6512. next.el = nextTree.el;
  6513. if (originNext === null) {
  6514. // self-triggered update. In case of HOC, update parent component
  6515. // vnode el. HOC is indicated by parent instance's subTree pointing
  6516. // to child component's vnode
  6517. updateHOCHostEl(instance, nextTree.el);
  6518. }
  6519. // updated hook
  6520. if (u) {
  6521. queuePostRenderEffect(u, parentSuspense);
  6522. }
  6523. // onVnodeUpdated
  6524. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  6525. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  6526. }
  6527. {
  6528. devtoolsComponentUpdated(instance);
  6529. }
  6530. {
  6531. popWarningContext();
  6532. }
  6533. }
  6534. };
  6535. // create reactive effect for rendering
  6536. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
  6537. ));
  6538. const update = (instance.update = effect.run.bind(effect));
  6539. update.id = instance.uid;
  6540. // allowRecurse
  6541. // #1801, #2043 component render effects should allow recursive updates
  6542. toggleRecurse(instance, true);
  6543. {
  6544. effect.onTrack = instance.rtc
  6545. ? e => invokeArrayFns(instance.rtc, e)
  6546. : void 0;
  6547. effect.onTrigger = instance.rtg
  6548. ? e => invokeArrayFns(instance.rtg, e)
  6549. : void 0;
  6550. // @ts-ignore (for scheduler)
  6551. update.ownerInstance = instance;
  6552. }
  6553. update();
  6554. };
  6555. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  6556. nextVNode.component = instance;
  6557. const prevProps = instance.vnode.props;
  6558. instance.vnode = nextVNode;
  6559. instance.next = null;
  6560. updateProps(instance, nextVNode.props, prevProps, optimized);
  6561. updateSlots(instance, nextVNode.children, optimized);
  6562. pauseTracking();
  6563. // props update may have triggered pre-flush watchers.
  6564. // flush them before the render update.
  6565. flushPreFlushCbs(undefined, instance.update);
  6566. resetTracking();
  6567. };
  6568. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  6569. const c1 = n1 && n1.children;
  6570. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  6571. const c2 = n2.children;
  6572. const { patchFlag, shapeFlag } = n2;
  6573. // fast path
  6574. if (patchFlag > 0) {
  6575. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  6576. // this could be either fully-keyed or mixed (some keyed some not)
  6577. // presence of patchFlag means children are guaranteed to be arrays
  6578. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6579. return;
  6580. }
  6581. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  6582. // unkeyed
  6583. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6584. return;
  6585. }
  6586. }
  6587. // children has 3 possibilities: text, array or no children.
  6588. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6589. // text children fast path
  6590. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  6591. unmountChildren(c1, parentComponent, parentSuspense);
  6592. }
  6593. if (c2 !== c1) {
  6594. hostSetElementText(container, c2);
  6595. }
  6596. }
  6597. else {
  6598. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  6599. // prev children was array
  6600. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6601. // two arrays, cannot assume anything, do full diff
  6602. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6603. }
  6604. else {
  6605. // no new children, just unmount old
  6606. unmountChildren(c1, parentComponent, parentSuspense, true);
  6607. }
  6608. }
  6609. else {
  6610. // prev children was text OR null
  6611. // new children is array OR null
  6612. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  6613. hostSetElementText(container, '');
  6614. }
  6615. // mount new if array
  6616. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6617. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6618. }
  6619. }
  6620. }
  6621. };
  6622. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6623. c1 = c1 || EMPTY_ARR;
  6624. c2 = c2 || EMPTY_ARR;
  6625. const oldLength = c1.length;
  6626. const newLength = c2.length;
  6627. const commonLength = Math.min(oldLength, newLength);
  6628. let i;
  6629. for (i = 0; i < commonLength; i++) {
  6630. const nextChild = (c2[i] = optimized
  6631. ? cloneIfMounted(c2[i])
  6632. : normalizeVNode(c2[i]));
  6633. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6634. }
  6635. if (oldLength > newLength) {
  6636. // remove old
  6637. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  6638. }
  6639. else {
  6640. // mount new
  6641. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  6642. }
  6643. };
  6644. // can be all-keyed or mixed
  6645. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6646. let i = 0;
  6647. const l2 = c2.length;
  6648. let e1 = c1.length - 1; // prev ending index
  6649. let e2 = l2 - 1; // next ending index
  6650. // 1. sync from start
  6651. // (a b) c
  6652. // (a b) d e
  6653. while (i <= e1 && i <= e2) {
  6654. const n1 = c1[i];
  6655. const n2 = (c2[i] = optimized
  6656. ? cloneIfMounted(c2[i])
  6657. : normalizeVNode(c2[i]));
  6658. if (isSameVNodeType(n1, n2)) {
  6659. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6660. }
  6661. else {
  6662. break;
  6663. }
  6664. i++;
  6665. }
  6666. // 2. sync from end
  6667. // a (b c)
  6668. // d e (b c)
  6669. while (i <= e1 && i <= e2) {
  6670. const n1 = c1[e1];
  6671. const n2 = (c2[e2] = optimized
  6672. ? cloneIfMounted(c2[e2])
  6673. : normalizeVNode(c2[e2]));
  6674. if (isSameVNodeType(n1, n2)) {
  6675. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6676. }
  6677. else {
  6678. break;
  6679. }
  6680. e1--;
  6681. e2--;
  6682. }
  6683. // 3. common sequence + mount
  6684. // (a b)
  6685. // (a b) c
  6686. // i = 2, e1 = 1, e2 = 2
  6687. // (a b)
  6688. // c (a b)
  6689. // i = 0, e1 = -1, e2 = 0
  6690. if (i > e1) {
  6691. if (i <= e2) {
  6692. const nextPos = e2 + 1;
  6693. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  6694. while (i <= e2) {
  6695. patch(null, (c2[i] = optimized
  6696. ? cloneIfMounted(c2[i])
  6697. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6698. i++;
  6699. }
  6700. }
  6701. }
  6702. // 4. common sequence + unmount
  6703. // (a b) c
  6704. // (a b)
  6705. // i = 2, e1 = 2, e2 = 1
  6706. // a (b c)
  6707. // (b c)
  6708. // i = 0, e1 = 0, e2 = -1
  6709. else if (i > e2) {
  6710. while (i <= e1) {
  6711. unmount(c1[i], parentComponent, parentSuspense, true);
  6712. i++;
  6713. }
  6714. }
  6715. // 5. unknown sequence
  6716. // [i ... e1 + 1]: a b [c d e] f g
  6717. // [i ... e2 + 1]: a b [e d c h] f g
  6718. // i = 2, e1 = 4, e2 = 5
  6719. else {
  6720. const s1 = i; // prev starting index
  6721. const s2 = i; // next starting index
  6722. // 5.1 build key:index map for newChildren
  6723. const keyToNewIndexMap = new Map();
  6724. for (i = s2; i <= e2; i++) {
  6725. const nextChild = (c2[i] = optimized
  6726. ? cloneIfMounted(c2[i])
  6727. : normalizeVNode(c2[i]));
  6728. if (nextChild.key != null) {
  6729. if (keyToNewIndexMap.has(nextChild.key)) {
  6730. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  6731. }
  6732. keyToNewIndexMap.set(nextChild.key, i);
  6733. }
  6734. }
  6735. // 5.2 loop through old children left to be patched and try to patch
  6736. // matching nodes & remove nodes that are no longer present
  6737. let j;
  6738. let patched = 0;
  6739. const toBePatched = e2 - s2 + 1;
  6740. let moved = false;
  6741. // used to track whether any node has moved
  6742. let maxNewIndexSoFar = 0;
  6743. // works as Map<newIndex, oldIndex>
  6744. // Note that oldIndex is offset by +1
  6745. // and oldIndex = 0 is a special value indicating the new node has
  6746. // no corresponding old node.
  6747. // used for determining longest stable subsequence
  6748. const newIndexToOldIndexMap = new Array(toBePatched);
  6749. for (i = 0; i < toBePatched; i++)
  6750. newIndexToOldIndexMap[i] = 0;
  6751. for (i = s1; i <= e1; i++) {
  6752. const prevChild = c1[i];
  6753. if (patched >= toBePatched) {
  6754. // all new children have been patched so this can only be a removal
  6755. unmount(prevChild, parentComponent, parentSuspense, true);
  6756. continue;
  6757. }
  6758. let newIndex;
  6759. if (prevChild.key != null) {
  6760. newIndex = keyToNewIndexMap.get(prevChild.key);
  6761. }
  6762. else {
  6763. // key-less node, try to locate a key-less node of the same type
  6764. for (j = s2; j <= e2; j++) {
  6765. if (newIndexToOldIndexMap[j - s2] === 0 &&
  6766. isSameVNodeType(prevChild, c2[j])) {
  6767. newIndex = j;
  6768. break;
  6769. }
  6770. }
  6771. }
  6772. if (newIndex === undefined) {
  6773. unmount(prevChild, parentComponent, parentSuspense, true);
  6774. }
  6775. else {
  6776. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  6777. if (newIndex >= maxNewIndexSoFar) {
  6778. maxNewIndexSoFar = newIndex;
  6779. }
  6780. else {
  6781. moved = true;
  6782. }
  6783. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6784. patched++;
  6785. }
  6786. }
  6787. // 5.3 move and mount
  6788. // generate longest stable subsequence only when nodes have moved
  6789. const increasingNewIndexSequence = moved
  6790. ? getSequence(newIndexToOldIndexMap)
  6791. : EMPTY_ARR;
  6792. j = increasingNewIndexSequence.length - 1;
  6793. // looping backwards so that we can use last patched node as anchor
  6794. for (i = toBePatched - 1; i >= 0; i--) {
  6795. const nextIndex = s2 + i;
  6796. const nextChild = c2[nextIndex];
  6797. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  6798. if (newIndexToOldIndexMap[i] === 0) {
  6799. // mount new
  6800. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6801. }
  6802. else if (moved) {
  6803. // move if:
  6804. // There is no stable subsequence (e.g. a reverse)
  6805. // OR current node is not among the stable sequence
  6806. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  6807. move(nextChild, container, anchor, 2 /* REORDER */);
  6808. }
  6809. else {
  6810. j--;
  6811. }
  6812. }
  6813. }
  6814. }
  6815. };
  6816. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  6817. const { el, type, transition, children, shapeFlag } = vnode;
  6818. if (shapeFlag & 6 /* COMPONENT */) {
  6819. move(vnode.component.subTree, container, anchor, moveType);
  6820. return;
  6821. }
  6822. if (shapeFlag & 128 /* SUSPENSE */) {
  6823. vnode.suspense.move(container, anchor, moveType);
  6824. return;
  6825. }
  6826. if (shapeFlag & 64 /* TELEPORT */) {
  6827. type.move(vnode, container, anchor, internals);
  6828. return;
  6829. }
  6830. if (type === Fragment) {
  6831. hostInsert(el, container, anchor);
  6832. for (let i = 0; i < children.length; i++) {
  6833. move(children[i], container, anchor, moveType);
  6834. }
  6835. hostInsert(vnode.anchor, container, anchor);
  6836. return;
  6837. }
  6838. if (type === Static) {
  6839. moveStaticNode(vnode, container, anchor);
  6840. return;
  6841. }
  6842. // single nodes
  6843. const needTransition = moveType !== 2 /* REORDER */ &&
  6844. shapeFlag & 1 /* ELEMENT */ &&
  6845. transition;
  6846. if (needTransition) {
  6847. if (moveType === 0 /* ENTER */) {
  6848. transition.beforeEnter(el);
  6849. hostInsert(el, container, anchor);
  6850. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  6851. }
  6852. else {
  6853. const { leave, delayLeave, afterLeave } = transition;
  6854. const remove = () => hostInsert(el, container, anchor);
  6855. const performLeave = () => {
  6856. leave(el, () => {
  6857. remove();
  6858. afterLeave && afterLeave();
  6859. });
  6860. };
  6861. if (delayLeave) {
  6862. delayLeave(el, remove, performLeave);
  6863. }
  6864. else {
  6865. performLeave();
  6866. }
  6867. }
  6868. }
  6869. else {
  6870. hostInsert(el, container, anchor);
  6871. }
  6872. };
  6873. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  6874. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  6875. // unset ref
  6876. if (ref != null) {
  6877. setRef(ref, null, parentSuspense, vnode, true);
  6878. }
  6879. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6880. parentComponent.ctx.deactivate(vnode);
  6881. return;
  6882. }
  6883. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  6884. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  6885. let vnodeHook;
  6886. if (shouldInvokeVnodeHook &&
  6887. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  6888. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6889. }
  6890. if (shapeFlag & 6 /* COMPONENT */) {
  6891. unmountComponent(vnode.component, parentSuspense, doRemove);
  6892. }
  6893. else {
  6894. if (shapeFlag & 128 /* SUSPENSE */) {
  6895. vnode.suspense.unmount(parentSuspense, doRemove);
  6896. return;
  6897. }
  6898. if (shouldInvokeDirs) {
  6899. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  6900. }
  6901. if (shapeFlag & 64 /* TELEPORT */) {
  6902. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  6903. }
  6904. else if (dynamicChildren &&
  6905. // #1153: fast path should not be taken for non-stable (v-for) fragments
  6906. (type !== Fragment ||
  6907. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  6908. // fast path for block nodes: only need to unmount dynamic children.
  6909. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  6910. }
  6911. else if ((type === Fragment &&
  6912. patchFlag &
  6913. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  6914. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  6915. unmountChildren(children, parentComponent, parentSuspense);
  6916. }
  6917. if (doRemove) {
  6918. remove(vnode);
  6919. }
  6920. }
  6921. if ((shouldInvokeVnodeHook &&
  6922. (vnodeHook = props && props.onVnodeUnmounted)) ||
  6923. shouldInvokeDirs) {
  6924. queuePostRenderEffect(() => {
  6925. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6926. shouldInvokeDirs &&
  6927. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  6928. }, parentSuspense);
  6929. }
  6930. };
  6931. const remove = vnode => {
  6932. const { type, el, anchor, transition } = vnode;
  6933. if (type === Fragment) {
  6934. removeFragment(el, anchor);
  6935. return;
  6936. }
  6937. if (type === Static) {
  6938. removeStaticNode(vnode);
  6939. return;
  6940. }
  6941. const performRemove = () => {
  6942. hostRemove(el);
  6943. if (transition && !transition.persisted && transition.afterLeave) {
  6944. transition.afterLeave();
  6945. }
  6946. };
  6947. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  6948. transition &&
  6949. !transition.persisted) {
  6950. const { leave, delayLeave } = transition;
  6951. const performLeave = () => leave(el, performRemove);
  6952. if (delayLeave) {
  6953. delayLeave(vnode.el, performRemove, performLeave);
  6954. }
  6955. else {
  6956. performLeave();
  6957. }
  6958. }
  6959. else {
  6960. performRemove();
  6961. }
  6962. };
  6963. const removeFragment = (cur, end) => {
  6964. // For fragments, directly remove all contained DOM nodes.
  6965. // (fragment child nodes cannot have transition)
  6966. let next;
  6967. while (cur !== end) {
  6968. next = hostNextSibling(cur);
  6969. hostRemove(cur);
  6970. cur = next;
  6971. }
  6972. hostRemove(end);
  6973. };
  6974. const unmountComponent = (instance, parentSuspense, doRemove) => {
  6975. if (instance.type.__hmrId) {
  6976. unregisterHMR(instance);
  6977. }
  6978. const { bum, scope, update, subTree, um } = instance;
  6979. // beforeUnmount hook
  6980. if (bum) {
  6981. invokeArrayFns(bum);
  6982. }
  6983. // stop effects in component scope
  6984. scope.stop();
  6985. // update may be null if a component is unmounted before its async
  6986. // setup has resolved.
  6987. if (update) {
  6988. // so that scheduler will no longer invoke it
  6989. update.active = false;
  6990. unmount(subTree, instance, parentSuspense, doRemove);
  6991. }
  6992. // unmounted hook
  6993. if (um) {
  6994. queuePostRenderEffect(um, parentSuspense);
  6995. }
  6996. queuePostRenderEffect(() => {
  6997. instance.isUnmounted = true;
  6998. }, parentSuspense);
  6999. // A component with async dep inside a pending suspense is unmounted before
  7000. // its async dep resolves. This should remove the dep from the suspense, and
  7001. // cause the suspense to resolve immediately if that was the last dep.
  7002. if (parentSuspense &&
  7003. parentSuspense.pendingBranch &&
  7004. !parentSuspense.isUnmounted &&
  7005. instance.asyncDep &&
  7006. !instance.asyncResolved &&
  7007. instance.suspenseId === parentSuspense.pendingId) {
  7008. parentSuspense.deps--;
  7009. if (parentSuspense.deps === 0) {
  7010. parentSuspense.resolve();
  7011. }
  7012. }
  7013. {
  7014. devtoolsComponentRemoved(instance);
  7015. }
  7016. };
  7017. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7018. for (let i = start; i < children.length; i++) {
  7019. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7020. }
  7021. };
  7022. const getNextHostNode = vnode => {
  7023. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  7024. return getNextHostNode(vnode.component.subTree);
  7025. }
  7026. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  7027. return vnode.suspense.next();
  7028. }
  7029. return hostNextSibling((vnode.anchor || vnode.el));
  7030. };
  7031. const render = (vnode, container, isSVG) => {
  7032. if (vnode == null) {
  7033. if (container._vnode) {
  7034. unmount(container._vnode, null, null, true);
  7035. }
  7036. }
  7037. else {
  7038. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7039. }
  7040. flushPostFlushCbs();
  7041. container._vnode = vnode;
  7042. };
  7043. const internals = {
  7044. p: patch,
  7045. um: unmount,
  7046. m: move,
  7047. r: remove,
  7048. mt: mountComponent,
  7049. mc: mountChildren,
  7050. pc: patchChildren,
  7051. pbc: patchBlockChildren,
  7052. n: getNextHostNode,
  7053. o: options
  7054. };
  7055. let hydrate;
  7056. let hydrateNode;
  7057. if (createHydrationFns) {
  7058. [hydrate, hydrateNode] = createHydrationFns(internals);
  7059. }
  7060. return {
  7061. render,
  7062. hydrate,
  7063. createApp: createAppAPI(render, hydrate)
  7064. };
  7065. }
  7066. function toggleRecurse({ effect, update }, allowed) {
  7067. effect.allowRecurse = update.allowRecurse = allowed;
  7068. }
  7069. /**
  7070. * #1156
  7071. * When a component is HMR-enabled, we need to make sure that all static nodes
  7072. * inside a block also inherit the DOM element from the previous tree so that
  7073. * HMR updates (which are full updates) can retrieve the element for patching.
  7074. *
  7075. * #2080
  7076. * Inside keyed `template` fragment static children, if a fragment is moved,
  7077. * the children will always be moved. Therefore, in order to ensure correct move
  7078. * position, el should be inherited from previous nodes.
  7079. */
  7080. function traverseStaticChildren(n1, n2, shallow = false) {
  7081. const ch1 = n1.children;
  7082. const ch2 = n2.children;
  7083. if (isArray(ch1) && isArray(ch2)) {
  7084. for (let i = 0; i < ch1.length; i++) {
  7085. // this is only called in the optimized path so array children are
  7086. // guaranteed to be vnodes
  7087. const c1 = ch1[i];
  7088. let c2 = ch2[i];
  7089. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  7090. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  7091. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7092. c2.el = c1.el;
  7093. }
  7094. if (!shallow)
  7095. traverseStaticChildren(c1, c2);
  7096. }
  7097. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7098. // would have received .el during block patch)
  7099. if (c2.type === Comment && !c2.el) {
  7100. c2.el = c1.el;
  7101. }
  7102. }
  7103. }
  7104. }
  7105. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7106. function getSequence(arr) {
  7107. const p = arr.slice();
  7108. const result = [0];
  7109. let i, j, u, v, c;
  7110. const len = arr.length;
  7111. for (i = 0; i < len; i++) {
  7112. const arrI = arr[i];
  7113. if (arrI !== 0) {
  7114. j = result[result.length - 1];
  7115. if (arr[j] < arrI) {
  7116. p[i] = j;
  7117. result.push(i);
  7118. continue;
  7119. }
  7120. u = 0;
  7121. v = result.length - 1;
  7122. while (u < v) {
  7123. c = (u + v) >> 1;
  7124. if (arr[result[c]] < arrI) {
  7125. u = c + 1;
  7126. }
  7127. else {
  7128. v = c;
  7129. }
  7130. }
  7131. if (arrI < arr[result[u]]) {
  7132. if (u > 0) {
  7133. p[i] = result[u - 1];
  7134. }
  7135. result[u] = i;
  7136. }
  7137. }
  7138. }
  7139. u = result.length;
  7140. v = result[u - 1];
  7141. while (u-- > 0) {
  7142. result[u] = v;
  7143. v = p[v];
  7144. }
  7145. return result;
  7146. }
  7147. const isTeleport = (type) => type.__isTeleport;
  7148. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7149. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7150. const resolveTarget = (props, select) => {
  7151. const targetSelector = props && props.to;
  7152. if (isString(targetSelector)) {
  7153. if (!select) {
  7154. warn$1(`Current renderer does not support string target for Teleports. ` +
  7155. `(missing querySelector renderer option)`);
  7156. return null;
  7157. }
  7158. else {
  7159. const target = select(targetSelector);
  7160. if (!target) {
  7161. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7162. `Note the target element must exist before the component is mounted - ` +
  7163. `i.e. the target cannot be rendered by the component itself, and ` +
  7164. `ideally should be outside of the entire Vue component tree.`);
  7165. }
  7166. return target;
  7167. }
  7168. }
  7169. else {
  7170. if (!targetSelector && !isTeleportDisabled(props)) {
  7171. warn$1(`Invalid Teleport target: ${targetSelector}`);
  7172. }
  7173. return targetSelector;
  7174. }
  7175. };
  7176. const TeleportImpl = {
  7177. __isTeleport: true,
  7178. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7179. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7180. const disabled = isTeleportDisabled(n2.props);
  7181. let { shapeFlag, children, dynamicChildren } = n2;
  7182. // #3302
  7183. // HMR updated, force full diff
  7184. if (isHmrUpdating) {
  7185. optimized = false;
  7186. dynamicChildren = null;
  7187. }
  7188. if (n1 == null) {
  7189. // insert anchors in the main view
  7190. const placeholder = (n2.el = createComment('teleport start')
  7191. );
  7192. const mainAnchor = (n2.anchor = createComment('teleport end')
  7193. );
  7194. insert(placeholder, container, anchor);
  7195. insert(mainAnchor, container, anchor);
  7196. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7197. const targetAnchor = (n2.targetAnchor = createText(''));
  7198. if (target) {
  7199. insert(targetAnchor, target);
  7200. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7201. isSVG = isSVG || isTargetSVG(target);
  7202. }
  7203. else if (!disabled) {
  7204. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7205. }
  7206. const mount = (container, anchor) => {
  7207. // Teleport *always* has Array children. This is enforced in both the
  7208. // compiler and vnode children normalization.
  7209. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7210. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7211. }
  7212. };
  7213. if (disabled) {
  7214. mount(container, mainAnchor);
  7215. }
  7216. else if (target) {
  7217. mount(target, targetAnchor);
  7218. }
  7219. }
  7220. else {
  7221. // update content
  7222. n2.el = n1.el;
  7223. const mainAnchor = (n2.anchor = n1.anchor);
  7224. const target = (n2.target = n1.target);
  7225. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7226. const wasDisabled = isTeleportDisabled(n1.props);
  7227. const currentContainer = wasDisabled ? container : target;
  7228. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7229. isSVG = isSVG || isTargetSVG(target);
  7230. if (dynamicChildren) {
  7231. // fast path when the teleport happens to be a block root
  7232. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7233. // even in block tree mode we need to make sure all root-level nodes
  7234. // in the teleport inherit previous DOM references so that they can
  7235. // be moved in future patches.
  7236. traverseStaticChildren(n1, n2, true);
  7237. }
  7238. else if (!optimized) {
  7239. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7240. }
  7241. if (disabled) {
  7242. if (!wasDisabled) {
  7243. // enabled -> disabled
  7244. // move into main container
  7245. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  7246. }
  7247. }
  7248. else {
  7249. // target changed
  7250. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7251. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7252. if (nextTarget) {
  7253. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  7254. }
  7255. else {
  7256. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  7257. }
  7258. }
  7259. else if (wasDisabled) {
  7260. // disabled -> enabled
  7261. // move into teleport target
  7262. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  7263. }
  7264. }
  7265. }
  7266. },
  7267. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7268. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7269. if (target) {
  7270. hostRemove(targetAnchor);
  7271. }
  7272. // an unmounted teleport should always remove its children if not disabled
  7273. if (doRemove || !isTeleportDisabled(props)) {
  7274. hostRemove(anchor);
  7275. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7276. for (let i = 0; i < children.length; i++) {
  7277. const child = children[i];
  7278. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7279. }
  7280. }
  7281. }
  7282. },
  7283. move: moveTeleport,
  7284. hydrate: hydrateTeleport
  7285. };
  7286. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  7287. // move target anchor if this is a target change.
  7288. if (moveType === 0 /* TARGET_CHANGE */) {
  7289. insert(vnode.targetAnchor, container, parentAnchor);
  7290. }
  7291. const { el, anchor, shapeFlag, children, props } = vnode;
  7292. const isReorder = moveType === 2 /* REORDER */;
  7293. // move main view anchor if this is a re-order.
  7294. if (isReorder) {
  7295. insert(el, container, parentAnchor);
  7296. }
  7297. // if this is a re-order and teleport is enabled (content is in target)
  7298. // do not move children. So the opposite is: only move children if this
  7299. // is not a reorder, or the teleport is disabled
  7300. if (!isReorder || isTeleportDisabled(props)) {
  7301. // Teleport has either Array children or no children.
  7302. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7303. for (let i = 0; i < children.length; i++) {
  7304. move(children[i], container, parentAnchor, 2 /* REORDER */);
  7305. }
  7306. }
  7307. }
  7308. // move main view anchor if this is a re-order.
  7309. if (isReorder) {
  7310. insert(anchor, container, parentAnchor);
  7311. }
  7312. }
  7313. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7314. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7315. if (target) {
  7316. // if multiple teleports rendered to the same target element, we need to
  7317. // pick up from where the last teleport finished instead of the first node
  7318. const targetNode = target._lpa || target.firstChild;
  7319. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7320. if (isTeleportDisabled(vnode.props)) {
  7321. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7322. vnode.targetAnchor = targetNode;
  7323. }
  7324. else {
  7325. vnode.anchor = nextSibling(node);
  7326. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7327. }
  7328. target._lpa =
  7329. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7330. }
  7331. }
  7332. return vnode.anchor && nextSibling(vnode.anchor);
  7333. }
  7334. // Force-casted public typing for h and TSX props inference
  7335. const Teleport = TeleportImpl;
  7336. const COMPONENTS = 'components';
  7337. const DIRECTIVES = 'directives';
  7338. /**
  7339. * @private
  7340. */
  7341. function resolveComponent(name, maybeSelfReference) {
  7342. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  7343. }
  7344. const NULL_DYNAMIC_COMPONENT = Symbol();
  7345. /**
  7346. * @private
  7347. */
  7348. function resolveDynamicComponent(component) {
  7349. if (isString(component)) {
  7350. return resolveAsset(COMPONENTS, component, false) || component;
  7351. }
  7352. else {
  7353. // invalid types will fallthrough to createVNode and raise warning
  7354. return (component || NULL_DYNAMIC_COMPONENT);
  7355. }
  7356. }
  7357. /**
  7358. * @private
  7359. */
  7360. function resolveDirective(name) {
  7361. return resolveAsset(DIRECTIVES, name);
  7362. }
  7363. // implementation
  7364. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  7365. const instance = currentRenderingInstance || currentInstance;
  7366. if (instance) {
  7367. const Component = instance.type;
  7368. // explicit self name has highest priority
  7369. if (type === COMPONENTS) {
  7370. const selfName = getComponentName(Component);
  7371. if (selfName &&
  7372. (selfName === name ||
  7373. selfName === camelize(name) ||
  7374. selfName === capitalize(camelize(name)))) {
  7375. return Component;
  7376. }
  7377. }
  7378. const res =
  7379. // local registration
  7380. // check instance[type] first which is resolved for options API
  7381. resolve(instance[type] || Component[type], name) ||
  7382. // global registration
  7383. resolve(instance.appContext[type], name);
  7384. if (!res && maybeSelfReference) {
  7385. // fallback to implicit self-reference
  7386. return Component;
  7387. }
  7388. if (warnMissing && !res) {
  7389. const extra = type === COMPONENTS
  7390. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  7391. `component resolution via compilerOptions.isCustomElement.`
  7392. : ``;
  7393. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  7394. }
  7395. return res;
  7396. }
  7397. else {
  7398. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  7399. `can only be used in render() or setup().`);
  7400. }
  7401. }
  7402. function resolve(registry, name) {
  7403. return (registry &&
  7404. (registry[name] ||
  7405. registry[camelize(name)] ||
  7406. registry[capitalize(camelize(name))]));
  7407. }
  7408. const Fragment = Symbol('Fragment' );
  7409. const Text = Symbol('Text' );
  7410. const Comment = Symbol('Comment' );
  7411. const Static = Symbol('Static' );
  7412. // Since v-if and v-for are the two possible ways node structure can dynamically
  7413. // change, once we consider v-if branches and each v-for fragment a block, we
  7414. // can divide a template into nested blocks, and within each block the node
  7415. // structure would be stable. This allows us to skip most children diffing
  7416. // and only worry about the dynamic nodes (indicated by patch flags).
  7417. const blockStack = [];
  7418. let currentBlock = null;
  7419. /**
  7420. * Open a block.
  7421. * This must be called before `createBlock`. It cannot be part of `createBlock`
  7422. * because the children of the block are evaluated before `createBlock` itself
  7423. * is called. The generated code typically looks like this:
  7424. *
  7425. * ```js
  7426. * function render() {
  7427. * return (openBlock(),createBlock('div', null, [...]))
  7428. * }
  7429. * ```
  7430. * disableTracking is true when creating a v-for fragment block, since a v-for
  7431. * fragment always diffs its children.
  7432. *
  7433. * @private
  7434. */
  7435. function openBlock(disableTracking = false) {
  7436. blockStack.push((currentBlock = disableTracking ? null : []));
  7437. }
  7438. function closeBlock() {
  7439. blockStack.pop();
  7440. currentBlock = blockStack[blockStack.length - 1] || null;
  7441. }
  7442. // Whether we should be tracking dynamic child nodes inside a block.
  7443. // Only tracks when this value is > 0
  7444. // We are not using a simple boolean because this value may need to be
  7445. // incremented/decremented by nested usage of v-once (see below)
  7446. let isBlockTreeEnabled = 1;
  7447. /**
  7448. * Block tracking sometimes needs to be disabled, for example during the
  7449. * creation of a tree that needs to be cached by v-once. The compiler generates
  7450. * code like this:
  7451. *
  7452. * ``` js
  7453. * _cache[1] || (
  7454. * setBlockTracking(-1),
  7455. * _cache[1] = createVNode(...),
  7456. * setBlockTracking(1),
  7457. * _cache[1]
  7458. * )
  7459. * ```
  7460. *
  7461. * @private
  7462. */
  7463. function setBlockTracking(value) {
  7464. isBlockTreeEnabled += value;
  7465. }
  7466. function setupBlock(vnode) {
  7467. // save current block children on the block vnode
  7468. vnode.dynamicChildren =
  7469. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  7470. // close block
  7471. closeBlock();
  7472. // a block is always going to be patched, so track it as a child of its
  7473. // parent block
  7474. if (isBlockTreeEnabled > 0 && currentBlock) {
  7475. currentBlock.push(vnode);
  7476. }
  7477. return vnode;
  7478. }
  7479. /**
  7480. * @private
  7481. */
  7482. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  7483. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  7484. }
  7485. /**
  7486. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  7487. * A block root keeps track of dynamic nodes within the block in the
  7488. * `dynamicChildren` array.
  7489. *
  7490. * @private
  7491. */
  7492. function createBlock(type, props, children, patchFlag, dynamicProps) {
  7493. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  7494. }
  7495. function isVNode(value) {
  7496. return value ? value.__v_isVNode === true : false;
  7497. }
  7498. function isSameVNodeType(n1, n2) {
  7499. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  7500. hmrDirtyComponents.has(n2.type)) {
  7501. // HMR only: if the component has been hot-updated, force a reload.
  7502. return false;
  7503. }
  7504. return n1.type === n2.type && n1.key === n2.key;
  7505. }
  7506. let vnodeArgsTransformer;
  7507. /**
  7508. * Internal API for registering an arguments transform for createVNode
  7509. * used for creating stubs in the test-utils
  7510. * It is *internal* but needs to be exposed for test-utils to pick up proper
  7511. * typings
  7512. */
  7513. function transformVNodeArgs(transformer) {
  7514. vnodeArgsTransformer = transformer;
  7515. }
  7516. const createVNodeWithArgsTransform = (...args) => {
  7517. return _createVNode(...(vnodeArgsTransformer
  7518. ? vnodeArgsTransformer(args, currentRenderingInstance)
  7519. : args));
  7520. };
  7521. const InternalObjectKey = `__vInternal`;
  7522. const normalizeKey = ({ key }) => key != null ? key : null;
  7523. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  7524. return (ref != null
  7525. ? isString(ref) || isRef(ref) || isFunction(ref)
  7526. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  7527. : ref
  7528. : null);
  7529. };
  7530. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  7531. const vnode = {
  7532. __v_isVNode: true,
  7533. __v_skip: true,
  7534. type,
  7535. props,
  7536. key: props && normalizeKey(props),
  7537. ref: props && normalizeRef(props),
  7538. scopeId: currentScopeId,
  7539. slotScopeIds: null,
  7540. children,
  7541. component: null,
  7542. suspense: null,
  7543. ssContent: null,
  7544. ssFallback: null,
  7545. dirs: null,
  7546. transition: null,
  7547. el: null,
  7548. anchor: null,
  7549. target: null,
  7550. targetAnchor: null,
  7551. staticCount: 0,
  7552. shapeFlag,
  7553. patchFlag,
  7554. dynamicProps,
  7555. dynamicChildren: null,
  7556. appContext: null
  7557. };
  7558. if (needFullChildrenNormalization) {
  7559. normalizeChildren(vnode, children);
  7560. // normalize suspense children
  7561. if (shapeFlag & 128 /* SUSPENSE */) {
  7562. type.normalize(vnode);
  7563. }
  7564. }
  7565. else if (children) {
  7566. // compiled element vnode - if children is passed, only possible types are
  7567. // string or Array.
  7568. vnode.shapeFlag |= isString(children)
  7569. ? 8 /* TEXT_CHILDREN */
  7570. : 16 /* ARRAY_CHILDREN */;
  7571. }
  7572. // validate key
  7573. if (vnode.key !== vnode.key) {
  7574. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  7575. }
  7576. // track vnode for block tree
  7577. if (isBlockTreeEnabled > 0 &&
  7578. // avoid a block node from tracking itself
  7579. !isBlockNode &&
  7580. // has current parent block
  7581. currentBlock &&
  7582. // presence of a patch flag indicates this node needs patching on updates.
  7583. // component nodes also should always be patched, because even if the
  7584. // component doesn't need to update, it needs to persist the instance on to
  7585. // the next vnode so that it can be properly unmounted later.
  7586. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  7587. // the EVENTS flag is only for hydration and if it is the only flag, the
  7588. // vnode should not be considered dynamic due to handler caching.
  7589. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  7590. currentBlock.push(vnode);
  7591. }
  7592. return vnode;
  7593. }
  7594. const createVNode = (createVNodeWithArgsTransform );
  7595. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  7596. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  7597. if (!type) {
  7598. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  7599. }
  7600. type = Comment;
  7601. }
  7602. if (isVNode(type)) {
  7603. // createVNode receiving an existing vnode. This happens in cases like
  7604. // <component :is="vnode"/>
  7605. // #2078 make sure to merge refs during the clone instead of overwriting it
  7606. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  7607. if (children) {
  7608. normalizeChildren(cloned, children);
  7609. }
  7610. return cloned;
  7611. }
  7612. // class component normalization.
  7613. if (isClassComponent(type)) {
  7614. type = type.__vccOpts;
  7615. }
  7616. // class & style normalization.
  7617. if (props) {
  7618. // for reactive or proxy objects, we need to clone it to enable mutation.
  7619. props = guardReactiveProps(props);
  7620. let { class: klass, style } = props;
  7621. if (klass && !isString(klass)) {
  7622. props.class = normalizeClass(klass);
  7623. }
  7624. if (isObject(style)) {
  7625. // reactive state objects need to be cloned since they are likely to be
  7626. // mutated
  7627. if (isProxy(style) && !isArray(style)) {
  7628. style = extend({}, style);
  7629. }
  7630. props.style = normalizeStyle(style);
  7631. }
  7632. }
  7633. // encode the vnode type information into a bitmap
  7634. const shapeFlag = isString(type)
  7635. ? 1 /* ELEMENT */
  7636. : isSuspense(type)
  7637. ? 128 /* SUSPENSE */
  7638. : isTeleport(type)
  7639. ? 64 /* TELEPORT */
  7640. : isObject(type)
  7641. ? 4 /* STATEFUL_COMPONENT */
  7642. : isFunction(type)
  7643. ? 2 /* FUNCTIONAL_COMPONENT */
  7644. : 0;
  7645. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  7646. type = toRaw(type);
  7647. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  7648. `lead to unnecessary performance overhead, and should be avoided by ` +
  7649. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  7650. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  7651. }
  7652. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  7653. }
  7654. function guardReactiveProps(props) {
  7655. if (!props)
  7656. return null;
  7657. return isProxy(props) || InternalObjectKey in props
  7658. ? extend({}, props)
  7659. : props;
  7660. }
  7661. function cloneVNode(vnode, extraProps, mergeRef = false) {
  7662. // This is intentionally NOT using spread or extend to avoid the runtime
  7663. // key enumeration cost.
  7664. const { props, ref, patchFlag, children } = vnode;
  7665. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  7666. const cloned = {
  7667. __v_isVNode: true,
  7668. __v_skip: true,
  7669. type: vnode.type,
  7670. props: mergedProps,
  7671. key: mergedProps && normalizeKey(mergedProps),
  7672. ref: extraProps && extraProps.ref
  7673. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  7674. // if the vnode itself already has a ref, cloneVNode will need to merge
  7675. // the refs so the single vnode can be set on multiple refs
  7676. mergeRef && ref
  7677. ? isArray(ref)
  7678. ? ref.concat(normalizeRef(extraProps))
  7679. : [ref, normalizeRef(extraProps)]
  7680. : normalizeRef(extraProps)
  7681. : ref,
  7682. scopeId: vnode.scopeId,
  7683. slotScopeIds: vnode.slotScopeIds,
  7684. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  7685. ? children.map(deepCloneVNode)
  7686. : children,
  7687. target: vnode.target,
  7688. targetAnchor: vnode.targetAnchor,
  7689. staticCount: vnode.staticCount,
  7690. shapeFlag: vnode.shapeFlag,
  7691. // if the vnode is cloned with extra props, we can no longer assume its
  7692. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  7693. // note: preserve flag for fragments since they use the flag for children
  7694. // fast paths only.
  7695. patchFlag: extraProps && vnode.type !== Fragment
  7696. ? patchFlag === -1 // hoisted node
  7697. ? 16 /* FULL_PROPS */
  7698. : patchFlag | 16 /* FULL_PROPS */
  7699. : patchFlag,
  7700. dynamicProps: vnode.dynamicProps,
  7701. dynamicChildren: vnode.dynamicChildren,
  7702. appContext: vnode.appContext,
  7703. dirs: vnode.dirs,
  7704. transition: vnode.transition,
  7705. // These should technically only be non-null on mounted VNodes. However,
  7706. // they *should* be copied for kept-alive vnodes. So we just always copy
  7707. // them since them being non-null during a mount doesn't affect the logic as
  7708. // they will simply be overwritten.
  7709. component: vnode.component,
  7710. suspense: vnode.suspense,
  7711. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  7712. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  7713. el: vnode.el,
  7714. anchor: vnode.anchor
  7715. };
  7716. return cloned;
  7717. }
  7718. /**
  7719. * Dev only, for HMR of hoisted vnodes reused in v-for
  7720. * https://github.com/vitejs/vite/issues/2022
  7721. */
  7722. function deepCloneVNode(vnode) {
  7723. const cloned = cloneVNode(vnode);
  7724. if (isArray(vnode.children)) {
  7725. cloned.children = vnode.children.map(deepCloneVNode);
  7726. }
  7727. return cloned;
  7728. }
  7729. /**
  7730. * @private
  7731. */
  7732. function createTextVNode(text = ' ', flag = 0) {
  7733. return createVNode(Text, null, text, flag);
  7734. }
  7735. /**
  7736. * @private
  7737. */
  7738. function createStaticVNode(content, numberOfNodes) {
  7739. // A static vnode can contain multiple stringified elements, and the number
  7740. // of elements is necessary for hydration.
  7741. const vnode = createVNode(Static, null, content);
  7742. vnode.staticCount = numberOfNodes;
  7743. return vnode;
  7744. }
  7745. /**
  7746. * @private
  7747. */
  7748. function createCommentVNode(text = '',
  7749. // when used as the v-else branch, the comment node must be created as a
  7750. // block to ensure correct updates.
  7751. asBlock = false) {
  7752. return asBlock
  7753. ? (openBlock(), createBlock(Comment, null, text))
  7754. : createVNode(Comment, null, text);
  7755. }
  7756. function normalizeVNode(child) {
  7757. if (child == null || typeof child === 'boolean') {
  7758. // empty placeholder
  7759. return createVNode(Comment);
  7760. }
  7761. else if (isArray(child)) {
  7762. // fragment
  7763. return createVNode(Fragment, null,
  7764. // #3666, avoid reference pollution when reusing vnode
  7765. child.slice());
  7766. }
  7767. else if (typeof child === 'object') {
  7768. // already vnode, this should be the most common since compiled templates
  7769. // always produce all-vnode children arrays
  7770. return cloneIfMounted(child);
  7771. }
  7772. else {
  7773. // strings and numbers
  7774. return createVNode(Text, null, String(child));
  7775. }
  7776. }
  7777. // optimized normalization for template-compiled render fns
  7778. function cloneIfMounted(child) {
  7779. return child.el === null || child.memo ? child : cloneVNode(child);
  7780. }
  7781. function normalizeChildren(vnode, children) {
  7782. let type = 0;
  7783. const { shapeFlag } = vnode;
  7784. if (children == null) {
  7785. children = null;
  7786. }
  7787. else if (isArray(children)) {
  7788. type = 16 /* ARRAY_CHILDREN */;
  7789. }
  7790. else if (typeof children === 'object') {
  7791. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  7792. // Normalize slot to plain children for plain element and Teleport
  7793. const slot = children.default;
  7794. if (slot) {
  7795. // _c marker is added by withCtx() indicating this is a compiled slot
  7796. slot._c && (slot._d = false);
  7797. normalizeChildren(vnode, slot());
  7798. slot._c && (slot._d = true);
  7799. }
  7800. return;
  7801. }
  7802. else {
  7803. type = 32 /* SLOTS_CHILDREN */;
  7804. const slotFlag = children._;
  7805. if (!slotFlag && !(InternalObjectKey in children)) {
  7806. children._ctx = currentRenderingInstance;
  7807. }
  7808. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  7809. // a child component receives forwarded slots from the parent.
  7810. // its slot type is determined by its parent's slot type.
  7811. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  7812. children._ = 1 /* STABLE */;
  7813. }
  7814. else {
  7815. children._ = 2 /* DYNAMIC */;
  7816. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  7817. }
  7818. }
  7819. }
  7820. }
  7821. else if (isFunction(children)) {
  7822. children = { default: children, _ctx: currentRenderingInstance };
  7823. type = 32 /* SLOTS_CHILDREN */;
  7824. }
  7825. else {
  7826. children = String(children);
  7827. // force teleport children to array so it can be moved around
  7828. if (shapeFlag & 64 /* TELEPORT */) {
  7829. type = 16 /* ARRAY_CHILDREN */;
  7830. children = [createTextVNode(children)];
  7831. }
  7832. else {
  7833. type = 8 /* TEXT_CHILDREN */;
  7834. }
  7835. }
  7836. vnode.children = children;
  7837. vnode.shapeFlag |= type;
  7838. }
  7839. function mergeProps(...args) {
  7840. const ret = {};
  7841. for (let i = 0; i < args.length; i++) {
  7842. const toMerge = args[i];
  7843. for (const key in toMerge) {
  7844. if (key === 'class') {
  7845. if (ret.class !== toMerge.class) {
  7846. ret.class = normalizeClass([ret.class, toMerge.class]);
  7847. }
  7848. }
  7849. else if (key === 'style') {
  7850. ret.style = normalizeStyle([ret.style, toMerge.style]);
  7851. }
  7852. else if (isOn(key)) {
  7853. const existing = ret[key];
  7854. const incoming = toMerge[key];
  7855. if (incoming &&
  7856. existing !== incoming &&
  7857. !(isArray(existing) && existing.includes(incoming))) {
  7858. ret[key] = existing
  7859. ? [].concat(existing, incoming)
  7860. : incoming;
  7861. }
  7862. }
  7863. else if (key !== '') {
  7864. ret[key] = toMerge[key];
  7865. }
  7866. }
  7867. }
  7868. return ret;
  7869. }
  7870. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  7871. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  7872. vnode,
  7873. prevVNode
  7874. ]);
  7875. }
  7876. /**
  7877. * Actual implementation
  7878. */
  7879. function renderList(source, renderItem, cache, index) {
  7880. let ret;
  7881. const cached = (cache && cache[index]);
  7882. if (isArray(source) || isString(source)) {
  7883. ret = new Array(source.length);
  7884. for (let i = 0, l = source.length; i < l; i++) {
  7885. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  7886. }
  7887. }
  7888. else if (typeof source === 'number') {
  7889. if (!Number.isInteger(source)) {
  7890. warn$1(`The v-for range expect an integer value but got ${source}.`);
  7891. return [];
  7892. }
  7893. ret = new Array(source);
  7894. for (let i = 0; i < source; i++) {
  7895. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  7896. }
  7897. }
  7898. else if (isObject(source)) {
  7899. if (source[Symbol.iterator]) {
  7900. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  7901. }
  7902. else {
  7903. const keys = Object.keys(source);
  7904. ret = new Array(keys.length);
  7905. for (let i = 0, l = keys.length; i < l; i++) {
  7906. const key = keys[i];
  7907. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  7908. }
  7909. }
  7910. }
  7911. else {
  7912. ret = [];
  7913. }
  7914. if (cache) {
  7915. cache[index] = ret;
  7916. }
  7917. return ret;
  7918. }
  7919. /**
  7920. * Compiler runtime helper for creating dynamic slots object
  7921. * @private
  7922. */
  7923. function createSlots(slots, dynamicSlots) {
  7924. for (let i = 0; i < dynamicSlots.length; i++) {
  7925. const slot = dynamicSlots[i];
  7926. // array of dynamic slot generated by <template v-for="..." #[...]>
  7927. if (isArray(slot)) {
  7928. for (let j = 0; j < slot.length; j++) {
  7929. slots[slot[j].name] = slot[j].fn;
  7930. }
  7931. }
  7932. else if (slot) {
  7933. // conditional single slot generated by <template v-if="..." #foo>
  7934. slots[slot.name] = slot.fn;
  7935. }
  7936. }
  7937. return slots;
  7938. }
  7939. /**
  7940. * Compiler runtime helper for rendering `<slot/>`
  7941. * @private
  7942. */
  7943. function renderSlot(slots, name, props = {},
  7944. // this is not a user-facing function, so the fallback is always generated by
  7945. // the compiler and guaranteed to be a function returning an array
  7946. fallback, noSlotted) {
  7947. if (currentRenderingInstance.isCE) {
  7948. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  7949. }
  7950. let slot = slots[name];
  7951. if (slot && slot.length > 1) {
  7952. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  7953. `function. You need to mark this component with $dynamic-slots in the ` +
  7954. `parent template.`);
  7955. slot = () => [];
  7956. }
  7957. // a compiled slot disables block tracking by default to avoid manual
  7958. // invocation interfering with template-based block tracking, but in
  7959. // `renderSlot` we can be sure that it's template-based so we can force
  7960. // enable it.
  7961. if (slot && slot._c) {
  7962. slot._d = false;
  7963. }
  7964. openBlock();
  7965. const validSlotContent = slot && ensureValidVNode(slot(props));
  7966. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  7967. ? 64 /* STABLE_FRAGMENT */
  7968. : -2 /* BAIL */);
  7969. if (!noSlotted && rendered.scopeId) {
  7970. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  7971. }
  7972. if (slot && slot._c) {
  7973. slot._d = true;
  7974. }
  7975. return rendered;
  7976. }
  7977. function ensureValidVNode(vnodes) {
  7978. return vnodes.some(child => {
  7979. if (!isVNode(child))
  7980. return true;
  7981. if (child.type === Comment)
  7982. return false;
  7983. if (child.type === Fragment &&
  7984. !ensureValidVNode(child.children))
  7985. return false;
  7986. return true;
  7987. })
  7988. ? vnodes
  7989. : null;
  7990. }
  7991. /**
  7992. * For prefixing keys in v-on="obj" with "on"
  7993. * @private
  7994. */
  7995. function toHandlers(obj) {
  7996. const ret = {};
  7997. if (!isObject(obj)) {
  7998. warn$1(`v-on with no argument expects an object value.`);
  7999. return ret;
  8000. }
  8001. for (const key in obj) {
  8002. ret[toHandlerKey(key)] = obj[key];
  8003. }
  8004. return ret;
  8005. }
  8006. /**
  8007. * #2437 In Vue 3, functional components do not have a public instance proxy but
  8008. * they exist in the internal parent chain. For code that relies on traversing
  8009. * public $parent chains, skip functional ones and go to the parent instead.
  8010. */
  8011. const getPublicInstance = (i) => {
  8012. if (!i)
  8013. return null;
  8014. if (isStatefulComponent(i))
  8015. return getExposeProxy(i) || i.proxy;
  8016. return getPublicInstance(i.parent);
  8017. };
  8018. const publicPropertiesMap = extend(Object.create(null), {
  8019. $: i => i,
  8020. $el: i => i.vnode.el,
  8021. $data: i => i.data,
  8022. $props: i => (shallowReadonly(i.props) ),
  8023. $attrs: i => (shallowReadonly(i.attrs) ),
  8024. $slots: i => (shallowReadonly(i.slots) ),
  8025. $refs: i => (shallowReadonly(i.refs) ),
  8026. $parent: i => getPublicInstance(i.parent),
  8027. $root: i => getPublicInstance(i.root),
  8028. $emit: i => i.emit,
  8029. $options: i => (resolveMergedOptions(i) ),
  8030. $forceUpdate: i => () => queueJob(i.update),
  8031. $nextTick: i => nextTick.bind(i.proxy),
  8032. $watch: i => (instanceWatch.bind(i) )
  8033. });
  8034. const PublicInstanceProxyHandlers = {
  8035. get({ _: instance }, key) {
  8036. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  8037. // for internal formatters to know that this is a Vue instance
  8038. if (key === '__isVue') {
  8039. return true;
  8040. }
  8041. // prioritize <script setup> bindings during dev.
  8042. // this allows even properties that start with _ or $ to be used - so that
  8043. // it aligns with the production behavior where the render fn is inlined and
  8044. // indeed has access to all declared variables.
  8045. if (setupState !== EMPTY_OBJ &&
  8046. setupState.__isScriptSetup &&
  8047. hasOwn(setupState, key)) {
  8048. return setupState[key];
  8049. }
  8050. // data / props / ctx
  8051. // This getter gets called for every property access on the render context
  8052. // during render and is a major hotspot. The most expensive part of this
  8053. // is the multiple hasOwn() calls. It's much faster to do a simple property
  8054. // access on a plain object, so we use an accessCache object (with null
  8055. // prototype) to memoize what access type a key corresponds to.
  8056. let normalizedProps;
  8057. if (key[0] !== '$') {
  8058. const n = accessCache[key];
  8059. if (n !== undefined) {
  8060. switch (n) {
  8061. case 1 /* SETUP */:
  8062. return setupState[key];
  8063. case 2 /* DATA */:
  8064. return data[key];
  8065. case 4 /* CONTEXT */:
  8066. return ctx[key];
  8067. case 3 /* PROPS */:
  8068. return props[key];
  8069. // default: just fallthrough
  8070. }
  8071. }
  8072. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  8073. accessCache[key] = 1 /* SETUP */;
  8074. return setupState[key];
  8075. }
  8076. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  8077. accessCache[key] = 2 /* DATA */;
  8078. return data[key];
  8079. }
  8080. else if (
  8081. // only cache other properties when instance has declared (thus stable)
  8082. // props
  8083. (normalizedProps = instance.propsOptions[0]) &&
  8084. hasOwn(normalizedProps, key)) {
  8085. accessCache[key] = 3 /* PROPS */;
  8086. return props[key];
  8087. }
  8088. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  8089. accessCache[key] = 4 /* CONTEXT */;
  8090. return ctx[key];
  8091. }
  8092. else if (shouldCacheAccess) {
  8093. accessCache[key] = 0 /* OTHER */;
  8094. }
  8095. }
  8096. const publicGetter = publicPropertiesMap[key];
  8097. let cssModule, globalProperties;
  8098. // public $xxx properties
  8099. if (publicGetter) {
  8100. if (key === '$attrs') {
  8101. track(instance, "get" /* GET */, key);
  8102. markAttrsAccessed();
  8103. }
  8104. return publicGetter(instance);
  8105. }
  8106. else if (
  8107. // css module (injected by vue-loader)
  8108. (cssModule = type.__cssModules) &&
  8109. (cssModule = cssModule[key])) {
  8110. return cssModule;
  8111. }
  8112. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  8113. // user may set custom properties to `this` that start with `$`
  8114. accessCache[key] = 4 /* CONTEXT */;
  8115. return ctx[key];
  8116. }
  8117. else if (
  8118. // global properties
  8119. ((globalProperties = appContext.config.globalProperties),
  8120. hasOwn(globalProperties, key))) {
  8121. {
  8122. return globalProperties[key];
  8123. }
  8124. }
  8125. else if (currentRenderingInstance &&
  8126. (!isString(key) ||
  8127. // #1091 avoid internal isRef/isVNode checks on component instance leading
  8128. // to infinite warning loop
  8129. key.indexOf('__v') !== 0)) {
  8130. if (data !== EMPTY_OBJ &&
  8131. (key[0] === '$' || key[0] === '_') &&
  8132. hasOwn(data, key)) {
  8133. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  8134. `character ("$" or "_") and is not proxied on the render context.`);
  8135. }
  8136. else if (instance === currentRenderingInstance) {
  8137. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  8138. `but is not defined on instance.`);
  8139. }
  8140. }
  8141. },
  8142. set({ _: instance }, key, value) {
  8143. const { data, setupState, ctx } = instance;
  8144. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  8145. setupState[key] = value;
  8146. return true;
  8147. }
  8148. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  8149. data[key] = value;
  8150. return true;
  8151. }
  8152. else if (hasOwn(instance.props, key)) {
  8153. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  8154. return false;
  8155. }
  8156. if (key[0] === '$' && key.slice(1) in instance) {
  8157. warn$1(`Attempting to mutate public property "${key}". ` +
  8158. `Properties starting with $ are reserved and readonly.`, instance);
  8159. return false;
  8160. }
  8161. else {
  8162. if (key in instance.appContext.config.globalProperties) {
  8163. Object.defineProperty(ctx, key, {
  8164. enumerable: true,
  8165. configurable: true,
  8166. value
  8167. });
  8168. }
  8169. else {
  8170. ctx[key] = value;
  8171. }
  8172. }
  8173. return true;
  8174. },
  8175. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  8176. let normalizedProps;
  8177. return (!!accessCache[key] ||
  8178. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  8179. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  8180. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  8181. hasOwn(ctx, key) ||
  8182. hasOwn(publicPropertiesMap, key) ||
  8183. hasOwn(appContext.config.globalProperties, key));
  8184. },
  8185. defineProperty(target, key, descriptor) {
  8186. if (descriptor.get != null) {
  8187. this.set(target, key, descriptor.get(), null);
  8188. }
  8189. else if (descriptor.value != null) {
  8190. this.set(target, key, descriptor.value, null);
  8191. }
  8192. return Reflect.defineProperty(target, key, descriptor);
  8193. }
  8194. };
  8195. {
  8196. PublicInstanceProxyHandlers.ownKeys = (target) => {
  8197. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  8198. `The keys will be empty in production mode to avoid performance overhead.`);
  8199. return Reflect.ownKeys(target);
  8200. };
  8201. }
  8202. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  8203. get(target, key) {
  8204. // fast path for unscopables when using `with` block
  8205. if (key === Symbol.unscopables) {
  8206. return;
  8207. }
  8208. return PublicInstanceProxyHandlers.get(target, key, target);
  8209. },
  8210. has(_, key) {
  8211. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  8212. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  8213. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  8214. }
  8215. return has;
  8216. }
  8217. });
  8218. // dev only
  8219. // In dev mode, the proxy target exposes the same properties as seen on `this`
  8220. // for easier console inspection. In prod mode it will be an empty object so
  8221. // these properties definitions can be skipped.
  8222. function createDevRenderContext(instance) {
  8223. const target = {};
  8224. // expose internal instance for proxy handlers
  8225. Object.defineProperty(target, `_`, {
  8226. configurable: true,
  8227. enumerable: false,
  8228. get: () => instance
  8229. });
  8230. // expose public properties
  8231. Object.keys(publicPropertiesMap).forEach(key => {
  8232. Object.defineProperty(target, key, {
  8233. configurable: true,
  8234. enumerable: false,
  8235. get: () => publicPropertiesMap[key](instance),
  8236. // intercepted by the proxy so no need for implementation,
  8237. // but needed to prevent set errors
  8238. set: NOOP
  8239. });
  8240. });
  8241. return target;
  8242. }
  8243. // dev only
  8244. function exposePropsOnRenderContext(instance) {
  8245. const { ctx, propsOptions: [propsOptions] } = instance;
  8246. if (propsOptions) {
  8247. Object.keys(propsOptions).forEach(key => {
  8248. Object.defineProperty(ctx, key, {
  8249. enumerable: true,
  8250. configurable: true,
  8251. get: () => instance.props[key],
  8252. set: NOOP
  8253. });
  8254. });
  8255. }
  8256. }
  8257. // dev only
  8258. function exposeSetupStateOnRenderContext(instance) {
  8259. const { ctx, setupState } = instance;
  8260. Object.keys(toRaw(setupState)).forEach(key => {
  8261. if (!setupState.__isScriptSetup) {
  8262. if (key[0] === '$' || key[0] === '_') {
  8263. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  8264. `which are reserved prefixes for Vue internals.`);
  8265. return;
  8266. }
  8267. Object.defineProperty(ctx, key, {
  8268. enumerable: true,
  8269. configurable: true,
  8270. get: () => setupState[key],
  8271. set: NOOP
  8272. });
  8273. }
  8274. });
  8275. }
  8276. const emptyAppContext = createAppContext();
  8277. let uid$1 = 0;
  8278. function createComponentInstance(vnode, parent, suspense) {
  8279. const type = vnode.type;
  8280. // inherit parent app context - or - if root, adopt from root vnode
  8281. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8282. const instance = {
  8283. uid: uid$1++,
  8284. vnode,
  8285. type,
  8286. parent,
  8287. appContext,
  8288. root: null,
  8289. next: null,
  8290. subTree: null,
  8291. effect: null,
  8292. update: null,
  8293. scope: new EffectScope(true /* detached */),
  8294. render: null,
  8295. proxy: null,
  8296. exposed: null,
  8297. exposeProxy: null,
  8298. withProxy: null,
  8299. provides: parent ? parent.provides : Object.create(appContext.provides),
  8300. accessCache: null,
  8301. renderCache: [],
  8302. // local resovled assets
  8303. components: null,
  8304. directives: null,
  8305. // resolved props and emits options
  8306. propsOptions: normalizePropsOptions(type, appContext),
  8307. emitsOptions: normalizeEmitsOptions(type, appContext),
  8308. // emit
  8309. emit: null,
  8310. emitted: null,
  8311. // props default value
  8312. propsDefaults: EMPTY_OBJ,
  8313. // inheritAttrs
  8314. inheritAttrs: type.inheritAttrs,
  8315. // state
  8316. ctx: EMPTY_OBJ,
  8317. data: EMPTY_OBJ,
  8318. props: EMPTY_OBJ,
  8319. attrs: EMPTY_OBJ,
  8320. slots: EMPTY_OBJ,
  8321. refs: EMPTY_OBJ,
  8322. setupState: EMPTY_OBJ,
  8323. setupContext: null,
  8324. // suspense related
  8325. suspense,
  8326. suspenseId: suspense ? suspense.pendingId : 0,
  8327. asyncDep: null,
  8328. asyncResolved: false,
  8329. // lifecycle hooks
  8330. // not using enums here because it results in computed properties
  8331. isMounted: false,
  8332. isUnmounted: false,
  8333. isDeactivated: false,
  8334. bc: null,
  8335. c: null,
  8336. bm: null,
  8337. m: null,
  8338. bu: null,
  8339. u: null,
  8340. um: null,
  8341. bum: null,
  8342. da: null,
  8343. a: null,
  8344. rtg: null,
  8345. rtc: null,
  8346. ec: null,
  8347. sp: null
  8348. };
  8349. {
  8350. instance.ctx = createDevRenderContext(instance);
  8351. }
  8352. instance.root = parent ? parent.root : instance;
  8353. instance.emit = emit$1.bind(null, instance);
  8354. // apply custom element special handling
  8355. if (vnode.ce) {
  8356. vnode.ce(instance);
  8357. }
  8358. return instance;
  8359. }
  8360. let currentInstance = null;
  8361. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8362. const setCurrentInstance = (instance) => {
  8363. currentInstance = instance;
  8364. instance.scope.on();
  8365. };
  8366. const unsetCurrentInstance = () => {
  8367. currentInstance && currentInstance.scope.off();
  8368. currentInstance = null;
  8369. };
  8370. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8371. function validateComponentName(name, config) {
  8372. const appIsNativeTag = config.isNativeTag || NO;
  8373. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8374. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  8375. }
  8376. }
  8377. function isStatefulComponent(instance) {
  8378. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  8379. }
  8380. let isInSSRComponentSetup = false;
  8381. function setupComponent(instance, isSSR = false) {
  8382. isInSSRComponentSetup = isSSR;
  8383. const { props, children } = instance.vnode;
  8384. const isStateful = isStatefulComponent(instance);
  8385. initProps(instance, props, isStateful, isSSR);
  8386. initSlots(instance, children);
  8387. const setupResult = isStateful
  8388. ? setupStatefulComponent(instance, isSSR)
  8389. : undefined;
  8390. isInSSRComponentSetup = false;
  8391. return setupResult;
  8392. }
  8393. function setupStatefulComponent(instance, isSSR) {
  8394. const Component = instance.type;
  8395. {
  8396. if (Component.name) {
  8397. validateComponentName(Component.name, instance.appContext.config);
  8398. }
  8399. if (Component.components) {
  8400. const names = Object.keys(Component.components);
  8401. for (let i = 0; i < names.length; i++) {
  8402. validateComponentName(names[i], instance.appContext.config);
  8403. }
  8404. }
  8405. if (Component.directives) {
  8406. const names = Object.keys(Component.directives);
  8407. for (let i = 0; i < names.length; i++) {
  8408. validateDirectiveName(names[i]);
  8409. }
  8410. }
  8411. if (Component.compilerOptions && isRuntimeOnly()) {
  8412. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  8413. `includes the runtime compiler. Since you are using a runtime-only ` +
  8414. `build, the options should be passed via your build tool config instead.`);
  8415. }
  8416. }
  8417. // 0. create render proxy property access cache
  8418. instance.accessCache = Object.create(null);
  8419. // 1. create public instance / render proxy
  8420. // also mark it raw so it's never observed
  8421. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8422. {
  8423. exposePropsOnRenderContext(instance);
  8424. }
  8425. // 2. call setup()
  8426. const { setup } = Component;
  8427. if (setup) {
  8428. const setupContext = (instance.setupContext =
  8429. setup.length > 1 ? createSetupContext(instance) : null);
  8430. setCurrentInstance(instance);
  8431. pauseTracking();
  8432. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8433. resetTracking();
  8434. unsetCurrentInstance();
  8435. if (isPromise(setupResult)) {
  8436. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8437. if (isSSR) {
  8438. // return the promise so server-renderer can wait on it
  8439. return setupResult
  8440. .then((resolvedResult) => {
  8441. handleSetupResult(instance, resolvedResult, isSSR);
  8442. })
  8443. .catch(e => {
  8444. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  8445. });
  8446. }
  8447. else {
  8448. // async setup returned Promise.
  8449. // bail here and wait for re-entry.
  8450. instance.asyncDep = setupResult;
  8451. }
  8452. }
  8453. else {
  8454. handleSetupResult(instance, setupResult, isSSR);
  8455. }
  8456. }
  8457. else {
  8458. finishComponentSetup(instance, isSSR);
  8459. }
  8460. }
  8461. function handleSetupResult(instance, setupResult, isSSR) {
  8462. if (isFunction(setupResult)) {
  8463. // setup returned an inline render function
  8464. {
  8465. instance.render = setupResult;
  8466. }
  8467. }
  8468. else if (isObject(setupResult)) {
  8469. if (isVNode(setupResult)) {
  8470. warn$1(`setup() should not return VNodes directly - ` +
  8471. `return a render function instead.`);
  8472. }
  8473. // setup returned bindings.
  8474. // assuming a render function compiled from template is present.
  8475. {
  8476. instance.devtoolsRawSetupState = setupResult;
  8477. }
  8478. instance.setupState = proxyRefs(setupResult);
  8479. {
  8480. exposeSetupStateOnRenderContext(instance);
  8481. }
  8482. }
  8483. else if (setupResult !== undefined) {
  8484. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8485. }
  8486. finishComponentSetup(instance, isSSR);
  8487. }
  8488. let compile;
  8489. let installWithProxy;
  8490. /**
  8491. * For runtime-dom to register the compiler.
  8492. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8493. */
  8494. function registerRuntimeCompiler(_compile) {
  8495. compile = _compile;
  8496. installWithProxy = i => {
  8497. if (i.render._rc) {
  8498. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8499. }
  8500. };
  8501. }
  8502. // dev only
  8503. const isRuntimeOnly = () => !compile;
  8504. function finishComponentSetup(instance, isSSR, skipOptions) {
  8505. const Component = instance.type;
  8506. // template / render function normalization
  8507. // could be already set when returned from setup()
  8508. if (!instance.render) {
  8509. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8510. // is done by server-renderer
  8511. if (!isSSR && compile && !Component.render) {
  8512. const template = Component.template;
  8513. if (template) {
  8514. {
  8515. startMeasure(instance, `compile`);
  8516. }
  8517. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8518. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8519. const finalCompilerOptions = extend(extend({
  8520. isCustomElement,
  8521. delimiters
  8522. }, compilerOptions), componentCompilerOptions);
  8523. Component.render = compile(template, finalCompilerOptions);
  8524. {
  8525. endMeasure(instance, `compile`);
  8526. }
  8527. }
  8528. }
  8529. instance.render = (Component.render || NOOP);
  8530. // for runtime-compiled render functions using `with` blocks, the render
  8531. // proxy used needs a different `has` handler which is more performant and
  8532. // also only allows a whitelist of globals to fallthrough.
  8533. if (installWithProxy) {
  8534. installWithProxy(instance);
  8535. }
  8536. }
  8537. // support for 2.x options
  8538. {
  8539. setCurrentInstance(instance);
  8540. pauseTracking();
  8541. applyOptions(instance);
  8542. resetTracking();
  8543. unsetCurrentInstance();
  8544. }
  8545. // warn missing template/render
  8546. // the runtime compilation of template in SSR is done by server-render
  8547. if (!Component.render && instance.render === NOOP && !isSSR) {
  8548. /* istanbul ignore if */
  8549. if (!compile && Component.template) {
  8550. warn$1(`Component provided template option but ` +
  8551. `runtime compilation is not supported in this build of Vue.` +
  8552. (` Use "vue.global.js" instead.`
  8553. ) /* should not happen */);
  8554. }
  8555. else {
  8556. warn$1(`Component is missing template or render function.`);
  8557. }
  8558. }
  8559. }
  8560. function createAttrsProxy(instance) {
  8561. return new Proxy(instance.attrs, {
  8562. get(target, key) {
  8563. markAttrsAccessed();
  8564. track(instance, "get" /* GET */, '$attrs');
  8565. return target[key];
  8566. },
  8567. set() {
  8568. warn$1(`setupContext.attrs is readonly.`);
  8569. return false;
  8570. },
  8571. deleteProperty() {
  8572. warn$1(`setupContext.attrs is readonly.`);
  8573. return false;
  8574. }
  8575. }
  8576. );
  8577. }
  8578. function createSetupContext(instance) {
  8579. const expose = exposed => {
  8580. if (instance.exposed) {
  8581. warn$1(`expose() should be called only once per setup().`);
  8582. }
  8583. instance.exposed = exposed || {};
  8584. };
  8585. let attrs;
  8586. {
  8587. // We use getters in dev in case libs like test-utils overwrite instance
  8588. // properties (overwrites should not be done in prod)
  8589. return Object.freeze({
  8590. get attrs() {
  8591. return attrs || (attrs = createAttrsProxy(instance));
  8592. },
  8593. get slots() {
  8594. return shallowReadonly(instance.slots);
  8595. },
  8596. get emit() {
  8597. return (event, ...args) => instance.emit(event, ...args);
  8598. },
  8599. expose
  8600. });
  8601. }
  8602. }
  8603. function getExposeProxy(instance) {
  8604. if (instance.exposed) {
  8605. return (instance.exposeProxy ||
  8606. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8607. get(target, key) {
  8608. if (key in target) {
  8609. return target[key];
  8610. }
  8611. else if (key in publicPropertiesMap) {
  8612. return publicPropertiesMap[key](instance);
  8613. }
  8614. }
  8615. })));
  8616. }
  8617. }
  8618. const classifyRE = /(?:^|[-_])(\w)/g;
  8619. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8620. function getComponentName(Component) {
  8621. return isFunction(Component)
  8622. ? Component.displayName || Component.name
  8623. : Component.name;
  8624. }
  8625. /* istanbul ignore next */
  8626. function formatComponentName(instance, Component, isRoot = false) {
  8627. let name = getComponentName(Component);
  8628. if (!name && Component.__file) {
  8629. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8630. if (match) {
  8631. name = match[1];
  8632. }
  8633. }
  8634. if (!name && instance && instance.parent) {
  8635. // try to infer the name based on reverse resolution
  8636. const inferFromRegistry = (registry) => {
  8637. for (const key in registry) {
  8638. if (registry[key] === Component) {
  8639. return key;
  8640. }
  8641. }
  8642. };
  8643. name =
  8644. inferFromRegistry(instance.components ||
  8645. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8646. }
  8647. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8648. }
  8649. function isClassComponent(value) {
  8650. return isFunction(value) && '__vccOpts' in value;
  8651. }
  8652. const computed$1 = ((getterOrOptions, debugOptions) => {
  8653. // @ts-ignore
  8654. return computed(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8655. });
  8656. // dev only
  8657. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8658. `<script setup> of a single file component. Its arguments should be ` +
  8659. `compiled away and passing it at runtime has no effect.`);
  8660. // implementation
  8661. function defineProps() {
  8662. {
  8663. warnRuntimeUsage(`defineProps`);
  8664. }
  8665. return null;
  8666. }
  8667. // implementation
  8668. function defineEmits() {
  8669. {
  8670. warnRuntimeUsage(`defineEmits`);
  8671. }
  8672. return null;
  8673. }
  8674. /**
  8675. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8676. * instance properties when it is accessed by a parent component via template
  8677. * refs.
  8678. *
  8679. * `<script setup>` components are closed by default - i.e. variables inside
  8680. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8681. * via `defineExpose`.
  8682. *
  8683. * This is only usable inside `<script setup>`, is compiled away in the
  8684. * output and should **not** be actually called at runtime.
  8685. */
  8686. function defineExpose(exposed) {
  8687. {
  8688. warnRuntimeUsage(`defineExpose`);
  8689. }
  8690. }
  8691. /**
  8692. * Vue `<script setup>` compiler macro for providing props default values when
  8693. * using type-based `defineProps` declaration.
  8694. *
  8695. * Example usage:
  8696. * ```ts
  8697. * withDefaults(defineProps<{
  8698. * size?: number
  8699. * labels?: string[]
  8700. * }>(), {
  8701. * size: 3,
  8702. * labels: () => ['default label']
  8703. * })
  8704. * ```
  8705. *
  8706. * This is only usable inside `<script setup>`, is compiled away in the output
  8707. * and should **not** be actually called at runtime.
  8708. */
  8709. function withDefaults(props, defaults) {
  8710. {
  8711. warnRuntimeUsage(`withDefaults`);
  8712. }
  8713. return null;
  8714. }
  8715. function useSlots() {
  8716. return getContext().slots;
  8717. }
  8718. function useAttrs() {
  8719. return getContext().attrs;
  8720. }
  8721. function getContext() {
  8722. const i = getCurrentInstance();
  8723. if (!i) {
  8724. warn$1(`useContext() called without active instance.`);
  8725. }
  8726. return i.setupContext || (i.setupContext = createSetupContext(i));
  8727. }
  8728. /**
  8729. * Runtime helper for merging default declarations. Imported by compiled code
  8730. * only.
  8731. * @internal
  8732. */
  8733. function mergeDefaults(raw, defaults) {
  8734. const props = isArray(raw)
  8735. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8736. : raw;
  8737. for (const key in defaults) {
  8738. const opt = props[key];
  8739. if (opt) {
  8740. if (isArray(opt) || isFunction(opt)) {
  8741. props[key] = { type: opt, default: defaults[key] };
  8742. }
  8743. else {
  8744. opt.default = defaults[key];
  8745. }
  8746. }
  8747. else if (opt === null) {
  8748. props[key] = { default: defaults[key] };
  8749. }
  8750. else {
  8751. warn$1(`props default key "${key}" has no corresponding declaration.`);
  8752. }
  8753. }
  8754. return props;
  8755. }
  8756. /**
  8757. * Used to create a proxy for the rest element when destructuring props with
  8758. * defineProps().
  8759. * @internal
  8760. */
  8761. function createPropsRestProxy(props, excludedKeys) {
  8762. const ret = {};
  8763. for (const key in props) {
  8764. if (!excludedKeys.includes(key)) {
  8765. Object.defineProperty(ret, key, {
  8766. enumerable: true,
  8767. get: () => props[key]
  8768. });
  8769. }
  8770. }
  8771. return ret;
  8772. }
  8773. /**
  8774. * `<script setup>` helper for persisting the current instance context over
  8775. * async/await flows.
  8776. *
  8777. * `@vue/compiler-sfc` converts the following:
  8778. *
  8779. * ```ts
  8780. * const x = await foo()
  8781. * ```
  8782. *
  8783. * into:
  8784. *
  8785. * ```ts
  8786. * let __temp, __restore
  8787. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8788. * ```
  8789. * @internal
  8790. */
  8791. function withAsyncContext(getAwaitable) {
  8792. const ctx = getCurrentInstance();
  8793. if (!ctx) {
  8794. warn$1(`withAsyncContext called without active current instance. ` +
  8795. `This is likely a bug.`);
  8796. }
  8797. let awaitable = getAwaitable();
  8798. unsetCurrentInstance();
  8799. if (isPromise(awaitable)) {
  8800. awaitable = awaitable.catch(e => {
  8801. setCurrentInstance(ctx);
  8802. throw e;
  8803. });
  8804. }
  8805. return [awaitable, () => setCurrentInstance(ctx)];
  8806. }
  8807. // Actual implementation
  8808. function h(type, propsOrChildren, children) {
  8809. const l = arguments.length;
  8810. if (l === 2) {
  8811. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  8812. // single vnode without props
  8813. if (isVNode(propsOrChildren)) {
  8814. return createVNode(type, null, [propsOrChildren]);
  8815. }
  8816. // props without children
  8817. return createVNode(type, propsOrChildren);
  8818. }
  8819. else {
  8820. // omit props
  8821. return createVNode(type, null, propsOrChildren);
  8822. }
  8823. }
  8824. else {
  8825. if (l > 3) {
  8826. children = Array.prototype.slice.call(arguments, 2);
  8827. }
  8828. else if (l === 3 && isVNode(children)) {
  8829. children = [children];
  8830. }
  8831. return createVNode(type, propsOrChildren, children);
  8832. }
  8833. }
  8834. const ssrContextKey = Symbol(`ssrContext` );
  8835. const useSSRContext = () => {
  8836. {
  8837. warn$1(`useSSRContext() is not supported in the global build.`);
  8838. }
  8839. };
  8840. function initCustomFormatter() {
  8841. /* eslint-disable no-restricted-globals */
  8842. if (typeof window === 'undefined') {
  8843. return;
  8844. }
  8845. const vueStyle = { style: 'color:#3ba776' };
  8846. const numberStyle = { style: 'color:#0b1bc9' };
  8847. const stringStyle = { style: 'color:#b62e24' };
  8848. const keywordStyle = { style: 'color:#9d288c' };
  8849. // custom formatter for Chrome
  8850. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  8851. const formatter = {
  8852. header(obj) {
  8853. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  8854. if (!isObject(obj)) {
  8855. return null;
  8856. }
  8857. if (obj.__isVue) {
  8858. return ['div', vueStyle, `VueInstance`];
  8859. }
  8860. else if (isRef(obj)) {
  8861. return [
  8862. 'div',
  8863. {},
  8864. ['span', vueStyle, genRefFlag(obj)],
  8865. '<',
  8866. formatValue(obj.value),
  8867. `>`
  8868. ];
  8869. }
  8870. else if (isReactive(obj)) {
  8871. return [
  8872. 'div',
  8873. {},
  8874. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  8875. '<',
  8876. formatValue(obj),
  8877. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  8878. ];
  8879. }
  8880. else if (isReadonly(obj)) {
  8881. return [
  8882. 'div',
  8883. {},
  8884. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  8885. '<',
  8886. formatValue(obj),
  8887. '>'
  8888. ];
  8889. }
  8890. return null;
  8891. },
  8892. hasBody(obj) {
  8893. return obj && obj.__isVue;
  8894. },
  8895. body(obj) {
  8896. if (obj && obj.__isVue) {
  8897. return [
  8898. 'div',
  8899. {},
  8900. ...formatInstance(obj.$)
  8901. ];
  8902. }
  8903. }
  8904. };
  8905. function formatInstance(instance) {
  8906. const blocks = [];
  8907. if (instance.type.props && instance.props) {
  8908. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  8909. }
  8910. if (instance.setupState !== EMPTY_OBJ) {
  8911. blocks.push(createInstanceBlock('setup', instance.setupState));
  8912. }
  8913. if (instance.data !== EMPTY_OBJ) {
  8914. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  8915. }
  8916. const computed = extractKeys(instance, 'computed');
  8917. if (computed) {
  8918. blocks.push(createInstanceBlock('computed', computed));
  8919. }
  8920. const injected = extractKeys(instance, 'inject');
  8921. if (injected) {
  8922. blocks.push(createInstanceBlock('injected', injected));
  8923. }
  8924. blocks.push([
  8925. 'div',
  8926. {},
  8927. [
  8928. 'span',
  8929. {
  8930. style: keywordStyle.style + ';opacity:0.66'
  8931. },
  8932. '$ (internal): '
  8933. ],
  8934. ['object', { object: instance }]
  8935. ]);
  8936. return blocks;
  8937. }
  8938. function createInstanceBlock(type, target) {
  8939. target = extend({}, target);
  8940. if (!Object.keys(target).length) {
  8941. return ['span', {}];
  8942. }
  8943. return [
  8944. 'div',
  8945. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  8946. [
  8947. 'div',
  8948. {
  8949. style: 'color:#476582'
  8950. },
  8951. type
  8952. ],
  8953. [
  8954. 'div',
  8955. {
  8956. style: 'padding-left:1.25em'
  8957. },
  8958. ...Object.keys(target).map(key => {
  8959. return [
  8960. 'div',
  8961. {},
  8962. ['span', keywordStyle, key + ': '],
  8963. formatValue(target[key], false)
  8964. ];
  8965. })
  8966. ]
  8967. ];
  8968. }
  8969. function formatValue(v, asRaw = true) {
  8970. if (typeof v === 'number') {
  8971. return ['span', numberStyle, v];
  8972. }
  8973. else if (typeof v === 'string') {
  8974. return ['span', stringStyle, JSON.stringify(v)];
  8975. }
  8976. else if (typeof v === 'boolean') {
  8977. return ['span', keywordStyle, v];
  8978. }
  8979. else if (isObject(v)) {
  8980. return ['object', { object: asRaw ? toRaw(v) : v }];
  8981. }
  8982. else {
  8983. return ['span', stringStyle, String(v)];
  8984. }
  8985. }
  8986. function extractKeys(instance, type) {
  8987. const Comp = instance.type;
  8988. if (isFunction(Comp)) {
  8989. return;
  8990. }
  8991. const extracted = {};
  8992. for (const key in instance.ctx) {
  8993. if (isKeyOfType(Comp, key, type)) {
  8994. extracted[key] = instance.ctx[key];
  8995. }
  8996. }
  8997. return extracted;
  8998. }
  8999. function isKeyOfType(Comp, key, type) {
  9000. const opts = Comp[type];
  9001. if ((isArray(opts) && opts.includes(key)) ||
  9002. (isObject(opts) && key in opts)) {
  9003. return true;
  9004. }
  9005. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9006. return true;
  9007. }
  9008. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9009. return true;
  9010. }
  9011. }
  9012. function genRefFlag(v) {
  9013. if (isShallow(v)) {
  9014. return `ShallowRef`;
  9015. }
  9016. if (v.effect) {
  9017. return `ComputedRef`;
  9018. }
  9019. return `Ref`;
  9020. }
  9021. if (window.devtoolsFormatters) {
  9022. window.devtoolsFormatters.push(formatter);
  9023. }
  9024. else {
  9025. window.devtoolsFormatters = [formatter];
  9026. }
  9027. }
  9028. function withMemo(memo, render, cache, index) {
  9029. const cached = cache[index];
  9030. if (cached && isMemoSame(cached, memo)) {
  9031. return cached;
  9032. }
  9033. const ret = render();
  9034. // shallow clone
  9035. ret.memo = memo.slice();
  9036. return (cache[index] = ret);
  9037. }
  9038. function isMemoSame(cached, memo) {
  9039. const prev = cached.memo;
  9040. if (prev.length != memo.length) {
  9041. return false;
  9042. }
  9043. for (let i = 0; i < prev.length; i++) {
  9044. if (prev[i] !== memo[i]) {
  9045. return false;
  9046. }
  9047. }
  9048. // make sure to let parent block track it when returning cached
  9049. if (isBlockTreeEnabled > 0 && currentBlock) {
  9050. currentBlock.push(cached);
  9051. }
  9052. return true;
  9053. }
  9054. // Core API ------------------------------------------------------------------
  9055. const version = "3.2.31";
  9056. /**
  9057. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  9058. * @internal
  9059. */
  9060. const ssrUtils = (null);
  9061. /**
  9062. * @internal only exposed in compat builds
  9063. */
  9064. const resolveFilter = null;
  9065. /**
  9066. * @internal only exposed in compat builds.
  9067. */
  9068. const compatUtils = (null);
  9069. const svgNS = 'http://www.w3.org/2000/svg';
  9070. const doc = (typeof document !== 'undefined' ? document : null);
  9071. const templateContainer = doc && doc.createElement('template');
  9072. const nodeOps = {
  9073. insert: (child, parent, anchor) => {
  9074. parent.insertBefore(child, anchor || null);
  9075. },
  9076. remove: child => {
  9077. const parent = child.parentNode;
  9078. if (parent) {
  9079. parent.removeChild(child);
  9080. }
  9081. },
  9082. createElement: (tag, isSVG, is, props) => {
  9083. const el = isSVG
  9084. ? doc.createElementNS(svgNS, tag)
  9085. : doc.createElement(tag, is ? { is } : undefined);
  9086. if (tag === 'select' && props && props.multiple != null) {
  9087. el.setAttribute('multiple', props.multiple);
  9088. }
  9089. return el;
  9090. },
  9091. createText: text => doc.createTextNode(text),
  9092. createComment: text => doc.createComment(text),
  9093. setText: (node, text) => {
  9094. node.nodeValue = text;
  9095. },
  9096. setElementText: (el, text) => {
  9097. el.textContent = text;
  9098. },
  9099. parentNode: node => node.parentNode,
  9100. nextSibling: node => node.nextSibling,
  9101. querySelector: selector => doc.querySelector(selector),
  9102. setScopeId(el, id) {
  9103. el.setAttribute(id, '');
  9104. },
  9105. cloneNode(el) {
  9106. const cloned = el.cloneNode(true);
  9107. // #3072
  9108. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  9109. // - normally, elements using `:value` bindings will not be hoisted, but if
  9110. // the bound value is a constant, e.g. `:value="true"` - they do get
  9111. // hoisted.
  9112. // - in production, hoisted nodes are cloned when subsequent inserts, but
  9113. // cloneNode() does not copy the custom property we attached.
  9114. // - This may need to account for other custom DOM properties we attach to
  9115. // elements in addition to `_value` in the future.
  9116. if (`_value` in el) {
  9117. cloned._value = el._value;
  9118. }
  9119. return cloned;
  9120. },
  9121. // __UNSAFE__
  9122. // Reason: innerHTML.
  9123. // Static content here can only come from compiled templates.
  9124. // As long as the user only uses trusted templates, this is safe.
  9125. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9126. // <parent> before | first ... last | anchor </parent>
  9127. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9128. // #5308 can only take cached path if:
  9129. // - has a single root node
  9130. // - nextSibling info is still available
  9131. if (start && (start === end || start.nextSibling)) {
  9132. // cached
  9133. while (true) {
  9134. parent.insertBefore(start.cloneNode(true), anchor);
  9135. if (start === end || !(start = start.nextSibling))
  9136. break;
  9137. }
  9138. }
  9139. else {
  9140. // fresh insert
  9141. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9142. const template = templateContainer.content;
  9143. if (isSVG) {
  9144. // remove outer svg wrapper
  9145. const wrapper = template.firstChild;
  9146. while (wrapper.firstChild) {
  9147. template.appendChild(wrapper.firstChild);
  9148. }
  9149. template.removeChild(wrapper);
  9150. }
  9151. parent.insertBefore(template, anchor);
  9152. }
  9153. return [
  9154. // first
  9155. before ? before.nextSibling : parent.firstChild,
  9156. // last
  9157. anchor ? anchor.previousSibling : parent.lastChild
  9158. ];
  9159. }
  9160. };
  9161. // compiler should normalize class + :class bindings on the same element
  9162. // into a single binding ['staticClass', dynamic]
  9163. function patchClass(el, value, isSVG) {
  9164. // directly setting className should be faster than setAttribute in theory
  9165. // if this is an element during a transition, take the temporary transition
  9166. // classes into account.
  9167. const transitionClasses = el._vtc;
  9168. if (transitionClasses) {
  9169. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9170. }
  9171. if (value == null) {
  9172. el.removeAttribute('class');
  9173. }
  9174. else if (isSVG) {
  9175. el.setAttribute('class', value);
  9176. }
  9177. else {
  9178. el.className = value;
  9179. }
  9180. }
  9181. function patchStyle(el, prev, next) {
  9182. const style = el.style;
  9183. const isCssString = isString(next);
  9184. if (next && !isCssString) {
  9185. for (const key in next) {
  9186. setStyle(style, key, next[key]);
  9187. }
  9188. if (prev && !isString(prev)) {
  9189. for (const key in prev) {
  9190. if (next[key] == null) {
  9191. setStyle(style, key, '');
  9192. }
  9193. }
  9194. }
  9195. }
  9196. else {
  9197. const currentDisplay = style.display;
  9198. if (isCssString) {
  9199. if (prev !== next) {
  9200. style.cssText = next;
  9201. }
  9202. }
  9203. else if (prev) {
  9204. el.removeAttribute('style');
  9205. }
  9206. // indicates that the `display` of the element is controlled by `v-show`,
  9207. // so we always keep the current `display` value regardless of the `style`
  9208. // value, thus handing over control to `v-show`.
  9209. if ('_vod' in el) {
  9210. style.display = currentDisplay;
  9211. }
  9212. }
  9213. }
  9214. const importantRE = /\s*!important$/;
  9215. function setStyle(style, name, val) {
  9216. if (isArray(val)) {
  9217. val.forEach(v => setStyle(style, name, v));
  9218. }
  9219. else {
  9220. if (name.startsWith('--')) {
  9221. // custom property definition
  9222. style.setProperty(name, val);
  9223. }
  9224. else {
  9225. const prefixed = autoPrefix(style, name);
  9226. if (importantRE.test(val)) {
  9227. // !important
  9228. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9229. }
  9230. else {
  9231. style[prefixed] = val;
  9232. }
  9233. }
  9234. }
  9235. }
  9236. const prefixes = ['Webkit', 'Moz', 'ms'];
  9237. const prefixCache = {};
  9238. function autoPrefix(style, rawName) {
  9239. const cached = prefixCache[rawName];
  9240. if (cached) {
  9241. return cached;
  9242. }
  9243. let name = camelize(rawName);
  9244. if (name !== 'filter' && name in style) {
  9245. return (prefixCache[rawName] = name);
  9246. }
  9247. name = capitalize(name);
  9248. for (let i = 0; i < prefixes.length; i++) {
  9249. const prefixed = prefixes[i] + name;
  9250. if (prefixed in style) {
  9251. return (prefixCache[rawName] = prefixed);
  9252. }
  9253. }
  9254. return rawName;
  9255. }
  9256. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9257. function patchAttr(el, key, value, isSVG, instance) {
  9258. if (isSVG && key.startsWith('xlink:')) {
  9259. if (value == null) {
  9260. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9261. }
  9262. else {
  9263. el.setAttributeNS(xlinkNS, key, value);
  9264. }
  9265. }
  9266. else {
  9267. // note we are only checking boolean attributes that don't have a
  9268. // corresponding dom prop of the same name here.
  9269. const isBoolean = isSpecialBooleanAttr(key);
  9270. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9271. el.removeAttribute(key);
  9272. }
  9273. else {
  9274. el.setAttribute(key, isBoolean ? '' : value);
  9275. }
  9276. }
  9277. }
  9278. // __UNSAFE__
  9279. // functions. The user is responsible for using them with only trusted content.
  9280. function patchDOMProp(el, key, value,
  9281. // the following args are passed only due to potential innerHTML/textContent
  9282. // overriding existing VNodes, in which case the old tree must be properly
  9283. // unmounted.
  9284. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9285. if (key === 'innerHTML' || key === 'textContent') {
  9286. if (prevChildren) {
  9287. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9288. }
  9289. el[key] = value == null ? '' : value;
  9290. return;
  9291. }
  9292. if (key === 'value' &&
  9293. el.tagName !== 'PROGRESS' &&
  9294. // custom elements may use _value internally
  9295. !el.tagName.includes('-')) {
  9296. // store value as _value as well since
  9297. // non-string values will be stringified.
  9298. el._value = value;
  9299. const newValue = value == null ? '' : value;
  9300. if (el.value !== newValue ||
  9301. // #4956: always set for OPTION elements because its value falls back to
  9302. // textContent if no value attribute is present. And setting .value for
  9303. // OPTION has no side effect
  9304. el.tagName === 'OPTION') {
  9305. el.value = newValue;
  9306. }
  9307. if (value == null) {
  9308. el.removeAttribute(key);
  9309. }
  9310. return;
  9311. }
  9312. if (value === '' || value == null) {
  9313. const type = typeof el[key];
  9314. if (type === 'boolean') {
  9315. // e.g. <select multiple> compiles to { multiple: '' }
  9316. el[key] = includeBooleanAttr(value);
  9317. return;
  9318. }
  9319. else if (value == null && type === 'string') {
  9320. // e.g. <div :id="null">
  9321. el[key] = '';
  9322. el.removeAttribute(key);
  9323. return;
  9324. }
  9325. else if (type === 'number') {
  9326. // e.g. <img :width="null">
  9327. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  9328. try {
  9329. el[key] = 0;
  9330. }
  9331. catch (_a) { }
  9332. el.removeAttribute(key);
  9333. return;
  9334. }
  9335. }
  9336. // some properties perform value validation and throw
  9337. try {
  9338. el[key] = value;
  9339. }
  9340. catch (e) {
  9341. {
  9342. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9343. `value ${value} is invalid.`, e);
  9344. }
  9345. }
  9346. }
  9347. // Async edge case fix requires storing an event listener's attach timestamp.
  9348. let _getNow = Date.now;
  9349. let skipTimestampCheck = false;
  9350. if (typeof window !== 'undefined') {
  9351. // Determine what event timestamp the browser is using. Annoyingly, the
  9352. // timestamp can either be hi-res (relative to page load) or low-res
  9353. // (relative to UNIX epoch), so in order to compare time we have to use the
  9354. // same timestamp type when saving the flush timestamp.
  9355. if (_getNow() > document.createEvent('Event').timeStamp) {
  9356. // if the low-res timestamp which is bigger than the event timestamp
  9357. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  9358. // and we need to use the hi-res version for event listeners as well.
  9359. _getNow = () => performance.now();
  9360. }
  9361. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  9362. // and does not fire microtasks in between event propagation, so safe to exclude.
  9363. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  9364. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  9365. }
  9366. // To avoid the overhead of repeatedly calling performance.now(), we cache
  9367. // and use the same timestamp for all event listeners attached in the same tick.
  9368. let cachedNow = 0;
  9369. const p = Promise.resolve();
  9370. const reset = () => {
  9371. cachedNow = 0;
  9372. };
  9373. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  9374. function addEventListener(el, event, handler, options) {
  9375. el.addEventListener(event, handler, options);
  9376. }
  9377. function removeEventListener(el, event, handler, options) {
  9378. el.removeEventListener(event, handler, options);
  9379. }
  9380. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9381. // vei = vue event invokers
  9382. const invokers = el._vei || (el._vei = {});
  9383. const existingInvoker = invokers[rawName];
  9384. if (nextValue && existingInvoker) {
  9385. // patch
  9386. existingInvoker.value = nextValue;
  9387. }
  9388. else {
  9389. const [name, options] = parseName(rawName);
  9390. if (nextValue) {
  9391. // add
  9392. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9393. addEventListener(el, name, invoker, options);
  9394. }
  9395. else if (existingInvoker) {
  9396. // remove
  9397. removeEventListener(el, name, existingInvoker, options);
  9398. invokers[rawName] = undefined;
  9399. }
  9400. }
  9401. }
  9402. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9403. function parseName(name) {
  9404. let options;
  9405. if (optionsModifierRE.test(name)) {
  9406. options = {};
  9407. let m;
  9408. while ((m = name.match(optionsModifierRE))) {
  9409. name = name.slice(0, name.length - m[0].length);
  9410. options[m[0].toLowerCase()] = true;
  9411. }
  9412. }
  9413. return [hyphenate(name.slice(2)), options];
  9414. }
  9415. function createInvoker(initialValue, instance) {
  9416. const invoker = (e) => {
  9417. // async edge case #6566: inner click event triggers patch, event handler
  9418. // attached to outer element during patch, and triggered again. This
  9419. // happens because browsers fire microtask ticks between event propagation.
  9420. // the solution is simple: we save the timestamp when a handler is attached,
  9421. // and the handler would only fire if the event passed to it was fired
  9422. // AFTER it was attached.
  9423. const timeStamp = e.timeStamp || _getNow();
  9424. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  9425. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  9426. }
  9427. };
  9428. invoker.value = initialValue;
  9429. invoker.attached = getNow();
  9430. return invoker;
  9431. }
  9432. function patchStopImmediatePropagation(e, value) {
  9433. if (isArray(value)) {
  9434. const originalStop = e.stopImmediatePropagation;
  9435. e.stopImmediatePropagation = () => {
  9436. originalStop.call(e);
  9437. e._stopped = true;
  9438. };
  9439. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9440. }
  9441. else {
  9442. return value;
  9443. }
  9444. }
  9445. const nativeOnRE = /^on[a-z]/;
  9446. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9447. if (key === 'class') {
  9448. patchClass(el, nextValue, isSVG);
  9449. }
  9450. else if (key === 'style') {
  9451. patchStyle(el, prevValue, nextValue);
  9452. }
  9453. else if (isOn(key)) {
  9454. // ignore v-model listeners
  9455. if (!isModelListener(key)) {
  9456. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9457. }
  9458. }
  9459. else if (key[0] === '.'
  9460. ? ((key = key.slice(1)), true)
  9461. : key[0] === '^'
  9462. ? ((key = key.slice(1)), false)
  9463. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9464. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9465. }
  9466. else {
  9467. // special case for <input v-model type="checkbox"> with
  9468. // :true-value & :false-value
  9469. // store value as dom properties since non-string values will be
  9470. // stringified.
  9471. if (key === 'true-value') {
  9472. el._trueValue = nextValue;
  9473. }
  9474. else if (key === 'false-value') {
  9475. el._falseValue = nextValue;
  9476. }
  9477. patchAttr(el, key, nextValue, isSVG);
  9478. }
  9479. };
  9480. function shouldSetAsProp(el, key, value, isSVG) {
  9481. if (isSVG) {
  9482. // most keys must be set as attribute on svg elements to work
  9483. // ...except innerHTML & textContent
  9484. if (key === 'innerHTML' || key === 'textContent') {
  9485. return true;
  9486. }
  9487. // or native onclick with function values
  9488. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9489. return true;
  9490. }
  9491. return false;
  9492. }
  9493. // spellcheck and draggable are numerated attrs, however their
  9494. // corresponding DOM properties are actually booleans - this leads to
  9495. // setting it with a string "false" value leading it to be coerced to
  9496. // `true`, so we need to always treat them as attributes.
  9497. // Note that `contentEditable` doesn't have this problem: its DOM
  9498. // property is also enumerated string values.
  9499. if (key === 'spellcheck' || key === 'draggable') {
  9500. return false;
  9501. }
  9502. // #1787, #2840 form property on form elements is readonly and must be set as
  9503. // attribute.
  9504. if (key === 'form') {
  9505. return false;
  9506. }
  9507. // #1526 <input list> must be set as attribute
  9508. if (key === 'list' && el.tagName === 'INPUT') {
  9509. return false;
  9510. }
  9511. // #2766 <textarea type> must be set as attribute
  9512. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9513. return false;
  9514. }
  9515. // native onclick with string value, must be set as attribute
  9516. if (nativeOnRE.test(key) && isString(value)) {
  9517. return false;
  9518. }
  9519. return key in el;
  9520. }
  9521. function defineCustomElement(options, hydate) {
  9522. const Comp = defineComponent(options);
  9523. class VueCustomElement extends VueElement {
  9524. constructor(initialProps) {
  9525. super(Comp, initialProps, hydate);
  9526. }
  9527. }
  9528. VueCustomElement.def = Comp;
  9529. return VueCustomElement;
  9530. }
  9531. const defineSSRCustomElement = ((options) => {
  9532. // @ts-ignore
  9533. return defineCustomElement(options, hydrate);
  9534. });
  9535. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9536. });
  9537. class VueElement extends BaseClass {
  9538. constructor(_def, _props = {}, hydrate) {
  9539. super();
  9540. this._def = _def;
  9541. this._props = _props;
  9542. /**
  9543. * @internal
  9544. */
  9545. this._instance = null;
  9546. this._connected = false;
  9547. this._resolved = false;
  9548. this._numberProps = null;
  9549. if (this.shadowRoot && hydrate) {
  9550. hydrate(this._createVNode(), this.shadowRoot);
  9551. }
  9552. else {
  9553. if (this.shadowRoot) {
  9554. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9555. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9556. }
  9557. this.attachShadow({ mode: 'open' });
  9558. }
  9559. }
  9560. connectedCallback() {
  9561. this._connected = true;
  9562. if (!this._instance) {
  9563. this._resolveDef();
  9564. }
  9565. }
  9566. disconnectedCallback() {
  9567. this._connected = false;
  9568. nextTick(() => {
  9569. if (!this._connected) {
  9570. render(null, this.shadowRoot);
  9571. this._instance = null;
  9572. }
  9573. });
  9574. }
  9575. /**
  9576. * resolve inner component definition (handle possible async component)
  9577. */
  9578. _resolveDef() {
  9579. if (this._resolved) {
  9580. return;
  9581. }
  9582. this._resolved = true;
  9583. // set initial attrs
  9584. for (let i = 0; i < this.attributes.length; i++) {
  9585. this._setAttr(this.attributes[i].name);
  9586. }
  9587. // watch future attr changes
  9588. new MutationObserver(mutations => {
  9589. for (const m of mutations) {
  9590. this._setAttr(m.attributeName);
  9591. }
  9592. }).observe(this, { attributes: true });
  9593. const resolve = (def) => {
  9594. const { props, styles } = def;
  9595. const hasOptions = !isArray(props);
  9596. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  9597. // cast Number-type props set before resolve
  9598. let numberProps;
  9599. if (hasOptions) {
  9600. for (const key in this._props) {
  9601. const opt = props[key];
  9602. if (opt === Number || (opt && opt.type === Number)) {
  9603. this._props[key] = toNumber(this._props[key]);
  9604. (numberProps || (numberProps = Object.create(null)))[key] = true;
  9605. }
  9606. }
  9607. }
  9608. this._numberProps = numberProps;
  9609. // check if there are props set pre-upgrade or connect
  9610. for (const key of Object.keys(this)) {
  9611. if (key[0] !== '_') {
  9612. this._setProp(key, this[key], true, false);
  9613. }
  9614. }
  9615. // defining getter/setters on prototype
  9616. for (const key of rawKeys.map(camelize)) {
  9617. Object.defineProperty(this, key, {
  9618. get() {
  9619. return this._getProp(key);
  9620. },
  9621. set(val) {
  9622. this._setProp(key, val);
  9623. }
  9624. });
  9625. }
  9626. // apply CSS
  9627. this._applyStyles(styles);
  9628. // initial render
  9629. this._update();
  9630. };
  9631. const asyncDef = this._def.__asyncLoader;
  9632. if (asyncDef) {
  9633. asyncDef().then(resolve);
  9634. }
  9635. else {
  9636. resolve(this._def);
  9637. }
  9638. }
  9639. _setAttr(key) {
  9640. let value = this.getAttribute(key);
  9641. if (this._numberProps && this._numberProps[key]) {
  9642. value = toNumber(value);
  9643. }
  9644. this._setProp(camelize(key), value, false);
  9645. }
  9646. /**
  9647. * @internal
  9648. */
  9649. _getProp(key) {
  9650. return this._props[key];
  9651. }
  9652. /**
  9653. * @internal
  9654. */
  9655. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9656. if (val !== this._props[key]) {
  9657. this._props[key] = val;
  9658. if (shouldUpdate && this._instance) {
  9659. this._update();
  9660. }
  9661. // reflect
  9662. if (shouldReflect) {
  9663. if (val === true) {
  9664. this.setAttribute(hyphenate(key), '');
  9665. }
  9666. else if (typeof val === 'string' || typeof val === 'number') {
  9667. this.setAttribute(hyphenate(key), val + '');
  9668. }
  9669. else if (!val) {
  9670. this.removeAttribute(hyphenate(key));
  9671. }
  9672. }
  9673. }
  9674. }
  9675. _update() {
  9676. render(this._createVNode(), this.shadowRoot);
  9677. }
  9678. _createVNode() {
  9679. const vnode = createVNode(this._def, extend({}, this._props));
  9680. if (!this._instance) {
  9681. vnode.ce = instance => {
  9682. this._instance = instance;
  9683. instance.isCE = true;
  9684. // HMR
  9685. {
  9686. instance.ceReload = newStyles => {
  9687. // always reset styles
  9688. if (this._styles) {
  9689. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9690. this._styles.length = 0;
  9691. }
  9692. this._applyStyles(newStyles);
  9693. // if this is an async component, ceReload is called from the inner
  9694. // component so no need to reload the async wrapper
  9695. if (!this._def.__asyncLoader) {
  9696. // reload
  9697. this._instance = null;
  9698. this._update();
  9699. }
  9700. };
  9701. }
  9702. // intercept emit
  9703. instance.emit = (event, ...args) => {
  9704. this.dispatchEvent(new CustomEvent(event, {
  9705. detail: args
  9706. }));
  9707. };
  9708. // locate nearest Vue custom element parent for provide/inject
  9709. let parent = this;
  9710. while ((parent =
  9711. parent && (parent.parentNode || parent.host))) {
  9712. if (parent instanceof VueElement) {
  9713. instance.parent = parent._instance;
  9714. break;
  9715. }
  9716. }
  9717. };
  9718. }
  9719. return vnode;
  9720. }
  9721. _applyStyles(styles) {
  9722. if (styles) {
  9723. styles.forEach(css => {
  9724. const s = document.createElement('style');
  9725. s.textContent = css;
  9726. this.shadowRoot.appendChild(s);
  9727. // record for HMR
  9728. {
  9729. (this._styles || (this._styles = [])).push(s);
  9730. }
  9731. });
  9732. }
  9733. }
  9734. }
  9735. function useCssModule(name = '$style') {
  9736. /* istanbul ignore else */
  9737. {
  9738. {
  9739. warn$1(`useCssModule() is not supported in the global build.`);
  9740. }
  9741. return EMPTY_OBJ;
  9742. }
  9743. }
  9744. /**
  9745. * Runtime helper for SFC's CSS variable injection feature.
  9746. * @private
  9747. */
  9748. function useCssVars(getter) {
  9749. const instance = getCurrentInstance();
  9750. /* istanbul ignore next */
  9751. if (!instance) {
  9752. warn$1(`useCssVars is called without current active component instance.`);
  9753. return;
  9754. }
  9755. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  9756. watchPostEffect(setVars);
  9757. onMounted(() => {
  9758. const ob = new MutationObserver(setVars);
  9759. ob.observe(instance.subTree.el.parentNode, { childList: true });
  9760. onUnmounted(() => ob.disconnect());
  9761. });
  9762. }
  9763. function setVarsOnVNode(vnode, vars) {
  9764. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  9765. const suspense = vnode.suspense;
  9766. vnode = suspense.activeBranch;
  9767. if (suspense.pendingBranch && !suspense.isHydrating) {
  9768. suspense.effects.push(() => {
  9769. setVarsOnVNode(suspense.activeBranch, vars);
  9770. });
  9771. }
  9772. }
  9773. // drill down HOCs until it's a non-component vnode
  9774. while (vnode.component) {
  9775. vnode = vnode.component.subTree;
  9776. }
  9777. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  9778. setVarsOnNode(vnode.el, vars);
  9779. }
  9780. else if (vnode.type === Fragment) {
  9781. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  9782. }
  9783. else if (vnode.type === Static) {
  9784. let { el, anchor } = vnode;
  9785. while (el) {
  9786. setVarsOnNode(el, vars);
  9787. if (el === anchor)
  9788. break;
  9789. el = el.nextSibling;
  9790. }
  9791. }
  9792. }
  9793. function setVarsOnNode(el, vars) {
  9794. if (el.nodeType === 1) {
  9795. const style = el.style;
  9796. for (const key in vars) {
  9797. style.setProperty(`--${key}`, vars[key]);
  9798. }
  9799. }
  9800. }
  9801. const TRANSITION = 'transition';
  9802. const ANIMATION = 'animation';
  9803. // DOM Transition is a higher-order-component based on the platform-agnostic
  9804. // base Transition component, with DOM-specific logic.
  9805. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  9806. Transition.displayName = 'Transition';
  9807. const DOMTransitionPropsValidators = {
  9808. name: String,
  9809. type: String,
  9810. css: {
  9811. type: Boolean,
  9812. default: true
  9813. },
  9814. duration: [String, Number, Object],
  9815. enterFromClass: String,
  9816. enterActiveClass: String,
  9817. enterToClass: String,
  9818. appearFromClass: String,
  9819. appearActiveClass: String,
  9820. appearToClass: String,
  9821. leaveFromClass: String,
  9822. leaveActiveClass: String,
  9823. leaveToClass: String
  9824. };
  9825. const TransitionPropsValidators = (Transition.props =
  9826. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  9827. /**
  9828. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  9829. * with custom HOCs.
  9830. */
  9831. const callHook$1 = (hook, args = []) => {
  9832. if (isArray(hook)) {
  9833. hook.forEach(h => h(...args));
  9834. }
  9835. else if (hook) {
  9836. hook(...args);
  9837. }
  9838. };
  9839. /**
  9840. * Check if a hook expects a callback (2nd arg), which means the user
  9841. * intends to explicitly control the end of the transition.
  9842. */
  9843. const hasExplicitCallback = (hook) => {
  9844. return hook
  9845. ? isArray(hook)
  9846. ? hook.some(h => h.length > 1)
  9847. : hook.length > 1
  9848. : false;
  9849. };
  9850. function resolveTransitionProps(rawProps) {
  9851. const baseProps = {};
  9852. for (const key in rawProps) {
  9853. if (!(key in DOMTransitionPropsValidators)) {
  9854. baseProps[key] = rawProps[key];
  9855. }
  9856. }
  9857. if (rawProps.css === false) {
  9858. return baseProps;
  9859. }
  9860. 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;
  9861. const durations = normalizeDuration(duration);
  9862. const enterDuration = durations && durations[0];
  9863. const leaveDuration = durations && durations[1];
  9864. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  9865. const finishEnter = (el, isAppear, done) => {
  9866. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9867. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  9868. done && done();
  9869. };
  9870. const finishLeave = (el, done) => {
  9871. removeTransitionClass(el, leaveToClass);
  9872. removeTransitionClass(el, leaveActiveClass);
  9873. done && done();
  9874. };
  9875. const makeEnterHook = (isAppear) => {
  9876. return (el, done) => {
  9877. const hook = isAppear ? onAppear : onEnter;
  9878. const resolve = () => finishEnter(el, isAppear, done);
  9879. callHook$1(hook, [el, resolve]);
  9880. nextFrame(() => {
  9881. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  9882. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  9883. if (!hasExplicitCallback(hook)) {
  9884. whenTransitionEnds(el, type, enterDuration, resolve);
  9885. }
  9886. });
  9887. };
  9888. };
  9889. return extend(baseProps, {
  9890. onBeforeEnter(el) {
  9891. callHook$1(onBeforeEnter, [el]);
  9892. addTransitionClass(el, enterFromClass);
  9893. addTransitionClass(el, enterActiveClass);
  9894. },
  9895. onBeforeAppear(el) {
  9896. callHook$1(onBeforeAppear, [el]);
  9897. addTransitionClass(el, appearFromClass);
  9898. addTransitionClass(el, appearActiveClass);
  9899. },
  9900. onEnter: makeEnterHook(false),
  9901. onAppear: makeEnterHook(true),
  9902. onLeave(el, done) {
  9903. const resolve = () => finishLeave(el, done);
  9904. addTransitionClass(el, leaveFromClass);
  9905. // force reflow so *-leave-from classes immediately take effect (#2593)
  9906. forceReflow();
  9907. addTransitionClass(el, leaveActiveClass);
  9908. nextFrame(() => {
  9909. removeTransitionClass(el, leaveFromClass);
  9910. addTransitionClass(el, leaveToClass);
  9911. if (!hasExplicitCallback(onLeave)) {
  9912. whenTransitionEnds(el, type, leaveDuration, resolve);
  9913. }
  9914. });
  9915. callHook$1(onLeave, [el, resolve]);
  9916. },
  9917. onEnterCancelled(el) {
  9918. finishEnter(el, false);
  9919. callHook$1(onEnterCancelled, [el]);
  9920. },
  9921. onAppearCancelled(el) {
  9922. finishEnter(el, true);
  9923. callHook$1(onAppearCancelled, [el]);
  9924. },
  9925. onLeaveCancelled(el) {
  9926. finishLeave(el);
  9927. callHook$1(onLeaveCancelled, [el]);
  9928. }
  9929. });
  9930. }
  9931. function normalizeDuration(duration) {
  9932. if (duration == null) {
  9933. return null;
  9934. }
  9935. else if (isObject(duration)) {
  9936. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  9937. }
  9938. else {
  9939. const n = NumberOf(duration);
  9940. return [n, n];
  9941. }
  9942. }
  9943. function NumberOf(val) {
  9944. const res = toNumber(val);
  9945. validateDuration(res);
  9946. return res;
  9947. }
  9948. function validateDuration(val) {
  9949. if (typeof val !== 'number') {
  9950. warn$1(`<transition> explicit duration is not a valid number - ` +
  9951. `got ${JSON.stringify(val)}.`);
  9952. }
  9953. else if (isNaN(val)) {
  9954. warn$1(`<transition> explicit duration is NaN - ` +
  9955. 'the duration expression might be incorrect.');
  9956. }
  9957. }
  9958. function addTransitionClass(el, cls) {
  9959. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  9960. (el._vtc ||
  9961. (el._vtc = new Set())).add(cls);
  9962. }
  9963. function removeTransitionClass(el, cls) {
  9964. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  9965. const { _vtc } = el;
  9966. if (_vtc) {
  9967. _vtc.delete(cls);
  9968. if (!_vtc.size) {
  9969. el._vtc = undefined;
  9970. }
  9971. }
  9972. }
  9973. function nextFrame(cb) {
  9974. requestAnimationFrame(() => {
  9975. requestAnimationFrame(cb);
  9976. });
  9977. }
  9978. let endId = 0;
  9979. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  9980. const id = (el._endId = ++endId);
  9981. const resolveIfNotStale = () => {
  9982. if (id === el._endId) {
  9983. resolve();
  9984. }
  9985. };
  9986. if (explicitTimeout) {
  9987. return setTimeout(resolveIfNotStale, explicitTimeout);
  9988. }
  9989. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  9990. if (!type) {
  9991. return resolve();
  9992. }
  9993. const endEvent = type + 'end';
  9994. let ended = 0;
  9995. const end = () => {
  9996. el.removeEventListener(endEvent, onEnd);
  9997. resolveIfNotStale();
  9998. };
  9999. const onEnd = (e) => {
  10000. if (e.target === el && ++ended >= propCount) {
  10001. end();
  10002. }
  10003. };
  10004. setTimeout(() => {
  10005. if (ended < propCount) {
  10006. end();
  10007. }
  10008. }, timeout + 1);
  10009. el.addEventListener(endEvent, onEnd);
  10010. }
  10011. function getTransitionInfo(el, expectedType) {
  10012. const styles = window.getComputedStyle(el);
  10013. // JSDOM may return undefined for transition properties
  10014. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10015. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  10016. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  10017. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10018. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  10019. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  10020. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10021. let type = null;
  10022. let timeout = 0;
  10023. let propCount = 0;
  10024. /* istanbul ignore if */
  10025. if (expectedType === TRANSITION) {
  10026. if (transitionTimeout > 0) {
  10027. type = TRANSITION;
  10028. timeout = transitionTimeout;
  10029. propCount = transitionDurations.length;
  10030. }
  10031. }
  10032. else if (expectedType === ANIMATION) {
  10033. if (animationTimeout > 0) {
  10034. type = ANIMATION;
  10035. timeout = animationTimeout;
  10036. propCount = animationDurations.length;
  10037. }
  10038. }
  10039. else {
  10040. timeout = Math.max(transitionTimeout, animationTimeout);
  10041. type =
  10042. timeout > 0
  10043. ? transitionTimeout > animationTimeout
  10044. ? TRANSITION
  10045. : ANIMATION
  10046. : null;
  10047. propCount = type
  10048. ? type === TRANSITION
  10049. ? transitionDurations.length
  10050. : animationDurations.length
  10051. : 0;
  10052. }
  10053. const hasTransform = type === TRANSITION &&
  10054. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  10055. return {
  10056. type,
  10057. timeout,
  10058. propCount,
  10059. hasTransform
  10060. };
  10061. }
  10062. function getTimeout(delays, durations) {
  10063. while (delays.length < durations.length) {
  10064. delays = delays.concat(delays);
  10065. }
  10066. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10067. }
  10068. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10069. // numbers in a locale-dependent way, using a comma instead of a dot.
  10070. // If comma is not replaced with a dot, the input will be rounded down
  10071. // (i.e. acting as a floor function) causing unexpected behaviors
  10072. function toMs(s) {
  10073. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10074. }
  10075. // synchronously force layout to put elements into a certain state
  10076. function forceReflow() {
  10077. return document.body.offsetHeight;
  10078. }
  10079. const positionMap = new WeakMap();
  10080. const newPositionMap = new WeakMap();
  10081. const TransitionGroupImpl = {
  10082. name: 'TransitionGroup',
  10083. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10084. tag: String,
  10085. moveClass: String
  10086. }),
  10087. setup(props, { slots }) {
  10088. const instance = getCurrentInstance();
  10089. const state = useTransitionState();
  10090. let prevChildren;
  10091. let children;
  10092. onUpdated(() => {
  10093. // children is guaranteed to exist after initial render
  10094. if (!prevChildren.length) {
  10095. return;
  10096. }
  10097. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10098. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10099. return;
  10100. }
  10101. // we divide the work into three loops to avoid mixing DOM reads and writes
  10102. // in each iteration - which helps prevent layout thrashing.
  10103. prevChildren.forEach(callPendingCbs);
  10104. prevChildren.forEach(recordPosition);
  10105. const movedChildren = prevChildren.filter(applyTranslation);
  10106. // force reflow to put everything in position
  10107. forceReflow();
  10108. movedChildren.forEach(c => {
  10109. const el = c.el;
  10110. const style = el.style;
  10111. addTransitionClass(el, moveClass);
  10112. style.transform = style.webkitTransform = style.transitionDuration = '';
  10113. const cb = (el._moveCb = (e) => {
  10114. if (e && e.target !== el) {
  10115. return;
  10116. }
  10117. if (!e || /transform$/.test(e.propertyName)) {
  10118. el.removeEventListener('transitionend', cb);
  10119. el._moveCb = null;
  10120. removeTransitionClass(el, moveClass);
  10121. }
  10122. });
  10123. el.addEventListener('transitionend', cb);
  10124. });
  10125. });
  10126. return () => {
  10127. const rawProps = toRaw(props);
  10128. const cssTransitionProps = resolveTransitionProps(rawProps);
  10129. let tag = rawProps.tag || Fragment;
  10130. prevChildren = children;
  10131. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10132. for (let i = 0; i < children.length; i++) {
  10133. const child = children[i];
  10134. if (child.key != null) {
  10135. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10136. }
  10137. else {
  10138. warn$1(`<TransitionGroup> children must be keyed.`);
  10139. }
  10140. }
  10141. if (prevChildren) {
  10142. for (let i = 0; i < prevChildren.length; i++) {
  10143. const child = prevChildren[i];
  10144. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10145. positionMap.set(child, child.el.getBoundingClientRect());
  10146. }
  10147. }
  10148. return createVNode(tag, null, children);
  10149. };
  10150. }
  10151. };
  10152. const TransitionGroup = TransitionGroupImpl;
  10153. function callPendingCbs(c) {
  10154. const el = c.el;
  10155. if (el._moveCb) {
  10156. el._moveCb();
  10157. }
  10158. if (el._enterCb) {
  10159. el._enterCb();
  10160. }
  10161. }
  10162. function recordPosition(c) {
  10163. newPositionMap.set(c, c.el.getBoundingClientRect());
  10164. }
  10165. function applyTranslation(c) {
  10166. const oldPos = positionMap.get(c);
  10167. const newPos = newPositionMap.get(c);
  10168. const dx = oldPos.left - newPos.left;
  10169. const dy = oldPos.top - newPos.top;
  10170. if (dx || dy) {
  10171. const s = c.el.style;
  10172. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10173. s.transitionDuration = '0s';
  10174. return c;
  10175. }
  10176. }
  10177. function hasCSSTransform(el, root, moveClass) {
  10178. // Detect whether an element with the move class applied has
  10179. // CSS transitions. Since the element may be inside an entering
  10180. // transition at this very moment, we make a clone of it and remove
  10181. // all other transition classes applied to ensure only the move class
  10182. // is applied.
  10183. const clone = el.cloneNode();
  10184. if (el._vtc) {
  10185. el._vtc.forEach(cls => {
  10186. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10187. });
  10188. }
  10189. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10190. clone.style.display = 'none';
  10191. const container = (root.nodeType === 1 ? root : root.parentNode);
  10192. container.appendChild(clone);
  10193. const { hasTransform } = getTransitionInfo(clone);
  10194. container.removeChild(clone);
  10195. return hasTransform;
  10196. }
  10197. const getModelAssigner = (vnode) => {
  10198. const fn = vnode.props['onUpdate:modelValue'];
  10199. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10200. };
  10201. function onCompositionStart(e) {
  10202. e.target.composing = true;
  10203. }
  10204. function onCompositionEnd(e) {
  10205. const target = e.target;
  10206. if (target.composing) {
  10207. target.composing = false;
  10208. trigger$1(target, 'input');
  10209. }
  10210. }
  10211. function trigger$1(el, type) {
  10212. const e = document.createEvent('HTMLEvents');
  10213. e.initEvent(type, true, true);
  10214. el.dispatchEvent(e);
  10215. }
  10216. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10217. // be tree-shaken in case v-model is never used.
  10218. const vModelText = {
  10219. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10220. el._assign = getModelAssigner(vnode);
  10221. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10222. addEventListener(el, lazy ? 'change' : 'input', e => {
  10223. if (e.target.composing)
  10224. return;
  10225. let domValue = el.value;
  10226. if (trim) {
  10227. domValue = domValue.trim();
  10228. }
  10229. else if (castToNumber) {
  10230. domValue = toNumber(domValue);
  10231. }
  10232. el._assign(domValue);
  10233. });
  10234. if (trim) {
  10235. addEventListener(el, 'change', () => {
  10236. el.value = el.value.trim();
  10237. });
  10238. }
  10239. if (!lazy) {
  10240. addEventListener(el, 'compositionstart', onCompositionStart);
  10241. addEventListener(el, 'compositionend', onCompositionEnd);
  10242. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10243. // switching focus before confirming composition choice
  10244. // this also fixes the issue where some browsers e.g. iOS Chrome
  10245. // fires "change" instead of "input" on autocomplete.
  10246. addEventListener(el, 'change', onCompositionEnd);
  10247. }
  10248. },
  10249. // set value on mounted so it's after min/max for type="range"
  10250. mounted(el, { value }) {
  10251. el.value = value == null ? '' : value;
  10252. },
  10253. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10254. el._assign = getModelAssigner(vnode);
  10255. // avoid clearing unresolved text. #2302
  10256. if (el.composing)
  10257. return;
  10258. if (document.activeElement === el) {
  10259. if (lazy) {
  10260. return;
  10261. }
  10262. if (trim && el.value.trim() === value) {
  10263. return;
  10264. }
  10265. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10266. return;
  10267. }
  10268. }
  10269. const newValue = value == null ? '' : value;
  10270. if (el.value !== newValue) {
  10271. el.value = newValue;
  10272. }
  10273. }
  10274. };
  10275. const vModelCheckbox = {
  10276. // #4096 array checkboxes need to be deep traversed
  10277. deep: true,
  10278. created(el, _, vnode) {
  10279. el._assign = getModelAssigner(vnode);
  10280. addEventListener(el, 'change', () => {
  10281. const modelValue = el._modelValue;
  10282. const elementValue = getValue(el);
  10283. const checked = el.checked;
  10284. const assign = el._assign;
  10285. if (isArray(modelValue)) {
  10286. const index = looseIndexOf(modelValue, elementValue);
  10287. const found = index !== -1;
  10288. if (checked && !found) {
  10289. assign(modelValue.concat(elementValue));
  10290. }
  10291. else if (!checked && found) {
  10292. const filtered = [...modelValue];
  10293. filtered.splice(index, 1);
  10294. assign(filtered);
  10295. }
  10296. }
  10297. else if (isSet(modelValue)) {
  10298. const cloned = new Set(modelValue);
  10299. if (checked) {
  10300. cloned.add(elementValue);
  10301. }
  10302. else {
  10303. cloned.delete(elementValue);
  10304. }
  10305. assign(cloned);
  10306. }
  10307. else {
  10308. assign(getCheckboxValue(el, checked));
  10309. }
  10310. });
  10311. },
  10312. // set initial checked on mount to wait for true-value/false-value
  10313. mounted: setChecked,
  10314. beforeUpdate(el, binding, vnode) {
  10315. el._assign = getModelAssigner(vnode);
  10316. setChecked(el, binding, vnode);
  10317. }
  10318. };
  10319. function setChecked(el, { value, oldValue }, vnode) {
  10320. el._modelValue = value;
  10321. if (isArray(value)) {
  10322. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10323. }
  10324. else if (isSet(value)) {
  10325. el.checked = value.has(vnode.props.value);
  10326. }
  10327. else if (value !== oldValue) {
  10328. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10329. }
  10330. }
  10331. const vModelRadio = {
  10332. created(el, { value }, vnode) {
  10333. el.checked = looseEqual(value, vnode.props.value);
  10334. el._assign = getModelAssigner(vnode);
  10335. addEventListener(el, 'change', () => {
  10336. el._assign(getValue(el));
  10337. });
  10338. },
  10339. beforeUpdate(el, { value, oldValue }, vnode) {
  10340. el._assign = getModelAssigner(vnode);
  10341. if (value !== oldValue) {
  10342. el.checked = looseEqual(value, vnode.props.value);
  10343. }
  10344. }
  10345. };
  10346. const vModelSelect = {
  10347. // <select multiple> value need to be deep traversed
  10348. deep: true,
  10349. created(el, { value, modifiers: { number } }, vnode) {
  10350. const isSetModel = isSet(value);
  10351. addEventListener(el, 'change', () => {
  10352. const selectedVal = Array.prototype.filter
  10353. .call(el.options, (o) => o.selected)
  10354. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10355. el._assign(el.multiple
  10356. ? isSetModel
  10357. ? new Set(selectedVal)
  10358. : selectedVal
  10359. : selectedVal[0]);
  10360. });
  10361. el._assign = getModelAssigner(vnode);
  10362. },
  10363. // set value in mounted & updated because <select> relies on its children
  10364. // <option>s.
  10365. mounted(el, { value }) {
  10366. setSelected(el, value);
  10367. },
  10368. beforeUpdate(el, _binding, vnode) {
  10369. el._assign = getModelAssigner(vnode);
  10370. },
  10371. updated(el, { value }) {
  10372. setSelected(el, value);
  10373. }
  10374. };
  10375. function setSelected(el, value) {
  10376. const isMultiple = el.multiple;
  10377. if (isMultiple && !isArray(value) && !isSet(value)) {
  10378. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10379. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10380. return;
  10381. }
  10382. for (let i = 0, l = el.options.length; i < l; i++) {
  10383. const option = el.options[i];
  10384. const optionValue = getValue(option);
  10385. if (isMultiple) {
  10386. if (isArray(value)) {
  10387. option.selected = looseIndexOf(value, optionValue) > -1;
  10388. }
  10389. else {
  10390. option.selected = value.has(optionValue);
  10391. }
  10392. }
  10393. else {
  10394. if (looseEqual(getValue(option), value)) {
  10395. if (el.selectedIndex !== i)
  10396. el.selectedIndex = i;
  10397. return;
  10398. }
  10399. }
  10400. }
  10401. if (!isMultiple && el.selectedIndex !== -1) {
  10402. el.selectedIndex = -1;
  10403. }
  10404. }
  10405. // retrieve raw value set via :value bindings
  10406. function getValue(el) {
  10407. return '_value' in el ? el._value : el.value;
  10408. }
  10409. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10410. function getCheckboxValue(el, checked) {
  10411. const key = checked ? '_trueValue' : '_falseValue';
  10412. return key in el ? el[key] : checked;
  10413. }
  10414. const vModelDynamic = {
  10415. created(el, binding, vnode) {
  10416. callModelHook(el, binding, vnode, null, 'created');
  10417. },
  10418. mounted(el, binding, vnode) {
  10419. callModelHook(el, binding, vnode, null, 'mounted');
  10420. },
  10421. beforeUpdate(el, binding, vnode, prevVNode) {
  10422. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10423. },
  10424. updated(el, binding, vnode, prevVNode) {
  10425. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10426. }
  10427. };
  10428. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10429. let modelToUse;
  10430. switch (el.tagName) {
  10431. case 'SELECT':
  10432. modelToUse = vModelSelect;
  10433. break;
  10434. case 'TEXTAREA':
  10435. modelToUse = vModelText;
  10436. break;
  10437. default:
  10438. switch (vnode.props && vnode.props.type) {
  10439. case 'checkbox':
  10440. modelToUse = vModelCheckbox;
  10441. break;
  10442. case 'radio':
  10443. modelToUse = vModelRadio;
  10444. break;
  10445. default:
  10446. modelToUse = vModelText;
  10447. }
  10448. }
  10449. const fn = modelToUse[hook];
  10450. fn && fn(el, binding, vnode, prevVNode);
  10451. }
  10452. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10453. const modifierGuards = {
  10454. stop: e => e.stopPropagation(),
  10455. prevent: e => e.preventDefault(),
  10456. self: e => e.target !== e.currentTarget,
  10457. ctrl: e => !e.ctrlKey,
  10458. shift: e => !e.shiftKey,
  10459. alt: e => !e.altKey,
  10460. meta: e => !e.metaKey,
  10461. left: e => 'button' in e && e.button !== 0,
  10462. middle: e => 'button' in e && e.button !== 1,
  10463. right: e => 'button' in e && e.button !== 2,
  10464. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10465. };
  10466. /**
  10467. * @private
  10468. */
  10469. const withModifiers = (fn, modifiers) => {
  10470. return (event, ...args) => {
  10471. for (let i = 0; i < modifiers.length; i++) {
  10472. const guard = modifierGuards[modifiers[i]];
  10473. if (guard && guard(event, modifiers))
  10474. return;
  10475. }
  10476. return fn(event, ...args);
  10477. };
  10478. };
  10479. // Kept for 2.x compat.
  10480. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10481. const keyNames = {
  10482. esc: 'escape',
  10483. space: ' ',
  10484. up: 'arrow-up',
  10485. left: 'arrow-left',
  10486. right: 'arrow-right',
  10487. down: 'arrow-down',
  10488. delete: 'backspace'
  10489. };
  10490. /**
  10491. * @private
  10492. */
  10493. const withKeys = (fn, modifiers) => {
  10494. return (event) => {
  10495. if (!('key' in event)) {
  10496. return;
  10497. }
  10498. const eventKey = hyphenate(event.key);
  10499. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10500. return fn(event);
  10501. }
  10502. };
  10503. };
  10504. const vShow = {
  10505. beforeMount(el, { value }, { transition }) {
  10506. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10507. if (transition && value) {
  10508. transition.beforeEnter(el);
  10509. }
  10510. else {
  10511. setDisplay(el, value);
  10512. }
  10513. },
  10514. mounted(el, { value }, { transition }) {
  10515. if (transition && value) {
  10516. transition.enter(el);
  10517. }
  10518. },
  10519. updated(el, { value, oldValue }, { transition }) {
  10520. if (!value === !oldValue)
  10521. return;
  10522. if (transition) {
  10523. if (value) {
  10524. transition.beforeEnter(el);
  10525. setDisplay(el, true);
  10526. transition.enter(el);
  10527. }
  10528. else {
  10529. transition.leave(el, () => {
  10530. setDisplay(el, false);
  10531. });
  10532. }
  10533. }
  10534. else {
  10535. setDisplay(el, value);
  10536. }
  10537. },
  10538. beforeUnmount(el, { value }) {
  10539. setDisplay(el, value);
  10540. }
  10541. };
  10542. function setDisplay(el, value) {
  10543. el.style.display = value ? el._vod : 'none';
  10544. }
  10545. const rendererOptions = extend({ patchProp }, nodeOps);
  10546. // lazy create the renderer - this makes core renderer logic tree-shakable
  10547. // in case the user only imports reactivity utilities from Vue.
  10548. let renderer;
  10549. let enabledHydration = false;
  10550. function ensureRenderer() {
  10551. return (renderer ||
  10552. (renderer = createRenderer(rendererOptions)));
  10553. }
  10554. function ensureHydrationRenderer() {
  10555. renderer = enabledHydration
  10556. ? renderer
  10557. : createHydrationRenderer(rendererOptions);
  10558. enabledHydration = true;
  10559. return renderer;
  10560. }
  10561. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10562. const render = ((...args) => {
  10563. ensureRenderer().render(...args);
  10564. });
  10565. const hydrate = ((...args) => {
  10566. ensureHydrationRenderer().hydrate(...args);
  10567. });
  10568. const createApp = ((...args) => {
  10569. const app = ensureRenderer().createApp(...args);
  10570. {
  10571. injectNativeTagCheck(app);
  10572. injectCompilerOptionsCheck(app);
  10573. }
  10574. const { mount } = app;
  10575. app.mount = (containerOrSelector) => {
  10576. const container = normalizeContainer(containerOrSelector);
  10577. if (!container)
  10578. return;
  10579. const component = app._component;
  10580. if (!isFunction(component) && !component.render && !component.template) {
  10581. // __UNSAFE__
  10582. // Reason: potential execution of JS expressions in in-DOM template.
  10583. // The user must make sure the in-DOM template is trusted. If it's
  10584. // rendered by the server, the template should not contain any user data.
  10585. component.template = container.innerHTML;
  10586. }
  10587. // clear content before mounting
  10588. container.innerHTML = '';
  10589. const proxy = mount(container, false, container instanceof SVGElement);
  10590. if (container instanceof Element) {
  10591. container.removeAttribute('v-cloak');
  10592. container.setAttribute('data-v-app', '');
  10593. }
  10594. return proxy;
  10595. };
  10596. return app;
  10597. });
  10598. const createSSRApp = ((...args) => {
  10599. const app = ensureHydrationRenderer().createApp(...args);
  10600. {
  10601. injectNativeTagCheck(app);
  10602. injectCompilerOptionsCheck(app);
  10603. }
  10604. const { mount } = app;
  10605. app.mount = (containerOrSelector) => {
  10606. const container = normalizeContainer(containerOrSelector);
  10607. if (container) {
  10608. return mount(container, true, container instanceof SVGElement);
  10609. }
  10610. };
  10611. return app;
  10612. });
  10613. function injectNativeTagCheck(app) {
  10614. // Inject `isNativeTag`
  10615. // this is used for component name validation (dev only)
  10616. Object.defineProperty(app.config, 'isNativeTag', {
  10617. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10618. writable: false
  10619. });
  10620. }
  10621. // dev only
  10622. function injectCompilerOptionsCheck(app) {
  10623. if (isRuntimeOnly()) {
  10624. const isCustomElement = app.config.isCustomElement;
  10625. Object.defineProperty(app.config, 'isCustomElement', {
  10626. get() {
  10627. return isCustomElement;
  10628. },
  10629. set() {
  10630. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10631. `\`compilerOptions.isCustomElement\` instead.`);
  10632. }
  10633. });
  10634. const compilerOptions = app.config.compilerOptions;
  10635. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10636. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10637. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10638. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10639. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10640. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10641. `- 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`;
  10642. Object.defineProperty(app.config, 'compilerOptions', {
  10643. get() {
  10644. warn$1(msg);
  10645. return compilerOptions;
  10646. },
  10647. set() {
  10648. warn$1(msg);
  10649. }
  10650. });
  10651. }
  10652. }
  10653. function normalizeContainer(container) {
  10654. if (isString(container)) {
  10655. const res = document.querySelector(container);
  10656. if (!res) {
  10657. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10658. }
  10659. return res;
  10660. }
  10661. if (window.ShadowRoot &&
  10662. container instanceof window.ShadowRoot &&
  10663. container.mode === 'closed') {
  10664. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10665. }
  10666. return container;
  10667. }
  10668. /**
  10669. * @internal
  10670. */
  10671. const initDirectivesForSSR = NOOP;
  10672. function initDev() {
  10673. {
  10674. {
  10675. console.info(`You are running a development build of Vue.\n` +
  10676. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10677. }
  10678. initCustomFormatter();
  10679. }
  10680. }
  10681. function defaultOnError(error) {
  10682. throw error;
  10683. }
  10684. function defaultOnWarn(msg) {
  10685. console.warn(`[Vue warn] ${msg.message}`);
  10686. }
  10687. function createCompilerError(code, loc, messages, additionalMessage) {
  10688. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  10689. ;
  10690. const error = new SyntaxError(String(msg));
  10691. error.code = code;
  10692. error.loc = loc;
  10693. return error;
  10694. }
  10695. const errorMessages = {
  10696. // parse errors
  10697. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  10698. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  10699. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  10700. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  10701. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  10702. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  10703. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  10704. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  10705. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  10706. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  10707. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  10708. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  10709. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  10710. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  10711. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  10712. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  10713. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  10714. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  10715. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  10716. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  10717. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  10718. [20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  10719. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  10720. // Vue-specific parse errors
  10721. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  10722. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  10723. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  10724. [27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  10725. 'Note that dynamic directive argument cannot contain spaces.',
  10726. [26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  10727. // transform errors
  10728. [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  10729. [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  10730. [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  10731. [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  10732. [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  10733. [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  10734. [34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  10735. [35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  10736. [36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  10737. [37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  10738. `When there are multiple named slots, all slots should use <template> ` +
  10739. `syntax to avoid scope ambiguity.`,
  10740. [38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  10741. [39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  10742. `default slot. These children will be ignored.`,
  10743. [40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  10744. [41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  10745. [42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  10746. [43 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  10747. [44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  10748. [45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  10749. // generic errors
  10750. [46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  10751. [47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  10752. [48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  10753. [49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  10754. // just to fulfill types
  10755. [50 /* __EXTEND_POINT__ */]: ``
  10756. };
  10757. const FRAGMENT = Symbol(`Fragment` );
  10758. const TELEPORT = Symbol(`Teleport` );
  10759. const SUSPENSE = Symbol(`Suspense` );
  10760. const KEEP_ALIVE = Symbol(`KeepAlive` );
  10761. const BASE_TRANSITION = Symbol(`BaseTransition` );
  10762. const OPEN_BLOCK = Symbol(`openBlock` );
  10763. const CREATE_BLOCK = Symbol(`createBlock` );
  10764. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  10765. const CREATE_VNODE = Symbol(`createVNode` );
  10766. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  10767. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  10768. const CREATE_TEXT = Symbol(`createTextVNode` );
  10769. const CREATE_STATIC = Symbol(`createStaticVNode` );
  10770. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  10771. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  10772. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  10773. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  10774. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  10775. const RENDER_LIST = Symbol(`renderList` );
  10776. const RENDER_SLOT = Symbol(`renderSlot` );
  10777. const CREATE_SLOTS = Symbol(`createSlots` );
  10778. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  10779. const MERGE_PROPS = Symbol(`mergeProps` );
  10780. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  10781. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  10782. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  10783. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  10784. const TO_HANDLERS = Symbol(`toHandlers` );
  10785. const CAMELIZE = Symbol(`camelize` );
  10786. const CAPITALIZE = Symbol(`capitalize` );
  10787. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  10788. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  10789. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  10790. const POP_SCOPE_ID = Symbol(`popScopeId` );
  10791. const WITH_CTX = Symbol(`withCtx` );
  10792. const UNREF = Symbol(`unref` );
  10793. const IS_REF = Symbol(`isRef` );
  10794. const WITH_MEMO = Symbol(`withMemo` );
  10795. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  10796. // Name mapping for runtime helpers that need to be imported from 'vue' in
  10797. // generated code. Make sure these are correctly exported in the runtime!
  10798. // Using `any` here because TS doesn't allow symbols as index type.
  10799. const helperNameMap = {
  10800. [FRAGMENT]: `Fragment`,
  10801. [TELEPORT]: `Teleport`,
  10802. [SUSPENSE]: `Suspense`,
  10803. [KEEP_ALIVE]: `KeepAlive`,
  10804. [BASE_TRANSITION]: `BaseTransition`,
  10805. [OPEN_BLOCK]: `openBlock`,
  10806. [CREATE_BLOCK]: `createBlock`,
  10807. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  10808. [CREATE_VNODE]: `createVNode`,
  10809. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  10810. [CREATE_COMMENT]: `createCommentVNode`,
  10811. [CREATE_TEXT]: `createTextVNode`,
  10812. [CREATE_STATIC]: `createStaticVNode`,
  10813. [RESOLVE_COMPONENT]: `resolveComponent`,
  10814. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  10815. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  10816. [RESOLVE_FILTER]: `resolveFilter`,
  10817. [WITH_DIRECTIVES]: `withDirectives`,
  10818. [RENDER_LIST]: `renderList`,
  10819. [RENDER_SLOT]: `renderSlot`,
  10820. [CREATE_SLOTS]: `createSlots`,
  10821. [TO_DISPLAY_STRING]: `toDisplayString`,
  10822. [MERGE_PROPS]: `mergeProps`,
  10823. [NORMALIZE_CLASS]: `normalizeClass`,
  10824. [NORMALIZE_STYLE]: `normalizeStyle`,
  10825. [NORMALIZE_PROPS]: `normalizeProps`,
  10826. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  10827. [TO_HANDLERS]: `toHandlers`,
  10828. [CAMELIZE]: `camelize`,
  10829. [CAPITALIZE]: `capitalize`,
  10830. [TO_HANDLER_KEY]: `toHandlerKey`,
  10831. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  10832. [PUSH_SCOPE_ID]: `pushScopeId`,
  10833. [POP_SCOPE_ID]: `popScopeId`,
  10834. [WITH_CTX]: `withCtx`,
  10835. [UNREF]: `unref`,
  10836. [IS_REF]: `isRef`,
  10837. [WITH_MEMO]: `withMemo`,
  10838. [IS_MEMO_SAME]: `isMemoSame`
  10839. };
  10840. function registerRuntimeHelpers(helpers) {
  10841. Object.getOwnPropertySymbols(helpers).forEach(s => {
  10842. helperNameMap[s] = helpers[s];
  10843. });
  10844. }
  10845. // AST Utilities ---------------------------------------------------------------
  10846. // Some expressions, e.g. sequence and conditional expressions, are never
  10847. // associated with template nodes, so their source locations are just a stub.
  10848. // Container types like CompoundExpression also don't need a real location.
  10849. const locStub = {
  10850. source: '',
  10851. start: { line: 1, column: 1, offset: 0 },
  10852. end: { line: 1, column: 1, offset: 0 }
  10853. };
  10854. function createRoot(children, loc = locStub) {
  10855. return {
  10856. type: 0 /* ROOT */,
  10857. children,
  10858. helpers: [],
  10859. components: [],
  10860. directives: [],
  10861. hoists: [],
  10862. imports: [],
  10863. cached: 0,
  10864. temps: 0,
  10865. codegenNode: undefined,
  10866. loc
  10867. };
  10868. }
  10869. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  10870. if (context) {
  10871. if (isBlock) {
  10872. context.helper(OPEN_BLOCK);
  10873. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  10874. }
  10875. else {
  10876. context.helper(getVNodeHelper(context.inSSR, isComponent));
  10877. }
  10878. if (directives) {
  10879. context.helper(WITH_DIRECTIVES);
  10880. }
  10881. }
  10882. return {
  10883. type: 13 /* VNODE_CALL */,
  10884. tag,
  10885. props,
  10886. children,
  10887. patchFlag,
  10888. dynamicProps,
  10889. directives,
  10890. isBlock,
  10891. disableTracking,
  10892. isComponent,
  10893. loc
  10894. };
  10895. }
  10896. function createArrayExpression(elements, loc = locStub) {
  10897. return {
  10898. type: 17 /* JS_ARRAY_EXPRESSION */,
  10899. loc,
  10900. elements
  10901. };
  10902. }
  10903. function createObjectExpression(properties, loc = locStub) {
  10904. return {
  10905. type: 15 /* JS_OBJECT_EXPRESSION */,
  10906. loc,
  10907. properties
  10908. };
  10909. }
  10910. function createObjectProperty(key, value) {
  10911. return {
  10912. type: 16 /* JS_PROPERTY */,
  10913. loc: locStub,
  10914. key: isString(key) ? createSimpleExpression(key, true) : key,
  10915. value
  10916. };
  10917. }
  10918. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  10919. return {
  10920. type: 4 /* SIMPLE_EXPRESSION */,
  10921. loc,
  10922. content,
  10923. isStatic,
  10924. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  10925. };
  10926. }
  10927. function createCompoundExpression(children, loc = locStub) {
  10928. return {
  10929. type: 8 /* COMPOUND_EXPRESSION */,
  10930. loc,
  10931. children
  10932. };
  10933. }
  10934. function createCallExpression(callee, args = [], loc = locStub) {
  10935. return {
  10936. type: 14 /* JS_CALL_EXPRESSION */,
  10937. loc,
  10938. callee,
  10939. arguments: args
  10940. };
  10941. }
  10942. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  10943. return {
  10944. type: 18 /* JS_FUNCTION_EXPRESSION */,
  10945. params,
  10946. returns,
  10947. newline,
  10948. isSlot,
  10949. loc
  10950. };
  10951. }
  10952. function createConditionalExpression(test, consequent, alternate, newline = true) {
  10953. return {
  10954. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  10955. test,
  10956. consequent,
  10957. alternate,
  10958. newline,
  10959. loc: locStub
  10960. };
  10961. }
  10962. function createCacheExpression(index, value, isVNode = false) {
  10963. return {
  10964. type: 20 /* JS_CACHE_EXPRESSION */,
  10965. index,
  10966. value,
  10967. isVNode,
  10968. loc: locStub
  10969. };
  10970. }
  10971. function createBlockStatement(body) {
  10972. return {
  10973. type: 21 /* JS_BLOCK_STATEMENT */,
  10974. body,
  10975. loc: locStub
  10976. };
  10977. }
  10978. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  10979. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  10980. function isCoreComponent(tag) {
  10981. if (isBuiltInType(tag, 'Teleport')) {
  10982. return TELEPORT;
  10983. }
  10984. else if (isBuiltInType(tag, 'Suspense')) {
  10985. return SUSPENSE;
  10986. }
  10987. else if (isBuiltInType(tag, 'KeepAlive')) {
  10988. return KEEP_ALIVE;
  10989. }
  10990. else if (isBuiltInType(tag, 'BaseTransition')) {
  10991. return BASE_TRANSITION;
  10992. }
  10993. }
  10994. const nonIdentifierRE = /^\d|[^\$\w]/;
  10995. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  10996. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  10997. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  10998. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  10999. /**
  11000. * Simple lexer to check if an expression is a member expression. This is
  11001. * lax and only checks validity at the root level (i.e. does not validate exps
  11002. * inside square brackets), but it's ok since these are only used on template
  11003. * expressions and false positives are invalid expressions in the first place.
  11004. */
  11005. const isMemberExpressionBrowser = (path) => {
  11006. // remove whitespaces around . or [ first
  11007. path = path.trim().replace(whitespaceRE, s => s.trim());
  11008. let state = 0 /* inMemberExp */;
  11009. let stateStack = [];
  11010. let currentOpenBracketCount = 0;
  11011. let currentOpenParensCount = 0;
  11012. let currentStringType = null;
  11013. for (let i = 0; i < path.length; i++) {
  11014. const char = path.charAt(i);
  11015. switch (state) {
  11016. case 0 /* inMemberExp */:
  11017. if (char === '[') {
  11018. stateStack.push(state);
  11019. state = 1 /* inBrackets */;
  11020. currentOpenBracketCount++;
  11021. }
  11022. else if (char === '(') {
  11023. stateStack.push(state);
  11024. state = 2 /* inParens */;
  11025. currentOpenParensCount++;
  11026. }
  11027. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  11028. return false;
  11029. }
  11030. break;
  11031. case 1 /* inBrackets */:
  11032. if (char === `'` || char === `"` || char === '`') {
  11033. stateStack.push(state);
  11034. state = 3 /* inString */;
  11035. currentStringType = char;
  11036. }
  11037. else if (char === `[`) {
  11038. currentOpenBracketCount++;
  11039. }
  11040. else if (char === `]`) {
  11041. if (!--currentOpenBracketCount) {
  11042. state = stateStack.pop();
  11043. }
  11044. }
  11045. break;
  11046. case 2 /* inParens */:
  11047. if (char === `'` || char === `"` || char === '`') {
  11048. stateStack.push(state);
  11049. state = 3 /* inString */;
  11050. currentStringType = char;
  11051. }
  11052. else if (char === `(`) {
  11053. currentOpenParensCount++;
  11054. }
  11055. else if (char === `)`) {
  11056. // if the exp ends as a call then it should not be considered valid
  11057. if (i === path.length - 1) {
  11058. return false;
  11059. }
  11060. if (!--currentOpenParensCount) {
  11061. state = stateStack.pop();
  11062. }
  11063. }
  11064. break;
  11065. case 3 /* inString */:
  11066. if (char === currentStringType) {
  11067. state = stateStack.pop();
  11068. currentStringType = null;
  11069. }
  11070. break;
  11071. }
  11072. }
  11073. return !currentOpenBracketCount && !currentOpenParensCount;
  11074. };
  11075. const isMemberExpression = isMemberExpressionBrowser
  11076. ;
  11077. function getInnerRange(loc, offset, length) {
  11078. const source = loc.source.slice(offset, offset + length);
  11079. const newLoc = {
  11080. source,
  11081. start: advancePositionWithClone(loc.start, loc.source, offset),
  11082. end: loc.end
  11083. };
  11084. if (length != null) {
  11085. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  11086. }
  11087. return newLoc;
  11088. }
  11089. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  11090. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  11091. }
  11092. // advance by mutation without cloning (for performance reasons), since this
  11093. // gets called a lot in the parser
  11094. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  11095. let linesCount = 0;
  11096. let lastNewLinePos = -1;
  11097. for (let i = 0; i < numberOfCharacters; i++) {
  11098. if (source.charCodeAt(i) === 10 /* newline char code */) {
  11099. linesCount++;
  11100. lastNewLinePos = i;
  11101. }
  11102. }
  11103. pos.offset += numberOfCharacters;
  11104. pos.line += linesCount;
  11105. pos.column =
  11106. lastNewLinePos === -1
  11107. ? pos.column + numberOfCharacters
  11108. : numberOfCharacters - lastNewLinePos;
  11109. return pos;
  11110. }
  11111. function assert(condition, msg) {
  11112. /* istanbul ignore if */
  11113. if (!condition) {
  11114. throw new Error(msg || `unexpected compiler condition`);
  11115. }
  11116. }
  11117. function findDir(node, name, allowEmpty = false) {
  11118. for (let i = 0; i < node.props.length; i++) {
  11119. const p = node.props[i];
  11120. if (p.type === 7 /* DIRECTIVE */ &&
  11121. (allowEmpty || p.exp) &&
  11122. (isString(name) ? p.name === name : name.test(p.name))) {
  11123. return p;
  11124. }
  11125. }
  11126. }
  11127. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  11128. for (let i = 0; i < node.props.length; i++) {
  11129. const p = node.props[i];
  11130. if (p.type === 6 /* ATTRIBUTE */) {
  11131. if (dynamicOnly)
  11132. continue;
  11133. if (p.name === name && (p.value || allowEmpty)) {
  11134. return p;
  11135. }
  11136. }
  11137. else if (p.name === 'bind' &&
  11138. (p.exp || allowEmpty) &&
  11139. isStaticArgOf(p.arg, name)) {
  11140. return p;
  11141. }
  11142. }
  11143. }
  11144. function isStaticArgOf(arg, name) {
  11145. return !!(arg && isStaticExp(arg) && arg.content === name);
  11146. }
  11147. function hasDynamicKeyVBind(node) {
  11148. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  11149. p.name === 'bind' &&
  11150. (!p.arg || // v-bind="obj"
  11151. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  11152. !p.arg.isStatic) // v-bind:[foo]
  11153. );
  11154. }
  11155. function isText(node) {
  11156. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  11157. }
  11158. function isVSlot(p) {
  11159. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  11160. }
  11161. function isTemplateNode(node) {
  11162. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  11163. }
  11164. function isSlotOutlet(node) {
  11165. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  11166. }
  11167. function getVNodeHelper(ssr, isComponent) {
  11168. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  11169. }
  11170. function getVNodeBlockHelper(ssr, isComponent) {
  11171. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  11172. }
  11173. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  11174. function getUnnormalizedProps(props, callPath = []) {
  11175. if (props &&
  11176. !isString(props) &&
  11177. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11178. const callee = props.callee;
  11179. if (!isString(callee) && propsHelperSet.has(callee)) {
  11180. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  11181. }
  11182. }
  11183. return [props, callPath];
  11184. }
  11185. function injectProp(node, prop, context) {
  11186. let propsWithInjection;
  11187. /**
  11188. * 1. mergeProps(...)
  11189. * 2. toHandlers(...)
  11190. * 3. normalizeProps(...)
  11191. * 4. normalizeProps(guardReactiveProps(...))
  11192. *
  11193. * we need to get the real props before normalization
  11194. */
  11195. let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  11196. let callPath = [];
  11197. let parentCall;
  11198. if (props &&
  11199. !isString(props) &&
  11200. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11201. const ret = getUnnormalizedProps(props);
  11202. props = ret[0];
  11203. callPath = ret[1];
  11204. parentCall = callPath[callPath.length - 1];
  11205. }
  11206. if (props == null || isString(props)) {
  11207. propsWithInjection = createObjectExpression([prop]);
  11208. }
  11209. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  11210. // merged props... add ours
  11211. // only inject key to object literal if it's the first argument so that
  11212. // if doesn't override user provided keys
  11213. const first = props.arguments[0];
  11214. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11215. first.properties.unshift(prop);
  11216. }
  11217. else {
  11218. if (props.callee === TO_HANDLERS) {
  11219. // #2366
  11220. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11221. createObjectExpression([prop]),
  11222. props
  11223. ]);
  11224. }
  11225. else {
  11226. props.arguments.unshift(createObjectExpression([prop]));
  11227. }
  11228. }
  11229. !propsWithInjection && (propsWithInjection = props);
  11230. }
  11231. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11232. let alreadyExists = false;
  11233. // check existing key to avoid overriding user provided keys
  11234. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  11235. const propKeyName = prop.key.content;
  11236. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  11237. p.key.content === propKeyName);
  11238. }
  11239. if (!alreadyExists) {
  11240. props.properties.unshift(prop);
  11241. }
  11242. propsWithInjection = props;
  11243. }
  11244. else {
  11245. // single v-bind with expression, return a merged replacement
  11246. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11247. createObjectExpression([prop]),
  11248. props
  11249. ]);
  11250. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  11251. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  11252. // the `guardReactiveProps` will no longer be needed
  11253. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  11254. parentCall = callPath[callPath.length - 2];
  11255. }
  11256. }
  11257. if (node.type === 13 /* VNODE_CALL */) {
  11258. if (parentCall) {
  11259. parentCall.arguments[0] = propsWithInjection;
  11260. }
  11261. else {
  11262. node.props = propsWithInjection;
  11263. }
  11264. }
  11265. else {
  11266. if (parentCall) {
  11267. parentCall.arguments[0] = propsWithInjection;
  11268. }
  11269. else {
  11270. node.arguments[2] = propsWithInjection;
  11271. }
  11272. }
  11273. }
  11274. function toValidAssetId(name, type) {
  11275. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  11276. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  11277. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  11278. })}`;
  11279. }
  11280. function getMemoedVNodeCall(node) {
  11281. if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  11282. return node.arguments[1].returns;
  11283. }
  11284. else {
  11285. return node;
  11286. }
  11287. }
  11288. function makeBlock(node, { helper, removeHelper, inSSR }) {
  11289. if (!node.isBlock) {
  11290. node.isBlock = true;
  11291. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  11292. helper(OPEN_BLOCK);
  11293. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  11294. }
  11295. }
  11296. const deprecationData = {
  11297. ["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
  11298. message: `Platform-native elements with "is" prop will no longer be ` +
  11299. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  11300. `prefixed with "vue:".`,
  11301. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  11302. },
  11303. ["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
  11304. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  11305. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  11306. `\`v-model:${key}\`.`,
  11307. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  11308. },
  11309. ["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
  11310. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  11311. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  11312. },
  11313. ["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
  11314. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  11315. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  11316. `that appears before v-bind in the case of conflict. ` +
  11317. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  11318. `You can also suppress this warning if the usage is intended.`,
  11319. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  11320. },
  11321. ["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
  11322. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  11323. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  11324. },
  11325. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  11326. message: `v-if / v-for precedence when used on the same element has changed ` +
  11327. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  11328. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  11329. `with <template> tags or use a computed property that filters v-for ` +
  11330. `data source.`,
  11331. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  11332. },
  11333. ["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
  11334. message: `<template> with no special directives will render as a native template ` +
  11335. `element instead of its inner content in Vue 3.`
  11336. },
  11337. ["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
  11338. message: `"inline-template" has been removed in Vue 3.`,
  11339. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  11340. },
  11341. ["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
  11342. message: `filters have been removed in Vue 3. ` +
  11343. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  11344. `Use method calls or computed properties instead.`,
  11345. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  11346. }
  11347. };
  11348. function getCompatValue(key, context) {
  11349. const config = context.options
  11350. ? context.options.compatConfig
  11351. : context.compatConfig;
  11352. const value = config && config[key];
  11353. if (key === 'MODE') {
  11354. return value || 3; // compiler defaults to v3 behavior
  11355. }
  11356. else {
  11357. return value;
  11358. }
  11359. }
  11360. function isCompatEnabled(key, context) {
  11361. const mode = getCompatValue('MODE', context);
  11362. const value = getCompatValue(key, context);
  11363. // in v3 mode, only enable if explicitly set to true
  11364. // otherwise enable for any non-false value
  11365. return mode === 3 ? value === true : value !== false;
  11366. }
  11367. function checkCompatEnabled(key, context, loc, ...args) {
  11368. const enabled = isCompatEnabled(key, context);
  11369. if (enabled) {
  11370. warnDeprecation(key, context, loc, ...args);
  11371. }
  11372. return enabled;
  11373. }
  11374. function warnDeprecation(key, context, loc, ...args) {
  11375. const val = getCompatValue(key, context);
  11376. if (val === 'suppress-warning') {
  11377. return;
  11378. }
  11379. const { message, link } = deprecationData[key];
  11380. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  11381. const err = new SyntaxError(msg);
  11382. err.code = key;
  11383. if (loc)
  11384. err.loc = loc;
  11385. context.onWarn(err);
  11386. }
  11387. // The default decoder only provides escapes for characters reserved as part of
  11388. // the template syntax, and is only used if the custom renderer did not provide
  11389. // a platform-specific decoder.
  11390. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  11391. const decodeMap = {
  11392. gt: '>',
  11393. lt: '<',
  11394. amp: '&',
  11395. apos: "'",
  11396. quot: '"'
  11397. };
  11398. const defaultParserOptions = {
  11399. delimiters: [`{{`, `}}`],
  11400. getNamespace: () => 0 /* HTML */,
  11401. getTextMode: () => 0 /* DATA */,
  11402. isVoidTag: NO,
  11403. isPreTag: NO,
  11404. isCustomElement: NO,
  11405. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  11406. onError: defaultOnError,
  11407. onWarn: defaultOnWarn,
  11408. comments: true
  11409. };
  11410. function baseParse(content, options = {}) {
  11411. const context = createParserContext(content, options);
  11412. const start = getCursor(context);
  11413. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  11414. }
  11415. function createParserContext(content, rawOptions) {
  11416. const options = extend({}, defaultParserOptions);
  11417. let key;
  11418. for (key in rawOptions) {
  11419. // @ts-ignore
  11420. options[key] =
  11421. rawOptions[key] === undefined
  11422. ? defaultParserOptions[key]
  11423. : rawOptions[key];
  11424. }
  11425. return {
  11426. options,
  11427. column: 1,
  11428. line: 1,
  11429. offset: 0,
  11430. originalSource: content,
  11431. source: content,
  11432. inPre: false,
  11433. inVPre: false,
  11434. onWarn: options.onWarn
  11435. };
  11436. }
  11437. function parseChildren(context, mode, ancestors) {
  11438. const parent = last(ancestors);
  11439. const ns = parent ? parent.ns : 0 /* HTML */;
  11440. const nodes = [];
  11441. while (!isEnd(context, mode, ancestors)) {
  11442. const s = context.source;
  11443. let node = undefined;
  11444. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  11445. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  11446. // '{{'
  11447. node = parseInterpolation(context, mode);
  11448. }
  11449. else if (mode === 0 /* DATA */ && s[0] === '<') {
  11450. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  11451. if (s.length === 1) {
  11452. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  11453. }
  11454. else if (s[1] === '!') {
  11455. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  11456. if (startsWith(s, '<!--')) {
  11457. node = parseComment(context);
  11458. }
  11459. else if (startsWith(s, '<!DOCTYPE')) {
  11460. // Ignore DOCTYPE by a limitation.
  11461. node = parseBogusComment(context);
  11462. }
  11463. else if (startsWith(s, '<![CDATA[')) {
  11464. if (ns !== 0 /* HTML */) {
  11465. node = parseCDATA(context, ancestors);
  11466. }
  11467. else {
  11468. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  11469. node = parseBogusComment(context);
  11470. }
  11471. }
  11472. else {
  11473. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  11474. node = parseBogusComment(context);
  11475. }
  11476. }
  11477. else if (s[1] === '/') {
  11478. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  11479. if (s.length === 2) {
  11480. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  11481. }
  11482. else if (s[2] === '>') {
  11483. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  11484. advanceBy(context, 3);
  11485. continue;
  11486. }
  11487. else if (/[a-z]/i.test(s[2])) {
  11488. emitError(context, 23 /* X_INVALID_END_TAG */);
  11489. parseTag(context, 1 /* End */, parent);
  11490. continue;
  11491. }
  11492. else {
  11493. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  11494. node = parseBogusComment(context);
  11495. }
  11496. }
  11497. else if (/[a-z]/i.test(s[1])) {
  11498. node = parseElement(context, ancestors);
  11499. }
  11500. else if (s[1] === '?') {
  11501. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  11502. node = parseBogusComment(context);
  11503. }
  11504. else {
  11505. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  11506. }
  11507. }
  11508. }
  11509. if (!node) {
  11510. node = parseText(context, mode);
  11511. }
  11512. if (isArray(node)) {
  11513. for (let i = 0; i < node.length; i++) {
  11514. pushNode(nodes, node[i]);
  11515. }
  11516. }
  11517. else {
  11518. pushNode(nodes, node);
  11519. }
  11520. }
  11521. // Whitespace handling strategy like v2
  11522. let removedWhitespace = false;
  11523. if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
  11524. const shouldCondense = context.options.whitespace !== 'preserve';
  11525. for (let i = 0; i < nodes.length; i++) {
  11526. const node = nodes[i];
  11527. if (!context.inPre && node.type === 2 /* TEXT */) {
  11528. if (!/[^\t\r\n\f ]/.test(node.content)) {
  11529. const prev = nodes[i - 1];
  11530. const next = nodes[i + 1];
  11531. // Remove if:
  11532. // - the whitespace is the first or last node, or:
  11533. // - (condense mode) the whitespace is adjacent to a comment, or:
  11534. // - (condense mode) the whitespace is between two elements AND contains newline
  11535. if (!prev ||
  11536. !next ||
  11537. (shouldCondense &&
  11538. (prev.type === 3 /* COMMENT */ ||
  11539. next.type === 3 /* COMMENT */ ||
  11540. (prev.type === 1 /* ELEMENT */ &&
  11541. next.type === 1 /* ELEMENT */ &&
  11542. /[\r\n]/.test(node.content))))) {
  11543. removedWhitespace = true;
  11544. nodes[i] = null;
  11545. }
  11546. else {
  11547. // Otherwise, the whitespace is condensed into a single space
  11548. node.content = ' ';
  11549. }
  11550. }
  11551. else if (shouldCondense) {
  11552. // in condense mode, consecutive whitespaces in text are condensed
  11553. // down to a single space.
  11554. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  11555. }
  11556. }
  11557. // Remove comment nodes if desired by configuration.
  11558. else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
  11559. removedWhitespace = true;
  11560. nodes[i] = null;
  11561. }
  11562. }
  11563. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  11564. // remove leading newline per html spec
  11565. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  11566. const first = nodes[0];
  11567. if (first && first.type === 2 /* TEXT */) {
  11568. first.content = first.content.replace(/^\r?\n/, '');
  11569. }
  11570. }
  11571. }
  11572. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  11573. }
  11574. function pushNode(nodes, node) {
  11575. if (node.type === 2 /* TEXT */) {
  11576. const prev = last(nodes);
  11577. // Merge if both this and the previous node are text and those are
  11578. // consecutive. This happens for cases like "a < b".
  11579. if (prev &&
  11580. prev.type === 2 /* TEXT */ &&
  11581. prev.loc.end.offset === node.loc.start.offset) {
  11582. prev.content += node.content;
  11583. prev.loc.end = node.loc.end;
  11584. prev.loc.source += node.loc.source;
  11585. return;
  11586. }
  11587. }
  11588. nodes.push(node);
  11589. }
  11590. function parseCDATA(context, ancestors) {
  11591. advanceBy(context, 9);
  11592. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  11593. if (context.source.length === 0) {
  11594. emitError(context, 6 /* EOF_IN_CDATA */);
  11595. }
  11596. else {
  11597. advanceBy(context, 3);
  11598. }
  11599. return nodes;
  11600. }
  11601. function parseComment(context) {
  11602. const start = getCursor(context);
  11603. let content;
  11604. // Regular comment.
  11605. const match = /--(\!)?>/.exec(context.source);
  11606. if (!match) {
  11607. content = context.source.slice(4);
  11608. advanceBy(context, context.source.length);
  11609. emitError(context, 7 /* EOF_IN_COMMENT */);
  11610. }
  11611. else {
  11612. if (match.index <= 3) {
  11613. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  11614. }
  11615. if (match[1]) {
  11616. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  11617. }
  11618. content = context.source.slice(4, match.index);
  11619. // Advancing with reporting nested comments.
  11620. const s = context.source.slice(0, match.index);
  11621. let prevIndex = 1, nestedIndex = 0;
  11622. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  11623. advanceBy(context, nestedIndex - prevIndex + 1);
  11624. if (nestedIndex + 4 < s.length) {
  11625. emitError(context, 16 /* NESTED_COMMENT */);
  11626. }
  11627. prevIndex = nestedIndex + 1;
  11628. }
  11629. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  11630. }
  11631. return {
  11632. type: 3 /* COMMENT */,
  11633. content,
  11634. loc: getSelection(context, start)
  11635. };
  11636. }
  11637. function parseBogusComment(context) {
  11638. const start = getCursor(context);
  11639. const contentStart = context.source[1] === '?' ? 1 : 2;
  11640. let content;
  11641. const closeIndex = context.source.indexOf('>');
  11642. if (closeIndex === -1) {
  11643. content = context.source.slice(contentStart);
  11644. advanceBy(context, context.source.length);
  11645. }
  11646. else {
  11647. content = context.source.slice(contentStart, closeIndex);
  11648. advanceBy(context, closeIndex + 1);
  11649. }
  11650. return {
  11651. type: 3 /* COMMENT */,
  11652. content,
  11653. loc: getSelection(context, start)
  11654. };
  11655. }
  11656. function parseElement(context, ancestors) {
  11657. // Start tag.
  11658. const wasInPre = context.inPre;
  11659. const wasInVPre = context.inVPre;
  11660. const parent = last(ancestors);
  11661. const element = parseTag(context, 0 /* Start */, parent);
  11662. const isPreBoundary = context.inPre && !wasInPre;
  11663. const isVPreBoundary = context.inVPre && !wasInVPre;
  11664. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  11665. // #4030 self-closing <pre> tag
  11666. if (isPreBoundary) {
  11667. context.inPre = false;
  11668. }
  11669. if (isVPreBoundary) {
  11670. context.inVPre = false;
  11671. }
  11672. return element;
  11673. }
  11674. // Children.
  11675. ancestors.push(element);
  11676. const mode = context.options.getTextMode(element, parent);
  11677. const children = parseChildren(context, mode, ancestors);
  11678. ancestors.pop();
  11679. element.children = children;
  11680. // End tag.
  11681. if (startsWithEndTagOpen(context.source, element.tag)) {
  11682. parseTag(context, 1 /* End */, parent);
  11683. }
  11684. else {
  11685. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  11686. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  11687. const first = children[0];
  11688. if (first && startsWith(first.loc.source, '<!--')) {
  11689. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  11690. }
  11691. }
  11692. }
  11693. element.loc = getSelection(context, element.loc.start);
  11694. if (isPreBoundary) {
  11695. context.inPre = false;
  11696. }
  11697. if (isVPreBoundary) {
  11698. context.inVPre = false;
  11699. }
  11700. return element;
  11701. }
  11702. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  11703. function parseTag(context, type, parent) {
  11704. // Tag open.
  11705. const start = getCursor(context);
  11706. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  11707. const tag = match[1];
  11708. const ns = context.options.getNamespace(tag, parent);
  11709. advanceBy(context, match[0].length);
  11710. advanceSpaces(context);
  11711. // save current state in case we need to re-parse attributes with v-pre
  11712. const cursor = getCursor(context);
  11713. const currentSource = context.source;
  11714. // check <pre> tag
  11715. if (context.options.isPreTag(tag)) {
  11716. context.inPre = true;
  11717. }
  11718. // Attributes.
  11719. let props = parseAttributes(context, type);
  11720. // check v-pre
  11721. if (type === 0 /* Start */ &&
  11722. !context.inVPre &&
  11723. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  11724. context.inVPre = true;
  11725. // reset context
  11726. extend(context, cursor);
  11727. context.source = currentSource;
  11728. // re-parse attrs and filter out v-pre itself
  11729. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  11730. }
  11731. // Tag close.
  11732. let isSelfClosing = false;
  11733. if (context.source.length === 0) {
  11734. emitError(context, 9 /* EOF_IN_TAG */);
  11735. }
  11736. else {
  11737. isSelfClosing = startsWith(context.source, '/>');
  11738. if (type === 1 /* End */ && isSelfClosing) {
  11739. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  11740. }
  11741. advanceBy(context, isSelfClosing ? 2 : 1);
  11742. }
  11743. if (type === 1 /* End */) {
  11744. return;
  11745. }
  11746. let tagType = 0 /* ELEMENT */;
  11747. if (!context.inVPre) {
  11748. if (tag === 'slot') {
  11749. tagType = 2 /* SLOT */;
  11750. }
  11751. else if (tag === 'template') {
  11752. if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  11753. tagType = 3 /* TEMPLATE */;
  11754. }
  11755. }
  11756. else if (isComponent(tag, props, context)) {
  11757. tagType = 1 /* COMPONENT */;
  11758. }
  11759. }
  11760. return {
  11761. type: 1 /* ELEMENT */,
  11762. ns,
  11763. tag,
  11764. tagType,
  11765. props,
  11766. isSelfClosing,
  11767. children: [],
  11768. loc: getSelection(context, start),
  11769. codegenNode: undefined // to be created during transform phase
  11770. };
  11771. }
  11772. function isComponent(tag, props, context) {
  11773. const options = context.options;
  11774. if (options.isCustomElement(tag)) {
  11775. return false;
  11776. }
  11777. if (tag === 'component' ||
  11778. /^[A-Z]/.test(tag) ||
  11779. isCoreComponent(tag) ||
  11780. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  11781. (options.isNativeTag && !options.isNativeTag(tag))) {
  11782. return true;
  11783. }
  11784. // at this point the tag should be a native tag, but check for potential "is"
  11785. // casting
  11786. for (let i = 0; i < props.length; i++) {
  11787. const p = props[i];
  11788. if (p.type === 6 /* ATTRIBUTE */) {
  11789. if (p.name === 'is' && p.value) {
  11790. if (p.value.content.startsWith('vue:')) {
  11791. return true;
  11792. }
  11793. }
  11794. }
  11795. else {
  11796. // directive
  11797. // v-is (TODO Deprecate)
  11798. if (p.name === 'is') {
  11799. return true;
  11800. }
  11801. else if (
  11802. // :is on plain element - only treat as component in compat mode
  11803. p.name === 'bind' &&
  11804. isStaticArgOf(p.arg, 'is') &&
  11805. false &&
  11806. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  11807. return true;
  11808. }
  11809. }
  11810. }
  11811. }
  11812. function parseAttributes(context, type) {
  11813. const props = [];
  11814. const attributeNames = new Set();
  11815. while (context.source.length > 0 &&
  11816. !startsWith(context.source, '>') &&
  11817. !startsWith(context.source, '/>')) {
  11818. if (startsWith(context.source, '/')) {
  11819. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  11820. advanceBy(context, 1);
  11821. advanceSpaces(context);
  11822. continue;
  11823. }
  11824. if (type === 1 /* End */) {
  11825. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  11826. }
  11827. const attr = parseAttribute(context, attributeNames);
  11828. // Trim whitespace between class
  11829. // https://github.com/vuejs/core/issues/4251
  11830. if (attr.type === 6 /* ATTRIBUTE */ &&
  11831. attr.value &&
  11832. attr.name === 'class') {
  11833. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  11834. }
  11835. if (type === 0 /* Start */) {
  11836. props.push(attr);
  11837. }
  11838. if (/^[^\t\r\n\f />]/.test(context.source)) {
  11839. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  11840. }
  11841. advanceSpaces(context);
  11842. }
  11843. return props;
  11844. }
  11845. function parseAttribute(context, nameSet) {
  11846. // Name.
  11847. const start = getCursor(context);
  11848. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  11849. const name = match[0];
  11850. if (nameSet.has(name)) {
  11851. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  11852. }
  11853. nameSet.add(name);
  11854. if (name[0] === '=') {
  11855. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  11856. }
  11857. {
  11858. const pattern = /["'<]/g;
  11859. let m;
  11860. while ((m = pattern.exec(name))) {
  11861. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  11862. }
  11863. }
  11864. advanceBy(context, name.length);
  11865. // Value
  11866. let value = undefined;
  11867. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  11868. advanceSpaces(context);
  11869. advanceBy(context, 1);
  11870. advanceSpaces(context);
  11871. value = parseAttributeValue(context);
  11872. if (!value) {
  11873. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  11874. }
  11875. }
  11876. const loc = getSelection(context, start);
  11877. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  11878. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  11879. let isPropShorthand = startsWith(name, '.');
  11880. let dirName = match[1] ||
  11881. (isPropShorthand || startsWith(name, ':')
  11882. ? 'bind'
  11883. : startsWith(name, '@')
  11884. ? 'on'
  11885. : 'slot');
  11886. let arg;
  11887. if (match[2]) {
  11888. const isSlot = dirName === 'slot';
  11889. const startOffset = name.lastIndexOf(match[2]);
  11890. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  11891. let content = match[2];
  11892. let isStatic = true;
  11893. if (content.startsWith('[')) {
  11894. isStatic = false;
  11895. if (!content.endsWith(']')) {
  11896. emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  11897. content = content.slice(1);
  11898. }
  11899. else {
  11900. content = content.slice(1, content.length - 1);
  11901. }
  11902. }
  11903. else if (isSlot) {
  11904. // #1241 special case for v-slot: vuetify relies extensively on slot
  11905. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  11906. // supports such usage so we are keeping it consistent with 2.x.
  11907. content += match[3] || '';
  11908. }
  11909. arg = {
  11910. type: 4 /* SIMPLE_EXPRESSION */,
  11911. content,
  11912. isStatic,
  11913. constType: isStatic
  11914. ? 3 /* CAN_STRINGIFY */
  11915. : 0 /* NOT_CONSTANT */,
  11916. loc
  11917. };
  11918. }
  11919. if (value && value.isQuoted) {
  11920. const valueLoc = value.loc;
  11921. valueLoc.start.offset++;
  11922. valueLoc.start.column++;
  11923. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  11924. valueLoc.source = valueLoc.source.slice(1, -1);
  11925. }
  11926. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  11927. if (isPropShorthand)
  11928. modifiers.push('prop');
  11929. return {
  11930. type: 7 /* DIRECTIVE */,
  11931. name: dirName,
  11932. exp: value && {
  11933. type: 4 /* SIMPLE_EXPRESSION */,
  11934. content: value.content,
  11935. isStatic: false,
  11936. // Treat as non-constant by default. This can be potentially set to
  11937. // other values by `transformExpression` to make it eligible for hoisting.
  11938. constType: 0 /* NOT_CONSTANT */,
  11939. loc: value.loc
  11940. },
  11941. arg,
  11942. modifiers,
  11943. loc
  11944. };
  11945. }
  11946. // missing directive name or illegal directive name
  11947. if (!context.inVPre && startsWith(name, 'v-')) {
  11948. emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
  11949. }
  11950. return {
  11951. type: 6 /* ATTRIBUTE */,
  11952. name,
  11953. value: value && {
  11954. type: 2 /* TEXT */,
  11955. content: value.content,
  11956. loc: value.loc
  11957. },
  11958. loc
  11959. };
  11960. }
  11961. function parseAttributeValue(context) {
  11962. const start = getCursor(context);
  11963. let content;
  11964. const quote = context.source[0];
  11965. const isQuoted = quote === `"` || quote === `'`;
  11966. if (isQuoted) {
  11967. // Quoted value.
  11968. advanceBy(context, 1);
  11969. const endIndex = context.source.indexOf(quote);
  11970. if (endIndex === -1) {
  11971. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  11972. }
  11973. else {
  11974. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  11975. advanceBy(context, 1);
  11976. }
  11977. }
  11978. else {
  11979. // Unquoted
  11980. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  11981. if (!match) {
  11982. return undefined;
  11983. }
  11984. const unexpectedChars = /["'<=`]/g;
  11985. let m;
  11986. while ((m = unexpectedChars.exec(match[0]))) {
  11987. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  11988. }
  11989. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  11990. }
  11991. return { content, isQuoted, loc: getSelection(context, start) };
  11992. }
  11993. function parseInterpolation(context, mode) {
  11994. const [open, close] = context.options.delimiters;
  11995. const closeIndex = context.source.indexOf(close, open.length);
  11996. if (closeIndex === -1) {
  11997. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  11998. return undefined;
  11999. }
  12000. const start = getCursor(context);
  12001. advanceBy(context, open.length);
  12002. const innerStart = getCursor(context);
  12003. const innerEnd = getCursor(context);
  12004. const rawContentLength = closeIndex - open.length;
  12005. const rawContent = context.source.slice(0, rawContentLength);
  12006. const preTrimContent = parseTextData(context, rawContentLength, mode);
  12007. const content = preTrimContent.trim();
  12008. const startOffset = preTrimContent.indexOf(content);
  12009. if (startOffset > 0) {
  12010. advancePositionWithMutation(innerStart, rawContent, startOffset);
  12011. }
  12012. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  12013. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  12014. advanceBy(context, close.length);
  12015. return {
  12016. type: 5 /* INTERPOLATION */,
  12017. content: {
  12018. type: 4 /* SIMPLE_EXPRESSION */,
  12019. isStatic: false,
  12020. // Set `isConstant` to false by default and will decide in transformExpression
  12021. constType: 0 /* NOT_CONSTANT */,
  12022. content,
  12023. loc: getSelection(context, innerStart, innerEnd)
  12024. },
  12025. loc: getSelection(context, start)
  12026. };
  12027. }
  12028. function parseText(context, mode) {
  12029. const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  12030. let endIndex = context.source.length;
  12031. for (let i = 0; i < endTokens.length; i++) {
  12032. const index = context.source.indexOf(endTokens[i], 1);
  12033. if (index !== -1 && endIndex > index) {
  12034. endIndex = index;
  12035. }
  12036. }
  12037. const start = getCursor(context);
  12038. const content = parseTextData(context, endIndex, mode);
  12039. return {
  12040. type: 2 /* TEXT */,
  12041. content,
  12042. loc: getSelection(context, start)
  12043. };
  12044. }
  12045. /**
  12046. * Get text data with a given length from the current location.
  12047. * This translates HTML entities in the text data.
  12048. */
  12049. function parseTextData(context, length, mode) {
  12050. const rawText = context.source.slice(0, length);
  12051. advanceBy(context, length);
  12052. if (mode === 2 /* RAWTEXT */ ||
  12053. mode === 3 /* CDATA */ ||
  12054. !rawText.includes('&')) {
  12055. return rawText;
  12056. }
  12057. else {
  12058. // DATA or RCDATA containing "&"". Entity decoding required.
  12059. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  12060. }
  12061. }
  12062. function getCursor(context) {
  12063. const { column, line, offset } = context;
  12064. return { column, line, offset };
  12065. }
  12066. function getSelection(context, start, end) {
  12067. end = end || getCursor(context);
  12068. return {
  12069. start,
  12070. end,
  12071. source: context.originalSource.slice(start.offset, end.offset)
  12072. };
  12073. }
  12074. function last(xs) {
  12075. return xs[xs.length - 1];
  12076. }
  12077. function startsWith(source, searchString) {
  12078. return source.startsWith(searchString);
  12079. }
  12080. function advanceBy(context, numberOfCharacters) {
  12081. const { source } = context;
  12082. advancePositionWithMutation(context, source, numberOfCharacters);
  12083. context.source = source.slice(numberOfCharacters);
  12084. }
  12085. function advanceSpaces(context) {
  12086. const match = /^[\t\r\n\f ]+/.exec(context.source);
  12087. if (match) {
  12088. advanceBy(context, match[0].length);
  12089. }
  12090. }
  12091. function getNewPosition(context, start, numberOfCharacters) {
  12092. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  12093. }
  12094. function emitError(context, code, offset, loc = getCursor(context)) {
  12095. if (offset) {
  12096. loc.offset += offset;
  12097. loc.column += offset;
  12098. }
  12099. context.options.onError(createCompilerError(code, {
  12100. start: loc,
  12101. end: loc,
  12102. source: ''
  12103. }));
  12104. }
  12105. function isEnd(context, mode, ancestors) {
  12106. const s = context.source;
  12107. switch (mode) {
  12108. case 0 /* DATA */:
  12109. if (startsWith(s, '</')) {
  12110. // TODO: probably bad performance
  12111. for (let i = ancestors.length - 1; i >= 0; --i) {
  12112. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  12113. return true;
  12114. }
  12115. }
  12116. }
  12117. break;
  12118. case 1 /* RCDATA */:
  12119. case 2 /* RAWTEXT */: {
  12120. const parent = last(ancestors);
  12121. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  12122. return true;
  12123. }
  12124. break;
  12125. }
  12126. case 3 /* CDATA */:
  12127. if (startsWith(s, ']]>')) {
  12128. return true;
  12129. }
  12130. break;
  12131. }
  12132. return !s;
  12133. }
  12134. function startsWithEndTagOpen(source, tag) {
  12135. return (startsWith(source, '</') &&
  12136. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  12137. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  12138. }
  12139. function hoistStatic(root, context) {
  12140. walk(root, context,
  12141. // Root node is unfortunately non-hoistable due to potential parent
  12142. // fallthrough attributes.
  12143. isSingleElementRoot(root, root.children[0]));
  12144. }
  12145. function isSingleElementRoot(root, child) {
  12146. const { children } = root;
  12147. return (children.length === 1 &&
  12148. child.type === 1 /* ELEMENT */ &&
  12149. !isSlotOutlet(child));
  12150. }
  12151. function walk(node, context, doNotHoistNode = false) {
  12152. const { children } = node;
  12153. const originalCount = children.length;
  12154. let hoistedCount = 0;
  12155. for (let i = 0; i < children.length; i++) {
  12156. const child = children[i];
  12157. // only plain elements & text calls are eligible for hoisting.
  12158. if (child.type === 1 /* ELEMENT */ &&
  12159. child.tagType === 0 /* ELEMENT */) {
  12160. const constantType = doNotHoistNode
  12161. ? 0 /* NOT_CONSTANT */
  12162. : getConstantType(child, context);
  12163. if (constantType > 0 /* NOT_CONSTANT */) {
  12164. if (constantType >= 2 /* CAN_HOIST */) {
  12165. child.codegenNode.patchFlag =
  12166. -1 /* HOISTED */ + (` /* HOISTED */` );
  12167. child.codegenNode = context.hoist(child.codegenNode);
  12168. hoistedCount++;
  12169. continue;
  12170. }
  12171. }
  12172. else {
  12173. // node may contain dynamic children, but its props may be eligible for
  12174. // hoisting.
  12175. const codegenNode = child.codegenNode;
  12176. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12177. const flag = getPatchFlag(codegenNode);
  12178. if ((!flag ||
  12179. flag === 512 /* NEED_PATCH */ ||
  12180. flag === 1 /* TEXT */) &&
  12181. getGeneratedPropsConstantType(child, context) >=
  12182. 2 /* CAN_HOIST */) {
  12183. const props = getNodeProps(child);
  12184. if (props) {
  12185. codegenNode.props = context.hoist(props);
  12186. }
  12187. }
  12188. if (codegenNode.dynamicProps) {
  12189. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  12190. }
  12191. }
  12192. }
  12193. }
  12194. else if (child.type === 12 /* TEXT_CALL */ &&
  12195. getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
  12196. child.codegenNode = context.hoist(child.codegenNode);
  12197. hoistedCount++;
  12198. }
  12199. // walk further
  12200. if (child.type === 1 /* ELEMENT */) {
  12201. const isComponent = child.tagType === 1 /* COMPONENT */;
  12202. if (isComponent) {
  12203. context.scopes.vSlot++;
  12204. }
  12205. walk(child, context);
  12206. if (isComponent) {
  12207. context.scopes.vSlot--;
  12208. }
  12209. }
  12210. else if (child.type === 11 /* FOR */) {
  12211. // Do not hoist v-for single child because it has to be a block
  12212. walk(child, context, child.children.length === 1);
  12213. }
  12214. else if (child.type === 9 /* IF */) {
  12215. for (let i = 0; i < child.branches.length; i++) {
  12216. // Do not hoist v-if single child because it has to be a block
  12217. walk(child.branches[i], context, child.branches[i].children.length === 1);
  12218. }
  12219. }
  12220. }
  12221. if (hoistedCount && context.transformHoist) {
  12222. context.transformHoist(children, context, node);
  12223. }
  12224. // all children were hoisted - the entire children array is hoistable.
  12225. if (hoistedCount &&
  12226. hoistedCount === originalCount &&
  12227. node.type === 1 /* ELEMENT */ &&
  12228. node.tagType === 0 /* ELEMENT */ &&
  12229. node.codegenNode &&
  12230. node.codegenNode.type === 13 /* VNODE_CALL */ &&
  12231. isArray(node.codegenNode.children)) {
  12232. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  12233. }
  12234. }
  12235. function getConstantType(node, context) {
  12236. const { constantCache } = context;
  12237. switch (node.type) {
  12238. case 1 /* ELEMENT */:
  12239. if (node.tagType !== 0 /* ELEMENT */) {
  12240. return 0 /* NOT_CONSTANT */;
  12241. }
  12242. const cached = constantCache.get(node);
  12243. if (cached !== undefined) {
  12244. return cached;
  12245. }
  12246. const codegenNode = node.codegenNode;
  12247. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  12248. return 0 /* NOT_CONSTANT */;
  12249. }
  12250. if (codegenNode.isBlock &&
  12251. node.tag !== 'svg' &&
  12252. node.tag !== 'foreignObject') {
  12253. return 0 /* NOT_CONSTANT */;
  12254. }
  12255. const flag = getPatchFlag(codegenNode);
  12256. if (!flag) {
  12257. let returnType = 3 /* CAN_STRINGIFY */;
  12258. // Element itself has no patch flag. However we still need to check:
  12259. // 1. Even for a node with no patch flag, it is possible for it to contain
  12260. // non-hoistable expressions that refers to scope variables, e.g. compiler
  12261. // injected keys or cached event handlers. Therefore we need to always
  12262. // check the codegenNode's props to be sure.
  12263. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  12264. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  12265. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12266. return 0 /* NOT_CONSTANT */;
  12267. }
  12268. if (generatedPropsType < returnType) {
  12269. returnType = generatedPropsType;
  12270. }
  12271. // 2. its children.
  12272. for (let i = 0; i < node.children.length; i++) {
  12273. const childType = getConstantType(node.children[i], context);
  12274. if (childType === 0 /* NOT_CONSTANT */) {
  12275. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12276. return 0 /* NOT_CONSTANT */;
  12277. }
  12278. if (childType < returnType) {
  12279. returnType = childType;
  12280. }
  12281. }
  12282. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  12283. // type, check if any of the props can cause the type to be lowered
  12284. // we can skip can_patch because it's guaranteed by the absence of a
  12285. // patchFlag.
  12286. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  12287. for (let i = 0; i < node.props.length; i++) {
  12288. const p = node.props[i];
  12289. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  12290. const expType = getConstantType(p.exp, context);
  12291. if (expType === 0 /* NOT_CONSTANT */) {
  12292. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12293. return 0 /* NOT_CONSTANT */;
  12294. }
  12295. if (expType < returnType) {
  12296. returnType = expType;
  12297. }
  12298. }
  12299. }
  12300. }
  12301. // only svg/foreignObject could be block here, however if they are
  12302. // static then they don't need to be blocks since there will be no
  12303. // nested updates.
  12304. if (codegenNode.isBlock) {
  12305. context.removeHelper(OPEN_BLOCK);
  12306. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  12307. codegenNode.isBlock = false;
  12308. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  12309. }
  12310. constantCache.set(node, returnType);
  12311. return returnType;
  12312. }
  12313. else {
  12314. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12315. return 0 /* NOT_CONSTANT */;
  12316. }
  12317. case 2 /* TEXT */:
  12318. case 3 /* COMMENT */:
  12319. return 3 /* CAN_STRINGIFY */;
  12320. case 9 /* IF */:
  12321. case 11 /* FOR */:
  12322. case 10 /* IF_BRANCH */:
  12323. return 0 /* NOT_CONSTANT */;
  12324. case 5 /* INTERPOLATION */:
  12325. case 12 /* TEXT_CALL */:
  12326. return getConstantType(node.content, context);
  12327. case 4 /* SIMPLE_EXPRESSION */:
  12328. return node.constType;
  12329. case 8 /* COMPOUND_EXPRESSION */:
  12330. let returnType = 3 /* CAN_STRINGIFY */;
  12331. for (let i = 0; i < node.children.length; i++) {
  12332. const child = node.children[i];
  12333. if (isString(child) || isSymbol(child)) {
  12334. continue;
  12335. }
  12336. const childType = getConstantType(child, context);
  12337. if (childType === 0 /* NOT_CONSTANT */) {
  12338. return 0 /* NOT_CONSTANT */;
  12339. }
  12340. else if (childType < returnType) {
  12341. returnType = childType;
  12342. }
  12343. }
  12344. return returnType;
  12345. default:
  12346. return 0 /* NOT_CONSTANT */;
  12347. }
  12348. }
  12349. const allowHoistedHelperSet = new Set([
  12350. NORMALIZE_CLASS,
  12351. NORMALIZE_STYLE,
  12352. NORMALIZE_PROPS,
  12353. GUARD_REACTIVE_PROPS
  12354. ]);
  12355. function getConstantTypeOfHelperCall(value, context) {
  12356. if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
  12357. !isString(value.callee) &&
  12358. allowHoistedHelperSet.has(value.callee)) {
  12359. const arg = value.arguments[0];
  12360. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12361. return getConstantType(arg, context);
  12362. }
  12363. else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
  12364. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  12365. return getConstantTypeOfHelperCall(arg, context);
  12366. }
  12367. }
  12368. return 0 /* NOT_CONSTANT */;
  12369. }
  12370. function getGeneratedPropsConstantType(node, context) {
  12371. let returnType = 3 /* CAN_STRINGIFY */;
  12372. const props = getNodeProps(node);
  12373. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  12374. const { properties } = props;
  12375. for (let i = 0; i < properties.length; i++) {
  12376. const { key, value } = properties[i];
  12377. const keyType = getConstantType(key, context);
  12378. if (keyType === 0 /* NOT_CONSTANT */) {
  12379. return keyType;
  12380. }
  12381. if (keyType < returnType) {
  12382. returnType = keyType;
  12383. }
  12384. let valueType;
  12385. if (value.type === 4 /* SIMPLE_EXPRESSION */) {
  12386. valueType = getConstantType(value, context);
  12387. }
  12388. else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
  12389. // some helper calls can be hoisted,
  12390. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  12391. // in this case we need to respect the ConstantType of the helper's arguments
  12392. valueType = getConstantTypeOfHelperCall(value, context);
  12393. }
  12394. else {
  12395. valueType = 0 /* NOT_CONSTANT */;
  12396. }
  12397. if (valueType === 0 /* NOT_CONSTANT */) {
  12398. return valueType;
  12399. }
  12400. if (valueType < returnType) {
  12401. returnType = valueType;
  12402. }
  12403. }
  12404. }
  12405. return returnType;
  12406. }
  12407. function getNodeProps(node) {
  12408. const codegenNode = node.codegenNode;
  12409. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12410. return codegenNode.props;
  12411. }
  12412. }
  12413. function getPatchFlag(node) {
  12414. const flag = node.patchFlag;
  12415. return flag ? parseInt(flag, 10) : undefined;
  12416. }
  12417. 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 }) {
  12418. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  12419. const context = {
  12420. // options
  12421. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  12422. prefixIdentifiers,
  12423. hoistStatic,
  12424. cacheHandlers,
  12425. nodeTransforms,
  12426. directiveTransforms,
  12427. transformHoist,
  12428. isBuiltInComponent,
  12429. isCustomElement,
  12430. expressionPlugins,
  12431. scopeId,
  12432. slotted,
  12433. ssr,
  12434. inSSR,
  12435. ssrCssVars,
  12436. bindingMetadata,
  12437. inline,
  12438. isTS,
  12439. onError,
  12440. onWarn,
  12441. compatConfig,
  12442. // state
  12443. root,
  12444. helpers: new Map(),
  12445. components: new Set(),
  12446. directives: new Set(),
  12447. hoists: [],
  12448. imports: [],
  12449. constantCache: new Map(),
  12450. temps: 0,
  12451. cached: 0,
  12452. identifiers: Object.create(null),
  12453. scopes: {
  12454. vFor: 0,
  12455. vSlot: 0,
  12456. vPre: 0,
  12457. vOnce: 0
  12458. },
  12459. parent: null,
  12460. currentNode: root,
  12461. childIndex: 0,
  12462. inVOnce: false,
  12463. // methods
  12464. helper(name) {
  12465. const count = context.helpers.get(name) || 0;
  12466. context.helpers.set(name, count + 1);
  12467. return name;
  12468. },
  12469. removeHelper(name) {
  12470. const count = context.helpers.get(name);
  12471. if (count) {
  12472. const currentCount = count - 1;
  12473. if (!currentCount) {
  12474. context.helpers.delete(name);
  12475. }
  12476. else {
  12477. context.helpers.set(name, currentCount);
  12478. }
  12479. }
  12480. },
  12481. helperString(name) {
  12482. return `_${helperNameMap[context.helper(name)]}`;
  12483. },
  12484. replaceNode(node) {
  12485. /* istanbul ignore if */
  12486. {
  12487. if (!context.currentNode) {
  12488. throw new Error(`Node being replaced is already removed.`);
  12489. }
  12490. if (!context.parent) {
  12491. throw new Error(`Cannot replace root node.`);
  12492. }
  12493. }
  12494. context.parent.children[context.childIndex] = context.currentNode = node;
  12495. },
  12496. removeNode(node) {
  12497. if (!context.parent) {
  12498. throw new Error(`Cannot remove root node.`);
  12499. }
  12500. const list = context.parent.children;
  12501. const removalIndex = node
  12502. ? list.indexOf(node)
  12503. : context.currentNode
  12504. ? context.childIndex
  12505. : -1;
  12506. /* istanbul ignore if */
  12507. if (removalIndex < 0) {
  12508. throw new Error(`node being removed is not a child of current parent`);
  12509. }
  12510. if (!node || node === context.currentNode) {
  12511. // current node removed
  12512. context.currentNode = null;
  12513. context.onNodeRemoved();
  12514. }
  12515. else {
  12516. // sibling node removed
  12517. if (context.childIndex > removalIndex) {
  12518. context.childIndex--;
  12519. context.onNodeRemoved();
  12520. }
  12521. }
  12522. context.parent.children.splice(removalIndex, 1);
  12523. },
  12524. onNodeRemoved: () => { },
  12525. addIdentifiers(exp) {
  12526. },
  12527. removeIdentifiers(exp) {
  12528. },
  12529. hoist(exp) {
  12530. if (isString(exp))
  12531. exp = createSimpleExpression(exp);
  12532. context.hoists.push(exp);
  12533. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  12534. identifier.hoisted = exp;
  12535. return identifier;
  12536. },
  12537. cache(exp, isVNode = false) {
  12538. return createCacheExpression(context.cached++, exp, isVNode);
  12539. }
  12540. };
  12541. return context;
  12542. }
  12543. function transform(root, options) {
  12544. const context = createTransformContext(root, options);
  12545. traverseNode(root, context);
  12546. if (options.hoistStatic) {
  12547. hoistStatic(root, context);
  12548. }
  12549. if (!options.ssr) {
  12550. createRootCodegen(root, context);
  12551. }
  12552. // finalize meta information
  12553. root.helpers = [...context.helpers.keys()];
  12554. root.components = [...context.components];
  12555. root.directives = [...context.directives];
  12556. root.imports = context.imports;
  12557. root.hoists = context.hoists;
  12558. root.temps = context.temps;
  12559. root.cached = context.cached;
  12560. }
  12561. function createRootCodegen(root, context) {
  12562. const { helper } = context;
  12563. const { children } = root;
  12564. if (children.length === 1) {
  12565. const child = children[0];
  12566. // if the single child is an element, turn it into a block.
  12567. if (isSingleElementRoot(root, child) && child.codegenNode) {
  12568. // single element root is never hoisted so codegenNode will never be
  12569. // SimpleExpressionNode
  12570. const codegenNode = child.codegenNode;
  12571. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12572. makeBlock(codegenNode, context);
  12573. }
  12574. root.codegenNode = codegenNode;
  12575. }
  12576. else {
  12577. // - single <slot/>, IfNode, ForNode: already blocks.
  12578. // - single text node: always patched.
  12579. // root codegen falls through via genNode()
  12580. root.codegenNode = child;
  12581. }
  12582. }
  12583. else if (children.length > 1) {
  12584. // root has multiple nodes - return a fragment block.
  12585. let patchFlag = 64 /* STABLE_FRAGMENT */;
  12586. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  12587. // check if the fragment actually contains a single valid child with
  12588. // the rest being comments
  12589. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  12590. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  12591. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  12592. }
  12593. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
  12594. }
  12595. else ;
  12596. }
  12597. function traverseChildren(parent, context) {
  12598. let i = 0;
  12599. const nodeRemoved = () => {
  12600. i--;
  12601. };
  12602. for (; i < parent.children.length; i++) {
  12603. const child = parent.children[i];
  12604. if (isString(child))
  12605. continue;
  12606. context.parent = parent;
  12607. context.childIndex = i;
  12608. context.onNodeRemoved = nodeRemoved;
  12609. traverseNode(child, context);
  12610. }
  12611. }
  12612. function traverseNode(node, context) {
  12613. context.currentNode = node;
  12614. // apply transform plugins
  12615. const { nodeTransforms } = context;
  12616. const exitFns = [];
  12617. for (let i = 0; i < nodeTransforms.length; i++) {
  12618. const onExit = nodeTransforms[i](node, context);
  12619. if (onExit) {
  12620. if (isArray(onExit)) {
  12621. exitFns.push(...onExit);
  12622. }
  12623. else {
  12624. exitFns.push(onExit);
  12625. }
  12626. }
  12627. if (!context.currentNode) {
  12628. // node was removed
  12629. return;
  12630. }
  12631. else {
  12632. // node may have been replaced
  12633. node = context.currentNode;
  12634. }
  12635. }
  12636. switch (node.type) {
  12637. case 3 /* COMMENT */:
  12638. if (!context.ssr) {
  12639. // inject import for the Comment symbol, which is needed for creating
  12640. // comment nodes with `createVNode`
  12641. context.helper(CREATE_COMMENT);
  12642. }
  12643. break;
  12644. case 5 /* INTERPOLATION */:
  12645. // no need to traverse, but we need to inject toString helper
  12646. if (!context.ssr) {
  12647. context.helper(TO_DISPLAY_STRING);
  12648. }
  12649. break;
  12650. // for container types, further traverse downwards
  12651. case 9 /* IF */:
  12652. for (let i = 0; i < node.branches.length; i++) {
  12653. traverseNode(node.branches[i], context);
  12654. }
  12655. break;
  12656. case 10 /* IF_BRANCH */:
  12657. case 11 /* FOR */:
  12658. case 1 /* ELEMENT */:
  12659. case 0 /* ROOT */:
  12660. traverseChildren(node, context);
  12661. break;
  12662. }
  12663. // exit transforms
  12664. context.currentNode = node;
  12665. let i = exitFns.length;
  12666. while (i--) {
  12667. exitFns[i]();
  12668. }
  12669. }
  12670. function createStructuralDirectiveTransform(name, fn) {
  12671. const matches = isString(name)
  12672. ? (n) => n === name
  12673. : (n) => name.test(n);
  12674. return (node, context) => {
  12675. if (node.type === 1 /* ELEMENT */) {
  12676. const { props } = node;
  12677. // structural directive transforms are not concerned with slots
  12678. // as they are handled separately in vSlot.ts
  12679. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  12680. return;
  12681. }
  12682. const exitFns = [];
  12683. for (let i = 0; i < props.length; i++) {
  12684. const prop = props[i];
  12685. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  12686. // structural directives are removed to avoid infinite recursion
  12687. // also we remove them *before* applying so that it can further
  12688. // traverse itself in case it moves the node around
  12689. props.splice(i, 1);
  12690. i--;
  12691. const onExit = fn(node, prop, context);
  12692. if (onExit)
  12693. exitFns.push(onExit);
  12694. }
  12695. }
  12696. return exitFns;
  12697. }
  12698. };
  12699. }
  12700. const PURE_ANNOTATION = `/*#__PURE__*/`;
  12701. 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 }) {
  12702. const context = {
  12703. mode,
  12704. prefixIdentifiers,
  12705. sourceMap,
  12706. filename,
  12707. scopeId,
  12708. optimizeImports,
  12709. runtimeGlobalName,
  12710. runtimeModuleName,
  12711. ssrRuntimeModuleName,
  12712. ssr,
  12713. isTS,
  12714. inSSR,
  12715. source: ast.loc.source,
  12716. code: ``,
  12717. column: 1,
  12718. line: 1,
  12719. offset: 0,
  12720. indentLevel: 0,
  12721. pure: false,
  12722. map: undefined,
  12723. helper(key) {
  12724. return `_${helperNameMap[key]}`;
  12725. },
  12726. push(code, node) {
  12727. context.code += code;
  12728. },
  12729. indent() {
  12730. newline(++context.indentLevel);
  12731. },
  12732. deindent(withoutNewLine = false) {
  12733. if (withoutNewLine) {
  12734. --context.indentLevel;
  12735. }
  12736. else {
  12737. newline(--context.indentLevel);
  12738. }
  12739. },
  12740. newline() {
  12741. newline(context.indentLevel);
  12742. }
  12743. };
  12744. function newline(n) {
  12745. context.push('\n' + ` `.repeat(n));
  12746. }
  12747. return context;
  12748. }
  12749. function generate(ast, options = {}) {
  12750. const context = createCodegenContext(ast, options);
  12751. if (options.onContextCreated)
  12752. options.onContextCreated(context);
  12753. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  12754. const hasHelpers = ast.helpers.length > 0;
  12755. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  12756. // preambles
  12757. // in setup() inline mode, the preamble is generated in a sub context
  12758. // and returned separately.
  12759. const preambleContext = context;
  12760. {
  12761. genFunctionPreamble(ast, preambleContext);
  12762. }
  12763. // enter render function
  12764. const functionName = ssr ? `ssrRender` : `render`;
  12765. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  12766. const signature = args.join(', ');
  12767. {
  12768. push(`function ${functionName}(${signature}) {`);
  12769. }
  12770. indent();
  12771. if (useWithBlock) {
  12772. push(`with (_ctx) {`);
  12773. indent();
  12774. // function mode const declarations should be inside with block
  12775. // also they should be renamed to avoid collision with user properties
  12776. if (hasHelpers) {
  12777. push(`const { ${ast.helpers
  12778. .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
  12779. .join(', ')} } = _Vue`);
  12780. push(`\n`);
  12781. newline();
  12782. }
  12783. }
  12784. // generate asset resolution statements
  12785. if (ast.components.length) {
  12786. genAssets(ast.components, 'component', context);
  12787. if (ast.directives.length || ast.temps > 0) {
  12788. newline();
  12789. }
  12790. }
  12791. if (ast.directives.length) {
  12792. genAssets(ast.directives, 'directive', context);
  12793. if (ast.temps > 0) {
  12794. newline();
  12795. }
  12796. }
  12797. if (ast.temps > 0) {
  12798. push(`let `);
  12799. for (let i = 0; i < ast.temps; i++) {
  12800. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  12801. }
  12802. }
  12803. if (ast.components.length || ast.directives.length || ast.temps) {
  12804. push(`\n`);
  12805. newline();
  12806. }
  12807. // generate the VNode tree expression
  12808. if (!ssr) {
  12809. push(`return `);
  12810. }
  12811. if (ast.codegenNode) {
  12812. genNode(ast.codegenNode, context);
  12813. }
  12814. else {
  12815. push(`null`);
  12816. }
  12817. if (useWithBlock) {
  12818. deindent();
  12819. push(`}`);
  12820. }
  12821. deindent();
  12822. push(`}`);
  12823. return {
  12824. ast,
  12825. code: context.code,
  12826. preamble: ``,
  12827. // SourceMapGenerator does have toJSON() method but it's not in the types
  12828. map: context.map ? context.map.toJSON() : undefined
  12829. };
  12830. }
  12831. function genFunctionPreamble(ast, context) {
  12832. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  12833. const VueBinding = runtimeGlobalName;
  12834. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  12835. // Generate const declaration for helpers
  12836. // In prefix mode, we place the const declaration at top so it's done
  12837. // only once; But if we not prefixing, we place the declaration inside the
  12838. // with block so it doesn't incur the `in` check cost for every helper access.
  12839. if (ast.helpers.length > 0) {
  12840. {
  12841. // "with" mode.
  12842. // save Vue in a separate variable to avoid collision
  12843. push(`const _Vue = ${VueBinding}\n`);
  12844. // in "with" mode, helpers are declared inside the with block to avoid
  12845. // has check cost, but hoists are lifted out of the function - we need
  12846. // to provide the helper here.
  12847. if (ast.hoists.length) {
  12848. const staticHelpers = [
  12849. CREATE_VNODE,
  12850. CREATE_ELEMENT_VNODE,
  12851. CREATE_COMMENT,
  12852. CREATE_TEXT,
  12853. CREATE_STATIC
  12854. ]
  12855. .filter(helper => ast.helpers.includes(helper))
  12856. .map(aliasHelper)
  12857. .join(', ');
  12858. push(`const { ${staticHelpers} } = _Vue\n`);
  12859. }
  12860. }
  12861. }
  12862. genHoists(ast.hoists, context);
  12863. newline();
  12864. push(`return `);
  12865. }
  12866. function genAssets(assets, type, { helper, push, newline, isTS }) {
  12867. const resolver = helper(type === 'component'
  12868. ? RESOLVE_COMPONENT
  12869. : RESOLVE_DIRECTIVE);
  12870. for (let i = 0; i < assets.length; i++) {
  12871. let id = assets[i];
  12872. // potential component implicit self-reference inferred from SFC filename
  12873. const maybeSelfReference = id.endsWith('__self');
  12874. if (maybeSelfReference) {
  12875. id = id.slice(0, -6);
  12876. }
  12877. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  12878. if (i < assets.length - 1) {
  12879. newline();
  12880. }
  12881. }
  12882. }
  12883. function genHoists(hoists, context) {
  12884. if (!hoists.length) {
  12885. return;
  12886. }
  12887. context.pure = true;
  12888. const { push, newline, helper, scopeId, mode } = context;
  12889. newline();
  12890. for (let i = 0; i < hoists.length; i++) {
  12891. const exp = hoists[i];
  12892. if (exp) {
  12893. push(`const _hoisted_${i + 1} = ${``}`);
  12894. genNode(exp, context);
  12895. newline();
  12896. }
  12897. }
  12898. context.pure = false;
  12899. }
  12900. function isText$1(n) {
  12901. return (isString(n) ||
  12902. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  12903. n.type === 2 /* TEXT */ ||
  12904. n.type === 5 /* INTERPOLATION */ ||
  12905. n.type === 8 /* COMPOUND_EXPRESSION */);
  12906. }
  12907. function genNodeListAsArray(nodes, context) {
  12908. const multilines = nodes.length > 3 ||
  12909. (nodes.some(n => isArray(n) || !isText$1(n)));
  12910. context.push(`[`);
  12911. multilines && context.indent();
  12912. genNodeList(nodes, context, multilines);
  12913. multilines && context.deindent();
  12914. context.push(`]`);
  12915. }
  12916. function genNodeList(nodes, context, multilines = false, comma = true) {
  12917. const { push, newline } = context;
  12918. for (let i = 0; i < nodes.length; i++) {
  12919. const node = nodes[i];
  12920. if (isString(node)) {
  12921. push(node);
  12922. }
  12923. else if (isArray(node)) {
  12924. genNodeListAsArray(node, context);
  12925. }
  12926. else {
  12927. genNode(node, context);
  12928. }
  12929. if (i < nodes.length - 1) {
  12930. if (multilines) {
  12931. comma && push(',');
  12932. newline();
  12933. }
  12934. else {
  12935. comma && push(', ');
  12936. }
  12937. }
  12938. }
  12939. }
  12940. function genNode(node, context) {
  12941. if (isString(node)) {
  12942. context.push(node);
  12943. return;
  12944. }
  12945. if (isSymbol(node)) {
  12946. context.push(context.helper(node));
  12947. return;
  12948. }
  12949. switch (node.type) {
  12950. case 1 /* ELEMENT */:
  12951. case 9 /* IF */:
  12952. case 11 /* FOR */:
  12953. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  12954. `Apply appropriate transforms first.`);
  12955. genNode(node.codegenNode, context);
  12956. break;
  12957. case 2 /* TEXT */:
  12958. genText(node, context);
  12959. break;
  12960. case 4 /* SIMPLE_EXPRESSION */:
  12961. genExpression(node, context);
  12962. break;
  12963. case 5 /* INTERPOLATION */:
  12964. genInterpolation(node, context);
  12965. break;
  12966. case 12 /* TEXT_CALL */:
  12967. genNode(node.codegenNode, context);
  12968. break;
  12969. case 8 /* COMPOUND_EXPRESSION */:
  12970. genCompoundExpression(node, context);
  12971. break;
  12972. case 3 /* COMMENT */:
  12973. genComment(node, context);
  12974. break;
  12975. case 13 /* VNODE_CALL */:
  12976. genVNodeCall(node, context);
  12977. break;
  12978. case 14 /* JS_CALL_EXPRESSION */:
  12979. genCallExpression(node, context);
  12980. break;
  12981. case 15 /* JS_OBJECT_EXPRESSION */:
  12982. genObjectExpression(node, context);
  12983. break;
  12984. case 17 /* JS_ARRAY_EXPRESSION */:
  12985. genArrayExpression(node, context);
  12986. break;
  12987. case 18 /* JS_FUNCTION_EXPRESSION */:
  12988. genFunctionExpression(node, context);
  12989. break;
  12990. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  12991. genConditionalExpression(node, context);
  12992. break;
  12993. case 20 /* JS_CACHE_EXPRESSION */:
  12994. genCacheExpression(node, context);
  12995. break;
  12996. case 21 /* JS_BLOCK_STATEMENT */:
  12997. genNodeList(node.body, context, true, false);
  12998. break;
  12999. // SSR only types
  13000. case 22 /* JS_TEMPLATE_LITERAL */:
  13001. break;
  13002. case 23 /* JS_IF_STATEMENT */:
  13003. break;
  13004. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  13005. break;
  13006. case 25 /* JS_SEQUENCE_EXPRESSION */:
  13007. break;
  13008. case 26 /* JS_RETURN_STATEMENT */:
  13009. break;
  13010. /* istanbul ignore next */
  13011. case 10 /* IF_BRANCH */:
  13012. // noop
  13013. break;
  13014. default:
  13015. {
  13016. assert(false, `unhandled codegen node type: ${node.type}`);
  13017. // make sure we exhaust all possible types
  13018. const exhaustiveCheck = node;
  13019. return exhaustiveCheck;
  13020. }
  13021. }
  13022. }
  13023. function genText(node, context) {
  13024. context.push(JSON.stringify(node.content), node);
  13025. }
  13026. function genExpression(node, context) {
  13027. const { content, isStatic } = node;
  13028. context.push(isStatic ? JSON.stringify(content) : content, node);
  13029. }
  13030. function genInterpolation(node, context) {
  13031. const { push, helper, pure } = context;
  13032. if (pure)
  13033. push(PURE_ANNOTATION);
  13034. push(`${helper(TO_DISPLAY_STRING)}(`);
  13035. genNode(node.content, context);
  13036. push(`)`);
  13037. }
  13038. function genCompoundExpression(node, context) {
  13039. for (let i = 0; i < node.children.length; i++) {
  13040. const child = node.children[i];
  13041. if (isString(child)) {
  13042. context.push(child);
  13043. }
  13044. else {
  13045. genNode(child, context);
  13046. }
  13047. }
  13048. }
  13049. function genExpressionAsPropertyKey(node, context) {
  13050. const { push } = context;
  13051. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  13052. push(`[`);
  13053. genCompoundExpression(node, context);
  13054. push(`]`);
  13055. }
  13056. else if (node.isStatic) {
  13057. // only quote keys if necessary
  13058. const text = isSimpleIdentifier(node.content)
  13059. ? node.content
  13060. : JSON.stringify(node.content);
  13061. push(text, node);
  13062. }
  13063. else {
  13064. push(`[${node.content}]`, node);
  13065. }
  13066. }
  13067. function genComment(node, context) {
  13068. const { push, helper, pure } = context;
  13069. if (pure) {
  13070. push(PURE_ANNOTATION);
  13071. }
  13072. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  13073. }
  13074. function genVNodeCall(node, context) {
  13075. const { push, helper, pure } = context;
  13076. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  13077. if (directives) {
  13078. push(helper(WITH_DIRECTIVES) + `(`);
  13079. }
  13080. if (isBlock) {
  13081. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  13082. }
  13083. if (pure) {
  13084. push(PURE_ANNOTATION);
  13085. }
  13086. const callHelper = isBlock
  13087. ? getVNodeBlockHelper(context.inSSR, isComponent)
  13088. : getVNodeHelper(context.inSSR, isComponent);
  13089. push(helper(callHelper) + `(`, node);
  13090. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  13091. push(`)`);
  13092. if (isBlock) {
  13093. push(`)`);
  13094. }
  13095. if (directives) {
  13096. push(`, `);
  13097. genNode(directives, context);
  13098. push(`)`);
  13099. }
  13100. }
  13101. function genNullableArgs(args) {
  13102. let i = args.length;
  13103. while (i--) {
  13104. if (args[i] != null)
  13105. break;
  13106. }
  13107. return args.slice(0, i + 1).map(arg => arg || `null`);
  13108. }
  13109. // JavaScript
  13110. function genCallExpression(node, context) {
  13111. const { push, helper, pure } = context;
  13112. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  13113. if (pure) {
  13114. push(PURE_ANNOTATION);
  13115. }
  13116. push(callee + `(`, node);
  13117. genNodeList(node.arguments, context);
  13118. push(`)`);
  13119. }
  13120. function genObjectExpression(node, context) {
  13121. const { push, indent, deindent, newline } = context;
  13122. const { properties } = node;
  13123. if (!properties.length) {
  13124. push(`{}`, node);
  13125. return;
  13126. }
  13127. const multilines = properties.length > 1 ||
  13128. (properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  13129. push(multilines ? `{` : `{ `);
  13130. multilines && indent();
  13131. for (let i = 0; i < properties.length; i++) {
  13132. const { key, value } = properties[i];
  13133. // key
  13134. genExpressionAsPropertyKey(key, context);
  13135. push(`: `);
  13136. // value
  13137. genNode(value, context);
  13138. if (i < properties.length - 1) {
  13139. // will only reach this if it's multilines
  13140. push(`,`);
  13141. newline();
  13142. }
  13143. }
  13144. multilines && deindent();
  13145. push(multilines ? `}` : ` }`);
  13146. }
  13147. function genArrayExpression(node, context) {
  13148. genNodeListAsArray(node.elements, context);
  13149. }
  13150. function genFunctionExpression(node, context) {
  13151. const { push, indent, deindent } = context;
  13152. const { params, returns, body, newline, isSlot } = node;
  13153. if (isSlot) {
  13154. // wrap slot functions with owner context
  13155. push(`_${helperNameMap[WITH_CTX]}(`);
  13156. }
  13157. push(`(`, node);
  13158. if (isArray(params)) {
  13159. genNodeList(params, context);
  13160. }
  13161. else if (params) {
  13162. genNode(params, context);
  13163. }
  13164. push(`) => `);
  13165. if (newline || body) {
  13166. push(`{`);
  13167. indent();
  13168. }
  13169. if (returns) {
  13170. if (newline) {
  13171. push(`return `);
  13172. }
  13173. if (isArray(returns)) {
  13174. genNodeListAsArray(returns, context);
  13175. }
  13176. else {
  13177. genNode(returns, context);
  13178. }
  13179. }
  13180. else if (body) {
  13181. genNode(body, context);
  13182. }
  13183. if (newline || body) {
  13184. deindent();
  13185. push(`}`);
  13186. }
  13187. if (isSlot) {
  13188. push(`)`);
  13189. }
  13190. }
  13191. function genConditionalExpression(node, context) {
  13192. const { test, consequent, alternate, newline: needNewline } = node;
  13193. const { push, indent, deindent, newline } = context;
  13194. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  13195. const needsParens = !isSimpleIdentifier(test.content);
  13196. needsParens && push(`(`);
  13197. genExpression(test, context);
  13198. needsParens && push(`)`);
  13199. }
  13200. else {
  13201. push(`(`);
  13202. genNode(test, context);
  13203. push(`)`);
  13204. }
  13205. needNewline && indent();
  13206. context.indentLevel++;
  13207. needNewline || push(` `);
  13208. push(`? `);
  13209. genNode(consequent, context);
  13210. context.indentLevel--;
  13211. needNewline && newline();
  13212. needNewline || push(` `);
  13213. push(`: `);
  13214. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  13215. if (!isNested) {
  13216. context.indentLevel++;
  13217. }
  13218. genNode(alternate, context);
  13219. if (!isNested) {
  13220. context.indentLevel--;
  13221. }
  13222. needNewline && deindent(true /* without newline */);
  13223. }
  13224. function genCacheExpression(node, context) {
  13225. const { push, helper, indent, deindent, newline } = context;
  13226. push(`_cache[${node.index}] || (`);
  13227. if (node.isVNode) {
  13228. indent();
  13229. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  13230. newline();
  13231. }
  13232. push(`_cache[${node.index}] = `);
  13233. genNode(node.value, context);
  13234. if (node.isVNode) {
  13235. push(`,`);
  13236. newline();
  13237. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  13238. newline();
  13239. push(`_cache[${node.index}]`);
  13240. deindent();
  13241. }
  13242. push(`)`);
  13243. }
  13244. // these keywords should not appear inside expressions, but operators like
  13245. // typeof, instanceof and in are allowed
  13246. const prohibitedKeywordRE = new RegExp('\\b' +
  13247. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  13248. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  13249. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  13250. .split(',')
  13251. .join('\\b|\\b') +
  13252. '\\b');
  13253. // strip strings in expressions
  13254. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  13255. /**
  13256. * Validate a non-prefixed expression.
  13257. * This is only called when using the in-browser runtime compiler since it
  13258. * doesn't prefix expressions.
  13259. */
  13260. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  13261. const exp = node.content;
  13262. // empty expressions are validated per-directive since some directives
  13263. // do allow empty expressions.
  13264. if (!exp.trim()) {
  13265. return;
  13266. }
  13267. try {
  13268. new Function(asRawStatements
  13269. ? ` ${exp} `
  13270. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  13271. }
  13272. catch (e) {
  13273. let message = e.message;
  13274. const keywordMatch = exp
  13275. .replace(stripStringRE, '')
  13276. .match(prohibitedKeywordRE);
  13277. if (keywordMatch) {
  13278. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  13279. }
  13280. context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  13281. }
  13282. }
  13283. const transformExpression = (node, context) => {
  13284. if (node.type === 5 /* INTERPOLATION */) {
  13285. node.content = processExpression(node.content, context);
  13286. }
  13287. else if (node.type === 1 /* ELEMENT */) {
  13288. // handle directives on element
  13289. for (let i = 0; i < node.props.length; i++) {
  13290. const dir = node.props[i];
  13291. // do not process for v-on & v-for since they are special handled
  13292. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  13293. const exp = dir.exp;
  13294. const arg = dir.arg;
  13295. // do not process exp if this is v-on:arg - we need special handling
  13296. // for wrapping inline statements.
  13297. if (exp &&
  13298. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  13299. !(dir.name === 'on' && arg)) {
  13300. dir.exp = processExpression(exp, context,
  13301. // slot args must be processed as function params
  13302. dir.name === 'slot');
  13303. }
  13304. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  13305. dir.arg = processExpression(arg, context);
  13306. }
  13307. }
  13308. }
  13309. }
  13310. };
  13311. // Important: since this function uses Node.js only dependencies, it should
  13312. // always be used with a leading !true check so that it can be
  13313. // tree-shaken from the browser build.
  13314. function processExpression(node, context,
  13315. // some expressions like v-slot props & v-for aliases should be parsed as
  13316. // function params
  13317. asParams = false,
  13318. // v-on handler values may contain multiple statements
  13319. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  13320. {
  13321. {
  13322. // simple in-browser validation (same logic in 2.x)
  13323. validateBrowserExpression(node, context, asParams, asRawStatements);
  13324. }
  13325. return node;
  13326. }
  13327. }
  13328. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  13329. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  13330. // #1587: We need to dynamically increment the key based on the current
  13331. // node's sibling nodes, since chained v-if/else branches are
  13332. // rendered at the same depth
  13333. const siblings = context.parent.children;
  13334. let i = siblings.indexOf(ifNode);
  13335. let key = 0;
  13336. while (i-- >= 0) {
  13337. const sibling = siblings[i];
  13338. if (sibling && sibling.type === 9 /* IF */) {
  13339. key += sibling.branches.length;
  13340. }
  13341. }
  13342. // Exit callback. Complete the codegenNode when all children have been
  13343. // transformed.
  13344. return () => {
  13345. if (isRoot) {
  13346. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  13347. }
  13348. else {
  13349. // attach this branch's codegen node to the v-if root.
  13350. const parentCondition = getParentCondition(ifNode.codegenNode);
  13351. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  13352. }
  13353. };
  13354. });
  13355. });
  13356. // target-agnostic transform used for both Client and SSR
  13357. function processIf(node, dir, context, processCodegen) {
  13358. if (dir.name !== 'else' &&
  13359. (!dir.exp || !dir.exp.content.trim())) {
  13360. const loc = dir.exp ? dir.exp.loc : node.loc;
  13361. context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  13362. dir.exp = createSimpleExpression(`true`, false, loc);
  13363. }
  13364. if (dir.exp) {
  13365. validateBrowserExpression(dir.exp, context);
  13366. }
  13367. if (dir.name === 'if') {
  13368. const branch = createIfBranch(node, dir);
  13369. const ifNode = {
  13370. type: 9 /* IF */,
  13371. loc: node.loc,
  13372. branches: [branch]
  13373. };
  13374. context.replaceNode(ifNode);
  13375. if (processCodegen) {
  13376. return processCodegen(ifNode, branch, true);
  13377. }
  13378. }
  13379. else {
  13380. // locate the adjacent v-if
  13381. const siblings = context.parent.children;
  13382. const comments = [];
  13383. let i = siblings.indexOf(node);
  13384. while (i-- >= -1) {
  13385. const sibling = siblings[i];
  13386. if (sibling && sibling.type === 3 /* COMMENT */) {
  13387. context.removeNode(sibling);
  13388. comments.unshift(sibling);
  13389. continue;
  13390. }
  13391. if (sibling &&
  13392. sibling.type === 2 /* TEXT */ &&
  13393. !sibling.content.trim().length) {
  13394. context.removeNode(sibling);
  13395. continue;
  13396. }
  13397. if (sibling && sibling.type === 9 /* IF */) {
  13398. // Check if v-else was followed by v-else-if
  13399. if (dir.name === 'else-if' &&
  13400. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  13401. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13402. }
  13403. // move the node to the if node's branches
  13404. context.removeNode();
  13405. const branch = createIfBranch(node, dir);
  13406. if (comments.length &&
  13407. // #3619 ignore comments if the v-if is direct child of <transition>
  13408. !(context.parent &&
  13409. context.parent.type === 1 /* ELEMENT */ &&
  13410. isBuiltInType(context.parent.tag, 'transition'))) {
  13411. branch.children = [...comments, ...branch.children];
  13412. }
  13413. // check if user is forcing same key on different branches
  13414. {
  13415. const key = branch.userKey;
  13416. if (key) {
  13417. sibling.branches.forEach(({ userKey }) => {
  13418. if (isSameKey(userKey, key)) {
  13419. context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  13420. }
  13421. });
  13422. }
  13423. }
  13424. sibling.branches.push(branch);
  13425. const onExit = processCodegen && processCodegen(sibling, branch, false);
  13426. // since the branch was removed, it will not be traversed.
  13427. // make sure to traverse here.
  13428. traverseNode(branch, context);
  13429. // call on exit
  13430. if (onExit)
  13431. onExit();
  13432. // make sure to reset currentNode after traversal to indicate this
  13433. // node has been removed.
  13434. context.currentNode = null;
  13435. }
  13436. else {
  13437. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13438. }
  13439. break;
  13440. }
  13441. }
  13442. }
  13443. function createIfBranch(node, dir) {
  13444. return {
  13445. type: 10 /* IF_BRANCH */,
  13446. loc: node.loc,
  13447. condition: dir.name === 'else' ? undefined : dir.exp,
  13448. children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
  13449. ? node.children
  13450. : [node],
  13451. userKey: findProp(node, `key`)
  13452. };
  13453. }
  13454. function createCodegenNodeForBranch(branch, keyIndex, context) {
  13455. if (branch.condition) {
  13456. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  13457. // make sure to pass in asBlock: true so that the comment node call
  13458. // closes the current block.
  13459. createCallExpression(context.helper(CREATE_COMMENT), [
  13460. '"v-if"' ,
  13461. 'true'
  13462. ]));
  13463. }
  13464. else {
  13465. return createChildrenCodegenNode(branch, keyIndex, context);
  13466. }
  13467. }
  13468. function createChildrenCodegenNode(branch, keyIndex, context) {
  13469. const { helper } = context;
  13470. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  13471. const { children } = branch;
  13472. const firstChild = children[0];
  13473. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  13474. if (needFragmentWrapper) {
  13475. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  13476. // optimize away nested fragments when child is a ForNode
  13477. const vnodeCall = firstChild.codegenNode;
  13478. injectProp(vnodeCall, keyProperty, context);
  13479. return vnodeCall;
  13480. }
  13481. else {
  13482. let patchFlag = 64 /* STABLE_FRAGMENT */;
  13483. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  13484. // check if the fragment actually contains a single valid child with
  13485. // the rest being comments
  13486. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  13487. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  13488. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  13489. }
  13490. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  13491. }
  13492. }
  13493. else {
  13494. const ret = firstChild.codegenNode;
  13495. const vnodeCall = getMemoedVNodeCall(ret);
  13496. // Change createVNode to createBlock.
  13497. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  13498. makeBlock(vnodeCall, context);
  13499. }
  13500. // inject branch key
  13501. injectProp(vnodeCall, keyProperty, context);
  13502. return ret;
  13503. }
  13504. }
  13505. function isSameKey(a, b) {
  13506. if (!a || a.type !== b.type) {
  13507. return false;
  13508. }
  13509. if (a.type === 6 /* ATTRIBUTE */) {
  13510. if (a.value.content !== b.value.content) {
  13511. return false;
  13512. }
  13513. }
  13514. else {
  13515. // directive
  13516. const exp = a.exp;
  13517. const branchExp = b.exp;
  13518. if (exp.type !== branchExp.type) {
  13519. return false;
  13520. }
  13521. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  13522. exp.isStatic !== branchExp.isStatic ||
  13523. exp.content !== branchExp.content) {
  13524. return false;
  13525. }
  13526. }
  13527. return true;
  13528. }
  13529. function getParentCondition(node) {
  13530. while (true) {
  13531. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13532. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13533. node = node.alternate;
  13534. }
  13535. else {
  13536. return node;
  13537. }
  13538. }
  13539. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  13540. node = node.value;
  13541. }
  13542. }
  13543. }
  13544. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  13545. const { helper, removeHelper } = context;
  13546. return processFor(node, dir, context, forNode => {
  13547. // create the loop render function expression now, and add the
  13548. // iterator on exit after all children have been traversed
  13549. const renderExp = createCallExpression(helper(RENDER_LIST), [
  13550. forNode.source
  13551. ]);
  13552. const isTemplate = isTemplateNode(node);
  13553. const memo = findDir(node, 'memo');
  13554. const keyProp = findProp(node, `key`);
  13555. const keyExp = keyProp &&
  13556. (keyProp.type === 6 /* ATTRIBUTE */
  13557. ? createSimpleExpression(keyProp.value.content, true)
  13558. : keyProp.exp);
  13559. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  13560. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  13561. forNode.source.constType > 0 /* NOT_CONSTANT */;
  13562. const fragmentFlag = isStableFragment
  13563. ? 64 /* STABLE_FRAGMENT */
  13564. : keyProp
  13565. ? 128 /* KEYED_FRAGMENT */
  13566. : 256 /* UNKEYED_FRAGMENT */;
  13567. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  13568. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  13569. return () => {
  13570. // finish the codegen now that all children have been traversed
  13571. let childBlock;
  13572. const { children } = forNode;
  13573. // check <template v-for> key placement
  13574. if (isTemplate) {
  13575. node.children.some(c => {
  13576. if (c.type === 1 /* ELEMENT */) {
  13577. const key = findProp(c, 'key');
  13578. if (key) {
  13579. context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  13580. return true;
  13581. }
  13582. }
  13583. });
  13584. }
  13585. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  13586. const slotOutlet = isSlotOutlet(node)
  13587. ? node
  13588. : isTemplate &&
  13589. node.children.length === 1 &&
  13590. isSlotOutlet(node.children[0])
  13591. ? node.children[0] // api-extractor somehow fails to infer this
  13592. : null;
  13593. if (slotOutlet) {
  13594. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  13595. childBlock = slotOutlet.codegenNode;
  13596. if (isTemplate && keyProperty) {
  13597. // <template v-for="..." :key="..."><slot/></template>
  13598. // we need to inject the key to the renderSlot() call.
  13599. // the props for renderSlot is passed as the 3rd argument.
  13600. injectProp(childBlock, keyProperty, context);
  13601. }
  13602. }
  13603. else if (needFragmentWrapper) {
  13604. // <template v-for="..."> with text or multi-elements
  13605. // should generate a fragment block for each loop
  13606. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  13607. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  13608. ), undefined, undefined, true, undefined, false /* isComponent */);
  13609. }
  13610. else {
  13611. // Normal element v-for. Directly use the child's codegenNode
  13612. // but mark it as a block.
  13613. childBlock = children[0]
  13614. .codegenNode;
  13615. if (isTemplate && keyProperty) {
  13616. injectProp(childBlock, keyProperty, context);
  13617. }
  13618. if (childBlock.isBlock !== !isStableFragment) {
  13619. if (childBlock.isBlock) {
  13620. // switch from block to vnode
  13621. removeHelper(OPEN_BLOCK);
  13622. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13623. }
  13624. else {
  13625. // switch from vnode to block
  13626. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13627. }
  13628. }
  13629. childBlock.isBlock = !isStableFragment;
  13630. if (childBlock.isBlock) {
  13631. helper(OPEN_BLOCK);
  13632. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13633. }
  13634. else {
  13635. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13636. }
  13637. }
  13638. if (memo) {
  13639. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  13640. createSimpleExpression(`_cached`)
  13641. ]));
  13642. loop.body = createBlockStatement([
  13643. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  13644. createCompoundExpression([
  13645. `if (_cached`,
  13646. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  13647. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  13648. ]),
  13649. createCompoundExpression([`const _item = `, childBlock]),
  13650. createSimpleExpression(`_item.memo = _memo`),
  13651. createSimpleExpression(`return _item`)
  13652. ]);
  13653. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  13654. }
  13655. else {
  13656. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  13657. }
  13658. };
  13659. });
  13660. });
  13661. // target-agnostic transform used for both Client and SSR
  13662. function processFor(node, dir, context, processCodegen) {
  13663. if (!dir.exp) {
  13664. context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  13665. return;
  13666. }
  13667. const parseResult = parseForExpression(
  13668. // can only be simple expression because vFor transform is applied
  13669. // before expression transform.
  13670. dir.exp, context);
  13671. if (!parseResult) {
  13672. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  13673. return;
  13674. }
  13675. const { addIdentifiers, removeIdentifiers, scopes } = context;
  13676. const { source, value, key, index } = parseResult;
  13677. const forNode = {
  13678. type: 11 /* FOR */,
  13679. loc: dir.loc,
  13680. source,
  13681. valueAlias: value,
  13682. keyAlias: key,
  13683. objectIndexAlias: index,
  13684. parseResult,
  13685. children: isTemplateNode(node) ? node.children : [node]
  13686. };
  13687. context.replaceNode(forNode);
  13688. // bookkeeping
  13689. scopes.vFor++;
  13690. const onExit = processCodegen && processCodegen(forNode);
  13691. return () => {
  13692. scopes.vFor--;
  13693. if (onExit)
  13694. onExit();
  13695. };
  13696. }
  13697. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  13698. // This regex doesn't cover the case if key or index aliases have destructuring,
  13699. // but those do not make sense in the first place, so this works in practice.
  13700. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  13701. const stripParensRE = /^\(|\)$/g;
  13702. function parseForExpression(input, context) {
  13703. const loc = input.loc;
  13704. const exp = input.content;
  13705. const inMatch = exp.match(forAliasRE);
  13706. if (!inMatch)
  13707. return;
  13708. const [, LHS, RHS] = inMatch;
  13709. const result = {
  13710. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  13711. value: undefined,
  13712. key: undefined,
  13713. index: undefined
  13714. };
  13715. {
  13716. validateBrowserExpression(result.source, context);
  13717. }
  13718. let valueContent = LHS.trim().replace(stripParensRE, '').trim();
  13719. const trimmedOffset = LHS.indexOf(valueContent);
  13720. const iteratorMatch = valueContent.match(forIteratorRE);
  13721. if (iteratorMatch) {
  13722. valueContent = valueContent.replace(forIteratorRE, '').trim();
  13723. const keyContent = iteratorMatch[1].trim();
  13724. let keyOffset;
  13725. if (keyContent) {
  13726. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  13727. result.key = createAliasExpression(loc, keyContent, keyOffset);
  13728. {
  13729. validateBrowserExpression(result.key, context, true);
  13730. }
  13731. }
  13732. if (iteratorMatch[2]) {
  13733. const indexContent = iteratorMatch[2].trim();
  13734. if (indexContent) {
  13735. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  13736. ? keyOffset + keyContent.length
  13737. : trimmedOffset + valueContent.length));
  13738. {
  13739. validateBrowserExpression(result.index, context, true);
  13740. }
  13741. }
  13742. }
  13743. }
  13744. if (valueContent) {
  13745. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  13746. {
  13747. validateBrowserExpression(result.value, context, true);
  13748. }
  13749. }
  13750. return result;
  13751. }
  13752. function createAliasExpression(range, content, offset) {
  13753. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  13754. }
  13755. function createForLoopParams({ value, key, index }, memoArgs = []) {
  13756. return createParamsList([value, key, index, ...memoArgs]);
  13757. }
  13758. function createParamsList(args) {
  13759. let i = args.length;
  13760. while (i--) {
  13761. if (args[i])
  13762. break;
  13763. }
  13764. return args
  13765. .slice(0, i + 1)
  13766. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  13767. }
  13768. const defaultFallback = createSimpleExpression(`undefined`, false);
  13769. // A NodeTransform that:
  13770. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  13771. // by transformExpression. This is only applied in non-browser builds with
  13772. // { prefixIdentifiers: true }.
  13773. // 2. Track v-slot depths so that we know a slot is inside another slot.
  13774. // Note the exit callback is executed before buildSlots() on the same node,
  13775. // so only nested slots see positive numbers.
  13776. const trackSlotScopes = (node, context) => {
  13777. if (node.type === 1 /* ELEMENT */ &&
  13778. (node.tagType === 1 /* COMPONENT */ ||
  13779. node.tagType === 3 /* TEMPLATE */)) {
  13780. // We are only checking non-empty v-slot here
  13781. // since we only care about slots that introduce scope variables.
  13782. const vSlot = findDir(node, 'slot');
  13783. if (vSlot) {
  13784. vSlot.exp;
  13785. context.scopes.vSlot++;
  13786. return () => {
  13787. context.scopes.vSlot--;
  13788. };
  13789. }
  13790. }
  13791. };
  13792. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  13793. // Instead of being a DirectiveTransform, v-slot processing is called during
  13794. // transformElement to build the slots object for a component.
  13795. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  13796. context.helper(WITH_CTX);
  13797. const { children, loc } = node;
  13798. const slotsProperties = [];
  13799. const dynamicSlots = [];
  13800. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  13801. // since it likely uses a scope variable.
  13802. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  13803. // 1. Check for slot with slotProps on component itself.
  13804. // <Comp v-slot="{ prop }"/>
  13805. const onComponentSlot = findDir(node, 'slot', true);
  13806. if (onComponentSlot) {
  13807. const { arg, exp } = onComponentSlot;
  13808. if (arg && !isStaticExp(arg)) {
  13809. hasDynamicSlots = true;
  13810. }
  13811. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  13812. }
  13813. // 2. Iterate through children and check for template slots
  13814. // <template v-slot:foo="{ prop }">
  13815. let hasTemplateSlots = false;
  13816. let hasNamedDefaultSlot = false;
  13817. const implicitDefaultChildren = [];
  13818. const seenSlotNames = new Set();
  13819. for (let i = 0; i < children.length; i++) {
  13820. const slotElement = children[i];
  13821. let slotDir;
  13822. if (!isTemplateNode(slotElement) ||
  13823. !(slotDir = findDir(slotElement, 'slot', true))) {
  13824. // not a <template v-slot>, skip.
  13825. if (slotElement.type !== 3 /* COMMENT */) {
  13826. implicitDefaultChildren.push(slotElement);
  13827. }
  13828. continue;
  13829. }
  13830. if (onComponentSlot) {
  13831. // already has on-component slot - this is incorrect usage.
  13832. context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  13833. break;
  13834. }
  13835. hasTemplateSlots = true;
  13836. const { children: slotChildren, loc: slotLoc } = slotElement;
  13837. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  13838. // check if name is dynamic.
  13839. let staticSlotName;
  13840. if (isStaticExp(slotName)) {
  13841. staticSlotName = slotName ? slotName.content : `default`;
  13842. }
  13843. else {
  13844. hasDynamicSlots = true;
  13845. }
  13846. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  13847. // check if this slot is conditional (v-if/v-for)
  13848. let vIf;
  13849. let vElse;
  13850. let vFor;
  13851. if ((vIf = findDir(slotElement, 'if'))) {
  13852. hasDynamicSlots = true;
  13853. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  13854. }
  13855. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  13856. // find adjacent v-if
  13857. let j = i;
  13858. let prev;
  13859. while (j--) {
  13860. prev = children[j];
  13861. if (prev.type !== 3 /* COMMENT */) {
  13862. break;
  13863. }
  13864. }
  13865. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  13866. // remove node
  13867. children.splice(i, 1);
  13868. i--;
  13869. // attach this slot to previous conditional
  13870. let conditional = dynamicSlots[dynamicSlots.length - 1];
  13871. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13872. conditional = conditional.alternate;
  13873. }
  13874. conditional.alternate = vElse.exp
  13875. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  13876. : buildDynamicSlot(slotName, slotFunction);
  13877. }
  13878. else {
  13879. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  13880. }
  13881. }
  13882. else if ((vFor = findDir(slotElement, 'for'))) {
  13883. hasDynamicSlots = true;
  13884. const parseResult = vFor.parseResult ||
  13885. parseForExpression(vFor.exp, context);
  13886. if (parseResult) {
  13887. // Render the dynamic slots as an array and add it to the createSlot()
  13888. // args. The runtime knows how to handle it appropriately.
  13889. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  13890. parseResult.source,
  13891. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  13892. ]));
  13893. }
  13894. else {
  13895. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  13896. }
  13897. }
  13898. else {
  13899. // check duplicate static names
  13900. if (staticSlotName) {
  13901. if (seenSlotNames.has(staticSlotName)) {
  13902. context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  13903. continue;
  13904. }
  13905. seenSlotNames.add(staticSlotName);
  13906. if (staticSlotName === 'default') {
  13907. hasNamedDefaultSlot = true;
  13908. }
  13909. }
  13910. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  13911. }
  13912. }
  13913. if (!onComponentSlot) {
  13914. const buildDefaultSlotProperty = (props, children) => {
  13915. const fn = buildSlotFn(props, children, loc);
  13916. return createObjectProperty(`default`, fn);
  13917. };
  13918. if (!hasTemplateSlots) {
  13919. // implicit default slot (on component)
  13920. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  13921. }
  13922. else if (implicitDefaultChildren.length &&
  13923. // #3766
  13924. // with whitespace: 'preserve', whitespaces between slots will end up in
  13925. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  13926. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  13927. // implicit default slot (mixed with named slots)
  13928. if (hasNamedDefaultSlot) {
  13929. context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  13930. }
  13931. else {
  13932. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  13933. }
  13934. }
  13935. }
  13936. const slotFlag = hasDynamicSlots
  13937. ? 2 /* DYNAMIC */
  13938. : hasForwardedSlots(node.children)
  13939. ? 3 /* FORWARDED */
  13940. : 1 /* STABLE */;
  13941. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  13942. // 2 = compiled but dynamic = can skip normalization, but must run diff
  13943. // 1 = compiled and static = can skip normalization AND diff as optimized
  13944. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  13945. if (dynamicSlots.length) {
  13946. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  13947. slots,
  13948. createArrayExpression(dynamicSlots)
  13949. ]);
  13950. }
  13951. return {
  13952. slots,
  13953. hasDynamicSlots
  13954. };
  13955. }
  13956. function buildDynamicSlot(name, fn) {
  13957. return createObjectExpression([
  13958. createObjectProperty(`name`, name),
  13959. createObjectProperty(`fn`, fn)
  13960. ]);
  13961. }
  13962. function hasForwardedSlots(children) {
  13963. for (let i = 0; i < children.length; i++) {
  13964. const child = children[i];
  13965. switch (child.type) {
  13966. case 1 /* ELEMENT */:
  13967. if (child.tagType === 2 /* SLOT */ ||
  13968. hasForwardedSlots(child.children)) {
  13969. return true;
  13970. }
  13971. break;
  13972. case 9 /* IF */:
  13973. if (hasForwardedSlots(child.branches))
  13974. return true;
  13975. break;
  13976. case 10 /* IF_BRANCH */:
  13977. case 11 /* FOR */:
  13978. if (hasForwardedSlots(child.children))
  13979. return true;
  13980. break;
  13981. }
  13982. }
  13983. return false;
  13984. }
  13985. function isNonWhitespaceContent(node) {
  13986. if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
  13987. return true;
  13988. return node.type === 2 /* TEXT */
  13989. ? !!node.content.trim()
  13990. : isNonWhitespaceContent(node.content);
  13991. }
  13992. // some directive transforms (e.g. v-model) may return a symbol for runtime
  13993. // import, which should be used instead of a resolveDirective call.
  13994. const directiveImportMap = new WeakMap();
  13995. // generate a JavaScript AST for this element's codegen
  13996. const transformElement = (node, context) => {
  13997. // perform the work on exit, after all child expressions have been
  13998. // processed and merged.
  13999. return function postTransformElement() {
  14000. node = context.currentNode;
  14001. if (!(node.type === 1 /* ELEMENT */ &&
  14002. (node.tagType === 0 /* ELEMENT */ ||
  14003. node.tagType === 1 /* COMPONENT */))) {
  14004. return;
  14005. }
  14006. const { tag, props } = node;
  14007. const isComponent = node.tagType === 1 /* COMPONENT */;
  14008. // The goal of the transform is to create a codegenNode implementing the
  14009. // VNodeCall interface.
  14010. let vnodeTag = isComponent
  14011. ? resolveComponentType(node, context)
  14012. : `"${tag}"`;
  14013. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  14014. let vnodeProps;
  14015. let vnodeChildren;
  14016. let vnodePatchFlag;
  14017. let patchFlag = 0;
  14018. let vnodeDynamicProps;
  14019. let dynamicPropNames;
  14020. let vnodeDirectives;
  14021. let shouldUseBlock =
  14022. // dynamic component may resolve to plain elements
  14023. isDynamicComponent ||
  14024. vnodeTag === TELEPORT ||
  14025. vnodeTag === SUSPENSE ||
  14026. (!isComponent &&
  14027. // <svg> and <foreignObject> must be forced into blocks so that block
  14028. // updates inside get proper isSVG flag at runtime. (#639, #643)
  14029. // This is technically web-specific, but splitting the logic out of core
  14030. // leads to too much unnecessary complexity.
  14031. (tag === 'svg' || tag === 'foreignObject'));
  14032. // props
  14033. if (props.length > 0) {
  14034. const propsBuildResult = buildProps(node, context);
  14035. vnodeProps = propsBuildResult.props;
  14036. patchFlag = propsBuildResult.patchFlag;
  14037. dynamicPropNames = propsBuildResult.dynamicPropNames;
  14038. const directives = propsBuildResult.directives;
  14039. vnodeDirectives =
  14040. directives && directives.length
  14041. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  14042. : undefined;
  14043. if (propsBuildResult.shouldUseBlock) {
  14044. shouldUseBlock = true;
  14045. }
  14046. }
  14047. // children
  14048. if (node.children.length > 0) {
  14049. if (vnodeTag === KEEP_ALIVE) {
  14050. // Although a built-in component, we compile KeepAlive with raw children
  14051. // instead of slot functions so that it can be used inside Transition
  14052. // or other Transition-wrapping HOCs.
  14053. // To ensure correct updates with block optimizations, we need to:
  14054. // 1. Force keep-alive into a block. This avoids its children being
  14055. // collected by a parent block.
  14056. shouldUseBlock = true;
  14057. // 2. Force keep-alive to always be updated, since it uses raw children.
  14058. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14059. if (node.children.length > 1) {
  14060. context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  14061. start: node.children[0].loc.start,
  14062. end: node.children[node.children.length - 1].loc.end,
  14063. source: ''
  14064. }));
  14065. }
  14066. }
  14067. const shouldBuildAsSlots = isComponent &&
  14068. // Teleport is not a real component and has dedicated runtime handling
  14069. vnodeTag !== TELEPORT &&
  14070. // explained above.
  14071. vnodeTag !== KEEP_ALIVE;
  14072. if (shouldBuildAsSlots) {
  14073. const { slots, hasDynamicSlots } = buildSlots(node, context);
  14074. vnodeChildren = slots;
  14075. if (hasDynamicSlots) {
  14076. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14077. }
  14078. }
  14079. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  14080. const child = node.children[0];
  14081. const type = child.type;
  14082. // check for dynamic text children
  14083. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  14084. type === 8 /* COMPOUND_EXPRESSION */;
  14085. if (hasDynamicTextChild &&
  14086. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14087. patchFlag |= 1 /* TEXT */;
  14088. }
  14089. // pass directly if the only child is a text node
  14090. // (plain / interpolation / expression)
  14091. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  14092. vnodeChildren = child;
  14093. }
  14094. else {
  14095. vnodeChildren = node.children;
  14096. }
  14097. }
  14098. else {
  14099. vnodeChildren = node.children;
  14100. }
  14101. }
  14102. // patchFlag & dynamicPropNames
  14103. if (patchFlag !== 0) {
  14104. {
  14105. if (patchFlag < 0) {
  14106. // special flags (negative and mutually exclusive)
  14107. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  14108. }
  14109. else {
  14110. // bitwise flags
  14111. const flagNames = Object.keys(PatchFlagNames)
  14112. .map(Number)
  14113. .filter(n => n > 0 && patchFlag & n)
  14114. .map(n => PatchFlagNames[n])
  14115. .join(`, `);
  14116. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  14117. }
  14118. }
  14119. if (dynamicPropNames && dynamicPropNames.length) {
  14120. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  14121. }
  14122. }
  14123. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  14124. };
  14125. };
  14126. function resolveComponentType(node, context, ssr = false) {
  14127. let { tag } = node;
  14128. // 1. dynamic component
  14129. const isExplicitDynamic = isComponentTag(tag);
  14130. const isProp = findProp(node, 'is');
  14131. if (isProp) {
  14132. if (isExplicitDynamic ||
  14133. (false )) {
  14134. const exp = isProp.type === 6 /* ATTRIBUTE */
  14135. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  14136. : isProp.exp;
  14137. if (exp) {
  14138. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14139. exp
  14140. ]);
  14141. }
  14142. }
  14143. else if (isProp.type === 6 /* ATTRIBUTE */ &&
  14144. isProp.value.content.startsWith('vue:')) {
  14145. // <button is="vue:xxx">
  14146. // if not <component>, only is value that starts with "vue:" will be
  14147. // treated as component by the parse phase and reach here, unless it's
  14148. // compat mode where all is values are considered components
  14149. tag = isProp.value.content.slice(4);
  14150. }
  14151. }
  14152. // 1.5 v-is (TODO: Deprecate)
  14153. const isDir = !isExplicitDynamic && findDir(node, 'is');
  14154. if (isDir && isDir.exp) {
  14155. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14156. isDir.exp
  14157. ]);
  14158. }
  14159. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  14160. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  14161. if (builtIn) {
  14162. // built-ins are simply fallthroughs / have special handling during ssr
  14163. // so we don't need to import their runtime equivalents
  14164. if (!ssr)
  14165. context.helper(builtIn);
  14166. return builtIn;
  14167. }
  14168. // 5. user component (resolve)
  14169. context.helper(RESOLVE_COMPONENT);
  14170. context.components.add(tag);
  14171. return toValidAssetId(tag, `component`);
  14172. }
  14173. function buildProps(node, context, props = node.props, ssr = false) {
  14174. const { tag, loc: elementLoc, children } = node;
  14175. const isComponent = node.tagType === 1 /* COMPONENT */;
  14176. let properties = [];
  14177. const mergeArgs = [];
  14178. const runtimeDirectives = [];
  14179. const hasChildren = children.length > 0;
  14180. let shouldUseBlock = false;
  14181. // patchFlag analysis
  14182. let patchFlag = 0;
  14183. let hasRef = false;
  14184. let hasClassBinding = false;
  14185. let hasStyleBinding = false;
  14186. let hasHydrationEventBinding = false;
  14187. let hasDynamicKeys = false;
  14188. let hasVnodeHook = false;
  14189. const dynamicPropNames = [];
  14190. const analyzePatchFlag = ({ key, value }) => {
  14191. if (isStaticExp(key)) {
  14192. const name = key.content;
  14193. const isEventHandler = isOn(name);
  14194. if (!isComponent &&
  14195. isEventHandler &&
  14196. // omit the flag for click handlers because hydration gives click
  14197. // dedicated fast path.
  14198. name.toLowerCase() !== 'onclick' &&
  14199. // omit v-model handlers
  14200. name !== 'onUpdate:modelValue' &&
  14201. // omit onVnodeXXX hooks
  14202. !isReservedProp(name)) {
  14203. hasHydrationEventBinding = true;
  14204. }
  14205. if (isEventHandler && isReservedProp(name)) {
  14206. hasVnodeHook = true;
  14207. }
  14208. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  14209. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  14210. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  14211. getConstantType(value, context) > 0)) {
  14212. // skip if the prop is a cached handler or has constant value
  14213. return;
  14214. }
  14215. if (name === 'ref') {
  14216. hasRef = true;
  14217. }
  14218. else if (name === 'class') {
  14219. hasClassBinding = true;
  14220. }
  14221. else if (name === 'style') {
  14222. hasStyleBinding = true;
  14223. }
  14224. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  14225. dynamicPropNames.push(name);
  14226. }
  14227. // treat the dynamic class and style binding of the component as dynamic props
  14228. if (isComponent &&
  14229. (name === 'class' || name === 'style') &&
  14230. !dynamicPropNames.includes(name)) {
  14231. dynamicPropNames.push(name);
  14232. }
  14233. }
  14234. else {
  14235. hasDynamicKeys = true;
  14236. }
  14237. };
  14238. for (let i = 0; i < props.length; i++) {
  14239. // static attribute
  14240. const prop = props[i];
  14241. if (prop.type === 6 /* ATTRIBUTE */) {
  14242. const { loc, name, value } = prop;
  14243. let isStatic = true;
  14244. if (name === 'ref') {
  14245. hasRef = true;
  14246. if (context.scopes.vFor > 0) {
  14247. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14248. }
  14249. }
  14250. // skip is on <component>, or is="vue:xxx"
  14251. if (name === 'is' &&
  14252. (isComponentTag(tag) ||
  14253. (value && value.content.startsWith('vue:')) ||
  14254. (false ))) {
  14255. continue;
  14256. }
  14257. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  14258. }
  14259. else {
  14260. // directives
  14261. const { name, arg, exp, loc } = prop;
  14262. const isVBind = name === 'bind';
  14263. const isVOn = name === 'on';
  14264. // skip v-slot - it is handled by its dedicated transform.
  14265. if (name === 'slot') {
  14266. if (!isComponent) {
  14267. context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
  14268. }
  14269. continue;
  14270. }
  14271. // skip v-once/v-memo - they are handled by dedicated transforms.
  14272. if (name === 'once' || name === 'memo') {
  14273. continue;
  14274. }
  14275. // skip v-is and :is on <component>
  14276. if (name === 'is' ||
  14277. (isVBind &&
  14278. isStaticArgOf(arg, 'is') &&
  14279. (isComponentTag(tag) ||
  14280. (false )))) {
  14281. continue;
  14282. }
  14283. // skip v-on in SSR compilation
  14284. if (isVOn && ssr) {
  14285. continue;
  14286. }
  14287. if (
  14288. // #938: elements with dynamic keys should be forced into blocks
  14289. (isVBind && isStaticArgOf(arg, 'key')) ||
  14290. // inline before-update hooks need to force block so that it is invoked
  14291. // before children
  14292. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  14293. shouldUseBlock = true;
  14294. }
  14295. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  14296. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14297. }
  14298. // special case for v-bind and v-on with no argument
  14299. if (!arg && (isVBind || isVOn)) {
  14300. hasDynamicKeys = true;
  14301. if (exp) {
  14302. if (properties.length) {
  14303. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14304. properties = [];
  14305. }
  14306. if (isVBind) {
  14307. mergeArgs.push(exp);
  14308. }
  14309. else {
  14310. // v-on="obj" -> toHandlers(obj)
  14311. mergeArgs.push({
  14312. type: 14 /* JS_CALL_EXPRESSION */,
  14313. loc,
  14314. callee: context.helper(TO_HANDLERS),
  14315. arguments: [exp]
  14316. });
  14317. }
  14318. }
  14319. else {
  14320. context.onError(createCompilerError(isVBind
  14321. ? 34 /* X_V_BIND_NO_EXPRESSION */
  14322. : 35 /* X_V_ON_NO_EXPRESSION */, loc));
  14323. }
  14324. continue;
  14325. }
  14326. const directiveTransform = context.directiveTransforms[name];
  14327. if (directiveTransform) {
  14328. // has built-in directive transform.
  14329. const { props, needRuntime } = directiveTransform(prop, node, context);
  14330. !ssr && props.forEach(analyzePatchFlag);
  14331. properties.push(...props);
  14332. if (needRuntime) {
  14333. runtimeDirectives.push(prop);
  14334. if (isSymbol(needRuntime)) {
  14335. directiveImportMap.set(prop, needRuntime);
  14336. }
  14337. }
  14338. }
  14339. else if (!isBuiltInDirective(name)) {
  14340. // no built-in transform, this is a user custom directive.
  14341. runtimeDirectives.push(prop);
  14342. // custom dirs may use beforeUpdate so they need to force blocks
  14343. // to ensure before-update gets called before children update
  14344. if (hasChildren) {
  14345. shouldUseBlock = true;
  14346. }
  14347. }
  14348. }
  14349. }
  14350. let propsExpression = undefined;
  14351. // has v-bind="object" or v-on="object", wrap with mergeProps
  14352. if (mergeArgs.length) {
  14353. if (properties.length) {
  14354. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14355. }
  14356. if (mergeArgs.length > 1) {
  14357. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  14358. }
  14359. else {
  14360. // single v-bind with nothing else - no need for a mergeProps call
  14361. propsExpression = mergeArgs[0];
  14362. }
  14363. }
  14364. else if (properties.length) {
  14365. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  14366. }
  14367. // patchFlag analysis
  14368. if (hasDynamicKeys) {
  14369. patchFlag |= 16 /* FULL_PROPS */;
  14370. }
  14371. else {
  14372. if (hasClassBinding && !isComponent) {
  14373. patchFlag |= 2 /* CLASS */;
  14374. }
  14375. if (hasStyleBinding && !isComponent) {
  14376. patchFlag |= 4 /* STYLE */;
  14377. }
  14378. if (dynamicPropNames.length) {
  14379. patchFlag |= 8 /* PROPS */;
  14380. }
  14381. if (hasHydrationEventBinding) {
  14382. patchFlag |= 32 /* HYDRATE_EVENTS */;
  14383. }
  14384. }
  14385. if (!shouldUseBlock &&
  14386. (patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  14387. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  14388. patchFlag |= 512 /* NEED_PATCH */;
  14389. }
  14390. // pre-normalize props, SSR is skipped for now
  14391. if (!context.inSSR && propsExpression) {
  14392. switch (propsExpression.type) {
  14393. case 15 /* JS_OBJECT_EXPRESSION */:
  14394. // means that there is no v-bind,
  14395. // but still need to deal with dynamic key binding
  14396. let classKeyIndex = -1;
  14397. let styleKeyIndex = -1;
  14398. let hasDynamicKey = false;
  14399. for (let i = 0; i < propsExpression.properties.length; i++) {
  14400. const key = propsExpression.properties[i].key;
  14401. if (isStaticExp(key)) {
  14402. if (key.content === 'class') {
  14403. classKeyIndex = i;
  14404. }
  14405. else if (key.content === 'style') {
  14406. styleKeyIndex = i;
  14407. }
  14408. }
  14409. else if (!key.isHandlerKey) {
  14410. hasDynamicKey = true;
  14411. }
  14412. }
  14413. const classProp = propsExpression.properties[classKeyIndex];
  14414. const styleProp = propsExpression.properties[styleKeyIndex];
  14415. // no dynamic key
  14416. if (!hasDynamicKey) {
  14417. if (classProp && !isStaticExp(classProp.value)) {
  14418. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  14419. }
  14420. if (styleProp &&
  14421. !isStaticExp(styleProp.value) &&
  14422. // the static style is compiled into an object,
  14423. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  14424. (hasStyleBinding ||
  14425. // v-bind:style and style both exist,
  14426. // v-bind:style with static literal object
  14427. styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
  14428. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  14429. }
  14430. }
  14431. else {
  14432. // dynamic key binding, wrap with `normalizeProps`
  14433. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  14434. }
  14435. break;
  14436. case 14 /* JS_CALL_EXPRESSION */:
  14437. // mergeProps call, do nothing
  14438. break;
  14439. default:
  14440. // single v-bind
  14441. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  14442. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  14443. propsExpression
  14444. ])
  14445. ]);
  14446. break;
  14447. }
  14448. }
  14449. return {
  14450. props: propsExpression,
  14451. directives: runtimeDirectives,
  14452. patchFlag,
  14453. dynamicPropNames,
  14454. shouldUseBlock
  14455. };
  14456. }
  14457. // Dedupe props in an object literal.
  14458. // Literal duplicated attributes would have been warned during the parse phase,
  14459. // however, it's possible to encounter duplicated `onXXX` handlers with different
  14460. // modifiers. We also need to merge static and dynamic class / style attributes.
  14461. // - onXXX handlers / style: merge into array
  14462. // - class: merge into single expression with concatenation
  14463. function dedupeProperties(properties) {
  14464. const knownProps = new Map();
  14465. const deduped = [];
  14466. for (let i = 0; i < properties.length; i++) {
  14467. const prop = properties[i];
  14468. // dynamic keys are always allowed
  14469. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  14470. deduped.push(prop);
  14471. continue;
  14472. }
  14473. const name = prop.key.content;
  14474. const existing = knownProps.get(name);
  14475. if (existing) {
  14476. if (name === 'style' || name === 'class' || isOn(name)) {
  14477. mergeAsArray$1(existing, prop);
  14478. }
  14479. // unexpected duplicate, should have emitted error during parse
  14480. }
  14481. else {
  14482. knownProps.set(name, prop);
  14483. deduped.push(prop);
  14484. }
  14485. }
  14486. return deduped;
  14487. }
  14488. function mergeAsArray$1(existing, incoming) {
  14489. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  14490. existing.value.elements.push(incoming.value);
  14491. }
  14492. else {
  14493. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  14494. }
  14495. }
  14496. function buildDirectiveArgs(dir, context) {
  14497. const dirArgs = [];
  14498. const runtime = directiveImportMap.get(dir);
  14499. if (runtime) {
  14500. // built-in directive with runtime
  14501. dirArgs.push(context.helperString(runtime));
  14502. }
  14503. else {
  14504. {
  14505. // inject statement for resolving directive
  14506. context.helper(RESOLVE_DIRECTIVE);
  14507. context.directives.add(dir.name);
  14508. dirArgs.push(toValidAssetId(dir.name, `directive`));
  14509. }
  14510. }
  14511. const { loc } = dir;
  14512. if (dir.exp)
  14513. dirArgs.push(dir.exp);
  14514. if (dir.arg) {
  14515. if (!dir.exp) {
  14516. dirArgs.push(`void 0`);
  14517. }
  14518. dirArgs.push(dir.arg);
  14519. }
  14520. if (Object.keys(dir.modifiers).length) {
  14521. if (!dir.arg) {
  14522. if (!dir.exp) {
  14523. dirArgs.push(`void 0`);
  14524. }
  14525. dirArgs.push(`void 0`);
  14526. }
  14527. const trueExpression = createSimpleExpression(`true`, false, loc);
  14528. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  14529. }
  14530. return createArrayExpression(dirArgs, dir.loc);
  14531. }
  14532. function stringifyDynamicPropNames(props) {
  14533. let propsNamesString = `[`;
  14534. for (let i = 0, l = props.length; i < l; i++) {
  14535. propsNamesString += JSON.stringify(props[i]);
  14536. if (i < l - 1)
  14537. propsNamesString += ', ';
  14538. }
  14539. return propsNamesString + `]`;
  14540. }
  14541. function isComponentTag(tag) {
  14542. return tag === 'component' || tag === 'Component';
  14543. }
  14544. const transformSlotOutlet = (node, context) => {
  14545. if (isSlotOutlet(node)) {
  14546. const { children, loc } = node;
  14547. const { slotName, slotProps } = processSlotOutlet(node, context);
  14548. const slotArgs = [
  14549. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  14550. slotName,
  14551. '{}',
  14552. 'undefined',
  14553. 'true'
  14554. ];
  14555. let expectedLen = 2;
  14556. if (slotProps) {
  14557. slotArgs[2] = slotProps;
  14558. expectedLen = 3;
  14559. }
  14560. if (children.length) {
  14561. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  14562. expectedLen = 4;
  14563. }
  14564. if (context.scopeId && !context.slotted) {
  14565. expectedLen = 5;
  14566. }
  14567. slotArgs.splice(expectedLen); // remove unused arguments
  14568. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  14569. }
  14570. };
  14571. function processSlotOutlet(node, context) {
  14572. let slotName = `"default"`;
  14573. let slotProps = undefined;
  14574. const nonNameProps = [];
  14575. for (let i = 0; i < node.props.length; i++) {
  14576. const p = node.props[i];
  14577. if (p.type === 6 /* ATTRIBUTE */) {
  14578. if (p.value) {
  14579. if (p.name === 'name') {
  14580. slotName = JSON.stringify(p.value.content);
  14581. }
  14582. else {
  14583. p.name = camelize(p.name);
  14584. nonNameProps.push(p);
  14585. }
  14586. }
  14587. }
  14588. else {
  14589. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  14590. if (p.exp)
  14591. slotName = p.exp;
  14592. }
  14593. else {
  14594. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  14595. p.arg.content = camelize(p.arg.content);
  14596. }
  14597. nonNameProps.push(p);
  14598. }
  14599. }
  14600. }
  14601. if (nonNameProps.length > 0) {
  14602. const { props, directives } = buildProps(node, context, nonNameProps);
  14603. slotProps = props;
  14604. if (directives.length) {
  14605. context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  14606. }
  14607. }
  14608. return {
  14609. slotName,
  14610. slotProps
  14611. };
  14612. }
  14613. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  14614. const transformOn = (dir, node, context, augmentor) => {
  14615. const { loc, modifiers, arg } = dir;
  14616. if (!dir.exp && !modifiers.length) {
  14617. context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
  14618. }
  14619. let eventName;
  14620. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14621. if (arg.isStatic) {
  14622. let rawName = arg.content;
  14623. // TODO deprecate @vnodeXXX usage
  14624. if (rawName.startsWith('vue:')) {
  14625. rawName = `vnode-${rawName.slice(4)}`;
  14626. }
  14627. // for all event listeners, auto convert it to camelCase. See issue #2249
  14628. eventName = createSimpleExpression(toHandlerKey(camelize(rawName)), true, arg.loc);
  14629. }
  14630. else {
  14631. // #2388
  14632. eventName = createCompoundExpression([
  14633. `${context.helperString(TO_HANDLER_KEY)}(`,
  14634. arg,
  14635. `)`
  14636. ]);
  14637. }
  14638. }
  14639. else {
  14640. // already a compound expression.
  14641. eventName = arg;
  14642. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  14643. eventName.children.push(`)`);
  14644. }
  14645. // handler processing
  14646. let exp = dir.exp;
  14647. if (exp && !exp.content.trim()) {
  14648. exp = undefined;
  14649. }
  14650. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  14651. if (exp) {
  14652. const isMemberExp = isMemberExpression(exp.content);
  14653. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  14654. const hasMultipleStatements = exp.content.includes(`;`);
  14655. {
  14656. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  14657. }
  14658. if (isInlineStatement || (shouldCache && isMemberExp)) {
  14659. // wrap inline statement in a function expression
  14660. exp = createCompoundExpression([
  14661. `${isInlineStatement
  14662. ? `$event`
  14663. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  14664. exp,
  14665. hasMultipleStatements ? `}` : `)`
  14666. ]);
  14667. }
  14668. }
  14669. let ret = {
  14670. props: [
  14671. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  14672. ]
  14673. };
  14674. // apply extended compiler augmentor
  14675. if (augmentor) {
  14676. ret = augmentor(ret);
  14677. }
  14678. if (shouldCache) {
  14679. // cache handlers so that it's always the same handler being passed down.
  14680. // this avoids unnecessary re-renders when users use inline handlers on
  14681. // components.
  14682. ret.props[0].value = context.cache(ret.props[0].value);
  14683. }
  14684. // mark the key as handler for props normalization check
  14685. ret.props.forEach(p => (p.key.isHandlerKey = true));
  14686. return ret;
  14687. };
  14688. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  14689. // codegen for the entire props object. This transform here is only for v-bind
  14690. // *with* args.
  14691. const transformBind = (dir, _node, context) => {
  14692. const { exp, modifiers, loc } = dir;
  14693. const arg = dir.arg;
  14694. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  14695. arg.children.unshift(`(`);
  14696. arg.children.push(`) || ""`);
  14697. }
  14698. else if (!arg.isStatic) {
  14699. arg.content = `${arg.content} || ""`;
  14700. }
  14701. // .sync is replaced by v-model:arg
  14702. if (modifiers.includes('camel')) {
  14703. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14704. if (arg.isStatic) {
  14705. arg.content = camelize(arg.content);
  14706. }
  14707. else {
  14708. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  14709. }
  14710. }
  14711. else {
  14712. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  14713. arg.children.push(`)`);
  14714. }
  14715. }
  14716. if (!context.inSSR) {
  14717. if (modifiers.includes('prop')) {
  14718. injectPrefix(arg, '.');
  14719. }
  14720. if (modifiers.includes('attr')) {
  14721. injectPrefix(arg, '^');
  14722. }
  14723. }
  14724. if (!exp ||
  14725. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  14726. context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
  14727. return {
  14728. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  14729. };
  14730. }
  14731. return {
  14732. props: [createObjectProperty(arg, exp)]
  14733. };
  14734. };
  14735. const injectPrefix = (arg, prefix) => {
  14736. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14737. if (arg.isStatic) {
  14738. arg.content = prefix + arg.content;
  14739. }
  14740. else {
  14741. arg.content = `\`${prefix}\${${arg.content}}\``;
  14742. }
  14743. }
  14744. else {
  14745. arg.children.unshift(`'${prefix}' + (`);
  14746. arg.children.push(`)`);
  14747. }
  14748. };
  14749. // Merge adjacent text nodes and expressions into a single expression
  14750. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  14751. const transformText = (node, context) => {
  14752. if (node.type === 0 /* ROOT */ ||
  14753. node.type === 1 /* ELEMENT */ ||
  14754. node.type === 11 /* FOR */ ||
  14755. node.type === 10 /* IF_BRANCH */) {
  14756. // perform the transform on node exit so that all expressions have already
  14757. // been processed.
  14758. return () => {
  14759. const children = node.children;
  14760. let currentContainer = undefined;
  14761. let hasText = false;
  14762. for (let i = 0; i < children.length; i++) {
  14763. const child = children[i];
  14764. if (isText(child)) {
  14765. hasText = true;
  14766. for (let j = i + 1; j < children.length; j++) {
  14767. const next = children[j];
  14768. if (isText(next)) {
  14769. if (!currentContainer) {
  14770. currentContainer = children[i] = {
  14771. type: 8 /* COMPOUND_EXPRESSION */,
  14772. loc: child.loc,
  14773. children: [child]
  14774. };
  14775. }
  14776. // merge adjacent text node into current
  14777. currentContainer.children.push(` + `, next);
  14778. children.splice(j, 1);
  14779. j--;
  14780. }
  14781. else {
  14782. currentContainer = undefined;
  14783. break;
  14784. }
  14785. }
  14786. }
  14787. }
  14788. if (!hasText ||
  14789. // if this is a plain element with a single text child, leave it
  14790. // as-is since the runtime has dedicated fast path for this by directly
  14791. // setting textContent of the element.
  14792. // for component root it's always normalized anyway.
  14793. (children.length === 1 &&
  14794. (node.type === 0 /* ROOT */ ||
  14795. (node.type === 1 /* ELEMENT */ &&
  14796. node.tagType === 0 /* ELEMENT */ &&
  14797. // #3756
  14798. // custom directives can potentially add DOM elements arbitrarily,
  14799. // we need to avoid setting textContent of the element at runtime
  14800. // to avoid accidentally overwriting the DOM elements added
  14801. // by the user through custom directives.
  14802. !node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
  14803. !context.directiveTransforms[p.name]) &&
  14804. // in compat mode, <template> tags with no special directives
  14805. // will be rendered as a fragment so its children must be
  14806. // converted into vnodes.
  14807. !(false ))))) {
  14808. return;
  14809. }
  14810. // pre-convert text nodes into createTextVNode(text) calls to avoid
  14811. // runtime normalization.
  14812. for (let i = 0; i < children.length; i++) {
  14813. const child = children[i];
  14814. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  14815. const callArgs = [];
  14816. // createTextVNode defaults to single whitespace, so if it is a
  14817. // single space the code could be an empty call to save bytes.
  14818. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  14819. callArgs.push(child);
  14820. }
  14821. // mark dynamic text with flag so it gets patched inside a block
  14822. if (!context.ssr &&
  14823. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14824. callArgs.push(1 /* TEXT */ +
  14825. (` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
  14826. }
  14827. children[i] = {
  14828. type: 12 /* TEXT_CALL */,
  14829. content: child,
  14830. loc: child.loc,
  14831. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  14832. };
  14833. }
  14834. }
  14835. };
  14836. }
  14837. };
  14838. const seen = new WeakSet();
  14839. const transformOnce = (node, context) => {
  14840. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  14841. if (seen.has(node) || context.inVOnce) {
  14842. return;
  14843. }
  14844. seen.add(node);
  14845. context.inVOnce = true;
  14846. context.helper(SET_BLOCK_TRACKING);
  14847. return () => {
  14848. context.inVOnce = false;
  14849. const cur = context.currentNode;
  14850. if (cur.codegenNode) {
  14851. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  14852. }
  14853. };
  14854. }
  14855. };
  14856. const transformModel = (dir, node, context) => {
  14857. const { exp, arg } = dir;
  14858. if (!exp) {
  14859. context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  14860. return createTransformProps();
  14861. }
  14862. const rawExp = exp.loc.source;
  14863. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  14864. // im SFC <script setup> inline mode, the exp may have been transformed into
  14865. // _unref(exp)
  14866. context.bindingMetadata[rawExp];
  14867. const maybeRef = !true /* SETUP_CONST */;
  14868. if (!expString.trim() ||
  14869. (!isMemberExpression(expString) && !maybeRef)) {
  14870. context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  14871. return createTransformProps();
  14872. }
  14873. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  14874. const eventName = arg
  14875. ? isStaticExp(arg)
  14876. ? `onUpdate:${arg.content}`
  14877. : createCompoundExpression(['"onUpdate:" + ', arg])
  14878. : `onUpdate:modelValue`;
  14879. let assignmentExp;
  14880. const eventArg = context.isTS ? `($event: any)` : `$event`;
  14881. {
  14882. assignmentExp = createCompoundExpression([
  14883. `${eventArg} => ((`,
  14884. exp,
  14885. `) = $event)`
  14886. ]);
  14887. }
  14888. const props = [
  14889. // modelValue: foo
  14890. createObjectProperty(propName, dir.exp),
  14891. // "onUpdate:modelValue": $event => (foo = $event)
  14892. createObjectProperty(eventName, assignmentExp)
  14893. ];
  14894. // modelModifiers: { foo: true, "bar-baz": true }
  14895. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  14896. const modifiers = dir.modifiers
  14897. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  14898. .join(`, `);
  14899. const modifiersKey = arg
  14900. ? isStaticExp(arg)
  14901. ? `${arg.content}Modifiers`
  14902. : createCompoundExpression([arg, ' + "Modifiers"'])
  14903. : `modelModifiers`;
  14904. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  14905. }
  14906. return createTransformProps(props);
  14907. };
  14908. function createTransformProps(props = []) {
  14909. return { props };
  14910. }
  14911. const seen$1 = new WeakSet();
  14912. const transformMemo = (node, context) => {
  14913. if (node.type === 1 /* ELEMENT */) {
  14914. const dir = findDir(node, 'memo');
  14915. if (!dir || seen$1.has(node)) {
  14916. return;
  14917. }
  14918. seen$1.add(node);
  14919. return () => {
  14920. const codegenNode = node.codegenNode ||
  14921. context.currentNode.codegenNode;
  14922. if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
  14923. // non-component sub tree should be turned into a block
  14924. if (node.tagType !== 1 /* COMPONENT */) {
  14925. makeBlock(codegenNode, context);
  14926. }
  14927. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  14928. dir.exp,
  14929. createFunctionExpression(undefined, codegenNode),
  14930. `_cache`,
  14931. String(context.cached++)
  14932. ]);
  14933. }
  14934. };
  14935. }
  14936. };
  14937. function getBaseTransformPreset(prefixIdentifiers) {
  14938. return [
  14939. [
  14940. transformOnce,
  14941. transformIf,
  14942. transformMemo,
  14943. transformFor,
  14944. ...([]),
  14945. ...([transformExpression]
  14946. ),
  14947. transformSlotOutlet,
  14948. transformElement,
  14949. trackSlotScopes,
  14950. transformText
  14951. ],
  14952. {
  14953. on: transformOn,
  14954. bind: transformBind,
  14955. model: transformModel
  14956. }
  14957. ];
  14958. }
  14959. // we name it `baseCompile` so that higher order compilers like
  14960. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  14961. function baseCompile(template, options = {}) {
  14962. const onError = options.onError || defaultOnError;
  14963. const isModuleMode = options.mode === 'module';
  14964. /* istanbul ignore if */
  14965. {
  14966. if (options.prefixIdentifiers === true) {
  14967. onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
  14968. }
  14969. else if (isModuleMode) {
  14970. onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
  14971. }
  14972. }
  14973. const prefixIdentifiers = !true ;
  14974. if (options.cacheHandlers) {
  14975. onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  14976. }
  14977. if (options.scopeId && !isModuleMode) {
  14978. onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
  14979. }
  14980. const ast = isString(template) ? baseParse(template, options) : template;
  14981. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  14982. transform(ast, extend({}, options, {
  14983. prefixIdentifiers,
  14984. nodeTransforms: [
  14985. ...nodeTransforms,
  14986. ...(options.nodeTransforms || []) // user transforms
  14987. ],
  14988. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  14989. )
  14990. }));
  14991. return generate(ast, extend({}, options, {
  14992. prefixIdentifiers
  14993. }));
  14994. }
  14995. const noopDirectiveTransform = () => ({ props: [] });
  14996. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  14997. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  14998. const V_MODEL_TEXT = Symbol(`vModelText` );
  14999. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  15000. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  15001. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  15002. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  15003. const V_SHOW = Symbol(`vShow` );
  15004. const TRANSITION$1 = Symbol(`Transition` );
  15005. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  15006. registerRuntimeHelpers({
  15007. [V_MODEL_RADIO]: `vModelRadio`,
  15008. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  15009. [V_MODEL_TEXT]: `vModelText`,
  15010. [V_MODEL_SELECT]: `vModelSelect`,
  15011. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  15012. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  15013. [V_ON_WITH_KEYS]: `withKeys`,
  15014. [V_SHOW]: `vShow`,
  15015. [TRANSITION$1]: `Transition`,
  15016. [TRANSITION_GROUP]: `TransitionGroup`
  15017. });
  15018. /* eslint-disable no-restricted-globals */
  15019. let decoder;
  15020. function decodeHtmlBrowser(raw, asAttr = false) {
  15021. if (!decoder) {
  15022. decoder = document.createElement('div');
  15023. }
  15024. if (asAttr) {
  15025. decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
  15026. return decoder.children[0].getAttribute('foo');
  15027. }
  15028. else {
  15029. decoder.innerHTML = raw;
  15030. return decoder.textContent;
  15031. }
  15032. }
  15033. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  15034. const parserOptions = {
  15035. isVoidTag,
  15036. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  15037. isPreTag: tag => tag === 'pre',
  15038. decodeEntities: decodeHtmlBrowser ,
  15039. isBuiltInComponent: (tag) => {
  15040. if (isBuiltInType(tag, `Transition`)) {
  15041. return TRANSITION$1;
  15042. }
  15043. else if (isBuiltInType(tag, `TransitionGroup`)) {
  15044. return TRANSITION_GROUP;
  15045. }
  15046. },
  15047. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  15048. getNamespace(tag, parent) {
  15049. let ns = parent ? parent.ns : 0 /* HTML */;
  15050. if (parent && ns === 2 /* MATH_ML */) {
  15051. if (parent.tag === 'annotation-xml') {
  15052. if (tag === 'svg') {
  15053. return 1 /* SVG */;
  15054. }
  15055. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  15056. a.name === 'encoding' &&
  15057. a.value != null &&
  15058. (a.value.content === 'text/html' ||
  15059. a.value.content === 'application/xhtml+xml'))) {
  15060. ns = 0 /* HTML */;
  15061. }
  15062. }
  15063. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  15064. tag !== 'mglyph' &&
  15065. tag !== 'malignmark') {
  15066. ns = 0 /* HTML */;
  15067. }
  15068. }
  15069. else if (parent && ns === 1 /* SVG */) {
  15070. if (parent.tag === 'foreignObject' ||
  15071. parent.tag === 'desc' ||
  15072. parent.tag === 'title') {
  15073. ns = 0 /* HTML */;
  15074. }
  15075. }
  15076. if (ns === 0 /* HTML */) {
  15077. if (tag === 'svg') {
  15078. return 1 /* SVG */;
  15079. }
  15080. if (tag === 'math') {
  15081. return 2 /* MATH_ML */;
  15082. }
  15083. }
  15084. return ns;
  15085. },
  15086. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  15087. getTextMode({ tag, ns }) {
  15088. if (ns === 0 /* HTML */) {
  15089. if (tag === 'textarea' || tag === 'title') {
  15090. return 1 /* RCDATA */;
  15091. }
  15092. if (isRawTextContainer(tag)) {
  15093. return 2 /* RAWTEXT */;
  15094. }
  15095. }
  15096. return 0 /* DATA */;
  15097. }
  15098. };
  15099. // Parse inline CSS strings for static style attributes into an object.
  15100. // This is a NodeTransform since it works on the static `style` attribute and
  15101. // converts it into a dynamic equivalent:
  15102. // style="color: red" -> :style='{ "color": "red" }'
  15103. // It is then processed by `transformElement` and included in the generated
  15104. // props.
  15105. const transformStyle = node => {
  15106. if (node.type === 1 /* ELEMENT */) {
  15107. node.props.forEach((p, i) => {
  15108. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  15109. // replace p with an expression node
  15110. node.props[i] = {
  15111. type: 7 /* DIRECTIVE */,
  15112. name: `bind`,
  15113. arg: createSimpleExpression(`style`, true, p.loc),
  15114. exp: parseInlineCSS(p.value.content, p.loc),
  15115. modifiers: [],
  15116. loc: p.loc
  15117. };
  15118. }
  15119. });
  15120. }
  15121. };
  15122. const parseInlineCSS = (cssText, loc) => {
  15123. const normalized = parseStringStyle(cssText);
  15124. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
  15125. };
  15126. function createDOMCompilerError(code, loc) {
  15127. return createCompilerError(code, loc, DOMErrorMessages );
  15128. }
  15129. const DOMErrorMessages = {
  15130. [50 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  15131. [51 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  15132. [52 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  15133. [53 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  15134. [54 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  15135. [55 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  15136. [56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  15137. [57 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  15138. [58 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  15139. [59 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  15140. [60 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  15141. };
  15142. const transformVHtml = (dir, node, context) => {
  15143. const { exp, loc } = dir;
  15144. if (!exp) {
  15145. context.onError(createDOMCompilerError(50 /* X_V_HTML_NO_EXPRESSION */, loc));
  15146. }
  15147. if (node.children.length) {
  15148. context.onError(createDOMCompilerError(51 /* X_V_HTML_WITH_CHILDREN */, loc));
  15149. node.children.length = 0;
  15150. }
  15151. return {
  15152. props: [
  15153. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  15154. ]
  15155. };
  15156. };
  15157. const transformVText = (dir, node, context) => {
  15158. const { exp, loc } = dir;
  15159. if (!exp) {
  15160. context.onError(createDOMCompilerError(52 /* X_V_TEXT_NO_EXPRESSION */, loc));
  15161. }
  15162. if (node.children.length) {
  15163. context.onError(createDOMCompilerError(53 /* X_V_TEXT_WITH_CHILDREN */, loc));
  15164. node.children.length = 0;
  15165. }
  15166. return {
  15167. props: [
  15168. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  15169. ? createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  15170. : createSimpleExpression('', true))
  15171. ]
  15172. };
  15173. };
  15174. const transformModel$1 = (dir, node, context) => {
  15175. const baseResult = transformModel(dir, node, context);
  15176. // base transform has errors OR component v-model (only need props)
  15177. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  15178. return baseResult;
  15179. }
  15180. if (dir.arg) {
  15181. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  15182. }
  15183. function checkDuplicatedValue() {
  15184. const value = findProp(node, 'value');
  15185. if (value) {
  15186. context.onError(createDOMCompilerError(57 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  15187. }
  15188. }
  15189. const { tag } = node;
  15190. const isCustomElement = context.isCustomElement(tag);
  15191. if (tag === 'input' ||
  15192. tag === 'textarea' ||
  15193. tag === 'select' ||
  15194. isCustomElement) {
  15195. let directiveToUse = V_MODEL_TEXT;
  15196. let isInvalidType = false;
  15197. if (tag === 'input' || isCustomElement) {
  15198. const type = findProp(node, `type`);
  15199. if (type) {
  15200. if (type.type === 7 /* DIRECTIVE */) {
  15201. // :type="foo"
  15202. directiveToUse = V_MODEL_DYNAMIC;
  15203. }
  15204. else if (type.value) {
  15205. switch (type.value.content) {
  15206. case 'radio':
  15207. directiveToUse = V_MODEL_RADIO;
  15208. break;
  15209. case 'checkbox':
  15210. directiveToUse = V_MODEL_CHECKBOX;
  15211. break;
  15212. case 'file':
  15213. isInvalidType = true;
  15214. context.onError(createDOMCompilerError(56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  15215. break;
  15216. default:
  15217. // text type
  15218. checkDuplicatedValue();
  15219. break;
  15220. }
  15221. }
  15222. }
  15223. else if (hasDynamicKeyVBind(node)) {
  15224. // element has bindings with dynamic keys, which can possibly contain
  15225. // "type".
  15226. directiveToUse = V_MODEL_DYNAMIC;
  15227. }
  15228. else {
  15229. // text type
  15230. checkDuplicatedValue();
  15231. }
  15232. }
  15233. else if (tag === 'select') {
  15234. directiveToUse = V_MODEL_SELECT;
  15235. }
  15236. else {
  15237. // textarea
  15238. checkDuplicatedValue();
  15239. }
  15240. // inject runtime directive
  15241. // by returning the helper symbol via needRuntime
  15242. // the import will replaced a resolveDirective call.
  15243. if (!isInvalidType) {
  15244. baseResult.needRuntime = context.helper(directiveToUse);
  15245. }
  15246. }
  15247. else {
  15248. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  15249. }
  15250. // native vmodel doesn't need the `modelValue` props since they are also
  15251. // passed to the runtime as `binding.value`. removing it reduces code size.
  15252. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  15253. p.key.content === 'modelValue'));
  15254. return baseResult;
  15255. };
  15256. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  15257. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  15258. // event propagation management
  15259. `stop,prevent,self,` +
  15260. // system modifiers + exact
  15261. `ctrl,shift,alt,meta,exact,` +
  15262. // mouse
  15263. `middle`);
  15264. // left & right could be mouse or key modifiers based on event type
  15265. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  15266. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  15267. const resolveModifiers = (key, modifiers, context, loc) => {
  15268. const keyModifiers = [];
  15269. const nonKeyModifiers = [];
  15270. const eventOptionModifiers = [];
  15271. for (let i = 0; i < modifiers.length; i++) {
  15272. const modifier = modifiers[i];
  15273. if (isEventOptionModifier(modifier)) {
  15274. // eventOptionModifiers: modifiers for addEventListener() options,
  15275. // e.g. .passive & .capture
  15276. eventOptionModifiers.push(modifier);
  15277. }
  15278. else {
  15279. // runtimeModifiers: modifiers that needs runtime guards
  15280. if (maybeKeyModifier(modifier)) {
  15281. if (isStaticExp(key)) {
  15282. if (isKeyboardEvent(key.content)) {
  15283. keyModifiers.push(modifier);
  15284. }
  15285. else {
  15286. nonKeyModifiers.push(modifier);
  15287. }
  15288. }
  15289. else {
  15290. keyModifiers.push(modifier);
  15291. nonKeyModifiers.push(modifier);
  15292. }
  15293. }
  15294. else {
  15295. if (isNonKeyModifier(modifier)) {
  15296. nonKeyModifiers.push(modifier);
  15297. }
  15298. else {
  15299. keyModifiers.push(modifier);
  15300. }
  15301. }
  15302. }
  15303. }
  15304. return {
  15305. keyModifiers,
  15306. nonKeyModifiers,
  15307. eventOptionModifiers
  15308. };
  15309. };
  15310. const transformClick = (key, event) => {
  15311. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  15312. return isStaticClick
  15313. ? createSimpleExpression(event, true)
  15314. : key.type !== 4 /* SIMPLE_EXPRESSION */
  15315. ? createCompoundExpression([
  15316. `(`,
  15317. key,
  15318. `) === "onClick" ? "${event}" : (`,
  15319. key,
  15320. `)`
  15321. ])
  15322. : key;
  15323. };
  15324. const transformOn$1 = (dir, node, context) => {
  15325. return transformOn(dir, node, context, baseResult => {
  15326. const { modifiers } = dir;
  15327. if (!modifiers.length)
  15328. return baseResult;
  15329. let { key, value: handlerExp } = baseResult.props[0];
  15330. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  15331. // normalize click.right and click.middle since they don't actually fire
  15332. if (nonKeyModifiers.includes('right')) {
  15333. key = transformClick(key, `onContextmenu`);
  15334. }
  15335. if (nonKeyModifiers.includes('middle')) {
  15336. key = transformClick(key, `onMouseup`);
  15337. }
  15338. if (nonKeyModifiers.length) {
  15339. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  15340. handlerExp,
  15341. JSON.stringify(nonKeyModifiers)
  15342. ]);
  15343. }
  15344. if (keyModifiers.length &&
  15345. // if event name is dynamic, always wrap with keys guard
  15346. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  15347. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  15348. handlerExp,
  15349. JSON.stringify(keyModifiers)
  15350. ]);
  15351. }
  15352. if (eventOptionModifiers.length) {
  15353. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  15354. key = isStaticExp(key)
  15355. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  15356. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  15357. }
  15358. return {
  15359. props: [createObjectProperty(key, handlerExp)]
  15360. };
  15361. });
  15362. };
  15363. const transformShow = (dir, node, context) => {
  15364. const { exp, loc } = dir;
  15365. if (!exp) {
  15366. context.onError(createDOMCompilerError(58 /* X_V_SHOW_NO_EXPRESSION */, loc));
  15367. }
  15368. return {
  15369. props: [],
  15370. needRuntime: context.helper(V_SHOW)
  15371. };
  15372. };
  15373. const warnTransitionChildren = (node, context) => {
  15374. if (node.type === 1 /* ELEMENT */ &&
  15375. node.tagType === 1 /* COMPONENT */) {
  15376. const component = context.isBuiltInComponent(node.tag);
  15377. if (component === TRANSITION$1) {
  15378. return () => {
  15379. if (node.children.length && hasMultipleChildren(node)) {
  15380. context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
  15381. start: node.children[0].loc.start,
  15382. end: node.children[node.children.length - 1].loc.end,
  15383. source: ''
  15384. }));
  15385. }
  15386. };
  15387. }
  15388. }
  15389. };
  15390. function hasMultipleChildren(node) {
  15391. // #1352 filter out potential comment nodes.
  15392. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */ &&
  15393. !(c.type === 2 /* TEXT */ && !c.content.trim())));
  15394. const child = children[0];
  15395. return (children.length !== 1 ||
  15396. child.type === 11 /* FOR */ ||
  15397. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  15398. }
  15399. const ignoreSideEffectTags = (node, context) => {
  15400. if (node.type === 1 /* ELEMENT */ &&
  15401. node.tagType === 0 /* ELEMENT */ &&
  15402. (node.tag === 'script' || node.tag === 'style')) {
  15403. context.onError(createDOMCompilerError(60 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  15404. context.removeNode();
  15405. }
  15406. };
  15407. const DOMNodeTransforms = [
  15408. transformStyle,
  15409. ...([warnTransitionChildren] )
  15410. ];
  15411. const DOMDirectiveTransforms = {
  15412. cloak: noopDirectiveTransform,
  15413. html: transformVHtml,
  15414. text: transformVText,
  15415. model: transformModel$1,
  15416. on: transformOn$1,
  15417. show: transformShow
  15418. };
  15419. function compile$1(template, options = {}) {
  15420. return baseCompile(template, extend({}, parserOptions, options, {
  15421. nodeTransforms: [
  15422. // ignore <script> and <tag>
  15423. // this is not put inside DOMNodeTransforms because that list is used
  15424. // by compiler-ssr to generate vnode fallback branches
  15425. ignoreSideEffectTags,
  15426. ...DOMNodeTransforms,
  15427. ...(options.nodeTransforms || [])
  15428. ],
  15429. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  15430. transformHoist: null
  15431. }));
  15432. }
  15433. // This entry is the "full-build" that includes both the runtime
  15434. {
  15435. initDev();
  15436. }
  15437. const compileCache = Object.create(null);
  15438. function compileToFunction(template, options) {
  15439. if (!isString(template)) {
  15440. if (template.nodeType) {
  15441. template = template.innerHTML;
  15442. }
  15443. else {
  15444. warn$1(`invalid template option: `, template);
  15445. return NOOP;
  15446. }
  15447. }
  15448. const key = template;
  15449. const cached = compileCache[key];
  15450. if (cached) {
  15451. return cached;
  15452. }
  15453. if (template[0] === '#') {
  15454. const el = document.querySelector(template);
  15455. if (!el) {
  15456. warn$1(`Template element not found or is empty: ${template}`);
  15457. }
  15458. // __UNSAFE__
  15459. // Reason: potential execution of JS expressions in in-DOM template.
  15460. // The user must make sure the in-DOM template is trusted. If it's rendered
  15461. // by the server, the template should not contain any user data.
  15462. template = el ? el.innerHTML : ``;
  15463. }
  15464. const { code } = compile$1(template, extend({
  15465. hoistStatic: true,
  15466. onError: onError ,
  15467. onWarn: e => onError(e, true)
  15468. }, options));
  15469. function onError(err, asWarning = false) {
  15470. const message = asWarning
  15471. ? err.message
  15472. : `Template compilation error: ${err.message}`;
  15473. const codeFrame = err.loc &&
  15474. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  15475. warn$1(codeFrame ? `${message}\n${codeFrame}` : message);
  15476. }
  15477. // The wildcard import results in a huge object with every export
  15478. // with keys that cannot be mangled, and can be quite heavy size-wise.
  15479. // In the global build we know `Vue` is available globally so we can avoid
  15480. // the wildcard object.
  15481. const render = (new Function(code)() );
  15482. render._rc = true;
  15483. return (compileCache[key] = render);
  15484. }
  15485. registerRuntimeCompiler(compileToFunction);
  15486. exports.BaseTransition = BaseTransition;
  15487. exports.Comment = Comment;
  15488. exports.EffectScope = EffectScope;
  15489. exports.Fragment = Fragment;
  15490. exports.KeepAlive = KeepAlive;
  15491. exports.ReactiveEffect = ReactiveEffect;
  15492. exports.Static = Static;
  15493. exports.Suspense = Suspense;
  15494. exports.Teleport = Teleport;
  15495. exports.Text = Text;
  15496. exports.Transition = Transition;
  15497. exports.TransitionGroup = TransitionGroup;
  15498. exports.VueElement = VueElement;
  15499. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  15500. exports.callWithErrorHandling = callWithErrorHandling;
  15501. exports.camelize = camelize;
  15502. exports.capitalize = capitalize;
  15503. exports.cloneVNode = cloneVNode;
  15504. exports.compatUtils = compatUtils;
  15505. exports.compile = compileToFunction;
  15506. exports.computed = computed$1;
  15507. exports.createApp = createApp;
  15508. exports.createBlock = createBlock;
  15509. exports.createCommentVNode = createCommentVNode;
  15510. exports.createElementBlock = createElementBlock;
  15511. exports.createElementVNode = createBaseVNode;
  15512. exports.createHydrationRenderer = createHydrationRenderer;
  15513. exports.createPropsRestProxy = createPropsRestProxy;
  15514. exports.createRenderer = createRenderer;
  15515. exports.createSSRApp = createSSRApp;
  15516. exports.createSlots = createSlots;
  15517. exports.createStaticVNode = createStaticVNode;
  15518. exports.createTextVNode = createTextVNode;
  15519. exports.createVNode = createVNode;
  15520. exports.customRef = customRef;
  15521. exports.defineAsyncComponent = defineAsyncComponent;
  15522. exports.defineComponent = defineComponent;
  15523. exports.defineCustomElement = defineCustomElement;
  15524. exports.defineEmits = defineEmits;
  15525. exports.defineExpose = defineExpose;
  15526. exports.defineProps = defineProps;
  15527. exports.defineSSRCustomElement = defineSSRCustomElement;
  15528. exports.effect = effect;
  15529. exports.effectScope = effectScope;
  15530. exports.getCurrentInstance = getCurrentInstance;
  15531. exports.getCurrentScope = getCurrentScope;
  15532. exports.getTransitionRawChildren = getTransitionRawChildren;
  15533. exports.guardReactiveProps = guardReactiveProps;
  15534. exports.h = h;
  15535. exports.handleError = handleError;
  15536. exports.hydrate = hydrate;
  15537. exports.initCustomFormatter = initCustomFormatter;
  15538. exports.initDirectivesForSSR = initDirectivesForSSR;
  15539. exports.inject = inject;
  15540. exports.isMemoSame = isMemoSame;
  15541. exports.isProxy = isProxy;
  15542. exports.isReactive = isReactive;
  15543. exports.isReadonly = isReadonly;
  15544. exports.isRef = isRef;
  15545. exports.isRuntimeOnly = isRuntimeOnly;
  15546. exports.isShallow = isShallow;
  15547. exports.isVNode = isVNode;
  15548. exports.markRaw = markRaw;
  15549. exports.mergeDefaults = mergeDefaults;
  15550. exports.mergeProps = mergeProps;
  15551. exports.nextTick = nextTick;
  15552. exports.normalizeClass = normalizeClass;
  15553. exports.normalizeProps = normalizeProps;
  15554. exports.normalizeStyle = normalizeStyle;
  15555. exports.onActivated = onActivated;
  15556. exports.onBeforeMount = onBeforeMount;
  15557. exports.onBeforeUnmount = onBeforeUnmount;
  15558. exports.onBeforeUpdate = onBeforeUpdate;
  15559. exports.onDeactivated = onDeactivated;
  15560. exports.onErrorCaptured = onErrorCaptured;
  15561. exports.onMounted = onMounted;
  15562. exports.onRenderTracked = onRenderTracked;
  15563. exports.onRenderTriggered = onRenderTriggered;
  15564. exports.onScopeDispose = onScopeDispose;
  15565. exports.onServerPrefetch = onServerPrefetch;
  15566. exports.onUnmounted = onUnmounted;
  15567. exports.onUpdated = onUpdated;
  15568. exports.openBlock = openBlock;
  15569. exports.popScopeId = popScopeId;
  15570. exports.provide = provide;
  15571. exports.proxyRefs = proxyRefs;
  15572. exports.pushScopeId = pushScopeId;
  15573. exports.queuePostFlushCb = queuePostFlushCb;
  15574. exports.reactive = reactive;
  15575. exports.readonly = readonly;
  15576. exports.ref = ref;
  15577. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  15578. exports.render = render;
  15579. exports.renderList = renderList;
  15580. exports.renderSlot = renderSlot;
  15581. exports.resolveComponent = resolveComponent;
  15582. exports.resolveDirective = resolveDirective;
  15583. exports.resolveDynamicComponent = resolveDynamicComponent;
  15584. exports.resolveFilter = resolveFilter;
  15585. exports.resolveTransitionHooks = resolveTransitionHooks;
  15586. exports.setBlockTracking = setBlockTracking;
  15587. exports.setDevtoolsHook = setDevtoolsHook;
  15588. exports.setTransitionHooks = setTransitionHooks;
  15589. exports.shallowReactive = shallowReactive;
  15590. exports.shallowReadonly = shallowReadonly;
  15591. exports.shallowRef = shallowRef;
  15592. exports.ssrContextKey = ssrContextKey;
  15593. exports.ssrUtils = ssrUtils;
  15594. exports.stop = stop;
  15595. exports.toDisplayString = toDisplayString;
  15596. exports.toHandlerKey = toHandlerKey;
  15597. exports.toHandlers = toHandlers;
  15598. exports.toRaw = toRaw;
  15599. exports.toRef = toRef;
  15600. exports.toRefs = toRefs;
  15601. exports.transformVNodeArgs = transformVNodeArgs;
  15602. exports.triggerRef = triggerRef;
  15603. exports.unref = unref;
  15604. exports.useAttrs = useAttrs;
  15605. exports.useCssModule = useCssModule;
  15606. exports.useCssVars = useCssVars;
  15607. exports.useSSRContext = useSSRContext;
  15608. exports.useSlots = useSlots;
  15609. exports.useTransitionState = useTransitionState;
  15610. exports.vModelCheckbox = vModelCheckbox;
  15611. exports.vModelDynamic = vModelDynamic;
  15612. exports.vModelRadio = vModelRadio;
  15613. exports.vModelSelect = vModelSelect;
  15614. exports.vModelText = vModelText;
  15615. exports.vShow = vShow;
  15616. exports.version = version;
  15617. exports.warn = warn$1;
  15618. exports.watch = watch;
  15619. exports.watchEffect = watchEffect;
  15620. exports.watchPostEffect = watchPostEffect;
  15621. exports.watchSyncEffect = watchSyncEffect;
  15622. exports.withAsyncContext = withAsyncContext;
  15623. exports.withCtx = withCtx;
  15624. exports.withDefaults = withDefaults;
  15625. exports.withDirectives = withDirectives;
  15626. exports.withKeys = withKeys;
  15627. exports.withMemo = withMemo;
  15628. exports.withModifiers = withModifiers;
  15629. exports.withScopeId = withScopeId;
  15630. Object.defineProperty(exports, '__esModule', { value: true });
  15631. return exports;
  15632. }({}));