vue.global.js 611 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934
  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 = isSymbol(a);
  237. bValidType = isSymbol(b);
  238. if (aValidType || bValidType) {
  239. return a === b;
  240. }
  241. aValidType = isArray(a);
  242. bValidType = isArray(b);
  243. if (aValidType || bValidType) {
  244. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  245. }
  246. aValidType = isObject(a);
  247. bValidType = isObject(b);
  248. if (aValidType || bValidType) {
  249. /* istanbul ignore if: this if will probably never be called */
  250. if (!aValidType || !bValidType) {
  251. return false;
  252. }
  253. const aKeysCount = Object.keys(a).length;
  254. const bKeysCount = Object.keys(b).length;
  255. if (aKeysCount !== bKeysCount) {
  256. return false;
  257. }
  258. for (const key in a) {
  259. const aHasKey = a.hasOwnProperty(key);
  260. const bHasKey = b.hasOwnProperty(key);
  261. if ((aHasKey && !bHasKey) ||
  262. (!aHasKey && bHasKey) ||
  263. !looseEqual(a[key], b[key])) {
  264. return false;
  265. }
  266. }
  267. }
  268. return String(a) === String(b);
  269. }
  270. function looseIndexOf(arr, val) {
  271. return arr.findIndex(item => looseEqual(item, val));
  272. }
  273. /**
  274. * For converting {{ interpolation }} values to displayed strings.
  275. * @private
  276. */
  277. const toDisplayString = (val) => {
  278. return isString(val)
  279. ? val
  280. : val == null
  281. ? ''
  282. : isArray(val) ||
  283. (isObject(val) &&
  284. (val.toString === objectToString || !isFunction(val.toString)))
  285. ? JSON.stringify(val, replacer, 2)
  286. : String(val);
  287. };
  288. const replacer = (_key, val) => {
  289. // can't use isRef here since @vue/shared has no deps
  290. if (val && val.__v_isRef) {
  291. return replacer(_key, val.value);
  292. }
  293. else if (isMap(val)) {
  294. return {
  295. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  296. entries[`${key} =>`] = val;
  297. return entries;
  298. }, {})
  299. };
  300. }
  301. else if (isSet(val)) {
  302. return {
  303. [`Set(${val.size})`]: [...val.values()]
  304. };
  305. }
  306. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  307. return String(val);
  308. }
  309. return val;
  310. };
  311. const EMPTY_OBJ = Object.freeze({})
  312. ;
  313. const EMPTY_ARR = Object.freeze([]) ;
  314. const NOOP = () => { };
  315. /**
  316. * Always return false.
  317. */
  318. const NO = () => false;
  319. const onRE = /^on[^a-z]/;
  320. const isOn = (key) => onRE.test(key);
  321. const isModelListener = (key) => key.startsWith('onUpdate:');
  322. const extend = Object.assign;
  323. const remove = (arr, el) => {
  324. const i = arr.indexOf(el);
  325. if (i > -1) {
  326. arr.splice(i, 1);
  327. }
  328. };
  329. const hasOwnProperty = Object.prototype.hasOwnProperty;
  330. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  331. const isArray = Array.isArray;
  332. const isMap = (val) => toTypeString(val) === '[object Map]';
  333. const isSet = (val) => toTypeString(val) === '[object Set]';
  334. const isDate = (val) => toTypeString(val) === '[object Date]';
  335. const isFunction = (val) => typeof val === 'function';
  336. const isString = (val) => typeof val === 'string';
  337. const isSymbol = (val) => typeof val === 'symbol';
  338. const isObject = (val) => val !== null && typeof val === 'object';
  339. const isPromise = (val) => {
  340. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  341. };
  342. const objectToString = Object.prototype.toString;
  343. const toTypeString = (value) => objectToString.call(value);
  344. const toRawType = (value) => {
  345. // extract "RawType" from strings like "[object RawType]"
  346. return toTypeString(value).slice(8, -1);
  347. };
  348. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  349. const isIntegerKey = (key) => isString(key) &&
  350. key !== 'NaN' &&
  351. key[0] !== '-' &&
  352. '' + parseInt(key, 10) === key;
  353. const isReservedProp = /*#__PURE__*/ makeMap(
  354. // the leading comma is intentional so empty string "" is also included
  355. ',key,ref,ref_for,ref_key,' +
  356. 'onVnodeBeforeMount,onVnodeMounted,' +
  357. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  358. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  359. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  360. const cacheStringFunction = (fn) => {
  361. const cache = Object.create(null);
  362. return ((str) => {
  363. const hit = cache[str];
  364. return hit || (cache[str] = fn(str));
  365. });
  366. };
  367. const camelizeRE = /-(\w)/g;
  368. /**
  369. * @private
  370. */
  371. const camelize = cacheStringFunction((str) => {
  372. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  373. });
  374. const hyphenateRE = /\B([A-Z])/g;
  375. /**
  376. * @private
  377. */
  378. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  379. /**
  380. * @private
  381. */
  382. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  383. /**
  384. * @private
  385. */
  386. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  387. // compare whether a value has changed, accounting for NaN.
  388. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  389. const invokeArrayFns = (fns, arg) => {
  390. for (let i = 0; i < fns.length; i++) {
  391. fns[i](arg);
  392. }
  393. };
  394. const def = (obj, key, value) => {
  395. Object.defineProperty(obj, key, {
  396. configurable: true,
  397. enumerable: false,
  398. value
  399. });
  400. };
  401. const toNumber = (val) => {
  402. const n = parseFloat(val);
  403. return isNaN(n) ? val : n;
  404. };
  405. let _globalThis;
  406. const getGlobalThis = () => {
  407. return (_globalThis ||
  408. (_globalThis =
  409. typeof globalThis !== 'undefined'
  410. ? globalThis
  411. : typeof self !== 'undefined'
  412. ? self
  413. : typeof window !== 'undefined'
  414. ? window
  415. : typeof global !== 'undefined'
  416. ? global
  417. : {}));
  418. };
  419. function warn(msg, ...args) {
  420. console.warn(`[Vue warn] ${msg}`, ...args);
  421. }
  422. let activeEffectScope;
  423. class EffectScope {
  424. constructor(detached = false) {
  425. /**
  426. * @internal
  427. */
  428. this.active = true;
  429. /**
  430. * @internal
  431. */
  432. this.effects = [];
  433. /**
  434. * @internal
  435. */
  436. this.cleanups = [];
  437. if (!detached && activeEffectScope) {
  438. this.parent = activeEffectScope;
  439. this.index =
  440. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  441. }
  442. }
  443. run(fn) {
  444. if (this.active) {
  445. const currentEffectScope = activeEffectScope;
  446. try {
  447. activeEffectScope = this;
  448. return fn();
  449. }
  450. finally {
  451. activeEffectScope = currentEffectScope;
  452. }
  453. }
  454. else {
  455. warn(`cannot run an inactive effect scope.`);
  456. }
  457. }
  458. /**
  459. * This should only be called on non-detached scopes
  460. * @internal
  461. */
  462. on() {
  463. activeEffectScope = this;
  464. }
  465. /**
  466. * This should only be called on non-detached scopes
  467. * @internal
  468. */
  469. off() {
  470. activeEffectScope = this.parent;
  471. }
  472. stop(fromParent) {
  473. if (this.active) {
  474. let i, l;
  475. for (i = 0, l = this.effects.length; i < l; i++) {
  476. this.effects[i].stop();
  477. }
  478. for (i = 0, l = this.cleanups.length; i < l; i++) {
  479. this.cleanups[i]();
  480. }
  481. if (this.scopes) {
  482. for (i = 0, l = this.scopes.length; i < l; i++) {
  483. this.scopes[i].stop(true);
  484. }
  485. }
  486. // nested scope, dereference from parent to avoid memory leaks
  487. if (this.parent && !fromParent) {
  488. // optimized O(1) removal
  489. const last = this.parent.scopes.pop();
  490. if (last && last !== this) {
  491. this.parent.scopes[this.index] = last;
  492. last.index = this.index;
  493. }
  494. }
  495. this.active = false;
  496. }
  497. }
  498. }
  499. function effectScope(detached) {
  500. return new EffectScope(detached);
  501. }
  502. function recordEffectScope(effect, scope = activeEffectScope) {
  503. if (scope && scope.active) {
  504. scope.effects.push(effect);
  505. }
  506. }
  507. function getCurrentScope() {
  508. return activeEffectScope;
  509. }
  510. function onScopeDispose(fn) {
  511. if (activeEffectScope) {
  512. activeEffectScope.cleanups.push(fn);
  513. }
  514. else {
  515. warn(`onScopeDispose() is called when there is no active effect scope` +
  516. ` to be associated with.`);
  517. }
  518. }
  519. const createDep = (effects) => {
  520. const dep = new Set(effects);
  521. dep.w = 0;
  522. dep.n = 0;
  523. return dep;
  524. };
  525. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  526. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  527. const initDepMarkers = ({ deps }) => {
  528. if (deps.length) {
  529. for (let i = 0; i < deps.length; i++) {
  530. deps[i].w |= trackOpBit; // set was tracked
  531. }
  532. }
  533. };
  534. const finalizeDepMarkers = (effect) => {
  535. const { deps } = effect;
  536. if (deps.length) {
  537. let ptr = 0;
  538. for (let i = 0; i < deps.length; i++) {
  539. const dep = deps[i];
  540. if (wasTracked(dep) && !newTracked(dep)) {
  541. dep.delete(effect);
  542. }
  543. else {
  544. deps[ptr++] = dep;
  545. }
  546. // clear bits
  547. dep.w &= ~trackOpBit;
  548. dep.n &= ~trackOpBit;
  549. }
  550. deps.length = ptr;
  551. }
  552. };
  553. const targetMap = new WeakMap();
  554. // The number of effects currently being tracked recursively.
  555. let effectTrackDepth = 0;
  556. let trackOpBit = 1;
  557. /**
  558. * The bitwise track markers support at most 30 levels of recursion.
  559. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  560. * When recursion depth is greater, fall back to using a full cleanup.
  561. */
  562. const maxMarkerBits = 30;
  563. let activeEffect;
  564. const ITERATE_KEY = Symbol('iterate' );
  565. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  566. class ReactiveEffect {
  567. constructor(fn, scheduler = null, scope) {
  568. this.fn = fn;
  569. this.scheduler = scheduler;
  570. this.active = true;
  571. this.deps = [];
  572. this.parent = undefined;
  573. recordEffectScope(this, scope);
  574. }
  575. run() {
  576. if (!this.active) {
  577. return this.fn();
  578. }
  579. let parent = activeEffect;
  580. let lastShouldTrack = shouldTrack;
  581. while (parent) {
  582. if (parent === this) {
  583. return;
  584. }
  585. parent = parent.parent;
  586. }
  587. try {
  588. this.parent = activeEffect;
  589. activeEffect = this;
  590. shouldTrack = true;
  591. trackOpBit = 1 << ++effectTrackDepth;
  592. if (effectTrackDepth <= maxMarkerBits) {
  593. initDepMarkers(this);
  594. }
  595. else {
  596. cleanupEffect(this);
  597. }
  598. return this.fn();
  599. }
  600. finally {
  601. if (effectTrackDepth <= maxMarkerBits) {
  602. finalizeDepMarkers(this);
  603. }
  604. trackOpBit = 1 << --effectTrackDepth;
  605. activeEffect = this.parent;
  606. shouldTrack = lastShouldTrack;
  607. this.parent = undefined;
  608. if (this.deferStop) {
  609. this.stop();
  610. }
  611. }
  612. }
  613. stop() {
  614. // stopped while running itself - defer the cleanup
  615. if (activeEffect === this) {
  616. this.deferStop = true;
  617. }
  618. else if (this.active) {
  619. cleanupEffect(this);
  620. if (this.onStop) {
  621. this.onStop();
  622. }
  623. this.active = false;
  624. }
  625. }
  626. }
  627. function cleanupEffect(effect) {
  628. const { deps } = effect;
  629. if (deps.length) {
  630. for (let i = 0; i < deps.length; i++) {
  631. deps[i].delete(effect);
  632. }
  633. deps.length = 0;
  634. }
  635. }
  636. function effect(fn, options) {
  637. if (fn.effect) {
  638. fn = fn.effect.fn;
  639. }
  640. const _effect = new ReactiveEffect(fn);
  641. if (options) {
  642. extend(_effect, options);
  643. if (options.scope)
  644. recordEffectScope(_effect, options.scope);
  645. }
  646. if (!options || !options.lazy) {
  647. _effect.run();
  648. }
  649. const runner = _effect.run.bind(_effect);
  650. runner.effect = _effect;
  651. return runner;
  652. }
  653. function stop(runner) {
  654. runner.effect.stop();
  655. }
  656. let shouldTrack = true;
  657. const trackStack = [];
  658. function pauseTracking() {
  659. trackStack.push(shouldTrack);
  660. shouldTrack = false;
  661. }
  662. function resetTracking() {
  663. const last = trackStack.pop();
  664. shouldTrack = last === undefined ? true : last;
  665. }
  666. function track(target, type, key) {
  667. if (shouldTrack && activeEffect) {
  668. let depsMap = targetMap.get(target);
  669. if (!depsMap) {
  670. targetMap.set(target, (depsMap = new Map()));
  671. }
  672. let dep = depsMap.get(key);
  673. if (!dep) {
  674. depsMap.set(key, (dep = createDep()));
  675. }
  676. const eventInfo = { effect: activeEffect, target, type, key }
  677. ;
  678. trackEffects(dep, eventInfo);
  679. }
  680. }
  681. function trackEffects(dep, debuggerEventExtraInfo) {
  682. let shouldTrack = false;
  683. if (effectTrackDepth <= maxMarkerBits) {
  684. if (!newTracked(dep)) {
  685. dep.n |= trackOpBit; // set newly tracked
  686. shouldTrack = !wasTracked(dep);
  687. }
  688. }
  689. else {
  690. // Full cleanup mode.
  691. shouldTrack = !dep.has(activeEffect);
  692. }
  693. if (shouldTrack) {
  694. dep.add(activeEffect);
  695. activeEffect.deps.push(dep);
  696. if (activeEffect.onTrack) {
  697. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  698. }
  699. }
  700. }
  701. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  702. const depsMap = targetMap.get(target);
  703. if (!depsMap) {
  704. // never been tracked
  705. return;
  706. }
  707. let deps = [];
  708. if (type === "clear" /* CLEAR */) {
  709. // collection being cleared
  710. // trigger all effects for target
  711. deps = [...depsMap.values()];
  712. }
  713. else if (key === 'length' && isArray(target)) {
  714. depsMap.forEach((dep, key) => {
  715. if (key === 'length' || key >= newValue) {
  716. deps.push(dep);
  717. }
  718. });
  719. }
  720. else {
  721. // schedule runs for SET | ADD | DELETE
  722. if (key !== void 0) {
  723. deps.push(depsMap.get(key));
  724. }
  725. // also run for iteration key on ADD | DELETE | Map.SET
  726. switch (type) {
  727. case "add" /* ADD */:
  728. if (!isArray(target)) {
  729. deps.push(depsMap.get(ITERATE_KEY));
  730. if (isMap(target)) {
  731. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  732. }
  733. }
  734. else if (isIntegerKey(key)) {
  735. // new index added to array -> length changes
  736. deps.push(depsMap.get('length'));
  737. }
  738. break;
  739. case "delete" /* DELETE */:
  740. if (!isArray(target)) {
  741. deps.push(depsMap.get(ITERATE_KEY));
  742. if (isMap(target)) {
  743. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  744. }
  745. }
  746. break;
  747. case "set" /* SET */:
  748. if (isMap(target)) {
  749. deps.push(depsMap.get(ITERATE_KEY));
  750. }
  751. break;
  752. }
  753. }
  754. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  755. ;
  756. if (deps.length === 1) {
  757. if (deps[0]) {
  758. {
  759. triggerEffects(deps[0], eventInfo);
  760. }
  761. }
  762. }
  763. else {
  764. const effects = [];
  765. for (const dep of deps) {
  766. if (dep) {
  767. effects.push(...dep);
  768. }
  769. }
  770. {
  771. triggerEffects(createDep(effects), eventInfo);
  772. }
  773. }
  774. }
  775. function triggerEffects(dep, debuggerEventExtraInfo) {
  776. // spread into array for stabilization
  777. const effects = isArray(dep) ? dep : [...dep];
  778. for (const effect of effects) {
  779. if (effect.computed) {
  780. triggerEffect(effect, debuggerEventExtraInfo);
  781. }
  782. }
  783. for (const effect of effects) {
  784. if (!effect.computed) {
  785. triggerEffect(effect, debuggerEventExtraInfo);
  786. }
  787. }
  788. }
  789. function triggerEffect(effect, debuggerEventExtraInfo) {
  790. if (effect !== activeEffect || effect.allowRecurse) {
  791. if (effect.onTrigger) {
  792. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  793. }
  794. if (effect.scheduler) {
  795. effect.scheduler();
  796. }
  797. else {
  798. effect.run();
  799. }
  800. }
  801. }
  802. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  803. const builtInSymbols = new Set(
  804. /*#__PURE__*/
  805. Object.getOwnPropertyNames(Symbol)
  806. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  807. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  808. // function
  809. .filter(key => key !== 'arguments' && key !== 'caller')
  810. .map(key => Symbol[key])
  811. .filter(isSymbol));
  812. const get = /*#__PURE__*/ createGetter();
  813. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  814. const readonlyGet = /*#__PURE__*/ createGetter(true);
  815. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  816. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  817. function createArrayInstrumentations() {
  818. const instrumentations = {};
  819. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  820. instrumentations[key] = function (...args) {
  821. const arr = toRaw(this);
  822. for (let i = 0, l = this.length; i < l; i++) {
  823. track(arr, "get" /* GET */, i + '');
  824. }
  825. // we run the method using the original args first (which may be reactive)
  826. const res = arr[key](...args);
  827. if (res === -1 || res === false) {
  828. // if that didn't work, run it again using raw values.
  829. return arr[key](...args.map(toRaw));
  830. }
  831. else {
  832. return res;
  833. }
  834. };
  835. });
  836. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  837. instrumentations[key] = function (...args) {
  838. pauseTracking();
  839. const res = toRaw(this)[key].apply(this, args);
  840. resetTracking();
  841. return res;
  842. };
  843. });
  844. return instrumentations;
  845. }
  846. function createGetter(isReadonly = false, shallow = false) {
  847. return function get(target, key, receiver) {
  848. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  849. return !isReadonly;
  850. }
  851. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  852. return isReadonly;
  853. }
  854. else if (key === "__v_isShallow" /* IS_SHALLOW */) {
  855. return shallow;
  856. }
  857. else if (key === "__v_raw" /* RAW */ &&
  858. receiver ===
  859. (isReadonly
  860. ? shallow
  861. ? shallowReadonlyMap
  862. : readonlyMap
  863. : shallow
  864. ? shallowReactiveMap
  865. : reactiveMap).get(target)) {
  866. return target;
  867. }
  868. const targetIsArray = isArray(target);
  869. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  870. return Reflect.get(arrayInstrumentations, key, receiver);
  871. }
  872. const res = Reflect.get(target, key, receiver);
  873. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  874. return res;
  875. }
  876. if (!isReadonly) {
  877. track(target, "get" /* GET */, key);
  878. }
  879. if (shallow) {
  880. return res;
  881. }
  882. if (isRef(res)) {
  883. // ref unwrapping - skip unwrap for Array + integer key.
  884. return targetIsArray && isIntegerKey(key) ? res : res.value;
  885. }
  886. if (isObject(res)) {
  887. // Convert returned value into a proxy as well. we do the isObject check
  888. // here to avoid invalid value warning. Also need to lazy access readonly
  889. // and reactive here to avoid circular dependency.
  890. return isReadonly ? readonly(res) : reactive(res);
  891. }
  892. return res;
  893. };
  894. }
  895. const set = /*#__PURE__*/ createSetter();
  896. const shallowSet = /*#__PURE__*/ createSetter(true);
  897. function createSetter(shallow = false) {
  898. return function set(target, key, value, receiver) {
  899. let oldValue = target[key];
  900. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  901. return false;
  902. }
  903. if (!shallow && !isReadonly(value)) {
  904. if (!isShallow(value)) {
  905. value = toRaw(value);
  906. oldValue = toRaw(oldValue);
  907. }
  908. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  909. oldValue.value = value;
  910. return true;
  911. }
  912. }
  913. const hadKey = isArray(target) && isIntegerKey(key)
  914. ? Number(key) < target.length
  915. : hasOwn(target, key);
  916. const result = Reflect.set(target, key, value, receiver);
  917. // don't trigger if target is something up in the prototype chain of original
  918. if (target === toRaw(receiver)) {
  919. if (!hadKey) {
  920. trigger(target, "add" /* ADD */, key, value);
  921. }
  922. else if (hasChanged(value, oldValue)) {
  923. trigger(target, "set" /* SET */, key, value, oldValue);
  924. }
  925. }
  926. return result;
  927. };
  928. }
  929. function deleteProperty(target, key) {
  930. const hadKey = hasOwn(target, key);
  931. const oldValue = target[key];
  932. const result = Reflect.deleteProperty(target, key);
  933. if (result && hadKey) {
  934. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  935. }
  936. return result;
  937. }
  938. function has(target, key) {
  939. const result = Reflect.has(target, key);
  940. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  941. track(target, "has" /* HAS */, key);
  942. }
  943. return result;
  944. }
  945. function ownKeys(target) {
  946. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  947. return Reflect.ownKeys(target);
  948. }
  949. const mutableHandlers = {
  950. get,
  951. set,
  952. deleteProperty,
  953. has,
  954. ownKeys
  955. };
  956. const readonlyHandlers = {
  957. get: readonlyGet,
  958. set(target, key) {
  959. {
  960. warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  961. }
  962. return true;
  963. },
  964. deleteProperty(target, key) {
  965. {
  966. warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  967. }
  968. return true;
  969. }
  970. };
  971. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  972. get: shallowGet,
  973. set: shallowSet
  974. });
  975. // Props handlers are special in the sense that it should not unwrap top-level
  976. // refs (in order to allow refs to be explicitly passed down), but should
  977. // retain the reactivity of the normal readonly object.
  978. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  979. get: shallowReadonlyGet
  980. });
  981. const toShallow = (value) => value;
  982. const getProto = (v) => Reflect.getPrototypeOf(v);
  983. function get$1(target, key, isReadonly = false, isShallow = false) {
  984. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  985. // of the value
  986. target = target["__v_raw" /* RAW */];
  987. const rawTarget = toRaw(target);
  988. const rawKey = toRaw(key);
  989. if (!isReadonly) {
  990. if (key !== rawKey) {
  991. track(rawTarget, "get" /* GET */, key);
  992. }
  993. track(rawTarget, "get" /* GET */, rawKey);
  994. }
  995. const { has } = getProto(rawTarget);
  996. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  997. if (has.call(rawTarget, key)) {
  998. return wrap(target.get(key));
  999. }
  1000. else if (has.call(rawTarget, rawKey)) {
  1001. return wrap(target.get(rawKey));
  1002. }
  1003. else if (target !== rawTarget) {
  1004. // #3602 readonly(reactive(Map))
  1005. // ensure that the nested reactive `Map` can do tracking for itself
  1006. target.get(key);
  1007. }
  1008. }
  1009. function has$1(key, isReadonly = false) {
  1010. const target = this["__v_raw" /* RAW */];
  1011. const rawTarget = toRaw(target);
  1012. const rawKey = toRaw(key);
  1013. if (!isReadonly) {
  1014. if (key !== rawKey) {
  1015. track(rawTarget, "has" /* HAS */, key);
  1016. }
  1017. track(rawTarget, "has" /* HAS */, rawKey);
  1018. }
  1019. return key === rawKey
  1020. ? target.has(key)
  1021. : target.has(key) || target.has(rawKey);
  1022. }
  1023. function size(target, isReadonly = false) {
  1024. target = target["__v_raw" /* RAW */];
  1025. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  1026. return Reflect.get(target, 'size', target);
  1027. }
  1028. function add(value) {
  1029. value = toRaw(value);
  1030. const target = toRaw(this);
  1031. const proto = getProto(target);
  1032. const hadKey = proto.has.call(target, value);
  1033. if (!hadKey) {
  1034. target.add(value);
  1035. trigger(target, "add" /* ADD */, value, value);
  1036. }
  1037. return this;
  1038. }
  1039. function set$1(key, value) {
  1040. value = toRaw(value);
  1041. const target = toRaw(this);
  1042. const { has, get } = getProto(target);
  1043. let hadKey = has.call(target, key);
  1044. if (!hadKey) {
  1045. key = toRaw(key);
  1046. hadKey = has.call(target, key);
  1047. }
  1048. else {
  1049. checkIdentityKeys(target, has, key);
  1050. }
  1051. const oldValue = get.call(target, key);
  1052. target.set(key, value);
  1053. if (!hadKey) {
  1054. trigger(target, "add" /* ADD */, key, value);
  1055. }
  1056. else if (hasChanged(value, oldValue)) {
  1057. trigger(target, "set" /* SET */, key, value, oldValue);
  1058. }
  1059. return this;
  1060. }
  1061. function deleteEntry(key) {
  1062. const target = toRaw(this);
  1063. const { has, get } = getProto(target);
  1064. let hadKey = has.call(target, key);
  1065. if (!hadKey) {
  1066. key = toRaw(key);
  1067. hadKey = has.call(target, key);
  1068. }
  1069. else {
  1070. checkIdentityKeys(target, has, key);
  1071. }
  1072. const oldValue = get ? get.call(target, key) : undefined;
  1073. // forward the operation before queueing reactions
  1074. const result = target.delete(key);
  1075. if (hadKey) {
  1076. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  1077. }
  1078. return result;
  1079. }
  1080. function clear() {
  1081. const target = toRaw(this);
  1082. const hadItems = target.size !== 0;
  1083. const oldTarget = isMap(target)
  1084. ? new Map(target)
  1085. : new Set(target)
  1086. ;
  1087. // forward the operation before queueing reactions
  1088. const result = target.clear();
  1089. if (hadItems) {
  1090. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  1091. }
  1092. return result;
  1093. }
  1094. function createForEach(isReadonly, isShallow) {
  1095. return function forEach(callback, thisArg) {
  1096. const observed = this;
  1097. const target = observed["__v_raw" /* RAW */];
  1098. const rawTarget = toRaw(target);
  1099. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1100. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  1101. return target.forEach((value, key) => {
  1102. // important: make sure the callback is
  1103. // 1. invoked with the reactive map as `this` and 3rd arg
  1104. // 2. the value received should be a corresponding reactive/readonly.
  1105. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1106. });
  1107. };
  1108. }
  1109. function createIterableMethod(method, isReadonly, isShallow) {
  1110. return function (...args) {
  1111. const target = this["__v_raw" /* RAW */];
  1112. const rawTarget = toRaw(target);
  1113. const targetIsMap = isMap(rawTarget);
  1114. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1115. const isKeyOnly = method === 'keys' && targetIsMap;
  1116. const innerIterator = target[method](...args);
  1117. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1118. !isReadonly &&
  1119. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1120. // return a wrapped iterator which returns observed versions of the
  1121. // values emitted from the real iterator
  1122. return {
  1123. // iterator protocol
  1124. next() {
  1125. const { value, done } = innerIterator.next();
  1126. return done
  1127. ? { value, done }
  1128. : {
  1129. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1130. done
  1131. };
  1132. },
  1133. // iterable protocol
  1134. [Symbol.iterator]() {
  1135. return this;
  1136. }
  1137. };
  1138. };
  1139. }
  1140. function createReadonlyMethod(type) {
  1141. return function (...args) {
  1142. {
  1143. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1144. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1145. }
  1146. return type === "delete" /* DELETE */ ? false : this;
  1147. };
  1148. }
  1149. function createInstrumentations() {
  1150. const mutableInstrumentations = {
  1151. get(key) {
  1152. return get$1(this, key);
  1153. },
  1154. get size() {
  1155. return size(this);
  1156. },
  1157. has: has$1,
  1158. add,
  1159. set: set$1,
  1160. delete: deleteEntry,
  1161. clear,
  1162. forEach: createForEach(false, false)
  1163. };
  1164. const shallowInstrumentations = {
  1165. get(key) {
  1166. return get$1(this, key, false, true);
  1167. },
  1168. get size() {
  1169. return size(this);
  1170. },
  1171. has: has$1,
  1172. add,
  1173. set: set$1,
  1174. delete: deleteEntry,
  1175. clear,
  1176. forEach: createForEach(false, true)
  1177. };
  1178. const readonlyInstrumentations = {
  1179. get(key) {
  1180. return get$1(this, key, true);
  1181. },
  1182. get size() {
  1183. return size(this, true);
  1184. },
  1185. has(key) {
  1186. return has$1.call(this, key, true);
  1187. },
  1188. add: createReadonlyMethod("add" /* ADD */),
  1189. set: createReadonlyMethod("set" /* SET */),
  1190. delete: createReadonlyMethod("delete" /* DELETE */),
  1191. clear: createReadonlyMethod("clear" /* CLEAR */),
  1192. forEach: createForEach(true, false)
  1193. };
  1194. const shallowReadonlyInstrumentations = {
  1195. get(key) {
  1196. return get$1(this, key, true, true);
  1197. },
  1198. get size() {
  1199. return size(this, true);
  1200. },
  1201. has(key) {
  1202. return has$1.call(this, key, true);
  1203. },
  1204. add: createReadonlyMethod("add" /* ADD */),
  1205. set: createReadonlyMethod("set" /* SET */),
  1206. delete: createReadonlyMethod("delete" /* DELETE */),
  1207. clear: createReadonlyMethod("clear" /* CLEAR */),
  1208. forEach: createForEach(true, true)
  1209. };
  1210. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1211. iteratorMethods.forEach(method => {
  1212. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1213. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1214. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1215. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1216. });
  1217. return [
  1218. mutableInstrumentations,
  1219. readonlyInstrumentations,
  1220. shallowInstrumentations,
  1221. shallowReadonlyInstrumentations
  1222. ];
  1223. }
  1224. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1225. function createInstrumentationGetter(isReadonly, shallow) {
  1226. const instrumentations = shallow
  1227. ? isReadonly
  1228. ? shallowReadonlyInstrumentations
  1229. : shallowInstrumentations
  1230. : isReadonly
  1231. ? readonlyInstrumentations
  1232. : mutableInstrumentations;
  1233. return (target, key, receiver) => {
  1234. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  1235. return !isReadonly;
  1236. }
  1237. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  1238. return isReadonly;
  1239. }
  1240. else if (key === "__v_raw" /* RAW */) {
  1241. return target;
  1242. }
  1243. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1244. ? instrumentations
  1245. : target, key, receiver);
  1246. };
  1247. }
  1248. const mutableCollectionHandlers = {
  1249. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1250. };
  1251. const shallowCollectionHandlers = {
  1252. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1253. };
  1254. const readonlyCollectionHandlers = {
  1255. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1256. };
  1257. const shallowReadonlyCollectionHandlers = {
  1258. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1259. };
  1260. function checkIdentityKeys(target, has, key) {
  1261. const rawKey = toRaw(key);
  1262. if (rawKey !== key && has.call(target, rawKey)) {
  1263. const type = toRawType(target);
  1264. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1265. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1266. `which can lead to inconsistencies. ` +
  1267. `Avoid differentiating between the raw and reactive versions ` +
  1268. `of an object and only use the reactive version if possible.`);
  1269. }
  1270. }
  1271. const reactiveMap = new WeakMap();
  1272. const shallowReactiveMap = new WeakMap();
  1273. const readonlyMap = new WeakMap();
  1274. const shallowReadonlyMap = new WeakMap();
  1275. function targetTypeMap(rawType) {
  1276. switch (rawType) {
  1277. case 'Object':
  1278. case 'Array':
  1279. return 1 /* COMMON */;
  1280. case 'Map':
  1281. case 'Set':
  1282. case 'WeakMap':
  1283. case 'WeakSet':
  1284. return 2 /* COLLECTION */;
  1285. default:
  1286. return 0 /* INVALID */;
  1287. }
  1288. }
  1289. function getTargetType(value) {
  1290. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  1291. ? 0 /* INVALID */
  1292. : targetTypeMap(toRawType(value));
  1293. }
  1294. function reactive(target) {
  1295. // if trying to observe a readonly proxy, return the readonly version.
  1296. if (isReadonly(target)) {
  1297. return target;
  1298. }
  1299. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1300. }
  1301. /**
  1302. * Return a shallowly-reactive copy of the original object, where only the root
  1303. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1304. * root level).
  1305. */
  1306. function shallowReactive(target) {
  1307. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1308. }
  1309. /**
  1310. * Creates a readonly copy of the original object. Note the returned copy is not
  1311. * made reactive, but `readonly` can be called on an already reactive object.
  1312. */
  1313. function readonly(target) {
  1314. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1315. }
  1316. /**
  1317. * Returns a reactive-copy of the original object, where only the root level
  1318. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1319. * returned properties.
  1320. * This is used for creating the props proxy object for stateful components.
  1321. */
  1322. function shallowReadonly(target) {
  1323. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1324. }
  1325. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1326. if (!isObject(target)) {
  1327. {
  1328. console.warn(`value cannot be made reactive: ${String(target)}`);
  1329. }
  1330. return target;
  1331. }
  1332. // target is already a Proxy, return it.
  1333. // exception: calling readonly() on a reactive object
  1334. if (target["__v_raw" /* RAW */] &&
  1335. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1336. return target;
  1337. }
  1338. // target already has corresponding Proxy
  1339. const existingProxy = proxyMap.get(target);
  1340. if (existingProxy) {
  1341. return existingProxy;
  1342. }
  1343. // only specific value types can be observed.
  1344. const targetType = getTargetType(target);
  1345. if (targetType === 0 /* INVALID */) {
  1346. return target;
  1347. }
  1348. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1349. proxyMap.set(target, proxy);
  1350. return proxy;
  1351. }
  1352. function isReactive(value) {
  1353. if (isReadonly(value)) {
  1354. return isReactive(value["__v_raw" /* RAW */]);
  1355. }
  1356. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1357. }
  1358. function isReadonly(value) {
  1359. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1360. }
  1361. function isShallow(value) {
  1362. return !!(value && value["__v_isShallow" /* IS_SHALLOW */]);
  1363. }
  1364. function isProxy(value) {
  1365. return isReactive(value) || isReadonly(value);
  1366. }
  1367. function toRaw(observed) {
  1368. const raw = observed && observed["__v_raw" /* RAW */];
  1369. return raw ? toRaw(raw) : observed;
  1370. }
  1371. function markRaw(value) {
  1372. def(value, "__v_skip" /* SKIP */, true);
  1373. return value;
  1374. }
  1375. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1376. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1377. function trackRefValue(ref) {
  1378. if (shouldTrack && activeEffect) {
  1379. ref = toRaw(ref);
  1380. {
  1381. trackEffects(ref.dep || (ref.dep = createDep()), {
  1382. target: ref,
  1383. type: "get" /* GET */,
  1384. key: 'value'
  1385. });
  1386. }
  1387. }
  1388. }
  1389. function triggerRefValue(ref, newVal) {
  1390. ref = toRaw(ref);
  1391. if (ref.dep) {
  1392. {
  1393. triggerEffects(ref.dep, {
  1394. target: ref,
  1395. type: "set" /* SET */,
  1396. key: 'value',
  1397. newValue: newVal
  1398. });
  1399. }
  1400. }
  1401. }
  1402. function isRef(r) {
  1403. return !!(r && r.__v_isRef === true);
  1404. }
  1405. function ref(value) {
  1406. return createRef(value, false);
  1407. }
  1408. function shallowRef(value) {
  1409. return createRef(value, true);
  1410. }
  1411. function createRef(rawValue, shallow) {
  1412. if (isRef(rawValue)) {
  1413. return rawValue;
  1414. }
  1415. return new RefImpl(rawValue, shallow);
  1416. }
  1417. class RefImpl {
  1418. constructor(value, __v_isShallow) {
  1419. this.__v_isShallow = __v_isShallow;
  1420. this.dep = undefined;
  1421. this.__v_isRef = true;
  1422. this._rawValue = __v_isShallow ? value : toRaw(value);
  1423. this._value = __v_isShallow ? value : toReactive(value);
  1424. }
  1425. get value() {
  1426. trackRefValue(this);
  1427. return this._value;
  1428. }
  1429. set value(newVal) {
  1430. newVal = this.__v_isShallow ? newVal : toRaw(newVal);
  1431. if (hasChanged(newVal, this._rawValue)) {
  1432. this._rawValue = newVal;
  1433. this._value = this.__v_isShallow ? newVal : toReactive(newVal);
  1434. triggerRefValue(this, newVal);
  1435. }
  1436. }
  1437. }
  1438. function triggerRef(ref) {
  1439. triggerRefValue(ref, ref.value );
  1440. }
  1441. function unref(ref) {
  1442. return isRef(ref) ? ref.value : ref;
  1443. }
  1444. const shallowUnwrapHandlers = {
  1445. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1446. set: (target, key, value, receiver) => {
  1447. const oldValue = target[key];
  1448. if (isRef(oldValue) && !isRef(value)) {
  1449. oldValue.value = value;
  1450. return true;
  1451. }
  1452. else {
  1453. return Reflect.set(target, key, value, receiver);
  1454. }
  1455. }
  1456. };
  1457. function proxyRefs(objectWithRefs) {
  1458. return isReactive(objectWithRefs)
  1459. ? objectWithRefs
  1460. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1461. }
  1462. class CustomRefImpl {
  1463. constructor(factory) {
  1464. this.dep = undefined;
  1465. this.__v_isRef = true;
  1466. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1467. this._get = get;
  1468. this._set = set;
  1469. }
  1470. get value() {
  1471. return this._get();
  1472. }
  1473. set value(newVal) {
  1474. this._set(newVal);
  1475. }
  1476. }
  1477. function customRef(factory) {
  1478. return new CustomRefImpl(factory);
  1479. }
  1480. function toRefs(object) {
  1481. if (!isProxy(object)) {
  1482. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1483. }
  1484. const ret = isArray(object) ? new Array(object.length) : {};
  1485. for (const key in object) {
  1486. ret[key] = toRef(object, key);
  1487. }
  1488. return ret;
  1489. }
  1490. class ObjectRefImpl {
  1491. constructor(_object, _key, _defaultValue) {
  1492. this._object = _object;
  1493. this._key = _key;
  1494. this._defaultValue = _defaultValue;
  1495. this.__v_isRef = true;
  1496. }
  1497. get value() {
  1498. const val = this._object[this._key];
  1499. return val === undefined ? this._defaultValue : val;
  1500. }
  1501. set value(newVal) {
  1502. this._object[this._key] = newVal;
  1503. }
  1504. }
  1505. function toRef(object, key, defaultValue) {
  1506. const val = object[key];
  1507. return isRef(val)
  1508. ? val
  1509. : new ObjectRefImpl(object, key, defaultValue);
  1510. }
  1511. class ComputedRefImpl {
  1512. constructor(getter, _setter, isReadonly, isSSR) {
  1513. this._setter = _setter;
  1514. this.dep = undefined;
  1515. this.__v_isRef = true;
  1516. this._dirty = true;
  1517. this.effect = new ReactiveEffect(getter, () => {
  1518. if (!this._dirty) {
  1519. this._dirty = true;
  1520. triggerRefValue(this);
  1521. }
  1522. });
  1523. this.effect.computed = this;
  1524. this.effect.active = this._cacheable = !isSSR;
  1525. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1526. }
  1527. get value() {
  1528. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1529. const self = toRaw(this);
  1530. trackRefValue(self);
  1531. if (self._dirty || !self._cacheable) {
  1532. self._dirty = false;
  1533. self._value = self.effect.run();
  1534. }
  1535. return self._value;
  1536. }
  1537. set value(newValue) {
  1538. this._setter(newValue);
  1539. }
  1540. }
  1541. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1542. let getter;
  1543. let setter;
  1544. const onlyGetter = isFunction(getterOrOptions);
  1545. if (onlyGetter) {
  1546. getter = getterOrOptions;
  1547. setter = () => {
  1548. console.warn('Write operation failed: computed value is readonly');
  1549. }
  1550. ;
  1551. }
  1552. else {
  1553. getter = getterOrOptions.get;
  1554. setter = getterOrOptions.set;
  1555. }
  1556. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1557. if (debugOptions && !isSSR) {
  1558. cRef.effect.onTrack = debugOptions.onTrack;
  1559. cRef.effect.onTrigger = debugOptions.onTrigger;
  1560. }
  1561. return cRef;
  1562. }
  1563. const stack = [];
  1564. function pushWarningContext(vnode) {
  1565. stack.push(vnode);
  1566. }
  1567. function popWarningContext() {
  1568. stack.pop();
  1569. }
  1570. function warn$1(msg, ...args) {
  1571. // avoid props formatting or warn handler tracking deps that might be mutated
  1572. // during patch, leading to infinite recursion.
  1573. pauseTracking();
  1574. const instance = stack.length ? stack[stack.length - 1].component : null;
  1575. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1576. const trace = getComponentTrace();
  1577. if (appWarnHandler) {
  1578. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1579. msg + args.join(''),
  1580. instance && instance.proxy,
  1581. trace
  1582. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1583. .join('\n'),
  1584. trace
  1585. ]);
  1586. }
  1587. else {
  1588. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1589. /* istanbul ignore if */
  1590. if (trace.length &&
  1591. // avoid spamming console during tests
  1592. !false) {
  1593. warnArgs.push(`\n`, ...formatTrace(trace));
  1594. }
  1595. console.warn(...warnArgs);
  1596. }
  1597. resetTracking();
  1598. }
  1599. function getComponentTrace() {
  1600. let currentVNode = stack[stack.length - 1];
  1601. if (!currentVNode) {
  1602. return [];
  1603. }
  1604. // we can't just use the stack because it will be incomplete during updates
  1605. // that did not start from the root. Re-construct the parent chain using
  1606. // instance parent pointers.
  1607. const normalizedStack = [];
  1608. while (currentVNode) {
  1609. const last = normalizedStack[0];
  1610. if (last && last.vnode === currentVNode) {
  1611. last.recurseCount++;
  1612. }
  1613. else {
  1614. normalizedStack.push({
  1615. vnode: currentVNode,
  1616. recurseCount: 0
  1617. });
  1618. }
  1619. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1620. currentVNode = parentInstance && parentInstance.vnode;
  1621. }
  1622. return normalizedStack;
  1623. }
  1624. /* istanbul ignore next */
  1625. function formatTrace(trace) {
  1626. const logs = [];
  1627. trace.forEach((entry, i) => {
  1628. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1629. });
  1630. return logs;
  1631. }
  1632. function formatTraceEntry({ vnode, recurseCount }) {
  1633. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1634. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1635. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1636. const close = `>` + postfix;
  1637. return vnode.props
  1638. ? [open, ...formatProps(vnode.props), close]
  1639. : [open + close];
  1640. }
  1641. /* istanbul ignore next */
  1642. function formatProps(props) {
  1643. const res = [];
  1644. const keys = Object.keys(props);
  1645. keys.slice(0, 3).forEach(key => {
  1646. res.push(...formatProp(key, props[key]));
  1647. });
  1648. if (keys.length > 3) {
  1649. res.push(` ...`);
  1650. }
  1651. return res;
  1652. }
  1653. /* istanbul ignore next */
  1654. function formatProp(key, value, raw) {
  1655. if (isString(value)) {
  1656. value = JSON.stringify(value);
  1657. return raw ? value : [`${key}=${value}`];
  1658. }
  1659. else if (typeof value === 'number' ||
  1660. typeof value === 'boolean' ||
  1661. value == null) {
  1662. return raw ? value : [`${key}=${value}`];
  1663. }
  1664. else if (isRef(value)) {
  1665. value = formatProp(key, toRaw(value.value), true);
  1666. return raw ? value : [`${key}=Ref<`, value, `>`];
  1667. }
  1668. else if (isFunction(value)) {
  1669. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1670. }
  1671. else {
  1672. value = toRaw(value);
  1673. return raw ? value : [`${key}=`, value];
  1674. }
  1675. }
  1676. const ErrorTypeStrings = {
  1677. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  1678. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1679. ["c" /* CREATED */]: 'created hook',
  1680. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1681. ["m" /* MOUNTED */]: 'mounted hook',
  1682. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1683. ["u" /* UPDATED */]: 'updated',
  1684. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1685. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1686. ["a" /* ACTIVATED */]: 'activated hook',
  1687. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1688. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1689. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1690. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1691. [0 /* SETUP_FUNCTION */]: 'setup function',
  1692. [1 /* RENDER_FUNCTION */]: 'render function',
  1693. [2 /* WATCH_GETTER */]: 'watcher getter',
  1694. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1695. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1696. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1697. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1698. [7 /* VNODE_HOOK */]: 'vnode hook',
  1699. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1700. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1701. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1702. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1703. [12 /* FUNCTION_REF */]: 'ref function',
  1704. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1705. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1706. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1707. };
  1708. function callWithErrorHandling(fn, instance, type, args) {
  1709. let res;
  1710. try {
  1711. res = args ? fn(...args) : fn();
  1712. }
  1713. catch (err) {
  1714. handleError(err, instance, type);
  1715. }
  1716. return res;
  1717. }
  1718. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1719. if (isFunction(fn)) {
  1720. const res = callWithErrorHandling(fn, instance, type, args);
  1721. if (res && isPromise(res)) {
  1722. res.catch(err => {
  1723. handleError(err, instance, type);
  1724. });
  1725. }
  1726. return res;
  1727. }
  1728. const values = [];
  1729. for (let i = 0; i < fn.length; i++) {
  1730. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1731. }
  1732. return values;
  1733. }
  1734. function handleError(err, instance, type, throwInDev = true) {
  1735. const contextVNode = instance ? instance.vnode : null;
  1736. if (instance) {
  1737. let cur = instance.parent;
  1738. // the exposed instance is the render proxy to keep it consistent with 2.x
  1739. const exposedInstance = instance.proxy;
  1740. // in production the hook receives only the error code
  1741. const errorInfo = ErrorTypeStrings[type] ;
  1742. while (cur) {
  1743. const errorCapturedHooks = cur.ec;
  1744. if (errorCapturedHooks) {
  1745. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1746. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1747. return;
  1748. }
  1749. }
  1750. }
  1751. cur = cur.parent;
  1752. }
  1753. // app-level handling
  1754. const appErrorHandler = instance.appContext.config.errorHandler;
  1755. if (appErrorHandler) {
  1756. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1757. return;
  1758. }
  1759. }
  1760. logError(err, type, contextVNode, throwInDev);
  1761. }
  1762. function logError(err, type, contextVNode, throwInDev = true) {
  1763. {
  1764. const info = ErrorTypeStrings[type];
  1765. if (contextVNode) {
  1766. pushWarningContext(contextVNode);
  1767. }
  1768. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1769. if (contextVNode) {
  1770. popWarningContext();
  1771. }
  1772. // crash in dev by default so it's more noticeable
  1773. if (throwInDev) {
  1774. throw err;
  1775. }
  1776. else {
  1777. console.error(err);
  1778. }
  1779. }
  1780. }
  1781. let isFlushing = false;
  1782. let isFlushPending = false;
  1783. const queue = [];
  1784. let flushIndex = 0;
  1785. const pendingPreFlushCbs = [];
  1786. let activePreFlushCbs = null;
  1787. let preFlushIndex = 0;
  1788. const pendingPostFlushCbs = [];
  1789. let activePostFlushCbs = null;
  1790. let postFlushIndex = 0;
  1791. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1792. let currentFlushPromise = null;
  1793. let currentPreFlushParentJob = null;
  1794. const RECURSION_LIMIT = 100;
  1795. function nextTick(fn) {
  1796. const p = currentFlushPromise || resolvedPromise;
  1797. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1798. }
  1799. // #2768
  1800. // Use binary-search to find a suitable position in the queue,
  1801. // so that the queue maintains the increasing order of job's id,
  1802. // which can prevent the job from being skipped and also can avoid repeated patching.
  1803. function findInsertionIndex(id) {
  1804. // the start index should be `flushIndex + 1`
  1805. let start = flushIndex + 1;
  1806. let end = queue.length;
  1807. while (start < end) {
  1808. const middle = (start + end) >>> 1;
  1809. const middleJobId = getId(queue[middle]);
  1810. middleJobId < id ? (start = middle + 1) : (end = middle);
  1811. }
  1812. return start;
  1813. }
  1814. function queueJob(job) {
  1815. // the dedupe search uses the startIndex argument of Array.includes()
  1816. // by default the search index includes the current job that is being run
  1817. // so it cannot recursively trigger itself again.
  1818. // if the job is a watch() callback, the search will start with a +1 index to
  1819. // allow it recursively trigger itself - it is the user's responsibility to
  1820. // ensure it doesn't end up in an infinite loop.
  1821. if ((!queue.length ||
  1822. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1823. job !== currentPreFlushParentJob) {
  1824. if (job.id == null) {
  1825. queue.push(job);
  1826. }
  1827. else {
  1828. queue.splice(findInsertionIndex(job.id), 0, job);
  1829. }
  1830. queueFlush();
  1831. }
  1832. }
  1833. function queueFlush() {
  1834. if (!isFlushing && !isFlushPending) {
  1835. isFlushPending = true;
  1836. currentFlushPromise = resolvedPromise.then(flushJobs);
  1837. }
  1838. }
  1839. function invalidateJob(job) {
  1840. const i = queue.indexOf(job);
  1841. if (i > flushIndex) {
  1842. queue.splice(i, 1);
  1843. }
  1844. }
  1845. function queueCb(cb, activeQueue, pendingQueue, index) {
  1846. if (!isArray(cb)) {
  1847. if (!activeQueue ||
  1848. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1849. pendingQueue.push(cb);
  1850. }
  1851. }
  1852. else {
  1853. // if cb is an array, it is a component lifecycle hook which can only be
  1854. // triggered by a job, which is already deduped in the main queue, so
  1855. // we can skip duplicate check here to improve perf
  1856. pendingQueue.push(...cb);
  1857. }
  1858. queueFlush();
  1859. }
  1860. function queuePreFlushCb(cb) {
  1861. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1862. }
  1863. function queuePostFlushCb(cb) {
  1864. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1865. }
  1866. function flushPreFlushCbs(seen, parentJob = null) {
  1867. if (pendingPreFlushCbs.length) {
  1868. currentPreFlushParentJob = parentJob;
  1869. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1870. pendingPreFlushCbs.length = 0;
  1871. {
  1872. seen = seen || new Map();
  1873. }
  1874. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1875. if (checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  1876. continue;
  1877. }
  1878. activePreFlushCbs[preFlushIndex]();
  1879. }
  1880. activePreFlushCbs = null;
  1881. preFlushIndex = 0;
  1882. currentPreFlushParentJob = null;
  1883. // recursively flush until it drains
  1884. flushPreFlushCbs(seen, parentJob);
  1885. }
  1886. }
  1887. function flushPostFlushCbs(seen) {
  1888. // flush any pre cbs queued during the flush (e.g. pre watchers)
  1889. flushPreFlushCbs();
  1890. if (pendingPostFlushCbs.length) {
  1891. const deduped = [...new Set(pendingPostFlushCbs)];
  1892. pendingPostFlushCbs.length = 0;
  1893. // #1947 already has active queue, nested flushPostFlushCbs call
  1894. if (activePostFlushCbs) {
  1895. activePostFlushCbs.push(...deduped);
  1896. return;
  1897. }
  1898. activePostFlushCbs = deduped;
  1899. {
  1900. seen = seen || new Map();
  1901. }
  1902. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1903. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1904. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1905. continue;
  1906. }
  1907. activePostFlushCbs[postFlushIndex]();
  1908. }
  1909. activePostFlushCbs = null;
  1910. postFlushIndex = 0;
  1911. }
  1912. }
  1913. const getId = (job) => job.id == null ? Infinity : job.id;
  1914. function flushJobs(seen) {
  1915. isFlushPending = false;
  1916. isFlushing = true;
  1917. {
  1918. seen = seen || new Map();
  1919. }
  1920. flushPreFlushCbs(seen);
  1921. // Sort queue before flush.
  1922. // This ensures that:
  1923. // 1. Components are updated from parent to child. (because parent is always
  1924. // created before the child so its render effect will have smaller
  1925. // priority number)
  1926. // 2. If a component is unmounted during a parent component's update,
  1927. // its update can be skipped.
  1928. queue.sort((a, b) => getId(a) - getId(b));
  1929. // conditional usage of checkRecursiveUpdate must be determined out of
  1930. // try ... catch block since Rollup by default de-optimizes treeshaking
  1931. // inside try-catch. This can leave all warning code unshaked. Although
  1932. // they would get eventually shaken by a minifier like terser, some minifiers
  1933. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1934. const check = (job) => checkRecursiveUpdates(seen, job)
  1935. ;
  1936. try {
  1937. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1938. const job = queue[flushIndex];
  1939. if (job && job.active !== false) {
  1940. if (true && check(job)) {
  1941. continue;
  1942. }
  1943. // console.log(`running:`, job.id)
  1944. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1945. }
  1946. }
  1947. }
  1948. finally {
  1949. flushIndex = 0;
  1950. queue.length = 0;
  1951. flushPostFlushCbs(seen);
  1952. isFlushing = false;
  1953. currentFlushPromise = null;
  1954. // some postFlushCb queued jobs!
  1955. // keep flushing until it drains.
  1956. if (queue.length ||
  1957. pendingPreFlushCbs.length ||
  1958. pendingPostFlushCbs.length) {
  1959. flushJobs(seen);
  1960. }
  1961. }
  1962. }
  1963. function checkRecursiveUpdates(seen, fn) {
  1964. if (!seen.has(fn)) {
  1965. seen.set(fn, 1);
  1966. }
  1967. else {
  1968. const count = seen.get(fn);
  1969. if (count > RECURSION_LIMIT) {
  1970. const instance = fn.ownerInstance;
  1971. const componentName = instance && getComponentName(instance.type);
  1972. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1973. `This means you have a reactive effect that is mutating its own ` +
  1974. `dependencies and thus recursively triggering itself. Possible sources ` +
  1975. `include component template, render function, updated hook or ` +
  1976. `watcher source function.`);
  1977. return true;
  1978. }
  1979. else {
  1980. seen.set(fn, count + 1);
  1981. }
  1982. }
  1983. }
  1984. /* eslint-disable no-restricted-globals */
  1985. let isHmrUpdating = false;
  1986. const hmrDirtyComponents = new Set();
  1987. // Expose the HMR runtime on the global object
  1988. // This makes it entirely tree-shakable without polluting the exports and makes
  1989. // it easier to be used in toolings like vue-loader
  1990. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1991. // to be set so that its instances can be registered / removed.
  1992. {
  1993. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1994. createRecord: tryWrap(createRecord),
  1995. rerender: tryWrap(rerender),
  1996. reload: tryWrap(reload)
  1997. };
  1998. }
  1999. const map = new Map();
  2000. function registerHMR(instance) {
  2001. const id = instance.type.__hmrId;
  2002. let record = map.get(id);
  2003. if (!record) {
  2004. createRecord(id, instance.type);
  2005. record = map.get(id);
  2006. }
  2007. record.instances.add(instance);
  2008. }
  2009. function unregisterHMR(instance) {
  2010. map.get(instance.type.__hmrId).instances.delete(instance);
  2011. }
  2012. function createRecord(id, initialDef) {
  2013. if (map.has(id)) {
  2014. return false;
  2015. }
  2016. map.set(id, {
  2017. initialDef: normalizeClassComponent(initialDef),
  2018. instances: new Set()
  2019. });
  2020. return true;
  2021. }
  2022. function normalizeClassComponent(component) {
  2023. return isClassComponent(component) ? component.__vccOpts : component;
  2024. }
  2025. function rerender(id, newRender) {
  2026. const record = map.get(id);
  2027. if (!record) {
  2028. return;
  2029. }
  2030. // update initial record (for not-yet-rendered component)
  2031. record.initialDef.render = newRender;
  2032. [...record.instances].forEach(instance => {
  2033. if (newRender) {
  2034. instance.render = newRender;
  2035. normalizeClassComponent(instance.type).render = newRender;
  2036. }
  2037. instance.renderCache = [];
  2038. // this flag forces child components with slot content to update
  2039. isHmrUpdating = true;
  2040. instance.update();
  2041. isHmrUpdating = false;
  2042. });
  2043. }
  2044. function reload(id, newComp) {
  2045. const record = map.get(id);
  2046. if (!record)
  2047. return;
  2048. newComp = normalizeClassComponent(newComp);
  2049. // update initial def (for not-yet-rendered components)
  2050. updateComponentDef(record.initialDef, newComp);
  2051. // create a snapshot which avoids the set being mutated during updates
  2052. const instances = [...record.instances];
  2053. for (const instance of instances) {
  2054. const oldComp = normalizeClassComponent(instance.type);
  2055. if (!hmrDirtyComponents.has(oldComp)) {
  2056. // 1. Update existing comp definition to match new one
  2057. if (oldComp !== record.initialDef) {
  2058. updateComponentDef(oldComp, newComp);
  2059. }
  2060. // 2. mark definition dirty. This forces the renderer to replace the
  2061. // component on patch.
  2062. hmrDirtyComponents.add(oldComp);
  2063. }
  2064. // 3. invalidate options resolution cache
  2065. instance.appContext.optionsCache.delete(instance.type);
  2066. // 4. actually update
  2067. if (instance.ceReload) {
  2068. // custom element
  2069. hmrDirtyComponents.add(oldComp);
  2070. instance.ceReload(newComp.styles);
  2071. hmrDirtyComponents.delete(oldComp);
  2072. }
  2073. else if (instance.parent) {
  2074. // 4. Force the parent instance to re-render. This will cause all updated
  2075. // components to be unmounted and re-mounted. Queue the update so that we
  2076. // don't end up forcing the same parent to re-render multiple times.
  2077. queueJob(instance.parent.update);
  2078. // instance is the inner component of an async custom element
  2079. // invoke to reset styles
  2080. if (instance.parent.type.__asyncLoader &&
  2081. instance.parent.ceReload) {
  2082. instance.parent.ceReload(newComp.styles);
  2083. }
  2084. }
  2085. else if (instance.appContext.reload) {
  2086. // root instance mounted via createApp() has a reload method
  2087. instance.appContext.reload();
  2088. }
  2089. else if (typeof window !== 'undefined') {
  2090. // root instance inside tree created via raw render(). Force reload.
  2091. window.location.reload();
  2092. }
  2093. else {
  2094. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  2095. }
  2096. }
  2097. // 5. make sure to cleanup dirty hmr components after update
  2098. queuePostFlushCb(() => {
  2099. for (const instance of instances) {
  2100. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  2101. }
  2102. });
  2103. }
  2104. function updateComponentDef(oldComp, newComp) {
  2105. extend(oldComp, newComp);
  2106. for (const key in oldComp) {
  2107. if (key !== '__file' && !(key in newComp)) {
  2108. delete oldComp[key];
  2109. }
  2110. }
  2111. }
  2112. function tryWrap(fn) {
  2113. return (id, arg) => {
  2114. try {
  2115. return fn(id, arg);
  2116. }
  2117. catch (e) {
  2118. console.error(e);
  2119. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2120. `Full reload required.`);
  2121. }
  2122. };
  2123. }
  2124. let buffer = [];
  2125. let devtoolsNotInstalled = false;
  2126. function emit(event, ...args) {
  2127. if (exports.devtools) {
  2128. exports.devtools.emit(event, ...args);
  2129. }
  2130. else if (!devtoolsNotInstalled) {
  2131. buffer.push({ event, args });
  2132. }
  2133. }
  2134. function setDevtoolsHook(hook, target) {
  2135. var _a, _b;
  2136. exports.devtools = hook;
  2137. if (exports.devtools) {
  2138. exports.devtools.enabled = true;
  2139. buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
  2140. buffer = [];
  2141. }
  2142. else if (
  2143. // handle late devtools injection - only do this if we are in an actual
  2144. // browser environment to avoid the timer handle stalling test runner exit
  2145. // (#4815)
  2146. typeof window !== 'undefined' &&
  2147. // some envs mock window but not fully
  2148. window.HTMLElement &&
  2149. // also exclude jsdom
  2150. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2151. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2152. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2153. replay.push((newHook) => {
  2154. setDevtoolsHook(newHook, target);
  2155. });
  2156. // clear buffer after 3s - the user probably doesn't have devtools installed
  2157. // at all, and keeping the buffer will cause memory leaks (#4738)
  2158. setTimeout(() => {
  2159. if (!exports.devtools) {
  2160. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2161. devtoolsNotInstalled = true;
  2162. buffer = [];
  2163. }
  2164. }, 3000);
  2165. }
  2166. else {
  2167. // non-browser env, assume not installed
  2168. devtoolsNotInstalled = true;
  2169. buffer = [];
  2170. }
  2171. }
  2172. function devtoolsInitApp(app, version) {
  2173. emit("app:init" /* APP_INIT */, app, version, {
  2174. Fragment,
  2175. Text,
  2176. Comment,
  2177. Static
  2178. });
  2179. }
  2180. function devtoolsUnmountApp(app) {
  2181. emit("app:unmount" /* APP_UNMOUNT */, app);
  2182. }
  2183. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  2184. const devtoolsComponentUpdated =
  2185. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  2186. const devtoolsComponentRemoved =
  2187. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  2188. function createDevtoolsComponentHook(hook) {
  2189. return (component) => {
  2190. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2191. };
  2192. }
  2193. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  2194. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  2195. function createDevtoolsPerformanceHook(hook) {
  2196. return (component, type, time) => {
  2197. emit(hook, component.appContext.app, component.uid, component, type, time);
  2198. };
  2199. }
  2200. function devtoolsComponentEmit(component, event, params) {
  2201. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2202. }
  2203. function emit$1(instance, event, ...rawArgs) {
  2204. if (instance.isUnmounted)
  2205. return;
  2206. const props = instance.vnode.props || EMPTY_OBJ;
  2207. {
  2208. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2209. if (emitsOptions) {
  2210. if (!(event in emitsOptions) &&
  2211. !(false )) {
  2212. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2213. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  2214. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2215. }
  2216. }
  2217. else {
  2218. const validator = emitsOptions[event];
  2219. if (isFunction(validator)) {
  2220. const isValid = validator(...rawArgs);
  2221. if (!isValid) {
  2222. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. let args = rawArgs;
  2229. const isModelListener = event.startsWith('update:');
  2230. // for v-model update:xxx events, apply modifiers on args
  2231. const modelArg = isModelListener && event.slice(7);
  2232. if (modelArg && modelArg in props) {
  2233. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2234. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2235. if (trim) {
  2236. args = rawArgs.map(a => a.trim());
  2237. }
  2238. if (number) {
  2239. args = rawArgs.map(toNumber);
  2240. }
  2241. }
  2242. {
  2243. devtoolsComponentEmit(instance, event, args);
  2244. }
  2245. {
  2246. const lowerCaseEvent = event.toLowerCase();
  2247. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2248. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  2249. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2250. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2251. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2252. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2253. }
  2254. }
  2255. let handlerName;
  2256. let handler = props[(handlerName = toHandlerKey(event))] ||
  2257. // also try camelCase event handler (#2249)
  2258. props[(handlerName = toHandlerKey(camelize(event)))];
  2259. // for v-model update:xxx events, also trigger kebab-case equivalent
  2260. // for props passed via kebab-case
  2261. if (!handler && isModelListener) {
  2262. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2263. }
  2264. if (handler) {
  2265. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2266. }
  2267. const onceHandler = props[handlerName + `Once`];
  2268. if (onceHandler) {
  2269. if (!instance.emitted) {
  2270. instance.emitted = {};
  2271. }
  2272. else if (instance.emitted[handlerName]) {
  2273. return;
  2274. }
  2275. instance.emitted[handlerName] = true;
  2276. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2277. }
  2278. }
  2279. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2280. const cache = appContext.emitsCache;
  2281. const cached = cache.get(comp);
  2282. if (cached !== undefined) {
  2283. return cached;
  2284. }
  2285. const raw = comp.emits;
  2286. let normalized = {};
  2287. // apply mixin/extends props
  2288. let hasExtends = false;
  2289. if (!isFunction(comp)) {
  2290. const extendEmits = (raw) => {
  2291. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2292. if (normalizedFromExtend) {
  2293. hasExtends = true;
  2294. extend(normalized, normalizedFromExtend);
  2295. }
  2296. };
  2297. if (!asMixin && appContext.mixins.length) {
  2298. appContext.mixins.forEach(extendEmits);
  2299. }
  2300. if (comp.extends) {
  2301. extendEmits(comp.extends);
  2302. }
  2303. if (comp.mixins) {
  2304. comp.mixins.forEach(extendEmits);
  2305. }
  2306. }
  2307. if (!raw && !hasExtends) {
  2308. cache.set(comp, null);
  2309. return null;
  2310. }
  2311. if (isArray(raw)) {
  2312. raw.forEach(key => (normalized[key] = null));
  2313. }
  2314. else {
  2315. extend(normalized, raw);
  2316. }
  2317. cache.set(comp, normalized);
  2318. return normalized;
  2319. }
  2320. // Check if an incoming prop key is a declared emit event listener.
  2321. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2322. // both considered matched listeners.
  2323. function isEmitListener(options, key) {
  2324. if (!options || !isOn(key)) {
  2325. return false;
  2326. }
  2327. key = key.slice(2).replace(/Once$/, '');
  2328. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2329. hasOwn(options, hyphenate(key)) ||
  2330. hasOwn(options, key));
  2331. }
  2332. /**
  2333. * mark the current rendering instance for asset resolution (e.g.
  2334. * resolveComponent, resolveDirective) during render
  2335. */
  2336. let currentRenderingInstance = null;
  2337. let currentScopeId = null;
  2338. /**
  2339. * Note: rendering calls maybe nested. The function returns the parent rendering
  2340. * instance if present, which should be restored after the render is done:
  2341. *
  2342. * ```js
  2343. * const prev = setCurrentRenderingInstance(i)
  2344. * // ...render
  2345. * setCurrentRenderingInstance(prev)
  2346. * ```
  2347. */
  2348. function setCurrentRenderingInstance(instance) {
  2349. const prev = currentRenderingInstance;
  2350. currentRenderingInstance = instance;
  2351. currentScopeId = (instance && instance.type.__scopeId) || null;
  2352. return prev;
  2353. }
  2354. /**
  2355. * Set scope id when creating hoisted vnodes.
  2356. * @private compiler helper
  2357. */
  2358. function pushScopeId(id) {
  2359. currentScopeId = id;
  2360. }
  2361. /**
  2362. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2363. * API for backwards compat w/ code generated by compilers.
  2364. * @private
  2365. */
  2366. function popScopeId() {
  2367. currentScopeId = null;
  2368. }
  2369. /**
  2370. * Only for backwards compat
  2371. * @private
  2372. */
  2373. const withScopeId = (_id) => withCtx;
  2374. /**
  2375. * Wrap a slot function to memoize current rendering instance
  2376. * @private compiler helper
  2377. */
  2378. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2379. ) {
  2380. if (!ctx)
  2381. return fn;
  2382. // already normalized
  2383. if (fn._n) {
  2384. return fn;
  2385. }
  2386. const renderFnWithContext = (...args) => {
  2387. // If a user calls a compiled slot inside a template expression (#1745), it
  2388. // can mess up block tracking, so by default we disable block tracking and
  2389. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2390. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2391. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2392. if (renderFnWithContext._d) {
  2393. setBlockTracking(-1);
  2394. }
  2395. const prevInstance = setCurrentRenderingInstance(ctx);
  2396. const res = fn(...args);
  2397. setCurrentRenderingInstance(prevInstance);
  2398. if (renderFnWithContext._d) {
  2399. setBlockTracking(1);
  2400. }
  2401. {
  2402. devtoolsComponentUpdated(ctx);
  2403. }
  2404. return res;
  2405. };
  2406. // mark normalized to avoid duplicated wrapping
  2407. renderFnWithContext._n = true;
  2408. // mark this as compiled by default
  2409. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2410. // rendering flag.
  2411. renderFnWithContext._c = true;
  2412. // disable block tracking by default
  2413. renderFnWithContext._d = true;
  2414. return renderFnWithContext;
  2415. }
  2416. /**
  2417. * dev only flag to track whether $attrs was used during render.
  2418. * If $attrs was used during render then the warning for failed attrs
  2419. * fallthrough can be suppressed.
  2420. */
  2421. let accessedAttrs = false;
  2422. function markAttrsAccessed() {
  2423. accessedAttrs = true;
  2424. }
  2425. function renderComponentRoot(instance) {
  2426. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2427. let result;
  2428. let fallthroughAttrs;
  2429. const prev = setCurrentRenderingInstance(instance);
  2430. {
  2431. accessedAttrs = false;
  2432. }
  2433. try {
  2434. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  2435. // withProxy is a proxy with a different `has` trap only for
  2436. // runtime-compiled render functions using `with` block.
  2437. const proxyToUse = withProxy || proxy;
  2438. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2439. fallthroughAttrs = attrs;
  2440. }
  2441. else {
  2442. // functional
  2443. const render = Component;
  2444. // in dev, mark attrs accessed if optional props (attrs === props)
  2445. if (true && attrs === props) {
  2446. markAttrsAccessed();
  2447. }
  2448. result = normalizeVNode(render.length > 1
  2449. ? render(props, true
  2450. ? {
  2451. get attrs() {
  2452. markAttrsAccessed();
  2453. return attrs;
  2454. },
  2455. slots,
  2456. emit
  2457. }
  2458. : { attrs, slots, emit })
  2459. : render(props, null /* we know it doesn't need it */));
  2460. fallthroughAttrs = Component.props
  2461. ? attrs
  2462. : getFunctionalFallthrough(attrs);
  2463. }
  2464. }
  2465. catch (err) {
  2466. blockStack.length = 0;
  2467. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  2468. result = createVNode(Comment);
  2469. }
  2470. // attr merging
  2471. // in dev mode, comments are preserved, and it's possible for a template
  2472. // to have comments along side the root element which makes it a fragment
  2473. let root = result;
  2474. let setRoot = undefined;
  2475. if (result.patchFlag > 0 &&
  2476. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  2477. [root, setRoot] = getChildRoot(result);
  2478. }
  2479. if (fallthroughAttrs && inheritAttrs !== false) {
  2480. const keys = Object.keys(fallthroughAttrs);
  2481. const { shapeFlag } = root;
  2482. if (keys.length) {
  2483. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  2484. if (propsOptions && keys.some(isModelListener)) {
  2485. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2486. // prop, it indicates this component expects to handle v-model and
  2487. // it should not fallthrough.
  2488. // related: #1543, #1643, #1989
  2489. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2490. }
  2491. root = cloneVNode(root, fallthroughAttrs);
  2492. }
  2493. else if (!accessedAttrs && root.type !== Comment) {
  2494. const allAttrs = Object.keys(attrs);
  2495. const eventAttrs = [];
  2496. const extraAttrs = [];
  2497. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2498. const key = allAttrs[i];
  2499. if (isOn(key)) {
  2500. // ignore v-model handlers when they fail to fallthrough
  2501. if (!isModelListener(key)) {
  2502. // remove `on`, lowercase first letter to reflect event casing
  2503. // accurately
  2504. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2505. }
  2506. }
  2507. else {
  2508. extraAttrs.push(key);
  2509. }
  2510. }
  2511. if (extraAttrs.length) {
  2512. warn$1(`Extraneous non-props attributes (` +
  2513. `${extraAttrs.join(', ')}) ` +
  2514. `were passed to component but could not be automatically inherited ` +
  2515. `because component renders fragment or text root nodes.`);
  2516. }
  2517. if (eventAttrs.length) {
  2518. warn$1(`Extraneous non-emits event listeners (` +
  2519. `${eventAttrs.join(', ')}) ` +
  2520. `were passed to component but could not be automatically inherited ` +
  2521. `because component renders fragment or text root nodes. ` +
  2522. `If the listener is intended to be a component custom event listener only, ` +
  2523. `declare it using the "emits" option.`);
  2524. }
  2525. }
  2526. }
  2527. }
  2528. // inherit directives
  2529. if (vnode.dirs) {
  2530. if (!isElementRoot(root)) {
  2531. warn$1(`Runtime directive used on component with non-element root node. ` +
  2532. `The directives will not function as intended.`);
  2533. }
  2534. // clone before mutating since the root may be a hoisted vnode
  2535. root = cloneVNode(root);
  2536. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2537. }
  2538. // inherit transition data
  2539. if (vnode.transition) {
  2540. if (!isElementRoot(root)) {
  2541. warn$1(`Component inside <Transition> renders non-element root node ` +
  2542. `that cannot be animated.`);
  2543. }
  2544. root.transition = vnode.transition;
  2545. }
  2546. if (setRoot) {
  2547. setRoot(root);
  2548. }
  2549. else {
  2550. result = root;
  2551. }
  2552. setCurrentRenderingInstance(prev);
  2553. return result;
  2554. }
  2555. /**
  2556. * dev only
  2557. * In dev mode, template root level comments are rendered, which turns the
  2558. * template into a fragment root, but we need to locate the single element
  2559. * root for attrs and scope id processing.
  2560. */
  2561. const getChildRoot = (vnode) => {
  2562. const rawChildren = vnode.children;
  2563. const dynamicChildren = vnode.dynamicChildren;
  2564. const childRoot = filterSingleRoot(rawChildren);
  2565. if (!childRoot) {
  2566. return [vnode, undefined];
  2567. }
  2568. const index = rawChildren.indexOf(childRoot);
  2569. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2570. const setRoot = (updatedRoot) => {
  2571. rawChildren[index] = updatedRoot;
  2572. if (dynamicChildren) {
  2573. if (dynamicIndex > -1) {
  2574. dynamicChildren[dynamicIndex] = updatedRoot;
  2575. }
  2576. else if (updatedRoot.patchFlag > 0) {
  2577. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2578. }
  2579. }
  2580. };
  2581. return [normalizeVNode(childRoot), setRoot];
  2582. };
  2583. function filterSingleRoot(children) {
  2584. let singleRoot;
  2585. for (let i = 0; i < children.length; i++) {
  2586. const child = children[i];
  2587. if (isVNode(child)) {
  2588. // ignore user comment
  2589. if (child.type !== Comment || child.children === 'v-if') {
  2590. if (singleRoot) {
  2591. // has more than 1 non-comment child, return now
  2592. return;
  2593. }
  2594. else {
  2595. singleRoot = child;
  2596. }
  2597. }
  2598. }
  2599. else {
  2600. return;
  2601. }
  2602. }
  2603. return singleRoot;
  2604. }
  2605. const getFunctionalFallthrough = (attrs) => {
  2606. let res;
  2607. for (const key in attrs) {
  2608. if (key === 'class' || key === 'style' || isOn(key)) {
  2609. (res || (res = {}))[key] = attrs[key];
  2610. }
  2611. }
  2612. return res;
  2613. };
  2614. const filterModelListeners = (attrs, props) => {
  2615. const res = {};
  2616. for (const key in attrs) {
  2617. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2618. res[key] = attrs[key];
  2619. }
  2620. }
  2621. return res;
  2622. };
  2623. const isElementRoot = (vnode) => {
  2624. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  2625. vnode.type === Comment // potential v-if branch switch
  2626. );
  2627. };
  2628. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2629. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2630. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2631. const emits = component.emitsOptions;
  2632. // Parent component's render function was hot-updated. Since this may have
  2633. // caused the child component's slots content to have changed, we need to
  2634. // force the child to update as well.
  2635. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2636. return true;
  2637. }
  2638. // force child update for runtime directive or transition on component vnode.
  2639. if (nextVNode.dirs || nextVNode.transition) {
  2640. return true;
  2641. }
  2642. if (optimized && patchFlag >= 0) {
  2643. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2644. // slot content that references values that might have changed,
  2645. // e.g. in a v-for
  2646. return true;
  2647. }
  2648. if (patchFlag & 16 /* FULL_PROPS */) {
  2649. if (!prevProps) {
  2650. return !!nextProps;
  2651. }
  2652. // presence of this flag indicates props are always non-null
  2653. return hasPropsChanged(prevProps, nextProps, emits);
  2654. }
  2655. else if (patchFlag & 8 /* PROPS */) {
  2656. const dynamicProps = nextVNode.dynamicProps;
  2657. for (let i = 0; i < dynamicProps.length; i++) {
  2658. const key = dynamicProps[i];
  2659. if (nextProps[key] !== prevProps[key] &&
  2660. !isEmitListener(emits, key)) {
  2661. return true;
  2662. }
  2663. }
  2664. }
  2665. }
  2666. else {
  2667. // this path is only taken by manually written render functions
  2668. // so presence of any children leads to a forced update
  2669. if (prevChildren || nextChildren) {
  2670. if (!nextChildren || !nextChildren.$stable) {
  2671. return true;
  2672. }
  2673. }
  2674. if (prevProps === nextProps) {
  2675. return false;
  2676. }
  2677. if (!prevProps) {
  2678. return !!nextProps;
  2679. }
  2680. if (!nextProps) {
  2681. return true;
  2682. }
  2683. return hasPropsChanged(prevProps, nextProps, emits);
  2684. }
  2685. return false;
  2686. }
  2687. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2688. const nextKeys = Object.keys(nextProps);
  2689. if (nextKeys.length !== Object.keys(prevProps).length) {
  2690. return true;
  2691. }
  2692. for (let i = 0; i < nextKeys.length; i++) {
  2693. const key = nextKeys[i];
  2694. if (nextProps[key] !== prevProps[key] &&
  2695. !isEmitListener(emitsOptions, key)) {
  2696. return true;
  2697. }
  2698. }
  2699. return false;
  2700. }
  2701. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2702. ) {
  2703. while (parent && parent.subTree === vnode) {
  2704. (vnode = parent.vnode).el = el;
  2705. parent = parent.parent;
  2706. }
  2707. }
  2708. const isSuspense = (type) => type.__isSuspense;
  2709. // Suspense exposes a component-like API, and is treated like a component
  2710. // in the compiler, but internally it's a special built-in type that hooks
  2711. // directly into the renderer.
  2712. const SuspenseImpl = {
  2713. name: 'Suspense',
  2714. // In order to make Suspense tree-shakable, we need to avoid importing it
  2715. // directly in the renderer. The renderer checks for the __isSuspense flag
  2716. // on a vnode's type and calls the `process` method, passing in renderer
  2717. // internals.
  2718. __isSuspense: true,
  2719. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2720. // platform-specific impl passed from renderer
  2721. rendererInternals) {
  2722. if (n1 == null) {
  2723. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2724. }
  2725. else {
  2726. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2727. }
  2728. },
  2729. hydrate: hydrateSuspense,
  2730. create: createSuspenseBoundary,
  2731. normalize: normalizeSuspenseChildren
  2732. };
  2733. // Force-casted public typing for h and TSX props inference
  2734. const Suspense = (SuspenseImpl );
  2735. function triggerEvent(vnode, name) {
  2736. const eventListener = vnode.props && vnode.props[name];
  2737. if (isFunction(eventListener)) {
  2738. eventListener();
  2739. }
  2740. }
  2741. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2742. const { p: patch, o: { createElement } } = rendererInternals;
  2743. const hiddenContainer = createElement('div');
  2744. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2745. // start mounting the content subtree in an off-dom container
  2746. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2747. // now check if we have encountered any async deps
  2748. if (suspense.deps > 0) {
  2749. // has async
  2750. // invoke @fallback event
  2751. triggerEvent(vnode, 'onPending');
  2752. triggerEvent(vnode, 'onFallback');
  2753. // mount the fallback tree
  2754. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2755. isSVG, slotScopeIds);
  2756. setActiveBranch(suspense, vnode.ssFallback);
  2757. }
  2758. else {
  2759. // Suspense has no async deps. Just resolve.
  2760. suspense.resolve();
  2761. }
  2762. }
  2763. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2764. const suspense = (n2.suspense = n1.suspense);
  2765. suspense.vnode = n2;
  2766. n2.el = n1.el;
  2767. const newBranch = n2.ssContent;
  2768. const newFallback = n2.ssFallback;
  2769. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2770. if (pendingBranch) {
  2771. suspense.pendingBranch = newBranch;
  2772. if (isSameVNodeType(newBranch, pendingBranch)) {
  2773. // same root type but content may have changed.
  2774. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2775. if (suspense.deps <= 0) {
  2776. suspense.resolve();
  2777. }
  2778. else if (isInFallback) {
  2779. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2780. isSVG, slotScopeIds, optimized);
  2781. setActiveBranch(suspense, newFallback);
  2782. }
  2783. }
  2784. else {
  2785. // toggled before pending tree is resolved
  2786. suspense.pendingId++;
  2787. if (isHydrating) {
  2788. // if toggled before hydration is finished, the current DOM tree is
  2789. // no longer valid. set it as the active branch so it will be unmounted
  2790. // when resolved
  2791. suspense.isHydrating = false;
  2792. suspense.activeBranch = pendingBranch;
  2793. }
  2794. else {
  2795. unmount(pendingBranch, parentComponent, suspense);
  2796. }
  2797. // increment pending ID. this is used to invalidate async callbacks
  2798. // reset suspense state
  2799. suspense.deps = 0;
  2800. // discard effects from pending branch
  2801. suspense.effects.length = 0;
  2802. // discard previous container
  2803. suspense.hiddenContainer = createElement('div');
  2804. if (isInFallback) {
  2805. // already in fallback state
  2806. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2807. if (suspense.deps <= 0) {
  2808. suspense.resolve();
  2809. }
  2810. else {
  2811. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2812. isSVG, slotScopeIds, optimized);
  2813. setActiveBranch(suspense, newFallback);
  2814. }
  2815. }
  2816. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2817. // toggled "back" to current active branch
  2818. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2819. // force resolve
  2820. suspense.resolve(true);
  2821. }
  2822. else {
  2823. // switched to a 3rd branch
  2824. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2825. if (suspense.deps <= 0) {
  2826. suspense.resolve();
  2827. }
  2828. }
  2829. }
  2830. }
  2831. else {
  2832. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2833. // root did not change, just normal patch
  2834. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2835. setActiveBranch(suspense, newBranch);
  2836. }
  2837. else {
  2838. // root node toggled
  2839. // invoke @pending event
  2840. triggerEvent(n2, 'onPending');
  2841. // mount pending branch in off-dom container
  2842. suspense.pendingBranch = newBranch;
  2843. suspense.pendingId++;
  2844. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2845. if (suspense.deps <= 0) {
  2846. // incoming branch has no async deps, resolve now.
  2847. suspense.resolve();
  2848. }
  2849. else {
  2850. const { timeout, pendingId } = suspense;
  2851. if (timeout > 0) {
  2852. setTimeout(() => {
  2853. if (suspense.pendingId === pendingId) {
  2854. suspense.fallback(newFallback);
  2855. }
  2856. }, timeout);
  2857. }
  2858. else if (timeout === 0) {
  2859. suspense.fallback(newFallback);
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. let hasWarned = false;
  2866. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2867. /* istanbul ignore if */
  2868. if (!hasWarned) {
  2869. hasWarned = true;
  2870. // @ts-ignore `console.info` cannot be null error
  2871. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2872. }
  2873. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2874. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2875. const suspense = {
  2876. vnode,
  2877. parent,
  2878. parentComponent,
  2879. isSVG,
  2880. container,
  2881. hiddenContainer,
  2882. anchor,
  2883. deps: 0,
  2884. pendingId: 0,
  2885. timeout: typeof timeout === 'number' ? timeout : -1,
  2886. activeBranch: null,
  2887. pendingBranch: null,
  2888. isInFallback: true,
  2889. isHydrating,
  2890. isUnmounted: false,
  2891. effects: [],
  2892. resolve(resume = false) {
  2893. {
  2894. if (!resume && !suspense.pendingBranch) {
  2895. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2896. }
  2897. if (suspense.isUnmounted) {
  2898. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2899. }
  2900. }
  2901. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2902. if (suspense.isHydrating) {
  2903. suspense.isHydrating = false;
  2904. }
  2905. else if (!resume) {
  2906. const delayEnter = activeBranch &&
  2907. pendingBranch.transition &&
  2908. pendingBranch.transition.mode === 'out-in';
  2909. if (delayEnter) {
  2910. activeBranch.transition.afterLeave = () => {
  2911. if (pendingId === suspense.pendingId) {
  2912. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2913. }
  2914. };
  2915. }
  2916. // this is initial anchor on mount
  2917. let { anchor } = suspense;
  2918. // unmount current active tree
  2919. if (activeBranch) {
  2920. // if the fallback tree was mounted, it may have been moved
  2921. // as part of a parent suspense. get the latest anchor for insertion
  2922. anchor = next(activeBranch);
  2923. unmount(activeBranch, parentComponent, suspense, true);
  2924. }
  2925. if (!delayEnter) {
  2926. // move content from off-dom container to actual container
  2927. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2928. }
  2929. }
  2930. setActiveBranch(suspense, pendingBranch);
  2931. suspense.pendingBranch = null;
  2932. suspense.isInFallback = false;
  2933. // flush buffered effects
  2934. // check if there is a pending parent suspense
  2935. let parent = suspense.parent;
  2936. let hasUnresolvedAncestor = false;
  2937. while (parent) {
  2938. if (parent.pendingBranch) {
  2939. // found a pending parent suspense, merge buffered post jobs
  2940. // into that parent
  2941. parent.effects.push(...effects);
  2942. hasUnresolvedAncestor = true;
  2943. break;
  2944. }
  2945. parent = parent.parent;
  2946. }
  2947. // no pending parent suspense, flush all jobs
  2948. if (!hasUnresolvedAncestor) {
  2949. queuePostFlushCb(effects);
  2950. }
  2951. suspense.effects = [];
  2952. // invoke @resolve event
  2953. triggerEvent(vnode, 'onResolve');
  2954. },
  2955. fallback(fallbackVNode) {
  2956. if (!suspense.pendingBranch) {
  2957. return;
  2958. }
  2959. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2960. // invoke @fallback event
  2961. triggerEvent(vnode, 'onFallback');
  2962. const anchor = next(activeBranch);
  2963. const mountFallback = () => {
  2964. if (!suspense.isInFallback) {
  2965. return;
  2966. }
  2967. // mount the fallback tree
  2968. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2969. isSVG, slotScopeIds, optimized);
  2970. setActiveBranch(suspense, fallbackVNode);
  2971. };
  2972. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2973. if (delayEnter) {
  2974. activeBranch.transition.afterLeave = mountFallback;
  2975. }
  2976. suspense.isInFallback = true;
  2977. // unmount current active branch
  2978. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2979. true // shouldRemove
  2980. );
  2981. if (!delayEnter) {
  2982. mountFallback();
  2983. }
  2984. },
  2985. move(container, anchor, type) {
  2986. suspense.activeBranch &&
  2987. move(suspense.activeBranch, container, anchor, type);
  2988. suspense.container = container;
  2989. },
  2990. next() {
  2991. return suspense.activeBranch && next(suspense.activeBranch);
  2992. },
  2993. registerDep(instance, setupRenderEffect) {
  2994. const isInPendingSuspense = !!suspense.pendingBranch;
  2995. if (isInPendingSuspense) {
  2996. suspense.deps++;
  2997. }
  2998. const hydratedEl = instance.vnode.el;
  2999. instance
  3000. .asyncDep.catch(err => {
  3001. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  3002. })
  3003. .then(asyncSetupResult => {
  3004. // retry when the setup() promise resolves.
  3005. // component may have been unmounted before resolve.
  3006. if (instance.isUnmounted ||
  3007. suspense.isUnmounted ||
  3008. suspense.pendingId !== instance.suspenseId) {
  3009. return;
  3010. }
  3011. // retry from this component
  3012. instance.asyncResolved = true;
  3013. const { vnode } = instance;
  3014. {
  3015. pushWarningContext(vnode);
  3016. }
  3017. handleSetupResult(instance, asyncSetupResult, false);
  3018. if (hydratedEl) {
  3019. // vnode may have been replaced if an update happened before the
  3020. // async dep is resolved.
  3021. vnode.el = hydratedEl;
  3022. }
  3023. const placeholder = !hydratedEl && instance.subTree.el;
  3024. setupRenderEffect(instance, vnode,
  3025. // component may have been moved before resolve.
  3026. // if this is not a hydration, instance.subTree will be the comment
  3027. // placeholder.
  3028. parentNode(hydratedEl || instance.subTree.el),
  3029. // anchor will not be used if this is hydration, so only need to
  3030. // consider the comment placeholder case.
  3031. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  3032. if (placeholder) {
  3033. remove(placeholder);
  3034. }
  3035. updateHOCHostEl(instance, vnode.el);
  3036. {
  3037. popWarningContext();
  3038. }
  3039. // only decrease deps count if suspense is not already resolved
  3040. if (isInPendingSuspense && --suspense.deps === 0) {
  3041. suspense.resolve();
  3042. }
  3043. });
  3044. },
  3045. unmount(parentSuspense, doRemove) {
  3046. suspense.isUnmounted = true;
  3047. if (suspense.activeBranch) {
  3048. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  3049. }
  3050. if (suspense.pendingBranch) {
  3051. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  3052. }
  3053. }
  3054. };
  3055. return suspense;
  3056. }
  3057. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  3058. /* eslint-disable no-restricted-globals */
  3059. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  3060. // there are two possible scenarios for server-rendered suspense:
  3061. // - success: ssr content should be fully resolved
  3062. // - failure: ssr content should be the fallback branch.
  3063. // however, on the client we don't really know if it has failed or not
  3064. // attempt to hydrate the DOM assuming it has succeeded, but we still
  3065. // need to construct a suspense boundary first
  3066. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  3067. if (suspense.deps === 0) {
  3068. suspense.resolve();
  3069. }
  3070. return result;
  3071. /* eslint-enable no-restricted-globals */
  3072. }
  3073. function normalizeSuspenseChildren(vnode) {
  3074. const { shapeFlag, children } = vnode;
  3075. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  3076. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  3077. vnode.ssFallback = isSlotChildren
  3078. ? normalizeSuspenseSlot(children.fallback)
  3079. : createVNode(Comment);
  3080. }
  3081. function normalizeSuspenseSlot(s) {
  3082. let block;
  3083. if (isFunction(s)) {
  3084. const trackBlock = isBlockTreeEnabled && s._c;
  3085. if (trackBlock) {
  3086. // disableTracking: false
  3087. // allow block tracking for compiled slots
  3088. // (see ./componentRenderContext.ts)
  3089. s._d = false;
  3090. openBlock();
  3091. }
  3092. s = s();
  3093. if (trackBlock) {
  3094. s._d = true;
  3095. block = currentBlock;
  3096. closeBlock();
  3097. }
  3098. }
  3099. if (isArray(s)) {
  3100. const singleChild = filterSingleRoot(s);
  3101. if (!singleChild) {
  3102. warn$1(`<Suspense> slots expect a single root node.`);
  3103. }
  3104. s = singleChild;
  3105. }
  3106. s = normalizeVNode(s);
  3107. if (block && !s.dynamicChildren) {
  3108. s.dynamicChildren = block.filter(c => c !== s);
  3109. }
  3110. return s;
  3111. }
  3112. function queueEffectWithSuspense(fn, suspense) {
  3113. if (suspense && suspense.pendingBranch) {
  3114. if (isArray(fn)) {
  3115. suspense.effects.push(...fn);
  3116. }
  3117. else {
  3118. suspense.effects.push(fn);
  3119. }
  3120. }
  3121. else {
  3122. queuePostFlushCb(fn);
  3123. }
  3124. }
  3125. function setActiveBranch(suspense, branch) {
  3126. suspense.activeBranch = branch;
  3127. const { vnode, parentComponent } = suspense;
  3128. const el = (vnode.el = branch.el);
  3129. // in case suspense is the root node of a component,
  3130. // recursively update the HOC el
  3131. if (parentComponent && parentComponent.subTree === vnode) {
  3132. parentComponent.vnode.el = el;
  3133. updateHOCHostEl(parentComponent, el);
  3134. }
  3135. }
  3136. function provide(key, value) {
  3137. if (!currentInstance) {
  3138. {
  3139. warn$1(`provide() can only be used inside setup().`);
  3140. }
  3141. }
  3142. else {
  3143. let provides = currentInstance.provides;
  3144. // by default an instance inherits its parent's provides object
  3145. // but when it needs to provide values of its own, it creates its
  3146. // own provides object using parent provides object as prototype.
  3147. // this way in `inject` we can simply look up injections from direct
  3148. // parent and let the prototype chain do the work.
  3149. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3150. if (parentProvides === provides) {
  3151. provides = currentInstance.provides = Object.create(parentProvides);
  3152. }
  3153. // TS doesn't allow symbol as index type
  3154. provides[key] = value;
  3155. }
  3156. }
  3157. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3158. // fallback to `currentRenderingInstance` so that this can be called in
  3159. // a functional component
  3160. const instance = currentInstance || currentRenderingInstance;
  3161. if (instance) {
  3162. // #2400
  3163. // to support `app.use` plugins,
  3164. // fallback to appContext's `provides` if the instance is at root
  3165. const provides = instance.parent == null
  3166. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3167. : instance.parent.provides;
  3168. if (provides && key in provides) {
  3169. // TS doesn't allow symbol as index type
  3170. return provides[key];
  3171. }
  3172. else if (arguments.length > 1) {
  3173. return treatDefaultAsFactory && isFunction(defaultValue)
  3174. ? defaultValue.call(instance.proxy)
  3175. : defaultValue;
  3176. }
  3177. else {
  3178. warn$1(`injection "${String(key)}" not found.`);
  3179. }
  3180. }
  3181. else {
  3182. warn$1(`inject() can only be used inside setup() or functional components.`);
  3183. }
  3184. }
  3185. // Simple effect.
  3186. function watchEffect(effect, options) {
  3187. return doWatch(effect, null, options);
  3188. }
  3189. function watchPostEffect(effect, options) {
  3190. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'post' }) ));
  3191. }
  3192. function watchSyncEffect(effect, options) {
  3193. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'sync' }) ));
  3194. }
  3195. // initial value for watchers to trigger on undefined initial values
  3196. const INITIAL_WATCHER_VALUE = {};
  3197. // implementation
  3198. function watch(source, cb, options) {
  3199. if (!isFunction(cb)) {
  3200. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3201. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3202. `supports \`watch(source, cb, options?) signature.`);
  3203. }
  3204. return doWatch(source, cb, options);
  3205. }
  3206. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3207. if (!cb) {
  3208. if (immediate !== undefined) {
  3209. warn$1(`watch() "immediate" option is only respected when using the ` +
  3210. `watch(source, callback, options?) signature.`);
  3211. }
  3212. if (deep !== undefined) {
  3213. warn$1(`watch() "deep" option is only respected when using the ` +
  3214. `watch(source, callback, options?) signature.`);
  3215. }
  3216. }
  3217. const warnInvalidSource = (s) => {
  3218. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3219. `a reactive object, or an array of these types.`);
  3220. };
  3221. const instance = currentInstance;
  3222. let getter;
  3223. let forceTrigger = false;
  3224. let isMultiSource = false;
  3225. if (isRef(source)) {
  3226. getter = () => source.value;
  3227. forceTrigger = isShallow(source);
  3228. }
  3229. else if (isReactive(source)) {
  3230. getter = () => source;
  3231. deep = true;
  3232. }
  3233. else if (isArray(source)) {
  3234. isMultiSource = true;
  3235. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  3236. getter = () => source.map(s => {
  3237. if (isRef(s)) {
  3238. return s.value;
  3239. }
  3240. else if (isReactive(s)) {
  3241. return traverse(s);
  3242. }
  3243. else if (isFunction(s)) {
  3244. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  3245. }
  3246. else {
  3247. warnInvalidSource(s);
  3248. }
  3249. });
  3250. }
  3251. else if (isFunction(source)) {
  3252. if (cb) {
  3253. // getter with cb
  3254. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  3255. }
  3256. else {
  3257. // no cb -> simple effect
  3258. getter = () => {
  3259. if (instance && instance.isUnmounted) {
  3260. return;
  3261. }
  3262. if (cleanup) {
  3263. cleanup();
  3264. }
  3265. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onCleanup]);
  3266. };
  3267. }
  3268. }
  3269. else {
  3270. getter = NOOP;
  3271. warnInvalidSource(source);
  3272. }
  3273. if (cb && deep) {
  3274. const baseGetter = getter;
  3275. getter = () => traverse(baseGetter());
  3276. }
  3277. let cleanup;
  3278. let onCleanup = (fn) => {
  3279. cleanup = effect.onStop = () => {
  3280. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  3281. };
  3282. };
  3283. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  3284. const job = () => {
  3285. if (!effect.active) {
  3286. return;
  3287. }
  3288. if (cb) {
  3289. // watch(source, cb)
  3290. const newValue = effect.run();
  3291. if (deep ||
  3292. forceTrigger ||
  3293. (isMultiSource
  3294. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3295. : hasChanged(newValue, oldValue)) ||
  3296. (false )) {
  3297. // cleanup before running cb again
  3298. if (cleanup) {
  3299. cleanup();
  3300. }
  3301. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  3302. newValue,
  3303. // pass undefined as the old value when it's changed for the first time
  3304. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  3305. onCleanup
  3306. ]);
  3307. oldValue = newValue;
  3308. }
  3309. }
  3310. else {
  3311. // watchEffect
  3312. effect.run();
  3313. }
  3314. };
  3315. // important: mark the job as a watcher callback so that scheduler knows
  3316. // it is allowed to self-trigger (#1727)
  3317. job.allowRecurse = !!cb;
  3318. let scheduler;
  3319. if (flush === 'sync') {
  3320. scheduler = job; // the scheduler function gets called directly
  3321. }
  3322. else if (flush === 'post') {
  3323. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3324. }
  3325. else {
  3326. // default: 'pre'
  3327. scheduler = () => queuePreFlushCb(job);
  3328. }
  3329. const effect = new ReactiveEffect(getter, scheduler);
  3330. {
  3331. effect.onTrack = onTrack;
  3332. effect.onTrigger = onTrigger;
  3333. }
  3334. // initial run
  3335. if (cb) {
  3336. if (immediate) {
  3337. job();
  3338. }
  3339. else {
  3340. oldValue = effect.run();
  3341. }
  3342. }
  3343. else if (flush === 'post') {
  3344. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3345. }
  3346. else {
  3347. effect.run();
  3348. }
  3349. return () => {
  3350. effect.stop();
  3351. if (instance && instance.scope) {
  3352. remove(instance.scope.effects, effect);
  3353. }
  3354. };
  3355. }
  3356. // this.$watch
  3357. function instanceWatch(source, value, options) {
  3358. const publicThis = this.proxy;
  3359. const getter = isString(source)
  3360. ? source.includes('.')
  3361. ? createPathGetter(publicThis, source)
  3362. : () => publicThis[source]
  3363. : source.bind(publicThis, publicThis);
  3364. let cb;
  3365. if (isFunction(value)) {
  3366. cb = value;
  3367. }
  3368. else {
  3369. cb = value.handler;
  3370. options = value;
  3371. }
  3372. const cur = currentInstance;
  3373. setCurrentInstance(this);
  3374. const res = doWatch(getter, cb.bind(publicThis), options);
  3375. if (cur) {
  3376. setCurrentInstance(cur);
  3377. }
  3378. else {
  3379. unsetCurrentInstance();
  3380. }
  3381. return res;
  3382. }
  3383. function createPathGetter(ctx, path) {
  3384. const segments = path.split('.');
  3385. return () => {
  3386. let cur = ctx;
  3387. for (let i = 0; i < segments.length && cur; i++) {
  3388. cur = cur[segments[i]];
  3389. }
  3390. return cur;
  3391. };
  3392. }
  3393. function traverse(value, seen) {
  3394. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  3395. return value;
  3396. }
  3397. seen = seen || new Set();
  3398. if (seen.has(value)) {
  3399. return value;
  3400. }
  3401. seen.add(value);
  3402. if (isRef(value)) {
  3403. traverse(value.value, seen);
  3404. }
  3405. else if (isArray(value)) {
  3406. for (let i = 0; i < value.length; i++) {
  3407. traverse(value[i], seen);
  3408. }
  3409. }
  3410. else if (isSet(value) || isMap(value)) {
  3411. value.forEach((v) => {
  3412. traverse(v, seen);
  3413. });
  3414. }
  3415. else if (isPlainObject(value)) {
  3416. for (const key in value) {
  3417. traverse(value[key], seen);
  3418. }
  3419. }
  3420. return value;
  3421. }
  3422. function useTransitionState() {
  3423. const state = {
  3424. isMounted: false,
  3425. isLeaving: false,
  3426. isUnmounting: false,
  3427. leavingVNodes: new Map()
  3428. };
  3429. onMounted(() => {
  3430. state.isMounted = true;
  3431. });
  3432. onBeforeUnmount(() => {
  3433. state.isUnmounting = true;
  3434. });
  3435. return state;
  3436. }
  3437. const TransitionHookValidator = [Function, Array];
  3438. const BaseTransitionImpl = {
  3439. name: `BaseTransition`,
  3440. props: {
  3441. mode: String,
  3442. appear: Boolean,
  3443. persisted: Boolean,
  3444. // enter
  3445. onBeforeEnter: TransitionHookValidator,
  3446. onEnter: TransitionHookValidator,
  3447. onAfterEnter: TransitionHookValidator,
  3448. onEnterCancelled: TransitionHookValidator,
  3449. // leave
  3450. onBeforeLeave: TransitionHookValidator,
  3451. onLeave: TransitionHookValidator,
  3452. onAfterLeave: TransitionHookValidator,
  3453. onLeaveCancelled: TransitionHookValidator,
  3454. // appear
  3455. onBeforeAppear: TransitionHookValidator,
  3456. onAppear: TransitionHookValidator,
  3457. onAfterAppear: TransitionHookValidator,
  3458. onAppearCancelled: TransitionHookValidator
  3459. },
  3460. setup(props, { slots }) {
  3461. const instance = getCurrentInstance();
  3462. const state = useTransitionState();
  3463. let prevTransitionKey;
  3464. return () => {
  3465. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3466. if (!children || !children.length) {
  3467. return;
  3468. }
  3469. let child = children[0];
  3470. if (children.length > 1) {
  3471. let hasFound = false;
  3472. // locate first non-comment child
  3473. for (const c of children) {
  3474. if (c.type !== Comment) {
  3475. if (hasFound) {
  3476. // warn more than one non-comment child
  3477. warn$1('<transition> can only be used on a single element or component. ' +
  3478. 'Use <transition-group> for lists.');
  3479. break;
  3480. }
  3481. child = c;
  3482. hasFound = true;
  3483. }
  3484. }
  3485. }
  3486. // there's no need to track reactivity for these props so use the raw
  3487. // props for a bit better perf
  3488. const rawProps = toRaw(props);
  3489. const { mode } = rawProps;
  3490. // check mode
  3491. if (mode &&
  3492. mode !== 'in-out' &&
  3493. mode !== 'out-in' &&
  3494. mode !== 'default') {
  3495. warn$1(`invalid <transition> mode: ${mode}`);
  3496. }
  3497. if (state.isLeaving) {
  3498. return emptyPlaceholder(child);
  3499. }
  3500. // in the case of <transition><keep-alive/></transition>, we need to
  3501. // compare the type of the kept-alive children.
  3502. const innerChild = getKeepAliveChild(child);
  3503. if (!innerChild) {
  3504. return emptyPlaceholder(child);
  3505. }
  3506. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3507. setTransitionHooks(innerChild, enterHooks);
  3508. const oldChild = instance.subTree;
  3509. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3510. let transitionKeyChanged = false;
  3511. const { getTransitionKey } = innerChild.type;
  3512. if (getTransitionKey) {
  3513. const key = getTransitionKey();
  3514. if (prevTransitionKey === undefined) {
  3515. prevTransitionKey = key;
  3516. }
  3517. else if (key !== prevTransitionKey) {
  3518. prevTransitionKey = key;
  3519. transitionKeyChanged = true;
  3520. }
  3521. }
  3522. // handle mode
  3523. if (oldInnerChild &&
  3524. oldInnerChild.type !== Comment &&
  3525. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3526. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3527. // update old tree's hooks in case of dynamic transition
  3528. setTransitionHooks(oldInnerChild, leavingHooks);
  3529. // switching between different views
  3530. if (mode === 'out-in') {
  3531. state.isLeaving = true;
  3532. // return placeholder node and queue update when leave finishes
  3533. leavingHooks.afterLeave = () => {
  3534. state.isLeaving = false;
  3535. instance.update();
  3536. };
  3537. return emptyPlaceholder(child);
  3538. }
  3539. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3540. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3541. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3542. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3543. // early removal callback
  3544. el._leaveCb = () => {
  3545. earlyRemove();
  3546. el._leaveCb = undefined;
  3547. delete enterHooks.delayedLeave;
  3548. };
  3549. enterHooks.delayedLeave = delayedLeave;
  3550. };
  3551. }
  3552. }
  3553. return child;
  3554. };
  3555. }
  3556. };
  3557. // export the public type for h/tsx inference
  3558. // also to avoid inline import() in generated d.ts files
  3559. const BaseTransition = BaseTransitionImpl;
  3560. function getLeavingNodesForType(state, vnode) {
  3561. const { leavingVNodes } = state;
  3562. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3563. if (!leavingVNodesCache) {
  3564. leavingVNodesCache = Object.create(null);
  3565. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3566. }
  3567. return leavingVNodesCache;
  3568. }
  3569. // The transition hooks are attached to the vnode as vnode.transition
  3570. // and will be called at appropriate timing in the renderer.
  3571. function resolveTransitionHooks(vnode, props, state, instance) {
  3572. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3573. const key = String(vnode.key);
  3574. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3575. const callHook = (hook, args) => {
  3576. hook &&
  3577. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3578. };
  3579. const callAsyncHook = (hook, args) => {
  3580. const done = args[1];
  3581. callHook(hook, args);
  3582. if (isArray(hook)) {
  3583. if (hook.every(hook => hook.length <= 1))
  3584. done();
  3585. }
  3586. else if (hook.length <= 1) {
  3587. done();
  3588. }
  3589. };
  3590. const hooks = {
  3591. mode,
  3592. persisted,
  3593. beforeEnter(el) {
  3594. let hook = onBeforeEnter;
  3595. if (!state.isMounted) {
  3596. if (appear) {
  3597. hook = onBeforeAppear || onBeforeEnter;
  3598. }
  3599. else {
  3600. return;
  3601. }
  3602. }
  3603. // for same element (v-show)
  3604. if (el._leaveCb) {
  3605. el._leaveCb(true /* cancelled */);
  3606. }
  3607. // for toggled element with same key (v-if)
  3608. const leavingVNode = leavingVNodesCache[key];
  3609. if (leavingVNode &&
  3610. isSameVNodeType(vnode, leavingVNode) &&
  3611. leavingVNode.el._leaveCb) {
  3612. // force early removal (not cancelled)
  3613. leavingVNode.el._leaveCb();
  3614. }
  3615. callHook(hook, [el]);
  3616. },
  3617. enter(el) {
  3618. let hook = onEnter;
  3619. let afterHook = onAfterEnter;
  3620. let cancelHook = onEnterCancelled;
  3621. if (!state.isMounted) {
  3622. if (appear) {
  3623. hook = onAppear || onEnter;
  3624. afterHook = onAfterAppear || onAfterEnter;
  3625. cancelHook = onAppearCancelled || onEnterCancelled;
  3626. }
  3627. else {
  3628. return;
  3629. }
  3630. }
  3631. let called = false;
  3632. const done = (el._enterCb = (cancelled) => {
  3633. if (called)
  3634. return;
  3635. called = true;
  3636. if (cancelled) {
  3637. callHook(cancelHook, [el]);
  3638. }
  3639. else {
  3640. callHook(afterHook, [el]);
  3641. }
  3642. if (hooks.delayedLeave) {
  3643. hooks.delayedLeave();
  3644. }
  3645. el._enterCb = undefined;
  3646. });
  3647. if (hook) {
  3648. callAsyncHook(hook, [el, done]);
  3649. }
  3650. else {
  3651. done();
  3652. }
  3653. },
  3654. leave(el, remove) {
  3655. const key = String(vnode.key);
  3656. if (el._enterCb) {
  3657. el._enterCb(true /* cancelled */);
  3658. }
  3659. if (state.isUnmounting) {
  3660. return remove();
  3661. }
  3662. callHook(onBeforeLeave, [el]);
  3663. let called = false;
  3664. const done = (el._leaveCb = (cancelled) => {
  3665. if (called)
  3666. return;
  3667. called = true;
  3668. remove();
  3669. if (cancelled) {
  3670. callHook(onLeaveCancelled, [el]);
  3671. }
  3672. else {
  3673. callHook(onAfterLeave, [el]);
  3674. }
  3675. el._leaveCb = undefined;
  3676. if (leavingVNodesCache[key] === vnode) {
  3677. delete leavingVNodesCache[key];
  3678. }
  3679. });
  3680. leavingVNodesCache[key] = vnode;
  3681. if (onLeave) {
  3682. callAsyncHook(onLeave, [el, done]);
  3683. }
  3684. else {
  3685. done();
  3686. }
  3687. },
  3688. clone(vnode) {
  3689. return resolveTransitionHooks(vnode, props, state, instance);
  3690. }
  3691. };
  3692. return hooks;
  3693. }
  3694. // the placeholder really only handles one special case: KeepAlive
  3695. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3696. // placeholder with empty content to avoid the KeepAlive instance from being
  3697. // unmounted.
  3698. function emptyPlaceholder(vnode) {
  3699. if (isKeepAlive(vnode)) {
  3700. vnode = cloneVNode(vnode);
  3701. vnode.children = null;
  3702. return vnode;
  3703. }
  3704. }
  3705. function getKeepAliveChild(vnode) {
  3706. return isKeepAlive(vnode)
  3707. ? vnode.children
  3708. ? vnode.children[0]
  3709. : undefined
  3710. : vnode;
  3711. }
  3712. function setTransitionHooks(vnode, hooks) {
  3713. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3714. setTransitionHooks(vnode.component.subTree, hooks);
  3715. }
  3716. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3717. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3718. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3719. }
  3720. else {
  3721. vnode.transition = hooks;
  3722. }
  3723. }
  3724. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3725. let ret = [];
  3726. let keyedFragmentCount = 0;
  3727. for (let i = 0; i < children.length; i++) {
  3728. let child = children[i];
  3729. // #5360 inherit parent key in case of <template v-for>
  3730. const key = parentKey == null
  3731. ? child.key
  3732. : String(parentKey) + String(child.key != null ? child.key : i);
  3733. // handle fragment children case, e.g. v-for
  3734. if (child.type === Fragment) {
  3735. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  3736. keyedFragmentCount++;
  3737. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3738. }
  3739. // comment placeholders should be skipped, e.g. v-if
  3740. else if (keepComment || child.type !== Comment) {
  3741. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3742. }
  3743. }
  3744. // #1126 if a transition children list contains multiple sub fragments, these
  3745. // fragments will be merged into a flat children array. Since each v-for
  3746. // fragment may contain different static bindings inside, we need to de-op
  3747. // these children to force full diffs to ensure correct behavior.
  3748. if (keyedFragmentCount > 1) {
  3749. for (let i = 0; i < ret.length; i++) {
  3750. ret[i].patchFlag = -2 /* BAIL */;
  3751. }
  3752. }
  3753. return ret;
  3754. }
  3755. // implementation, close to no-op
  3756. function defineComponent(options) {
  3757. return isFunction(options) ? { setup: options, name: options.name } : options;
  3758. }
  3759. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3760. function defineAsyncComponent(source) {
  3761. if (isFunction(source)) {
  3762. source = { loader: source };
  3763. }
  3764. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3765. suspensible = true, onError: userOnError } = source;
  3766. let pendingRequest = null;
  3767. let resolvedComp;
  3768. let retries = 0;
  3769. const retry = () => {
  3770. retries++;
  3771. pendingRequest = null;
  3772. return load();
  3773. };
  3774. const load = () => {
  3775. let thisRequest;
  3776. return (pendingRequest ||
  3777. (thisRequest = pendingRequest =
  3778. loader()
  3779. .catch(err => {
  3780. err = err instanceof Error ? err : new Error(String(err));
  3781. if (userOnError) {
  3782. return new Promise((resolve, reject) => {
  3783. const userRetry = () => resolve(retry());
  3784. const userFail = () => reject(err);
  3785. userOnError(err, userRetry, userFail, retries + 1);
  3786. });
  3787. }
  3788. else {
  3789. throw err;
  3790. }
  3791. })
  3792. .then((comp) => {
  3793. if (thisRequest !== pendingRequest && pendingRequest) {
  3794. return pendingRequest;
  3795. }
  3796. if (!comp) {
  3797. warn$1(`Async component loader resolved to undefined. ` +
  3798. `If you are using retry(), make sure to return its return value.`);
  3799. }
  3800. // interop module default
  3801. if (comp &&
  3802. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3803. comp = comp.default;
  3804. }
  3805. if (comp && !isObject(comp) && !isFunction(comp)) {
  3806. throw new Error(`Invalid async component load result: ${comp}`);
  3807. }
  3808. resolvedComp = comp;
  3809. return comp;
  3810. })));
  3811. };
  3812. return defineComponent({
  3813. name: 'AsyncComponentWrapper',
  3814. __asyncLoader: load,
  3815. get __asyncResolved() {
  3816. return resolvedComp;
  3817. },
  3818. setup() {
  3819. const instance = currentInstance;
  3820. // already resolved
  3821. if (resolvedComp) {
  3822. return () => createInnerComp(resolvedComp, instance);
  3823. }
  3824. const onError = (err) => {
  3825. pendingRequest = null;
  3826. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3827. };
  3828. // suspense-controlled or SSR.
  3829. if ((suspensible && instance.suspense) ||
  3830. (false )) {
  3831. return load()
  3832. .then(comp => {
  3833. return () => createInnerComp(comp, instance);
  3834. })
  3835. .catch(err => {
  3836. onError(err);
  3837. return () => errorComponent
  3838. ? createVNode(errorComponent, {
  3839. error: err
  3840. })
  3841. : null;
  3842. });
  3843. }
  3844. const loaded = ref(false);
  3845. const error = ref();
  3846. const delayed = ref(!!delay);
  3847. if (delay) {
  3848. setTimeout(() => {
  3849. delayed.value = false;
  3850. }, delay);
  3851. }
  3852. if (timeout != null) {
  3853. setTimeout(() => {
  3854. if (!loaded.value && !error.value) {
  3855. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3856. onError(err);
  3857. error.value = err;
  3858. }
  3859. }, timeout);
  3860. }
  3861. load()
  3862. .then(() => {
  3863. loaded.value = true;
  3864. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3865. // parent is keep-alive, force update so the loaded component's
  3866. // name is taken into account
  3867. queueJob(instance.parent.update);
  3868. }
  3869. })
  3870. .catch(err => {
  3871. onError(err);
  3872. error.value = err;
  3873. });
  3874. return () => {
  3875. if (loaded.value && resolvedComp) {
  3876. return createInnerComp(resolvedComp, instance);
  3877. }
  3878. else if (error.value && errorComponent) {
  3879. return createVNode(errorComponent, {
  3880. error: error.value
  3881. });
  3882. }
  3883. else if (loadingComponent && !delayed.value) {
  3884. return createVNode(loadingComponent);
  3885. }
  3886. };
  3887. }
  3888. });
  3889. }
  3890. function createInnerComp(comp, { vnode: { ref, props, children, shapeFlag }, parent }) {
  3891. const vnode = createVNode(comp, props, children);
  3892. // ensure inner component inherits the async wrapper's ref owner
  3893. vnode.ref = ref;
  3894. return vnode;
  3895. }
  3896. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3897. const KeepAliveImpl = {
  3898. name: `KeepAlive`,
  3899. // Marker for special handling inside the renderer. We are not using a ===
  3900. // check directly on KeepAlive in the renderer, because importing it directly
  3901. // would prevent it from being tree-shaken.
  3902. __isKeepAlive: true,
  3903. props: {
  3904. include: [String, RegExp, Array],
  3905. exclude: [String, RegExp, Array],
  3906. max: [String, Number]
  3907. },
  3908. setup(props, { slots }) {
  3909. const instance = getCurrentInstance();
  3910. // KeepAlive communicates with the instantiated renderer via the
  3911. // ctx where the renderer passes in its internals,
  3912. // and the KeepAlive instance exposes activate/deactivate implementations.
  3913. // The whole point of this is to avoid importing KeepAlive directly in the
  3914. // renderer to facilitate tree-shaking.
  3915. const sharedContext = instance.ctx;
  3916. const cache = new Map();
  3917. const keys = new Set();
  3918. let current = null;
  3919. {
  3920. instance.__v_cache = cache;
  3921. }
  3922. const parentSuspense = instance.suspense;
  3923. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3924. const storageContainer = createElement('div');
  3925. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3926. const instance = vnode.component;
  3927. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3928. // in case props have changed
  3929. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3930. queuePostRenderEffect(() => {
  3931. instance.isDeactivated = false;
  3932. if (instance.a) {
  3933. invokeArrayFns(instance.a);
  3934. }
  3935. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3936. if (vnodeHook) {
  3937. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3938. }
  3939. }, parentSuspense);
  3940. {
  3941. // Update components tree
  3942. devtoolsComponentAdded(instance);
  3943. }
  3944. };
  3945. sharedContext.deactivate = (vnode) => {
  3946. const instance = vnode.component;
  3947. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3948. queuePostRenderEffect(() => {
  3949. if (instance.da) {
  3950. invokeArrayFns(instance.da);
  3951. }
  3952. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3953. if (vnodeHook) {
  3954. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3955. }
  3956. instance.isDeactivated = true;
  3957. }, parentSuspense);
  3958. {
  3959. // Update components tree
  3960. devtoolsComponentAdded(instance);
  3961. }
  3962. };
  3963. function unmount(vnode) {
  3964. // reset the shapeFlag so it can be properly unmounted
  3965. resetShapeFlag(vnode);
  3966. _unmount(vnode, instance, parentSuspense, true);
  3967. }
  3968. function pruneCache(filter) {
  3969. cache.forEach((vnode, key) => {
  3970. const name = getComponentName(vnode.type);
  3971. if (name && (!filter || !filter(name))) {
  3972. pruneCacheEntry(key);
  3973. }
  3974. });
  3975. }
  3976. function pruneCacheEntry(key) {
  3977. const cached = cache.get(key);
  3978. if (!current || cached.type !== current.type) {
  3979. unmount(cached);
  3980. }
  3981. else if (current) {
  3982. // current active instance should no longer be kept-alive.
  3983. // we can't unmount it now but it might be later, so reset its flag now.
  3984. resetShapeFlag(current);
  3985. }
  3986. cache.delete(key);
  3987. keys.delete(key);
  3988. }
  3989. // prune cache on include/exclude prop change
  3990. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3991. include && pruneCache(name => matches(include, name));
  3992. exclude && pruneCache(name => !matches(exclude, name));
  3993. },
  3994. // prune post-render after `current` has been updated
  3995. { flush: 'post', deep: true });
  3996. // cache sub tree after render
  3997. let pendingCacheKey = null;
  3998. const cacheSubtree = () => {
  3999. // fix #1621, the pendingCacheKey could be 0
  4000. if (pendingCacheKey != null) {
  4001. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  4002. }
  4003. };
  4004. onMounted(cacheSubtree);
  4005. onUpdated(cacheSubtree);
  4006. onBeforeUnmount(() => {
  4007. cache.forEach(cached => {
  4008. const { subTree, suspense } = instance;
  4009. const vnode = getInnerChild(subTree);
  4010. if (cached.type === vnode.type) {
  4011. // current instance will be unmounted as part of keep-alive's unmount
  4012. resetShapeFlag(vnode);
  4013. // but invoke its deactivated hook here
  4014. const da = vnode.component.da;
  4015. da && queuePostRenderEffect(da, suspense);
  4016. return;
  4017. }
  4018. unmount(cached);
  4019. });
  4020. });
  4021. return () => {
  4022. pendingCacheKey = null;
  4023. if (!slots.default) {
  4024. return null;
  4025. }
  4026. const children = slots.default();
  4027. const rawVNode = children[0];
  4028. if (children.length > 1) {
  4029. {
  4030. warn$1(`KeepAlive should contain exactly one component child.`);
  4031. }
  4032. current = null;
  4033. return children;
  4034. }
  4035. else if (!isVNode(rawVNode) ||
  4036. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  4037. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  4038. current = null;
  4039. return rawVNode;
  4040. }
  4041. let vnode = getInnerChild(rawVNode);
  4042. const comp = vnode.type;
  4043. // for async components, name check should be based in its loaded
  4044. // inner component if available
  4045. const name = getComponentName(isAsyncWrapper(vnode)
  4046. ? vnode.type.__asyncResolved || {}
  4047. : comp);
  4048. const { include, exclude, max } = props;
  4049. if ((include && (!name || !matches(include, name))) ||
  4050. (exclude && name && matches(exclude, name))) {
  4051. current = vnode;
  4052. return rawVNode;
  4053. }
  4054. const key = vnode.key == null ? comp : vnode.key;
  4055. const cachedVNode = cache.get(key);
  4056. // clone vnode if it's reused because we are going to mutate it
  4057. if (vnode.el) {
  4058. vnode = cloneVNode(vnode);
  4059. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  4060. rawVNode.ssContent = vnode;
  4061. }
  4062. }
  4063. // #1513 it's possible for the returned vnode to be cloned due to attr
  4064. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4065. // that is mounted. Instead of caching it directly, we store the pending
  4066. // key and cache `instance.subTree` (the normalized vnode) in
  4067. // beforeMount/beforeUpdate hooks.
  4068. pendingCacheKey = key;
  4069. if (cachedVNode) {
  4070. // copy over mounted state
  4071. vnode.el = cachedVNode.el;
  4072. vnode.component = cachedVNode.component;
  4073. if (vnode.transition) {
  4074. // recursively update transition hooks on subTree
  4075. setTransitionHooks(vnode, vnode.transition);
  4076. }
  4077. // avoid vnode being mounted as fresh
  4078. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  4079. // make this key the freshest
  4080. keys.delete(key);
  4081. keys.add(key);
  4082. }
  4083. else {
  4084. keys.add(key);
  4085. // prune oldest entry
  4086. if (max && keys.size > parseInt(max, 10)) {
  4087. pruneCacheEntry(keys.values().next().value);
  4088. }
  4089. }
  4090. // avoid vnode being unmounted
  4091. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4092. current = vnode;
  4093. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  4094. };
  4095. }
  4096. };
  4097. // export the public type for h/tsx inference
  4098. // also to avoid inline import() in generated d.ts files
  4099. const KeepAlive = KeepAliveImpl;
  4100. function matches(pattern, name) {
  4101. if (isArray(pattern)) {
  4102. return pattern.some((p) => matches(p, name));
  4103. }
  4104. else if (isString(pattern)) {
  4105. return pattern.split(',').includes(name);
  4106. }
  4107. else if (pattern.test) {
  4108. return pattern.test(name);
  4109. }
  4110. /* istanbul ignore next */
  4111. return false;
  4112. }
  4113. function onActivated(hook, target) {
  4114. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  4115. }
  4116. function onDeactivated(hook, target) {
  4117. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  4118. }
  4119. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4120. // cache the deactivate branch check wrapper for injected hooks so the same
  4121. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4122. // deactivation check".
  4123. const wrappedHook = hook.__wdc ||
  4124. (hook.__wdc = () => {
  4125. // only fire the hook if the target instance is NOT in a deactivated branch.
  4126. let current = target;
  4127. while (current) {
  4128. if (current.isDeactivated) {
  4129. return;
  4130. }
  4131. current = current.parent;
  4132. }
  4133. return hook();
  4134. });
  4135. injectHook(type, wrappedHook, target);
  4136. // In addition to registering it on the target instance, we walk up the parent
  4137. // chain and register it on all ancestor instances that are keep-alive roots.
  4138. // This avoids the need to walk the entire component tree when invoking these
  4139. // hooks, and more importantly, avoids the need to track child components in
  4140. // arrays.
  4141. if (target) {
  4142. let current = target.parent;
  4143. while (current && current.parent) {
  4144. if (isKeepAlive(current.parent.vnode)) {
  4145. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4146. }
  4147. current = current.parent;
  4148. }
  4149. }
  4150. }
  4151. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4152. // injectHook wraps the original for error handling, so make sure to remove
  4153. // the wrapped version.
  4154. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4155. onUnmounted(() => {
  4156. remove(keepAliveRoot[type], injected);
  4157. }, target);
  4158. }
  4159. function resetShapeFlag(vnode) {
  4160. let shapeFlag = vnode.shapeFlag;
  4161. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4162. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4163. }
  4164. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  4165. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  4166. }
  4167. vnode.shapeFlag = shapeFlag;
  4168. }
  4169. function getInnerChild(vnode) {
  4170. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  4171. }
  4172. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4173. if (target) {
  4174. const hooks = target[type] || (target[type] = []);
  4175. // cache the error handling wrapper for injected hooks so the same hook
  4176. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4177. // handling".
  4178. const wrappedHook = hook.__weh ||
  4179. (hook.__weh = (...args) => {
  4180. if (target.isUnmounted) {
  4181. return;
  4182. }
  4183. // disable tracking inside all lifecycle hooks
  4184. // since they can potentially be called inside effects.
  4185. pauseTracking();
  4186. // Set currentInstance during hook invocation.
  4187. // This assumes the hook does not synchronously trigger other hooks, which
  4188. // can only be false when the user does something really funky.
  4189. setCurrentInstance(target);
  4190. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4191. unsetCurrentInstance();
  4192. resetTracking();
  4193. return res;
  4194. });
  4195. if (prepend) {
  4196. hooks.unshift(wrappedHook);
  4197. }
  4198. else {
  4199. hooks.push(wrappedHook);
  4200. }
  4201. return wrappedHook;
  4202. }
  4203. else {
  4204. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4205. warn$1(`${apiName} is called when there is no active component instance to be ` +
  4206. `associated with. ` +
  4207. `Lifecycle injection APIs can only be used during execution of setup().` +
  4208. (` If you are using async setup(), make sure to register lifecycle ` +
  4209. `hooks before the first await statement.`
  4210. ));
  4211. }
  4212. }
  4213. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4214. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4215. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  4216. injectHook(lifecycle, hook, target);
  4217. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  4218. const onMounted = createHook("m" /* MOUNTED */);
  4219. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  4220. const onUpdated = createHook("u" /* UPDATED */);
  4221. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  4222. const onUnmounted = createHook("um" /* UNMOUNTED */);
  4223. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  4224. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  4225. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  4226. function onErrorCaptured(hook, target = currentInstance) {
  4227. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  4228. }
  4229. /**
  4230. Runtime helper for applying directives to a vnode. Example usage:
  4231. const comp = resolveComponent('comp')
  4232. const foo = resolveDirective('foo')
  4233. const bar = resolveDirective('bar')
  4234. return withDirectives(h(comp), [
  4235. [foo, this.x],
  4236. [bar, this.y]
  4237. ])
  4238. */
  4239. function validateDirectiveName(name) {
  4240. if (isBuiltInDirective(name)) {
  4241. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  4242. }
  4243. }
  4244. /**
  4245. * Adds directives to a VNode.
  4246. */
  4247. function withDirectives(vnode, directives) {
  4248. const internalInstance = currentRenderingInstance;
  4249. if (internalInstance === null) {
  4250. warn$1(`withDirectives can only be used inside render functions.`);
  4251. return vnode;
  4252. }
  4253. const instance = getExposeProxy(internalInstance) ||
  4254. internalInstance.proxy;
  4255. const bindings = vnode.dirs || (vnode.dirs = []);
  4256. for (let i = 0; i < directives.length; i++) {
  4257. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4258. if (isFunction(dir)) {
  4259. dir = {
  4260. mounted: dir,
  4261. updated: dir
  4262. };
  4263. }
  4264. if (dir.deep) {
  4265. traverse(value);
  4266. }
  4267. bindings.push({
  4268. dir,
  4269. instance,
  4270. value,
  4271. oldValue: void 0,
  4272. arg,
  4273. modifiers
  4274. });
  4275. }
  4276. return vnode;
  4277. }
  4278. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4279. const bindings = vnode.dirs;
  4280. const oldBindings = prevVNode && prevVNode.dirs;
  4281. for (let i = 0; i < bindings.length; i++) {
  4282. const binding = bindings[i];
  4283. if (oldBindings) {
  4284. binding.oldValue = oldBindings[i].value;
  4285. }
  4286. let hook = binding.dir[name];
  4287. if (hook) {
  4288. // disable tracking inside all lifecycle hooks
  4289. // since they can potentially be called inside effects.
  4290. pauseTracking();
  4291. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  4292. vnode.el,
  4293. binding,
  4294. vnode,
  4295. prevVNode
  4296. ]);
  4297. resetTracking();
  4298. }
  4299. }
  4300. }
  4301. const COMPONENTS = 'components';
  4302. const DIRECTIVES = 'directives';
  4303. /**
  4304. * @private
  4305. */
  4306. function resolveComponent(name, maybeSelfReference) {
  4307. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  4308. }
  4309. const NULL_DYNAMIC_COMPONENT = Symbol();
  4310. /**
  4311. * @private
  4312. */
  4313. function resolveDynamicComponent(component) {
  4314. if (isString(component)) {
  4315. return resolveAsset(COMPONENTS, component, false) || component;
  4316. }
  4317. else {
  4318. // invalid types will fallthrough to createVNode and raise warning
  4319. return (component || NULL_DYNAMIC_COMPONENT);
  4320. }
  4321. }
  4322. /**
  4323. * @private
  4324. */
  4325. function resolveDirective(name) {
  4326. return resolveAsset(DIRECTIVES, name);
  4327. }
  4328. // implementation
  4329. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  4330. const instance = currentRenderingInstance || currentInstance;
  4331. if (instance) {
  4332. const Component = instance.type;
  4333. // explicit self name has highest priority
  4334. if (type === COMPONENTS) {
  4335. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  4336. if (selfName &&
  4337. (selfName === name ||
  4338. selfName === camelize(name) ||
  4339. selfName === capitalize(camelize(name)))) {
  4340. return Component;
  4341. }
  4342. }
  4343. const res =
  4344. // local registration
  4345. // check instance[type] first which is resolved for options API
  4346. resolve(instance[type] || Component[type], name) ||
  4347. // global registration
  4348. resolve(instance.appContext[type], name);
  4349. if (!res && maybeSelfReference) {
  4350. // fallback to implicit self-reference
  4351. return Component;
  4352. }
  4353. if (warnMissing && !res) {
  4354. const extra = type === COMPONENTS
  4355. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  4356. `component resolution via compilerOptions.isCustomElement.`
  4357. : ``;
  4358. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  4359. }
  4360. return res;
  4361. }
  4362. else {
  4363. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  4364. `can only be used in render() or setup().`);
  4365. }
  4366. }
  4367. function resolve(registry, name) {
  4368. return (registry &&
  4369. (registry[name] ||
  4370. registry[camelize(name)] ||
  4371. registry[capitalize(camelize(name))]));
  4372. }
  4373. /**
  4374. * Actual implementation
  4375. */
  4376. function renderList(source, renderItem, cache, index) {
  4377. let ret;
  4378. const cached = (cache && cache[index]);
  4379. if (isArray(source) || isString(source)) {
  4380. ret = new Array(source.length);
  4381. for (let i = 0, l = source.length; i < l; i++) {
  4382. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  4383. }
  4384. }
  4385. else if (typeof source === 'number') {
  4386. if (!Number.isInteger(source)) {
  4387. warn$1(`The v-for range expect an integer value but got ${source}.`);
  4388. }
  4389. ret = new Array(source);
  4390. for (let i = 0; i < source; i++) {
  4391. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  4392. }
  4393. }
  4394. else if (isObject(source)) {
  4395. if (source[Symbol.iterator]) {
  4396. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  4397. }
  4398. else {
  4399. const keys = Object.keys(source);
  4400. ret = new Array(keys.length);
  4401. for (let i = 0, l = keys.length; i < l; i++) {
  4402. const key = keys[i];
  4403. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  4404. }
  4405. }
  4406. }
  4407. else {
  4408. ret = [];
  4409. }
  4410. if (cache) {
  4411. cache[index] = ret;
  4412. }
  4413. return ret;
  4414. }
  4415. /**
  4416. * Compiler runtime helper for creating dynamic slots object
  4417. * @private
  4418. */
  4419. function createSlots(slots, dynamicSlots) {
  4420. for (let i = 0; i < dynamicSlots.length; i++) {
  4421. const slot = dynamicSlots[i];
  4422. // array of dynamic slot generated by <template v-for="..." #[...]>
  4423. if (isArray(slot)) {
  4424. for (let j = 0; j < slot.length; j++) {
  4425. slots[slot[j].name] = slot[j].fn;
  4426. }
  4427. }
  4428. else if (slot) {
  4429. // conditional single slot generated by <template v-if="..." #foo>
  4430. slots[slot.name] = slot.fn;
  4431. }
  4432. }
  4433. return slots;
  4434. }
  4435. /**
  4436. * Compiler runtime helper for rendering `<slot/>`
  4437. * @private
  4438. */
  4439. function renderSlot(slots, name, props = {},
  4440. // this is not a user-facing function, so the fallback is always generated by
  4441. // the compiler and guaranteed to be a function returning an array
  4442. fallback, noSlotted) {
  4443. if (currentRenderingInstance.isCE ||
  4444. (currentRenderingInstance.parent &&
  4445. isAsyncWrapper(currentRenderingInstance.parent) &&
  4446. currentRenderingInstance.parent.isCE)) {
  4447. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  4448. }
  4449. let slot = slots[name];
  4450. if (slot && slot.length > 1) {
  4451. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  4452. `function. You need to mark this component with $dynamic-slots in the ` +
  4453. `parent template.`);
  4454. slot = () => [];
  4455. }
  4456. // a compiled slot disables block tracking by default to avoid manual
  4457. // invocation interfering with template-based block tracking, but in
  4458. // `renderSlot` we can be sure that it's template-based so we can force
  4459. // enable it.
  4460. if (slot && slot._c) {
  4461. slot._d = false;
  4462. }
  4463. openBlock();
  4464. const validSlotContent = slot && ensureValidVNode(slot(props));
  4465. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  4466. ? 64 /* STABLE_FRAGMENT */
  4467. : -2 /* BAIL */);
  4468. if (!noSlotted && rendered.scopeId) {
  4469. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  4470. }
  4471. if (slot && slot._c) {
  4472. slot._d = true;
  4473. }
  4474. return rendered;
  4475. }
  4476. function ensureValidVNode(vnodes) {
  4477. return vnodes.some(child => {
  4478. if (!isVNode(child))
  4479. return true;
  4480. if (child.type === Comment)
  4481. return false;
  4482. if (child.type === Fragment &&
  4483. !ensureValidVNode(child.children))
  4484. return false;
  4485. return true;
  4486. })
  4487. ? vnodes
  4488. : null;
  4489. }
  4490. /**
  4491. * For prefixing keys in v-on="obj" with "on"
  4492. * @private
  4493. */
  4494. function toHandlers(obj) {
  4495. const ret = {};
  4496. if (!isObject(obj)) {
  4497. warn$1(`v-on with no argument expects an object value.`);
  4498. return ret;
  4499. }
  4500. for (const key in obj) {
  4501. ret[toHandlerKey(key)] = obj[key];
  4502. }
  4503. return ret;
  4504. }
  4505. /**
  4506. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4507. * they exist in the internal parent chain. For code that relies on traversing
  4508. * public $parent chains, skip functional ones and go to the parent instead.
  4509. */
  4510. const getPublicInstance = (i) => {
  4511. if (!i)
  4512. return null;
  4513. if (isStatefulComponent(i))
  4514. return getExposeProxy(i) || i.proxy;
  4515. return getPublicInstance(i.parent);
  4516. };
  4517. const publicPropertiesMap =
  4518. // Move PURE marker to new line to workaround compiler discarding it
  4519. // due to type annotation
  4520. /*#__PURE__*/ extend(Object.create(null), {
  4521. $: i => i,
  4522. $el: i => i.vnode.el,
  4523. $data: i => i.data,
  4524. $props: i => (shallowReadonly(i.props) ),
  4525. $attrs: i => (shallowReadonly(i.attrs) ),
  4526. $slots: i => (shallowReadonly(i.slots) ),
  4527. $refs: i => (shallowReadonly(i.refs) ),
  4528. $parent: i => getPublicInstance(i.parent),
  4529. $root: i => getPublicInstance(i.root),
  4530. $emit: i => i.emit,
  4531. $options: i => (resolveMergedOptions(i) ),
  4532. $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
  4533. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  4534. $watch: i => (instanceWatch.bind(i) )
  4535. });
  4536. const isReservedPrefix = (key) => key === '_' || key === '$';
  4537. const PublicInstanceProxyHandlers = {
  4538. get({ _: instance }, key) {
  4539. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  4540. // for internal formatters to know that this is a Vue instance
  4541. if (key === '__isVue') {
  4542. return true;
  4543. }
  4544. // prioritize <script setup> bindings during dev.
  4545. // this allows even properties that start with _ or $ to be used - so that
  4546. // it aligns with the production behavior where the render fn is inlined and
  4547. // indeed has access to all declared variables.
  4548. if (setupState !== EMPTY_OBJ &&
  4549. setupState.__isScriptSetup &&
  4550. hasOwn(setupState, key)) {
  4551. return setupState[key];
  4552. }
  4553. // data / props / ctx
  4554. // This getter gets called for every property access on the render context
  4555. // during render and is a major hotspot. The most expensive part of this
  4556. // is the multiple hasOwn() calls. It's much faster to do a simple property
  4557. // access on a plain object, so we use an accessCache object (with null
  4558. // prototype) to memoize what access type a key corresponds to.
  4559. let normalizedProps;
  4560. if (key[0] !== '$') {
  4561. const n = accessCache[key];
  4562. if (n !== undefined) {
  4563. switch (n) {
  4564. case 1 /* SETUP */:
  4565. return setupState[key];
  4566. case 2 /* DATA */:
  4567. return data[key];
  4568. case 4 /* CONTEXT */:
  4569. return ctx[key];
  4570. case 3 /* PROPS */:
  4571. return props[key];
  4572. // default: just fallthrough
  4573. }
  4574. }
  4575. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  4576. accessCache[key] = 1 /* SETUP */;
  4577. return setupState[key];
  4578. }
  4579. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4580. accessCache[key] = 2 /* DATA */;
  4581. return data[key];
  4582. }
  4583. else if (
  4584. // only cache other properties when instance has declared (thus stable)
  4585. // props
  4586. (normalizedProps = instance.propsOptions[0]) &&
  4587. hasOwn(normalizedProps, key)) {
  4588. accessCache[key] = 3 /* PROPS */;
  4589. return props[key];
  4590. }
  4591. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4592. accessCache[key] = 4 /* CONTEXT */;
  4593. return ctx[key];
  4594. }
  4595. else if (shouldCacheAccess) {
  4596. accessCache[key] = 0 /* OTHER */;
  4597. }
  4598. }
  4599. const publicGetter = publicPropertiesMap[key];
  4600. let cssModule, globalProperties;
  4601. // public $xxx properties
  4602. if (publicGetter) {
  4603. if (key === '$attrs') {
  4604. track(instance, "get" /* GET */, key);
  4605. markAttrsAccessed();
  4606. }
  4607. return publicGetter(instance);
  4608. }
  4609. else if (
  4610. // css module (injected by vue-loader)
  4611. (cssModule = type.__cssModules) &&
  4612. (cssModule = cssModule[key])) {
  4613. return cssModule;
  4614. }
  4615. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4616. // user may set custom properties to `this` that start with `$`
  4617. accessCache[key] = 4 /* CONTEXT */;
  4618. return ctx[key];
  4619. }
  4620. else if (
  4621. // global properties
  4622. ((globalProperties = appContext.config.globalProperties),
  4623. hasOwn(globalProperties, key))) {
  4624. {
  4625. return globalProperties[key];
  4626. }
  4627. }
  4628. else if (currentRenderingInstance &&
  4629. (!isString(key) ||
  4630. // #1091 avoid internal isRef/isVNode checks on component instance leading
  4631. // to infinite warning loop
  4632. key.indexOf('__v') !== 0)) {
  4633. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  4634. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  4635. `character ("$" or "_") and is not proxied on the render context.`);
  4636. }
  4637. else if (instance === currentRenderingInstance) {
  4638. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  4639. `but is not defined on instance.`);
  4640. }
  4641. }
  4642. },
  4643. set({ _: instance }, key, value) {
  4644. const { data, setupState, ctx } = instance;
  4645. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  4646. setupState[key] = value;
  4647. return true;
  4648. }
  4649. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4650. data[key] = value;
  4651. return true;
  4652. }
  4653. else if (hasOwn(instance.props, key)) {
  4654. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  4655. return false;
  4656. }
  4657. if (key[0] === '$' && key.slice(1) in instance) {
  4658. warn$1(`Attempting to mutate public property "${key}". ` +
  4659. `Properties starting with $ are reserved and readonly.`, instance);
  4660. return false;
  4661. }
  4662. else {
  4663. if (key in instance.appContext.config.globalProperties) {
  4664. Object.defineProperty(ctx, key, {
  4665. enumerable: true,
  4666. configurable: true,
  4667. value
  4668. });
  4669. }
  4670. else {
  4671. ctx[key] = value;
  4672. }
  4673. }
  4674. return true;
  4675. },
  4676. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  4677. let normalizedProps;
  4678. return (!!accessCache[key] ||
  4679. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  4680. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  4681. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  4682. hasOwn(ctx, key) ||
  4683. hasOwn(publicPropertiesMap, key) ||
  4684. hasOwn(appContext.config.globalProperties, key));
  4685. },
  4686. defineProperty(target, key, descriptor) {
  4687. if (descriptor.get != null) {
  4688. // invalidate key cache of a getter based property #5417
  4689. target._.accessCache[key] = 0;
  4690. }
  4691. else if (hasOwn(descriptor, 'value')) {
  4692. this.set(target, key, descriptor.value, null);
  4693. }
  4694. return Reflect.defineProperty(target, key, descriptor);
  4695. }
  4696. };
  4697. {
  4698. PublicInstanceProxyHandlers.ownKeys = (target) => {
  4699. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  4700. `The keys will be empty in production mode to avoid performance overhead.`);
  4701. return Reflect.ownKeys(target);
  4702. };
  4703. }
  4704. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  4705. get(target, key) {
  4706. // fast path for unscopables when using `with` block
  4707. if (key === Symbol.unscopables) {
  4708. return;
  4709. }
  4710. return PublicInstanceProxyHandlers.get(target, key, target);
  4711. },
  4712. has(_, key) {
  4713. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  4714. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  4715. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  4716. }
  4717. return has;
  4718. }
  4719. });
  4720. // dev only
  4721. // In dev mode, the proxy target exposes the same properties as seen on `this`
  4722. // for easier console inspection. In prod mode it will be an empty object so
  4723. // these properties definitions can be skipped.
  4724. function createDevRenderContext(instance) {
  4725. const target = {};
  4726. // expose internal instance for proxy handlers
  4727. Object.defineProperty(target, `_`, {
  4728. configurable: true,
  4729. enumerable: false,
  4730. get: () => instance
  4731. });
  4732. // expose public properties
  4733. Object.keys(publicPropertiesMap).forEach(key => {
  4734. Object.defineProperty(target, key, {
  4735. configurable: true,
  4736. enumerable: false,
  4737. get: () => publicPropertiesMap[key](instance),
  4738. // intercepted by the proxy so no need for implementation,
  4739. // but needed to prevent set errors
  4740. set: NOOP
  4741. });
  4742. });
  4743. return target;
  4744. }
  4745. // dev only
  4746. function exposePropsOnRenderContext(instance) {
  4747. const { ctx, propsOptions: [propsOptions] } = instance;
  4748. if (propsOptions) {
  4749. Object.keys(propsOptions).forEach(key => {
  4750. Object.defineProperty(ctx, key, {
  4751. enumerable: true,
  4752. configurable: true,
  4753. get: () => instance.props[key],
  4754. set: NOOP
  4755. });
  4756. });
  4757. }
  4758. }
  4759. // dev only
  4760. function exposeSetupStateOnRenderContext(instance) {
  4761. const { ctx, setupState } = instance;
  4762. Object.keys(toRaw(setupState)).forEach(key => {
  4763. if (!setupState.__isScriptSetup) {
  4764. if (isReservedPrefix(key[0])) {
  4765. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  4766. `which are reserved prefixes for Vue internals.`);
  4767. return;
  4768. }
  4769. Object.defineProperty(ctx, key, {
  4770. enumerable: true,
  4771. configurable: true,
  4772. get: () => setupState[key],
  4773. set: NOOP
  4774. });
  4775. }
  4776. });
  4777. }
  4778. function createDuplicateChecker() {
  4779. const cache = Object.create(null);
  4780. return (type, key) => {
  4781. if (cache[key]) {
  4782. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4783. }
  4784. else {
  4785. cache[key] = type;
  4786. }
  4787. };
  4788. }
  4789. let shouldCacheAccess = true;
  4790. function applyOptions(instance) {
  4791. const options = resolveMergedOptions(instance);
  4792. const publicThis = instance.proxy;
  4793. const ctx = instance.ctx;
  4794. // do not cache property access on public proxy during state initialization
  4795. shouldCacheAccess = false;
  4796. // call beforeCreate first before accessing other options since
  4797. // the hook may mutate resolved options (#2791)
  4798. if (options.beforeCreate) {
  4799. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  4800. }
  4801. const {
  4802. // state
  4803. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4804. // lifecycle
  4805. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4806. // public API
  4807. expose, inheritAttrs,
  4808. // assets
  4809. components, directives, filters } = options;
  4810. const checkDuplicateProperties = createDuplicateChecker() ;
  4811. {
  4812. const [propsOptions] = instance.propsOptions;
  4813. if (propsOptions) {
  4814. for (const key in propsOptions) {
  4815. checkDuplicateProperties("Props" /* PROPS */, key);
  4816. }
  4817. }
  4818. }
  4819. // options initialization order (to be consistent with Vue 2):
  4820. // - props (already done outside of this function)
  4821. // - inject
  4822. // - methods
  4823. // - data (deferred since it relies on `this` access)
  4824. // - computed
  4825. // - watch (deferred since it relies on `this` access)
  4826. if (injectOptions) {
  4827. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4828. }
  4829. if (methods) {
  4830. for (const key in methods) {
  4831. const methodHandler = methods[key];
  4832. if (isFunction(methodHandler)) {
  4833. // In dev mode, we use the `createRenderContext` function to define
  4834. // methods to the proxy target, and those are read-only but
  4835. // reconfigurable, so it needs to be redefined here
  4836. {
  4837. Object.defineProperty(ctx, key, {
  4838. value: methodHandler.bind(publicThis),
  4839. configurable: true,
  4840. enumerable: true,
  4841. writable: true
  4842. });
  4843. }
  4844. {
  4845. checkDuplicateProperties("Methods" /* METHODS */, key);
  4846. }
  4847. }
  4848. else {
  4849. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4850. `Did you reference the function correctly?`);
  4851. }
  4852. }
  4853. }
  4854. if (dataOptions) {
  4855. if (!isFunction(dataOptions)) {
  4856. warn$1(`The data option must be a function. ` +
  4857. `Plain object usage is no longer supported.`);
  4858. }
  4859. const data = dataOptions.call(publicThis, publicThis);
  4860. if (isPromise(data)) {
  4861. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  4862. `intend to perform data fetching before component renders, use ` +
  4863. `async setup() + <Suspense>.`);
  4864. }
  4865. if (!isObject(data)) {
  4866. warn$1(`data() should return an object.`);
  4867. }
  4868. else {
  4869. instance.data = reactive(data);
  4870. {
  4871. for (const key in data) {
  4872. checkDuplicateProperties("Data" /* DATA */, key);
  4873. // expose data on ctx during dev
  4874. if (!isReservedPrefix(key[0])) {
  4875. Object.defineProperty(ctx, key, {
  4876. configurable: true,
  4877. enumerable: true,
  4878. get: () => data[key],
  4879. set: NOOP
  4880. });
  4881. }
  4882. }
  4883. }
  4884. }
  4885. }
  4886. // state initialization complete at this point - start caching access
  4887. shouldCacheAccess = true;
  4888. if (computedOptions) {
  4889. for (const key in computedOptions) {
  4890. const opt = computedOptions[key];
  4891. const get = isFunction(opt)
  4892. ? opt.bind(publicThis, publicThis)
  4893. : isFunction(opt.get)
  4894. ? opt.get.bind(publicThis, publicThis)
  4895. : NOOP;
  4896. if (get === NOOP) {
  4897. warn$1(`Computed property "${key}" has no getter.`);
  4898. }
  4899. const set = !isFunction(opt) && isFunction(opt.set)
  4900. ? opt.set.bind(publicThis)
  4901. : () => {
  4902. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  4903. }
  4904. ;
  4905. const c = computed$1({
  4906. get,
  4907. set
  4908. });
  4909. Object.defineProperty(ctx, key, {
  4910. enumerable: true,
  4911. configurable: true,
  4912. get: () => c.value,
  4913. set: v => (c.value = v)
  4914. });
  4915. {
  4916. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  4917. }
  4918. }
  4919. }
  4920. if (watchOptions) {
  4921. for (const key in watchOptions) {
  4922. createWatcher(watchOptions[key], ctx, publicThis, key);
  4923. }
  4924. }
  4925. if (provideOptions) {
  4926. const provides = isFunction(provideOptions)
  4927. ? provideOptions.call(publicThis)
  4928. : provideOptions;
  4929. Reflect.ownKeys(provides).forEach(key => {
  4930. provide(key, provides[key]);
  4931. });
  4932. }
  4933. if (created) {
  4934. callHook(created, instance, "c" /* CREATED */);
  4935. }
  4936. function registerLifecycleHook(register, hook) {
  4937. if (isArray(hook)) {
  4938. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4939. }
  4940. else if (hook) {
  4941. register(hook.bind(publicThis));
  4942. }
  4943. }
  4944. registerLifecycleHook(onBeforeMount, beforeMount);
  4945. registerLifecycleHook(onMounted, mounted);
  4946. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4947. registerLifecycleHook(onUpdated, updated);
  4948. registerLifecycleHook(onActivated, activated);
  4949. registerLifecycleHook(onDeactivated, deactivated);
  4950. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4951. registerLifecycleHook(onRenderTracked, renderTracked);
  4952. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4953. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4954. registerLifecycleHook(onUnmounted, unmounted);
  4955. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4956. if (isArray(expose)) {
  4957. if (expose.length) {
  4958. const exposed = instance.exposed || (instance.exposed = {});
  4959. expose.forEach(key => {
  4960. Object.defineProperty(exposed, key, {
  4961. get: () => publicThis[key],
  4962. set: val => (publicThis[key] = val)
  4963. });
  4964. });
  4965. }
  4966. else if (!instance.exposed) {
  4967. instance.exposed = {};
  4968. }
  4969. }
  4970. // options that are handled when creating the instance but also need to be
  4971. // applied from mixins
  4972. if (render && instance.render === NOOP) {
  4973. instance.render = render;
  4974. }
  4975. if (inheritAttrs != null) {
  4976. instance.inheritAttrs = inheritAttrs;
  4977. }
  4978. // asset options.
  4979. if (components)
  4980. instance.components = components;
  4981. if (directives)
  4982. instance.directives = directives;
  4983. }
  4984. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  4985. if (isArray(injectOptions)) {
  4986. injectOptions = normalizeInject(injectOptions);
  4987. }
  4988. for (const key in injectOptions) {
  4989. const opt = injectOptions[key];
  4990. let injected;
  4991. if (isObject(opt)) {
  4992. if ('default' in opt) {
  4993. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4994. }
  4995. else {
  4996. injected = inject(opt.from || key);
  4997. }
  4998. }
  4999. else {
  5000. injected = inject(opt);
  5001. }
  5002. if (isRef(injected)) {
  5003. // TODO remove the check in 3.3
  5004. if (unwrapRef) {
  5005. Object.defineProperty(ctx, key, {
  5006. enumerable: true,
  5007. configurable: true,
  5008. get: () => injected.value,
  5009. set: v => (injected.value = v)
  5010. });
  5011. }
  5012. else {
  5013. {
  5014. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  5015. `and no longer needs \`.value\` in the next minor release. ` +
  5016. `To opt-in to the new behavior now, ` +
  5017. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  5018. `temporary and will not be needed in the future.)`);
  5019. }
  5020. ctx[key] = injected;
  5021. }
  5022. }
  5023. else {
  5024. ctx[key] = injected;
  5025. }
  5026. {
  5027. checkDuplicateProperties("Inject" /* INJECT */, key);
  5028. }
  5029. }
  5030. }
  5031. function callHook(hook, instance, type) {
  5032. callWithAsyncErrorHandling(isArray(hook)
  5033. ? hook.map(h => h.bind(instance.proxy))
  5034. : hook.bind(instance.proxy), instance, type);
  5035. }
  5036. function createWatcher(raw, ctx, publicThis, key) {
  5037. const getter = key.includes('.')
  5038. ? createPathGetter(publicThis, key)
  5039. : () => publicThis[key];
  5040. if (isString(raw)) {
  5041. const handler = ctx[raw];
  5042. if (isFunction(handler)) {
  5043. watch(getter, handler);
  5044. }
  5045. else {
  5046. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  5047. }
  5048. }
  5049. else if (isFunction(raw)) {
  5050. watch(getter, raw.bind(publicThis));
  5051. }
  5052. else if (isObject(raw)) {
  5053. if (isArray(raw)) {
  5054. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  5055. }
  5056. else {
  5057. const handler = isFunction(raw.handler)
  5058. ? raw.handler.bind(publicThis)
  5059. : ctx[raw.handler];
  5060. if (isFunction(handler)) {
  5061. watch(getter, handler, raw);
  5062. }
  5063. else {
  5064. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  5065. }
  5066. }
  5067. }
  5068. else {
  5069. warn$1(`Invalid watch option: "${key}"`, raw);
  5070. }
  5071. }
  5072. /**
  5073. * Resolve merged options and cache it on the component.
  5074. * This is done only once per-component since the merging does not involve
  5075. * instances.
  5076. */
  5077. function resolveMergedOptions(instance) {
  5078. const base = instance.type;
  5079. const { mixins, extends: extendsOptions } = base;
  5080. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  5081. const cached = cache.get(base);
  5082. let resolved;
  5083. if (cached) {
  5084. resolved = cached;
  5085. }
  5086. else if (!globalMixins.length && !mixins && !extendsOptions) {
  5087. {
  5088. resolved = base;
  5089. }
  5090. }
  5091. else {
  5092. resolved = {};
  5093. if (globalMixins.length) {
  5094. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  5095. }
  5096. mergeOptions(resolved, base, optionMergeStrategies);
  5097. }
  5098. cache.set(base, resolved);
  5099. return resolved;
  5100. }
  5101. function mergeOptions(to, from, strats, asMixin = false) {
  5102. const { mixins, extends: extendsOptions } = from;
  5103. if (extendsOptions) {
  5104. mergeOptions(to, extendsOptions, strats, true);
  5105. }
  5106. if (mixins) {
  5107. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  5108. }
  5109. for (const key in from) {
  5110. if (asMixin && key === 'expose') {
  5111. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  5112. `It should only be declared in the base component itself.`);
  5113. }
  5114. else {
  5115. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  5116. to[key] = strat ? strat(to[key], from[key]) : from[key];
  5117. }
  5118. }
  5119. return to;
  5120. }
  5121. const internalOptionMergeStrats = {
  5122. data: mergeDataFn,
  5123. props: mergeObjectOptions,
  5124. emits: mergeObjectOptions,
  5125. // objects
  5126. methods: mergeObjectOptions,
  5127. computed: mergeObjectOptions,
  5128. // lifecycle
  5129. beforeCreate: mergeAsArray,
  5130. created: mergeAsArray,
  5131. beforeMount: mergeAsArray,
  5132. mounted: mergeAsArray,
  5133. beforeUpdate: mergeAsArray,
  5134. updated: mergeAsArray,
  5135. beforeDestroy: mergeAsArray,
  5136. beforeUnmount: mergeAsArray,
  5137. destroyed: mergeAsArray,
  5138. unmounted: mergeAsArray,
  5139. activated: mergeAsArray,
  5140. deactivated: mergeAsArray,
  5141. errorCaptured: mergeAsArray,
  5142. serverPrefetch: mergeAsArray,
  5143. // assets
  5144. components: mergeObjectOptions,
  5145. directives: mergeObjectOptions,
  5146. // watch
  5147. watch: mergeWatchOptions,
  5148. // provide / inject
  5149. provide: mergeDataFn,
  5150. inject: mergeInject
  5151. };
  5152. function mergeDataFn(to, from) {
  5153. if (!from) {
  5154. return to;
  5155. }
  5156. if (!to) {
  5157. return from;
  5158. }
  5159. return function mergedDataFn() {
  5160. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  5161. };
  5162. }
  5163. function mergeInject(to, from) {
  5164. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  5165. }
  5166. function normalizeInject(raw) {
  5167. if (isArray(raw)) {
  5168. const res = {};
  5169. for (let i = 0; i < raw.length; i++) {
  5170. res[raw[i]] = raw[i];
  5171. }
  5172. return res;
  5173. }
  5174. return raw;
  5175. }
  5176. function mergeAsArray(to, from) {
  5177. return to ? [...new Set([].concat(to, from))] : from;
  5178. }
  5179. function mergeObjectOptions(to, from) {
  5180. return to ? extend(extend(Object.create(null), to), from) : from;
  5181. }
  5182. function mergeWatchOptions(to, from) {
  5183. if (!to)
  5184. return from;
  5185. if (!from)
  5186. return to;
  5187. const merged = extend(Object.create(null), to);
  5188. for (const key in from) {
  5189. merged[key] = mergeAsArray(to[key], from[key]);
  5190. }
  5191. return merged;
  5192. }
  5193. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  5194. isSSR = false) {
  5195. const props = {};
  5196. const attrs = {};
  5197. def(attrs, InternalObjectKey, 1);
  5198. instance.propsDefaults = Object.create(null);
  5199. setFullProps(instance, rawProps, props, attrs);
  5200. // ensure all declared prop keys are present
  5201. for (const key in instance.propsOptions[0]) {
  5202. if (!(key in props)) {
  5203. props[key] = undefined;
  5204. }
  5205. }
  5206. // validation
  5207. {
  5208. validateProps(rawProps || {}, props, instance);
  5209. }
  5210. if (isStateful) {
  5211. // stateful
  5212. instance.props = isSSR ? props : shallowReactive(props);
  5213. }
  5214. else {
  5215. if (!instance.type.props) {
  5216. // functional w/ optional props, props === attrs
  5217. instance.props = attrs;
  5218. }
  5219. else {
  5220. // functional w/ declared props
  5221. instance.props = props;
  5222. }
  5223. }
  5224. instance.attrs = attrs;
  5225. }
  5226. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  5227. const { props, attrs, vnode: { patchFlag } } = instance;
  5228. const rawCurrentProps = toRaw(props);
  5229. const [options] = instance.propsOptions;
  5230. let hasAttrsChanged = false;
  5231. if (
  5232. // always force full diff in dev
  5233. // - #1942 if hmr is enabled with sfc component
  5234. // - vite#872 non-sfc component used by sfc component
  5235. !((instance.type.__hmrId ||
  5236. (instance.parent && instance.parent.type.__hmrId))) &&
  5237. (optimized || patchFlag > 0) &&
  5238. !(patchFlag & 16 /* FULL_PROPS */)) {
  5239. if (patchFlag & 8 /* PROPS */) {
  5240. // Compiler-generated props & no keys change, just set the updated
  5241. // the props.
  5242. const propsToUpdate = instance.vnode.dynamicProps;
  5243. for (let i = 0; i < propsToUpdate.length; i++) {
  5244. let key = propsToUpdate[i];
  5245. // skip if the prop key is a declared emit event listener
  5246. if (isEmitListener(instance.emitsOptions, key)) {
  5247. continue;
  5248. }
  5249. // PROPS flag guarantees rawProps to be non-null
  5250. const value = rawProps[key];
  5251. if (options) {
  5252. // attr / props separation was done on init and will be consistent
  5253. // in this code path, so just check if attrs have it.
  5254. if (hasOwn(attrs, key)) {
  5255. if (value !== attrs[key]) {
  5256. attrs[key] = value;
  5257. hasAttrsChanged = true;
  5258. }
  5259. }
  5260. else {
  5261. const camelizedKey = camelize(key);
  5262. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  5263. }
  5264. }
  5265. else {
  5266. if (value !== attrs[key]) {
  5267. attrs[key] = value;
  5268. hasAttrsChanged = true;
  5269. }
  5270. }
  5271. }
  5272. }
  5273. }
  5274. else {
  5275. // full props update.
  5276. if (setFullProps(instance, rawProps, props, attrs)) {
  5277. hasAttrsChanged = true;
  5278. }
  5279. // in case of dynamic props, check if we need to delete keys from
  5280. // the props object
  5281. let kebabKey;
  5282. for (const key in rawCurrentProps) {
  5283. if (!rawProps ||
  5284. // for camelCase
  5285. (!hasOwn(rawProps, key) &&
  5286. // it's possible the original props was passed in as kebab-case
  5287. // and converted to camelCase (#955)
  5288. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  5289. if (options) {
  5290. if (rawPrevProps &&
  5291. // for camelCase
  5292. (rawPrevProps[key] !== undefined ||
  5293. // for kebab-case
  5294. rawPrevProps[kebabKey] !== undefined)) {
  5295. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  5296. }
  5297. }
  5298. else {
  5299. delete props[key];
  5300. }
  5301. }
  5302. }
  5303. // in the case of functional component w/o props declaration, props and
  5304. // attrs point to the same object so it should already have been updated.
  5305. if (attrs !== rawCurrentProps) {
  5306. for (const key in attrs) {
  5307. if (!rawProps ||
  5308. (!hasOwn(rawProps, key) &&
  5309. (!false ))) {
  5310. delete attrs[key];
  5311. hasAttrsChanged = true;
  5312. }
  5313. }
  5314. }
  5315. }
  5316. // trigger updates for $attrs in case it's used in component slots
  5317. if (hasAttrsChanged) {
  5318. trigger(instance, "set" /* SET */, '$attrs');
  5319. }
  5320. {
  5321. validateProps(rawProps || {}, props, instance);
  5322. }
  5323. }
  5324. function setFullProps(instance, rawProps, props, attrs) {
  5325. const [options, needCastKeys] = instance.propsOptions;
  5326. let hasAttrsChanged = false;
  5327. let rawCastValues;
  5328. if (rawProps) {
  5329. for (let key in rawProps) {
  5330. // key, ref are reserved and never passed down
  5331. if (isReservedProp(key)) {
  5332. continue;
  5333. }
  5334. const value = rawProps[key];
  5335. // prop option names are camelized during normalization, so to support
  5336. // kebab -> camel conversion here we need to camelize the key.
  5337. let camelKey;
  5338. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  5339. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  5340. props[camelKey] = value;
  5341. }
  5342. else {
  5343. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  5344. }
  5345. }
  5346. else if (!isEmitListener(instance.emitsOptions, key)) {
  5347. if (!(key in attrs) || value !== attrs[key]) {
  5348. attrs[key] = value;
  5349. hasAttrsChanged = true;
  5350. }
  5351. }
  5352. }
  5353. }
  5354. if (needCastKeys) {
  5355. const rawCurrentProps = toRaw(props);
  5356. const castValues = rawCastValues || EMPTY_OBJ;
  5357. for (let i = 0; i < needCastKeys.length; i++) {
  5358. const key = needCastKeys[i];
  5359. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  5360. }
  5361. }
  5362. return hasAttrsChanged;
  5363. }
  5364. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  5365. const opt = options[key];
  5366. if (opt != null) {
  5367. const hasDefault = hasOwn(opt, 'default');
  5368. // default values
  5369. if (hasDefault && value === undefined) {
  5370. const defaultValue = opt.default;
  5371. if (opt.type !== Function && isFunction(defaultValue)) {
  5372. const { propsDefaults } = instance;
  5373. if (key in propsDefaults) {
  5374. value = propsDefaults[key];
  5375. }
  5376. else {
  5377. setCurrentInstance(instance);
  5378. value = propsDefaults[key] = defaultValue.call(null, props);
  5379. unsetCurrentInstance();
  5380. }
  5381. }
  5382. else {
  5383. value = defaultValue;
  5384. }
  5385. }
  5386. // boolean casting
  5387. if (opt[0 /* shouldCast */]) {
  5388. if (isAbsent && !hasDefault) {
  5389. value = false;
  5390. }
  5391. else if (opt[1 /* shouldCastTrue */] &&
  5392. (value === '' || value === hyphenate(key))) {
  5393. value = true;
  5394. }
  5395. }
  5396. }
  5397. return value;
  5398. }
  5399. function normalizePropsOptions(comp, appContext, asMixin = false) {
  5400. const cache = appContext.propsCache;
  5401. const cached = cache.get(comp);
  5402. if (cached) {
  5403. return cached;
  5404. }
  5405. const raw = comp.props;
  5406. const normalized = {};
  5407. const needCastKeys = [];
  5408. // apply mixin/extends props
  5409. let hasExtends = false;
  5410. if (!isFunction(comp)) {
  5411. const extendProps = (raw) => {
  5412. hasExtends = true;
  5413. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  5414. extend(normalized, props);
  5415. if (keys)
  5416. needCastKeys.push(...keys);
  5417. };
  5418. if (!asMixin && appContext.mixins.length) {
  5419. appContext.mixins.forEach(extendProps);
  5420. }
  5421. if (comp.extends) {
  5422. extendProps(comp.extends);
  5423. }
  5424. if (comp.mixins) {
  5425. comp.mixins.forEach(extendProps);
  5426. }
  5427. }
  5428. if (!raw && !hasExtends) {
  5429. cache.set(comp, EMPTY_ARR);
  5430. return EMPTY_ARR;
  5431. }
  5432. if (isArray(raw)) {
  5433. for (let i = 0; i < raw.length; i++) {
  5434. if (!isString(raw[i])) {
  5435. warn$1(`props must be strings when using array syntax.`, raw[i]);
  5436. }
  5437. const normalizedKey = camelize(raw[i]);
  5438. if (validatePropName(normalizedKey)) {
  5439. normalized[normalizedKey] = EMPTY_OBJ;
  5440. }
  5441. }
  5442. }
  5443. else if (raw) {
  5444. if (!isObject(raw)) {
  5445. warn$1(`invalid props options`, raw);
  5446. }
  5447. for (const key in raw) {
  5448. const normalizedKey = camelize(key);
  5449. if (validatePropName(normalizedKey)) {
  5450. const opt = raw[key];
  5451. const prop = (normalized[normalizedKey] =
  5452. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  5453. if (prop) {
  5454. const booleanIndex = getTypeIndex(Boolean, prop.type);
  5455. const stringIndex = getTypeIndex(String, prop.type);
  5456. prop[0 /* shouldCast */] = booleanIndex > -1;
  5457. prop[1 /* shouldCastTrue */] =
  5458. stringIndex < 0 || booleanIndex < stringIndex;
  5459. // if the prop needs boolean casting or default value
  5460. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  5461. needCastKeys.push(normalizedKey);
  5462. }
  5463. }
  5464. }
  5465. }
  5466. }
  5467. const res = [normalized, needCastKeys];
  5468. cache.set(comp, res);
  5469. return res;
  5470. }
  5471. function validatePropName(key) {
  5472. if (key[0] !== '$') {
  5473. return true;
  5474. }
  5475. else {
  5476. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  5477. }
  5478. return false;
  5479. }
  5480. // use function string name to check type constructors
  5481. // so that it works across vms / iframes.
  5482. function getType(ctor) {
  5483. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  5484. return match ? match[1] : ctor === null ? 'null' : '';
  5485. }
  5486. function isSameType(a, b) {
  5487. return getType(a) === getType(b);
  5488. }
  5489. function getTypeIndex(type, expectedTypes) {
  5490. if (isArray(expectedTypes)) {
  5491. return expectedTypes.findIndex(t => isSameType(t, type));
  5492. }
  5493. else if (isFunction(expectedTypes)) {
  5494. return isSameType(expectedTypes, type) ? 0 : -1;
  5495. }
  5496. return -1;
  5497. }
  5498. /**
  5499. * dev only
  5500. */
  5501. function validateProps(rawProps, props, instance) {
  5502. const resolvedValues = toRaw(props);
  5503. const options = instance.propsOptions[0];
  5504. for (const key in options) {
  5505. let opt = options[key];
  5506. if (opt == null)
  5507. continue;
  5508. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  5509. }
  5510. }
  5511. /**
  5512. * dev only
  5513. */
  5514. function validateProp(name, value, prop, isAbsent) {
  5515. const { type, required, validator } = prop;
  5516. // required!
  5517. if (required && isAbsent) {
  5518. warn$1('Missing required prop: "' + name + '"');
  5519. return;
  5520. }
  5521. // missing but optional
  5522. if (value == null && !prop.required) {
  5523. return;
  5524. }
  5525. // type check
  5526. if (type != null && type !== true) {
  5527. let isValid = false;
  5528. const types = isArray(type) ? type : [type];
  5529. const expectedTypes = [];
  5530. // value is valid as long as one of the specified types match
  5531. for (let i = 0; i < types.length && !isValid; i++) {
  5532. const { valid, expectedType } = assertType(value, types[i]);
  5533. expectedTypes.push(expectedType || '');
  5534. isValid = valid;
  5535. }
  5536. if (!isValid) {
  5537. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  5538. return;
  5539. }
  5540. }
  5541. // custom validator
  5542. if (validator && !validator(value)) {
  5543. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  5544. }
  5545. }
  5546. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  5547. /**
  5548. * dev only
  5549. */
  5550. function assertType(value, type) {
  5551. let valid;
  5552. const expectedType = getType(type);
  5553. if (isSimpleType(expectedType)) {
  5554. const t = typeof value;
  5555. valid = t === expectedType.toLowerCase();
  5556. // for primitive wrapper objects
  5557. if (!valid && t === 'object') {
  5558. valid = value instanceof type;
  5559. }
  5560. }
  5561. else if (expectedType === 'Object') {
  5562. valid = isObject(value);
  5563. }
  5564. else if (expectedType === 'Array') {
  5565. valid = isArray(value);
  5566. }
  5567. else if (expectedType === 'null') {
  5568. valid = value === null;
  5569. }
  5570. else {
  5571. valid = value instanceof type;
  5572. }
  5573. return {
  5574. valid,
  5575. expectedType
  5576. };
  5577. }
  5578. /**
  5579. * dev only
  5580. */
  5581. function getInvalidTypeMessage(name, value, expectedTypes) {
  5582. let message = `Invalid prop: type check failed for prop "${name}".` +
  5583. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  5584. const expectedType = expectedTypes[0];
  5585. const receivedType = toRawType(value);
  5586. const expectedValue = styleValue(value, expectedType);
  5587. const receivedValue = styleValue(value, receivedType);
  5588. // check if we need to specify expected value
  5589. if (expectedTypes.length === 1 &&
  5590. isExplicable(expectedType) &&
  5591. !isBoolean(expectedType, receivedType)) {
  5592. message += ` with value ${expectedValue}`;
  5593. }
  5594. message += `, got ${receivedType} `;
  5595. // check if we need to specify received value
  5596. if (isExplicable(receivedType)) {
  5597. message += `with value ${receivedValue}.`;
  5598. }
  5599. return message;
  5600. }
  5601. /**
  5602. * dev only
  5603. */
  5604. function styleValue(value, type) {
  5605. if (type === 'String') {
  5606. return `"${value}"`;
  5607. }
  5608. else if (type === 'Number') {
  5609. return `${Number(value)}`;
  5610. }
  5611. else {
  5612. return `${value}`;
  5613. }
  5614. }
  5615. /**
  5616. * dev only
  5617. */
  5618. function isExplicable(type) {
  5619. const explicitTypes = ['string', 'number', 'boolean'];
  5620. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5621. }
  5622. /**
  5623. * dev only
  5624. */
  5625. function isBoolean(...args) {
  5626. return args.some(elem => elem.toLowerCase() === 'boolean');
  5627. }
  5628. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5629. const normalizeSlotValue = (value) => isArray(value)
  5630. ? value.map(normalizeVNode)
  5631. : [normalizeVNode(value)];
  5632. const normalizeSlot = (key, rawSlot, ctx) => {
  5633. if (rawSlot._n) {
  5634. // already normalized - #5353
  5635. return rawSlot;
  5636. }
  5637. const normalized = withCtx((...args) => {
  5638. if (currentInstance) {
  5639. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  5640. `this will not track dependencies used in the slot. ` +
  5641. `Invoke the slot function inside the render function instead.`);
  5642. }
  5643. return normalizeSlotValue(rawSlot(...args));
  5644. }, ctx);
  5645. normalized._c = false;
  5646. return normalized;
  5647. };
  5648. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5649. const ctx = rawSlots._ctx;
  5650. for (const key in rawSlots) {
  5651. if (isInternalKey(key))
  5652. continue;
  5653. const value = rawSlots[key];
  5654. if (isFunction(value)) {
  5655. slots[key] = normalizeSlot(key, value, ctx);
  5656. }
  5657. else if (value != null) {
  5658. {
  5659. warn$1(`Non-function value encountered for slot "${key}". ` +
  5660. `Prefer function slots for better performance.`);
  5661. }
  5662. const normalized = normalizeSlotValue(value);
  5663. slots[key] = () => normalized;
  5664. }
  5665. }
  5666. };
  5667. const normalizeVNodeSlots = (instance, children) => {
  5668. if (!isKeepAlive(instance.vnode) &&
  5669. !(false )) {
  5670. warn$1(`Non-function value encountered for default slot. ` +
  5671. `Prefer function slots for better performance.`);
  5672. }
  5673. const normalized = normalizeSlotValue(children);
  5674. instance.slots.default = () => normalized;
  5675. };
  5676. const initSlots = (instance, children) => {
  5677. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5678. const type = children._;
  5679. if (type) {
  5680. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5681. // we should avoid the proxy object polluting the slots of the internal instance
  5682. instance.slots = toRaw(children);
  5683. // make compiler marker non-enumerable
  5684. def(children, '_', type);
  5685. }
  5686. else {
  5687. normalizeObjectSlots(children, (instance.slots = {}));
  5688. }
  5689. }
  5690. else {
  5691. instance.slots = {};
  5692. if (children) {
  5693. normalizeVNodeSlots(instance, children);
  5694. }
  5695. }
  5696. def(instance.slots, InternalObjectKey, 1);
  5697. };
  5698. const updateSlots = (instance, children, optimized) => {
  5699. const { vnode, slots } = instance;
  5700. let needDeletionCheck = true;
  5701. let deletionComparisonTarget = EMPTY_OBJ;
  5702. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5703. const type = children._;
  5704. if (type) {
  5705. // compiled slots.
  5706. if (isHmrUpdating) {
  5707. // Parent was HMR updated so slot content may have changed.
  5708. // force update slots and mark instance for hmr as well
  5709. extend(slots, children);
  5710. }
  5711. else if (optimized && type === 1 /* STABLE */) {
  5712. // compiled AND stable.
  5713. // no need to update, and skip stale slots removal.
  5714. needDeletionCheck = false;
  5715. }
  5716. else {
  5717. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5718. // normalization.
  5719. extend(slots, children);
  5720. // #2893
  5721. // when rendering the optimized slots by manually written render function,
  5722. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5723. // i.e. let the `renderSlot` create the bailed Fragment
  5724. if (!optimized && type === 1 /* STABLE */) {
  5725. delete slots._;
  5726. }
  5727. }
  5728. }
  5729. else {
  5730. needDeletionCheck = !children.$stable;
  5731. normalizeObjectSlots(children, slots);
  5732. }
  5733. deletionComparisonTarget = children;
  5734. }
  5735. else if (children) {
  5736. // non slot object children (direct value) passed to a component
  5737. normalizeVNodeSlots(instance, children);
  5738. deletionComparisonTarget = { default: 1 };
  5739. }
  5740. // delete stale slots
  5741. if (needDeletionCheck) {
  5742. for (const key in slots) {
  5743. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5744. delete slots[key];
  5745. }
  5746. }
  5747. }
  5748. };
  5749. function createAppContext() {
  5750. return {
  5751. app: null,
  5752. config: {
  5753. isNativeTag: NO,
  5754. performance: false,
  5755. globalProperties: {},
  5756. optionMergeStrategies: {},
  5757. errorHandler: undefined,
  5758. warnHandler: undefined,
  5759. compilerOptions: {}
  5760. },
  5761. mixins: [],
  5762. components: {},
  5763. directives: {},
  5764. provides: Object.create(null),
  5765. optionsCache: new WeakMap(),
  5766. propsCache: new WeakMap(),
  5767. emitsCache: new WeakMap()
  5768. };
  5769. }
  5770. let uid = 0;
  5771. function createAppAPI(render, hydrate) {
  5772. return function createApp(rootComponent, rootProps = null) {
  5773. if (!isFunction(rootComponent)) {
  5774. rootComponent = Object.assign({}, rootComponent);
  5775. }
  5776. if (rootProps != null && !isObject(rootProps)) {
  5777. warn$1(`root props passed to app.mount() must be an object.`);
  5778. rootProps = null;
  5779. }
  5780. const context = createAppContext();
  5781. const installedPlugins = new Set();
  5782. let isMounted = false;
  5783. const app = (context.app = {
  5784. _uid: uid++,
  5785. _component: rootComponent,
  5786. _props: rootProps,
  5787. _container: null,
  5788. _context: context,
  5789. _instance: null,
  5790. version,
  5791. get config() {
  5792. return context.config;
  5793. },
  5794. set config(v) {
  5795. {
  5796. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  5797. }
  5798. },
  5799. use(plugin, ...options) {
  5800. if (installedPlugins.has(plugin)) {
  5801. warn$1(`Plugin has already been applied to target app.`);
  5802. }
  5803. else if (plugin && isFunction(plugin.install)) {
  5804. installedPlugins.add(plugin);
  5805. plugin.install(app, ...options);
  5806. }
  5807. else if (isFunction(plugin)) {
  5808. installedPlugins.add(plugin);
  5809. plugin(app, ...options);
  5810. }
  5811. else {
  5812. warn$1(`A plugin must either be a function or an object with an "install" ` +
  5813. `function.`);
  5814. }
  5815. return app;
  5816. },
  5817. mixin(mixin) {
  5818. {
  5819. if (!context.mixins.includes(mixin)) {
  5820. context.mixins.push(mixin);
  5821. }
  5822. else {
  5823. warn$1('Mixin has already been applied to target app' +
  5824. (mixin.name ? `: ${mixin.name}` : ''));
  5825. }
  5826. }
  5827. return app;
  5828. },
  5829. component(name, component) {
  5830. {
  5831. validateComponentName(name, context.config);
  5832. }
  5833. if (!component) {
  5834. return context.components[name];
  5835. }
  5836. if (context.components[name]) {
  5837. warn$1(`Component "${name}" has already been registered in target app.`);
  5838. }
  5839. context.components[name] = component;
  5840. return app;
  5841. },
  5842. directive(name, directive) {
  5843. {
  5844. validateDirectiveName(name);
  5845. }
  5846. if (!directive) {
  5847. return context.directives[name];
  5848. }
  5849. if (context.directives[name]) {
  5850. warn$1(`Directive "${name}" has already been registered in target app.`);
  5851. }
  5852. context.directives[name] = directive;
  5853. return app;
  5854. },
  5855. mount(rootContainer, isHydrate, isSVG) {
  5856. if (!isMounted) {
  5857. // #5571
  5858. if (rootContainer.__vue_app__) {
  5859. warn$1(`There is already an app instance mounted on the host container.\n` +
  5860. ` If you want to mount another app on the same host container,` +
  5861. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  5862. }
  5863. const vnode = createVNode(rootComponent, rootProps);
  5864. // store app context on the root VNode.
  5865. // this will be set on the root instance on initial mount.
  5866. vnode.appContext = context;
  5867. // HMR root reload
  5868. {
  5869. context.reload = () => {
  5870. render(cloneVNode(vnode), rootContainer, isSVG);
  5871. };
  5872. }
  5873. if (isHydrate && hydrate) {
  5874. hydrate(vnode, rootContainer);
  5875. }
  5876. else {
  5877. render(vnode, rootContainer, isSVG);
  5878. }
  5879. isMounted = true;
  5880. app._container = rootContainer;
  5881. rootContainer.__vue_app__ = app;
  5882. {
  5883. app._instance = vnode.component;
  5884. devtoolsInitApp(app, version);
  5885. }
  5886. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5887. }
  5888. else {
  5889. warn$1(`App has already been mounted.\n` +
  5890. `If you want to remount the same app, move your app creation logic ` +
  5891. `into a factory function and create fresh app instances for each ` +
  5892. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5893. }
  5894. },
  5895. unmount() {
  5896. if (isMounted) {
  5897. render(null, app._container);
  5898. {
  5899. app._instance = null;
  5900. devtoolsUnmountApp(app);
  5901. }
  5902. delete app._container.__vue_app__;
  5903. }
  5904. else {
  5905. warn$1(`Cannot unmount an app that is not mounted.`);
  5906. }
  5907. },
  5908. provide(key, value) {
  5909. if (key in context.provides) {
  5910. warn$1(`App already provides property with key "${String(key)}". ` +
  5911. `It will be overwritten with the new value.`);
  5912. }
  5913. context.provides[key] = value;
  5914. return app;
  5915. }
  5916. });
  5917. return app;
  5918. };
  5919. }
  5920. /**
  5921. * Function for handling a template ref
  5922. */
  5923. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5924. if (isArray(rawRef)) {
  5925. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5926. return;
  5927. }
  5928. if (isAsyncWrapper(vnode) && !isUnmount) {
  5929. // when mounting async components, nothing needs to be done,
  5930. // because the template ref is forwarded to inner component
  5931. return;
  5932. }
  5933. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  5934. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5935. : vnode.el;
  5936. const value = isUnmount ? null : refValue;
  5937. const { i: owner, r: ref } = rawRef;
  5938. if (!owner) {
  5939. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5940. `A vnode with ref must be created inside the render function.`);
  5941. return;
  5942. }
  5943. const oldRef = oldRawRef && oldRawRef.r;
  5944. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5945. const setupState = owner.setupState;
  5946. // dynamic ref changed. unset old ref
  5947. if (oldRef != null && oldRef !== ref) {
  5948. if (isString(oldRef)) {
  5949. refs[oldRef] = null;
  5950. if (hasOwn(setupState, oldRef)) {
  5951. setupState[oldRef] = null;
  5952. }
  5953. }
  5954. else if (isRef(oldRef)) {
  5955. oldRef.value = null;
  5956. }
  5957. }
  5958. if (isFunction(ref)) {
  5959. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  5960. }
  5961. else {
  5962. const _isString = isString(ref);
  5963. const _isRef = isRef(ref);
  5964. if (_isString || _isRef) {
  5965. const doSet = () => {
  5966. if (rawRef.f) {
  5967. const existing = _isString ? refs[ref] : ref.value;
  5968. if (isUnmount) {
  5969. isArray(existing) && remove(existing, refValue);
  5970. }
  5971. else {
  5972. if (!isArray(existing)) {
  5973. if (_isString) {
  5974. refs[ref] = [refValue];
  5975. if (hasOwn(setupState, ref)) {
  5976. setupState[ref] = refs[ref];
  5977. }
  5978. }
  5979. else {
  5980. ref.value = [refValue];
  5981. if (rawRef.k)
  5982. refs[rawRef.k] = ref.value;
  5983. }
  5984. }
  5985. else if (!existing.includes(refValue)) {
  5986. existing.push(refValue);
  5987. }
  5988. }
  5989. }
  5990. else if (_isString) {
  5991. refs[ref] = value;
  5992. if (hasOwn(setupState, ref)) {
  5993. setupState[ref] = value;
  5994. }
  5995. }
  5996. else if (_isRef) {
  5997. ref.value = value;
  5998. if (rawRef.k)
  5999. refs[rawRef.k] = value;
  6000. }
  6001. else {
  6002. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  6003. }
  6004. };
  6005. if (value) {
  6006. doSet.id = -1;
  6007. queuePostRenderEffect(doSet, parentSuspense);
  6008. }
  6009. else {
  6010. doSet();
  6011. }
  6012. }
  6013. else {
  6014. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  6015. }
  6016. }
  6017. }
  6018. let hasMismatch = false;
  6019. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  6020. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  6021. // Note: hydration is DOM-specific
  6022. // But we have to place it in core due to tight coupling with core - splitting
  6023. // it out creates a ton of unnecessary complexity.
  6024. // Hydration also depends on some renderer internal logic which needs to be
  6025. // passed in via arguments.
  6026. function createHydrationFunctions(rendererInternals) {
  6027. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  6028. const hydrate = (vnode, container) => {
  6029. if (!container.hasChildNodes()) {
  6030. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  6031. `Performing full mount instead.`);
  6032. patch(null, vnode, container);
  6033. flushPostFlushCbs();
  6034. container._vnode = vnode;
  6035. return;
  6036. }
  6037. hasMismatch = false;
  6038. hydrateNode(container.firstChild, vnode, null, null, null);
  6039. flushPostFlushCbs();
  6040. container._vnode = vnode;
  6041. if (hasMismatch && !false) {
  6042. // this error should show up in production
  6043. console.error(`Hydration completed but contains mismatches.`);
  6044. }
  6045. };
  6046. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  6047. const isFragmentStart = isComment(node) && node.data === '[';
  6048. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  6049. const { type, ref, shapeFlag, patchFlag } = vnode;
  6050. const domType = node.nodeType;
  6051. vnode.el = node;
  6052. if (patchFlag === -2 /* BAIL */) {
  6053. optimized = false;
  6054. vnode.dynamicChildren = null;
  6055. }
  6056. let nextNode = null;
  6057. switch (type) {
  6058. case Text:
  6059. if (domType !== 3 /* TEXT */) {
  6060. // #5728 empty text node inside a slot can cause hydration failure
  6061. // because the server rendered HTML won't contain a text node
  6062. if (vnode.children === '') {
  6063. insert((vnode.el = createText('')), parentNode(node), node);
  6064. nextNode = node;
  6065. }
  6066. else {
  6067. nextNode = onMismatch();
  6068. }
  6069. }
  6070. else {
  6071. if (node.data !== vnode.children) {
  6072. hasMismatch = true;
  6073. warn$1(`Hydration text mismatch:` +
  6074. `\n- Client: ${JSON.stringify(node.data)}` +
  6075. `\n- Server: ${JSON.stringify(vnode.children)}`);
  6076. node.data = vnode.children;
  6077. }
  6078. nextNode = nextSibling(node);
  6079. }
  6080. break;
  6081. case Comment:
  6082. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  6083. nextNode = onMismatch();
  6084. }
  6085. else {
  6086. nextNode = nextSibling(node);
  6087. }
  6088. break;
  6089. case Static:
  6090. if (domType !== 1 /* ELEMENT */ && domType !== 3 /* TEXT */) {
  6091. nextNode = onMismatch();
  6092. }
  6093. else {
  6094. // determine anchor, adopt content
  6095. nextNode = node;
  6096. // if the static vnode has its content stripped during build,
  6097. // adopt it from the server-rendered HTML.
  6098. const needToAdoptContent = !vnode.children.length;
  6099. for (let i = 0; i < vnode.staticCount; i++) {
  6100. if (needToAdoptContent)
  6101. vnode.children +=
  6102. nextNode.nodeType === 1 /* ELEMENT */
  6103. ? nextNode.outerHTML
  6104. : nextNode.data;
  6105. if (i === vnode.staticCount - 1) {
  6106. vnode.anchor = nextNode;
  6107. }
  6108. nextNode = nextSibling(nextNode);
  6109. }
  6110. return nextNode;
  6111. }
  6112. break;
  6113. case Fragment:
  6114. if (!isFragmentStart) {
  6115. nextNode = onMismatch();
  6116. }
  6117. else {
  6118. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6119. }
  6120. break;
  6121. default:
  6122. if (shapeFlag & 1 /* ELEMENT */) {
  6123. if (domType !== 1 /* ELEMENT */ ||
  6124. vnode.type.toLowerCase() !==
  6125. node.tagName.toLowerCase()) {
  6126. nextNode = onMismatch();
  6127. }
  6128. else {
  6129. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6130. }
  6131. }
  6132. else if (shapeFlag & 6 /* COMPONENT */) {
  6133. // when setting up the render effect, if the initial vnode already
  6134. // has .el set, the component will perform hydration instead of mount
  6135. // on its sub-tree.
  6136. vnode.slotScopeIds = slotScopeIds;
  6137. const container = parentNode(node);
  6138. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  6139. // component may be async, so in the case of fragments we cannot rely
  6140. // on component's rendered output to determine the end of the fragment
  6141. // instead, we do a lookahead to find the end anchor node.
  6142. nextNode = isFragmentStart
  6143. ? locateClosingAsyncAnchor(node)
  6144. : nextSibling(node);
  6145. // #4293 teleport as component root
  6146. if (nextNode &&
  6147. isComment(nextNode) &&
  6148. nextNode.data === 'teleport end') {
  6149. nextNode = nextSibling(nextNode);
  6150. }
  6151. // #3787
  6152. // if component is async, it may get moved / unmounted before its
  6153. // inner component is loaded, so we need to give it a placeholder
  6154. // vnode that matches its adopted DOM.
  6155. if (isAsyncWrapper(vnode)) {
  6156. let subTree;
  6157. if (isFragmentStart) {
  6158. subTree = createVNode(Fragment);
  6159. subTree.anchor = nextNode
  6160. ? nextNode.previousSibling
  6161. : container.lastChild;
  6162. }
  6163. else {
  6164. subTree =
  6165. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  6166. }
  6167. subTree.el = node;
  6168. vnode.component.subTree = subTree;
  6169. }
  6170. }
  6171. else if (shapeFlag & 64 /* TELEPORT */) {
  6172. if (domType !== 8 /* COMMENT */) {
  6173. nextNode = onMismatch();
  6174. }
  6175. else {
  6176. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  6177. }
  6178. }
  6179. else if (shapeFlag & 128 /* SUSPENSE */) {
  6180. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  6181. }
  6182. else {
  6183. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  6184. }
  6185. }
  6186. if (ref != null) {
  6187. setRef(ref, null, parentSuspense, vnode);
  6188. }
  6189. return nextNode;
  6190. };
  6191. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6192. optimized = optimized || !!vnode.dynamicChildren;
  6193. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  6194. // #4006 for form elements with non-string v-model value bindings
  6195. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  6196. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  6197. // skip props & children if this is hoisted static nodes
  6198. // #5405 in dev, always hydrate children for HMR
  6199. {
  6200. if (dirs) {
  6201. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6202. }
  6203. // props
  6204. if (props) {
  6205. if (forcePatchValue ||
  6206. !optimized ||
  6207. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  6208. for (const key in props) {
  6209. if ((forcePatchValue && key.endsWith('value')) ||
  6210. (isOn(key) && !isReservedProp(key))) {
  6211. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  6212. }
  6213. }
  6214. }
  6215. else if (props.onClick) {
  6216. // Fast path for click listeners (which is most often) to avoid
  6217. // iterating through props.
  6218. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  6219. }
  6220. }
  6221. // vnode / directive hooks
  6222. let vnodeHooks;
  6223. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  6224. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6225. }
  6226. if (dirs) {
  6227. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6228. }
  6229. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  6230. queueEffectWithSuspense(() => {
  6231. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6232. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6233. }, parentSuspense);
  6234. }
  6235. // children
  6236. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  6237. // skip if element has innerHTML / textContent
  6238. !(props && (props.innerHTML || props.textContent))) {
  6239. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  6240. let hasWarned = false;
  6241. while (next) {
  6242. hasMismatch = true;
  6243. if (!hasWarned) {
  6244. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  6245. `server rendered element contains more child nodes than client vdom.`);
  6246. hasWarned = true;
  6247. }
  6248. // The SSRed DOM contains more nodes than it should. Remove them.
  6249. const cur = next;
  6250. next = next.nextSibling;
  6251. remove(cur);
  6252. }
  6253. }
  6254. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6255. if (el.textContent !== vnode.children) {
  6256. hasMismatch = true;
  6257. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  6258. `- Client: ${el.textContent}\n` +
  6259. `- Server: ${vnode.children}`);
  6260. el.textContent = vnode.children;
  6261. }
  6262. }
  6263. }
  6264. return el.nextSibling;
  6265. };
  6266. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6267. optimized = optimized || !!parentVNode.dynamicChildren;
  6268. const children = parentVNode.children;
  6269. const l = children.length;
  6270. let hasWarned = false;
  6271. for (let i = 0; i < l; i++) {
  6272. const vnode = optimized
  6273. ? children[i]
  6274. : (children[i] = normalizeVNode(children[i]));
  6275. if (node) {
  6276. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6277. }
  6278. else if (vnode.type === Text && !vnode.children) {
  6279. continue;
  6280. }
  6281. else {
  6282. hasMismatch = true;
  6283. if (!hasWarned) {
  6284. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  6285. `server rendered element contains fewer child nodes than client vdom.`);
  6286. hasWarned = true;
  6287. }
  6288. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  6289. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6290. }
  6291. }
  6292. return node;
  6293. };
  6294. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6295. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  6296. if (fragmentSlotScopeIds) {
  6297. slotScopeIds = slotScopeIds
  6298. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6299. : fragmentSlotScopeIds;
  6300. }
  6301. const container = parentNode(node);
  6302. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  6303. if (next && isComment(next) && next.data === ']') {
  6304. return nextSibling((vnode.anchor = next));
  6305. }
  6306. else {
  6307. // fragment didn't hydrate successfully, since we didn't get a end anchor
  6308. // back. This should have led to node/children mismatch warnings.
  6309. hasMismatch = true;
  6310. // since the anchor is missing, we need to create one and insert it
  6311. insert((vnode.anchor = createComment(`]`)), container, next);
  6312. return next;
  6313. }
  6314. };
  6315. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  6316. hasMismatch = true;
  6317. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  6318. ? `(text)`
  6319. : isComment(node) && node.data === '['
  6320. ? `(start of fragment)`
  6321. : ``);
  6322. vnode.el = null;
  6323. if (isFragment) {
  6324. // remove excessive fragment nodes
  6325. const end = locateClosingAsyncAnchor(node);
  6326. while (true) {
  6327. const next = nextSibling(node);
  6328. if (next && next !== end) {
  6329. remove(next);
  6330. }
  6331. else {
  6332. break;
  6333. }
  6334. }
  6335. }
  6336. const next = nextSibling(node);
  6337. const container = parentNode(node);
  6338. remove(node);
  6339. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6340. return next;
  6341. };
  6342. const locateClosingAsyncAnchor = (node) => {
  6343. let match = 0;
  6344. while (node) {
  6345. node = nextSibling(node);
  6346. if (node && isComment(node)) {
  6347. if (node.data === '[')
  6348. match++;
  6349. if (node.data === ']') {
  6350. if (match === 0) {
  6351. return nextSibling(node);
  6352. }
  6353. else {
  6354. match--;
  6355. }
  6356. }
  6357. }
  6358. }
  6359. return node;
  6360. };
  6361. return [hydrate, hydrateNode];
  6362. }
  6363. /* eslint-disable no-restricted-globals */
  6364. let supported;
  6365. let perf;
  6366. function startMeasure(instance, type) {
  6367. if (instance.appContext.config.performance && isSupported()) {
  6368. perf.mark(`vue-${type}-${instance.uid}`);
  6369. }
  6370. {
  6371. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  6372. }
  6373. }
  6374. function endMeasure(instance, type) {
  6375. if (instance.appContext.config.performance && isSupported()) {
  6376. const startTag = `vue-${type}-${instance.uid}`;
  6377. const endTag = startTag + `:end`;
  6378. perf.mark(endTag);
  6379. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  6380. perf.clearMarks(startTag);
  6381. perf.clearMarks(endTag);
  6382. }
  6383. {
  6384. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  6385. }
  6386. }
  6387. function isSupported() {
  6388. if (supported !== undefined) {
  6389. return supported;
  6390. }
  6391. if (typeof window !== 'undefined' && window.performance) {
  6392. supported = true;
  6393. perf = window.performance;
  6394. }
  6395. else {
  6396. supported = false;
  6397. }
  6398. return supported;
  6399. }
  6400. const queuePostRenderEffect = queueEffectWithSuspense
  6401. ;
  6402. /**
  6403. * The createRenderer function accepts two generic arguments:
  6404. * HostNode and HostElement, corresponding to Node and Element types in the
  6405. * host environment. For example, for runtime-dom, HostNode would be the DOM
  6406. * `Node` interface and HostElement would be the DOM `Element` interface.
  6407. *
  6408. * Custom renderers can pass in the platform specific types like this:
  6409. *
  6410. * ``` js
  6411. * const { render, createApp } = createRenderer<Node, Element>({
  6412. * patchProp,
  6413. * ...nodeOps
  6414. * })
  6415. * ```
  6416. */
  6417. function createRenderer(options) {
  6418. return baseCreateRenderer(options);
  6419. }
  6420. // Separate API for creating hydration-enabled renderer.
  6421. // Hydration logic is only used when calling this function, making it
  6422. // tree-shakable.
  6423. function createHydrationRenderer(options) {
  6424. return baseCreateRenderer(options, createHydrationFunctions);
  6425. }
  6426. // implementation
  6427. function baseCreateRenderer(options, createHydrationFns) {
  6428. const target = getGlobalThis();
  6429. target.__VUE__ = true;
  6430. {
  6431. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  6432. }
  6433. 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;
  6434. // Note: functions inside this closure should use `const xxx = () => {}`
  6435. // style in order to prevent being inlined by minifiers.
  6436. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  6437. if (n1 === n2) {
  6438. return;
  6439. }
  6440. // patching & not same type, unmount old tree
  6441. if (n1 && !isSameVNodeType(n1, n2)) {
  6442. anchor = getNextHostNode(n1);
  6443. unmount(n1, parentComponent, parentSuspense, true);
  6444. n1 = null;
  6445. }
  6446. if (n2.patchFlag === -2 /* BAIL */) {
  6447. optimized = false;
  6448. n2.dynamicChildren = null;
  6449. }
  6450. const { type, ref, shapeFlag } = n2;
  6451. switch (type) {
  6452. case Text:
  6453. processText(n1, n2, container, anchor);
  6454. break;
  6455. case Comment:
  6456. processCommentNode(n1, n2, container, anchor);
  6457. break;
  6458. case Static:
  6459. if (n1 == null) {
  6460. mountStaticNode(n2, container, anchor, isSVG);
  6461. }
  6462. else {
  6463. patchStaticNode(n1, n2, container, isSVG);
  6464. }
  6465. break;
  6466. case Fragment:
  6467. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6468. break;
  6469. default:
  6470. if (shapeFlag & 1 /* ELEMENT */) {
  6471. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6472. }
  6473. else if (shapeFlag & 6 /* COMPONENT */) {
  6474. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6475. }
  6476. else if (shapeFlag & 64 /* TELEPORT */) {
  6477. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6478. }
  6479. else if (shapeFlag & 128 /* SUSPENSE */) {
  6480. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6481. }
  6482. else {
  6483. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  6484. }
  6485. }
  6486. // set ref
  6487. if (ref != null && parentComponent) {
  6488. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  6489. }
  6490. };
  6491. const processText = (n1, n2, container, anchor) => {
  6492. if (n1 == null) {
  6493. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  6494. }
  6495. else {
  6496. const el = (n2.el = n1.el);
  6497. if (n2.children !== n1.children) {
  6498. hostSetText(el, n2.children);
  6499. }
  6500. }
  6501. };
  6502. const processCommentNode = (n1, n2, container, anchor) => {
  6503. if (n1 == null) {
  6504. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  6505. }
  6506. else {
  6507. // there's no support for dynamic comments
  6508. n2.el = n1.el;
  6509. }
  6510. };
  6511. const mountStaticNode = (n2, container, anchor, isSVG) => {
  6512. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  6513. };
  6514. /**
  6515. * Dev / HMR only
  6516. */
  6517. const patchStaticNode = (n1, n2, container, isSVG) => {
  6518. // static nodes are only patched during dev for HMR
  6519. if (n2.children !== n1.children) {
  6520. const anchor = hostNextSibling(n1.anchor);
  6521. // remove existing
  6522. removeStaticNode(n1);
  6523. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  6524. }
  6525. else {
  6526. n2.el = n1.el;
  6527. n2.anchor = n1.anchor;
  6528. }
  6529. };
  6530. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6531. let next;
  6532. while (el && el !== anchor) {
  6533. next = hostNextSibling(el);
  6534. hostInsert(el, container, nextSibling);
  6535. el = next;
  6536. }
  6537. hostInsert(anchor, container, nextSibling);
  6538. };
  6539. const removeStaticNode = ({ el, anchor }) => {
  6540. let next;
  6541. while (el && el !== anchor) {
  6542. next = hostNextSibling(el);
  6543. hostRemove(el);
  6544. el = next;
  6545. }
  6546. hostRemove(anchor);
  6547. };
  6548. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6549. isSVG = isSVG || n2.type === 'svg';
  6550. if (n1 == null) {
  6551. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6552. }
  6553. else {
  6554. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6555. }
  6556. };
  6557. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6558. let el;
  6559. let vnodeHook;
  6560. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  6561. {
  6562. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6563. // mount children first, since some props may rely on child content
  6564. // being already rendered, e.g. `<select value>`
  6565. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6566. hostSetElementText(el, vnode.children);
  6567. }
  6568. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6569. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6570. }
  6571. if (dirs) {
  6572. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6573. }
  6574. // props
  6575. if (props) {
  6576. for (const key in props) {
  6577. if (key !== 'value' && !isReservedProp(key)) {
  6578. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6579. }
  6580. }
  6581. /**
  6582. * Special case for setting value on DOM elements:
  6583. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6584. * - it needs to be forced (#1471)
  6585. * #2353 proposes adding another renderer option to configure this, but
  6586. * the properties affects are so finite it is worth special casing it
  6587. * here to reduce the complexity. (Special casing it also should not
  6588. * affect non-DOM renderers)
  6589. */
  6590. if ('value' in props) {
  6591. hostPatchProp(el, 'value', null, props.value);
  6592. }
  6593. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6594. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6595. }
  6596. }
  6597. // scopeId
  6598. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6599. }
  6600. {
  6601. Object.defineProperty(el, '__vnode', {
  6602. value: vnode,
  6603. enumerable: false
  6604. });
  6605. Object.defineProperty(el, '__vueParentComponent', {
  6606. value: parentComponent,
  6607. enumerable: false
  6608. });
  6609. }
  6610. if (dirs) {
  6611. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6612. }
  6613. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6614. // #1689 For inside suspense + suspense resolved case, just call it
  6615. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6616. transition &&
  6617. !transition.persisted;
  6618. if (needCallTransitionHooks) {
  6619. transition.beforeEnter(el);
  6620. }
  6621. hostInsert(el, container, anchor);
  6622. if ((vnodeHook = props && props.onVnodeMounted) ||
  6623. needCallTransitionHooks ||
  6624. dirs) {
  6625. queuePostRenderEffect(() => {
  6626. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6627. needCallTransitionHooks && transition.enter(el);
  6628. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6629. }, parentSuspense);
  6630. }
  6631. };
  6632. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6633. if (scopeId) {
  6634. hostSetScopeId(el, scopeId);
  6635. }
  6636. if (slotScopeIds) {
  6637. for (let i = 0; i < slotScopeIds.length; i++) {
  6638. hostSetScopeId(el, slotScopeIds[i]);
  6639. }
  6640. }
  6641. if (parentComponent) {
  6642. let subTree = parentComponent.subTree;
  6643. if (subTree.patchFlag > 0 &&
  6644. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  6645. subTree =
  6646. filterSingleRoot(subTree.children) || subTree;
  6647. }
  6648. if (vnode === subTree) {
  6649. const parentVNode = parentComponent.vnode;
  6650. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6651. }
  6652. }
  6653. };
  6654. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6655. for (let i = start; i < children.length; i++) {
  6656. const child = (children[i] = optimized
  6657. ? cloneIfMounted(children[i])
  6658. : normalizeVNode(children[i]));
  6659. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6660. }
  6661. };
  6662. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6663. const el = (n2.el = n1.el);
  6664. let { patchFlag, dynamicChildren, dirs } = n2;
  6665. // #1426 take the old vnode's patch flag into account since user may clone a
  6666. // compiler-generated vnode, which de-opts to FULL_PROPS
  6667. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  6668. const oldProps = n1.props || EMPTY_OBJ;
  6669. const newProps = n2.props || EMPTY_OBJ;
  6670. let vnodeHook;
  6671. // disable recurse in beforeUpdate hooks
  6672. parentComponent && toggleRecurse(parentComponent, false);
  6673. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6674. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6675. }
  6676. if (dirs) {
  6677. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6678. }
  6679. parentComponent && toggleRecurse(parentComponent, true);
  6680. if (isHmrUpdating) {
  6681. // HMR updated, force full diff
  6682. patchFlag = 0;
  6683. optimized = false;
  6684. dynamicChildren = null;
  6685. }
  6686. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6687. if (dynamicChildren) {
  6688. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6689. if (parentComponent && parentComponent.type.__hmrId) {
  6690. traverseStaticChildren(n1, n2);
  6691. }
  6692. }
  6693. else if (!optimized) {
  6694. // full diff
  6695. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6696. }
  6697. if (patchFlag > 0) {
  6698. // the presence of a patchFlag means this element's render code was
  6699. // generated by the compiler and can take the fast path.
  6700. // in this path old node and new node are guaranteed to have the same shape
  6701. // (i.e. at the exact same position in the source template)
  6702. if (patchFlag & 16 /* FULL_PROPS */) {
  6703. // element props contain dynamic keys, full diff needed
  6704. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6705. }
  6706. else {
  6707. // class
  6708. // this flag is matched when the element has dynamic class bindings.
  6709. if (patchFlag & 2 /* CLASS */) {
  6710. if (oldProps.class !== newProps.class) {
  6711. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6712. }
  6713. }
  6714. // style
  6715. // this flag is matched when the element has dynamic style bindings
  6716. if (patchFlag & 4 /* STYLE */) {
  6717. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6718. }
  6719. // props
  6720. // This flag is matched when the element has dynamic prop/attr bindings
  6721. // other than class and style. The keys of dynamic prop/attrs are saved for
  6722. // faster iteration.
  6723. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6724. // bail out and go through a full diff because we need to unset the old key
  6725. if (patchFlag & 8 /* PROPS */) {
  6726. // if the flag is present then dynamicProps must be non-null
  6727. const propsToUpdate = n2.dynamicProps;
  6728. for (let i = 0; i < propsToUpdate.length; i++) {
  6729. const key = propsToUpdate[i];
  6730. const prev = oldProps[key];
  6731. const next = newProps[key];
  6732. // #1471 force patch value
  6733. if (next !== prev || key === 'value') {
  6734. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6735. }
  6736. }
  6737. }
  6738. }
  6739. // text
  6740. // This flag is matched when the element has only dynamic text children.
  6741. if (patchFlag & 1 /* TEXT */) {
  6742. if (n1.children !== n2.children) {
  6743. hostSetElementText(el, n2.children);
  6744. }
  6745. }
  6746. }
  6747. else if (!optimized && dynamicChildren == null) {
  6748. // unoptimized, full diff
  6749. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6750. }
  6751. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6752. queuePostRenderEffect(() => {
  6753. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6754. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6755. }, parentSuspense);
  6756. }
  6757. };
  6758. // The fast path for blocks.
  6759. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6760. for (let i = 0; i < newChildren.length; i++) {
  6761. const oldVNode = oldChildren[i];
  6762. const newVNode = newChildren[i];
  6763. // Determine the container (parent element) for the patch.
  6764. const container =
  6765. // oldVNode may be an errored async setup() component inside Suspense
  6766. // which will not have a mounted element
  6767. oldVNode.el &&
  6768. // - In the case of a Fragment, we need to provide the actual parent
  6769. // of the Fragment itself so it can move its children.
  6770. (oldVNode.type === Fragment ||
  6771. // - In the case of different nodes, there is going to be a replacement
  6772. // which also requires the correct parent container
  6773. !isSameVNodeType(oldVNode, newVNode) ||
  6774. // - In the case of a component, it could contain anything.
  6775. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  6776. ? hostParentNode(oldVNode.el)
  6777. : // In other cases, the parent container is not actually used so we
  6778. // just pass the block element here to avoid a DOM parentNode call.
  6779. fallbackContainer;
  6780. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6781. }
  6782. };
  6783. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6784. if (oldProps !== newProps) {
  6785. for (const key in newProps) {
  6786. // empty string is not valid prop
  6787. if (isReservedProp(key))
  6788. continue;
  6789. const next = newProps[key];
  6790. const prev = oldProps[key];
  6791. // defer patching value
  6792. if (next !== prev && key !== 'value') {
  6793. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6794. }
  6795. }
  6796. if (oldProps !== EMPTY_OBJ) {
  6797. for (const key in oldProps) {
  6798. if (!isReservedProp(key) && !(key in newProps)) {
  6799. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6800. }
  6801. }
  6802. }
  6803. if ('value' in newProps) {
  6804. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6805. }
  6806. }
  6807. };
  6808. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6809. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6810. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6811. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6812. if (// #5523 dev root fragment may inherit directives
  6813. (isHmrUpdating || patchFlag & 2048 /* DEV_ROOT_FRAGMENT */)) {
  6814. // HMR updated / Dev root fragment (w/ comments), force full diff
  6815. patchFlag = 0;
  6816. optimized = false;
  6817. dynamicChildren = null;
  6818. }
  6819. // check if this is a slot fragment with :slotted scope ids
  6820. if (fragmentSlotScopeIds) {
  6821. slotScopeIds = slotScopeIds
  6822. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6823. : fragmentSlotScopeIds;
  6824. }
  6825. if (n1 == null) {
  6826. hostInsert(fragmentStartAnchor, container, anchor);
  6827. hostInsert(fragmentEndAnchor, container, anchor);
  6828. // a fragment can only have array children
  6829. // since they are either generated by the compiler, or implicitly created
  6830. // from arrays.
  6831. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6832. }
  6833. else {
  6834. if (patchFlag > 0 &&
  6835. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  6836. dynamicChildren &&
  6837. // #2715 the previous fragment could've been a BAILed one as a result
  6838. // of renderSlot() with no valid children
  6839. n1.dynamicChildren) {
  6840. // a stable fragment (template root or <template v-for>) doesn't need to
  6841. // patch children order, but it may contain dynamicChildren.
  6842. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6843. if (parentComponent && parentComponent.type.__hmrId) {
  6844. traverseStaticChildren(n1, n2);
  6845. }
  6846. else if (
  6847. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6848. // get moved around. Make sure all root level vnodes inherit el.
  6849. // #2134 or if it's a component root, it may also get moved around
  6850. // as the component is being moved.
  6851. n2.key != null ||
  6852. (parentComponent && n2 === parentComponent.subTree)) {
  6853. traverseStaticChildren(n1, n2, true /* shallow */);
  6854. }
  6855. }
  6856. else {
  6857. // keyed / unkeyed, or manual fragments.
  6858. // for keyed & unkeyed, since they are compiler generated from v-for,
  6859. // each child is guaranteed to be a block so the fragment will never
  6860. // have dynamicChildren.
  6861. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6862. }
  6863. }
  6864. };
  6865. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6866. n2.slotScopeIds = slotScopeIds;
  6867. if (n1 == null) {
  6868. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  6869. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6870. }
  6871. else {
  6872. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6873. }
  6874. }
  6875. else {
  6876. updateComponent(n1, n2, optimized);
  6877. }
  6878. };
  6879. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6880. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6881. if (instance.type.__hmrId) {
  6882. registerHMR(instance);
  6883. }
  6884. {
  6885. pushWarningContext(initialVNode);
  6886. startMeasure(instance, `mount`);
  6887. }
  6888. // inject renderer internals for keepAlive
  6889. if (isKeepAlive(initialVNode)) {
  6890. instance.ctx.renderer = internals;
  6891. }
  6892. // resolve props and slots for setup context
  6893. {
  6894. {
  6895. startMeasure(instance, `init`);
  6896. }
  6897. setupComponent(instance);
  6898. {
  6899. endMeasure(instance, `init`);
  6900. }
  6901. }
  6902. // setup() is async. This component relies on async logic to be resolved
  6903. // before proceeding
  6904. if (instance.asyncDep) {
  6905. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6906. // Give it a placeholder if this is not hydration
  6907. // TODO handle self-defined fallback
  6908. if (!initialVNode.el) {
  6909. const placeholder = (instance.subTree = createVNode(Comment));
  6910. processCommentNode(null, placeholder, container, anchor);
  6911. }
  6912. return;
  6913. }
  6914. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6915. {
  6916. popWarningContext();
  6917. endMeasure(instance, `mount`);
  6918. }
  6919. };
  6920. const updateComponent = (n1, n2, optimized) => {
  6921. const instance = (n2.component = n1.component);
  6922. if (shouldUpdateComponent(n1, n2, optimized)) {
  6923. if (instance.asyncDep &&
  6924. !instance.asyncResolved) {
  6925. // async & still pending - just update props and slots
  6926. // since the component's reactive effect for render isn't set-up yet
  6927. {
  6928. pushWarningContext(n2);
  6929. }
  6930. updateComponentPreRender(instance, n2, optimized);
  6931. {
  6932. popWarningContext();
  6933. }
  6934. return;
  6935. }
  6936. else {
  6937. // normal update
  6938. instance.next = n2;
  6939. // in case the child component is also queued, remove it to avoid
  6940. // double updating the same child component in the same flush.
  6941. invalidateJob(instance.update);
  6942. // instance.update is the reactive effect.
  6943. instance.update();
  6944. }
  6945. }
  6946. else {
  6947. // no update needed. just copy over properties
  6948. n2.el = n1.el;
  6949. instance.vnode = n2;
  6950. }
  6951. };
  6952. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6953. const componentUpdateFn = () => {
  6954. if (!instance.isMounted) {
  6955. let vnodeHook;
  6956. const { el, props } = initialVNode;
  6957. const { bm, m, parent } = instance;
  6958. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6959. toggleRecurse(instance, false);
  6960. // beforeMount hook
  6961. if (bm) {
  6962. invokeArrayFns(bm);
  6963. }
  6964. // onVnodeBeforeMount
  6965. if (!isAsyncWrapperVNode &&
  6966. (vnodeHook = props && props.onVnodeBeforeMount)) {
  6967. invokeVNodeHook(vnodeHook, parent, initialVNode);
  6968. }
  6969. toggleRecurse(instance, true);
  6970. if (el && hydrateNode) {
  6971. // vnode has adopted host node - perform hydration instead of mount.
  6972. const hydrateSubTree = () => {
  6973. {
  6974. startMeasure(instance, `render`);
  6975. }
  6976. instance.subTree = renderComponentRoot(instance);
  6977. {
  6978. endMeasure(instance, `render`);
  6979. }
  6980. {
  6981. startMeasure(instance, `hydrate`);
  6982. }
  6983. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  6984. {
  6985. endMeasure(instance, `hydrate`);
  6986. }
  6987. };
  6988. if (isAsyncWrapperVNode) {
  6989. initialVNode.type.__asyncLoader().then(
  6990. // note: we are moving the render call into an async callback,
  6991. // which means it won't track dependencies - but it's ok because
  6992. // a server-rendered async wrapper is already in resolved state
  6993. // and it will never need to change.
  6994. () => !instance.isUnmounted && hydrateSubTree());
  6995. }
  6996. else {
  6997. hydrateSubTree();
  6998. }
  6999. }
  7000. else {
  7001. {
  7002. startMeasure(instance, `render`);
  7003. }
  7004. const subTree = (instance.subTree = renderComponentRoot(instance));
  7005. {
  7006. endMeasure(instance, `render`);
  7007. }
  7008. {
  7009. startMeasure(instance, `patch`);
  7010. }
  7011. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  7012. {
  7013. endMeasure(instance, `patch`);
  7014. }
  7015. initialVNode.el = subTree.el;
  7016. }
  7017. // mounted hook
  7018. if (m) {
  7019. queuePostRenderEffect(m, parentSuspense);
  7020. }
  7021. // onVnodeMounted
  7022. if (!isAsyncWrapperVNode &&
  7023. (vnodeHook = props && props.onVnodeMounted)) {
  7024. const scopedInitialVNode = initialVNode;
  7025. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  7026. }
  7027. // activated hook for keep-alive roots.
  7028. // #1742 activated hook must be accessed after first render
  7029. // since the hook may be injected by a child keep-alive
  7030. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */ ||
  7031. (parent &&
  7032. isAsyncWrapper(parent.vnode) &&
  7033. parent.vnode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */)) {
  7034. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  7035. }
  7036. instance.isMounted = true;
  7037. {
  7038. devtoolsComponentAdded(instance);
  7039. }
  7040. // #2458: deference mount-only object parameters to prevent memleaks
  7041. initialVNode = container = anchor = null;
  7042. }
  7043. else {
  7044. // updateComponent
  7045. // This is triggered by mutation of component's own state (next: null)
  7046. // OR parent calling processComponent (next: VNode)
  7047. let { next, bu, u, parent, vnode } = instance;
  7048. let originNext = next;
  7049. let vnodeHook;
  7050. {
  7051. pushWarningContext(next || instance.vnode);
  7052. }
  7053. // Disallow component effect recursion during pre-lifecycle hooks.
  7054. toggleRecurse(instance, false);
  7055. if (next) {
  7056. next.el = vnode.el;
  7057. updateComponentPreRender(instance, next, optimized);
  7058. }
  7059. else {
  7060. next = vnode;
  7061. }
  7062. // beforeUpdate hook
  7063. if (bu) {
  7064. invokeArrayFns(bu);
  7065. }
  7066. // onVnodeBeforeUpdate
  7067. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  7068. invokeVNodeHook(vnodeHook, parent, next, vnode);
  7069. }
  7070. toggleRecurse(instance, true);
  7071. // render
  7072. {
  7073. startMeasure(instance, `render`);
  7074. }
  7075. const nextTree = renderComponentRoot(instance);
  7076. {
  7077. endMeasure(instance, `render`);
  7078. }
  7079. const prevTree = instance.subTree;
  7080. instance.subTree = nextTree;
  7081. {
  7082. startMeasure(instance, `patch`);
  7083. }
  7084. patch(prevTree, nextTree,
  7085. // parent may have changed if it's in a teleport
  7086. hostParentNode(prevTree.el),
  7087. // anchor may have changed if it's in a fragment
  7088. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  7089. {
  7090. endMeasure(instance, `patch`);
  7091. }
  7092. next.el = nextTree.el;
  7093. if (originNext === null) {
  7094. // self-triggered update. In case of HOC, update parent component
  7095. // vnode el. HOC is indicated by parent instance's subTree pointing
  7096. // to child component's vnode
  7097. updateHOCHostEl(instance, nextTree.el);
  7098. }
  7099. // updated hook
  7100. if (u) {
  7101. queuePostRenderEffect(u, parentSuspense);
  7102. }
  7103. // onVnodeUpdated
  7104. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  7105. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  7106. }
  7107. {
  7108. devtoolsComponentUpdated(instance);
  7109. }
  7110. {
  7111. popWarningContext();
  7112. }
  7113. }
  7114. };
  7115. // create reactive effect for rendering
  7116. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  7117. ));
  7118. const update = (instance.update = () => effect.run());
  7119. update.id = instance.uid;
  7120. // allowRecurse
  7121. // #1801, #2043 component render effects should allow recursive updates
  7122. toggleRecurse(instance, true);
  7123. {
  7124. effect.onTrack = instance.rtc
  7125. ? e => invokeArrayFns(instance.rtc, e)
  7126. : void 0;
  7127. effect.onTrigger = instance.rtg
  7128. ? e => invokeArrayFns(instance.rtg, e)
  7129. : void 0;
  7130. update.ownerInstance = instance;
  7131. }
  7132. update();
  7133. };
  7134. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  7135. nextVNode.component = instance;
  7136. const prevProps = instance.vnode.props;
  7137. instance.vnode = nextVNode;
  7138. instance.next = null;
  7139. updateProps(instance, nextVNode.props, prevProps, optimized);
  7140. updateSlots(instance, nextVNode.children, optimized);
  7141. pauseTracking();
  7142. // props update may have triggered pre-flush watchers.
  7143. // flush them before the render update.
  7144. flushPreFlushCbs(undefined, instance.update);
  7145. resetTracking();
  7146. };
  7147. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  7148. const c1 = n1 && n1.children;
  7149. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  7150. const c2 = n2.children;
  7151. const { patchFlag, shapeFlag } = n2;
  7152. // fast path
  7153. if (patchFlag > 0) {
  7154. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  7155. // this could be either fully-keyed or mixed (some keyed some not)
  7156. // presence of patchFlag means children are guaranteed to be arrays
  7157. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7158. return;
  7159. }
  7160. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  7161. // unkeyed
  7162. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7163. return;
  7164. }
  7165. }
  7166. // children has 3 possibilities: text, array or no children.
  7167. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  7168. // text children fast path
  7169. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  7170. unmountChildren(c1, parentComponent, parentSuspense);
  7171. }
  7172. if (c2 !== c1) {
  7173. hostSetElementText(container, c2);
  7174. }
  7175. }
  7176. else {
  7177. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  7178. // prev children was array
  7179. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7180. // two arrays, cannot assume anything, do full diff
  7181. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7182. }
  7183. else {
  7184. // no new children, just unmount old
  7185. unmountChildren(c1, parentComponent, parentSuspense, true);
  7186. }
  7187. }
  7188. else {
  7189. // prev children was text OR null
  7190. // new children is array OR null
  7191. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  7192. hostSetElementText(container, '');
  7193. }
  7194. // mount new if array
  7195. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7196. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7197. }
  7198. }
  7199. }
  7200. };
  7201. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7202. c1 = c1 || EMPTY_ARR;
  7203. c2 = c2 || EMPTY_ARR;
  7204. const oldLength = c1.length;
  7205. const newLength = c2.length;
  7206. const commonLength = Math.min(oldLength, newLength);
  7207. let i;
  7208. for (i = 0; i < commonLength; i++) {
  7209. const nextChild = (c2[i] = optimized
  7210. ? cloneIfMounted(c2[i])
  7211. : normalizeVNode(c2[i]));
  7212. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7213. }
  7214. if (oldLength > newLength) {
  7215. // remove old
  7216. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  7217. }
  7218. else {
  7219. // mount new
  7220. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  7221. }
  7222. };
  7223. // can be all-keyed or mixed
  7224. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7225. let i = 0;
  7226. const l2 = c2.length;
  7227. let e1 = c1.length - 1; // prev ending index
  7228. let e2 = l2 - 1; // next ending index
  7229. // 1. sync from start
  7230. // (a b) c
  7231. // (a b) d e
  7232. while (i <= e1 && i <= e2) {
  7233. const n1 = c1[i];
  7234. const n2 = (c2[i] = optimized
  7235. ? cloneIfMounted(c2[i])
  7236. : normalizeVNode(c2[i]));
  7237. if (isSameVNodeType(n1, n2)) {
  7238. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7239. }
  7240. else {
  7241. break;
  7242. }
  7243. i++;
  7244. }
  7245. // 2. sync from end
  7246. // a (b c)
  7247. // d e (b c)
  7248. while (i <= e1 && i <= e2) {
  7249. const n1 = c1[e1];
  7250. const n2 = (c2[e2] = optimized
  7251. ? cloneIfMounted(c2[e2])
  7252. : normalizeVNode(c2[e2]));
  7253. if (isSameVNodeType(n1, n2)) {
  7254. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7255. }
  7256. else {
  7257. break;
  7258. }
  7259. e1--;
  7260. e2--;
  7261. }
  7262. // 3. common sequence + mount
  7263. // (a b)
  7264. // (a b) c
  7265. // i = 2, e1 = 1, e2 = 2
  7266. // (a b)
  7267. // c (a b)
  7268. // i = 0, e1 = -1, e2 = 0
  7269. if (i > e1) {
  7270. if (i <= e2) {
  7271. const nextPos = e2 + 1;
  7272. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  7273. while (i <= e2) {
  7274. patch(null, (c2[i] = optimized
  7275. ? cloneIfMounted(c2[i])
  7276. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7277. i++;
  7278. }
  7279. }
  7280. }
  7281. // 4. common sequence + unmount
  7282. // (a b) c
  7283. // (a b)
  7284. // i = 2, e1 = 2, e2 = 1
  7285. // a (b c)
  7286. // (b c)
  7287. // i = 0, e1 = 0, e2 = -1
  7288. else if (i > e2) {
  7289. while (i <= e1) {
  7290. unmount(c1[i], parentComponent, parentSuspense, true);
  7291. i++;
  7292. }
  7293. }
  7294. // 5. unknown sequence
  7295. // [i ... e1 + 1]: a b [c d e] f g
  7296. // [i ... e2 + 1]: a b [e d c h] f g
  7297. // i = 2, e1 = 4, e2 = 5
  7298. else {
  7299. const s1 = i; // prev starting index
  7300. const s2 = i; // next starting index
  7301. // 5.1 build key:index map for newChildren
  7302. const keyToNewIndexMap = new Map();
  7303. for (i = s2; i <= e2; i++) {
  7304. const nextChild = (c2[i] = optimized
  7305. ? cloneIfMounted(c2[i])
  7306. : normalizeVNode(c2[i]));
  7307. if (nextChild.key != null) {
  7308. if (keyToNewIndexMap.has(nextChild.key)) {
  7309. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  7310. }
  7311. keyToNewIndexMap.set(nextChild.key, i);
  7312. }
  7313. }
  7314. // 5.2 loop through old children left to be patched and try to patch
  7315. // matching nodes & remove nodes that are no longer present
  7316. let j;
  7317. let patched = 0;
  7318. const toBePatched = e2 - s2 + 1;
  7319. let moved = false;
  7320. // used to track whether any node has moved
  7321. let maxNewIndexSoFar = 0;
  7322. // works as Map<newIndex, oldIndex>
  7323. // Note that oldIndex is offset by +1
  7324. // and oldIndex = 0 is a special value indicating the new node has
  7325. // no corresponding old node.
  7326. // used for determining longest stable subsequence
  7327. const newIndexToOldIndexMap = new Array(toBePatched);
  7328. for (i = 0; i < toBePatched; i++)
  7329. newIndexToOldIndexMap[i] = 0;
  7330. for (i = s1; i <= e1; i++) {
  7331. const prevChild = c1[i];
  7332. if (patched >= toBePatched) {
  7333. // all new children have been patched so this can only be a removal
  7334. unmount(prevChild, parentComponent, parentSuspense, true);
  7335. continue;
  7336. }
  7337. let newIndex;
  7338. if (prevChild.key != null) {
  7339. newIndex = keyToNewIndexMap.get(prevChild.key);
  7340. }
  7341. else {
  7342. // key-less node, try to locate a key-less node of the same type
  7343. for (j = s2; j <= e2; j++) {
  7344. if (newIndexToOldIndexMap[j - s2] === 0 &&
  7345. isSameVNodeType(prevChild, c2[j])) {
  7346. newIndex = j;
  7347. break;
  7348. }
  7349. }
  7350. }
  7351. if (newIndex === undefined) {
  7352. unmount(prevChild, parentComponent, parentSuspense, true);
  7353. }
  7354. else {
  7355. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  7356. if (newIndex >= maxNewIndexSoFar) {
  7357. maxNewIndexSoFar = newIndex;
  7358. }
  7359. else {
  7360. moved = true;
  7361. }
  7362. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7363. patched++;
  7364. }
  7365. }
  7366. // 5.3 move and mount
  7367. // generate longest stable subsequence only when nodes have moved
  7368. const increasingNewIndexSequence = moved
  7369. ? getSequence(newIndexToOldIndexMap)
  7370. : EMPTY_ARR;
  7371. j = increasingNewIndexSequence.length - 1;
  7372. // looping backwards so that we can use last patched node as anchor
  7373. for (i = toBePatched - 1; i >= 0; i--) {
  7374. const nextIndex = s2 + i;
  7375. const nextChild = c2[nextIndex];
  7376. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  7377. if (newIndexToOldIndexMap[i] === 0) {
  7378. // mount new
  7379. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7380. }
  7381. else if (moved) {
  7382. // move if:
  7383. // There is no stable subsequence (e.g. a reverse)
  7384. // OR current node is not among the stable sequence
  7385. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  7386. move(nextChild, container, anchor, 2 /* REORDER */);
  7387. }
  7388. else {
  7389. j--;
  7390. }
  7391. }
  7392. }
  7393. }
  7394. };
  7395. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  7396. const { el, type, transition, children, shapeFlag } = vnode;
  7397. if (shapeFlag & 6 /* COMPONENT */) {
  7398. move(vnode.component.subTree, container, anchor, moveType);
  7399. return;
  7400. }
  7401. if (shapeFlag & 128 /* SUSPENSE */) {
  7402. vnode.suspense.move(container, anchor, moveType);
  7403. return;
  7404. }
  7405. if (shapeFlag & 64 /* TELEPORT */) {
  7406. type.move(vnode, container, anchor, internals);
  7407. return;
  7408. }
  7409. if (type === Fragment) {
  7410. hostInsert(el, container, anchor);
  7411. for (let i = 0; i < children.length; i++) {
  7412. move(children[i], container, anchor, moveType);
  7413. }
  7414. hostInsert(vnode.anchor, container, anchor);
  7415. return;
  7416. }
  7417. if (type === Static) {
  7418. moveStaticNode(vnode, container, anchor);
  7419. return;
  7420. }
  7421. // single nodes
  7422. const needTransition = moveType !== 2 /* REORDER */ &&
  7423. shapeFlag & 1 /* ELEMENT */ &&
  7424. transition;
  7425. if (needTransition) {
  7426. if (moveType === 0 /* ENTER */) {
  7427. transition.beforeEnter(el);
  7428. hostInsert(el, container, anchor);
  7429. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  7430. }
  7431. else {
  7432. const { leave, delayLeave, afterLeave } = transition;
  7433. const remove = () => hostInsert(el, container, anchor);
  7434. const performLeave = () => {
  7435. leave(el, () => {
  7436. remove();
  7437. afterLeave && afterLeave();
  7438. });
  7439. };
  7440. if (delayLeave) {
  7441. delayLeave(el, remove, performLeave);
  7442. }
  7443. else {
  7444. performLeave();
  7445. }
  7446. }
  7447. }
  7448. else {
  7449. hostInsert(el, container, anchor);
  7450. }
  7451. };
  7452. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  7453. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  7454. // unset ref
  7455. if (ref != null) {
  7456. setRef(ref, null, parentSuspense, vnode, true);
  7457. }
  7458. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  7459. parentComponent.ctx.deactivate(vnode);
  7460. return;
  7461. }
  7462. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  7463. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  7464. let vnodeHook;
  7465. if (shouldInvokeVnodeHook &&
  7466. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  7467. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7468. }
  7469. if (shapeFlag & 6 /* COMPONENT */) {
  7470. unmountComponent(vnode.component, parentSuspense, doRemove);
  7471. }
  7472. else {
  7473. if (shapeFlag & 128 /* SUSPENSE */) {
  7474. vnode.suspense.unmount(parentSuspense, doRemove);
  7475. return;
  7476. }
  7477. if (shouldInvokeDirs) {
  7478. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  7479. }
  7480. if (shapeFlag & 64 /* TELEPORT */) {
  7481. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  7482. }
  7483. else if (dynamicChildren &&
  7484. // #1153: fast path should not be taken for non-stable (v-for) fragments
  7485. (type !== Fragment ||
  7486. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  7487. // fast path for block nodes: only need to unmount dynamic children.
  7488. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  7489. }
  7490. else if ((type === Fragment &&
  7491. patchFlag &
  7492. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  7493. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  7494. unmountChildren(children, parentComponent, parentSuspense);
  7495. }
  7496. if (doRemove) {
  7497. remove(vnode);
  7498. }
  7499. }
  7500. if ((shouldInvokeVnodeHook &&
  7501. (vnodeHook = props && props.onVnodeUnmounted)) ||
  7502. shouldInvokeDirs) {
  7503. queuePostRenderEffect(() => {
  7504. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7505. shouldInvokeDirs &&
  7506. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  7507. }, parentSuspense);
  7508. }
  7509. };
  7510. const remove = vnode => {
  7511. const { type, el, anchor, transition } = vnode;
  7512. if (type === Fragment) {
  7513. if (vnode.patchFlag > 0 &&
  7514. vnode.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */ &&
  7515. transition &&
  7516. !transition.persisted) {
  7517. vnode.children.forEach(child => {
  7518. if (child.type === Comment) {
  7519. hostRemove(child.el);
  7520. }
  7521. else {
  7522. remove(child);
  7523. }
  7524. });
  7525. }
  7526. else {
  7527. removeFragment(el, anchor);
  7528. }
  7529. return;
  7530. }
  7531. if (type === Static) {
  7532. removeStaticNode(vnode);
  7533. return;
  7534. }
  7535. const performRemove = () => {
  7536. hostRemove(el);
  7537. if (transition && !transition.persisted && transition.afterLeave) {
  7538. transition.afterLeave();
  7539. }
  7540. };
  7541. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  7542. transition &&
  7543. !transition.persisted) {
  7544. const { leave, delayLeave } = transition;
  7545. const performLeave = () => leave(el, performRemove);
  7546. if (delayLeave) {
  7547. delayLeave(vnode.el, performRemove, performLeave);
  7548. }
  7549. else {
  7550. performLeave();
  7551. }
  7552. }
  7553. else {
  7554. performRemove();
  7555. }
  7556. };
  7557. const removeFragment = (cur, end) => {
  7558. // For fragments, directly remove all contained DOM nodes.
  7559. // (fragment child nodes cannot have transition)
  7560. let next;
  7561. while (cur !== end) {
  7562. next = hostNextSibling(cur);
  7563. hostRemove(cur);
  7564. cur = next;
  7565. }
  7566. hostRemove(end);
  7567. };
  7568. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7569. if (instance.type.__hmrId) {
  7570. unregisterHMR(instance);
  7571. }
  7572. const { bum, scope, update, subTree, um } = instance;
  7573. // beforeUnmount hook
  7574. if (bum) {
  7575. invokeArrayFns(bum);
  7576. }
  7577. // stop effects in component scope
  7578. scope.stop();
  7579. // update may be null if a component is unmounted before its async
  7580. // setup has resolved.
  7581. if (update) {
  7582. // so that scheduler will no longer invoke it
  7583. update.active = false;
  7584. unmount(subTree, instance, parentSuspense, doRemove);
  7585. }
  7586. // unmounted hook
  7587. if (um) {
  7588. queuePostRenderEffect(um, parentSuspense);
  7589. }
  7590. queuePostRenderEffect(() => {
  7591. instance.isUnmounted = true;
  7592. }, parentSuspense);
  7593. // A component with async dep inside a pending suspense is unmounted before
  7594. // its async dep resolves. This should remove the dep from the suspense, and
  7595. // cause the suspense to resolve immediately if that was the last dep.
  7596. if (parentSuspense &&
  7597. parentSuspense.pendingBranch &&
  7598. !parentSuspense.isUnmounted &&
  7599. instance.asyncDep &&
  7600. !instance.asyncResolved &&
  7601. instance.suspenseId === parentSuspense.pendingId) {
  7602. parentSuspense.deps--;
  7603. if (parentSuspense.deps === 0) {
  7604. parentSuspense.resolve();
  7605. }
  7606. }
  7607. {
  7608. devtoolsComponentRemoved(instance);
  7609. }
  7610. };
  7611. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7612. for (let i = start; i < children.length; i++) {
  7613. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7614. }
  7615. };
  7616. const getNextHostNode = vnode => {
  7617. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  7618. return getNextHostNode(vnode.component.subTree);
  7619. }
  7620. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  7621. return vnode.suspense.next();
  7622. }
  7623. return hostNextSibling((vnode.anchor || vnode.el));
  7624. };
  7625. const render = (vnode, container, isSVG) => {
  7626. if (vnode == null) {
  7627. if (container._vnode) {
  7628. unmount(container._vnode, null, null, true);
  7629. }
  7630. }
  7631. else {
  7632. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7633. }
  7634. flushPostFlushCbs();
  7635. container._vnode = vnode;
  7636. };
  7637. const internals = {
  7638. p: patch,
  7639. um: unmount,
  7640. m: move,
  7641. r: remove,
  7642. mt: mountComponent,
  7643. mc: mountChildren,
  7644. pc: patchChildren,
  7645. pbc: patchBlockChildren,
  7646. n: getNextHostNode,
  7647. o: options
  7648. };
  7649. let hydrate;
  7650. let hydrateNode;
  7651. if (createHydrationFns) {
  7652. [hydrate, hydrateNode] = createHydrationFns(internals);
  7653. }
  7654. return {
  7655. render,
  7656. hydrate,
  7657. createApp: createAppAPI(render, hydrate)
  7658. };
  7659. }
  7660. function toggleRecurse({ effect, update }, allowed) {
  7661. effect.allowRecurse = update.allowRecurse = allowed;
  7662. }
  7663. /**
  7664. * #1156
  7665. * When a component is HMR-enabled, we need to make sure that all static nodes
  7666. * inside a block also inherit the DOM element from the previous tree so that
  7667. * HMR updates (which are full updates) can retrieve the element for patching.
  7668. *
  7669. * #2080
  7670. * Inside keyed `template` fragment static children, if a fragment is moved,
  7671. * the children will always be moved. Therefore, in order to ensure correct move
  7672. * position, el should be inherited from previous nodes.
  7673. */
  7674. function traverseStaticChildren(n1, n2, shallow = false) {
  7675. const ch1 = n1.children;
  7676. const ch2 = n2.children;
  7677. if (isArray(ch1) && isArray(ch2)) {
  7678. for (let i = 0; i < ch1.length; i++) {
  7679. // this is only called in the optimized path so array children are
  7680. // guaranteed to be vnodes
  7681. const c1 = ch1[i];
  7682. let c2 = ch2[i];
  7683. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  7684. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  7685. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7686. c2.el = c1.el;
  7687. }
  7688. if (!shallow)
  7689. traverseStaticChildren(c1, c2);
  7690. }
  7691. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7692. // would have received .el during block patch)
  7693. if (c2.type === Comment && !c2.el) {
  7694. c2.el = c1.el;
  7695. }
  7696. }
  7697. }
  7698. }
  7699. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7700. function getSequence(arr) {
  7701. const p = arr.slice();
  7702. const result = [0];
  7703. let i, j, u, v, c;
  7704. const len = arr.length;
  7705. for (i = 0; i < len; i++) {
  7706. const arrI = arr[i];
  7707. if (arrI !== 0) {
  7708. j = result[result.length - 1];
  7709. if (arr[j] < arrI) {
  7710. p[i] = j;
  7711. result.push(i);
  7712. continue;
  7713. }
  7714. u = 0;
  7715. v = result.length - 1;
  7716. while (u < v) {
  7717. c = (u + v) >> 1;
  7718. if (arr[result[c]] < arrI) {
  7719. u = c + 1;
  7720. }
  7721. else {
  7722. v = c;
  7723. }
  7724. }
  7725. if (arrI < arr[result[u]]) {
  7726. if (u > 0) {
  7727. p[i] = result[u - 1];
  7728. }
  7729. result[u] = i;
  7730. }
  7731. }
  7732. }
  7733. u = result.length;
  7734. v = result[u - 1];
  7735. while (u-- > 0) {
  7736. result[u] = v;
  7737. v = p[v];
  7738. }
  7739. return result;
  7740. }
  7741. const isTeleport = (type) => type.__isTeleport;
  7742. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7743. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7744. const resolveTarget = (props, select) => {
  7745. const targetSelector = props && props.to;
  7746. if (isString(targetSelector)) {
  7747. if (!select) {
  7748. warn$1(`Current renderer does not support string target for Teleports. ` +
  7749. `(missing querySelector renderer option)`);
  7750. return null;
  7751. }
  7752. else {
  7753. const target = select(targetSelector);
  7754. if (!target) {
  7755. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7756. `Note the target element must exist before the component is mounted - ` +
  7757. `i.e. the target cannot be rendered by the component itself, and ` +
  7758. `ideally should be outside of the entire Vue component tree.`);
  7759. }
  7760. return target;
  7761. }
  7762. }
  7763. else {
  7764. if (!targetSelector && !isTeleportDisabled(props)) {
  7765. warn$1(`Invalid Teleport target: ${targetSelector}`);
  7766. }
  7767. return targetSelector;
  7768. }
  7769. };
  7770. const TeleportImpl = {
  7771. __isTeleport: true,
  7772. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7773. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7774. const disabled = isTeleportDisabled(n2.props);
  7775. let { shapeFlag, children, dynamicChildren } = n2;
  7776. // #3302
  7777. // HMR updated, force full diff
  7778. if (isHmrUpdating) {
  7779. optimized = false;
  7780. dynamicChildren = null;
  7781. }
  7782. if (n1 == null) {
  7783. // insert anchors in the main view
  7784. const placeholder = (n2.el = createComment('teleport start')
  7785. );
  7786. const mainAnchor = (n2.anchor = createComment('teleport end')
  7787. );
  7788. insert(placeholder, container, anchor);
  7789. insert(mainAnchor, container, anchor);
  7790. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7791. const targetAnchor = (n2.targetAnchor = createText(''));
  7792. if (target) {
  7793. insert(targetAnchor, target);
  7794. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7795. isSVG = isSVG || isTargetSVG(target);
  7796. }
  7797. else if (!disabled) {
  7798. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7799. }
  7800. const mount = (container, anchor) => {
  7801. // Teleport *always* has Array children. This is enforced in both the
  7802. // compiler and vnode children normalization.
  7803. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7804. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7805. }
  7806. };
  7807. if (disabled) {
  7808. mount(container, mainAnchor);
  7809. }
  7810. else if (target) {
  7811. mount(target, targetAnchor);
  7812. }
  7813. }
  7814. else {
  7815. // update content
  7816. n2.el = n1.el;
  7817. const mainAnchor = (n2.anchor = n1.anchor);
  7818. const target = (n2.target = n1.target);
  7819. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7820. const wasDisabled = isTeleportDisabled(n1.props);
  7821. const currentContainer = wasDisabled ? container : target;
  7822. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7823. isSVG = isSVG || isTargetSVG(target);
  7824. if (dynamicChildren) {
  7825. // fast path when the teleport happens to be a block root
  7826. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7827. // even in block tree mode we need to make sure all root-level nodes
  7828. // in the teleport inherit previous DOM references so that they can
  7829. // be moved in future patches.
  7830. traverseStaticChildren(n1, n2, true);
  7831. }
  7832. else if (!optimized) {
  7833. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7834. }
  7835. if (disabled) {
  7836. if (!wasDisabled) {
  7837. // enabled -> disabled
  7838. // move into main container
  7839. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  7840. }
  7841. }
  7842. else {
  7843. // target changed
  7844. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7845. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7846. if (nextTarget) {
  7847. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  7848. }
  7849. else {
  7850. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  7851. }
  7852. }
  7853. else if (wasDisabled) {
  7854. // disabled -> enabled
  7855. // move into teleport target
  7856. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  7857. }
  7858. }
  7859. }
  7860. },
  7861. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7862. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7863. if (target) {
  7864. hostRemove(targetAnchor);
  7865. }
  7866. // an unmounted teleport should always remove its children if not disabled
  7867. if (doRemove || !isTeleportDisabled(props)) {
  7868. hostRemove(anchor);
  7869. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7870. for (let i = 0; i < children.length; i++) {
  7871. const child = children[i];
  7872. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7873. }
  7874. }
  7875. }
  7876. },
  7877. move: moveTeleport,
  7878. hydrate: hydrateTeleport
  7879. };
  7880. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  7881. // move target anchor if this is a target change.
  7882. if (moveType === 0 /* TARGET_CHANGE */) {
  7883. insert(vnode.targetAnchor, container, parentAnchor);
  7884. }
  7885. const { el, anchor, shapeFlag, children, props } = vnode;
  7886. const isReorder = moveType === 2 /* REORDER */;
  7887. // move main view anchor if this is a re-order.
  7888. if (isReorder) {
  7889. insert(el, container, parentAnchor);
  7890. }
  7891. // if this is a re-order and teleport is enabled (content is in target)
  7892. // do not move children. So the opposite is: only move children if this
  7893. // is not a reorder, or the teleport is disabled
  7894. if (!isReorder || isTeleportDisabled(props)) {
  7895. // Teleport has either Array children or no children.
  7896. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7897. for (let i = 0; i < children.length; i++) {
  7898. move(children[i], container, parentAnchor, 2 /* REORDER */);
  7899. }
  7900. }
  7901. }
  7902. // move main view anchor if this is a re-order.
  7903. if (isReorder) {
  7904. insert(anchor, container, parentAnchor);
  7905. }
  7906. }
  7907. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7908. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7909. if (target) {
  7910. // if multiple teleports rendered to the same target element, we need to
  7911. // pick up from where the last teleport finished instead of the first node
  7912. const targetNode = target._lpa || target.firstChild;
  7913. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7914. if (isTeleportDisabled(vnode.props)) {
  7915. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7916. vnode.targetAnchor = targetNode;
  7917. }
  7918. else {
  7919. vnode.anchor = nextSibling(node);
  7920. // lookahead until we find the target anchor
  7921. // we cannot rely on return value of hydrateChildren() because there
  7922. // could be nested teleports
  7923. let targetAnchor = targetNode;
  7924. while (targetAnchor) {
  7925. targetAnchor = nextSibling(targetAnchor);
  7926. if (targetAnchor &&
  7927. targetAnchor.nodeType === 8 &&
  7928. targetAnchor.data === 'teleport anchor') {
  7929. vnode.targetAnchor = targetAnchor;
  7930. target._lpa =
  7931. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7932. break;
  7933. }
  7934. }
  7935. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7936. }
  7937. }
  7938. }
  7939. return vnode.anchor && nextSibling(vnode.anchor);
  7940. }
  7941. // Force-casted public typing for h and TSX props inference
  7942. const Teleport = TeleportImpl;
  7943. const Fragment = Symbol('Fragment' );
  7944. const Text = Symbol('Text' );
  7945. const Comment = Symbol('Comment' );
  7946. const Static = Symbol('Static' );
  7947. // Since v-if and v-for are the two possible ways node structure can dynamically
  7948. // change, once we consider v-if branches and each v-for fragment a block, we
  7949. // can divide a template into nested blocks, and within each block the node
  7950. // structure would be stable. This allows us to skip most children diffing
  7951. // and only worry about the dynamic nodes (indicated by patch flags).
  7952. const blockStack = [];
  7953. let currentBlock = null;
  7954. /**
  7955. * Open a block.
  7956. * This must be called before `createBlock`. It cannot be part of `createBlock`
  7957. * because the children of the block are evaluated before `createBlock` itself
  7958. * is called. The generated code typically looks like this:
  7959. *
  7960. * ```js
  7961. * function render() {
  7962. * return (openBlock(),createBlock('div', null, [...]))
  7963. * }
  7964. * ```
  7965. * disableTracking is true when creating a v-for fragment block, since a v-for
  7966. * fragment always diffs its children.
  7967. *
  7968. * @private
  7969. */
  7970. function openBlock(disableTracking = false) {
  7971. blockStack.push((currentBlock = disableTracking ? null : []));
  7972. }
  7973. function closeBlock() {
  7974. blockStack.pop();
  7975. currentBlock = blockStack[blockStack.length - 1] || null;
  7976. }
  7977. // Whether we should be tracking dynamic child nodes inside a block.
  7978. // Only tracks when this value is > 0
  7979. // We are not using a simple boolean because this value may need to be
  7980. // incremented/decremented by nested usage of v-once (see below)
  7981. let isBlockTreeEnabled = 1;
  7982. /**
  7983. * Block tracking sometimes needs to be disabled, for example during the
  7984. * creation of a tree that needs to be cached by v-once. The compiler generates
  7985. * code like this:
  7986. *
  7987. * ``` js
  7988. * _cache[1] || (
  7989. * setBlockTracking(-1),
  7990. * _cache[1] = createVNode(...),
  7991. * setBlockTracking(1),
  7992. * _cache[1]
  7993. * )
  7994. * ```
  7995. *
  7996. * @private
  7997. */
  7998. function setBlockTracking(value) {
  7999. isBlockTreeEnabled += value;
  8000. }
  8001. function setupBlock(vnode) {
  8002. // save current block children on the block vnode
  8003. vnode.dynamicChildren =
  8004. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  8005. // close block
  8006. closeBlock();
  8007. // a block is always going to be patched, so track it as a child of its
  8008. // parent block
  8009. if (isBlockTreeEnabled > 0 && currentBlock) {
  8010. currentBlock.push(vnode);
  8011. }
  8012. return vnode;
  8013. }
  8014. /**
  8015. * @private
  8016. */
  8017. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  8018. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  8019. }
  8020. /**
  8021. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  8022. * A block root keeps track of dynamic nodes within the block in the
  8023. * `dynamicChildren` array.
  8024. *
  8025. * @private
  8026. */
  8027. function createBlock(type, props, children, patchFlag, dynamicProps) {
  8028. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  8029. }
  8030. function isVNode(value) {
  8031. return value ? value.__v_isVNode === true : false;
  8032. }
  8033. function isSameVNodeType(n1, n2) {
  8034. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  8035. hmrDirtyComponents.has(n2.type)) {
  8036. // HMR only: if the component has been hot-updated, force a reload.
  8037. return false;
  8038. }
  8039. return n1.type === n2.type && n1.key === n2.key;
  8040. }
  8041. let vnodeArgsTransformer;
  8042. /**
  8043. * Internal API for registering an arguments transform for createVNode
  8044. * used for creating stubs in the test-utils
  8045. * It is *internal* but needs to be exposed for test-utils to pick up proper
  8046. * typings
  8047. */
  8048. function transformVNodeArgs(transformer) {
  8049. vnodeArgsTransformer = transformer;
  8050. }
  8051. const createVNodeWithArgsTransform = (...args) => {
  8052. return _createVNode(...(vnodeArgsTransformer
  8053. ? vnodeArgsTransformer(args, currentRenderingInstance)
  8054. : args));
  8055. };
  8056. const InternalObjectKey = `__vInternal`;
  8057. const normalizeKey = ({ key }) => key != null ? key : null;
  8058. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  8059. return (ref != null
  8060. ? isString(ref) || isRef(ref) || isFunction(ref)
  8061. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  8062. : ref
  8063. : null);
  8064. };
  8065. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  8066. const vnode = {
  8067. __v_isVNode: true,
  8068. __v_skip: true,
  8069. type,
  8070. props,
  8071. key: props && normalizeKey(props),
  8072. ref: props && normalizeRef(props),
  8073. scopeId: currentScopeId,
  8074. slotScopeIds: null,
  8075. children,
  8076. component: null,
  8077. suspense: null,
  8078. ssContent: null,
  8079. ssFallback: null,
  8080. dirs: null,
  8081. transition: null,
  8082. el: null,
  8083. anchor: null,
  8084. target: null,
  8085. targetAnchor: null,
  8086. staticCount: 0,
  8087. shapeFlag,
  8088. patchFlag,
  8089. dynamicProps,
  8090. dynamicChildren: null,
  8091. appContext: null
  8092. };
  8093. if (needFullChildrenNormalization) {
  8094. normalizeChildren(vnode, children);
  8095. // normalize suspense children
  8096. if (shapeFlag & 128 /* SUSPENSE */) {
  8097. type.normalize(vnode);
  8098. }
  8099. }
  8100. else if (children) {
  8101. // compiled element vnode - if children is passed, only possible types are
  8102. // string or Array.
  8103. vnode.shapeFlag |= isString(children)
  8104. ? 8 /* TEXT_CHILDREN */
  8105. : 16 /* ARRAY_CHILDREN */;
  8106. }
  8107. // validate key
  8108. if (vnode.key !== vnode.key) {
  8109. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  8110. }
  8111. // track vnode for block tree
  8112. if (isBlockTreeEnabled > 0 &&
  8113. // avoid a block node from tracking itself
  8114. !isBlockNode &&
  8115. // has current parent block
  8116. currentBlock &&
  8117. // presence of a patch flag indicates this node needs patching on updates.
  8118. // component nodes also should always be patched, because even if the
  8119. // component doesn't need to update, it needs to persist the instance on to
  8120. // the next vnode so that it can be properly unmounted later.
  8121. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  8122. // the EVENTS flag is only for hydration and if it is the only flag, the
  8123. // vnode should not be considered dynamic due to handler caching.
  8124. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  8125. currentBlock.push(vnode);
  8126. }
  8127. return vnode;
  8128. }
  8129. const createVNode = (createVNodeWithArgsTransform );
  8130. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  8131. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  8132. if (!type) {
  8133. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  8134. }
  8135. type = Comment;
  8136. }
  8137. if (isVNode(type)) {
  8138. // createVNode receiving an existing vnode. This happens in cases like
  8139. // <component :is="vnode"/>
  8140. // #2078 make sure to merge refs during the clone instead of overwriting it
  8141. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  8142. if (children) {
  8143. normalizeChildren(cloned, children);
  8144. }
  8145. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  8146. if (cloned.shapeFlag & 6 /* COMPONENT */) {
  8147. currentBlock[currentBlock.indexOf(type)] = cloned;
  8148. }
  8149. else {
  8150. currentBlock.push(cloned);
  8151. }
  8152. }
  8153. cloned.patchFlag |= -2 /* BAIL */;
  8154. return cloned;
  8155. }
  8156. // class component normalization.
  8157. if (isClassComponent(type)) {
  8158. type = type.__vccOpts;
  8159. }
  8160. // class & style normalization.
  8161. if (props) {
  8162. // for reactive or proxy objects, we need to clone it to enable mutation.
  8163. props = guardReactiveProps(props);
  8164. let { class: klass, style } = props;
  8165. if (klass && !isString(klass)) {
  8166. props.class = normalizeClass(klass);
  8167. }
  8168. if (isObject(style)) {
  8169. // reactive state objects need to be cloned since they are likely to be
  8170. // mutated
  8171. if (isProxy(style) && !isArray(style)) {
  8172. style = extend({}, style);
  8173. }
  8174. props.style = normalizeStyle(style);
  8175. }
  8176. }
  8177. // encode the vnode type information into a bitmap
  8178. const shapeFlag = isString(type)
  8179. ? 1 /* ELEMENT */
  8180. : isSuspense(type)
  8181. ? 128 /* SUSPENSE */
  8182. : isTeleport(type)
  8183. ? 64 /* TELEPORT */
  8184. : isObject(type)
  8185. ? 4 /* STATEFUL_COMPONENT */
  8186. : isFunction(type)
  8187. ? 2 /* FUNCTIONAL_COMPONENT */
  8188. : 0;
  8189. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  8190. type = toRaw(type);
  8191. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  8192. `lead to unnecessary performance overhead, and should be avoided by ` +
  8193. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  8194. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  8195. }
  8196. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  8197. }
  8198. function guardReactiveProps(props) {
  8199. if (!props)
  8200. return null;
  8201. return isProxy(props) || InternalObjectKey in props
  8202. ? extend({}, props)
  8203. : props;
  8204. }
  8205. function cloneVNode(vnode, extraProps, mergeRef = false) {
  8206. // This is intentionally NOT using spread or extend to avoid the runtime
  8207. // key enumeration cost.
  8208. const { props, ref, patchFlag, children } = vnode;
  8209. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  8210. const cloned = {
  8211. __v_isVNode: true,
  8212. __v_skip: true,
  8213. type: vnode.type,
  8214. props: mergedProps,
  8215. key: mergedProps && normalizeKey(mergedProps),
  8216. ref: extraProps && extraProps.ref
  8217. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  8218. // if the vnode itself already has a ref, cloneVNode will need to merge
  8219. // the refs so the single vnode can be set on multiple refs
  8220. mergeRef && ref
  8221. ? isArray(ref)
  8222. ? ref.concat(normalizeRef(extraProps))
  8223. : [ref, normalizeRef(extraProps)]
  8224. : normalizeRef(extraProps)
  8225. : ref,
  8226. scopeId: vnode.scopeId,
  8227. slotScopeIds: vnode.slotScopeIds,
  8228. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  8229. ? children.map(deepCloneVNode)
  8230. : children,
  8231. target: vnode.target,
  8232. targetAnchor: vnode.targetAnchor,
  8233. staticCount: vnode.staticCount,
  8234. shapeFlag: vnode.shapeFlag,
  8235. // if the vnode is cloned with extra props, we can no longer assume its
  8236. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  8237. // note: preserve flag for fragments since they use the flag for children
  8238. // fast paths only.
  8239. patchFlag: extraProps && vnode.type !== Fragment
  8240. ? patchFlag === -1 // hoisted node
  8241. ? 16 /* FULL_PROPS */
  8242. : patchFlag | 16 /* FULL_PROPS */
  8243. : patchFlag,
  8244. dynamicProps: vnode.dynamicProps,
  8245. dynamicChildren: vnode.dynamicChildren,
  8246. appContext: vnode.appContext,
  8247. dirs: vnode.dirs,
  8248. transition: vnode.transition,
  8249. // These should technically only be non-null on mounted VNodes. However,
  8250. // they *should* be copied for kept-alive vnodes. So we just always copy
  8251. // them since them being non-null during a mount doesn't affect the logic as
  8252. // they will simply be overwritten.
  8253. component: vnode.component,
  8254. suspense: vnode.suspense,
  8255. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  8256. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  8257. el: vnode.el,
  8258. anchor: vnode.anchor
  8259. };
  8260. return cloned;
  8261. }
  8262. /**
  8263. * Dev only, for HMR of hoisted vnodes reused in v-for
  8264. * https://github.com/vitejs/vite/issues/2022
  8265. */
  8266. function deepCloneVNode(vnode) {
  8267. const cloned = cloneVNode(vnode);
  8268. if (isArray(vnode.children)) {
  8269. cloned.children = vnode.children.map(deepCloneVNode);
  8270. }
  8271. return cloned;
  8272. }
  8273. /**
  8274. * @private
  8275. */
  8276. function createTextVNode(text = ' ', flag = 0) {
  8277. return createVNode(Text, null, text, flag);
  8278. }
  8279. /**
  8280. * @private
  8281. */
  8282. function createStaticVNode(content, numberOfNodes) {
  8283. // A static vnode can contain multiple stringified elements, and the number
  8284. // of elements is necessary for hydration.
  8285. const vnode = createVNode(Static, null, content);
  8286. vnode.staticCount = numberOfNodes;
  8287. return vnode;
  8288. }
  8289. /**
  8290. * @private
  8291. */
  8292. function createCommentVNode(text = '',
  8293. // when used as the v-else branch, the comment node must be created as a
  8294. // block to ensure correct updates.
  8295. asBlock = false) {
  8296. return asBlock
  8297. ? (openBlock(), createBlock(Comment, null, text))
  8298. : createVNode(Comment, null, text);
  8299. }
  8300. function normalizeVNode(child) {
  8301. if (child == null || typeof child === 'boolean') {
  8302. // empty placeholder
  8303. return createVNode(Comment);
  8304. }
  8305. else if (isArray(child)) {
  8306. // fragment
  8307. return createVNode(Fragment, null,
  8308. // #3666, avoid reference pollution when reusing vnode
  8309. child.slice());
  8310. }
  8311. else if (typeof child === 'object') {
  8312. // already vnode, this should be the most common since compiled templates
  8313. // always produce all-vnode children arrays
  8314. return cloneIfMounted(child);
  8315. }
  8316. else {
  8317. // strings and numbers
  8318. return createVNode(Text, null, String(child));
  8319. }
  8320. }
  8321. // optimized normalization for template-compiled render fns
  8322. function cloneIfMounted(child) {
  8323. return child.el === null || child.memo ? child : cloneVNode(child);
  8324. }
  8325. function normalizeChildren(vnode, children) {
  8326. let type = 0;
  8327. const { shapeFlag } = vnode;
  8328. if (children == null) {
  8329. children = null;
  8330. }
  8331. else if (isArray(children)) {
  8332. type = 16 /* ARRAY_CHILDREN */;
  8333. }
  8334. else if (typeof children === 'object') {
  8335. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  8336. // Normalize slot to plain children for plain element and Teleport
  8337. const slot = children.default;
  8338. if (slot) {
  8339. // _c marker is added by withCtx() indicating this is a compiled slot
  8340. slot._c && (slot._d = false);
  8341. normalizeChildren(vnode, slot());
  8342. slot._c && (slot._d = true);
  8343. }
  8344. return;
  8345. }
  8346. else {
  8347. type = 32 /* SLOTS_CHILDREN */;
  8348. const slotFlag = children._;
  8349. if (!slotFlag && !(InternalObjectKey in children)) {
  8350. children._ctx = currentRenderingInstance;
  8351. }
  8352. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  8353. // a child component receives forwarded slots from the parent.
  8354. // its slot type is determined by its parent's slot type.
  8355. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  8356. children._ = 1 /* STABLE */;
  8357. }
  8358. else {
  8359. children._ = 2 /* DYNAMIC */;
  8360. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  8361. }
  8362. }
  8363. }
  8364. }
  8365. else if (isFunction(children)) {
  8366. children = { default: children, _ctx: currentRenderingInstance };
  8367. type = 32 /* SLOTS_CHILDREN */;
  8368. }
  8369. else {
  8370. children = String(children);
  8371. // force teleport children to array so it can be moved around
  8372. if (shapeFlag & 64 /* TELEPORT */) {
  8373. type = 16 /* ARRAY_CHILDREN */;
  8374. children = [createTextVNode(children)];
  8375. }
  8376. else {
  8377. type = 8 /* TEXT_CHILDREN */;
  8378. }
  8379. }
  8380. vnode.children = children;
  8381. vnode.shapeFlag |= type;
  8382. }
  8383. function mergeProps(...args) {
  8384. const ret = {};
  8385. for (let i = 0; i < args.length; i++) {
  8386. const toMerge = args[i];
  8387. for (const key in toMerge) {
  8388. if (key === 'class') {
  8389. if (ret.class !== toMerge.class) {
  8390. ret.class = normalizeClass([ret.class, toMerge.class]);
  8391. }
  8392. }
  8393. else if (key === 'style') {
  8394. ret.style = normalizeStyle([ret.style, toMerge.style]);
  8395. }
  8396. else if (isOn(key)) {
  8397. const existing = ret[key];
  8398. const incoming = toMerge[key];
  8399. if (incoming &&
  8400. existing !== incoming &&
  8401. !(isArray(existing) && existing.includes(incoming))) {
  8402. ret[key] = existing
  8403. ? [].concat(existing, incoming)
  8404. : incoming;
  8405. }
  8406. }
  8407. else if (key !== '') {
  8408. ret[key] = toMerge[key];
  8409. }
  8410. }
  8411. }
  8412. return ret;
  8413. }
  8414. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  8415. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  8416. vnode,
  8417. prevVNode
  8418. ]);
  8419. }
  8420. const emptyAppContext = createAppContext();
  8421. let uid$1 = 0;
  8422. function createComponentInstance(vnode, parent, suspense) {
  8423. const type = vnode.type;
  8424. // inherit parent app context - or - if root, adopt from root vnode
  8425. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8426. const instance = {
  8427. uid: uid$1++,
  8428. vnode,
  8429. type,
  8430. parent,
  8431. appContext,
  8432. root: null,
  8433. next: null,
  8434. subTree: null,
  8435. effect: null,
  8436. update: null,
  8437. scope: new EffectScope(true /* detached */),
  8438. render: null,
  8439. proxy: null,
  8440. exposed: null,
  8441. exposeProxy: null,
  8442. withProxy: null,
  8443. provides: parent ? parent.provides : Object.create(appContext.provides),
  8444. accessCache: null,
  8445. renderCache: [],
  8446. // local resolved assets
  8447. components: null,
  8448. directives: null,
  8449. // resolved props and emits options
  8450. propsOptions: normalizePropsOptions(type, appContext),
  8451. emitsOptions: normalizeEmitsOptions(type, appContext),
  8452. // emit
  8453. emit: null,
  8454. emitted: null,
  8455. // props default value
  8456. propsDefaults: EMPTY_OBJ,
  8457. // inheritAttrs
  8458. inheritAttrs: type.inheritAttrs,
  8459. // state
  8460. ctx: EMPTY_OBJ,
  8461. data: EMPTY_OBJ,
  8462. props: EMPTY_OBJ,
  8463. attrs: EMPTY_OBJ,
  8464. slots: EMPTY_OBJ,
  8465. refs: EMPTY_OBJ,
  8466. setupState: EMPTY_OBJ,
  8467. setupContext: null,
  8468. // suspense related
  8469. suspense,
  8470. suspenseId: suspense ? suspense.pendingId : 0,
  8471. asyncDep: null,
  8472. asyncResolved: false,
  8473. // lifecycle hooks
  8474. // not using enums here because it results in computed properties
  8475. isMounted: false,
  8476. isUnmounted: false,
  8477. isDeactivated: false,
  8478. bc: null,
  8479. c: null,
  8480. bm: null,
  8481. m: null,
  8482. bu: null,
  8483. u: null,
  8484. um: null,
  8485. bum: null,
  8486. da: null,
  8487. a: null,
  8488. rtg: null,
  8489. rtc: null,
  8490. ec: null,
  8491. sp: null
  8492. };
  8493. {
  8494. instance.ctx = createDevRenderContext(instance);
  8495. }
  8496. instance.root = parent ? parent.root : instance;
  8497. instance.emit = emit$1.bind(null, instance);
  8498. // apply custom element special handling
  8499. if (vnode.ce) {
  8500. vnode.ce(instance);
  8501. }
  8502. return instance;
  8503. }
  8504. let currentInstance = null;
  8505. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8506. const setCurrentInstance = (instance) => {
  8507. currentInstance = instance;
  8508. instance.scope.on();
  8509. };
  8510. const unsetCurrentInstance = () => {
  8511. currentInstance && currentInstance.scope.off();
  8512. currentInstance = null;
  8513. };
  8514. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8515. function validateComponentName(name, config) {
  8516. const appIsNativeTag = config.isNativeTag || NO;
  8517. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8518. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  8519. }
  8520. }
  8521. function isStatefulComponent(instance) {
  8522. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  8523. }
  8524. let isInSSRComponentSetup = false;
  8525. function setupComponent(instance, isSSR = false) {
  8526. isInSSRComponentSetup = isSSR;
  8527. const { props, children } = instance.vnode;
  8528. const isStateful = isStatefulComponent(instance);
  8529. initProps(instance, props, isStateful, isSSR);
  8530. initSlots(instance, children);
  8531. const setupResult = isStateful
  8532. ? setupStatefulComponent(instance, isSSR)
  8533. : undefined;
  8534. isInSSRComponentSetup = false;
  8535. return setupResult;
  8536. }
  8537. function setupStatefulComponent(instance, isSSR) {
  8538. var _a;
  8539. const Component = instance.type;
  8540. {
  8541. if (Component.name) {
  8542. validateComponentName(Component.name, instance.appContext.config);
  8543. }
  8544. if (Component.components) {
  8545. const names = Object.keys(Component.components);
  8546. for (let i = 0; i < names.length; i++) {
  8547. validateComponentName(names[i], instance.appContext.config);
  8548. }
  8549. }
  8550. if (Component.directives) {
  8551. const names = Object.keys(Component.directives);
  8552. for (let i = 0; i < names.length; i++) {
  8553. validateDirectiveName(names[i]);
  8554. }
  8555. }
  8556. if (Component.compilerOptions && isRuntimeOnly()) {
  8557. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  8558. `includes the runtime compiler. Since you are using a runtime-only ` +
  8559. `build, the options should be passed via your build tool config instead.`);
  8560. }
  8561. }
  8562. // 0. create render proxy property access cache
  8563. instance.accessCache = Object.create(null);
  8564. // 1. create public instance / render proxy
  8565. // also mark it raw so it's never observed
  8566. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8567. {
  8568. exposePropsOnRenderContext(instance);
  8569. }
  8570. // 2. call setup()
  8571. const { setup } = Component;
  8572. if (setup) {
  8573. const setupContext = (instance.setupContext =
  8574. setup.length > 1 ? createSetupContext(instance) : null);
  8575. setCurrentInstance(instance);
  8576. pauseTracking();
  8577. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8578. resetTracking();
  8579. unsetCurrentInstance();
  8580. if (isPromise(setupResult)) {
  8581. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8582. if (isSSR) {
  8583. // return the promise so server-renderer can wait on it
  8584. return setupResult
  8585. .then((resolvedResult) => {
  8586. handleSetupResult(instance, resolvedResult, isSSR);
  8587. })
  8588. .catch(e => {
  8589. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  8590. });
  8591. }
  8592. else {
  8593. // async setup returned Promise.
  8594. // bail here and wait for re-entry.
  8595. instance.asyncDep = setupResult;
  8596. if (!instance.suspense) {
  8597. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8598. warn$1(`Component <${name}>: setup function returned a promise, but no ` +
  8599. `<Suspense> boundary was found in the parent component tree. ` +
  8600. `A component with async setup() must be nested in a <Suspense> ` +
  8601. `in order to be rendered.`);
  8602. }
  8603. }
  8604. }
  8605. else {
  8606. handleSetupResult(instance, setupResult, isSSR);
  8607. }
  8608. }
  8609. else {
  8610. finishComponentSetup(instance, isSSR);
  8611. }
  8612. }
  8613. function handleSetupResult(instance, setupResult, isSSR) {
  8614. if (isFunction(setupResult)) {
  8615. // setup returned an inline render function
  8616. {
  8617. instance.render = setupResult;
  8618. }
  8619. }
  8620. else if (isObject(setupResult)) {
  8621. if (isVNode(setupResult)) {
  8622. warn$1(`setup() should not return VNodes directly - ` +
  8623. `return a render function instead.`);
  8624. }
  8625. // setup returned bindings.
  8626. // assuming a render function compiled from template is present.
  8627. {
  8628. instance.devtoolsRawSetupState = setupResult;
  8629. }
  8630. instance.setupState = proxyRefs(setupResult);
  8631. {
  8632. exposeSetupStateOnRenderContext(instance);
  8633. }
  8634. }
  8635. else if (setupResult !== undefined) {
  8636. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8637. }
  8638. finishComponentSetup(instance, isSSR);
  8639. }
  8640. let compile;
  8641. let installWithProxy;
  8642. /**
  8643. * For runtime-dom to register the compiler.
  8644. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8645. */
  8646. function registerRuntimeCompiler(_compile) {
  8647. compile = _compile;
  8648. installWithProxy = i => {
  8649. if (i.render._rc) {
  8650. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8651. }
  8652. };
  8653. }
  8654. // dev only
  8655. const isRuntimeOnly = () => !compile;
  8656. function finishComponentSetup(instance, isSSR, skipOptions) {
  8657. const Component = instance.type;
  8658. // template / render function normalization
  8659. // could be already set when returned from setup()
  8660. if (!instance.render) {
  8661. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8662. // is done by server-renderer
  8663. if (!isSSR && compile && !Component.render) {
  8664. const template = Component.template;
  8665. if (template) {
  8666. {
  8667. startMeasure(instance, `compile`);
  8668. }
  8669. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8670. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8671. const finalCompilerOptions = extend(extend({
  8672. isCustomElement,
  8673. delimiters
  8674. }, compilerOptions), componentCompilerOptions);
  8675. Component.render = compile(template, finalCompilerOptions);
  8676. {
  8677. endMeasure(instance, `compile`);
  8678. }
  8679. }
  8680. }
  8681. instance.render = (Component.render || NOOP);
  8682. // for runtime-compiled render functions using `with` blocks, the render
  8683. // proxy used needs a different `has` handler which is more performant and
  8684. // also only allows a whitelist of globals to fallthrough.
  8685. if (installWithProxy) {
  8686. installWithProxy(instance);
  8687. }
  8688. }
  8689. // support for 2.x options
  8690. {
  8691. setCurrentInstance(instance);
  8692. pauseTracking();
  8693. applyOptions(instance);
  8694. resetTracking();
  8695. unsetCurrentInstance();
  8696. }
  8697. // warn missing template/render
  8698. // the runtime compilation of template in SSR is done by server-render
  8699. if (!Component.render && instance.render === NOOP && !isSSR) {
  8700. /* istanbul ignore if */
  8701. if (!compile && Component.template) {
  8702. warn$1(`Component provided template option but ` +
  8703. `runtime compilation is not supported in this build of Vue.` +
  8704. (` Use "vue.global.js" instead.`
  8705. ) /* should not happen */);
  8706. }
  8707. else {
  8708. warn$1(`Component is missing template or render function.`);
  8709. }
  8710. }
  8711. }
  8712. function createAttrsProxy(instance) {
  8713. return new Proxy(instance.attrs, {
  8714. get(target, key) {
  8715. markAttrsAccessed();
  8716. track(instance, "get" /* GET */, '$attrs');
  8717. return target[key];
  8718. },
  8719. set() {
  8720. warn$1(`setupContext.attrs is readonly.`);
  8721. return false;
  8722. },
  8723. deleteProperty() {
  8724. warn$1(`setupContext.attrs is readonly.`);
  8725. return false;
  8726. }
  8727. }
  8728. );
  8729. }
  8730. function createSetupContext(instance) {
  8731. const expose = exposed => {
  8732. if (instance.exposed) {
  8733. warn$1(`expose() should be called only once per setup().`);
  8734. }
  8735. instance.exposed = exposed || {};
  8736. };
  8737. let attrs;
  8738. {
  8739. // We use getters in dev in case libs like test-utils overwrite instance
  8740. // properties (overwrites should not be done in prod)
  8741. return Object.freeze({
  8742. get attrs() {
  8743. return attrs || (attrs = createAttrsProxy(instance));
  8744. },
  8745. get slots() {
  8746. return shallowReadonly(instance.slots);
  8747. },
  8748. get emit() {
  8749. return (event, ...args) => instance.emit(event, ...args);
  8750. },
  8751. expose
  8752. });
  8753. }
  8754. }
  8755. function getExposeProxy(instance) {
  8756. if (instance.exposed) {
  8757. return (instance.exposeProxy ||
  8758. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8759. get(target, key) {
  8760. if (key in target) {
  8761. return target[key];
  8762. }
  8763. else if (key in publicPropertiesMap) {
  8764. return publicPropertiesMap[key](instance);
  8765. }
  8766. }
  8767. })));
  8768. }
  8769. }
  8770. const classifyRE = /(?:^|[-_])(\w)/g;
  8771. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8772. function getComponentName(Component, includeInferred = true) {
  8773. return isFunction(Component)
  8774. ? Component.displayName || Component.name
  8775. : Component.name || (includeInferred && Component.__name);
  8776. }
  8777. /* istanbul ignore next */
  8778. function formatComponentName(instance, Component, isRoot = false) {
  8779. let name = getComponentName(Component);
  8780. if (!name && Component.__file) {
  8781. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8782. if (match) {
  8783. name = match[1];
  8784. }
  8785. }
  8786. if (!name && instance && instance.parent) {
  8787. // try to infer the name based on reverse resolution
  8788. const inferFromRegistry = (registry) => {
  8789. for (const key in registry) {
  8790. if (registry[key] === Component) {
  8791. return key;
  8792. }
  8793. }
  8794. };
  8795. name =
  8796. inferFromRegistry(instance.components ||
  8797. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8798. }
  8799. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8800. }
  8801. function isClassComponent(value) {
  8802. return isFunction(value) && '__vccOpts' in value;
  8803. }
  8804. const computed$1 = ((getterOrOptions, debugOptions) => {
  8805. // @ts-ignore
  8806. return computed(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8807. });
  8808. // dev only
  8809. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8810. `<script setup> of a single file component. Its arguments should be ` +
  8811. `compiled away and passing it at runtime has no effect.`);
  8812. // implementation
  8813. function defineProps() {
  8814. {
  8815. warnRuntimeUsage(`defineProps`);
  8816. }
  8817. return null;
  8818. }
  8819. // implementation
  8820. function defineEmits() {
  8821. {
  8822. warnRuntimeUsage(`defineEmits`);
  8823. }
  8824. return null;
  8825. }
  8826. /**
  8827. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8828. * instance properties when it is accessed by a parent component via template
  8829. * refs.
  8830. *
  8831. * `<script setup>` components are closed by default - i.e. variables inside
  8832. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8833. * via `defineExpose`.
  8834. *
  8835. * This is only usable inside `<script setup>`, is compiled away in the
  8836. * output and should **not** be actually called at runtime.
  8837. */
  8838. function defineExpose(exposed) {
  8839. {
  8840. warnRuntimeUsage(`defineExpose`);
  8841. }
  8842. }
  8843. /**
  8844. * Vue `<script setup>` compiler macro for providing props default values when
  8845. * using type-based `defineProps` declaration.
  8846. *
  8847. * Example usage:
  8848. * ```ts
  8849. * withDefaults(defineProps<{
  8850. * size?: number
  8851. * labels?: string[]
  8852. * }>(), {
  8853. * size: 3,
  8854. * labels: () => ['default label']
  8855. * })
  8856. * ```
  8857. *
  8858. * This is only usable inside `<script setup>`, is compiled away in the output
  8859. * and should **not** be actually called at runtime.
  8860. */
  8861. function withDefaults(props, defaults) {
  8862. {
  8863. warnRuntimeUsage(`withDefaults`);
  8864. }
  8865. return null;
  8866. }
  8867. function useSlots() {
  8868. return getContext().slots;
  8869. }
  8870. function useAttrs() {
  8871. return getContext().attrs;
  8872. }
  8873. function getContext() {
  8874. const i = getCurrentInstance();
  8875. if (!i) {
  8876. warn$1(`useContext() called without active instance.`);
  8877. }
  8878. return i.setupContext || (i.setupContext = createSetupContext(i));
  8879. }
  8880. /**
  8881. * Runtime helper for merging default declarations. Imported by compiled code
  8882. * only.
  8883. * @internal
  8884. */
  8885. function mergeDefaults(raw, defaults) {
  8886. const props = isArray(raw)
  8887. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8888. : raw;
  8889. for (const key in defaults) {
  8890. const opt = props[key];
  8891. if (opt) {
  8892. if (isArray(opt) || isFunction(opt)) {
  8893. props[key] = { type: opt, default: defaults[key] };
  8894. }
  8895. else {
  8896. opt.default = defaults[key];
  8897. }
  8898. }
  8899. else if (opt === null) {
  8900. props[key] = { default: defaults[key] };
  8901. }
  8902. else {
  8903. warn$1(`props default key "${key}" has no corresponding declaration.`);
  8904. }
  8905. }
  8906. return props;
  8907. }
  8908. /**
  8909. * Used to create a proxy for the rest element when destructuring props with
  8910. * defineProps().
  8911. * @internal
  8912. */
  8913. function createPropsRestProxy(props, excludedKeys) {
  8914. const ret = {};
  8915. for (const key in props) {
  8916. if (!excludedKeys.includes(key)) {
  8917. Object.defineProperty(ret, key, {
  8918. enumerable: true,
  8919. get: () => props[key]
  8920. });
  8921. }
  8922. }
  8923. return ret;
  8924. }
  8925. /**
  8926. * `<script setup>` helper for persisting the current instance context over
  8927. * async/await flows.
  8928. *
  8929. * `@vue/compiler-sfc` converts the following:
  8930. *
  8931. * ```ts
  8932. * const x = await foo()
  8933. * ```
  8934. *
  8935. * into:
  8936. *
  8937. * ```ts
  8938. * let __temp, __restore
  8939. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8940. * ```
  8941. * @internal
  8942. */
  8943. function withAsyncContext(getAwaitable) {
  8944. const ctx = getCurrentInstance();
  8945. if (!ctx) {
  8946. warn$1(`withAsyncContext called without active current instance. ` +
  8947. `This is likely a bug.`);
  8948. }
  8949. let awaitable = getAwaitable();
  8950. unsetCurrentInstance();
  8951. if (isPromise(awaitable)) {
  8952. awaitable = awaitable.catch(e => {
  8953. setCurrentInstance(ctx);
  8954. throw e;
  8955. });
  8956. }
  8957. return [awaitable, () => setCurrentInstance(ctx)];
  8958. }
  8959. // Actual implementation
  8960. function h(type, propsOrChildren, children) {
  8961. const l = arguments.length;
  8962. if (l === 2) {
  8963. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  8964. // single vnode without props
  8965. if (isVNode(propsOrChildren)) {
  8966. return createVNode(type, null, [propsOrChildren]);
  8967. }
  8968. // props without children
  8969. return createVNode(type, propsOrChildren);
  8970. }
  8971. else {
  8972. // omit props
  8973. return createVNode(type, null, propsOrChildren);
  8974. }
  8975. }
  8976. else {
  8977. if (l > 3) {
  8978. children = Array.prototype.slice.call(arguments, 2);
  8979. }
  8980. else if (l === 3 && isVNode(children)) {
  8981. children = [children];
  8982. }
  8983. return createVNode(type, propsOrChildren, children);
  8984. }
  8985. }
  8986. const ssrContextKey = Symbol(`ssrContext` );
  8987. const useSSRContext = () => {
  8988. {
  8989. warn$1(`useSSRContext() is not supported in the global build.`);
  8990. }
  8991. };
  8992. function initCustomFormatter() {
  8993. /* eslint-disable no-restricted-globals */
  8994. if (typeof window === 'undefined') {
  8995. return;
  8996. }
  8997. const vueStyle = { style: 'color:#3ba776' };
  8998. const numberStyle = { style: 'color:#0b1bc9' };
  8999. const stringStyle = { style: 'color:#b62e24' };
  9000. const keywordStyle = { style: 'color:#9d288c' };
  9001. // custom formatter for Chrome
  9002. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  9003. const formatter = {
  9004. header(obj) {
  9005. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  9006. if (!isObject(obj)) {
  9007. return null;
  9008. }
  9009. if (obj.__isVue) {
  9010. return ['div', vueStyle, `VueInstance`];
  9011. }
  9012. else if (isRef(obj)) {
  9013. return [
  9014. 'div',
  9015. {},
  9016. ['span', vueStyle, genRefFlag(obj)],
  9017. '<',
  9018. formatValue(obj.value),
  9019. `>`
  9020. ];
  9021. }
  9022. else if (isReactive(obj)) {
  9023. return [
  9024. 'div',
  9025. {},
  9026. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  9027. '<',
  9028. formatValue(obj),
  9029. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  9030. ];
  9031. }
  9032. else if (isReadonly(obj)) {
  9033. return [
  9034. 'div',
  9035. {},
  9036. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  9037. '<',
  9038. formatValue(obj),
  9039. '>'
  9040. ];
  9041. }
  9042. return null;
  9043. },
  9044. hasBody(obj) {
  9045. return obj && obj.__isVue;
  9046. },
  9047. body(obj) {
  9048. if (obj && obj.__isVue) {
  9049. return [
  9050. 'div',
  9051. {},
  9052. ...formatInstance(obj.$)
  9053. ];
  9054. }
  9055. }
  9056. };
  9057. function formatInstance(instance) {
  9058. const blocks = [];
  9059. if (instance.type.props && instance.props) {
  9060. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  9061. }
  9062. if (instance.setupState !== EMPTY_OBJ) {
  9063. blocks.push(createInstanceBlock('setup', instance.setupState));
  9064. }
  9065. if (instance.data !== EMPTY_OBJ) {
  9066. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  9067. }
  9068. const computed = extractKeys(instance, 'computed');
  9069. if (computed) {
  9070. blocks.push(createInstanceBlock('computed', computed));
  9071. }
  9072. const injected = extractKeys(instance, 'inject');
  9073. if (injected) {
  9074. blocks.push(createInstanceBlock('injected', injected));
  9075. }
  9076. blocks.push([
  9077. 'div',
  9078. {},
  9079. [
  9080. 'span',
  9081. {
  9082. style: keywordStyle.style + ';opacity:0.66'
  9083. },
  9084. '$ (internal): '
  9085. ],
  9086. ['object', { object: instance }]
  9087. ]);
  9088. return blocks;
  9089. }
  9090. function createInstanceBlock(type, target) {
  9091. target = extend({}, target);
  9092. if (!Object.keys(target).length) {
  9093. return ['span', {}];
  9094. }
  9095. return [
  9096. 'div',
  9097. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9098. [
  9099. 'div',
  9100. {
  9101. style: 'color:#476582'
  9102. },
  9103. type
  9104. ],
  9105. [
  9106. 'div',
  9107. {
  9108. style: 'padding-left:1.25em'
  9109. },
  9110. ...Object.keys(target).map(key => {
  9111. return [
  9112. 'div',
  9113. {},
  9114. ['span', keywordStyle, key + ': '],
  9115. formatValue(target[key], false)
  9116. ];
  9117. })
  9118. ]
  9119. ];
  9120. }
  9121. function formatValue(v, asRaw = true) {
  9122. if (typeof v === 'number') {
  9123. return ['span', numberStyle, v];
  9124. }
  9125. else if (typeof v === 'string') {
  9126. return ['span', stringStyle, JSON.stringify(v)];
  9127. }
  9128. else if (typeof v === 'boolean') {
  9129. return ['span', keywordStyle, v];
  9130. }
  9131. else if (isObject(v)) {
  9132. return ['object', { object: asRaw ? toRaw(v) : v }];
  9133. }
  9134. else {
  9135. return ['span', stringStyle, String(v)];
  9136. }
  9137. }
  9138. function extractKeys(instance, type) {
  9139. const Comp = instance.type;
  9140. if (isFunction(Comp)) {
  9141. return;
  9142. }
  9143. const extracted = {};
  9144. for (const key in instance.ctx) {
  9145. if (isKeyOfType(Comp, key, type)) {
  9146. extracted[key] = instance.ctx[key];
  9147. }
  9148. }
  9149. return extracted;
  9150. }
  9151. function isKeyOfType(Comp, key, type) {
  9152. const opts = Comp[type];
  9153. if ((isArray(opts) && opts.includes(key)) ||
  9154. (isObject(opts) && key in opts)) {
  9155. return true;
  9156. }
  9157. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9158. return true;
  9159. }
  9160. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9161. return true;
  9162. }
  9163. }
  9164. function genRefFlag(v) {
  9165. if (isShallow(v)) {
  9166. return `ShallowRef`;
  9167. }
  9168. if (v.effect) {
  9169. return `ComputedRef`;
  9170. }
  9171. return `Ref`;
  9172. }
  9173. if (window.devtoolsFormatters) {
  9174. window.devtoolsFormatters.push(formatter);
  9175. }
  9176. else {
  9177. window.devtoolsFormatters = [formatter];
  9178. }
  9179. }
  9180. function withMemo(memo, render, cache, index) {
  9181. const cached = cache[index];
  9182. if (cached && isMemoSame(cached, memo)) {
  9183. return cached;
  9184. }
  9185. const ret = render();
  9186. // shallow clone
  9187. ret.memo = memo.slice();
  9188. return (cache[index] = ret);
  9189. }
  9190. function isMemoSame(cached, memo) {
  9191. const prev = cached.memo;
  9192. if (prev.length != memo.length) {
  9193. return false;
  9194. }
  9195. for (let i = 0; i < prev.length; i++) {
  9196. if (hasChanged(prev[i], memo[i])) {
  9197. return false;
  9198. }
  9199. }
  9200. // make sure to let parent block track it when returning cached
  9201. if (isBlockTreeEnabled > 0 && currentBlock) {
  9202. currentBlock.push(cached);
  9203. }
  9204. return true;
  9205. }
  9206. // Core API ------------------------------------------------------------------
  9207. const version = "3.2.37";
  9208. /**
  9209. * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
  9210. * @internal
  9211. */
  9212. const ssrUtils = (null);
  9213. /**
  9214. * @internal only exposed in compat builds
  9215. */
  9216. const resolveFilter = null;
  9217. /**
  9218. * @internal only exposed in compat builds.
  9219. */
  9220. const compatUtils = (null);
  9221. const svgNS = 'http://www.w3.org/2000/svg';
  9222. const doc = (typeof document !== 'undefined' ? document : null);
  9223. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9224. const nodeOps = {
  9225. insert: (child, parent, anchor) => {
  9226. parent.insertBefore(child, anchor || null);
  9227. },
  9228. remove: child => {
  9229. const parent = child.parentNode;
  9230. if (parent) {
  9231. parent.removeChild(child);
  9232. }
  9233. },
  9234. createElement: (tag, isSVG, is, props) => {
  9235. const el = isSVG
  9236. ? doc.createElementNS(svgNS, tag)
  9237. : doc.createElement(tag, is ? { is } : undefined);
  9238. if (tag === 'select' && props && props.multiple != null) {
  9239. el.setAttribute('multiple', props.multiple);
  9240. }
  9241. return el;
  9242. },
  9243. createText: text => doc.createTextNode(text),
  9244. createComment: text => doc.createComment(text),
  9245. setText: (node, text) => {
  9246. node.nodeValue = text;
  9247. },
  9248. setElementText: (el, text) => {
  9249. el.textContent = text;
  9250. },
  9251. parentNode: node => node.parentNode,
  9252. nextSibling: node => node.nextSibling,
  9253. querySelector: selector => doc.querySelector(selector),
  9254. setScopeId(el, id) {
  9255. el.setAttribute(id, '');
  9256. },
  9257. cloneNode(el) {
  9258. const cloned = el.cloneNode(true);
  9259. // #3072
  9260. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  9261. // - normally, elements using `:value` bindings will not be hoisted, but if
  9262. // the bound value is a constant, e.g. `:value="true"` - they do get
  9263. // hoisted.
  9264. // - in production, hoisted nodes are cloned when subsequent inserts, but
  9265. // cloneNode() does not copy the custom property we attached.
  9266. // - This may need to account for other custom DOM properties we attach to
  9267. // elements in addition to `_value` in the future.
  9268. if (`_value` in el) {
  9269. cloned._value = el._value;
  9270. }
  9271. return cloned;
  9272. },
  9273. // __UNSAFE__
  9274. // Reason: innerHTML.
  9275. // Static content here can only come from compiled templates.
  9276. // As long as the user only uses trusted templates, this is safe.
  9277. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9278. // <parent> before | first ... last | anchor </parent>
  9279. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9280. // #5308 can only take cached path if:
  9281. // - has a single root node
  9282. // - nextSibling info is still available
  9283. if (start && (start === end || start.nextSibling)) {
  9284. // cached
  9285. while (true) {
  9286. parent.insertBefore(start.cloneNode(true), anchor);
  9287. if (start === end || !(start = start.nextSibling))
  9288. break;
  9289. }
  9290. }
  9291. else {
  9292. // fresh insert
  9293. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9294. const template = templateContainer.content;
  9295. if (isSVG) {
  9296. // remove outer svg wrapper
  9297. const wrapper = template.firstChild;
  9298. while (wrapper.firstChild) {
  9299. template.appendChild(wrapper.firstChild);
  9300. }
  9301. template.removeChild(wrapper);
  9302. }
  9303. parent.insertBefore(template, anchor);
  9304. }
  9305. return [
  9306. // first
  9307. before ? before.nextSibling : parent.firstChild,
  9308. // last
  9309. anchor ? anchor.previousSibling : parent.lastChild
  9310. ];
  9311. }
  9312. };
  9313. // compiler should normalize class + :class bindings on the same element
  9314. // into a single binding ['staticClass', dynamic]
  9315. function patchClass(el, value, isSVG) {
  9316. // directly setting className should be faster than setAttribute in theory
  9317. // if this is an element during a transition, take the temporary transition
  9318. // classes into account.
  9319. const transitionClasses = el._vtc;
  9320. if (transitionClasses) {
  9321. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9322. }
  9323. if (value == null) {
  9324. el.removeAttribute('class');
  9325. }
  9326. else if (isSVG) {
  9327. el.setAttribute('class', value);
  9328. }
  9329. else {
  9330. el.className = value;
  9331. }
  9332. }
  9333. function patchStyle(el, prev, next) {
  9334. const style = el.style;
  9335. const isCssString = isString(next);
  9336. if (next && !isCssString) {
  9337. for (const key in next) {
  9338. setStyle(style, key, next[key]);
  9339. }
  9340. if (prev && !isString(prev)) {
  9341. for (const key in prev) {
  9342. if (next[key] == null) {
  9343. setStyle(style, key, '');
  9344. }
  9345. }
  9346. }
  9347. }
  9348. else {
  9349. const currentDisplay = style.display;
  9350. if (isCssString) {
  9351. if (prev !== next) {
  9352. style.cssText = next;
  9353. }
  9354. }
  9355. else if (prev) {
  9356. el.removeAttribute('style');
  9357. }
  9358. // indicates that the `display` of the element is controlled by `v-show`,
  9359. // so we always keep the current `display` value regardless of the `style`
  9360. // value, thus handing over control to `v-show`.
  9361. if ('_vod' in el) {
  9362. style.display = currentDisplay;
  9363. }
  9364. }
  9365. }
  9366. const importantRE = /\s*!important$/;
  9367. function setStyle(style, name, val) {
  9368. if (isArray(val)) {
  9369. val.forEach(v => setStyle(style, name, v));
  9370. }
  9371. else {
  9372. if (val == null)
  9373. val = '';
  9374. if (name.startsWith('--')) {
  9375. // custom property definition
  9376. style.setProperty(name, val);
  9377. }
  9378. else {
  9379. const prefixed = autoPrefix(style, name);
  9380. if (importantRE.test(val)) {
  9381. // !important
  9382. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9383. }
  9384. else {
  9385. style[prefixed] = val;
  9386. }
  9387. }
  9388. }
  9389. }
  9390. const prefixes = ['Webkit', 'Moz', 'ms'];
  9391. const prefixCache = {};
  9392. function autoPrefix(style, rawName) {
  9393. const cached = prefixCache[rawName];
  9394. if (cached) {
  9395. return cached;
  9396. }
  9397. let name = camelize(rawName);
  9398. if (name !== 'filter' && name in style) {
  9399. return (prefixCache[rawName] = name);
  9400. }
  9401. name = capitalize(name);
  9402. for (let i = 0; i < prefixes.length; i++) {
  9403. const prefixed = prefixes[i] + name;
  9404. if (prefixed in style) {
  9405. return (prefixCache[rawName] = prefixed);
  9406. }
  9407. }
  9408. return rawName;
  9409. }
  9410. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9411. function patchAttr(el, key, value, isSVG, instance) {
  9412. if (isSVG && key.startsWith('xlink:')) {
  9413. if (value == null) {
  9414. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9415. }
  9416. else {
  9417. el.setAttributeNS(xlinkNS, key, value);
  9418. }
  9419. }
  9420. else {
  9421. // note we are only checking boolean attributes that don't have a
  9422. // corresponding dom prop of the same name here.
  9423. const isBoolean = isSpecialBooleanAttr(key);
  9424. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9425. el.removeAttribute(key);
  9426. }
  9427. else {
  9428. el.setAttribute(key, isBoolean ? '' : value);
  9429. }
  9430. }
  9431. }
  9432. // __UNSAFE__
  9433. // functions. The user is responsible for using them with only trusted content.
  9434. function patchDOMProp(el, key, value,
  9435. // the following args are passed only due to potential innerHTML/textContent
  9436. // overriding existing VNodes, in which case the old tree must be properly
  9437. // unmounted.
  9438. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9439. if (key === 'innerHTML' || key === 'textContent') {
  9440. if (prevChildren) {
  9441. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9442. }
  9443. el[key] = value == null ? '' : value;
  9444. return;
  9445. }
  9446. if (key === 'value' &&
  9447. el.tagName !== 'PROGRESS' &&
  9448. // custom elements may use _value internally
  9449. !el.tagName.includes('-')) {
  9450. // store value as _value as well since
  9451. // non-string values will be stringified.
  9452. el._value = value;
  9453. const newValue = value == null ? '' : value;
  9454. if (el.value !== newValue ||
  9455. // #4956: always set for OPTION elements because its value falls back to
  9456. // textContent if no value attribute is present. And setting .value for
  9457. // OPTION has no side effect
  9458. el.tagName === 'OPTION') {
  9459. el.value = newValue;
  9460. }
  9461. if (value == null) {
  9462. el.removeAttribute(key);
  9463. }
  9464. return;
  9465. }
  9466. let needRemove = false;
  9467. if (value === '' || value == null) {
  9468. const type = typeof el[key];
  9469. if (type === 'boolean') {
  9470. // e.g. <select multiple> compiles to { multiple: '' }
  9471. value = includeBooleanAttr(value);
  9472. }
  9473. else if (value == null && type === 'string') {
  9474. // e.g. <div :id="null">
  9475. value = '';
  9476. needRemove = true;
  9477. }
  9478. else if (type === 'number') {
  9479. // e.g. <img :width="null">
  9480. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  9481. value = 0;
  9482. needRemove = true;
  9483. }
  9484. }
  9485. // some properties perform value validation and throw,
  9486. // some properties has getter, no setter, will error in 'use strict'
  9487. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9488. try {
  9489. el[key] = value;
  9490. }
  9491. catch (e) {
  9492. {
  9493. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9494. `value ${value} is invalid.`, e);
  9495. }
  9496. }
  9497. needRemove && el.removeAttribute(key);
  9498. }
  9499. // Async edge case fix requires storing an event listener's attach timestamp.
  9500. const [_getNow, skipTimestampCheck] = /*#__PURE__*/ (() => {
  9501. let _getNow = Date.now;
  9502. let skipTimestampCheck = false;
  9503. if (typeof window !== 'undefined') {
  9504. // Determine what event timestamp the browser is using. Annoyingly, the
  9505. // timestamp can either be hi-res (relative to page load) or low-res
  9506. // (relative to UNIX epoch), so in order to compare time we have to use the
  9507. // same timestamp type when saving the flush timestamp.
  9508. if (Date.now() > document.createEvent('Event').timeStamp) {
  9509. // if the low-res timestamp which is bigger than the event timestamp
  9510. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  9511. // and we need to use the hi-res version for event listeners as well.
  9512. _getNow = performance.now.bind(performance);
  9513. }
  9514. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  9515. // and does not fire microtasks in between event propagation, so safe to exclude.
  9516. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  9517. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  9518. }
  9519. return [_getNow, skipTimestampCheck];
  9520. })();
  9521. // To avoid the overhead of repeatedly calling performance.now(), we cache
  9522. // and use the same timestamp for all event listeners attached in the same tick.
  9523. let cachedNow = 0;
  9524. const p = /*#__PURE__*/ Promise.resolve();
  9525. const reset = () => {
  9526. cachedNow = 0;
  9527. };
  9528. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  9529. function addEventListener(el, event, handler, options) {
  9530. el.addEventListener(event, handler, options);
  9531. }
  9532. function removeEventListener(el, event, handler, options) {
  9533. el.removeEventListener(event, handler, options);
  9534. }
  9535. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9536. // vei = vue event invokers
  9537. const invokers = el._vei || (el._vei = {});
  9538. const existingInvoker = invokers[rawName];
  9539. if (nextValue && existingInvoker) {
  9540. // patch
  9541. existingInvoker.value = nextValue;
  9542. }
  9543. else {
  9544. const [name, options] = parseName(rawName);
  9545. if (nextValue) {
  9546. // add
  9547. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9548. addEventListener(el, name, invoker, options);
  9549. }
  9550. else if (existingInvoker) {
  9551. // remove
  9552. removeEventListener(el, name, existingInvoker, options);
  9553. invokers[rawName] = undefined;
  9554. }
  9555. }
  9556. }
  9557. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9558. function parseName(name) {
  9559. let options;
  9560. if (optionsModifierRE.test(name)) {
  9561. options = {};
  9562. let m;
  9563. while ((m = name.match(optionsModifierRE))) {
  9564. name = name.slice(0, name.length - m[0].length);
  9565. options[m[0].toLowerCase()] = true;
  9566. }
  9567. }
  9568. return [hyphenate(name.slice(2)), options];
  9569. }
  9570. function createInvoker(initialValue, instance) {
  9571. const invoker = (e) => {
  9572. // async edge case #6566: inner click event triggers patch, event handler
  9573. // attached to outer element during patch, and triggered again. This
  9574. // happens because browsers fire microtask ticks between event propagation.
  9575. // the solution is simple: we save the timestamp when a handler is attached,
  9576. // and the handler would only fire if the event passed to it was fired
  9577. // AFTER it was attached.
  9578. const timeStamp = e.timeStamp || _getNow();
  9579. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  9580. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  9581. }
  9582. };
  9583. invoker.value = initialValue;
  9584. invoker.attached = getNow();
  9585. return invoker;
  9586. }
  9587. function patchStopImmediatePropagation(e, value) {
  9588. if (isArray(value)) {
  9589. const originalStop = e.stopImmediatePropagation;
  9590. e.stopImmediatePropagation = () => {
  9591. originalStop.call(e);
  9592. e._stopped = true;
  9593. };
  9594. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9595. }
  9596. else {
  9597. return value;
  9598. }
  9599. }
  9600. const nativeOnRE = /^on[a-z]/;
  9601. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9602. if (key === 'class') {
  9603. patchClass(el, nextValue, isSVG);
  9604. }
  9605. else if (key === 'style') {
  9606. patchStyle(el, prevValue, nextValue);
  9607. }
  9608. else if (isOn(key)) {
  9609. // ignore v-model listeners
  9610. if (!isModelListener(key)) {
  9611. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9612. }
  9613. }
  9614. else if (key[0] === '.'
  9615. ? ((key = key.slice(1)), true)
  9616. : key[0] === '^'
  9617. ? ((key = key.slice(1)), false)
  9618. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9619. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9620. }
  9621. else {
  9622. // special case for <input v-model type="checkbox"> with
  9623. // :true-value & :false-value
  9624. // store value as dom properties since non-string values will be
  9625. // stringified.
  9626. if (key === 'true-value') {
  9627. el._trueValue = nextValue;
  9628. }
  9629. else if (key === 'false-value') {
  9630. el._falseValue = nextValue;
  9631. }
  9632. patchAttr(el, key, nextValue, isSVG);
  9633. }
  9634. };
  9635. function shouldSetAsProp(el, key, value, isSVG) {
  9636. if (isSVG) {
  9637. // most keys must be set as attribute on svg elements to work
  9638. // ...except innerHTML & textContent
  9639. if (key === 'innerHTML' || key === 'textContent') {
  9640. return true;
  9641. }
  9642. // or native onclick with function values
  9643. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9644. return true;
  9645. }
  9646. return false;
  9647. }
  9648. // these are enumerated attrs, however their corresponding DOM properties
  9649. // are actually booleans - this leads to setting it with a string "false"
  9650. // value leading it to be coerced to `true`, so we need to always treat
  9651. // them as attributes.
  9652. // Note that `contentEditable` doesn't have this problem: its DOM
  9653. // property is also enumerated string values.
  9654. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9655. return false;
  9656. }
  9657. // #1787, #2840 form property on form elements is readonly and must be set as
  9658. // attribute.
  9659. if (key === 'form') {
  9660. return false;
  9661. }
  9662. // #1526 <input list> must be set as attribute
  9663. if (key === 'list' && el.tagName === 'INPUT') {
  9664. return false;
  9665. }
  9666. // #2766 <textarea type> must be set as attribute
  9667. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9668. return false;
  9669. }
  9670. // native onclick with string value, must be set as attribute
  9671. if (nativeOnRE.test(key) && isString(value)) {
  9672. return false;
  9673. }
  9674. return key in el;
  9675. }
  9676. function defineCustomElement(options, hydrate) {
  9677. const Comp = defineComponent(options);
  9678. class VueCustomElement extends VueElement {
  9679. constructor(initialProps) {
  9680. super(Comp, initialProps, hydrate);
  9681. }
  9682. }
  9683. VueCustomElement.def = Comp;
  9684. return VueCustomElement;
  9685. }
  9686. const defineSSRCustomElement = ((options) => {
  9687. // @ts-ignore
  9688. return defineCustomElement(options, hydrate);
  9689. });
  9690. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9691. });
  9692. class VueElement extends BaseClass {
  9693. constructor(_def, _props = {}, hydrate) {
  9694. super();
  9695. this._def = _def;
  9696. this._props = _props;
  9697. /**
  9698. * @internal
  9699. */
  9700. this._instance = null;
  9701. this._connected = false;
  9702. this._resolved = false;
  9703. this._numberProps = null;
  9704. if (this.shadowRoot && hydrate) {
  9705. hydrate(this._createVNode(), this.shadowRoot);
  9706. }
  9707. else {
  9708. if (this.shadowRoot) {
  9709. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9710. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9711. }
  9712. this.attachShadow({ mode: 'open' });
  9713. }
  9714. }
  9715. connectedCallback() {
  9716. this._connected = true;
  9717. if (!this._instance) {
  9718. this._resolveDef();
  9719. }
  9720. }
  9721. disconnectedCallback() {
  9722. this._connected = false;
  9723. nextTick(() => {
  9724. if (!this._connected) {
  9725. render(null, this.shadowRoot);
  9726. this._instance = null;
  9727. }
  9728. });
  9729. }
  9730. /**
  9731. * resolve inner component definition (handle possible async component)
  9732. */
  9733. _resolveDef() {
  9734. if (this._resolved) {
  9735. return;
  9736. }
  9737. this._resolved = true;
  9738. // set initial attrs
  9739. for (let i = 0; i < this.attributes.length; i++) {
  9740. this._setAttr(this.attributes[i].name);
  9741. }
  9742. // watch future attr changes
  9743. new MutationObserver(mutations => {
  9744. for (const m of mutations) {
  9745. this._setAttr(m.attributeName);
  9746. }
  9747. }).observe(this, { attributes: true });
  9748. const resolve = (def) => {
  9749. const { props, styles } = def;
  9750. const hasOptions = !isArray(props);
  9751. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  9752. // cast Number-type props set before resolve
  9753. let numberProps;
  9754. if (hasOptions) {
  9755. for (const key in this._props) {
  9756. const opt = props[key];
  9757. if (opt === Number || (opt && opt.type === Number)) {
  9758. this._props[key] = toNumber(this._props[key]);
  9759. (numberProps || (numberProps = Object.create(null)))[key] = true;
  9760. }
  9761. }
  9762. }
  9763. this._numberProps = numberProps;
  9764. // check if there are props set pre-upgrade or connect
  9765. for (const key of Object.keys(this)) {
  9766. if (key[0] !== '_') {
  9767. this._setProp(key, this[key], true, false);
  9768. }
  9769. }
  9770. // defining getter/setters on prototype
  9771. for (const key of rawKeys.map(camelize)) {
  9772. Object.defineProperty(this, key, {
  9773. get() {
  9774. return this._getProp(key);
  9775. },
  9776. set(val) {
  9777. this._setProp(key, val);
  9778. }
  9779. });
  9780. }
  9781. // apply CSS
  9782. this._applyStyles(styles);
  9783. // initial render
  9784. this._update();
  9785. };
  9786. const asyncDef = this._def.__asyncLoader;
  9787. if (asyncDef) {
  9788. asyncDef().then(resolve);
  9789. }
  9790. else {
  9791. resolve(this._def);
  9792. }
  9793. }
  9794. _setAttr(key) {
  9795. let value = this.getAttribute(key);
  9796. if (this._numberProps && this._numberProps[key]) {
  9797. value = toNumber(value);
  9798. }
  9799. this._setProp(camelize(key), value, false);
  9800. }
  9801. /**
  9802. * @internal
  9803. */
  9804. _getProp(key) {
  9805. return this._props[key];
  9806. }
  9807. /**
  9808. * @internal
  9809. */
  9810. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9811. if (val !== this._props[key]) {
  9812. this._props[key] = val;
  9813. if (shouldUpdate && this._instance) {
  9814. this._update();
  9815. }
  9816. // reflect
  9817. if (shouldReflect) {
  9818. if (val === true) {
  9819. this.setAttribute(hyphenate(key), '');
  9820. }
  9821. else if (typeof val === 'string' || typeof val === 'number') {
  9822. this.setAttribute(hyphenate(key), val + '');
  9823. }
  9824. else if (!val) {
  9825. this.removeAttribute(hyphenate(key));
  9826. }
  9827. }
  9828. }
  9829. }
  9830. _update() {
  9831. render(this._createVNode(), this.shadowRoot);
  9832. }
  9833. _createVNode() {
  9834. const vnode = createVNode(this._def, extend({}, this._props));
  9835. if (!this._instance) {
  9836. vnode.ce = instance => {
  9837. this._instance = instance;
  9838. instance.isCE = true;
  9839. // HMR
  9840. {
  9841. instance.ceReload = newStyles => {
  9842. // always reset styles
  9843. if (this._styles) {
  9844. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9845. this._styles.length = 0;
  9846. }
  9847. this._applyStyles(newStyles);
  9848. // if this is an async component, ceReload is called from the inner
  9849. // component so no need to reload the async wrapper
  9850. if (!this._def.__asyncLoader) {
  9851. // reload
  9852. this._instance = null;
  9853. this._update();
  9854. }
  9855. };
  9856. }
  9857. // intercept emit
  9858. instance.emit = (event, ...args) => {
  9859. this.dispatchEvent(new CustomEvent(event, {
  9860. detail: args
  9861. }));
  9862. };
  9863. // locate nearest Vue custom element parent for provide/inject
  9864. let parent = this;
  9865. while ((parent =
  9866. parent && (parent.parentNode || parent.host))) {
  9867. if (parent instanceof VueElement) {
  9868. instance.parent = parent._instance;
  9869. break;
  9870. }
  9871. }
  9872. };
  9873. }
  9874. return vnode;
  9875. }
  9876. _applyStyles(styles) {
  9877. if (styles) {
  9878. styles.forEach(css => {
  9879. const s = document.createElement('style');
  9880. s.textContent = css;
  9881. this.shadowRoot.appendChild(s);
  9882. // record for HMR
  9883. {
  9884. (this._styles || (this._styles = [])).push(s);
  9885. }
  9886. });
  9887. }
  9888. }
  9889. }
  9890. function useCssModule(name = '$style') {
  9891. /* istanbul ignore else */
  9892. {
  9893. {
  9894. warn$1(`useCssModule() is not supported in the global build.`);
  9895. }
  9896. return EMPTY_OBJ;
  9897. }
  9898. }
  9899. /**
  9900. * Runtime helper for SFC's CSS variable injection feature.
  9901. * @private
  9902. */
  9903. function useCssVars(getter) {
  9904. const instance = getCurrentInstance();
  9905. /* istanbul ignore next */
  9906. if (!instance) {
  9907. warn$1(`useCssVars is called without current active component instance.`);
  9908. return;
  9909. }
  9910. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  9911. watchPostEffect(setVars);
  9912. onMounted(() => {
  9913. const ob = new MutationObserver(setVars);
  9914. ob.observe(instance.subTree.el.parentNode, { childList: true });
  9915. onUnmounted(() => ob.disconnect());
  9916. });
  9917. }
  9918. function setVarsOnVNode(vnode, vars) {
  9919. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  9920. const suspense = vnode.suspense;
  9921. vnode = suspense.activeBranch;
  9922. if (suspense.pendingBranch && !suspense.isHydrating) {
  9923. suspense.effects.push(() => {
  9924. setVarsOnVNode(suspense.activeBranch, vars);
  9925. });
  9926. }
  9927. }
  9928. // drill down HOCs until it's a non-component vnode
  9929. while (vnode.component) {
  9930. vnode = vnode.component.subTree;
  9931. }
  9932. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  9933. setVarsOnNode(vnode.el, vars);
  9934. }
  9935. else if (vnode.type === Fragment) {
  9936. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  9937. }
  9938. else if (vnode.type === Static) {
  9939. let { el, anchor } = vnode;
  9940. while (el) {
  9941. setVarsOnNode(el, vars);
  9942. if (el === anchor)
  9943. break;
  9944. el = el.nextSibling;
  9945. }
  9946. }
  9947. }
  9948. function setVarsOnNode(el, vars) {
  9949. if (el.nodeType === 1) {
  9950. const style = el.style;
  9951. for (const key in vars) {
  9952. style.setProperty(`--${key}`, vars[key]);
  9953. }
  9954. }
  9955. }
  9956. const TRANSITION = 'transition';
  9957. const ANIMATION = 'animation';
  9958. // DOM Transition is a higher-order-component based on the platform-agnostic
  9959. // base Transition component, with DOM-specific logic.
  9960. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  9961. Transition.displayName = 'Transition';
  9962. const DOMTransitionPropsValidators = {
  9963. name: String,
  9964. type: String,
  9965. css: {
  9966. type: Boolean,
  9967. default: true
  9968. },
  9969. duration: [String, Number, Object],
  9970. enterFromClass: String,
  9971. enterActiveClass: String,
  9972. enterToClass: String,
  9973. appearFromClass: String,
  9974. appearActiveClass: String,
  9975. appearToClass: String,
  9976. leaveFromClass: String,
  9977. leaveActiveClass: String,
  9978. leaveToClass: String
  9979. };
  9980. const TransitionPropsValidators = (Transition.props =
  9981. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  9982. /**
  9983. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  9984. * with custom HOCs.
  9985. */
  9986. const callHook$1 = (hook, args = []) => {
  9987. if (isArray(hook)) {
  9988. hook.forEach(h => h(...args));
  9989. }
  9990. else if (hook) {
  9991. hook(...args);
  9992. }
  9993. };
  9994. /**
  9995. * Check if a hook expects a callback (2nd arg), which means the user
  9996. * intends to explicitly control the end of the transition.
  9997. */
  9998. const hasExplicitCallback = (hook) => {
  9999. return hook
  10000. ? isArray(hook)
  10001. ? hook.some(h => h.length > 1)
  10002. : hook.length > 1
  10003. : false;
  10004. };
  10005. function resolveTransitionProps(rawProps) {
  10006. const baseProps = {};
  10007. for (const key in rawProps) {
  10008. if (!(key in DOMTransitionPropsValidators)) {
  10009. baseProps[key] = rawProps[key];
  10010. }
  10011. }
  10012. if (rawProps.css === false) {
  10013. return baseProps;
  10014. }
  10015. 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;
  10016. const durations = normalizeDuration(duration);
  10017. const enterDuration = durations && durations[0];
  10018. const leaveDuration = durations && durations[1];
  10019. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  10020. const finishEnter = (el, isAppear, done) => {
  10021. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10022. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  10023. done && done();
  10024. };
  10025. const finishLeave = (el, done) => {
  10026. el._isLeaving = false;
  10027. removeTransitionClass(el, leaveFromClass);
  10028. removeTransitionClass(el, leaveToClass);
  10029. removeTransitionClass(el, leaveActiveClass);
  10030. done && done();
  10031. };
  10032. const makeEnterHook = (isAppear) => {
  10033. return (el, done) => {
  10034. const hook = isAppear ? onAppear : onEnter;
  10035. const resolve = () => finishEnter(el, isAppear, done);
  10036. callHook$1(hook, [el, resolve]);
  10037. nextFrame(() => {
  10038. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  10039. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10040. if (!hasExplicitCallback(hook)) {
  10041. whenTransitionEnds(el, type, enterDuration, resolve);
  10042. }
  10043. });
  10044. };
  10045. };
  10046. return extend(baseProps, {
  10047. onBeforeEnter(el) {
  10048. callHook$1(onBeforeEnter, [el]);
  10049. addTransitionClass(el, enterFromClass);
  10050. addTransitionClass(el, enterActiveClass);
  10051. },
  10052. onBeforeAppear(el) {
  10053. callHook$1(onBeforeAppear, [el]);
  10054. addTransitionClass(el, appearFromClass);
  10055. addTransitionClass(el, appearActiveClass);
  10056. },
  10057. onEnter: makeEnterHook(false),
  10058. onAppear: makeEnterHook(true),
  10059. onLeave(el, done) {
  10060. el._isLeaving = true;
  10061. const resolve = () => finishLeave(el, done);
  10062. addTransitionClass(el, leaveFromClass);
  10063. // force reflow so *-leave-from classes immediately take effect (#2593)
  10064. forceReflow();
  10065. addTransitionClass(el, leaveActiveClass);
  10066. nextFrame(() => {
  10067. if (!el._isLeaving) {
  10068. // cancelled
  10069. return;
  10070. }
  10071. removeTransitionClass(el, leaveFromClass);
  10072. addTransitionClass(el, leaveToClass);
  10073. if (!hasExplicitCallback(onLeave)) {
  10074. whenTransitionEnds(el, type, leaveDuration, resolve);
  10075. }
  10076. });
  10077. callHook$1(onLeave, [el, resolve]);
  10078. },
  10079. onEnterCancelled(el) {
  10080. finishEnter(el, false);
  10081. callHook$1(onEnterCancelled, [el]);
  10082. },
  10083. onAppearCancelled(el) {
  10084. finishEnter(el, true);
  10085. callHook$1(onAppearCancelled, [el]);
  10086. },
  10087. onLeaveCancelled(el) {
  10088. finishLeave(el);
  10089. callHook$1(onLeaveCancelled, [el]);
  10090. }
  10091. });
  10092. }
  10093. function normalizeDuration(duration) {
  10094. if (duration == null) {
  10095. return null;
  10096. }
  10097. else if (isObject(duration)) {
  10098. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10099. }
  10100. else {
  10101. const n = NumberOf(duration);
  10102. return [n, n];
  10103. }
  10104. }
  10105. function NumberOf(val) {
  10106. const res = toNumber(val);
  10107. validateDuration(res);
  10108. return res;
  10109. }
  10110. function validateDuration(val) {
  10111. if (typeof val !== 'number') {
  10112. warn$1(`<transition> explicit duration is not a valid number - ` +
  10113. `got ${JSON.stringify(val)}.`);
  10114. }
  10115. else if (isNaN(val)) {
  10116. warn$1(`<transition> explicit duration is NaN - ` +
  10117. 'the duration expression might be incorrect.');
  10118. }
  10119. }
  10120. function addTransitionClass(el, cls) {
  10121. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10122. (el._vtc ||
  10123. (el._vtc = new Set())).add(cls);
  10124. }
  10125. function removeTransitionClass(el, cls) {
  10126. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10127. const { _vtc } = el;
  10128. if (_vtc) {
  10129. _vtc.delete(cls);
  10130. if (!_vtc.size) {
  10131. el._vtc = undefined;
  10132. }
  10133. }
  10134. }
  10135. function nextFrame(cb) {
  10136. requestAnimationFrame(() => {
  10137. requestAnimationFrame(cb);
  10138. });
  10139. }
  10140. let endId = 0;
  10141. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10142. const id = (el._endId = ++endId);
  10143. const resolveIfNotStale = () => {
  10144. if (id === el._endId) {
  10145. resolve();
  10146. }
  10147. };
  10148. if (explicitTimeout) {
  10149. return setTimeout(resolveIfNotStale, explicitTimeout);
  10150. }
  10151. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10152. if (!type) {
  10153. return resolve();
  10154. }
  10155. const endEvent = type + 'end';
  10156. let ended = 0;
  10157. const end = () => {
  10158. el.removeEventListener(endEvent, onEnd);
  10159. resolveIfNotStale();
  10160. };
  10161. const onEnd = (e) => {
  10162. if (e.target === el && ++ended >= propCount) {
  10163. end();
  10164. }
  10165. };
  10166. setTimeout(() => {
  10167. if (ended < propCount) {
  10168. end();
  10169. }
  10170. }, timeout + 1);
  10171. el.addEventListener(endEvent, onEnd);
  10172. }
  10173. function getTransitionInfo(el, expectedType) {
  10174. const styles = window.getComputedStyle(el);
  10175. // JSDOM may return undefined for transition properties
  10176. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10177. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  10178. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  10179. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10180. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  10181. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  10182. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10183. let type = null;
  10184. let timeout = 0;
  10185. let propCount = 0;
  10186. /* istanbul ignore if */
  10187. if (expectedType === TRANSITION) {
  10188. if (transitionTimeout > 0) {
  10189. type = TRANSITION;
  10190. timeout = transitionTimeout;
  10191. propCount = transitionDurations.length;
  10192. }
  10193. }
  10194. else if (expectedType === ANIMATION) {
  10195. if (animationTimeout > 0) {
  10196. type = ANIMATION;
  10197. timeout = animationTimeout;
  10198. propCount = animationDurations.length;
  10199. }
  10200. }
  10201. else {
  10202. timeout = Math.max(transitionTimeout, animationTimeout);
  10203. type =
  10204. timeout > 0
  10205. ? transitionTimeout > animationTimeout
  10206. ? TRANSITION
  10207. : ANIMATION
  10208. : null;
  10209. propCount = type
  10210. ? type === TRANSITION
  10211. ? transitionDurations.length
  10212. : animationDurations.length
  10213. : 0;
  10214. }
  10215. const hasTransform = type === TRANSITION &&
  10216. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  10217. return {
  10218. type,
  10219. timeout,
  10220. propCount,
  10221. hasTransform
  10222. };
  10223. }
  10224. function getTimeout(delays, durations) {
  10225. while (delays.length < durations.length) {
  10226. delays = delays.concat(delays);
  10227. }
  10228. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10229. }
  10230. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10231. // numbers in a locale-dependent way, using a comma instead of a dot.
  10232. // If comma is not replaced with a dot, the input will be rounded down
  10233. // (i.e. acting as a floor function) causing unexpected behaviors
  10234. function toMs(s) {
  10235. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10236. }
  10237. // synchronously force layout to put elements into a certain state
  10238. function forceReflow() {
  10239. return document.body.offsetHeight;
  10240. }
  10241. const positionMap = new WeakMap();
  10242. const newPositionMap = new WeakMap();
  10243. const TransitionGroupImpl = {
  10244. name: 'TransitionGroup',
  10245. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10246. tag: String,
  10247. moveClass: String
  10248. }),
  10249. setup(props, { slots }) {
  10250. const instance = getCurrentInstance();
  10251. const state = useTransitionState();
  10252. let prevChildren;
  10253. let children;
  10254. onUpdated(() => {
  10255. // children is guaranteed to exist after initial render
  10256. if (!prevChildren.length) {
  10257. return;
  10258. }
  10259. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10260. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10261. return;
  10262. }
  10263. // we divide the work into three loops to avoid mixing DOM reads and writes
  10264. // in each iteration - which helps prevent layout thrashing.
  10265. prevChildren.forEach(callPendingCbs);
  10266. prevChildren.forEach(recordPosition);
  10267. const movedChildren = prevChildren.filter(applyTranslation);
  10268. // force reflow to put everything in position
  10269. forceReflow();
  10270. movedChildren.forEach(c => {
  10271. const el = c.el;
  10272. const style = el.style;
  10273. addTransitionClass(el, moveClass);
  10274. style.transform = style.webkitTransform = style.transitionDuration = '';
  10275. const cb = (el._moveCb = (e) => {
  10276. if (e && e.target !== el) {
  10277. return;
  10278. }
  10279. if (!e || /transform$/.test(e.propertyName)) {
  10280. el.removeEventListener('transitionend', cb);
  10281. el._moveCb = null;
  10282. removeTransitionClass(el, moveClass);
  10283. }
  10284. });
  10285. el.addEventListener('transitionend', cb);
  10286. });
  10287. });
  10288. return () => {
  10289. const rawProps = toRaw(props);
  10290. const cssTransitionProps = resolveTransitionProps(rawProps);
  10291. let tag = rawProps.tag || Fragment;
  10292. prevChildren = children;
  10293. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10294. for (let i = 0; i < children.length; i++) {
  10295. const child = children[i];
  10296. if (child.key != null) {
  10297. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10298. }
  10299. else {
  10300. warn$1(`<TransitionGroup> children must be keyed.`);
  10301. }
  10302. }
  10303. if (prevChildren) {
  10304. for (let i = 0; i < prevChildren.length; i++) {
  10305. const child = prevChildren[i];
  10306. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10307. positionMap.set(child, child.el.getBoundingClientRect());
  10308. }
  10309. }
  10310. return createVNode(tag, null, children);
  10311. };
  10312. }
  10313. };
  10314. const TransitionGroup = TransitionGroupImpl;
  10315. function callPendingCbs(c) {
  10316. const el = c.el;
  10317. if (el._moveCb) {
  10318. el._moveCb();
  10319. }
  10320. if (el._enterCb) {
  10321. el._enterCb();
  10322. }
  10323. }
  10324. function recordPosition(c) {
  10325. newPositionMap.set(c, c.el.getBoundingClientRect());
  10326. }
  10327. function applyTranslation(c) {
  10328. const oldPos = positionMap.get(c);
  10329. const newPos = newPositionMap.get(c);
  10330. const dx = oldPos.left - newPos.left;
  10331. const dy = oldPos.top - newPos.top;
  10332. if (dx || dy) {
  10333. const s = c.el.style;
  10334. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10335. s.transitionDuration = '0s';
  10336. return c;
  10337. }
  10338. }
  10339. function hasCSSTransform(el, root, moveClass) {
  10340. // Detect whether an element with the move class applied has
  10341. // CSS transitions. Since the element may be inside an entering
  10342. // transition at this very moment, we make a clone of it and remove
  10343. // all other transition classes applied to ensure only the move class
  10344. // is applied.
  10345. const clone = el.cloneNode();
  10346. if (el._vtc) {
  10347. el._vtc.forEach(cls => {
  10348. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10349. });
  10350. }
  10351. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10352. clone.style.display = 'none';
  10353. const container = (root.nodeType === 1 ? root : root.parentNode);
  10354. container.appendChild(clone);
  10355. const { hasTransform } = getTransitionInfo(clone);
  10356. container.removeChild(clone);
  10357. return hasTransform;
  10358. }
  10359. const getModelAssigner = (vnode) => {
  10360. const fn = vnode.props['onUpdate:modelValue'] ||
  10361. (false );
  10362. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10363. };
  10364. function onCompositionStart(e) {
  10365. e.target.composing = true;
  10366. }
  10367. function onCompositionEnd(e) {
  10368. const target = e.target;
  10369. if (target.composing) {
  10370. target.composing = false;
  10371. target.dispatchEvent(new Event('input'));
  10372. }
  10373. }
  10374. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10375. // be tree-shaken in case v-model is never used.
  10376. const vModelText = {
  10377. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10378. el._assign = getModelAssigner(vnode);
  10379. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10380. addEventListener(el, lazy ? 'change' : 'input', e => {
  10381. if (e.target.composing)
  10382. return;
  10383. let domValue = el.value;
  10384. if (trim) {
  10385. domValue = domValue.trim();
  10386. }
  10387. if (castToNumber) {
  10388. domValue = toNumber(domValue);
  10389. }
  10390. el._assign(domValue);
  10391. });
  10392. if (trim) {
  10393. addEventListener(el, 'change', () => {
  10394. el.value = el.value.trim();
  10395. });
  10396. }
  10397. if (!lazy) {
  10398. addEventListener(el, 'compositionstart', onCompositionStart);
  10399. addEventListener(el, 'compositionend', onCompositionEnd);
  10400. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10401. // switching focus before confirming composition choice
  10402. // this also fixes the issue where some browsers e.g. iOS Chrome
  10403. // fires "change" instead of "input" on autocomplete.
  10404. addEventListener(el, 'change', onCompositionEnd);
  10405. }
  10406. },
  10407. // set value on mounted so it's after min/max for type="range"
  10408. mounted(el, { value }) {
  10409. el.value = value == null ? '' : value;
  10410. },
  10411. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10412. el._assign = getModelAssigner(vnode);
  10413. // avoid clearing unresolved text. #2302
  10414. if (el.composing)
  10415. return;
  10416. if (document.activeElement === el && el.type !== 'range') {
  10417. if (lazy) {
  10418. return;
  10419. }
  10420. if (trim && el.value.trim() === value) {
  10421. return;
  10422. }
  10423. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10424. return;
  10425. }
  10426. }
  10427. const newValue = value == null ? '' : value;
  10428. if (el.value !== newValue) {
  10429. el.value = newValue;
  10430. }
  10431. }
  10432. };
  10433. const vModelCheckbox = {
  10434. // #4096 array checkboxes need to be deep traversed
  10435. deep: true,
  10436. created(el, _, vnode) {
  10437. el._assign = getModelAssigner(vnode);
  10438. addEventListener(el, 'change', () => {
  10439. const modelValue = el._modelValue;
  10440. const elementValue = getValue(el);
  10441. const checked = el.checked;
  10442. const assign = el._assign;
  10443. if (isArray(modelValue)) {
  10444. const index = looseIndexOf(modelValue, elementValue);
  10445. const found = index !== -1;
  10446. if (checked && !found) {
  10447. assign(modelValue.concat(elementValue));
  10448. }
  10449. else if (!checked && found) {
  10450. const filtered = [...modelValue];
  10451. filtered.splice(index, 1);
  10452. assign(filtered);
  10453. }
  10454. }
  10455. else if (isSet(modelValue)) {
  10456. const cloned = new Set(modelValue);
  10457. if (checked) {
  10458. cloned.add(elementValue);
  10459. }
  10460. else {
  10461. cloned.delete(elementValue);
  10462. }
  10463. assign(cloned);
  10464. }
  10465. else {
  10466. assign(getCheckboxValue(el, checked));
  10467. }
  10468. });
  10469. },
  10470. // set initial checked on mount to wait for true-value/false-value
  10471. mounted: setChecked,
  10472. beforeUpdate(el, binding, vnode) {
  10473. el._assign = getModelAssigner(vnode);
  10474. setChecked(el, binding, vnode);
  10475. }
  10476. };
  10477. function setChecked(el, { value, oldValue }, vnode) {
  10478. el._modelValue = value;
  10479. if (isArray(value)) {
  10480. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10481. }
  10482. else if (isSet(value)) {
  10483. el.checked = value.has(vnode.props.value);
  10484. }
  10485. else if (value !== oldValue) {
  10486. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10487. }
  10488. }
  10489. const vModelRadio = {
  10490. created(el, { value }, vnode) {
  10491. el.checked = looseEqual(value, vnode.props.value);
  10492. el._assign = getModelAssigner(vnode);
  10493. addEventListener(el, 'change', () => {
  10494. el._assign(getValue(el));
  10495. });
  10496. },
  10497. beforeUpdate(el, { value, oldValue }, vnode) {
  10498. el._assign = getModelAssigner(vnode);
  10499. if (value !== oldValue) {
  10500. el.checked = looseEqual(value, vnode.props.value);
  10501. }
  10502. }
  10503. };
  10504. const vModelSelect = {
  10505. // <select multiple> value need to be deep traversed
  10506. deep: true,
  10507. created(el, { value, modifiers: { number } }, vnode) {
  10508. const isSetModel = isSet(value);
  10509. addEventListener(el, 'change', () => {
  10510. const selectedVal = Array.prototype.filter
  10511. .call(el.options, (o) => o.selected)
  10512. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10513. el._assign(el.multiple
  10514. ? isSetModel
  10515. ? new Set(selectedVal)
  10516. : selectedVal
  10517. : selectedVal[0]);
  10518. });
  10519. el._assign = getModelAssigner(vnode);
  10520. },
  10521. // set value in mounted & updated because <select> relies on its children
  10522. // <option>s.
  10523. mounted(el, { value }) {
  10524. setSelected(el, value);
  10525. },
  10526. beforeUpdate(el, _binding, vnode) {
  10527. el._assign = getModelAssigner(vnode);
  10528. },
  10529. updated(el, { value }) {
  10530. setSelected(el, value);
  10531. }
  10532. };
  10533. function setSelected(el, value) {
  10534. const isMultiple = el.multiple;
  10535. if (isMultiple && !isArray(value) && !isSet(value)) {
  10536. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10537. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10538. return;
  10539. }
  10540. for (let i = 0, l = el.options.length; i < l; i++) {
  10541. const option = el.options[i];
  10542. const optionValue = getValue(option);
  10543. if (isMultiple) {
  10544. if (isArray(value)) {
  10545. option.selected = looseIndexOf(value, optionValue) > -1;
  10546. }
  10547. else {
  10548. option.selected = value.has(optionValue);
  10549. }
  10550. }
  10551. else {
  10552. if (looseEqual(getValue(option), value)) {
  10553. if (el.selectedIndex !== i)
  10554. el.selectedIndex = i;
  10555. return;
  10556. }
  10557. }
  10558. }
  10559. if (!isMultiple && el.selectedIndex !== -1) {
  10560. el.selectedIndex = -1;
  10561. }
  10562. }
  10563. // retrieve raw value set via :value bindings
  10564. function getValue(el) {
  10565. return '_value' in el ? el._value : el.value;
  10566. }
  10567. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10568. function getCheckboxValue(el, checked) {
  10569. const key = checked ? '_trueValue' : '_falseValue';
  10570. return key in el ? el[key] : checked;
  10571. }
  10572. const vModelDynamic = {
  10573. created(el, binding, vnode) {
  10574. callModelHook(el, binding, vnode, null, 'created');
  10575. },
  10576. mounted(el, binding, vnode) {
  10577. callModelHook(el, binding, vnode, null, 'mounted');
  10578. },
  10579. beforeUpdate(el, binding, vnode, prevVNode) {
  10580. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10581. },
  10582. updated(el, binding, vnode, prevVNode) {
  10583. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10584. }
  10585. };
  10586. function resolveDynamicModel(tagName, type) {
  10587. switch (tagName) {
  10588. case 'SELECT':
  10589. return vModelSelect;
  10590. case 'TEXTAREA':
  10591. return vModelText;
  10592. default:
  10593. switch (type) {
  10594. case 'checkbox':
  10595. return vModelCheckbox;
  10596. case 'radio':
  10597. return vModelRadio;
  10598. default:
  10599. return vModelText;
  10600. }
  10601. }
  10602. }
  10603. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10604. const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
  10605. const fn = modelToUse[hook];
  10606. fn && fn(el, binding, vnode, prevVNode);
  10607. }
  10608. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10609. const modifierGuards = {
  10610. stop: e => e.stopPropagation(),
  10611. prevent: e => e.preventDefault(),
  10612. self: e => e.target !== e.currentTarget,
  10613. ctrl: e => !e.ctrlKey,
  10614. shift: e => !e.shiftKey,
  10615. alt: e => !e.altKey,
  10616. meta: e => !e.metaKey,
  10617. left: e => 'button' in e && e.button !== 0,
  10618. middle: e => 'button' in e && e.button !== 1,
  10619. right: e => 'button' in e && e.button !== 2,
  10620. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10621. };
  10622. /**
  10623. * @private
  10624. */
  10625. const withModifiers = (fn, modifiers) => {
  10626. return (event, ...args) => {
  10627. for (let i = 0; i < modifiers.length; i++) {
  10628. const guard = modifierGuards[modifiers[i]];
  10629. if (guard && guard(event, modifiers))
  10630. return;
  10631. }
  10632. return fn(event, ...args);
  10633. };
  10634. };
  10635. // Kept for 2.x compat.
  10636. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10637. const keyNames = {
  10638. esc: 'escape',
  10639. space: ' ',
  10640. up: 'arrow-up',
  10641. left: 'arrow-left',
  10642. right: 'arrow-right',
  10643. down: 'arrow-down',
  10644. delete: 'backspace'
  10645. };
  10646. /**
  10647. * @private
  10648. */
  10649. const withKeys = (fn, modifiers) => {
  10650. return (event) => {
  10651. if (!('key' in event)) {
  10652. return;
  10653. }
  10654. const eventKey = hyphenate(event.key);
  10655. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10656. return fn(event);
  10657. }
  10658. };
  10659. };
  10660. const vShow = {
  10661. beforeMount(el, { value }, { transition }) {
  10662. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10663. if (transition && value) {
  10664. transition.beforeEnter(el);
  10665. }
  10666. else {
  10667. setDisplay(el, value);
  10668. }
  10669. },
  10670. mounted(el, { value }, { transition }) {
  10671. if (transition && value) {
  10672. transition.enter(el);
  10673. }
  10674. },
  10675. updated(el, { value, oldValue }, { transition }) {
  10676. if (!value === !oldValue)
  10677. return;
  10678. if (transition) {
  10679. if (value) {
  10680. transition.beforeEnter(el);
  10681. setDisplay(el, true);
  10682. transition.enter(el);
  10683. }
  10684. else {
  10685. transition.leave(el, () => {
  10686. setDisplay(el, false);
  10687. });
  10688. }
  10689. }
  10690. else {
  10691. setDisplay(el, value);
  10692. }
  10693. },
  10694. beforeUnmount(el, { value }) {
  10695. setDisplay(el, value);
  10696. }
  10697. };
  10698. function setDisplay(el, value) {
  10699. el.style.display = value ? el._vod : 'none';
  10700. }
  10701. const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
  10702. // lazy create the renderer - this makes core renderer logic tree-shakable
  10703. // in case the user only imports reactivity utilities from Vue.
  10704. let renderer;
  10705. let enabledHydration = false;
  10706. function ensureRenderer() {
  10707. return (renderer ||
  10708. (renderer = createRenderer(rendererOptions)));
  10709. }
  10710. function ensureHydrationRenderer() {
  10711. renderer = enabledHydration
  10712. ? renderer
  10713. : createHydrationRenderer(rendererOptions);
  10714. enabledHydration = true;
  10715. return renderer;
  10716. }
  10717. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10718. const render = ((...args) => {
  10719. ensureRenderer().render(...args);
  10720. });
  10721. const hydrate = ((...args) => {
  10722. ensureHydrationRenderer().hydrate(...args);
  10723. });
  10724. const createApp = ((...args) => {
  10725. const app = ensureRenderer().createApp(...args);
  10726. {
  10727. injectNativeTagCheck(app);
  10728. injectCompilerOptionsCheck(app);
  10729. }
  10730. const { mount } = app;
  10731. app.mount = (containerOrSelector) => {
  10732. const container = normalizeContainer(containerOrSelector);
  10733. if (!container)
  10734. return;
  10735. const component = app._component;
  10736. if (!isFunction(component) && !component.render && !component.template) {
  10737. // __UNSAFE__
  10738. // Reason: potential execution of JS expressions in in-DOM template.
  10739. // The user must make sure the in-DOM template is trusted. If it's
  10740. // rendered by the server, the template should not contain any user data.
  10741. component.template = container.innerHTML;
  10742. }
  10743. // clear content before mounting
  10744. container.innerHTML = '';
  10745. const proxy = mount(container, false, container instanceof SVGElement);
  10746. if (container instanceof Element) {
  10747. container.removeAttribute('v-cloak');
  10748. container.setAttribute('data-v-app', '');
  10749. }
  10750. return proxy;
  10751. };
  10752. return app;
  10753. });
  10754. const createSSRApp = ((...args) => {
  10755. const app = ensureHydrationRenderer().createApp(...args);
  10756. {
  10757. injectNativeTagCheck(app);
  10758. injectCompilerOptionsCheck(app);
  10759. }
  10760. const { mount } = app;
  10761. app.mount = (containerOrSelector) => {
  10762. const container = normalizeContainer(containerOrSelector);
  10763. if (container) {
  10764. return mount(container, true, container instanceof SVGElement);
  10765. }
  10766. };
  10767. return app;
  10768. });
  10769. function injectNativeTagCheck(app) {
  10770. // Inject `isNativeTag`
  10771. // this is used for component name validation (dev only)
  10772. Object.defineProperty(app.config, 'isNativeTag', {
  10773. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10774. writable: false
  10775. });
  10776. }
  10777. // dev only
  10778. function injectCompilerOptionsCheck(app) {
  10779. if (isRuntimeOnly()) {
  10780. const isCustomElement = app.config.isCustomElement;
  10781. Object.defineProperty(app.config, 'isCustomElement', {
  10782. get() {
  10783. return isCustomElement;
  10784. },
  10785. set() {
  10786. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10787. `\`compilerOptions.isCustomElement\` instead.`);
  10788. }
  10789. });
  10790. const compilerOptions = app.config.compilerOptions;
  10791. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10792. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10793. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10794. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10795. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10796. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10797. `- 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`;
  10798. Object.defineProperty(app.config, 'compilerOptions', {
  10799. get() {
  10800. warn$1(msg);
  10801. return compilerOptions;
  10802. },
  10803. set() {
  10804. warn$1(msg);
  10805. }
  10806. });
  10807. }
  10808. }
  10809. function normalizeContainer(container) {
  10810. if (isString(container)) {
  10811. const res = document.querySelector(container);
  10812. if (!res) {
  10813. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10814. }
  10815. return res;
  10816. }
  10817. if (window.ShadowRoot &&
  10818. container instanceof window.ShadowRoot &&
  10819. container.mode === 'closed') {
  10820. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10821. }
  10822. return container;
  10823. }
  10824. /**
  10825. * @internal
  10826. */
  10827. const initDirectivesForSSR = NOOP;
  10828. function initDev() {
  10829. {
  10830. {
  10831. console.info(`You are running a development build of Vue.\n` +
  10832. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10833. }
  10834. initCustomFormatter();
  10835. }
  10836. }
  10837. function defaultOnError(error) {
  10838. throw error;
  10839. }
  10840. function defaultOnWarn(msg) {
  10841. console.warn(`[Vue warn] ${msg.message}`);
  10842. }
  10843. function createCompilerError(code, loc, messages, additionalMessage) {
  10844. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  10845. ;
  10846. const error = new SyntaxError(String(msg));
  10847. error.code = code;
  10848. error.loc = loc;
  10849. return error;
  10850. }
  10851. const errorMessages = {
  10852. // parse errors
  10853. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  10854. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  10855. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  10856. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  10857. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  10858. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  10859. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  10860. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  10861. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  10862. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  10863. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  10864. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  10865. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  10866. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  10867. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  10868. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  10869. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  10870. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  10871. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  10872. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  10873. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  10874. [20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  10875. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  10876. // Vue-specific parse errors
  10877. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  10878. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  10879. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  10880. [27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  10881. 'Note that dynamic directive argument cannot contain spaces.',
  10882. [26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  10883. // transform errors
  10884. [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  10885. [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  10886. [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  10887. [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  10888. [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  10889. [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  10890. [34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  10891. [35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  10892. [36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  10893. [37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  10894. `When there are multiple named slots, all slots should use <template> ` +
  10895. `syntax to avoid scope ambiguity.`,
  10896. [38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  10897. [39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  10898. `default slot. These children will be ignored.`,
  10899. [40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  10900. [41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  10901. [42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  10902. [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.`,
  10903. [44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  10904. [45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  10905. // generic errors
  10906. [46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  10907. [47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  10908. [48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  10909. [49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  10910. // just to fulfill types
  10911. [50 /* __EXTEND_POINT__ */]: ``
  10912. };
  10913. const FRAGMENT = Symbol(`Fragment` );
  10914. const TELEPORT = Symbol(`Teleport` );
  10915. const SUSPENSE = Symbol(`Suspense` );
  10916. const KEEP_ALIVE = Symbol(`KeepAlive` );
  10917. const BASE_TRANSITION = Symbol(`BaseTransition` );
  10918. const OPEN_BLOCK = Symbol(`openBlock` );
  10919. const CREATE_BLOCK = Symbol(`createBlock` );
  10920. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  10921. const CREATE_VNODE = Symbol(`createVNode` );
  10922. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  10923. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  10924. const CREATE_TEXT = Symbol(`createTextVNode` );
  10925. const CREATE_STATIC = Symbol(`createStaticVNode` );
  10926. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  10927. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  10928. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  10929. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  10930. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  10931. const RENDER_LIST = Symbol(`renderList` );
  10932. const RENDER_SLOT = Symbol(`renderSlot` );
  10933. const CREATE_SLOTS = Symbol(`createSlots` );
  10934. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  10935. const MERGE_PROPS = Symbol(`mergeProps` );
  10936. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  10937. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  10938. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  10939. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  10940. const TO_HANDLERS = Symbol(`toHandlers` );
  10941. const CAMELIZE = Symbol(`camelize` );
  10942. const CAPITALIZE = Symbol(`capitalize` );
  10943. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  10944. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  10945. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  10946. const POP_SCOPE_ID = Symbol(`popScopeId` );
  10947. const WITH_CTX = Symbol(`withCtx` );
  10948. const UNREF = Symbol(`unref` );
  10949. const IS_REF = Symbol(`isRef` );
  10950. const WITH_MEMO = Symbol(`withMemo` );
  10951. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  10952. // Name mapping for runtime helpers that need to be imported from 'vue' in
  10953. // generated code. Make sure these are correctly exported in the runtime!
  10954. // Using `any` here because TS doesn't allow symbols as index type.
  10955. const helperNameMap = {
  10956. [FRAGMENT]: `Fragment`,
  10957. [TELEPORT]: `Teleport`,
  10958. [SUSPENSE]: `Suspense`,
  10959. [KEEP_ALIVE]: `KeepAlive`,
  10960. [BASE_TRANSITION]: `BaseTransition`,
  10961. [OPEN_BLOCK]: `openBlock`,
  10962. [CREATE_BLOCK]: `createBlock`,
  10963. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  10964. [CREATE_VNODE]: `createVNode`,
  10965. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  10966. [CREATE_COMMENT]: `createCommentVNode`,
  10967. [CREATE_TEXT]: `createTextVNode`,
  10968. [CREATE_STATIC]: `createStaticVNode`,
  10969. [RESOLVE_COMPONENT]: `resolveComponent`,
  10970. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  10971. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  10972. [RESOLVE_FILTER]: `resolveFilter`,
  10973. [WITH_DIRECTIVES]: `withDirectives`,
  10974. [RENDER_LIST]: `renderList`,
  10975. [RENDER_SLOT]: `renderSlot`,
  10976. [CREATE_SLOTS]: `createSlots`,
  10977. [TO_DISPLAY_STRING]: `toDisplayString`,
  10978. [MERGE_PROPS]: `mergeProps`,
  10979. [NORMALIZE_CLASS]: `normalizeClass`,
  10980. [NORMALIZE_STYLE]: `normalizeStyle`,
  10981. [NORMALIZE_PROPS]: `normalizeProps`,
  10982. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  10983. [TO_HANDLERS]: `toHandlers`,
  10984. [CAMELIZE]: `camelize`,
  10985. [CAPITALIZE]: `capitalize`,
  10986. [TO_HANDLER_KEY]: `toHandlerKey`,
  10987. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  10988. [PUSH_SCOPE_ID]: `pushScopeId`,
  10989. [POP_SCOPE_ID]: `popScopeId`,
  10990. [WITH_CTX]: `withCtx`,
  10991. [UNREF]: `unref`,
  10992. [IS_REF]: `isRef`,
  10993. [WITH_MEMO]: `withMemo`,
  10994. [IS_MEMO_SAME]: `isMemoSame`
  10995. };
  10996. function registerRuntimeHelpers(helpers) {
  10997. Object.getOwnPropertySymbols(helpers).forEach(s => {
  10998. helperNameMap[s] = helpers[s];
  10999. });
  11000. }
  11001. // AST Utilities ---------------------------------------------------------------
  11002. // Some expressions, e.g. sequence and conditional expressions, are never
  11003. // associated with template nodes, so their source locations are just a stub.
  11004. // Container types like CompoundExpression also don't need a real location.
  11005. const locStub = {
  11006. source: '',
  11007. start: { line: 1, column: 1, offset: 0 },
  11008. end: { line: 1, column: 1, offset: 0 }
  11009. };
  11010. function createRoot(children, loc = locStub) {
  11011. return {
  11012. type: 0 /* ROOT */,
  11013. children,
  11014. helpers: [],
  11015. components: [],
  11016. directives: [],
  11017. hoists: [],
  11018. imports: [],
  11019. cached: 0,
  11020. temps: 0,
  11021. codegenNode: undefined,
  11022. loc
  11023. };
  11024. }
  11025. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  11026. if (context) {
  11027. if (isBlock) {
  11028. context.helper(OPEN_BLOCK);
  11029. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  11030. }
  11031. else {
  11032. context.helper(getVNodeHelper(context.inSSR, isComponent));
  11033. }
  11034. if (directives) {
  11035. context.helper(WITH_DIRECTIVES);
  11036. }
  11037. }
  11038. return {
  11039. type: 13 /* VNODE_CALL */,
  11040. tag,
  11041. props,
  11042. children,
  11043. patchFlag,
  11044. dynamicProps,
  11045. directives,
  11046. isBlock,
  11047. disableTracking,
  11048. isComponent,
  11049. loc
  11050. };
  11051. }
  11052. function createArrayExpression(elements, loc = locStub) {
  11053. return {
  11054. type: 17 /* JS_ARRAY_EXPRESSION */,
  11055. loc,
  11056. elements
  11057. };
  11058. }
  11059. function createObjectExpression(properties, loc = locStub) {
  11060. return {
  11061. type: 15 /* JS_OBJECT_EXPRESSION */,
  11062. loc,
  11063. properties
  11064. };
  11065. }
  11066. function createObjectProperty(key, value) {
  11067. return {
  11068. type: 16 /* JS_PROPERTY */,
  11069. loc: locStub,
  11070. key: isString(key) ? createSimpleExpression(key, true) : key,
  11071. value
  11072. };
  11073. }
  11074. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  11075. return {
  11076. type: 4 /* SIMPLE_EXPRESSION */,
  11077. loc,
  11078. content,
  11079. isStatic,
  11080. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  11081. };
  11082. }
  11083. function createCompoundExpression(children, loc = locStub) {
  11084. return {
  11085. type: 8 /* COMPOUND_EXPRESSION */,
  11086. loc,
  11087. children
  11088. };
  11089. }
  11090. function createCallExpression(callee, args = [], loc = locStub) {
  11091. return {
  11092. type: 14 /* JS_CALL_EXPRESSION */,
  11093. loc,
  11094. callee,
  11095. arguments: args
  11096. };
  11097. }
  11098. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  11099. return {
  11100. type: 18 /* JS_FUNCTION_EXPRESSION */,
  11101. params,
  11102. returns,
  11103. newline,
  11104. isSlot,
  11105. loc
  11106. };
  11107. }
  11108. function createConditionalExpression(test, consequent, alternate, newline = true) {
  11109. return {
  11110. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  11111. test,
  11112. consequent,
  11113. alternate,
  11114. newline,
  11115. loc: locStub
  11116. };
  11117. }
  11118. function createCacheExpression(index, value, isVNode = false) {
  11119. return {
  11120. type: 20 /* JS_CACHE_EXPRESSION */,
  11121. index,
  11122. value,
  11123. isVNode,
  11124. loc: locStub
  11125. };
  11126. }
  11127. function createBlockStatement(body) {
  11128. return {
  11129. type: 21 /* JS_BLOCK_STATEMENT */,
  11130. body,
  11131. loc: locStub
  11132. };
  11133. }
  11134. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  11135. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  11136. function isCoreComponent(tag) {
  11137. if (isBuiltInType(tag, 'Teleport')) {
  11138. return TELEPORT;
  11139. }
  11140. else if (isBuiltInType(tag, 'Suspense')) {
  11141. return SUSPENSE;
  11142. }
  11143. else if (isBuiltInType(tag, 'KeepAlive')) {
  11144. return KEEP_ALIVE;
  11145. }
  11146. else if (isBuiltInType(tag, 'BaseTransition')) {
  11147. return BASE_TRANSITION;
  11148. }
  11149. }
  11150. const nonIdentifierRE = /^\d|[^\$\w]/;
  11151. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  11152. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  11153. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  11154. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  11155. /**
  11156. * Simple lexer to check if an expression is a member expression. This is
  11157. * lax and only checks validity at the root level (i.e. does not validate exps
  11158. * inside square brackets), but it's ok since these are only used on template
  11159. * expressions and false positives are invalid expressions in the first place.
  11160. */
  11161. const isMemberExpressionBrowser = (path) => {
  11162. // remove whitespaces around . or [ first
  11163. path = path.trim().replace(whitespaceRE, s => s.trim());
  11164. let state = 0 /* inMemberExp */;
  11165. let stateStack = [];
  11166. let currentOpenBracketCount = 0;
  11167. let currentOpenParensCount = 0;
  11168. let currentStringType = null;
  11169. for (let i = 0; i < path.length; i++) {
  11170. const char = path.charAt(i);
  11171. switch (state) {
  11172. case 0 /* inMemberExp */:
  11173. if (char === '[') {
  11174. stateStack.push(state);
  11175. state = 1 /* inBrackets */;
  11176. currentOpenBracketCount++;
  11177. }
  11178. else if (char === '(') {
  11179. stateStack.push(state);
  11180. state = 2 /* inParens */;
  11181. currentOpenParensCount++;
  11182. }
  11183. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  11184. return false;
  11185. }
  11186. break;
  11187. case 1 /* inBrackets */:
  11188. if (char === `'` || char === `"` || char === '`') {
  11189. stateStack.push(state);
  11190. state = 3 /* inString */;
  11191. currentStringType = char;
  11192. }
  11193. else if (char === `[`) {
  11194. currentOpenBracketCount++;
  11195. }
  11196. else if (char === `]`) {
  11197. if (!--currentOpenBracketCount) {
  11198. state = stateStack.pop();
  11199. }
  11200. }
  11201. break;
  11202. case 2 /* inParens */:
  11203. if (char === `'` || char === `"` || char === '`') {
  11204. stateStack.push(state);
  11205. state = 3 /* inString */;
  11206. currentStringType = char;
  11207. }
  11208. else if (char === `(`) {
  11209. currentOpenParensCount++;
  11210. }
  11211. else if (char === `)`) {
  11212. // if the exp ends as a call then it should not be considered valid
  11213. if (i === path.length - 1) {
  11214. return false;
  11215. }
  11216. if (!--currentOpenParensCount) {
  11217. state = stateStack.pop();
  11218. }
  11219. }
  11220. break;
  11221. case 3 /* inString */:
  11222. if (char === currentStringType) {
  11223. state = stateStack.pop();
  11224. currentStringType = null;
  11225. }
  11226. break;
  11227. }
  11228. }
  11229. return !currentOpenBracketCount && !currentOpenParensCount;
  11230. };
  11231. const isMemberExpression = isMemberExpressionBrowser
  11232. ;
  11233. function getInnerRange(loc, offset, length) {
  11234. const source = loc.source.slice(offset, offset + length);
  11235. const newLoc = {
  11236. source,
  11237. start: advancePositionWithClone(loc.start, loc.source, offset),
  11238. end: loc.end
  11239. };
  11240. if (length != null) {
  11241. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  11242. }
  11243. return newLoc;
  11244. }
  11245. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  11246. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  11247. }
  11248. // advance by mutation without cloning (for performance reasons), since this
  11249. // gets called a lot in the parser
  11250. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  11251. let linesCount = 0;
  11252. let lastNewLinePos = -1;
  11253. for (let i = 0; i < numberOfCharacters; i++) {
  11254. if (source.charCodeAt(i) === 10 /* newline char code */) {
  11255. linesCount++;
  11256. lastNewLinePos = i;
  11257. }
  11258. }
  11259. pos.offset += numberOfCharacters;
  11260. pos.line += linesCount;
  11261. pos.column =
  11262. lastNewLinePos === -1
  11263. ? pos.column + numberOfCharacters
  11264. : numberOfCharacters - lastNewLinePos;
  11265. return pos;
  11266. }
  11267. function assert(condition, msg) {
  11268. /* istanbul ignore if */
  11269. if (!condition) {
  11270. throw new Error(msg || `unexpected compiler condition`);
  11271. }
  11272. }
  11273. function findDir(node, name, allowEmpty = false) {
  11274. for (let i = 0; i < node.props.length; i++) {
  11275. const p = node.props[i];
  11276. if (p.type === 7 /* DIRECTIVE */ &&
  11277. (allowEmpty || p.exp) &&
  11278. (isString(name) ? p.name === name : name.test(p.name))) {
  11279. return p;
  11280. }
  11281. }
  11282. }
  11283. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  11284. for (let i = 0; i < node.props.length; i++) {
  11285. const p = node.props[i];
  11286. if (p.type === 6 /* ATTRIBUTE */) {
  11287. if (dynamicOnly)
  11288. continue;
  11289. if (p.name === name && (p.value || allowEmpty)) {
  11290. return p;
  11291. }
  11292. }
  11293. else if (p.name === 'bind' &&
  11294. (p.exp || allowEmpty) &&
  11295. isStaticArgOf(p.arg, name)) {
  11296. return p;
  11297. }
  11298. }
  11299. }
  11300. function isStaticArgOf(arg, name) {
  11301. return !!(arg && isStaticExp(arg) && arg.content === name);
  11302. }
  11303. function hasDynamicKeyVBind(node) {
  11304. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  11305. p.name === 'bind' &&
  11306. (!p.arg || // v-bind="obj"
  11307. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  11308. !p.arg.isStatic) // v-bind:[foo]
  11309. );
  11310. }
  11311. function isText(node) {
  11312. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  11313. }
  11314. function isVSlot(p) {
  11315. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  11316. }
  11317. function isTemplateNode(node) {
  11318. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  11319. }
  11320. function isSlotOutlet(node) {
  11321. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  11322. }
  11323. function getVNodeHelper(ssr, isComponent) {
  11324. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  11325. }
  11326. function getVNodeBlockHelper(ssr, isComponent) {
  11327. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  11328. }
  11329. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  11330. function getUnnormalizedProps(props, callPath = []) {
  11331. if (props &&
  11332. !isString(props) &&
  11333. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11334. const callee = props.callee;
  11335. if (!isString(callee) && propsHelperSet.has(callee)) {
  11336. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  11337. }
  11338. }
  11339. return [props, callPath];
  11340. }
  11341. function injectProp(node, prop, context) {
  11342. let propsWithInjection;
  11343. /**
  11344. * 1. mergeProps(...)
  11345. * 2. toHandlers(...)
  11346. * 3. normalizeProps(...)
  11347. * 4. normalizeProps(guardReactiveProps(...))
  11348. *
  11349. * we need to get the real props before normalization
  11350. */
  11351. let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  11352. let callPath = [];
  11353. let parentCall;
  11354. if (props &&
  11355. !isString(props) &&
  11356. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11357. const ret = getUnnormalizedProps(props);
  11358. props = ret[0];
  11359. callPath = ret[1];
  11360. parentCall = callPath[callPath.length - 1];
  11361. }
  11362. if (props == null || isString(props)) {
  11363. propsWithInjection = createObjectExpression([prop]);
  11364. }
  11365. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  11366. // merged props... add ours
  11367. // only inject key to object literal if it's the first argument so that
  11368. // if doesn't override user provided keys
  11369. const first = props.arguments[0];
  11370. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11371. first.properties.unshift(prop);
  11372. }
  11373. else {
  11374. if (props.callee === TO_HANDLERS) {
  11375. // #2366
  11376. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11377. createObjectExpression([prop]),
  11378. props
  11379. ]);
  11380. }
  11381. else {
  11382. props.arguments.unshift(createObjectExpression([prop]));
  11383. }
  11384. }
  11385. !propsWithInjection && (propsWithInjection = props);
  11386. }
  11387. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11388. let alreadyExists = false;
  11389. // check existing key to avoid overriding user provided keys
  11390. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  11391. const propKeyName = prop.key.content;
  11392. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  11393. p.key.content === propKeyName);
  11394. }
  11395. if (!alreadyExists) {
  11396. props.properties.unshift(prop);
  11397. }
  11398. propsWithInjection = props;
  11399. }
  11400. else {
  11401. // single v-bind with expression, return a merged replacement
  11402. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11403. createObjectExpression([prop]),
  11404. props
  11405. ]);
  11406. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  11407. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  11408. // the `guardReactiveProps` will no longer be needed
  11409. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  11410. parentCall = callPath[callPath.length - 2];
  11411. }
  11412. }
  11413. if (node.type === 13 /* VNODE_CALL */) {
  11414. if (parentCall) {
  11415. parentCall.arguments[0] = propsWithInjection;
  11416. }
  11417. else {
  11418. node.props = propsWithInjection;
  11419. }
  11420. }
  11421. else {
  11422. if (parentCall) {
  11423. parentCall.arguments[0] = propsWithInjection;
  11424. }
  11425. else {
  11426. node.arguments[2] = propsWithInjection;
  11427. }
  11428. }
  11429. }
  11430. function toValidAssetId(name, type) {
  11431. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  11432. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  11433. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  11434. })}`;
  11435. }
  11436. function getMemoedVNodeCall(node) {
  11437. if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  11438. return node.arguments[1].returns;
  11439. }
  11440. else {
  11441. return node;
  11442. }
  11443. }
  11444. function makeBlock(node, { helper, removeHelper, inSSR }) {
  11445. if (!node.isBlock) {
  11446. node.isBlock = true;
  11447. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  11448. helper(OPEN_BLOCK);
  11449. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  11450. }
  11451. }
  11452. const deprecationData = {
  11453. ["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
  11454. message: `Platform-native elements with "is" prop will no longer be ` +
  11455. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  11456. `prefixed with "vue:".`,
  11457. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  11458. },
  11459. ["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
  11460. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  11461. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  11462. `\`v-model:${key}\`.`,
  11463. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  11464. },
  11465. ["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
  11466. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  11467. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  11468. },
  11469. ["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
  11470. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  11471. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  11472. `that appears before v-bind in the case of conflict. ` +
  11473. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  11474. `You can also suppress this warning if the usage is intended.`,
  11475. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  11476. },
  11477. ["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
  11478. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  11479. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  11480. },
  11481. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  11482. message: `v-if / v-for precedence when used on the same element has changed ` +
  11483. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  11484. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  11485. `with <template> tags or use a computed property that filters v-for ` +
  11486. `data source.`,
  11487. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  11488. },
  11489. ["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
  11490. message: `<template> with no special directives will render as a native template ` +
  11491. `element instead of its inner content in Vue 3.`
  11492. },
  11493. ["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
  11494. message: `"inline-template" has been removed in Vue 3.`,
  11495. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  11496. },
  11497. ["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
  11498. message: `filters have been removed in Vue 3. ` +
  11499. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  11500. `Use method calls or computed properties instead.`,
  11501. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  11502. }
  11503. };
  11504. function getCompatValue(key, context) {
  11505. const config = context.options
  11506. ? context.options.compatConfig
  11507. : context.compatConfig;
  11508. const value = config && config[key];
  11509. if (key === 'MODE') {
  11510. return value || 3; // compiler defaults to v3 behavior
  11511. }
  11512. else {
  11513. return value;
  11514. }
  11515. }
  11516. function isCompatEnabled(key, context) {
  11517. const mode = getCompatValue('MODE', context);
  11518. const value = getCompatValue(key, context);
  11519. // in v3 mode, only enable if explicitly set to true
  11520. // otherwise enable for any non-false value
  11521. return mode === 3 ? value === true : value !== false;
  11522. }
  11523. function checkCompatEnabled(key, context, loc, ...args) {
  11524. const enabled = isCompatEnabled(key, context);
  11525. if (enabled) {
  11526. warnDeprecation(key, context, loc, ...args);
  11527. }
  11528. return enabled;
  11529. }
  11530. function warnDeprecation(key, context, loc, ...args) {
  11531. const val = getCompatValue(key, context);
  11532. if (val === 'suppress-warning') {
  11533. return;
  11534. }
  11535. const { message, link } = deprecationData[key];
  11536. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  11537. const err = new SyntaxError(msg);
  11538. err.code = key;
  11539. if (loc)
  11540. err.loc = loc;
  11541. context.onWarn(err);
  11542. }
  11543. // The default decoder only provides escapes for characters reserved as part of
  11544. // the template syntax, and is only used if the custom renderer did not provide
  11545. // a platform-specific decoder.
  11546. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  11547. const decodeMap = {
  11548. gt: '>',
  11549. lt: '<',
  11550. amp: '&',
  11551. apos: "'",
  11552. quot: '"'
  11553. };
  11554. const defaultParserOptions = {
  11555. delimiters: [`{{`, `}}`],
  11556. getNamespace: () => 0 /* HTML */,
  11557. getTextMode: () => 0 /* DATA */,
  11558. isVoidTag: NO,
  11559. isPreTag: NO,
  11560. isCustomElement: NO,
  11561. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  11562. onError: defaultOnError,
  11563. onWarn: defaultOnWarn,
  11564. comments: true
  11565. };
  11566. function baseParse(content, options = {}) {
  11567. const context = createParserContext(content, options);
  11568. const start = getCursor(context);
  11569. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  11570. }
  11571. function createParserContext(content, rawOptions) {
  11572. const options = extend({}, defaultParserOptions);
  11573. let key;
  11574. for (key in rawOptions) {
  11575. // @ts-ignore
  11576. options[key] =
  11577. rawOptions[key] === undefined
  11578. ? defaultParserOptions[key]
  11579. : rawOptions[key];
  11580. }
  11581. return {
  11582. options,
  11583. column: 1,
  11584. line: 1,
  11585. offset: 0,
  11586. originalSource: content,
  11587. source: content,
  11588. inPre: false,
  11589. inVPre: false,
  11590. onWarn: options.onWarn
  11591. };
  11592. }
  11593. function parseChildren(context, mode, ancestors) {
  11594. const parent = last(ancestors);
  11595. const ns = parent ? parent.ns : 0 /* HTML */;
  11596. const nodes = [];
  11597. while (!isEnd(context, mode, ancestors)) {
  11598. const s = context.source;
  11599. let node = undefined;
  11600. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  11601. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  11602. // '{{'
  11603. node = parseInterpolation(context, mode);
  11604. }
  11605. else if (mode === 0 /* DATA */ && s[0] === '<') {
  11606. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  11607. if (s.length === 1) {
  11608. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  11609. }
  11610. else if (s[1] === '!') {
  11611. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  11612. if (startsWith(s, '<!--')) {
  11613. node = parseComment(context);
  11614. }
  11615. else if (startsWith(s, '<!DOCTYPE')) {
  11616. // Ignore DOCTYPE by a limitation.
  11617. node = parseBogusComment(context);
  11618. }
  11619. else if (startsWith(s, '<![CDATA[')) {
  11620. if (ns !== 0 /* HTML */) {
  11621. node = parseCDATA(context, ancestors);
  11622. }
  11623. else {
  11624. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  11625. node = parseBogusComment(context);
  11626. }
  11627. }
  11628. else {
  11629. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  11630. node = parseBogusComment(context);
  11631. }
  11632. }
  11633. else if (s[1] === '/') {
  11634. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  11635. if (s.length === 2) {
  11636. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  11637. }
  11638. else if (s[2] === '>') {
  11639. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  11640. advanceBy(context, 3);
  11641. continue;
  11642. }
  11643. else if (/[a-z]/i.test(s[2])) {
  11644. emitError(context, 23 /* X_INVALID_END_TAG */);
  11645. parseTag(context, 1 /* End */, parent);
  11646. continue;
  11647. }
  11648. else {
  11649. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  11650. node = parseBogusComment(context);
  11651. }
  11652. }
  11653. else if (/[a-z]/i.test(s[1])) {
  11654. node = parseElement(context, ancestors);
  11655. }
  11656. else if (s[1] === '?') {
  11657. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  11658. node = parseBogusComment(context);
  11659. }
  11660. else {
  11661. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  11662. }
  11663. }
  11664. }
  11665. if (!node) {
  11666. node = parseText(context, mode);
  11667. }
  11668. if (isArray(node)) {
  11669. for (let i = 0; i < node.length; i++) {
  11670. pushNode(nodes, node[i]);
  11671. }
  11672. }
  11673. else {
  11674. pushNode(nodes, node);
  11675. }
  11676. }
  11677. // Whitespace handling strategy like v2
  11678. let removedWhitespace = false;
  11679. if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
  11680. const shouldCondense = context.options.whitespace !== 'preserve';
  11681. for (let i = 0; i < nodes.length; i++) {
  11682. const node = nodes[i];
  11683. if (!context.inPre && node.type === 2 /* TEXT */) {
  11684. if (!/[^\t\r\n\f ]/.test(node.content)) {
  11685. const prev = nodes[i - 1];
  11686. const next = nodes[i + 1];
  11687. // Remove if:
  11688. // - the whitespace is the first or last node, or:
  11689. // - (condense mode) the whitespace is adjacent to a comment, or:
  11690. // - (condense mode) the whitespace is between two elements AND contains newline
  11691. if (!prev ||
  11692. !next ||
  11693. (shouldCondense &&
  11694. (prev.type === 3 /* COMMENT */ ||
  11695. next.type === 3 /* COMMENT */ ||
  11696. (prev.type === 1 /* ELEMENT */ &&
  11697. next.type === 1 /* ELEMENT */ &&
  11698. /[\r\n]/.test(node.content))))) {
  11699. removedWhitespace = true;
  11700. nodes[i] = null;
  11701. }
  11702. else {
  11703. // Otherwise, the whitespace is condensed into a single space
  11704. node.content = ' ';
  11705. }
  11706. }
  11707. else if (shouldCondense) {
  11708. // in condense mode, consecutive whitespaces in text are condensed
  11709. // down to a single space.
  11710. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  11711. }
  11712. }
  11713. // Remove comment nodes if desired by configuration.
  11714. else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
  11715. removedWhitespace = true;
  11716. nodes[i] = null;
  11717. }
  11718. }
  11719. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  11720. // remove leading newline per html spec
  11721. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  11722. const first = nodes[0];
  11723. if (first && first.type === 2 /* TEXT */) {
  11724. first.content = first.content.replace(/^\r?\n/, '');
  11725. }
  11726. }
  11727. }
  11728. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  11729. }
  11730. function pushNode(nodes, node) {
  11731. if (node.type === 2 /* TEXT */) {
  11732. const prev = last(nodes);
  11733. // Merge if both this and the previous node are text and those are
  11734. // consecutive. This happens for cases like "a < b".
  11735. if (prev &&
  11736. prev.type === 2 /* TEXT */ &&
  11737. prev.loc.end.offset === node.loc.start.offset) {
  11738. prev.content += node.content;
  11739. prev.loc.end = node.loc.end;
  11740. prev.loc.source += node.loc.source;
  11741. return;
  11742. }
  11743. }
  11744. nodes.push(node);
  11745. }
  11746. function parseCDATA(context, ancestors) {
  11747. advanceBy(context, 9);
  11748. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  11749. if (context.source.length === 0) {
  11750. emitError(context, 6 /* EOF_IN_CDATA */);
  11751. }
  11752. else {
  11753. advanceBy(context, 3);
  11754. }
  11755. return nodes;
  11756. }
  11757. function parseComment(context) {
  11758. const start = getCursor(context);
  11759. let content;
  11760. // Regular comment.
  11761. const match = /--(\!)?>/.exec(context.source);
  11762. if (!match) {
  11763. content = context.source.slice(4);
  11764. advanceBy(context, context.source.length);
  11765. emitError(context, 7 /* EOF_IN_COMMENT */);
  11766. }
  11767. else {
  11768. if (match.index <= 3) {
  11769. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  11770. }
  11771. if (match[1]) {
  11772. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  11773. }
  11774. content = context.source.slice(4, match.index);
  11775. // Advancing with reporting nested comments.
  11776. const s = context.source.slice(0, match.index);
  11777. let prevIndex = 1, nestedIndex = 0;
  11778. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  11779. advanceBy(context, nestedIndex - prevIndex + 1);
  11780. if (nestedIndex + 4 < s.length) {
  11781. emitError(context, 16 /* NESTED_COMMENT */);
  11782. }
  11783. prevIndex = nestedIndex + 1;
  11784. }
  11785. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  11786. }
  11787. return {
  11788. type: 3 /* COMMENT */,
  11789. content,
  11790. loc: getSelection(context, start)
  11791. };
  11792. }
  11793. function parseBogusComment(context) {
  11794. const start = getCursor(context);
  11795. const contentStart = context.source[1] === '?' ? 1 : 2;
  11796. let content;
  11797. const closeIndex = context.source.indexOf('>');
  11798. if (closeIndex === -1) {
  11799. content = context.source.slice(contentStart);
  11800. advanceBy(context, context.source.length);
  11801. }
  11802. else {
  11803. content = context.source.slice(contentStart, closeIndex);
  11804. advanceBy(context, closeIndex + 1);
  11805. }
  11806. return {
  11807. type: 3 /* COMMENT */,
  11808. content,
  11809. loc: getSelection(context, start)
  11810. };
  11811. }
  11812. function parseElement(context, ancestors) {
  11813. // Start tag.
  11814. const wasInPre = context.inPre;
  11815. const wasInVPre = context.inVPre;
  11816. const parent = last(ancestors);
  11817. const element = parseTag(context, 0 /* Start */, parent);
  11818. const isPreBoundary = context.inPre && !wasInPre;
  11819. const isVPreBoundary = context.inVPre && !wasInVPre;
  11820. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  11821. // #4030 self-closing <pre> tag
  11822. if (isPreBoundary) {
  11823. context.inPre = false;
  11824. }
  11825. if (isVPreBoundary) {
  11826. context.inVPre = false;
  11827. }
  11828. return element;
  11829. }
  11830. // Children.
  11831. ancestors.push(element);
  11832. const mode = context.options.getTextMode(element, parent);
  11833. const children = parseChildren(context, mode, ancestors);
  11834. ancestors.pop();
  11835. element.children = children;
  11836. // End tag.
  11837. if (startsWithEndTagOpen(context.source, element.tag)) {
  11838. parseTag(context, 1 /* End */, parent);
  11839. }
  11840. else {
  11841. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  11842. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  11843. const first = children[0];
  11844. if (first && startsWith(first.loc.source, '<!--')) {
  11845. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  11846. }
  11847. }
  11848. }
  11849. element.loc = getSelection(context, element.loc.start);
  11850. if (isPreBoundary) {
  11851. context.inPre = false;
  11852. }
  11853. if (isVPreBoundary) {
  11854. context.inVPre = false;
  11855. }
  11856. return element;
  11857. }
  11858. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  11859. function parseTag(context, type, parent) {
  11860. // Tag open.
  11861. const start = getCursor(context);
  11862. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  11863. const tag = match[1];
  11864. const ns = context.options.getNamespace(tag, parent);
  11865. advanceBy(context, match[0].length);
  11866. advanceSpaces(context);
  11867. // save current state in case we need to re-parse attributes with v-pre
  11868. const cursor = getCursor(context);
  11869. const currentSource = context.source;
  11870. // check <pre> tag
  11871. if (context.options.isPreTag(tag)) {
  11872. context.inPre = true;
  11873. }
  11874. // Attributes.
  11875. let props = parseAttributes(context, type);
  11876. // check v-pre
  11877. if (type === 0 /* Start */ &&
  11878. !context.inVPre &&
  11879. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  11880. context.inVPre = true;
  11881. // reset context
  11882. extend(context, cursor);
  11883. context.source = currentSource;
  11884. // re-parse attrs and filter out v-pre itself
  11885. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  11886. }
  11887. // Tag close.
  11888. let isSelfClosing = false;
  11889. if (context.source.length === 0) {
  11890. emitError(context, 9 /* EOF_IN_TAG */);
  11891. }
  11892. else {
  11893. isSelfClosing = startsWith(context.source, '/>');
  11894. if (type === 1 /* End */ && isSelfClosing) {
  11895. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  11896. }
  11897. advanceBy(context, isSelfClosing ? 2 : 1);
  11898. }
  11899. if (type === 1 /* End */) {
  11900. return;
  11901. }
  11902. let tagType = 0 /* ELEMENT */;
  11903. if (!context.inVPre) {
  11904. if (tag === 'slot') {
  11905. tagType = 2 /* SLOT */;
  11906. }
  11907. else if (tag === 'template') {
  11908. if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  11909. tagType = 3 /* TEMPLATE */;
  11910. }
  11911. }
  11912. else if (isComponent(tag, props, context)) {
  11913. tagType = 1 /* COMPONENT */;
  11914. }
  11915. }
  11916. return {
  11917. type: 1 /* ELEMENT */,
  11918. ns,
  11919. tag,
  11920. tagType,
  11921. props,
  11922. isSelfClosing,
  11923. children: [],
  11924. loc: getSelection(context, start),
  11925. codegenNode: undefined // to be created during transform phase
  11926. };
  11927. }
  11928. function isComponent(tag, props, context) {
  11929. const options = context.options;
  11930. if (options.isCustomElement(tag)) {
  11931. return false;
  11932. }
  11933. if (tag === 'component' ||
  11934. /^[A-Z]/.test(tag) ||
  11935. isCoreComponent(tag) ||
  11936. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  11937. (options.isNativeTag && !options.isNativeTag(tag))) {
  11938. return true;
  11939. }
  11940. // at this point the tag should be a native tag, but check for potential "is"
  11941. // casting
  11942. for (let i = 0; i < props.length; i++) {
  11943. const p = props[i];
  11944. if (p.type === 6 /* ATTRIBUTE */) {
  11945. if (p.name === 'is' && p.value) {
  11946. if (p.value.content.startsWith('vue:')) {
  11947. return true;
  11948. }
  11949. }
  11950. }
  11951. else {
  11952. // directive
  11953. // v-is (TODO Deprecate)
  11954. if (p.name === 'is') {
  11955. return true;
  11956. }
  11957. else if (
  11958. // :is on plain element - only treat as component in compat mode
  11959. p.name === 'bind' &&
  11960. isStaticArgOf(p.arg, 'is') &&
  11961. false &&
  11962. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  11963. return true;
  11964. }
  11965. }
  11966. }
  11967. }
  11968. function parseAttributes(context, type) {
  11969. const props = [];
  11970. const attributeNames = new Set();
  11971. while (context.source.length > 0 &&
  11972. !startsWith(context.source, '>') &&
  11973. !startsWith(context.source, '/>')) {
  11974. if (startsWith(context.source, '/')) {
  11975. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  11976. advanceBy(context, 1);
  11977. advanceSpaces(context);
  11978. continue;
  11979. }
  11980. if (type === 1 /* End */) {
  11981. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  11982. }
  11983. const attr = parseAttribute(context, attributeNames);
  11984. // Trim whitespace between class
  11985. // https://github.com/vuejs/core/issues/4251
  11986. if (attr.type === 6 /* ATTRIBUTE */ &&
  11987. attr.value &&
  11988. attr.name === 'class') {
  11989. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  11990. }
  11991. if (type === 0 /* Start */) {
  11992. props.push(attr);
  11993. }
  11994. if (/^[^\t\r\n\f />]/.test(context.source)) {
  11995. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  11996. }
  11997. advanceSpaces(context);
  11998. }
  11999. return props;
  12000. }
  12001. function parseAttribute(context, nameSet) {
  12002. // Name.
  12003. const start = getCursor(context);
  12004. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  12005. const name = match[0];
  12006. if (nameSet.has(name)) {
  12007. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  12008. }
  12009. nameSet.add(name);
  12010. if (name[0] === '=') {
  12011. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  12012. }
  12013. {
  12014. const pattern = /["'<]/g;
  12015. let m;
  12016. while ((m = pattern.exec(name))) {
  12017. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  12018. }
  12019. }
  12020. advanceBy(context, name.length);
  12021. // Value
  12022. let value = undefined;
  12023. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  12024. advanceSpaces(context);
  12025. advanceBy(context, 1);
  12026. advanceSpaces(context);
  12027. value = parseAttributeValue(context);
  12028. if (!value) {
  12029. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  12030. }
  12031. }
  12032. const loc = getSelection(context, start);
  12033. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  12034. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  12035. let isPropShorthand = startsWith(name, '.');
  12036. let dirName = match[1] ||
  12037. (isPropShorthand || startsWith(name, ':')
  12038. ? 'bind'
  12039. : startsWith(name, '@')
  12040. ? 'on'
  12041. : 'slot');
  12042. let arg;
  12043. if (match[2]) {
  12044. const isSlot = dirName === 'slot';
  12045. const startOffset = name.lastIndexOf(match[2]);
  12046. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  12047. let content = match[2];
  12048. let isStatic = true;
  12049. if (content.startsWith('[')) {
  12050. isStatic = false;
  12051. if (!content.endsWith(']')) {
  12052. emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  12053. content = content.slice(1);
  12054. }
  12055. else {
  12056. content = content.slice(1, content.length - 1);
  12057. }
  12058. }
  12059. else if (isSlot) {
  12060. // #1241 special case for v-slot: vuetify relies extensively on slot
  12061. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  12062. // supports such usage so we are keeping it consistent with 2.x.
  12063. content += match[3] || '';
  12064. }
  12065. arg = {
  12066. type: 4 /* SIMPLE_EXPRESSION */,
  12067. content,
  12068. isStatic,
  12069. constType: isStatic
  12070. ? 3 /* CAN_STRINGIFY */
  12071. : 0 /* NOT_CONSTANT */,
  12072. loc
  12073. };
  12074. }
  12075. if (value && value.isQuoted) {
  12076. const valueLoc = value.loc;
  12077. valueLoc.start.offset++;
  12078. valueLoc.start.column++;
  12079. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  12080. valueLoc.source = valueLoc.source.slice(1, -1);
  12081. }
  12082. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  12083. if (isPropShorthand)
  12084. modifiers.push('prop');
  12085. return {
  12086. type: 7 /* DIRECTIVE */,
  12087. name: dirName,
  12088. exp: value && {
  12089. type: 4 /* SIMPLE_EXPRESSION */,
  12090. content: value.content,
  12091. isStatic: false,
  12092. // Treat as non-constant by default. This can be potentially set to
  12093. // other values by `transformExpression` to make it eligible for hoisting.
  12094. constType: 0 /* NOT_CONSTANT */,
  12095. loc: value.loc
  12096. },
  12097. arg,
  12098. modifiers,
  12099. loc
  12100. };
  12101. }
  12102. // missing directive name or illegal directive name
  12103. if (!context.inVPre && startsWith(name, 'v-')) {
  12104. emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
  12105. }
  12106. return {
  12107. type: 6 /* ATTRIBUTE */,
  12108. name,
  12109. value: value && {
  12110. type: 2 /* TEXT */,
  12111. content: value.content,
  12112. loc: value.loc
  12113. },
  12114. loc
  12115. };
  12116. }
  12117. function parseAttributeValue(context) {
  12118. const start = getCursor(context);
  12119. let content;
  12120. const quote = context.source[0];
  12121. const isQuoted = quote === `"` || quote === `'`;
  12122. if (isQuoted) {
  12123. // Quoted value.
  12124. advanceBy(context, 1);
  12125. const endIndex = context.source.indexOf(quote);
  12126. if (endIndex === -1) {
  12127. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  12128. }
  12129. else {
  12130. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  12131. advanceBy(context, 1);
  12132. }
  12133. }
  12134. else {
  12135. // Unquoted
  12136. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  12137. if (!match) {
  12138. return undefined;
  12139. }
  12140. const unexpectedChars = /["'<=`]/g;
  12141. let m;
  12142. while ((m = unexpectedChars.exec(match[0]))) {
  12143. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  12144. }
  12145. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  12146. }
  12147. return { content, isQuoted, loc: getSelection(context, start) };
  12148. }
  12149. function parseInterpolation(context, mode) {
  12150. const [open, close] = context.options.delimiters;
  12151. const closeIndex = context.source.indexOf(close, open.length);
  12152. if (closeIndex === -1) {
  12153. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  12154. return undefined;
  12155. }
  12156. const start = getCursor(context);
  12157. advanceBy(context, open.length);
  12158. const innerStart = getCursor(context);
  12159. const innerEnd = getCursor(context);
  12160. const rawContentLength = closeIndex - open.length;
  12161. const rawContent = context.source.slice(0, rawContentLength);
  12162. const preTrimContent = parseTextData(context, rawContentLength, mode);
  12163. const content = preTrimContent.trim();
  12164. const startOffset = preTrimContent.indexOf(content);
  12165. if (startOffset > 0) {
  12166. advancePositionWithMutation(innerStart, rawContent, startOffset);
  12167. }
  12168. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  12169. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  12170. advanceBy(context, close.length);
  12171. return {
  12172. type: 5 /* INTERPOLATION */,
  12173. content: {
  12174. type: 4 /* SIMPLE_EXPRESSION */,
  12175. isStatic: false,
  12176. // Set `isConstant` to false by default and will decide in transformExpression
  12177. constType: 0 /* NOT_CONSTANT */,
  12178. content,
  12179. loc: getSelection(context, innerStart, innerEnd)
  12180. },
  12181. loc: getSelection(context, start)
  12182. };
  12183. }
  12184. function parseText(context, mode) {
  12185. const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  12186. let endIndex = context.source.length;
  12187. for (let i = 0; i < endTokens.length; i++) {
  12188. const index = context.source.indexOf(endTokens[i], 1);
  12189. if (index !== -1 && endIndex > index) {
  12190. endIndex = index;
  12191. }
  12192. }
  12193. const start = getCursor(context);
  12194. const content = parseTextData(context, endIndex, mode);
  12195. return {
  12196. type: 2 /* TEXT */,
  12197. content,
  12198. loc: getSelection(context, start)
  12199. };
  12200. }
  12201. /**
  12202. * Get text data with a given length from the current location.
  12203. * This translates HTML entities in the text data.
  12204. */
  12205. function parseTextData(context, length, mode) {
  12206. const rawText = context.source.slice(0, length);
  12207. advanceBy(context, length);
  12208. if (mode === 2 /* RAWTEXT */ ||
  12209. mode === 3 /* CDATA */ ||
  12210. !rawText.includes('&')) {
  12211. return rawText;
  12212. }
  12213. else {
  12214. // DATA or RCDATA containing "&"". Entity decoding required.
  12215. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  12216. }
  12217. }
  12218. function getCursor(context) {
  12219. const { column, line, offset } = context;
  12220. return { column, line, offset };
  12221. }
  12222. function getSelection(context, start, end) {
  12223. end = end || getCursor(context);
  12224. return {
  12225. start,
  12226. end,
  12227. source: context.originalSource.slice(start.offset, end.offset)
  12228. };
  12229. }
  12230. function last(xs) {
  12231. return xs[xs.length - 1];
  12232. }
  12233. function startsWith(source, searchString) {
  12234. return source.startsWith(searchString);
  12235. }
  12236. function advanceBy(context, numberOfCharacters) {
  12237. const { source } = context;
  12238. advancePositionWithMutation(context, source, numberOfCharacters);
  12239. context.source = source.slice(numberOfCharacters);
  12240. }
  12241. function advanceSpaces(context) {
  12242. const match = /^[\t\r\n\f ]+/.exec(context.source);
  12243. if (match) {
  12244. advanceBy(context, match[0].length);
  12245. }
  12246. }
  12247. function getNewPosition(context, start, numberOfCharacters) {
  12248. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  12249. }
  12250. function emitError(context, code, offset, loc = getCursor(context)) {
  12251. if (offset) {
  12252. loc.offset += offset;
  12253. loc.column += offset;
  12254. }
  12255. context.options.onError(createCompilerError(code, {
  12256. start: loc,
  12257. end: loc,
  12258. source: ''
  12259. }));
  12260. }
  12261. function isEnd(context, mode, ancestors) {
  12262. const s = context.source;
  12263. switch (mode) {
  12264. case 0 /* DATA */:
  12265. if (startsWith(s, '</')) {
  12266. // TODO: probably bad performance
  12267. for (let i = ancestors.length - 1; i >= 0; --i) {
  12268. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  12269. return true;
  12270. }
  12271. }
  12272. }
  12273. break;
  12274. case 1 /* RCDATA */:
  12275. case 2 /* RAWTEXT */: {
  12276. const parent = last(ancestors);
  12277. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  12278. return true;
  12279. }
  12280. break;
  12281. }
  12282. case 3 /* CDATA */:
  12283. if (startsWith(s, ']]>')) {
  12284. return true;
  12285. }
  12286. break;
  12287. }
  12288. return !s;
  12289. }
  12290. function startsWithEndTagOpen(source, tag) {
  12291. return (startsWith(source, '</') &&
  12292. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  12293. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  12294. }
  12295. function hoistStatic(root, context) {
  12296. walk(root, context,
  12297. // Root node is unfortunately non-hoistable due to potential parent
  12298. // fallthrough attributes.
  12299. isSingleElementRoot(root, root.children[0]));
  12300. }
  12301. function isSingleElementRoot(root, child) {
  12302. const { children } = root;
  12303. return (children.length === 1 &&
  12304. child.type === 1 /* ELEMENT */ &&
  12305. !isSlotOutlet(child));
  12306. }
  12307. function walk(node, context, doNotHoistNode = false) {
  12308. const { children } = node;
  12309. const originalCount = children.length;
  12310. let hoistedCount = 0;
  12311. for (let i = 0; i < children.length; i++) {
  12312. const child = children[i];
  12313. // only plain elements & text calls are eligible for hoisting.
  12314. if (child.type === 1 /* ELEMENT */ &&
  12315. child.tagType === 0 /* ELEMENT */) {
  12316. const constantType = doNotHoistNode
  12317. ? 0 /* NOT_CONSTANT */
  12318. : getConstantType(child, context);
  12319. if (constantType > 0 /* NOT_CONSTANT */) {
  12320. if (constantType >= 2 /* CAN_HOIST */) {
  12321. child.codegenNode.patchFlag =
  12322. -1 /* HOISTED */ + (` /* HOISTED */` );
  12323. child.codegenNode = context.hoist(child.codegenNode);
  12324. hoistedCount++;
  12325. continue;
  12326. }
  12327. }
  12328. else {
  12329. // node may contain dynamic children, but its props may be eligible for
  12330. // hoisting.
  12331. const codegenNode = child.codegenNode;
  12332. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12333. const flag = getPatchFlag(codegenNode);
  12334. if ((!flag ||
  12335. flag === 512 /* NEED_PATCH */ ||
  12336. flag === 1 /* TEXT */) &&
  12337. getGeneratedPropsConstantType(child, context) >=
  12338. 2 /* CAN_HOIST */) {
  12339. const props = getNodeProps(child);
  12340. if (props) {
  12341. codegenNode.props = context.hoist(props);
  12342. }
  12343. }
  12344. if (codegenNode.dynamicProps) {
  12345. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  12346. }
  12347. }
  12348. }
  12349. }
  12350. else if (child.type === 12 /* TEXT_CALL */ &&
  12351. getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
  12352. child.codegenNode = context.hoist(child.codegenNode);
  12353. hoistedCount++;
  12354. }
  12355. // walk further
  12356. if (child.type === 1 /* ELEMENT */) {
  12357. const isComponent = child.tagType === 1 /* COMPONENT */;
  12358. if (isComponent) {
  12359. context.scopes.vSlot++;
  12360. }
  12361. walk(child, context);
  12362. if (isComponent) {
  12363. context.scopes.vSlot--;
  12364. }
  12365. }
  12366. else if (child.type === 11 /* FOR */) {
  12367. // Do not hoist v-for single child because it has to be a block
  12368. walk(child, context, child.children.length === 1);
  12369. }
  12370. else if (child.type === 9 /* IF */) {
  12371. for (let i = 0; i < child.branches.length; i++) {
  12372. // Do not hoist v-if single child because it has to be a block
  12373. walk(child.branches[i], context, child.branches[i].children.length === 1);
  12374. }
  12375. }
  12376. }
  12377. if (hoistedCount && context.transformHoist) {
  12378. context.transformHoist(children, context, node);
  12379. }
  12380. // all children were hoisted - the entire children array is hoistable.
  12381. if (hoistedCount &&
  12382. hoistedCount === originalCount &&
  12383. node.type === 1 /* ELEMENT */ &&
  12384. node.tagType === 0 /* ELEMENT */ &&
  12385. node.codegenNode &&
  12386. node.codegenNode.type === 13 /* VNODE_CALL */ &&
  12387. isArray(node.codegenNode.children)) {
  12388. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  12389. }
  12390. }
  12391. function getConstantType(node, context) {
  12392. const { constantCache } = context;
  12393. switch (node.type) {
  12394. case 1 /* ELEMENT */:
  12395. if (node.tagType !== 0 /* ELEMENT */) {
  12396. return 0 /* NOT_CONSTANT */;
  12397. }
  12398. const cached = constantCache.get(node);
  12399. if (cached !== undefined) {
  12400. return cached;
  12401. }
  12402. const codegenNode = node.codegenNode;
  12403. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  12404. return 0 /* NOT_CONSTANT */;
  12405. }
  12406. if (codegenNode.isBlock &&
  12407. node.tag !== 'svg' &&
  12408. node.tag !== 'foreignObject') {
  12409. return 0 /* NOT_CONSTANT */;
  12410. }
  12411. const flag = getPatchFlag(codegenNode);
  12412. if (!flag) {
  12413. let returnType = 3 /* CAN_STRINGIFY */;
  12414. // Element itself has no patch flag. However we still need to check:
  12415. // 1. Even for a node with no patch flag, it is possible for it to contain
  12416. // non-hoistable expressions that refers to scope variables, e.g. compiler
  12417. // injected keys or cached event handlers. Therefore we need to always
  12418. // check the codegenNode's props to be sure.
  12419. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  12420. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  12421. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12422. return 0 /* NOT_CONSTANT */;
  12423. }
  12424. if (generatedPropsType < returnType) {
  12425. returnType = generatedPropsType;
  12426. }
  12427. // 2. its children.
  12428. for (let i = 0; i < node.children.length; i++) {
  12429. const childType = getConstantType(node.children[i], context);
  12430. if (childType === 0 /* NOT_CONSTANT */) {
  12431. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12432. return 0 /* NOT_CONSTANT */;
  12433. }
  12434. if (childType < returnType) {
  12435. returnType = childType;
  12436. }
  12437. }
  12438. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  12439. // type, check if any of the props can cause the type to be lowered
  12440. // we can skip can_patch because it's guaranteed by the absence of a
  12441. // patchFlag.
  12442. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  12443. for (let i = 0; i < node.props.length; i++) {
  12444. const p = node.props[i];
  12445. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  12446. const expType = getConstantType(p.exp, context);
  12447. if (expType === 0 /* NOT_CONSTANT */) {
  12448. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12449. return 0 /* NOT_CONSTANT */;
  12450. }
  12451. if (expType < returnType) {
  12452. returnType = expType;
  12453. }
  12454. }
  12455. }
  12456. }
  12457. // only svg/foreignObject could be block here, however if they are
  12458. // static then they don't need to be blocks since there will be no
  12459. // nested updates.
  12460. if (codegenNode.isBlock) {
  12461. // except set custom directives.
  12462. for (let i = 0; i < node.props.length; i++) {
  12463. const p = node.props[i];
  12464. if (p.type === 7 /* DIRECTIVE */) {
  12465. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12466. return 0 /* NOT_CONSTANT */;
  12467. }
  12468. }
  12469. context.removeHelper(OPEN_BLOCK);
  12470. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  12471. codegenNode.isBlock = false;
  12472. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  12473. }
  12474. constantCache.set(node, returnType);
  12475. return returnType;
  12476. }
  12477. else {
  12478. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12479. return 0 /* NOT_CONSTANT */;
  12480. }
  12481. case 2 /* TEXT */:
  12482. case 3 /* COMMENT */:
  12483. return 3 /* CAN_STRINGIFY */;
  12484. case 9 /* IF */:
  12485. case 11 /* FOR */:
  12486. case 10 /* IF_BRANCH */:
  12487. return 0 /* NOT_CONSTANT */;
  12488. case 5 /* INTERPOLATION */:
  12489. case 12 /* TEXT_CALL */:
  12490. return getConstantType(node.content, context);
  12491. case 4 /* SIMPLE_EXPRESSION */:
  12492. return node.constType;
  12493. case 8 /* COMPOUND_EXPRESSION */:
  12494. let returnType = 3 /* CAN_STRINGIFY */;
  12495. for (let i = 0; i < node.children.length; i++) {
  12496. const child = node.children[i];
  12497. if (isString(child) || isSymbol(child)) {
  12498. continue;
  12499. }
  12500. const childType = getConstantType(child, context);
  12501. if (childType === 0 /* NOT_CONSTANT */) {
  12502. return 0 /* NOT_CONSTANT */;
  12503. }
  12504. else if (childType < returnType) {
  12505. returnType = childType;
  12506. }
  12507. }
  12508. return returnType;
  12509. default:
  12510. return 0 /* NOT_CONSTANT */;
  12511. }
  12512. }
  12513. const allowHoistedHelperSet = new Set([
  12514. NORMALIZE_CLASS,
  12515. NORMALIZE_STYLE,
  12516. NORMALIZE_PROPS,
  12517. GUARD_REACTIVE_PROPS
  12518. ]);
  12519. function getConstantTypeOfHelperCall(value, context) {
  12520. if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
  12521. !isString(value.callee) &&
  12522. allowHoistedHelperSet.has(value.callee)) {
  12523. const arg = value.arguments[0];
  12524. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12525. return getConstantType(arg, context);
  12526. }
  12527. else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
  12528. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  12529. return getConstantTypeOfHelperCall(arg, context);
  12530. }
  12531. }
  12532. return 0 /* NOT_CONSTANT */;
  12533. }
  12534. function getGeneratedPropsConstantType(node, context) {
  12535. let returnType = 3 /* CAN_STRINGIFY */;
  12536. const props = getNodeProps(node);
  12537. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  12538. const { properties } = props;
  12539. for (let i = 0; i < properties.length; i++) {
  12540. const { key, value } = properties[i];
  12541. const keyType = getConstantType(key, context);
  12542. if (keyType === 0 /* NOT_CONSTANT */) {
  12543. return keyType;
  12544. }
  12545. if (keyType < returnType) {
  12546. returnType = keyType;
  12547. }
  12548. let valueType;
  12549. if (value.type === 4 /* SIMPLE_EXPRESSION */) {
  12550. valueType = getConstantType(value, context);
  12551. }
  12552. else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
  12553. // some helper calls can be hoisted,
  12554. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  12555. // in this case we need to respect the ConstantType of the helper's arguments
  12556. valueType = getConstantTypeOfHelperCall(value, context);
  12557. }
  12558. else {
  12559. valueType = 0 /* NOT_CONSTANT */;
  12560. }
  12561. if (valueType === 0 /* NOT_CONSTANT */) {
  12562. return valueType;
  12563. }
  12564. if (valueType < returnType) {
  12565. returnType = valueType;
  12566. }
  12567. }
  12568. }
  12569. return returnType;
  12570. }
  12571. function getNodeProps(node) {
  12572. const codegenNode = node.codegenNode;
  12573. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12574. return codegenNode.props;
  12575. }
  12576. }
  12577. function getPatchFlag(node) {
  12578. const flag = node.patchFlag;
  12579. return flag ? parseInt(flag, 10) : undefined;
  12580. }
  12581. 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 }) {
  12582. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  12583. const context = {
  12584. // options
  12585. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  12586. prefixIdentifiers,
  12587. hoistStatic,
  12588. cacheHandlers,
  12589. nodeTransforms,
  12590. directiveTransforms,
  12591. transformHoist,
  12592. isBuiltInComponent,
  12593. isCustomElement,
  12594. expressionPlugins,
  12595. scopeId,
  12596. slotted,
  12597. ssr,
  12598. inSSR,
  12599. ssrCssVars,
  12600. bindingMetadata,
  12601. inline,
  12602. isTS,
  12603. onError,
  12604. onWarn,
  12605. compatConfig,
  12606. // state
  12607. root,
  12608. helpers: new Map(),
  12609. components: new Set(),
  12610. directives: new Set(),
  12611. hoists: [],
  12612. imports: [],
  12613. constantCache: new Map(),
  12614. temps: 0,
  12615. cached: 0,
  12616. identifiers: Object.create(null),
  12617. scopes: {
  12618. vFor: 0,
  12619. vSlot: 0,
  12620. vPre: 0,
  12621. vOnce: 0
  12622. },
  12623. parent: null,
  12624. currentNode: root,
  12625. childIndex: 0,
  12626. inVOnce: false,
  12627. // methods
  12628. helper(name) {
  12629. const count = context.helpers.get(name) || 0;
  12630. context.helpers.set(name, count + 1);
  12631. return name;
  12632. },
  12633. removeHelper(name) {
  12634. const count = context.helpers.get(name);
  12635. if (count) {
  12636. const currentCount = count - 1;
  12637. if (!currentCount) {
  12638. context.helpers.delete(name);
  12639. }
  12640. else {
  12641. context.helpers.set(name, currentCount);
  12642. }
  12643. }
  12644. },
  12645. helperString(name) {
  12646. return `_${helperNameMap[context.helper(name)]}`;
  12647. },
  12648. replaceNode(node) {
  12649. /* istanbul ignore if */
  12650. {
  12651. if (!context.currentNode) {
  12652. throw new Error(`Node being replaced is already removed.`);
  12653. }
  12654. if (!context.parent) {
  12655. throw new Error(`Cannot replace root node.`);
  12656. }
  12657. }
  12658. context.parent.children[context.childIndex] = context.currentNode = node;
  12659. },
  12660. removeNode(node) {
  12661. if (!context.parent) {
  12662. throw new Error(`Cannot remove root node.`);
  12663. }
  12664. const list = context.parent.children;
  12665. const removalIndex = node
  12666. ? list.indexOf(node)
  12667. : context.currentNode
  12668. ? context.childIndex
  12669. : -1;
  12670. /* istanbul ignore if */
  12671. if (removalIndex < 0) {
  12672. throw new Error(`node being removed is not a child of current parent`);
  12673. }
  12674. if (!node || node === context.currentNode) {
  12675. // current node removed
  12676. context.currentNode = null;
  12677. context.onNodeRemoved();
  12678. }
  12679. else {
  12680. // sibling node removed
  12681. if (context.childIndex > removalIndex) {
  12682. context.childIndex--;
  12683. context.onNodeRemoved();
  12684. }
  12685. }
  12686. context.parent.children.splice(removalIndex, 1);
  12687. },
  12688. onNodeRemoved: () => { },
  12689. addIdentifiers(exp) {
  12690. },
  12691. removeIdentifiers(exp) {
  12692. },
  12693. hoist(exp) {
  12694. if (isString(exp))
  12695. exp = createSimpleExpression(exp);
  12696. context.hoists.push(exp);
  12697. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  12698. identifier.hoisted = exp;
  12699. return identifier;
  12700. },
  12701. cache(exp, isVNode = false) {
  12702. return createCacheExpression(context.cached++, exp, isVNode);
  12703. }
  12704. };
  12705. return context;
  12706. }
  12707. function transform(root, options) {
  12708. const context = createTransformContext(root, options);
  12709. traverseNode(root, context);
  12710. if (options.hoistStatic) {
  12711. hoistStatic(root, context);
  12712. }
  12713. if (!options.ssr) {
  12714. createRootCodegen(root, context);
  12715. }
  12716. // finalize meta information
  12717. root.helpers = [...context.helpers.keys()];
  12718. root.components = [...context.components];
  12719. root.directives = [...context.directives];
  12720. root.imports = context.imports;
  12721. root.hoists = context.hoists;
  12722. root.temps = context.temps;
  12723. root.cached = context.cached;
  12724. }
  12725. function createRootCodegen(root, context) {
  12726. const { helper } = context;
  12727. const { children } = root;
  12728. if (children.length === 1) {
  12729. const child = children[0];
  12730. // if the single child is an element, turn it into a block.
  12731. if (isSingleElementRoot(root, child) && child.codegenNode) {
  12732. // single element root is never hoisted so codegenNode will never be
  12733. // SimpleExpressionNode
  12734. const codegenNode = child.codegenNode;
  12735. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12736. makeBlock(codegenNode, context);
  12737. }
  12738. root.codegenNode = codegenNode;
  12739. }
  12740. else {
  12741. // - single <slot/>, IfNode, ForNode: already blocks.
  12742. // - single text node: always patched.
  12743. // root codegen falls through via genNode()
  12744. root.codegenNode = child;
  12745. }
  12746. }
  12747. else if (children.length > 1) {
  12748. // root has multiple nodes - return a fragment block.
  12749. let patchFlag = 64 /* STABLE_FRAGMENT */;
  12750. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  12751. // check if the fragment actually contains a single valid child with
  12752. // the rest being comments
  12753. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  12754. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  12755. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  12756. }
  12757. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
  12758. }
  12759. else ;
  12760. }
  12761. function traverseChildren(parent, context) {
  12762. let i = 0;
  12763. const nodeRemoved = () => {
  12764. i--;
  12765. };
  12766. for (; i < parent.children.length; i++) {
  12767. const child = parent.children[i];
  12768. if (isString(child))
  12769. continue;
  12770. context.parent = parent;
  12771. context.childIndex = i;
  12772. context.onNodeRemoved = nodeRemoved;
  12773. traverseNode(child, context);
  12774. }
  12775. }
  12776. function traverseNode(node, context) {
  12777. context.currentNode = node;
  12778. // apply transform plugins
  12779. const { nodeTransforms } = context;
  12780. const exitFns = [];
  12781. for (let i = 0; i < nodeTransforms.length; i++) {
  12782. const onExit = nodeTransforms[i](node, context);
  12783. if (onExit) {
  12784. if (isArray(onExit)) {
  12785. exitFns.push(...onExit);
  12786. }
  12787. else {
  12788. exitFns.push(onExit);
  12789. }
  12790. }
  12791. if (!context.currentNode) {
  12792. // node was removed
  12793. return;
  12794. }
  12795. else {
  12796. // node may have been replaced
  12797. node = context.currentNode;
  12798. }
  12799. }
  12800. switch (node.type) {
  12801. case 3 /* COMMENT */:
  12802. if (!context.ssr) {
  12803. // inject import for the Comment symbol, which is needed for creating
  12804. // comment nodes with `createVNode`
  12805. context.helper(CREATE_COMMENT);
  12806. }
  12807. break;
  12808. case 5 /* INTERPOLATION */:
  12809. // no need to traverse, but we need to inject toString helper
  12810. if (!context.ssr) {
  12811. context.helper(TO_DISPLAY_STRING);
  12812. }
  12813. break;
  12814. // for container types, further traverse downwards
  12815. case 9 /* IF */:
  12816. for (let i = 0; i < node.branches.length; i++) {
  12817. traverseNode(node.branches[i], context);
  12818. }
  12819. break;
  12820. case 10 /* IF_BRANCH */:
  12821. case 11 /* FOR */:
  12822. case 1 /* ELEMENT */:
  12823. case 0 /* ROOT */:
  12824. traverseChildren(node, context);
  12825. break;
  12826. }
  12827. // exit transforms
  12828. context.currentNode = node;
  12829. let i = exitFns.length;
  12830. while (i--) {
  12831. exitFns[i]();
  12832. }
  12833. }
  12834. function createStructuralDirectiveTransform(name, fn) {
  12835. const matches = isString(name)
  12836. ? (n) => n === name
  12837. : (n) => name.test(n);
  12838. return (node, context) => {
  12839. if (node.type === 1 /* ELEMENT */) {
  12840. const { props } = node;
  12841. // structural directive transforms are not concerned with slots
  12842. // as they are handled separately in vSlot.ts
  12843. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  12844. return;
  12845. }
  12846. const exitFns = [];
  12847. for (let i = 0; i < props.length; i++) {
  12848. const prop = props[i];
  12849. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  12850. // structural directives are removed to avoid infinite recursion
  12851. // also we remove them *before* applying so that it can further
  12852. // traverse itself in case it moves the node around
  12853. props.splice(i, 1);
  12854. i--;
  12855. const onExit = fn(node, prop, context);
  12856. if (onExit)
  12857. exitFns.push(onExit);
  12858. }
  12859. }
  12860. return exitFns;
  12861. }
  12862. };
  12863. }
  12864. const PURE_ANNOTATION = `/*#__PURE__*/`;
  12865. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  12866. 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 }) {
  12867. const context = {
  12868. mode,
  12869. prefixIdentifiers,
  12870. sourceMap,
  12871. filename,
  12872. scopeId,
  12873. optimizeImports,
  12874. runtimeGlobalName,
  12875. runtimeModuleName,
  12876. ssrRuntimeModuleName,
  12877. ssr,
  12878. isTS,
  12879. inSSR,
  12880. source: ast.loc.source,
  12881. code: ``,
  12882. column: 1,
  12883. line: 1,
  12884. offset: 0,
  12885. indentLevel: 0,
  12886. pure: false,
  12887. map: undefined,
  12888. helper(key) {
  12889. return `_${helperNameMap[key]}`;
  12890. },
  12891. push(code, node) {
  12892. context.code += code;
  12893. },
  12894. indent() {
  12895. newline(++context.indentLevel);
  12896. },
  12897. deindent(withoutNewLine = false) {
  12898. if (withoutNewLine) {
  12899. --context.indentLevel;
  12900. }
  12901. else {
  12902. newline(--context.indentLevel);
  12903. }
  12904. },
  12905. newline() {
  12906. newline(context.indentLevel);
  12907. }
  12908. };
  12909. function newline(n) {
  12910. context.push('\n' + ` `.repeat(n));
  12911. }
  12912. return context;
  12913. }
  12914. function generate(ast, options = {}) {
  12915. const context = createCodegenContext(ast, options);
  12916. if (options.onContextCreated)
  12917. options.onContextCreated(context);
  12918. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  12919. const hasHelpers = ast.helpers.length > 0;
  12920. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  12921. // preambles
  12922. // in setup() inline mode, the preamble is generated in a sub context
  12923. // and returned separately.
  12924. const preambleContext = context;
  12925. {
  12926. genFunctionPreamble(ast, preambleContext);
  12927. }
  12928. // enter render function
  12929. const functionName = ssr ? `ssrRender` : `render`;
  12930. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  12931. const signature = args.join(', ');
  12932. {
  12933. push(`function ${functionName}(${signature}) {`);
  12934. }
  12935. indent();
  12936. if (useWithBlock) {
  12937. push(`with (_ctx) {`);
  12938. indent();
  12939. // function mode const declarations should be inside with block
  12940. // also they should be renamed to avoid collision with user properties
  12941. if (hasHelpers) {
  12942. push(`const { ${ast.helpers.map(aliasHelper).join(', ')} } = _Vue`);
  12943. push(`\n`);
  12944. newline();
  12945. }
  12946. }
  12947. // generate asset resolution statements
  12948. if (ast.components.length) {
  12949. genAssets(ast.components, 'component', context);
  12950. if (ast.directives.length || ast.temps > 0) {
  12951. newline();
  12952. }
  12953. }
  12954. if (ast.directives.length) {
  12955. genAssets(ast.directives, 'directive', context);
  12956. if (ast.temps > 0) {
  12957. newline();
  12958. }
  12959. }
  12960. if (ast.temps > 0) {
  12961. push(`let `);
  12962. for (let i = 0; i < ast.temps; i++) {
  12963. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  12964. }
  12965. }
  12966. if (ast.components.length || ast.directives.length || ast.temps) {
  12967. push(`\n`);
  12968. newline();
  12969. }
  12970. // generate the VNode tree expression
  12971. if (!ssr) {
  12972. push(`return `);
  12973. }
  12974. if (ast.codegenNode) {
  12975. genNode(ast.codegenNode, context);
  12976. }
  12977. else {
  12978. push(`null`);
  12979. }
  12980. if (useWithBlock) {
  12981. deindent();
  12982. push(`}`);
  12983. }
  12984. deindent();
  12985. push(`}`);
  12986. return {
  12987. ast,
  12988. code: context.code,
  12989. preamble: ``,
  12990. // SourceMapGenerator does have toJSON() method but it's not in the types
  12991. map: context.map ? context.map.toJSON() : undefined
  12992. };
  12993. }
  12994. function genFunctionPreamble(ast, context) {
  12995. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  12996. const VueBinding = runtimeGlobalName;
  12997. // Generate const declaration for helpers
  12998. // In prefix mode, we place the const declaration at top so it's done
  12999. // only once; But if we not prefixing, we place the declaration inside the
  13000. // with block so it doesn't incur the `in` check cost for every helper access.
  13001. if (ast.helpers.length > 0) {
  13002. {
  13003. // "with" mode.
  13004. // save Vue in a separate variable to avoid collision
  13005. push(`const _Vue = ${VueBinding}\n`);
  13006. // in "with" mode, helpers are declared inside the with block to avoid
  13007. // has check cost, but hoists are lifted out of the function - we need
  13008. // to provide the helper here.
  13009. if (ast.hoists.length) {
  13010. const staticHelpers = [
  13011. CREATE_VNODE,
  13012. CREATE_ELEMENT_VNODE,
  13013. CREATE_COMMENT,
  13014. CREATE_TEXT,
  13015. CREATE_STATIC
  13016. ]
  13017. .filter(helper => ast.helpers.includes(helper))
  13018. .map(aliasHelper)
  13019. .join(', ');
  13020. push(`const { ${staticHelpers} } = _Vue\n`);
  13021. }
  13022. }
  13023. }
  13024. genHoists(ast.hoists, context);
  13025. newline();
  13026. push(`return `);
  13027. }
  13028. function genAssets(assets, type, { helper, push, newline, isTS }) {
  13029. const resolver = helper(type === 'component'
  13030. ? RESOLVE_COMPONENT
  13031. : RESOLVE_DIRECTIVE);
  13032. for (let i = 0; i < assets.length; i++) {
  13033. let id = assets[i];
  13034. // potential component implicit self-reference inferred from SFC filename
  13035. const maybeSelfReference = id.endsWith('__self');
  13036. if (maybeSelfReference) {
  13037. id = id.slice(0, -6);
  13038. }
  13039. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  13040. if (i < assets.length - 1) {
  13041. newline();
  13042. }
  13043. }
  13044. }
  13045. function genHoists(hoists, context) {
  13046. if (!hoists.length) {
  13047. return;
  13048. }
  13049. context.pure = true;
  13050. const { push, newline, helper, scopeId, mode } = context;
  13051. newline();
  13052. for (let i = 0; i < hoists.length; i++) {
  13053. const exp = hoists[i];
  13054. if (exp) {
  13055. push(`const _hoisted_${i + 1} = ${``}`);
  13056. genNode(exp, context);
  13057. newline();
  13058. }
  13059. }
  13060. context.pure = false;
  13061. }
  13062. function isText$1(n) {
  13063. return (isString(n) ||
  13064. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  13065. n.type === 2 /* TEXT */ ||
  13066. n.type === 5 /* INTERPOLATION */ ||
  13067. n.type === 8 /* COMPOUND_EXPRESSION */);
  13068. }
  13069. function genNodeListAsArray(nodes, context) {
  13070. const multilines = nodes.length > 3 ||
  13071. (nodes.some(n => isArray(n) || !isText$1(n)));
  13072. context.push(`[`);
  13073. multilines && context.indent();
  13074. genNodeList(nodes, context, multilines);
  13075. multilines && context.deindent();
  13076. context.push(`]`);
  13077. }
  13078. function genNodeList(nodes, context, multilines = false, comma = true) {
  13079. const { push, newline } = context;
  13080. for (let i = 0; i < nodes.length; i++) {
  13081. const node = nodes[i];
  13082. if (isString(node)) {
  13083. push(node);
  13084. }
  13085. else if (isArray(node)) {
  13086. genNodeListAsArray(node, context);
  13087. }
  13088. else {
  13089. genNode(node, context);
  13090. }
  13091. if (i < nodes.length - 1) {
  13092. if (multilines) {
  13093. comma && push(',');
  13094. newline();
  13095. }
  13096. else {
  13097. comma && push(', ');
  13098. }
  13099. }
  13100. }
  13101. }
  13102. function genNode(node, context) {
  13103. if (isString(node)) {
  13104. context.push(node);
  13105. return;
  13106. }
  13107. if (isSymbol(node)) {
  13108. context.push(context.helper(node));
  13109. return;
  13110. }
  13111. switch (node.type) {
  13112. case 1 /* ELEMENT */:
  13113. case 9 /* IF */:
  13114. case 11 /* FOR */:
  13115. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  13116. `Apply appropriate transforms first.`);
  13117. genNode(node.codegenNode, context);
  13118. break;
  13119. case 2 /* TEXT */:
  13120. genText(node, context);
  13121. break;
  13122. case 4 /* SIMPLE_EXPRESSION */:
  13123. genExpression(node, context);
  13124. break;
  13125. case 5 /* INTERPOLATION */:
  13126. genInterpolation(node, context);
  13127. break;
  13128. case 12 /* TEXT_CALL */:
  13129. genNode(node.codegenNode, context);
  13130. break;
  13131. case 8 /* COMPOUND_EXPRESSION */:
  13132. genCompoundExpression(node, context);
  13133. break;
  13134. case 3 /* COMMENT */:
  13135. genComment(node, context);
  13136. break;
  13137. case 13 /* VNODE_CALL */:
  13138. genVNodeCall(node, context);
  13139. break;
  13140. case 14 /* JS_CALL_EXPRESSION */:
  13141. genCallExpression(node, context);
  13142. break;
  13143. case 15 /* JS_OBJECT_EXPRESSION */:
  13144. genObjectExpression(node, context);
  13145. break;
  13146. case 17 /* JS_ARRAY_EXPRESSION */:
  13147. genArrayExpression(node, context);
  13148. break;
  13149. case 18 /* JS_FUNCTION_EXPRESSION */:
  13150. genFunctionExpression(node, context);
  13151. break;
  13152. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  13153. genConditionalExpression(node, context);
  13154. break;
  13155. case 20 /* JS_CACHE_EXPRESSION */:
  13156. genCacheExpression(node, context);
  13157. break;
  13158. case 21 /* JS_BLOCK_STATEMENT */:
  13159. genNodeList(node.body, context, true, false);
  13160. break;
  13161. // SSR only types
  13162. case 22 /* JS_TEMPLATE_LITERAL */:
  13163. break;
  13164. case 23 /* JS_IF_STATEMENT */:
  13165. break;
  13166. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  13167. break;
  13168. case 25 /* JS_SEQUENCE_EXPRESSION */:
  13169. break;
  13170. case 26 /* JS_RETURN_STATEMENT */:
  13171. break;
  13172. /* istanbul ignore next */
  13173. case 10 /* IF_BRANCH */:
  13174. // noop
  13175. break;
  13176. default:
  13177. {
  13178. assert(false, `unhandled codegen node type: ${node.type}`);
  13179. // make sure we exhaust all possible types
  13180. const exhaustiveCheck = node;
  13181. return exhaustiveCheck;
  13182. }
  13183. }
  13184. }
  13185. function genText(node, context) {
  13186. context.push(JSON.stringify(node.content), node);
  13187. }
  13188. function genExpression(node, context) {
  13189. const { content, isStatic } = node;
  13190. context.push(isStatic ? JSON.stringify(content) : content, node);
  13191. }
  13192. function genInterpolation(node, context) {
  13193. const { push, helper, pure } = context;
  13194. if (pure)
  13195. push(PURE_ANNOTATION);
  13196. push(`${helper(TO_DISPLAY_STRING)}(`);
  13197. genNode(node.content, context);
  13198. push(`)`);
  13199. }
  13200. function genCompoundExpression(node, context) {
  13201. for (let i = 0; i < node.children.length; i++) {
  13202. const child = node.children[i];
  13203. if (isString(child)) {
  13204. context.push(child);
  13205. }
  13206. else {
  13207. genNode(child, context);
  13208. }
  13209. }
  13210. }
  13211. function genExpressionAsPropertyKey(node, context) {
  13212. const { push } = context;
  13213. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  13214. push(`[`);
  13215. genCompoundExpression(node, context);
  13216. push(`]`);
  13217. }
  13218. else if (node.isStatic) {
  13219. // only quote keys if necessary
  13220. const text = isSimpleIdentifier(node.content)
  13221. ? node.content
  13222. : JSON.stringify(node.content);
  13223. push(text, node);
  13224. }
  13225. else {
  13226. push(`[${node.content}]`, node);
  13227. }
  13228. }
  13229. function genComment(node, context) {
  13230. const { push, helper, pure } = context;
  13231. if (pure) {
  13232. push(PURE_ANNOTATION);
  13233. }
  13234. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  13235. }
  13236. function genVNodeCall(node, context) {
  13237. const { push, helper, pure } = context;
  13238. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  13239. if (directives) {
  13240. push(helper(WITH_DIRECTIVES) + `(`);
  13241. }
  13242. if (isBlock) {
  13243. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  13244. }
  13245. if (pure) {
  13246. push(PURE_ANNOTATION);
  13247. }
  13248. const callHelper = isBlock
  13249. ? getVNodeBlockHelper(context.inSSR, isComponent)
  13250. : getVNodeHelper(context.inSSR, isComponent);
  13251. push(helper(callHelper) + `(`, node);
  13252. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  13253. push(`)`);
  13254. if (isBlock) {
  13255. push(`)`);
  13256. }
  13257. if (directives) {
  13258. push(`, `);
  13259. genNode(directives, context);
  13260. push(`)`);
  13261. }
  13262. }
  13263. function genNullableArgs(args) {
  13264. let i = args.length;
  13265. while (i--) {
  13266. if (args[i] != null)
  13267. break;
  13268. }
  13269. return args.slice(0, i + 1).map(arg => arg || `null`);
  13270. }
  13271. // JavaScript
  13272. function genCallExpression(node, context) {
  13273. const { push, helper, pure } = context;
  13274. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  13275. if (pure) {
  13276. push(PURE_ANNOTATION);
  13277. }
  13278. push(callee + `(`, node);
  13279. genNodeList(node.arguments, context);
  13280. push(`)`);
  13281. }
  13282. function genObjectExpression(node, context) {
  13283. const { push, indent, deindent, newline } = context;
  13284. const { properties } = node;
  13285. if (!properties.length) {
  13286. push(`{}`, node);
  13287. return;
  13288. }
  13289. const multilines = properties.length > 1 ||
  13290. (properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  13291. push(multilines ? `{` : `{ `);
  13292. multilines && indent();
  13293. for (let i = 0; i < properties.length; i++) {
  13294. const { key, value } = properties[i];
  13295. // key
  13296. genExpressionAsPropertyKey(key, context);
  13297. push(`: `);
  13298. // value
  13299. genNode(value, context);
  13300. if (i < properties.length - 1) {
  13301. // will only reach this if it's multilines
  13302. push(`,`);
  13303. newline();
  13304. }
  13305. }
  13306. multilines && deindent();
  13307. push(multilines ? `}` : ` }`);
  13308. }
  13309. function genArrayExpression(node, context) {
  13310. genNodeListAsArray(node.elements, context);
  13311. }
  13312. function genFunctionExpression(node, context) {
  13313. const { push, indent, deindent } = context;
  13314. const { params, returns, body, newline, isSlot } = node;
  13315. if (isSlot) {
  13316. // wrap slot functions with owner context
  13317. push(`_${helperNameMap[WITH_CTX]}(`);
  13318. }
  13319. push(`(`, node);
  13320. if (isArray(params)) {
  13321. genNodeList(params, context);
  13322. }
  13323. else if (params) {
  13324. genNode(params, context);
  13325. }
  13326. push(`) => `);
  13327. if (newline || body) {
  13328. push(`{`);
  13329. indent();
  13330. }
  13331. if (returns) {
  13332. if (newline) {
  13333. push(`return `);
  13334. }
  13335. if (isArray(returns)) {
  13336. genNodeListAsArray(returns, context);
  13337. }
  13338. else {
  13339. genNode(returns, context);
  13340. }
  13341. }
  13342. else if (body) {
  13343. genNode(body, context);
  13344. }
  13345. if (newline || body) {
  13346. deindent();
  13347. push(`}`);
  13348. }
  13349. if (isSlot) {
  13350. push(`)`);
  13351. }
  13352. }
  13353. function genConditionalExpression(node, context) {
  13354. const { test, consequent, alternate, newline: needNewline } = node;
  13355. const { push, indent, deindent, newline } = context;
  13356. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  13357. const needsParens = !isSimpleIdentifier(test.content);
  13358. needsParens && push(`(`);
  13359. genExpression(test, context);
  13360. needsParens && push(`)`);
  13361. }
  13362. else {
  13363. push(`(`);
  13364. genNode(test, context);
  13365. push(`)`);
  13366. }
  13367. needNewline && indent();
  13368. context.indentLevel++;
  13369. needNewline || push(` `);
  13370. push(`? `);
  13371. genNode(consequent, context);
  13372. context.indentLevel--;
  13373. needNewline && newline();
  13374. needNewline || push(` `);
  13375. push(`: `);
  13376. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  13377. if (!isNested) {
  13378. context.indentLevel++;
  13379. }
  13380. genNode(alternate, context);
  13381. if (!isNested) {
  13382. context.indentLevel--;
  13383. }
  13384. needNewline && deindent(true /* without newline */);
  13385. }
  13386. function genCacheExpression(node, context) {
  13387. const { push, helper, indent, deindent, newline } = context;
  13388. push(`_cache[${node.index}] || (`);
  13389. if (node.isVNode) {
  13390. indent();
  13391. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  13392. newline();
  13393. }
  13394. push(`_cache[${node.index}] = `);
  13395. genNode(node.value, context);
  13396. if (node.isVNode) {
  13397. push(`,`);
  13398. newline();
  13399. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  13400. newline();
  13401. push(`_cache[${node.index}]`);
  13402. deindent();
  13403. }
  13404. push(`)`);
  13405. }
  13406. // these keywords should not appear inside expressions, but operators like
  13407. // typeof, instanceof and in are allowed
  13408. const prohibitedKeywordRE = new RegExp('\\b' +
  13409. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  13410. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  13411. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  13412. .split(',')
  13413. .join('\\b|\\b') +
  13414. '\\b');
  13415. // strip strings in expressions
  13416. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  13417. /**
  13418. * Validate a non-prefixed expression.
  13419. * This is only called when using the in-browser runtime compiler since it
  13420. * doesn't prefix expressions.
  13421. */
  13422. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  13423. const exp = node.content;
  13424. // empty expressions are validated per-directive since some directives
  13425. // do allow empty expressions.
  13426. if (!exp.trim()) {
  13427. return;
  13428. }
  13429. try {
  13430. new Function(asRawStatements
  13431. ? ` ${exp} `
  13432. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  13433. }
  13434. catch (e) {
  13435. let message = e.message;
  13436. const keywordMatch = exp
  13437. .replace(stripStringRE, '')
  13438. .match(prohibitedKeywordRE);
  13439. if (keywordMatch) {
  13440. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  13441. }
  13442. context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  13443. }
  13444. }
  13445. const transformExpression = (node, context) => {
  13446. if (node.type === 5 /* INTERPOLATION */) {
  13447. node.content = processExpression(node.content, context);
  13448. }
  13449. else if (node.type === 1 /* ELEMENT */) {
  13450. // handle directives on element
  13451. for (let i = 0; i < node.props.length; i++) {
  13452. const dir = node.props[i];
  13453. // do not process for v-on & v-for since they are special handled
  13454. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  13455. const exp = dir.exp;
  13456. const arg = dir.arg;
  13457. // do not process exp if this is v-on:arg - we need special handling
  13458. // for wrapping inline statements.
  13459. if (exp &&
  13460. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  13461. !(dir.name === 'on' && arg)) {
  13462. dir.exp = processExpression(exp, context,
  13463. // slot args must be processed as function params
  13464. dir.name === 'slot');
  13465. }
  13466. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  13467. dir.arg = processExpression(arg, context);
  13468. }
  13469. }
  13470. }
  13471. }
  13472. };
  13473. // Important: since this function uses Node.js only dependencies, it should
  13474. // always be used with a leading !true check so that it can be
  13475. // tree-shaken from the browser build.
  13476. function processExpression(node, context,
  13477. // some expressions like v-slot props & v-for aliases should be parsed as
  13478. // function params
  13479. asParams = false,
  13480. // v-on handler values may contain multiple statements
  13481. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  13482. {
  13483. {
  13484. // simple in-browser validation (same logic in 2.x)
  13485. validateBrowserExpression(node, context, asParams, asRawStatements);
  13486. }
  13487. return node;
  13488. }
  13489. }
  13490. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  13491. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  13492. // #1587: We need to dynamically increment the key based on the current
  13493. // node's sibling nodes, since chained v-if/else branches are
  13494. // rendered at the same depth
  13495. const siblings = context.parent.children;
  13496. let i = siblings.indexOf(ifNode);
  13497. let key = 0;
  13498. while (i-- >= 0) {
  13499. const sibling = siblings[i];
  13500. if (sibling && sibling.type === 9 /* IF */) {
  13501. key += sibling.branches.length;
  13502. }
  13503. }
  13504. // Exit callback. Complete the codegenNode when all children have been
  13505. // transformed.
  13506. return () => {
  13507. if (isRoot) {
  13508. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  13509. }
  13510. else {
  13511. // attach this branch's codegen node to the v-if root.
  13512. const parentCondition = getParentCondition(ifNode.codegenNode);
  13513. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  13514. }
  13515. };
  13516. });
  13517. });
  13518. // target-agnostic transform used for both Client and SSR
  13519. function processIf(node, dir, context, processCodegen) {
  13520. if (dir.name !== 'else' &&
  13521. (!dir.exp || !dir.exp.content.trim())) {
  13522. const loc = dir.exp ? dir.exp.loc : node.loc;
  13523. context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  13524. dir.exp = createSimpleExpression(`true`, false, loc);
  13525. }
  13526. if (dir.exp) {
  13527. validateBrowserExpression(dir.exp, context);
  13528. }
  13529. if (dir.name === 'if') {
  13530. const branch = createIfBranch(node, dir);
  13531. const ifNode = {
  13532. type: 9 /* IF */,
  13533. loc: node.loc,
  13534. branches: [branch]
  13535. };
  13536. context.replaceNode(ifNode);
  13537. if (processCodegen) {
  13538. return processCodegen(ifNode, branch, true);
  13539. }
  13540. }
  13541. else {
  13542. // locate the adjacent v-if
  13543. const siblings = context.parent.children;
  13544. const comments = [];
  13545. let i = siblings.indexOf(node);
  13546. while (i-- >= -1) {
  13547. const sibling = siblings[i];
  13548. if (sibling && sibling.type === 3 /* COMMENT */) {
  13549. context.removeNode(sibling);
  13550. comments.unshift(sibling);
  13551. continue;
  13552. }
  13553. if (sibling &&
  13554. sibling.type === 2 /* TEXT */ &&
  13555. !sibling.content.trim().length) {
  13556. context.removeNode(sibling);
  13557. continue;
  13558. }
  13559. if (sibling && sibling.type === 9 /* IF */) {
  13560. // Check if v-else was followed by v-else-if
  13561. if (dir.name === 'else-if' &&
  13562. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  13563. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13564. }
  13565. // move the node to the if node's branches
  13566. context.removeNode();
  13567. const branch = createIfBranch(node, dir);
  13568. if (comments.length &&
  13569. // #3619 ignore comments if the v-if is direct child of <transition>
  13570. !(context.parent &&
  13571. context.parent.type === 1 /* ELEMENT */ &&
  13572. isBuiltInType(context.parent.tag, 'transition'))) {
  13573. branch.children = [...comments, ...branch.children];
  13574. }
  13575. // check if user is forcing same key on different branches
  13576. {
  13577. const key = branch.userKey;
  13578. if (key) {
  13579. sibling.branches.forEach(({ userKey }) => {
  13580. if (isSameKey(userKey, key)) {
  13581. context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  13582. }
  13583. });
  13584. }
  13585. }
  13586. sibling.branches.push(branch);
  13587. const onExit = processCodegen && processCodegen(sibling, branch, false);
  13588. // since the branch was removed, it will not be traversed.
  13589. // make sure to traverse here.
  13590. traverseNode(branch, context);
  13591. // call on exit
  13592. if (onExit)
  13593. onExit();
  13594. // make sure to reset currentNode after traversal to indicate this
  13595. // node has been removed.
  13596. context.currentNode = null;
  13597. }
  13598. else {
  13599. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13600. }
  13601. break;
  13602. }
  13603. }
  13604. }
  13605. function createIfBranch(node, dir) {
  13606. const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
  13607. return {
  13608. type: 10 /* IF_BRANCH */,
  13609. loc: node.loc,
  13610. condition: dir.name === 'else' ? undefined : dir.exp,
  13611. children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
  13612. userKey: findProp(node, `key`),
  13613. isTemplateIf
  13614. };
  13615. }
  13616. function createCodegenNodeForBranch(branch, keyIndex, context) {
  13617. if (branch.condition) {
  13618. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  13619. // make sure to pass in asBlock: true so that the comment node call
  13620. // closes the current block.
  13621. createCallExpression(context.helper(CREATE_COMMENT), [
  13622. '"v-if"' ,
  13623. 'true'
  13624. ]));
  13625. }
  13626. else {
  13627. return createChildrenCodegenNode(branch, keyIndex, context);
  13628. }
  13629. }
  13630. function createChildrenCodegenNode(branch, keyIndex, context) {
  13631. const { helper } = context;
  13632. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  13633. const { children } = branch;
  13634. const firstChild = children[0];
  13635. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  13636. if (needFragmentWrapper) {
  13637. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  13638. // optimize away nested fragments when child is a ForNode
  13639. const vnodeCall = firstChild.codegenNode;
  13640. injectProp(vnodeCall, keyProperty, context);
  13641. return vnodeCall;
  13642. }
  13643. else {
  13644. let patchFlag = 64 /* STABLE_FRAGMENT */;
  13645. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  13646. // check if the fragment actually contains a single valid child with
  13647. // the rest being comments
  13648. if (!branch.isTemplateIf &&
  13649. children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  13650. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  13651. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  13652. }
  13653. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  13654. }
  13655. }
  13656. else {
  13657. const ret = firstChild.codegenNode;
  13658. const vnodeCall = getMemoedVNodeCall(ret);
  13659. // Change createVNode to createBlock.
  13660. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  13661. makeBlock(vnodeCall, context);
  13662. }
  13663. // inject branch key
  13664. injectProp(vnodeCall, keyProperty, context);
  13665. return ret;
  13666. }
  13667. }
  13668. function isSameKey(a, b) {
  13669. if (!a || a.type !== b.type) {
  13670. return false;
  13671. }
  13672. if (a.type === 6 /* ATTRIBUTE */) {
  13673. if (a.value.content !== b.value.content) {
  13674. return false;
  13675. }
  13676. }
  13677. else {
  13678. // directive
  13679. const exp = a.exp;
  13680. const branchExp = b.exp;
  13681. if (exp.type !== branchExp.type) {
  13682. return false;
  13683. }
  13684. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  13685. exp.isStatic !== branchExp.isStatic ||
  13686. exp.content !== branchExp.content) {
  13687. return false;
  13688. }
  13689. }
  13690. return true;
  13691. }
  13692. function getParentCondition(node) {
  13693. while (true) {
  13694. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13695. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13696. node = node.alternate;
  13697. }
  13698. else {
  13699. return node;
  13700. }
  13701. }
  13702. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  13703. node = node.value;
  13704. }
  13705. }
  13706. }
  13707. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  13708. const { helper, removeHelper } = context;
  13709. return processFor(node, dir, context, forNode => {
  13710. // create the loop render function expression now, and add the
  13711. // iterator on exit after all children have been traversed
  13712. const renderExp = createCallExpression(helper(RENDER_LIST), [
  13713. forNode.source
  13714. ]);
  13715. const isTemplate = isTemplateNode(node);
  13716. const memo = findDir(node, 'memo');
  13717. const keyProp = findProp(node, `key`);
  13718. const keyExp = keyProp &&
  13719. (keyProp.type === 6 /* ATTRIBUTE */
  13720. ? createSimpleExpression(keyProp.value.content, true)
  13721. : keyProp.exp);
  13722. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  13723. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  13724. forNode.source.constType > 0 /* NOT_CONSTANT */;
  13725. const fragmentFlag = isStableFragment
  13726. ? 64 /* STABLE_FRAGMENT */
  13727. : keyProp
  13728. ? 128 /* KEYED_FRAGMENT */
  13729. : 256 /* UNKEYED_FRAGMENT */;
  13730. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  13731. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  13732. return () => {
  13733. // finish the codegen now that all children have been traversed
  13734. let childBlock;
  13735. const { children } = forNode;
  13736. // check <template v-for> key placement
  13737. if (isTemplate) {
  13738. node.children.some(c => {
  13739. if (c.type === 1 /* ELEMENT */) {
  13740. const key = findProp(c, 'key');
  13741. if (key) {
  13742. context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  13743. return true;
  13744. }
  13745. }
  13746. });
  13747. }
  13748. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  13749. const slotOutlet = isSlotOutlet(node)
  13750. ? node
  13751. : isTemplate &&
  13752. node.children.length === 1 &&
  13753. isSlotOutlet(node.children[0])
  13754. ? node.children[0] // api-extractor somehow fails to infer this
  13755. : null;
  13756. if (slotOutlet) {
  13757. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  13758. childBlock = slotOutlet.codegenNode;
  13759. if (isTemplate && keyProperty) {
  13760. // <template v-for="..." :key="..."><slot/></template>
  13761. // we need to inject the key to the renderSlot() call.
  13762. // the props for renderSlot is passed as the 3rd argument.
  13763. injectProp(childBlock, keyProperty, context);
  13764. }
  13765. }
  13766. else if (needFragmentWrapper) {
  13767. // <template v-for="..."> with text or multi-elements
  13768. // should generate a fragment block for each loop
  13769. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  13770. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  13771. ), undefined, undefined, true, undefined, false /* isComponent */);
  13772. }
  13773. else {
  13774. // Normal element v-for. Directly use the child's codegenNode
  13775. // but mark it as a block.
  13776. childBlock = children[0]
  13777. .codegenNode;
  13778. if (isTemplate && keyProperty) {
  13779. injectProp(childBlock, keyProperty, context);
  13780. }
  13781. if (childBlock.isBlock !== !isStableFragment) {
  13782. if (childBlock.isBlock) {
  13783. // switch from block to vnode
  13784. removeHelper(OPEN_BLOCK);
  13785. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13786. }
  13787. else {
  13788. // switch from vnode to block
  13789. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13790. }
  13791. }
  13792. childBlock.isBlock = !isStableFragment;
  13793. if (childBlock.isBlock) {
  13794. helper(OPEN_BLOCK);
  13795. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13796. }
  13797. else {
  13798. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13799. }
  13800. }
  13801. if (memo) {
  13802. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  13803. createSimpleExpression(`_cached`)
  13804. ]));
  13805. loop.body = createBlockStatement([
  13806. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  13807. createCompoundExpression([
  13808. `if (_cached`,
  13809. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  13810. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  13811. ]),
  13812. createCompoundExpression([`const _item = `, childBlock]),
  13813. createSimpleExpression(`_item.memo = _memo`),
  13814. createSimpleExpression(`return _item`)
  13815. ]);
  13816. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  13817. }
  13818. else {
  13819. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  13820. }
  13821. };
  13822. });
  13823. });
  13824. // target-agnostic transform used for both Client and SSR
  13825. function processFor(node, dir, context, processCodegen) {
  13826. if (!dir.exp) {
  13827. context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  13828. return;
  13829. }
  13830. const parseResult = parseForExpression(
  13831. // can only be simple expression because vFor transform is applied
  13832. // before expression transform.
  13833. dir.exp, context);
  13834. if (!parseResult) {
  13835. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  13836. return;
  13837. }
  13838. const { addIdentifiers, removeIdentifiers, scopes } = context;
  13839. const { source, value, key, index } = parseResult;
  13840. const forNode = {
  13841. type: 11 /* FOR */,
  13842. loc: dir.loc,
  13843. source,
  13844. valueAlias: value,
  13845. keyAlias: key,
  13846. objectIndexAlias: index,
  13847. parseResult,
  13848. children: isTemplateNode(node) ? node.children : [node]
  13849. };
  13850. context.replaceNode(forNode);
  13851. // bookkeeping
  13852. scopes.vFor++;
  13853. const onExit = processCodegen && processCodegen(forNode);
  13854. return () => {
  13855. scopes.vFor--;
  13856. if (onExit)
  13857. onExit();
  13858. };
  13859. }
  13860. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  13861. // This regex doesn't cover the case if key or index aliases have destructuring,
  13862. // but those do not make sense in the first place, so this works in practice.
  13863. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  13864. const stripParensRE = /^\(|\)$/g;
  13865. function parseForExpression(input, context) {
  13866. const loc = input.loc;
  13867. const exp = input.content;
  13868. const inMatch = exp.match(forAliasRE);
  13869. if (!inMatch)
  13870. return;
  13871. const [, LHS, RHS] = inMatch;
  13872. const result = {
  13873. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  13874. value: undefined,
  13875. key: undefined,
  13876. index: undefined
  13877. };
  13878. {
  13879. validateBrowserExpression(result.source, context);
  13880. }
  13881. let valueContent = LHS.trim().replace(stripParensRE, '').trim();
  13882. const trimmedOffset = LHS.indexOf(valueContent);
  13883. const iteratorMatch = valueContent.match(forIteratorRE);
  13884. if (iteratorMatch) {
  13885. valueContent = valueContent.replace(forIteratorRE, '').trim();
  13886. const keyContent = iteratorMatch[1].trim();
  13887. let keyOffset;
  13888. if (keyContent) {
  13889. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  13890. result.key = createAliasExpression(loc, keyContent, keyOffset);
  13891. {
  13892. validateBrowserExpression(result.key, context, true);
  13893. }
  13894. }
  13895. if (iteratorMatch[2]) {
  13896. const indexContent = iteratorMatch[2].trim();
  13897. if (indexContent) {
  13898. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  13899. ? keyOffset + keyContent.length
  13900. : trimmedOffset + valueContent.length));
  13901. {
  13902. validateBrowserExpression(result.index, context, true);
  13903. }
  13904. }
  13905. }
  13906. }
  13907. if (valueContent) {
  13908. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  13909. {
  13910. validateBrowserExpression(result.value, context, true);
  13911. }
  13912. }
  13913. return result;
  13914. }
  13915. function createAliasExpression(range, content, offset) {
  13916. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  13917. }
  13918. function createForLoopParams({ value, key, index }, memoArgs = []) {
  13919. return createParamsList([value, key, index, ...memoArgs]);
  13920. }
  13921. function createParamsList(args) {
  13922. let i = args.length;
  13923. while (i--) {
  13924. if (args[i])
  13925. break;
  13926. }
  13927. return args
  13928. .slice(0, i + 1)
  13929. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  13930. }
  13931. const defaultFallback = createSimpleExpression(`undefined`, false);
  13932. // A NodeTransform that:
  13933. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  13934. // by transformExpression. This is only applied in non-browser builds with
  13935. // { prefixIdentifiers: true }.
  13936. // 2. Track v-slot depths so that we know a slot is inside another slot.
  13937. // Note the exit callback is executed before buildSlots() on the same node,
  13938. // so only nested slots see positive numbers.
  13939. const trackSlotScopes = (node, context) => {
  13940. if (node.type === 1 /* ELEMENT */ &&
  13941. (node.tagType === 1 /* COMPONENT */ ||
  13942. node.tagType === 3 /* TEMPLATE */)) {
  13943. // We are only checking non-empty v-slot here
  13944. // since we only care about slots that introduce scope variables.
  13945. const vSlot = findDir(node, 'slot');
  13946. if (vSlot) {
  13947. vSlot.exp;
  13948. context.scopes.vSlot++;
  13949. return () => {
  13950. context.scopes.vSlot--;
  13951. };
  13952. }
  13953. }
  13954. };
  13955. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  13956. // Instead of being a DirectiveTransform, v-slot processing is called during
  13957. // transformElement to build the slots object for a component.
  13958. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  13959. context.helper(WITH_CTX);
  13960. const { children, loc } = node;
  13961. const slotsProperties = [];
  13962. const dynamicSlots = [];
  13963. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  13964. // since it likely uses a scope variable.
  13965. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  13966. // 1. Check for slot with slotProps on component itself.
  13967. // <Comp v-slot="{ prop }"/>
  13968. const onComponentSlot = findDir(node, 'slot', true);
  13969. if (onComponentSlot) {
  13970. const { arg, exp } = onComponentSlot;
  13971. if (arg && !isStaticExp(arg)) {
  13972. hasDynamicSlots = true;
  13973. }
  13974. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  13975. }
  13976. // 2. Iterate through children and check for template slots
  13977. // <template v-slot:foo="{ prop }">
  13978. let hasTemplateSlots = false;
  13979. let hasNamedDefaultSlot = false;
  13980. const implicitDefaultChildren = [];
  13981. const seenSlotNames = new Set();
  13982. for (let i = 0; i < children.length; i++) {
  13983. const slotElement = children[i];
  13984. let slotDir;
  13985. if (!isTemplateNode(slotElement) ||
  13986. !(slotDir = findDir(slotElement, 'slot', true))) {
  13987. // not a <template v-slot>, skip.
  13988. if (slotElement.type !== 3 /* COMMENT */) {
  13989. implicitDefaultChildren.push(slotElement);
  13990. }
  13991. continue;
  13992. }
  13993. if (onComponentSlot) {
  13994. // already has on-component slot - this is incorrect usage.
  13995. context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  13996. break;
  13997. }
  13998. hasTemplateSlots = true;
  13999. const { children: slotChildren, loc: slotLoc } = slotElement;
  14000. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  14001. // check if name is dynamic.
  14002. let staticSlotName;
  14003. if (isStaticExp(slotName)) {
  14004. staticSlotName = slotName ? slotName.content : `default`;
  14005. }
  14006. else {
  14007. hasDynamicSlots = true;
  14008. }
  14009. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  14010. // check if this slot is conditional (v-if/v-for)
  14011. let vIf;
  14012. let vElse;
  14013. let vFor;
  14014. if ((vIf = findDir(slotElement, 'if'))) {
  14015. hasDynamicSlots = true;
  14016. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  14017. }
  14018. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  14019. // find adjacent v-if
  14020. let j = i;
  14021. let prev;
  14022. while (j--) {
  14023. prev = children[j];
  14024. if (prev.type !== 3 /* COMMENT */) {
  14025. break;
  14026. }
  14027. }
  14028. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  14029. // remove node
  14030. children.splice(i, 1);
  14031. i--;
  14032. // attach this slot to previous conditional
  14033. let conditional = dynamicSlots[dynamicSlots.length - 1];
  14034. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  14035. conditional = conditional.alternate;
  14036. }
  14037. conditional.alternate = vElse.exp
  14038. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  14039. : buildDynamicSlot(slotName, slotFunction);
  14040. }
  14041. else {
  14042. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  14043. }
  14044. }
  14045. else if ((vFor = findDir(slotElement, 'for'))) {
  14046. hasDynamicSlots = true;
  14047. const parseResult = vFor.parseResult ||
  14048. parseForExpression(vFor.exp, context);
  14049. if (parseResult) {
  14050. // Render the dynamic slots as an array and add it to the createSlot()
  14051. // args. The runtime knows how to handle it appropriately.
  14052. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  14053. parseResult.source,
  14054. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  14055. ]));
  14056. }
  14057. else {
  14058. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  14059. }
  14060. }
  14061. else {
  14062. // check duplicate static names
  14063. if (staticSlotName) {
  14064. if (seenSlotNames.has(staticSlotName)) {
  14065. context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  14066. continue;
  14067. }
  14068. seenSlotNames.add(staticSlotName);
  14069. if (staticSlotName === 'default') {
  14070. hasNamedDefaultSlot = true;
  14071. }
  14072. }
  14073. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  14074. }
  14075. }
  14076. if (!onComponentSlot) {
  14077. const buildDefaultSlotProperty = (props, children) => {
  14078. const fn = buildSlotFn(props, children, loc);
  14079. return createObjectProperty(`default`, fn);
  14080. };
  14081. if (!hasTemplateSlots) {
  14082. // implicit default slot (on component)
  14083. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  14084. }
  14085. else if (implicitDefaultChildren.length &&
  14086. // #3766
  14087. // with whitespace: 'preserve', whitespaces between slots will end up in
  14088. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  14089. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  14090. // implicit default slot (mixed with named slots)
  14091. if (hasNamedDefaultSlot) {
  14092. context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  14093. }
  14094. else {
  14095. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  14096. }
  14097. }
  14098. }
  14099. const slotFlag = hasDynamicSlots
  14100. ? 2 /* DYNAMIC */
  14101. : hasForwardedSlots(node.children)
  14102. ? 3 /* FORWARDED */
  14103. : 1 /* STABLE */;
  14104. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  14105. // 2 = compiled but dynamic = can skip normalization, but must run diff
  14106. // 1 = compiled and static = can skip normalization AND diff as optimized
  14107. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  14108. if (dynamicSlots.length) {
  14109. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  14110. slots,
  14111. createArrayExpression(dynamicSlots)
  14112. ]);
  14113. }
  14114. return {
  14115. slots,
  14116. hasDynamicSlots
  14117. };
  14118. }
  14119. function buildDynamicSlot(name, fn) {
  14120. return createObjectExpression([
  14121. createObjectProperty(`name`, name),
  14122. createObjectProperty(`fn`, fn)
  14123. ]);
  14124. }
  14125. function hasForwardedSlots(children) {
  14126. for (let i = 0; i < children.length; i++) {
  14127. const child = children[i];
  14128. switch (child.type) {
  14129. case 1 /* ELEMENT */:
  14130. if (child.tagType === 2 /* SLOT */ ||
  14131. hasForwardedSlots(child.children)) {
  14132. return true;
  14133. }
  14134. break;
  14135. case 9 /* IF */:
  14136. if (hasForwardedSlots(child.branches))
  14137. return true;
  14138. break;
  14139. case 10 /* IF_BRANCH */:
  14140. case 11 /* FOR */:
  14141. if (hasForwardedSlots(child.children))
  14142. return true;
  14143. break;
  14144. }
  14145. }
  14146. return false;
  14147. }
  14148. function isNonWhitespaceContent(node) {
  14149. if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
  14150. return true;
  14151. return node.type === 2 /* TEXT */
  14152. ? !!node.content.trim()
  14153. : isNonWhitespaceContent(node.content);
  14154. }
  14155. // some directive transforms (e.g. v-model) may return a symbol for runtime
  14156. // import, which should be used instead of a resolveDirective call.
  14157. const directiveImportMap = new WeakMap();
  14158. // generate a JavaScript AST for this element's codegen
  14159. const transformElement = (node, context) => {
  14160. // perform the work on exit, after all child expressions have been
  14161. // processed and merged.
  14162. return function postTransformElement() {
  14163. node = context.currentNode;
  14164. if (!(node.type === 1 /* ELEMENT */ &&
  14165. (node.tagType === 0 /* ELEMENT */ ||
  14166. node.tagType === 1 /* COMPONENT */))) {
  14167. return;
  14168. }
  14169. const { tag, props } = node;
  14170. const isComponent = node.tagType === 1 /* COMPONENT */;
  14171. // The goal of the transform is to create a codegenNode implementing the
  14172. // VNodeCall interface.
  14173. let vnodeTag = isComponent
  14174. ? resolveComponentType(node, context)
  14175. : `"${tag}"`;
  14176. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  14177. let vnodeProps;
  14178. let vnodeChildren;
  14179. let vnodePatchFlag;
  14180. let patchFlag = 0;
  14181. let vnodeDynamicProps;
  14182. let dynamicPropNames;
  14183. let vnodeDirectives;
  14184. let shouldUseBlock =
  14185. // dynamic component may resolve to plain elements
  14186. isDynamicComponent ||
  14187. vnodeTag === TELEPORT ||
  14188. vnodeTag === SUSPENSE ||
  14189. (!isComponent &&
  14190. // <svg> and <foreignObject> must be forced into blocks so that block
  14191. // updates inside get proper isSVG flag at runtime. (#639, #643)
  14192. // This is technically web-specific, but splitting the logic out of core
  14193. // leads to too much unnecessary complexity.
  14194. (tag === 'svg' || tag === 'foreignObject'));
  14195. // props
  14196. if (props.length > 0) {
  14197. const propsBuildResult = buildProps(node, context, undefined, isComponent, isDynamicComponent);
  14198. vnodeProps = propsBuildResult.props;
  14199. patchFlag = propsBuildResult.patchFlag;
  14200. dynamicPropNames = propsBuildResult.dynamicPropNames;
  14201. const directives = propsBuildResult.directives;
  14202. vnodeDirectives =
  14203. directives && directives.length
  14204. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  14205. : undefined;
  14206. if (propsBuildResult.shouldUseBlock) {
  14207. shouldUseBlock = true;
  14208. }
  14209. }
  14210. // children
  14211. if (node.children.length > 0) {
  14212. if (vnodeTag === KEEP_ALIVE) {
  14213. // Although a built-in component, we compile KeepAlive with raw children
  14214. // instead of slot functions so that it can be used inside Transition
  14215. // or other Transition-wrapping HOCs.
  14216. // To ensure correct updates with block optimizations, we need to:
  14217. // 1. Force keep-alive into a block. This avoids its children being
  14218. // collected by a parent block.
  14219. shouldUseBlock = true;
  14220. // 2. Force keep-alive to always be updated, since it uses raw children.
  14221. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14222. if (node.children.length > 1) {
  14223. context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  14224. start: node.children[0].loc.start,
  14225. end: node.children[node.children.length - 1].loc.end,
  14226. source: ''
  14227. }));
  14228. }
  14229. }
  14230. const shouldBuildAsSlots = isComponent &&
  14231. // Teleport is not a real component and has dedicated runtime handling
  14232. vnodeTag !== TELEPORT &&
  14233. // explained above.
  14234. vnodeTag !== KEEP_ALIVE;
  14235. if (shouldBuildAsSlots) {
  14236. const { slots, hasDynamicSlots } = buildSlots(node, context);
  14237. vnodeChildren = slots;
  14238. if (hasDynamicSlots) {
  14239. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14240. }
  14241. }
  14242. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  14243. const child = node.children[0];
  14244. const type = child.type;
  14245. // check for dynamic text children
  14246. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  14247. type === 8 /* COMPOUND_EXPRESSION */;
  14248. if (hasDynamicTextChild &&
  14249. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14250. patchFlag |= 1 /* TEXT */;
  14251. }
  14252. // pass directly if the only child is a text node
  14253. // (plain / interpolation / expression)
  14254. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  14255. vnodeChildren = child;
  14256. }
  14257. else {
  14258. vnodeChildren = node.children;
  14259. }
  14260. }
  14261. else {
  14262. vnodeChildren = node.children;
  14263. }
  14264. }
  14265. // patchFlag & dynamicPropNames
  14266. if (patchFlag !== 0) {
  14267. {
  14268. if (patchFlag < 0) {
  14269. // special flags (negative and mutually exclusive)
  14270. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  14271. }
  14272. else {
  14273. // bitwise flags
  14274. const flagNames = Object.keys(PatchFlagNames)
  14275. .map(Number)
  14276. .filter(n => n > 0 && patchFlag & n)
  14277. .map(n => PatchFlagNames[n])
  14278. .join(`, `);
  14279. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  14280. }
  14281. }
  14282. if (dynamicPropNames && dynamicPropNames.length) {
  14283. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  14284. }
  14285. }
  14286. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  14287. };
  14288. };
  14289. function resolveComponentType(node, context, ssr = false) {
  14290. let { tag } = node;
  14291. // 1. dynamic component
  14292. const isExplicitDynamic = isComponentTag(tag);
  14293. const isProp = findProp(node, 'is');
  14294. if (isProp) {
  14295. if (isExplicitDynamic ||
  14296. (false )) {
  14297. const exp = isProp.type === 6 /* ATTRIBUTE */
  14298. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  14299. : isProp.exp;
  14300. if (exp) {
  14301. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14302. exp
  14303. ]);
  14304. }
  14305. }
  14306. else if (isProp.type === 6 /* ATTRIBUTE */ &&
  14307. isProp.value.content.startsWith('vue:')) {
  14308. // <button is="vue:xxx">
  14309. // if not <component>, only is value that starts with "vue:" will be
  14310. // treated as component by the parse phase and reach here, unless it's
  14311. // compat mode where all is values are considered components
  14312. tag = isProp.value.content.slice(4);
  14313. }
  14314. }
  14315. // 1.5 v-is (TODO: Deprecate)
  14316. const isDir = !isExplicitDynamic && findDir(node, 'is');
  14317. if (isDir && isDir.exp) {
  14318. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14319. isDir.exp
  14320. ]);
  14321. }
  14322. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  14323. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  14324. if (builtIn) {
  14325. // built-ins are simply fallthroughs / have special handling during ssr
  14326. // so we don't need to import their runtime equivalents
  14327. if (!ssr)
  14328. context.helper(builtIn);
  14329. return builtIn;
  14330. }
  14331. // 5. user component (resolve)
  14332. context.helper(RESOLVE_COMPONENT);
  14333. context.components.add(tag);
  14334. return toValidAssetId(tag, `component`);
  14335. }
  14336. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  14337. const { tag, loc: elementLoc, children } = node;
  14338. let properties = [];
  14339. const mergeArgs = [];
  14340. const runtimeDirectives = [];
  14341. const hasChildren = children.length > 0;
  14342. let shouldUseBlock = false;
  14343. // patchFlag analysis
  14344. let patchFlag = 0;
  14345. let hasRef = false;
  14346. let hasClassBinding = false;
  14347. let hasStyleBinding = false;
  14348. let hasHydrationEventBinding = false;
  14349. let hasDynamicKeys = false;
  14350. let hasVnodeHook = false;
  14351. const dynamicPropNames = [];
  14352. const analyzePatchFlag = ({ key, value }) => {
  14353. if (isStaticExp(key)) {
  14354. const name = key.content;
  14355. const isEventHandler = isOn(name);
  14356. if (isEventHandler &&
  14357. (!isComponent || isDynamicComponent) &&
  14358. // omit the flag for click handlers because hydration gives click
  14359. // dedicated fast path.
  14360. name.toLowerCase() !== 'onclick' &&
  14361. // omit v-model handlers
  14362. name !== 'onUpdate:modelValue' &&
  14363. // omit onVnodeXXX hooks
  14364. !isReservedProp(name)) {
  14365. hasHydrationEventBinding = true;
  14366. }
  14367. if (isEventHandler && isReservedProp(name)) {
  14368. hasVnodeHook = true;
  14369. }
  14370. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  14371. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  14372. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  14373. getConstantType(value, context) > 0)) {
  14374. // skip if the prop is a cached handler or has constant value
  14375. return;
  14376. }
  14377. if (name === 'ref') {
  14378. hasRef = true;
  14379. }
  14380. else if (name === 'class') {
  14381. hasClassBinding = true;
  14382. }
  14383. else if (name === 'style') {
  14384. hasStyleBinding = true;
  14385. }
  14386. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  14387. dynamicPropNames.push(name);
  14388. }
  14389. // treat the dynamic class and style binding of the component as dynamic props
  14390. if (isComponent &&
  14391. (name === 'class' || name === 'style') &&
  14392. !dynamicPropNames.includes(name)) {
  14393. dynamicPropNames.push(name);
  14394. }
  14395. }
  14396. else {
  14397. hasDynamicKeys = true;
  14398. }
  14399. };
  14400. for (let i = 0; i < props.length; i++) {
  14401. // static attribute
  14402. const prop = props[i];
  14403. if (prop.type === 6 /* ATTRIBUTE */) {
  14404. const { loc, name, value } = prop;
  14405. let isStatic = true;
  14406. if (name === 'ref') {
  14407. hasRef = true;
  14408. if (context.scopes.vFor > 0) {
  14409. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14410. }
  14411. }
  14412. // skip is on <component>, or is="vue:xxx"
  14413. if (name === 'is' &&
  14414. (isComponentTag(tag) ||
  14415. (value && value.content.startsWith('vue:')) ||
  14416. (false ))) {
  14417. continue;
  14418. }
  14419. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  14420. }
  14421. else {
  14422. // directives
  14423. const { name, arg, exp, loc } = prop;
  14424. const isVBind = name === 'bind';
  14425. const isVOn = name === 'on';
  14426. // skip v-slot - it is handled by its dedicated transform.
  14427. if (name === 'slot') {
  14428. if (!isComponent) {
  14429. context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
  14430. }
  14431. continue;
  14432. }
  14433. // skip v-once/v-memo - they are handled by dedicated transforms.
  14434. if (name === 'once' || name === 'memo') {
  14435. continue;
  14436. }
  14437. // skip v-is and :is on <component>
  14438. if (name === 'is' ||
  14439. (isVBind &&
  14440. isStaticArgOf(arg, 'is') &&
  14441. (isComponentTag(tag) ||
  14442. (false )))) {
  14443. continue;
  14444. }
  14445. // skip v-on in SSR compilation
  14446. if (isVOn && ssr) {
  14447. continue;
  14448. }
  14449. if (
  14450. // #938: elements with dynamic keys should be forced into blocks
  14451. (isVBind && isStaticArgOf(arg, 'key')) ||
  14452. // inline before-update hooks need to force block so that it is invoked
  14453. // before children
  14454. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  14455. shouldUseBlock = true;
  14456. }
  14457. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  14458. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14459. }
  14460. // special case for v-bind and v-on with no argument
  14461. if (!arg && (isVBind || isVOn)) {
  14462. hasDynamicKeys = true;
  14463. if (exp) {
  14464. if (properties.length) {
  14465. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14466. properties = [];
  14467. }
  14468. if (isVBind) {
  14469. mergeArgs.push(exp);
  14470. }
  14471. else {
  14472. // v-on="obj" -> toHandlers(obj)
  14473. mergeArgs.push({
  14474. type: 14 /* JS_CALL_EXPRESSION */,
  14475. loc,
  14476. callee: context.helper(TO_HANDLERS),
  14477. arguments: [exp]
  14478. });
  14479. }
  14480. }
  14481. else {
  14482. context.onError(createCompilerError(isVBind
  14483. ? 34 /* X_V_BIND_NO_EXPRESSION */
  14484. : 35 /* X_V_ON_NO_EXPRESSION */, loc));
  14485. }
  14486. continue;
  14487. }
  14488. const directiveTransform = context.directiveTransforms[name];
  14489. if (directiveTransform) {
  14490. // has built-in directive transform.
  14491. const { props, needRuntime } = directiveTransform(prop, node, context);
  14492. !ssr && props.forEach(analyzePatchFlag);
  14493. properties.push(...props);
  14494. if (needRuntime) {
  14495. runtimeDirectives.push(prop);
  14496. if (isSymbol(needRuntime)) {
  14497. directiveImportMap.set(prop, needRuntime);
  14498. }
  14499. }
  14500. }
  14501. else if (!isBuiltInDirective(name)) {
  14502. // no built-in transform, this is a user custom directive.
  14503. runtimeDirectives.push(prop);
  14504. // custom dirs may use beforeUpdate so they need to force blocks
  14505. // to ensure before-update gets called before children update
  14506. if (hasChildren) {
  14507. shouldUseBlock = true;
  14508. }
  14509. }
  14510. }
  14511. }
  14512. let propsExpression = undefined;
  14513. // has v-bind="object" or v-on="object", wrap with mergeProps
  14514. if (mergeArgs.length) {
  14515. if (properties.length) {
  14516. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14517. }
  14518. if (mergeArgs.length > 1) {
  14519. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  14520. }
  14521. else {
  14522. // single v-bind with nothing else - no need for a mergeProps call
  14523. propsExpression = mergeArgs[0];
  14524. }
  14525. }
  14526. else if (properties.length) {
  14527. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  14528. }
  14529. // patchFlag analysis
  14530. if (hasDynamicKeys) {
  14531. patchFlag |= 16 /* FULL_PROPS */;
  14532. }
  14533. else {
  14534. if (hasClassBinding && !isComponent) {
  14535. patchFlag |= 2 /* CLASS */;
  14536. }
  14537. if (hasStyleBinding && !isComponent) {
  14538. patchFlag |= 4 /* STYLE */;
  14539. }
  14540. if (dynamicPropNames.length) {
  14541. patchFlag |= 8 /* PROPS */;
  14542. }
  14543. if (hasHydrationEventBinding) {
  14544. patchFlag |= 32 /* HYDRATE_EVENTS */;
  14545. }
  14546. }
  14547. if (!shouldUseBlock &&
  14548. (patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  14549. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  14550. patchFlag |= 512 /* NEED_PATCH */;
  14551. }
  14552. // pre-normalize props, SSR is skipped for now
  14553. if (!context.inSSR && propsExpression) {
  14554. switch (propsExpression.type) {
  14555. case 15 /* JS_OBJECT_EXPRESSION */:
  14556. // means that there is no v-bind,
  14557. // but still need to deal with dynamic key binding
  14558. let classKeyIndex = -1;
  14559. let styleKeyIndex = -1;
  14560. let hasDynamicKey = false;
  14561. for (let i = 0; i < propsExpression.properties.length; i++) {
  14562. const key = propsExpression.properties[i].key;
  14563. if (isStaticExp(key)) {
  14564. if (key.content === 'class') {
  14565. classKeyIndex = i;
  14566. }
  14567. else if (key.content === 'style') {
  14568. styleKeyIndex = i;
  14569. }
  14570. }
  14571. else if (!key.isHandlerKey) {
  14572. hasDynamicKey = true;
  14573. }
  14574. }
  14575. const classProp = propsExpression.properties[classKeyIndex];
  14576. const styleProp = propsExpression.properties[styleKeyIndex];
  14577. // no dynamic key
  14578. if (!hasDynamicKey) {
  14579. if (classProp && !isStaticExp(classProp.value)) {
  14580. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  14581. }
  14582. if (styleProp &&
  14583. // the static style is compiled into an object,
  14584. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  14585. (hasStyleBinding ||
  14586. (styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
  14587. styleProp.value.content.trim()[0] === `[`) ||
  14588. // v-bind:style and style both exist,
  14589. // v-bind:style with static literal object
  14590. styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
  14591. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  14592. }
  14593. }
  14594. else {
  14595. // dynamic key binding, wrap with `normalizeProps`
  14596. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  14597. }
  14598. break;
  14599. case 14 /* JS_CALL_EXPRESSION */:
  14600. // mergeProps call, do nothing
  14601. break;
  14602. default:
  14603. // single v-bind
  14604. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  14605. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  14606. propsExpression
  14607. ])
  14608. ]);
  14609. break;
  14610. }
  14611. }
  14612. return {
  14613. props: propsExpression,
  14614. directives: runtimeDirectives,
  14615. patchFlag,
  14616. dynamicPropNames,
  14617. shouldUseBlock
  14618. };
  14619. }
  14620. // Dedupe props in an object literal.
  14621. // Literal duplicated attributes would have been warned during the parse phase,
  14622. // however, it's possible to encounter duplicated `onXXX` handlers with different
  14623. // modifiers. We also need to merge static and dynamic class / style attributes.
  14624. // - onXXX handlers / style: merge into array
  14625. // - class: merge into single expression with concatenation
  14626. function dedupeProperties(properties) {
  14627. const knownProps = new Map();
  14628. const deduped = [];
  14629. for (let i = 0; i < properties.length; i++) {
  14630. const prop = properties[i];
  14631. // dynamic keys are always allowed
  14632. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  14633. deduped.push(prop);
  14634. continue;
  14635. }
  14636. const name = prop.key.content;
  14637. const existing = knownProps.get(name);
  14638. if (existing) {
  14639. if (name === 'style' || name === 'class' || isOn(name)) {
  14640. mergeAsArray$1(existing, prop);
  14641. }
  14642. // unexpected duplicate, should have emitted error during parse
  14643. }
  14644. else {
  14645. knownProps.set(name, prop);
  14646. deduped.push(prop);
  14647. }
  14648. }
  14649. return deduped;
  14650. }
  14651. function mergeAsArray$1(existing, incoming) {
  14652. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  14653. existing.value.elements.push(incoming.value);
  14654. }
  14655. else {
  14656. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  14657. }
  14658. }
  14659. function buildDirectiveArgs(dir, context) {
  14660. const dirArgs = [];
  14661. const runtime = directiveImportMap.get(dir);
  14662. if (runtime) {
  14663. // built-in directive with runtime
  14664. dirArgs.push(context.helperString(runtime));
  14665. }
  14666. else {
  14667. {
  14668. // inject statement for resolving directive
  14669. context.helper(RESOLVE_DIRECTIVE);
  14670. context.directives.add(dir.name);
  14671. dirArgs.push(toValidAssetId(dir.name, `directive`));
  14672. }
  14673. }
  14674. const { loc } = dir;
  14675. if (dir.exp)
  14676. dirArgs.push(dir.exp);
  14677. if (dir.arg) {
  14678. if (!dir.exp) {
  14679. dirArgs.push(`void 0`);
  14680. }
  14681. dirArgs.push(dir.arg);
  14682. }
  14683. if (Object.keys(dir.modifiers).length) {
  14684. if (!dir.arg) {
  14685. if (!dir.exp) {
  14686. dirArgs.push(`void 0`);
  14687. }
  14688. dirArgs.push(`void 0`);
  14689. }
  14690. const trueExpression = createSimpleExpression(`true`, false, loc);
  14691. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  14692. }
  14693. return createArrayExpression(dirArgs, dir.loc);
  14694. }
  14695. function stringifyDynamicPropNames(props) {
  14696. let propsNamesString = `[`;
  14697. for (let i = 0, l = props.length; i < l; i++) {
  14698. propsNamesString += JSON.stringify(props[i]);
  14699. if (i < l - 1)
  14700. propsNamesString += ', ';
  14701. }
  14702. return propsNamesString + `]`;
  14703. }
  14704. function isComponentTag(tag) {
  14705. return tag === 'component' || tag === 'Component';
  14706. }
  14707. const transformSlotOutlet = (node, context) => {
  14708. if (isSlotOutlet(node)) {
  14709. const { children, loc } = node;
  14710. const { slotName, slotProps } = processSlotOutlet(node, context);
  14711. const slotArgs = [
  14712. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  14713. slotName,
  14714. '{}',
  14715. 'undefined',
  14716. 'true'
  14717. ];
  14718. let expectedLen = 2;
  14719. if (slotProps) {
  14720. slotArgs[2] = slotProps;
  14721. expectedLen = 3;
  14722. }
  14723. if (children.length) {
  14724. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  14725. expectedLen = 4;
  14726. }
  14727. if (context.scopeId && !context.slotted) {
  14728. expectedLen = 5;
  14729. }
  14730. slotArgs.splice(expectedLen); // remove unused arguments
  14731. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  14732. }
  14733. };
  14734. function processSlotOutlet(node, context) {
  14735. let slotName = `"default"`;
  14736. let slotProps = undefined;
  14737. const nonNameProps = [];
  14738. for (let i = 0; i < node.props.length; i++) {
  14739. const p = node.props[i];
  14740. if (p.type === 6 /* ATTRIBUTE */) {
  14741. if (p.value) {
  14742. if (p.name === 'name') {
  14743. slotName = JSON.stringify(p.value.content);
  14744. }
  14745. else {
  14746. p.name = camelize(p.name);
  14747. nonNameProps.push(p);
  14748. }
  14749. }
  14750. }
  14751. else {
  14752. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  14753. if (p.exp)
  14754. slotName = p.exp;
  14755. }
  14756. else {
  14757. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  14758. p.arg.content = camelize(p.arg.content);
  14759. }
  14760. nonNameProps.push(p);
  14761. }
  14762. }
  14763. }
  14764. if (nonNameProps.length > 0) {
  14765. const { props, directives } = buildProps(node, context, nonNameProps, false, false);
  14766. slotProps = props;
  14767. if (directives.length) {
  14768. context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  14769. }
  14770. }
  14771. return {
  14772. slotName,
  14773. slotProps
  14774. };
  14775. }
  14776. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  14777. const transformOn = (dir, node, context, augmentor) => {
  14778. const { loc, modifiers, arg } = dir;
  14779. if (!dir.exp && !modifiers.length) {
  14780. context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
  14781. }
  14782. let eventName;
  14783. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14784. if (arg.isStatic) {
  14785. let rawName = arg.content;
  14786. // TODO deprecate @vnodeXXX usage
  14787. if (rawName.startsWith('vue:')) {
  14788. rawName = `vnode-${rawName.slice(4)}`;
  14789. }
  14790. // for all event listeners, auto convert it to camelCase. See issue #2249
  14791. eventName = createSimpleExpression(toHandlerKey(camelize(rawName)), true, arg.loc);
  14792. }
  14793. else {
  14794. // #2388
  14795. eventName = createCompoundExpression([
  14796. `${context.helperString(TO_HANDLER_KEY)}(`,
  14797. arg,
  14798. `)`
  14799. ]);
  14800. }
  14801. }
  14802. else {
  14803. // already a compound expression.
  14804. eventName = arg;
  14805. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  14806. eventName.children.push(`)`);
  14807. }
  14808. // handler processing
  14809. let exp = dir.exp;
  14810. if (exp && !exp.content.trim()) {
  14811. exp = undefined;
  14812. }
  14813. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  14814. if (exp) {
  14815. const isMemberExp = isMemberExpression(exp.content);
  14816. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  14817. const hasMultipleStatements = exp.content.includes(`;`);
  14818. {
  14819. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  14820. }
  14821. if (isInlineStatement || (shouldCache && isMemberExp)) {
  14822. // wrap inline statement in a function expression
  14823. exp = createCompoundExpression([
  14824. `${isInlineStatement
  14825. ? `$event`
  14826. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  14827. exp,
  14828. hasMultipleStatements ? `}` : `)`
  14829. ]);
  14830. }
  14831. }
  14832. let ret = {
  14833. props: [
  14834. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  14835. ]
  14836. };
  14837. // apply extended compiler augmentor
  14838. if (augmentor) {
  14839. ret = augmentor(ret);
  14840. }
  14841. if (shouldCache) {
  14842. // cache handlers so that it's always the same handler being passed down.
  14843. // this avoids unnecessary re-renders when users use inline handlers on
  14844. // components.
  14845. ret.props[0].value = context.cache(ret.props[0].value);
  14846. }
  14847. // mark the key as handler for props normalization check
  14848. ret.props.forEach(p => (p.key.isHandlerKey = true));
  14849. return ret;
  14850. };
  14851. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  14852. // codegen for the entire props object. This transform here is only for v-bind
  14853. // *with* args.
  14854. const transformBind = (dir, _node, context) => {
  14855. const { exp, modifiers, loc } = dir;
  14856. const arg = dir.arg;
  14857. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  14858. arg.children.unshift(`(`);
  14859. arg.children.push(`) || ""`);
  14860. }
  14861. else if (!arg.isStatic) {
  14862. arg.content = `${arg.content} || ""`;
  14863. }
  14864. // .sync is replaced by v-model:arg
  14865. if (modifiers.includes('camel')) {
  14866. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14867. if (arg.isStatic) {
  14868. arg.content = camelize(arg.content);
  14869. }
  14870. else {
  14871. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  14872. }
  14873. }
  14874. else {
  14875. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  14876. arg.children.push(`)`);
  14877. }
  14878. }
  14879. if (!context.inSSR) {
  14880. if (modifiers.includes('prop')) {
  14881. injectPrefix(arg, '.');
  14882. }
  14883. if (modifiers.includes('attr')) {
  14884. injectPrefix(arg, '^');
  14885. }
  14886. }
  14887. if (!exp ||
  14888. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  14889. context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
  14890. return {
  14891. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  14892. };
  14893. }
  14894. return {
  14895. props: [createObjectProperty(arg, exp)]
  14896. };
  14897. };
  14898. const injectPrefix = (arg, prefix) => {
  14899. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14900. if (arg.isStatic) {
  14901. arg.content = prefix + arg.content;
  14902. }
  14903. else {
  14904. arg.content = `\`${prefix}\${${arg.content}}\``;
  14905. }
  14906. }
  14907. else {
  14908. arg.children.unshift(`'${prefix}' + (`);
  14909. arg.children.push(`)`);
  14910. }
  14911. };
  14912. // Merge adjacent text nodes and expressions into a single expression
  14913. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  14914. const transformText = (node, context) => {
  14915. if (node.type === 0 /* ROOT */ ||
  14916. node.type === 1 /* ELEMENT */ ||
  14917. node.type === 11 /* FOR */ ||
  14918. node.type === 10 /* IF_BRANCH */) {
  14919. // perform the transform on node exit so that all expressions have already
  14920. // been processed.
  14921. return () => {
  14922. const children = node.children;
  14923. let currentContainer = undefined;
  14924. let hasText = false;
  14925. for (let i = 0; i < children.length; i++) {
  14926. const child = children[i];
  14927. if (isText(child)) {
  14928. hasText = true;
  14929. for (let j = i + 1; j < children.length; j++) {
  14930. const next = children[j];
  14931. if (isText(next)) {
  14932. if (!currentContainer) {
  14933. currentContainer = children[i] = createCompoundExpression([child], child.loc);
  14934. }
  14935. // merge adjacent text node into current
  14936. currentContainer.children.push(` + `, next);
  14937. children.splice(j, 1);
  14938. j--;
  14939. }
  14940. else {
  14941. currentContainer = undefined;
  14942. break;
  14943. }
  14944. }
  14945. }
  14946. }
  14947. if (!hasText ||
  14948. // if this is a plain element with a single text child, leave it
  14949. // as-is since the runtime has dedicated fast path for this by directly
  14950. // setting textContent of the element.
  14951. // for component root it's always normalized anyway.
  14952. (children.length === 1 &&
  14953. (node.type === 0 /* ROOT */ ||
  14954. (node.type === 1 /* ELEMENT */ &&
  14955. node.tagType === 0 /* ELEMENT */ &&
  14956. // #3756
  14957. // custom directives can potentially add DOM elements arbitrarily,
  14958. // we need to avoid setting textContent of the element at runtime
  14959. // to avoid accidentally overwriting the DOM elements added
  14960. // by the user through custom directives.
  14961. !node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
  14962. !context.directiveTransforms[p.name]) &&
  14963. // in compat mode, <template> tags with no special directives
  14964. // will be rendered as a fragment so its children must be
  14965. // converted into vnodes.
  14966. !(false ))))) {
  14967. return;
  14968. }
  14969. // pre-convert text nodes into createTextVNode(text) calls to avoid
  14970. // runtime normalization.
  14971. for (let i = 0; i < children.length; i++) {
  14972. const child = children[i];
  14973. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  14974. const callArgs = [];
  14975. // createTextVNode defaults to single whitespace, so if it is a
  14976. // single space the code could be an empty call to save bytes.
  14977. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  14978. callArgs.push(child);
  14979. }
  14980. // mark dynamic text with flag so it gets patched inside a block
  14981. if (!context.ssr &&
  14982. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14983. callArgs.push(1 /* TEXT */ +
  14984. (` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
  14985. }
  14986. children[i] = {
  14987. type: 12 /* TEXT_CALL */,
  14988. content: child,
  14989. loc: child.loc,
  14990. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  14991. };
  14992. }
  14993. }
  14994. };
  14995. }
  14996. };
  14997. const seen = new WeakSet();
  14998. const transformOnce = (node, context) => {
  14999. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  15000. if (seen.has(node) || context.inVOnce) {
  15001. return;
  15002. }
  15003. seen.add(node);
  15004. context.inVOnce = true;
  15005. context.helper(SET_BLOCK_TRACKING);
  15006. return () => {
  15007. context.inVOnce = false;
  15008. const cur = context.currentNode;
  15009. if (cur.codegenNode) {
  15010. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  15011. }
  15012. };
  15013. }
  15014. };
  15015. const transformModel = (dir, node, context) => {
  15016. const { exp, arg } = dir;
  15017. if (!exp) {
  15018. context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  15019. return createTransformProps();
  15020. }
  15021. const rawExp = exp.loc.source;
  15022. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  15023. // im SFC <script setup> inline mode, the exp may have been transformed into
  15024. // _unref(exp)
  15025. context.bindingMetadata[rawExp];
  15026. const maybeRef = !true /* SETUP_CONST */;
  15027. if (!expString.trim() ||
  15028. (!isMemberExpression(expString) && !maybeRef)) {
  15029. context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  15030. return createTransformProps();
  15031. }
  15032. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  15033. const eventName = arg
  15034. ? isStaticExp(arg)
  15035. ? `onUpdate:${arg.content}`
  15036. : createCompoundExpression(['"onUpdate:" + ', arg])
  15037. : `onUpdate:modelValue`;
  15038. let assignmentExp;
  15039. const eventArg = context.isTS ? `($event: any)` : `$event`;
  15040. {
  15041. assignmentExp = createCompoundExpression([
  15042. `${eventArg} => ((`,
  15043. exp,
  15044. `) = $event)`
  15045. ]);
  15046. }
  15047. const props = [
  15048. // modelValue: foo
  15049. createObjectProperty(propName, dir.exp),
  15050. // "onUpdate:modelValue": $event => (foo = $event)
  15051. createObjectProperty(eventName, assignmentExp)
  15052. ];
  15053. // modelModifiers: { foo: true, "bar-baz": true }
  15054. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  15055. const modifiers = dir.modifiers
  15056. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  15057. .join(`, `);
  15058. const modifiersKey = arg
  15059. ? isStaticExp(arg)
  15060. ? `${arg.content}Modifiers`
  15061. : createCompoundExpression([arg, ' + "Modifiers"'])
  15062. : `modelModifiers`;
  15063. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  15064. }
  15065. return createTransformProps(props);
  15066. };
  15067. function createTransformProps(props = []) {
  15068. return { props };
  15069. }
  15070. const seen$1 = new WeakSet();
  15071. const transformMemo = (node, context) => {
  15072. if (node.type === 1 /* ELEMENT */) {
  15073. const dir = findDir(node, 'memo');
  15074. if (!dir || seen$1.has(node)) {
  15075. return;
  15076. }
  15077. seen$1.add(node);
  15078. return () => {
  15079. const codegenNode = node.codegenNode ||
  15080. context.currentNode.codegenNode;
  15081. if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
  15082. // non-component sub tree should be turned into a block
  15083. if (node.tagType !== 1 /* COMPONENT */) {
  15084. makeBlock(codegenNode, context);
  15085. }
  15086. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  15087. dir.exp,
  15088. createFunctionExpression(undefined, codegenNode),
  15089. `_cache`,
  15090. String(context.cached++)
  15091. ]);
  15092. }
  15093. };
  15094. }
  15095. };
  15096. function getBaseTransformPreset(prefixIdentifiers) {
  15097. return [
  15098. [
  15099. transformOnce,
  15100. transformIf,
  15101. transformMemo,
  15102. transformFor,
  15103. ...([]),
  15104. ...([transformExpression]
  15105. ),
  15106. transformSlotOutlet,
  15107. transformElement,
  15108. trackSlotScopes,
  15109. transformText
  15110. ],
  15111. {
  15112. on: transformOn,
  15113. bind: transformBind,
  15114. model: transformModel
  15115. }
  15116. ];
  15117. }
  15118. // we name it `baseCompile` so that higher order compilers like
  15119. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  15120. function baseCompile(template, options = {}) {
  15121. const onError = options.onError || defaultOnError;
  15122. const isModuleMode = options.mode === 'module';
  15123. /* istanbul ignore if */
  15124. {
  15125. if (options.prefixIdentifiers === true) {
  15126. onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
  15127. }
  15128. else if (isModuleMode) {
  15129. onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
  15130. }
  15131. }
  15132. const prefixIdentifiers = !true ;
  15133. if (options.cacheHandlers) {
  15134. onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  15135. }
  15136. if (options.scopeId && !isModuleMode) {
  15137. onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
  15138. }
  15139. const ast = isString(template) ? baseParse(template, options) : template;
  15140. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  15141. transform(ast, extend({}, options, {
  15142. prefixIdentifiers,
  15143. nodeTransforms: [
  15144. ...nodeTransforms,
  15145. ...(options.nodeTransforms || []) // user transforms
  15146. ],
  15147. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  15148. )
  15149. }));
  15150. return generate(ast, extend({}, options, {
  15151. prefixIdentifiers
  15152. }));
  15153. }
  15154. const noopDirectiveTransform = () => ({ props: [] });
  15155. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  15156. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  15157. const V_MODEL_TEXT = Symbol(`vModelText` );
  15158. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  15159. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  15160. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  15161. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  15162. const V_SHOW = Symbol(`vShow` );
  15163. const TRANSITION$1 = Symbol(`Transition` );
  15164. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  15165. registerRuntimeHelpers({
  15166. [V_MODEL_RADIO]: `vModelRadio`,
  15167. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  15168. [V_MODEL_TEXT]: `vModelText`,
  15169. [V_MODEL_SELECT]: `vModelSelect`,
  15170. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  15171. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  15172. [V_ON_WITH_KEYS]: `withKeys`,
  15173. [V_SHOW]: `vShow`,
  15174. [TRANSITION$1]: `Transition`,
  15175. [TRANSITION_GROUP]: `TransitionGroup`
  15176. });
  15177. /* eslint-disable no-restricted-globals */
  15178. let decoder;
  15179. function decodeHtmlBrowser(raw, asAttr = false) {
  15180. if (!decoder) {
  15181. decoder = document.createElement('div');
  15182. }
  15183. if (asAttr) {
  15184. decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
  15185. return decoder.children[0].getAttribute('foo');
  15186. }
  15187. else {
  15188. decoder.innerHTML = raw;
  15189. return decoder.textContent;
  15190. }
  15191. }
  15192. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  15193. const parserOptions = {
  15194. isVoidTag,
  15195. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  15196. isPreTag: tag => tag === 'pre',
  15197. decodeEntities: decodeHtmlBrowser ,
  15198. isBuiltInComponent: (tag) => {
  15199. if (isBuiltInType(tag, `Transition`)) {
  15200. return TRANSITION$1;
  15201. }
  15202. else if (isBuiltInType(tag, `TransitionGroup`)) {
  15203. return TRANSITION_GROUP;
  15204. }
  15205. },
  15206. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  15207. getNamespace(tag, parent) {
  15208. let ns = parent ? parent.ns : 0 /* HTML */;
  15209. if (parent && ns === 2 /* MATH_ML */) {
  15210. if (parent.tag === 'annotation-xml') {
  15211. if (tag === 'svg') {
  15212. return 1 /* SVG */;
  15213. }
  15214. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  15215. a.name === 'encoding' &&
  15216. a.value != null &&
  15217. (a.value.content === 'text/html' ||
  15218. a.value.content === 'application/xhtml+xml'))) {
  15219. ns = 0 /* HTML */;
  15220. }
  15221. }
  15222. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  15223. tag !== 'mglyph' &&
  15224. tag !== 'malignmark') {
  15225. ns = 0 /* HTML */;
  15226. }
  15227. }
  15228. else if (parent && ns === 1 /* SVG */) {
  15229. if (parent.tag === 'foreignObject' ||
  15230. parent.tag === 'desc' ||
  15231. parent.tag === 'title') {
  15232. ns = 0 /* HTML */;
  15233. }
  15234. }
  15235. if (ns === 0 /* HTML */) {
  15236. if (tag === 'svg') {
  15237. return 1 /* SVG */;
  15238. }
  15239. if (tag === 'math') {
  15240. return 2 /* MATH_ML */;
  15241. }
  15242. }
  15243. return ns;
  15244. },
  15245. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  15246. getTextMode({ tag, ns }) {
  15247. if (ns === 0 /* HTML */) {
  15248. if (tag === 'textarea' || tag === 'title') {
  15249. return 1 /* RCDATA */;
  15250. }
  15251. if (isRawTextContainer(tag)) {
  15252. return 2 /* RAWTEXT */;
  15253. }
  15254. }
  15255. return 0 /* DATA */;
  15256. }
  15257. };
  15258. // Parse inline CSS strings for static style attributes into an object.
  15259. // This is a NodeTransform since it works on the static `style` attribute and
  15260. // converts it into a dynamic equivalent:
  15261. // style="color: red" -> :style='{ "color": "red" }'
  15262. // It is then processed by `transformElement` and included in the generated
  15263. // props.
  15264. const transformStyle = node => {
  15265. if (node.type === 1 /* ELEMENT */) {
  15266. node.props.forEach((p, i) => {
  15267. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  15268. // replace p with an expression node
  15269. node.props[i] = {
  15270. type: 7 /* DIRECTIVE */,
  15271. name: `bind`,
  15272. arg: createSimpleExpression(`style`, true, p.loc),
  15273. exp: parseInlineCSS(p.value.content, p.loc),
  15274. modifiers: [],
  15275. loc: p.loc
  15276. };
  15277. }
  15278. });
  15279. }
  15280. };
  15281. const parseInlineCSS = (cssText, loc) => {
  15282. const normalized = parseStringStyle(cssText);
  15283. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
  15284. };
  15285. function createDOMCompilerError(code, loc) {
  15286. return createCompilerError(code, loc, DOMErrorMessages );
  15287. }
  15288. const DOMErrorMessages = {
  15289. [50 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  15290. [51 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  15291. [52 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  15292. [53 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  15293. [54 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  15294. [55 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  15295. [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.`,
  15296. [57 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  15297. [58 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  15298. [59 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  15299. [60 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  15300. };
  15301. const transformVHtml = (dir, node, context) => {
  15302. const { exp, loc } = dir;
  15303. if (!exp) {
  15304. context.onError(createDOMCompilerError(50 /* X_V_HTML_NO_EXPRESSION */, loc));
  15305. }
  15306. if (node.children.length) {
  15307. context.onError(createDOMCompilerError(51 /* X_V_HTML_WITH_CHILDREN */, loc));
  15308. node.children.length = 0;
  15309. }
  15310. return {
  15311. props: [
  15312. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  15313. ]
  15314. };
  15315. };
  15316. const transformVText = (dir, node, context) => {
  15317. const { exp, loc } = dir;
  15318. if (!exp) {
  15319. context.onError(createDOMCompilerError(52 /* X_V_TEXT_NO_EXPRESSION */, loc));
  15320. }
  15321. if (node.children.length) {
  15322. context.onError(createDOMCompilerError(53 /* X_V_TEXT_WITH_CHILDREN */, loc));
  15323. node.children.length = 0;
  15324. }
  15325. return {
  15326. props: [
  15327. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  15328. ? getConstantType(exp, context) > 0
  15329. ? exp
  15330. : createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  15331. : createSimpleExpression('', true))
  15332. ]
  15333. };
  15334. };
  15335. const transformModel$1 = (dir, node, context) => {
  15336. const baseResult = transformModel(dir, node, context);
  15337. // base transform has errors OR component v-model (only need props)
  15338. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  15339. return baseResult;
  15340. }
  15341. if (dir.arg) {
  15342. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  15343. }
  15344. function checkDuplicatedValue() {
  15345. const value = findProp(node, 'value');
  15346. if (value) {
  15347. context.onError(createDOMCompilerError(57 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  15348. }
  15349. }
  15350. const { tag } = node;
  15351. const isCustomElement = context.isCustomElement(tag);
  15352. if (tag === 'input' ||
  15353. tag === 'textarea' ||
  15354. tag === 'select' ||
  15355. isCustomElement) {
  15356. let directiveToUse = V_MODEL_TEXT;
  15357. let isInvalidType = false;
  15358. if (tag === 'input' || isCustomElement) {
  15359. const type = findProp(node, `type`);
  15360. if (type) {
  15361. if (type.type === 7 /* DIRECTIVE */) {
  15362. // :type="foo"
  15363. directiveToUse = V_MODEL_DYNAMIC;
  15364. }
  15365. else if (type.value) {
  15366. switch (type.value.content) {
  15367. case 'radio':
  15368. directiveToUse = V_MODEL_RADIO;
  15369. break;
  15370. case 'checkbox':
  15371. directiveToUse = V_MODEL_CHECKBOX;
  15372. break;
  15373. case 'file':
  15374. isInvalidType = true;
  15375. context.onError(createDOMCompilerError(56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  15376. break;
  15377. default:
  15378. // text type
  15379. checkDuplicatedValue();
  15380. break;
  15381. }
  15382. }
  15383. }
  15384. else if (hasDynamicKeyVBind(node)) {
  15385. // element has bindings with dynamic keys, which can possibly contain
  15386. // "type".
  15387. directiveToUse = V_MODEL_DYNAMIC;
  15388. }
  15389. else {
  15390. // text type
  15391. checkDuplicatedValue();
  15392. }
  15393. }
  15394. else if (tag === 'select') {
  15395. directiveToUse = V_MODEL_SELECT;
  15396. }
  15397. else {
  15398. // textarea
  15399. checkDuplicatedValue();
  15400. }
  15401. // inject runtime directive
  15402. // by returning the helper symbol via needRuntime
  15403. // the import will replaced a resolveDirective call.
  15404. if (!isInvalidType) {
  15405. baseResult.needRuntime = context.helper(directiveToUse);
  15406. }
  15407. }
  15408. else {
  15409. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  15410. }
  15411. // native vmodel doesn't need the `modelValue` props since they are also
  15412. // passed to the runtime as `binding.value`. removing it reduces code size.
  15413. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  15414. p.key.content === 'modelValue'));
  15415. return baseResult;
  15416. };
  15417. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  15418. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  15419. // event propagation management
  15420. `stop,prevent,self,` +
  15421. // system modifiers + exact
  15422. `ctrl,shift,alt,meta,exact,` +
  15423. // mouse
  15424. `middle`);
  15425. // left & right could be mouse or key modifiers based on event type
  15426. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  15427. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  15428. const resolveModifiers = (key, modifiers, context, loc) => {
  15429. const keyModifiers = [];
  15430. const nonKeyModifiers = [];
  15431. const eventOptionModifiers = [];
  15432. for (let i = 0; i < modifiers.length; i++) {
  15433. const modifier = modifiers[i];
  15434. if (isEventOptionModifier(modifier)) {
  15435. // eventOptionModifiers: modifiers for addEventListener() options,
  15436. // e.g. .passive & .capture
  15437. eventOptionModifiers.push(modifier);
  15438. }
  15439. else {
  15440. // runtimeModifiers: modifiers that needs runtime guards
  15441. if (maybeKeyModifier(modifier)) {
  15442. if (isStaticExp(key)) {
  15443. if (isKeyboardEvent(key.content)) {
  15444. keyModifiers.push(modifier);
  15445. }
  15446. else {
  15447. nonKeyModifiers.push(modifier);
  15448. }
  15449. }
  15450. else {
  15451. keyModifiers.push(modifier);
  15452. nonKeyModifiers.push(modifier);
  15453. }
  15454. }
  15455. else {
  15456. if (isNonKeyModifier(modifier)) {
  15457. nonKeyModifiers.push(modifier);
  15458. }
  15459. else {
  15460. keyModifiers.push(modifier);
  15461. }
  15462. }
  15463. }
  15464. }
  15465. return {
  15466. keyModifiers,
  15467. nonKeyModifiers,
  15468. eventOptionModifiers
  15469. };
  15470. };
  15471. const transformClick = (key, event) => {
  15472. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  15473. return isStaticClick
  15474. ? createSimpleExpression(event, true)
  15475. : key.type !== 4 /* SIMPLE_EXPRESSION */
  15476. ? createCompoundExpression([
  15477. `(`,
  15478. key,
  15479. `) === "onClick" ? "${event}" : (`,
  15480. key,
  15481. `)`
  15482. ])
  15483. : key;
  15484. };
  15485. const transformOn$1 = (dir, node, context) => {
  15486. return transformOn(dir, node, context, baseResult => {
  15487. const { modifiers } = dir;
  15488. if (!modifiers.length)
  15489. return baseResult;
  15490. let { key, value: handlerExp } = baseResult.props[0];
  15491. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  15492. // normalize click.right and click.middle since they don't actually fire
  15493. if (nonKeyModifiers.includes('right')) {
  15494. key = transformClick(key, `onContextmenu`);
  15495. }
  15496. if (nonKeyModifiers.includes('middle')) {
  15497. key = transformClick(key, `onMouseup`);
  15498. }
  15499. if (nonKeyModifiers.length) {
  15500. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  15501. handlerExp,
  15502. JSON.stringify(nonKeyModifiers)
  15503. ]);
  15504. }
  15505. if (keyModifiers.length &&
  15506. // if event name is dynamic, always wrap with keys guard
  15507. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  15508. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  15509. handlerExp,
  15510. JSON.stringify(keyModifiers)
  15511. ]);
  15512. }
  15513. if (eventOptionModifiers.length) {
  15514. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  15515. key = isStaticExp(key)
  15516. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  15517. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  15518. }
  15519. return {
  15520. props: [createObjectProperty(key, handlerExp)]
  15521. };
  15522. });
  15523. };
  15524. const transformShow = (dir, node, context) => {
  15525. const { exp, loc } = dir;
  15526. if (!exp) {
  15527. context.onError(createDOMCompilerError(58 /* X_V_SHOW_NO_EXPRESSION */, loc));
  15528. }
  15529. return {
  15530. props: [],
  15531. needRuntime: context.helper(V_SHOW)
  15532. };
  15533. };
  15534. const transformTransition = (node, context) => {
  15535. if (node.type === 1 /* ELEMENT */ &&
  15536. node.tagType === 1 /* COMPONENT */) {
  15537. const component = context.isBuiltInComponent(node.tag);
  15538. if (component === TRANSITION$1) {
  15539. return () => {
  15540. if (!node.children.length) {
  15541. return;
  15542. }
  15543. // warn multiple transition children
  15544. if (hasMultipleChildren(node)) {
  15545. context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
  15546. start: node.children[0].loc.start,
  15547. end: node.children[node.children.length - 1].loc.end,
  15548. source: ''
  15549. }));
  15550. }
  15551. // check if it's s single child w/ v-show
  15552. // if yes, inject "persisted: true" to the transition props
  15553. const child = node.children[0];
  15554. if (child.type === 1 /* ELEMENT */) {
  15555. for (const p of child.props) {
  15556. if (p.type === 7 /* DIRECTIVE */ && p.name === 'show') {
  15557. node.props.push({
  15558. type: 6 /* ATTRIBUTE */,
  15559. name: 'persisted',
  15560. value: undefined,
  15561. loc: node.loc
  15562. });
  15563. }
  15564. }
  15565. }
  15566. };
  15567. }
  15568. }
  15569. };
  15570. function hasMultipleChildren(node) {
  15571. // #1352 filter out potential comment nodes.
  15572. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */ &&
  15573. !(c.type === 2 /* TEXT */ && !c.content.trim())));
  15574. const child = children[0];
  15575. return (children.length !== 1 ||
  15576. child.type === 11 /* FOR */ ||
  15577. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  15578. }
  15579. const ignoreSideEffectTags = (node, context) => {
  15580. if (node.type === 1 /* ELEMENT */ &&
  15581. node.tagType === 0 /* ELEMENT */ &&
  15582. (node.tag === 'script' || node.tag === 'style')) {
  15583. context.onError(createDOMCompilerError(60 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  15584. context.removeNode();
  15585. }
  15586. };
  15587. const DOMNodeTransforms = [
  15588. transformStyle,
  15589. ...([transformTransition] )
  15590. ];
  15591. const DOMDirectiveTransforms = {
  15592. cloak: noopDirectiveTransform,
  15593. html: transformVHtml,
  15594. text: transformVText,
  15595. model: transformModel$1,
  15596. on: transformOn$1,
  15597. show: transformShow
  15598. };
  15599. function compile$1(template, options = {}) {
  15600. return baseCompile(template, extend({}, parserOptions, options, {
  15601. nodeTransforms: [
  15602. // ignore <script> and <tag>
  15603. // this is not put inside DOMNodeTransforms because that list is used
  15604. // by compiler-ssr to generate vnode fallback branches
  15605. ignoreSideEffectTags,
  15606. ...DOMNodeTransforms,
  15607. ...(options.nodeTransforms || [])
  15608. ],
  15609. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  15610. transformHoist: null
  15611. }));
  15612. }
  15613. // This entry is the "full-build" that includes both the runtime
  15614. {
  15615. initDev();
  15616. }
  15617. const compileCache = Object.create(null);
  15618. function compileToFunction(template, options) {
  15619. if (!isString(template)) {
  15620. if (template.nodeType) {
  15621. template = template.innerHTML;
  15622. }
  15623. else {
  15624. warn$1(`invalid template option: `, template);
  15625. return NOOP;
  15626. }
  15627. }
  15628. const key = template;
  15629. const cached = compileCache[key];
  15630. if (cached) {
  15631. return cached;
  15632. }
  15633. if (template[0] === '#') {
  15634. const el = document.querySelector(template);
  15635. if (!el) {
  15636. warn$1(`Template element not found or is empty: ${template}`);
  15637. }
  15638. // __UNSAFE__
  15639. // Reason: potential execution of JS expressions in in-DOM template.
  15640. // The user must make sure the in-DOM template is trusted. If it's rendered
  15641. // by the server, the template should not contain any user data.
  15642. template = el ? el.innerHTML : ``;
  15643. }
  15644. const { code } = compile$1(template, extend({
  15645. hoistStatic: true,
  15646. onError: onError ,
  15647. onWarn: e => onError(e, true)
  15648. }, options));
  15649. function onError(err, asWarning = false) {
  15650. const message = asWarning
  15651. ? err.message
  15652. : `Template compilation error: ${err.message}`;
  15653. const codeFrame = err.loc &&
  15654. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  15655. warn$1(codeFrame ? `${message}\n${codeFrame}` : message);
  15656. }
  15657. // The wildcard import results in a huge object with every export
  15658. // with keys that cannot be mangled, and can be quite heavy size-wise.
  15659. // In the global build we know `Vue` is available globally so we can avoid
  15660. // the wildcard object.
  15661. const render = (new Function(code)() );
  15662. render._rc = true;
  15663. return (compileCache[key] = render);
  15664. }
  15665. registerRuntimeCompiler(compileToFunction);
  15666. exports.BaseTransition = BaseTransition;
  15667. exports.Comment = Comment;
  15668. exports.EffectScope = EffectScope;
  15669. exports.Fragment = Fragment;
  15670. exports.KeepAlive = KeepAlive;
  15671. exports.ReactiveEffect = ReactiveEffect;
  15672. exports.Static = Static;
  15673. exports.Suspense = Suspense;
  15674. exports.Teleport = Teleport;
  15675. exports.Text = Text;
  15676. exports.Transition = Transition;
  15677. exports.TransitionGroup = TransitionGroup;
  15678. exports.VueElement = VueElement;
  15679. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  15680. exports.callWithErrorHandling = callWithErrorHandling;
  15681. exports.camelize = camelize;
  15682. exports.capitalize = capitalize;
  15683. exports.cloneVNode = cloneVNode;
  15684. exports.compatUtils = compatUtils;
  15685. exports.compile = compileToFunction;
  15686. exports.computed = computed$1;
  15687. exports.createApp = createApp;
  15688. exports.createBlock = createBlock;
  15689. exports.createCommentVNode = createCommentVNode;
  15690. exports.createElementBlock = createElementBlock;
  15691. exports.createElementVNode = createBaseVNode;
  15692. exports.createHydrationRenderer = createHydrationRenderer;
  15693. exports.createPropsRestProxy = createPropsRestProxy;
  15694. exports.createRenderer = createRenderer;
  15695. exports.createSSRApp = createSSRApp;
  15696. exports.createSlots = createSlots;
  15697. exports.createStaticVNode = createStaticVNode;
  15698. exports.createTextVNode = createTextVNode;
  15699. exports.createVNode = createVNode;
  15700. exports.customRef = customRef;
  15701. exports.defineAsyncComponent = defineAsyncComponent;
  15702. exports.defineComponent = defineComponent;
  15703. exports.defineCustomElement = defineCustomElement;
  15704. exports.defineEmits = defineEmits;
  15705. exports.defineExpose = defineExpose;
  15706. exports.defineProps = defineProps;
  15707. exports.defineSSRCustomElement = defineSSRCustomElement;
  15708. exports.effect = effect;
  15709. exports.effectScope = effectScope;
  15710. exports.getCurrentInstance = getCurrentInstance;
  15711. exports.getCurrentScope = getCurrentScope;
  15712. exports.getTransitionRawChildren = getTransitionRawChildren;
  15713. exports.guardReactiveProps = guardReactiveProps;
  15714. exports.h = h;
  15715. exports.handleError = handleError;
  15716. exports.hydrate = hydrate;
  15717. exports.initCustomFormatter = initCustomFormatter;
  15718. exports.initDirectivesForSSR = initDirectivesForSSR;
  15719. exports.inject = inject;
  15720. exports.isMemoSame = isMemoSame;
  15721. exports.isProxy = isProxy;
  15722. exports.isReactive = isReactive;
  15723. exports.isReadonly = isReadonly;
  15724. exports.isRef = isRef;
  15725. exports.isRuntimeOnly = isRuntimeOnly;
  15726. exports.isShallow = isShallow;
  15727. exports.isVNode = isVNode;
  15728. exports.markRaw = markRaw;
  15729. exports.mergeDefaults = mergeDefaults;
  15730. exports.mergeProps = mergeProps;
  15731. exports.nextTick = nextTick;
  15732. exports.normalizeClass = normalizeClass;
  15733. exports.normalizeProps = normalizeProps;
  15734. exports.normalizeStyle = normalizeStyle;
  15735. exports.onActivated = onActivated;
  15736. exports.onBeforeMount = onBeforeMount;
  15737. exports.onBeforeUnmount = onBeforeUnmount;
  15738. exports.onBeforeUpdate = onBeforeUpdate;
  15739. exports.onDeactivated = onDeactivated;
  15740. exports.onErrorCaptured = onErrorCaptured;
  15741. exports.onMounted = onMounted;
  15742. exports.onRenderTracked = onRenderTracked;
  15743. exports.onRenderTriggered = onRenderTriggered;
  15744. exports.onScopeDispose = onScopeDispose;
  15745. exports.onServerPrefetch = onServerPrefetch;
  15746. exports.onUnmounted = onUnmounted;
  15747. exports.onUpdated = onUpdated;
  15748. exports.openBlock = openBlock;
  15749. exports.popScopeId = popScopeId;
  15750. exports.provide = provide;
  15751. exports.proxyRefs = proxyRefs;
  15752. exports.pushScopeId = pushScopeId;
  15753. exports.queuePostFlushCb = queuePostFlushCb;
  15754. exports.reactive = reactive;
  15755. exports.readonly = readonly;
  15756. exports.ref = ref;
  15757. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  15758. exports.render = render;
  15759. exports.renderList = renderList;
  15760. exports.renderSlot = renderSlot;
  15761. exports.resolveComponent = resolveComponent;
  15762. exports.resolveDirective = resolveDirective;
  15763. exports.resolveDynamicComponent = resolveDynamicComponent;
  15764. exports.resolveFilter = resolveFilter;
  15765. exports.resolveTransitionHooks = resolveTransitionHooks;
  15766. exports.setBlockTracking = setBlockTracking;
  15767. exports.setDevtoolsHook = setDevtoolsHook;
  15768. exports.setTransitionHooks = setTransitionHooks;
  15769. exports.shallowReactive = shallowReactive;
  15770. exports.shallowReadonly = shallowReadonly;
  15771. exports.shallowRef = shallowRef;
  15772. exports.ssrContextKey = ssrContextKey;
  15773. exports.ssrUtils = ssrUtils;
  15774. exports.stop = stop;
  15775. exports.toDisplayString = toDisplayString;
  15776. exports.toHandlerKey = toHandlerKey;
  15777. exports.toHandlers = toHandlers;
  15778. exports.toRaw = toRaw;
  15779. exports.toRef = toRef;
  15780. exports.toRefs = toRefs;
  15781. exports.transformVNodeArgs = transformVNodeArgs;
  15782. exports.triggerRef = triggerRef;
  15783. exports.unref = unref;
  15784. exports.useAttrs = useAttrs;
  15785. exports.useCssModule = useCssModule;
  15786. exports.useCssVars = useCssVars;
  15787. exports.useSSRContext = useSSRContext;
  15788. exports.useSlots = useSlots;
  15789. exports.useTransitionState = useTransitionState;
  15790. exports.vModelCheckbox = vModelCheckbox;
  15791. exports.vModelDynamic = vModelDynamic;
  15792. exports.vModelRadio = vModelRadio;
  15793. exports.vModelSelect = vModelSelect;
  15794. exports.vModelText = vModelText;
  15795. exports.vShow = vShow;
  15796. exports.version = version;
  15797. exports.warn = warn$1;
  15798. exports.watch = watch;
  15799. exports.watchEffect = watchEffect;
  15800. exports.watchPostEffect = watchPostEffect;
  15801. exports.watchSyncEffect = watchSyncEffect;
  15802. exports.withAsyncContext = withAsyncContext;
  15803. exports.withCtx = withCtx;
  15804. exports.withDefaults = withDefaults;
  15805. exports.withDirectives = withDirectives;
  15806. exports.withKeys = withKeys;
  15807. exports.withMemo = withMemo;
  15808. exports.withModifiers = withModifiers;
  15809. exports.withScopeId = withScopeId;
  15810. Object.defineProperty(exports, '__esModule', { value: true });
  15811. return exports;
  15812. }({}));